Skip to content

asm: Add Load-Acquire and Store-Release instructions #1751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dylandreimerink
Copy link
Member

This PR adds proper stringification for the Load-Acquire and Store-Release instructions added in v6.15 as well as functions to generate these instructions.

These new instructions will fall under the BPF ISAv4. They are atomic load/store instructions with a "memory order", which seems to be best explained here.

The acquire-release semantics surrounding these instructions provide rules for the non-atomic reads and writes around these instructions can and cannot be reordered. See the kernel lore linked in the original issue for details.

The way they decided to encode these new instructions is to use the imm/Constant bit of the BPF instruction to further special the BPF_ATOMIC | BPF_STX / StXClass | XAddMode opcode. Interestingly, this means that the "store" class now actually can be a load depending on its imm/Constant value, which forces us to do some special casing in our string formatting logic.

Fixes: #1750

This commit adds proper stringification for the Load-Acquire and
Store-Release instructions as well as functions to generate these
instructions.

Signed-off-by: Dylan Reimerink <[email protected]>
Comment on lines +245 to +257
// LoadAcquire emits an atomic load with acquire semantics.
func LoadAcquire(dst, src Register, offset int16, size Size) Instruction {
return Instruction{
OpCode: StoreXAddOp(size), // We use Store here, for a Load, this is a quirk of the ISA
Dst: dst,
Src: src,
Offset: offset,
Constant: int64(LoadAcquireAtomicFlag),
}
}

// StoreRelease emits an atomic store with release semantics.
func StoreRelease(dst, src Register, offset int16, size Size) Instruction {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the descriptions on these brief for now. Not sure how much context we need to give the user about what these instructions do.

@dylandreimerink dylandreimerink marked this pull request as ready for review April 14, 2025 08:53
@dylandreimerink dylandreimerink requested a review from a team as a code owner April 14, 2025 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update asm package with load-aquire and store-release instructions
1 participant