This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Make SCS prologue interrupt safe on RISC-V
ClosedPublic

Authored by paulkirth on Apr 24 2023, 2:20 PM.

Details

Summary

Prior to this patch the SCS prologue used the following instruction
sequence.

s[w|d]  ra, 0(gp)
addi    gp, gp, [4|8]

The problem with this sequence is that an interrupt occurring between the
store and the increment could clobber the value just written to the SCS.

https://reviews.llvm.org/D84414#inline-813203 pointed out a similar
issues that could have affected the epilogue.

This patch changes the instruction sequence in the prologue to:

addi    gp, gp, [4|8]
s[w|d]  ra, -[4|8](gp)

The downside to this is that there is now a data dependency between the
add and the store.

Diff Detail

Event Timeline

paulkirth created this revision.Apr 24 2023, 2:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2023, 2:20 PM
paulkirth requested review of this revision.Apr 24 2023, 2:20 PM
asb accepted this revision.Apr 26 2023, 7:44 AM

LGTM.

This revision is now accepted and ready to land.Apr 26 2023, 7:44 AM
This revision was landed with ongoing or failed builds.Apr 26 2023, 8:58 AM
This revision was automatically updated to reflect the committed changes.