x86/bpf: Avoid emitting LOCK prefix for XCHG atomic ops
Subsystems (3)
PATCH 1/1 x86/bpf: Avoid emitting LOCK prefix for XCHG atomic ops
The x86 XCHG instruction is implicitly locked when one of the operands is a memory location, making an explicit LOCK prefix unnecessary.
Stop emitting the LOCK prefix for BPF_XCHG in the JIT atomic read-modify-write helpers. This avoids redundant instruction prefixes while preserving correct atomic semantics.
No functional change for other atomic operations.
--- arch/x86/net/bpf_jit_comp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/net/bpf_jit_comp.c +5 -2
@@ -1305,7 +1305,8 @@ static int emit_atomic_rmw(u8 **pprog, u32 atomic_op, {u8 *prog = *pprog; -EMIT1 (0xF0 );/* lock prefix */ +if (atomic_op !=BPF_XCHG ) +EMIT1 (0xF0 );/* lock prefix */ maybe_emit_mod (&prog, dst_reg, src_reg, bpf_size ==BPF_DW );
@@ -1347,7 +1348,9 @@ static int emit_atomic_rmw_index(u8 **pprog, u32 atomic_op, u32 size, {u8 *prog = *pprog; -EMIT1 (0xF0 );/* lock prefix */ +if (atomic_op !=BPF_XCHG ) +EMIT1 (0xF0 );/* lock prefix */ +switch (size) {case BPF_W :EMIT1 (add_3mod (0x40 , dst_reg, src_reg, index_reg));
Signature · 1 line
2.52.0
Alexei Starovoitov
AppliedQuoted 20 lines · Uros Bizjak
The x86 XCHG instruction is implicitly locked when one of the operands is a memory location, making an explicit LOCK prefix unnecessary.
Stop emitting the LOCK prefix for
BPF_XCHGin the JIT atomic read-modify-write helpers. This avoids redundant instruction prefixes while preserving correct atomic semantics.No functional change for other atomic operations.
Signed-off-by Uros Bizjak <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Daniel Borkmann <[email protected]>Cc Andrii Nakryiko <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Borislav Petkov <[email protected]>Cc Dave Hansen <[email protected]>Cc "H. Peter Anvin" <[email protected]>
Quoted 3 lines
--- arch/x86/net/bpf_jit_comp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Applied to bpf-next.