All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/atomic: Add arch_atomic_not()
@ 2026-07-14  5:42 Ziran Zhang
  0 siblings, 0 replies; only message in thread
From: Ziran Zhang @ 2026-07-14  5:42 UTC (permalink / raw)
  To: Will Deacon, Peter Zijlstra, Boqun Feng, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H . Peter Anvin
  Cc: Mark Rutland, Gary Guo, linux-kernel, Ziran Zhang

The kernel already has non-atomic bitmap_complement(), but
no direct atomic implementation.

According to Intel and AMD manuals, the NOT instruction
supports a LOCK prefix.

Currently the only way to achieve this is arch_atomic_xor(-1, v),
which is non-obvious and hurts readability, so add arch_atomic_not()
to provide an explicit atomic complement operation.

Signed-off-by: Ziran Zhang <zhangcoder@yeah.net>
---
 arch/x86/include/asm/atomic.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
index 75743f1df..d7e543194 100644
--- a/arch/x86/include/asm/atomic.h
+++ b/arch/x86/include/asm/atomic.h
@@ -168,6 +168,13 @@ static __always_inline int arch_atomic_fetch_xor(int i, atomic_t *v)
 }
 #define arch_atomic_fetch_xor arch_atomic_fetch_xor
 
+static __always_inline void arch_atomic_not(atomic_t *v)
+{
+	asm_inline volatile(LOCK_PREFIX "notl %0"
+			: "+m" (v->counter) :: "memory");
+}
+#define arch_atomic_not arch_atomic_not
+
 #ifdef CONFIG_X86_32
 # include <asm/atomic64_32.h>
 #else
-- 
2.51.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-14  5:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-14  5:42 [PATCH] x86/atomic: Add arch_atomic_not() Ziran Zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.