From 74579d8dab476b66cd28715e73832ab777f20984 Mon Sep 17 00:00:00 2001 From: Lorenzo Stoakes Date: Mon, 29 Jul 2024 12:50:40 +0100 Subject: tools: separate out shared radix-tree components The core components contained within the radix-tree tests which provide shims for kernel headers and access to the maple tree are useful for testing other things, so separate them out and make the radix tree tests dependent on the shared components. This lays the groundwork for us to add VMA tests of the newly introduced vma.c file. Link: https://lkml.kernel.org/r/1ee720c265808168e0d75608e687607d77c36719.1722251717.git.lorenzo.stoakes@oracle.com Signed-off-by: Lorenzo Stoakes Acked-by: Vlastimil Babka Reviewed-by: Liam R. Howlett Cc: Alexander Viro Cc: Brendan Higgins Cc: Christian Brauner Cc: David Gow Cc: Eric W. Biederman Cc: Jan Kara Cc: Kees Cook Cc: Matthew Wilcox (Oracle) Cc: Rae Moar Cc: SeongJae Park Cc: Shuah Khan Cc: Suren Baghdasaryan Cc: Pengfei Xu Signed-off-by: Andrew Morton --- tools/testing/shared/linux/bug.h | 2 ++ tools/testing/shared/linux/cpu.h | 1 + tools/testing/shared/linux/idr.h | 1 + tools/testing/shared/linux/init.h | 2 ++ tools/testing/shared/linux/kconfig.h | 1 + tools/testing/shared/linux/kernel.h | 29 +++++++++++++++++++++++++++++ tools/testing/shared/linux/kmemleak.h | 1 + tools/testing/shared/linux/local_lock.h | 8 ++++++++ tools/testing/shared/linux/lockdep.h | 16 ++++++++++++++++ tools/testing/shared/linux/maple_tree.h | 7 +++++++ tools/testing/shared/linux/percpu.h | 11 +++++++++++ tools/testing/shared/linux/preempt.h | 15 +++++++++++++++ tools/testing/shared/linux/radix-tree.h | 26 ++++++++++++++++++++++++++ tools/testing/shared/linux/rcupdate.h | 12 ++++++++++++ tools/testing/shared/linux/xarray.h | 2 ++ 15 files changed, 134 insertions(+) create mode 100644 tools/testing/shared/linux/bug.h create mode 100644 tools/testing/shared/linux/cpu.h create mode 100644 tools/testing/shared/linux/idr.h create mode 100644 tools/testing/shared/linux/init.h create mode 100644 tools/testing/shared/linux/kconfig.h create mode 100644 tools/testing/shared/linux/kernel.h create mode 100644 tools/testing/shared/linux/kmemleak.h create mode 100644 tools/testing/shared/linux/local_lock.h create mode 100644 tools/testing/shared/linux/lockdep.h create mode 100644 tools/testing/shared/linux/maple_tree.h create mode 100644 tools/testing/shared/linux/percpu.h create mode 100644 tools/testing/shared/linux/preempt.h create mode 100644 tools/testing/shared/linux/radix-tree.h create mode 100644 tools/testing/shared/linux/rcupdate.h create mode 100644 tools/testing/shared/linux/xarray.h (limited to 'tools/testing/shared/linux') diff --git a/tools/testing/shared/linux/bug.h b/tools/testing/shared/linux/bug.h new file mode 100644 index 000000000000..03dc8a57eb99 --- /dev/null +++ b/tools/testing/shared/linux/bug.h @@ -0,0 +1,2 @@ +#include +#include "asm/bug.h" diff --git a/tools/testing/shared/linux/cpu.h b/tools/testing/shared/linux/cpu.h new file mode 100644 index 000000000000..a45530d78107 --- /dev/null +++ b/tools/testing/shared/linux/cpu.h @@ -0,0 +1 @@ +#define cpuhp_setup_state_nocalls(a, b, c, d) (0) diff --git a/tools/testing/shared/linux/idr.h b/tools/testing/shared/linux/idr.h new file mode 100644 index 000000000000..4e342f2e37cf --- /dev/null +++ b/tools/testing/shared/linux/idr.h @@ -0,0 +1 @@ +#include "../../../../include/linux/idr.h" diff --git a/tools/testing/shared/linux/init.h b/tools/testing/shared/linux/init.h new file mode 100644 index 000000000000..81563c3dfce7 --- /dev/null +++ b/tools/testing/shared/linux/init.h @@ -0,0 +1,2 @@ +#define __init +#define __exit diff --git a/tools/testing/shared/linux/kconfig.h b/tools/testing/shared/linux/kconfig.h new file mode 100644 index 000000000000..6c8675859913 --- /dev/null +++ b/tools/testing/shared/linux/kconfig.h @@ -0,0 +1 @@ +#include "../../../../include/linux/kconfig.h" diff --git a/tools/testing/shared/linux/kernel.h b/tools/testing/shared/linux/kernel.h new file mode 100644 index 000000000000..c0a2bb785b92 --- /dev/null +++ b/tools/testing/shared/linux/kernel.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _KERNEL_H +#define _KERNEL_H + +#include "../../include/linux/kernel.h" +#include +#include +#include + +#include +#include +#include +#include +#include "../../../include/linux/kconfig.h" + +#define printk printf +#define pr_err printk +#define pr_info printk +#define pr_debug printk +#define pr_cont printk +#define schedule() +#define PAGE_SHIFT 12 + +#define __acquires(x) +#define __releases(x) +#define __must_hold(x) + +#define EXPORT_PER_CPU_SYMBOL_GPL(x) +#endif /* _KERNEL_H */ diff --git a/tools/testing/shared/linux/kmemleak.h b/tools/testing/shared/linux/kmemleak.h new file mode 100644 index 000000000000..155f112786c4 --- /dev/null +++ b/tools/testing/shared/linux/kmemleak.h @@ -0,0 +1 @@ +static inline void kmemleak_update_trace(const void *ptr) { } diff --git a/tools/testing/shared/linux/local_lock.h b/tools/testing/shared/linux/local_lock.h new file mode 100644 index 000000000000..b3cf8b233ca4 --- /dev/null +++ b/tools/testing/shared/linux/local_lock.h @@ -0,0 +1,8 @@ +#ifndef _LINUX_LOCAL_LOCK +#define _LINUX_LOCAL_LOCK +typedef struct { } local_lock_t; + +static inline void local_lock(local_lock_t *lock) { } +static inline void local_unlock(local_lock_t *lock) { } +#define INIT_LOCAL_LOCK(x) { } +#endif diff --git a/tools/testing/shared/linux/lockdep.h b/tools/testing/shared/linux/lockdep.h new file mode 100644 index 000000000000..62473ab57f99 --- /dev/null +++ b/tools/testing/shared/linux/lockdep.h @@ -0,0 +1,16 @@ +#ifndef _LINUX_LOCKDEP_H +#define _LINUX_LOCKDEP_H + +#include + +struct lock_class_key { + unsigned int a; +}; + +static inline void lockdep_set_class(spinlock_t *lock, + struct lock_class_key *key) +{ +} + +extern int lockdep_is_held(const void *); +#endif /* _LINUX_LOCKDEP_H */ diff --git a/tools/testing/shared/linux/maple_tree.h b/tools/testing/shared/linux/maple_tree.h new file mode 100644 index 000000000000..06c89bdcc515 --- /dev/null +++ b/tools/testing/shared/linux/maple_tree.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +#define atomic_t int32_t +#define atomic_inc(x) uatomic_inc(x) +#define atomic_read(x) uatomic_read(x) +#define atomic_set(x, y) do {} while (0) +#define U8_MAX UCHAR_MAX +#include "../../../../include/linux/maple_tree.h" diff --git a/tools/testing/shared/linux/percpu.h b/tools/testing/shared/linux/percpu.h new file mode 100644 index 000000000000..b2403aa743b2 --- /dev/null +++ b/tools/testing/shared/linux/percpu.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#define DECLARE_PER_CPU(type, val) extern type val +#define DEFINE_PER_CPU(type, val) type val + +#define __get_cpu_var(var) var +#define this_cpu_ptr(var) var +#define this_cpu_read(var) var +#define this_cpu_xchg(var, val) uatomic_xchg(&var, val) +#define this_cpu_cmpxchg(var, old, new) uatomic_cmpxchg(&var, old, new) +#define per_cpu_ptr(ptr, cpu) ({ (void)(cpu); (ptr); }) +#define per_cpu(var, cpu) (*per_cpu_ptr(&(var), cpu)) diff --git a/tools/testing/shared/linux/preempt.h b/tools/testing/shared/linux/preempt.h new file mode 100644 index 000000000000..edb10302b903 --- /dev/null +++ b/tools/testing/shared/linux/preempt.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_PREEMPT_H +#define __LINUX_PREEMPT_H + +extern int preempt_count; + +#define preempt_disable() uatomic_inc(&preempt_count) +#define preempt_enable() uatomic_dec(&preempt_count) + +static inline int in_interrupt(void) +{ + return 0; +} + +#endif /* __LINUX_PREEMPT_H */ diff --git a/tools/testing/shared/linux/radix-tree.h b/tools/testing/shared/linux/radix-tree.h new file mode 100644 index 000000000000..d1635a5bef02 --- /dev/null +++ b/tools/testing/shared/linux/radix-tree.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TEST_RADIX_TREE_H +#define _TEST_RADIX_TREE_H + +#include "../../../../include/linux/radix-tree.h" + +extern int kmalloc_verbose; +extern int test_verbose; + +static inline void trace_call_rcu(struct rcu_head *head, + void (*func)(struct rcu_head *head)) +{ + if (kmalloc_verbose) + printf("Delaying free of %p to slab\n", (char *)head - + offsetof(struct radix_tree_node, rcu_head)); + call_rcu(head, func); +} + +#define printv(verbosity_level, fmt, ...) \ + if(test_verbose >= verbosity_level) \ + printf(fmt, ##__VA_ARGS__) + +#undef call_rcu +#define call_rcu(x, y) trace_call_rcu(x, y) + +#endif /* _TEST_RADIX_TREE_H */ diff --git a/tools/testing/shared/linux/rcupdate.h b/tools/testing/shared/linux/rcupdate.h new file mode 100644 index 000000000000..fed468fb0c78 --- /dev/null +++ b/tools/testing/shared/linux/rcupdate.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _RCUPDATE_H +#define _RCUPDATE_H + +#include + +#define rcu_dereference_raw(p) rcu_dereference(p) +#define rcu_dereference_protected(p, cond) rcu_dereference(p) +#define rcu_dereference_check(p, cond) rcu_dereference(p) +#define RCU_INIT_POINTER(p, v) do { (p) = (v); } while (0) + +#endif diff --git a/tools/testing/shared/linux/xarray.h b/tools/testing/shared/linux/xarray.h new file mode 100644 index 000000000000..df3812cda376 --- /dev/null +++ b/tools/testing/shared/linux/xarray.h @@ -0,0 +1,2 @@ +#include "generated/map-shift.h" +#include "../../../../include/linux/xarray.h" -- cgit v1.2.3