Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <ubizjak@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Link: https://lore.kernel.org/r/20251208163420.7643-1-ubizjak@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Uros Bizjak and committed by
Alexei Starovoitov
e09f6be4 c2f2f005

+5 -2
+5 -2
arch/x86/net/bpf_jit_comp.c
··· 1305 1305 { 1306 1306 u8 *prog = *pprog; 1307 1307 1308 - EMIT1(0xF0); /* lock prefix */ 1308 + if (atomic_op != BPF_XCHG) 1309 + EMIT1(0xF0); /* lock prefix */ 1309 1310 1310 1311 maybe_emit_mod(&prog, dst_reg, src_reg, bpf_size == BPF_DW); 1311 1312 ··· 1348 1347 { 1349 1348 u8 *prog = *pprog; 1350 1349 1351 - EMIT1(0xF0); /* lock prefix */ 1350 + if (atomic_op != BPF_XCHG) 1351 + EMIT1(0xF0); /* lock prefix */ 1352 + 1352 1353 switch (size) { 1353 1354 case BPF_W: 1354 1355 EMIT1(add_3mod(0x40, dst_reg, src_reg, index_reg));