Skip to content

Commit f539f97

Browse files
committed
eBPF.md: Document atomic exchange and atomic compare-and-write
Atomic exchange and atomic compare-and-write are selected when the immediate value for an atomic operation is set to BPF_XCHG (0xe0) | BPF_FETCH (1) and BPF_CMPXCHG (0xf0) | BPF_FETCH (1), respectively. This is supported in the kernel since commit: 5ffa25502b5a ("bpf: Add instructions for atomic_[cmp]xchg")
1 parent fc0e54a commit f539f97

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

eBPF.md

+4
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,14 @@ Opcode | Mnemonic | Pseudocode
234234
-------------------|----------------------------|---------------------------------------------------------
235235
0xdb (imm == 0x00) | add [dst+off], src | (dst + off) += src
236236
0xdb (imm == 0x01) | fetch_add [dst+off], src | src = dst, (dst + off) += src
237+
0xdb (imm == 0xe1) | xchg [dst+off], src | src = (dst + off), (dst + off) = src
238+
0xdb (imm == 0xf1) | cmpxchg [dst+off], src | r0 = (dst + off), (dst + off) = src if (dst + off) == r0
237239

238240
### 32-bit
239241

240242
Opcode | Mnemonic | Pseudocode (uint32_t * casts omitted for readability)
241243
-------|----------------------------|---------------------------------------------------------------------
242244
0xc3 (imm == 0x00) | add32 [dst+off], src | (dst + off) += src
243245
0xc3 (imm == 0x01) | fetch_add32 [dst+off], src | src = dst, (dst + off) += src
246+
0xc3 (imm == 0xe1) | xchg32 [dst+off], src | src = (dst + off), (dst + off) = src
247+
0xc3 (imm == 0xf1) | cmpxchg32 [dst+off], src | r0 = (dst + off), (dst + off) = src if (dst + off) == r0

0 commit comments

Comments
 (0)