diff options
| author | Sean Christopherson <seanjc@google.com> | 2022-11-19 01:34:50 +0000 |
|---|---|---|
| committer | Paolo Bonzini <pbonzini@redhat.com> | 2022-12-02 13:22:35 -0500 |
| commit | bb056c0f080a3d15c2a9ad9057a8b542d45e4ba0 (patch) | |
| tree | a7231d2f04e11798c35e848bcfbddb4db0bc098b /tools/include/asm-generic/atomic-gcc.h | |
| parent | tools: Drop "atomic_" prefix from atomic test_and_set_bit() (diff) | |
| download | linux-bb056c0f080a3d15c2a9ad9057a8b542d45e4ba0.tar.gz linux-bb056c0f080a3d15c2a9ad9057a8b542d45e4ba0.zip | |
tools: KVM: selftests: Convert clear/set_bit() to actual atomics
Convert {clear,set}_bit() to atomics as KVM's ucall implementation relies
on clear_bit() being atomic, they are defined in atomic.h, and the same
helpers in the kernel proper are atomic.
KVM's ucall infrastructure is the only user of clear_bit() in tools/, and
there are no true set_bit() users. tools/testing/nvdimm/ does make heavy
use of set_bit(), but that code builds into a kernel module of sorts, i.e.
pulls in all of the kernel's header and so is already getting the kernel's
atomic set_bit().
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20221119013450.2643007-10-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tools/include/asm-generic/atomic-gcc.h')
| -rw-r--r-- | tools/include/asm-generic/atomic-gcc.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tools/include/asm-generic/atomic-gcc.h b/tools/include/asm-generic/atomic-gcc.h index 37ef522aaac4..9b3c528bab92 100644 --- a/tools/include/asm-generic/atomic-gcc.h +++ b/tools/include/asm-generic/atomic-gcc.h @@ -81,4 +81,15 @@ static inline int test_and_set_bit(long nr, unsigned long *addr) return !!(old & mask); } +static inline int test_and_clear_bit(long nr, unsigned long *addr) +{ + unsigned long mask = BIT_MASK(nr); + long old; + + addr += BIT_WORD(nr); + + old = __sync_fetch_and_and(addr, ~mask); + return !!(old & mask); +} + #endif /* __TOOLS_ASM_GENERIC_ATOMIC_H */ |
