mirror-linux/tools/include
Brendan Jackman ff0db419b2 tools/include: implement a couple of atomic_t ops
Patch series "tools: testing: Use existing atomic.h for vma/maple tests",
v2.

De-duplicating this lets us delete a bit of code. 

Ulterior motive: I'm working on a new set of the userspace-based unit
tests, which will need the atomics API too.  That would involve even more
duplication, so while the win in this patchset alone is very minimal, it
looks a lot more significant with my other WIP patchset.

I've tested these commands:

make -C tools/testing/vma -j 
tools/testing/vma/vma

make -C tools/testing/radix-tree -j
tools/testing/radix-tree/maple

Note the EXTRA_CFLAGS patch is actually orthogonal, let me know if you'd
prefer I send it separately.


This patch (of 4):

The VMA tests need an operation equivalent to atomic_inc_unless_negative()
to implement a fake mapping_map_writable().  Adding it will enable them to
switch to the shared atomic headers and simplify that fake implementation.

In order to add that, also add atomic_try_cmpxchg() which can be used to
implement it.  This is copied from Documentation/atomic_t.txt.  Then,
implement atomic_inc_unless_negative() itself based on the
raw_atomic_dec_unless_positive() in
include/linux/atomic/atomic-arch-fallback.h.

There's no present need for a highly-optimised version of this (nor any
reason to think this implementation is sub-optimal on x86) so just
implement this with generic C, no x86-specifics.

Link: https://lkml.kernel.org/r/20250828-b4-vma-no-atomic-h-v2-0-02d146a58ed2@google.com
Link: https://lkml.kernel.org/r/20250828-b4-vma-no-atomic-h-v2-1-02d146a58ed2@google.com
Signed-off-by: Brendan Jackman <jackmanb@google.com>
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
Cc: Jann Horn <jannh@google.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2025-09-13 16:55:24 -07:00
..
asm lib/rbtree: enable userland test suite for rbtree related data structure 2025-03-17 12:17:00 -07:00
asm-generic move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
generated selftests: vDSO: don't include generated headers for chacha test 2024-09-13 17:28:36 +02:00
io_uring selftests/net: Extract uring helpers to be reusable 2023-10-19 16:42:03 -06:00
linux tools/include: implement a couple of atomic_t ops 2025-09-13 16:55:24 -07:00
nolibc tools/nolibc: define time_t in terms of __kernel_old_time_t 2025-07-13 16:58:34 +02:00
perf KVM: selftests: aarch64: Update tools copy of arm_pmuv3.h 2023-12-12 09:46:22 +00:00
tools
trace/events
uapi tools headers: Sync syscall tables with the kernel source 2025-08-18 13:49:25 -07:00
vdso tools headers: Sync the linux/unaligned.h copy with the kernel sources 2025-05-20 12:57:18 -03:00