mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-03-22 07:27:12 +08:00
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>
This commit is contained in:
committed by
Alexei Starovoitov
parent
c2f2f005a1
commit
e09f6be4a3
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user