summaryrefslogtreecommitdiff
path: root/tools/include/asm-generic
diff options
context:
space:
mode:
authorPeter Gonda <pgonda@google.com>2022-10-06 00:34:06 +0000
committerSean Christopherson <seanjc@google.com>2022-11-16 16:58:52 -0800
commitcf4694be2b2cf74945e50d39a02ea2307c4495f4 (patch)
tree74389c8ce3d4978a99def91aa5f9a259a61437fb /tools/include/asm-generic
parentdc88244bf5488b04fb7bbe47d8d9c38ff8f7dbb4 (diff)
downloadlwn-cf4694be2b2cf74945e50d39a02ea2307c4495f4.tar.gz
lwn-cf4694be2b2cf74945e50d39a02ea2307c4495f4.zip
tools: Add atomic_test_and_set_bit()
Add x86 and generic implementations of atomic_test_and_set_bit() to allow KVM selftests to atomically manage bitmaps. Note, the generic version is taken from arch_test_and_set_bit() as of commit 415d83249709 ("locking/atomic: Make test_and_*_bit() ordered on failure"). Signed-off-by: Peter Gonda <pgonda@google.com> Co-developed-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Link: https://lore.kernel.org/r/20221006003409.649993-5-seanjc@google.com
Diffstat (limited to 'tools/include/asm-generic')
-rw-r--r--tools/include/asm-generic/atomic-gcc.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/include/asm-generic/atomic-gcc.h b/tools/include/asm-generic/atomic-gcc.h
index 4c1966f7c77a..6daa68bf5b9e 100644
--- a/tools/include/asm-generic/atomic-gcc.h
+++ b/tools/include/asm-generic/atomic-gcc.h
@@ -4,6 +4,7 @@
#include <linux/compiler.h>
#include <linux/types.h>
+#include <linux/bitops.h>
/*
* Atomic operations that C can't guarantee us. Useful for
@@ -69,4 +70,15 @@ static inline int atomic_cmpxchg(atomic_t *v, int oldval, int newval)
return cmpxchg(&(v)->counter, oldval, newval);
}
+static inline int atomic_test_and_set_bit(long nr, unsigned long *addr)
+{
+ unsigned long mask = BIT_MASK(nr);
+ long old;
+
+ addr += BIT_WORD(nr);
+
+ old = __sync_fetch_and_or(addr, mask);
+ return !!(old & mask);
+}
+
#endif /* __TOOLS_ASM_GENERIC_ATOMIC_H */