Skip to content

Commit 5cf957b

Browse files
ubizjakKernel Patches Daemon
authored andcommitted
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. 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]>
1 parent 162c0b3 commit 5cf957b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

arch/x86/net/bpf_jit_comp.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,8 @@ static int emit_atomic_rmw(u8 **pprog, u32 atomic_op,
13051305
{
13061306
u8 *prog = *pprog;
13071307

1308-
EMIT1(0xF0); /* lock prefix */
1308+
if (atomic_op != BPF_XCHG)
1309+
EMIT1(0xF0); /* lock prefix */
13091310

13101311
maybe_emit_mod(&prog, dst_reg, src_reg, bpf_size == BPF_DW);
13111312

@@ -1347,7 +1348,9 @@ static int emit_atomic_rmw_index(u8 **pprog, u32 atomic_op, u32 size,
13471348
{
13481349
u8 *prog = *pprog;
13491350

1350-
EMIT1(0xF0); /* lock prefix */
1351+
if (atomic_op != BPF_XCHG)
1352+
EMIT1(0xF0); /* lock prefix */
1353+
13511354
switch (size) {
13521355
case BPF_W:
13531356
EMIT1(add_3mod(0x40, dst_reg, src_reg, index_reg));

0 commit comments

Comments
 (0)