Skip to contentSkip to conversation

maple_tree: Reorganize testing to restore module testing

PATCH Superseded Liam Howlett 2 participants 3 messages Oct 28, 2022

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 maple_tree: Reorganize testing to restore module testing

Along the development cycle, the testing code support for module/in-kernel compiles was removed. Restore this functionality by moving any internal API tests to the userspace side, as well as threading tests. Fix the lockdep issues and add a way to reduce memory usage so the tests can complete with KASAN + memleak detection. Make the tests work on 32 bit hosts where possible and detect 32 bit hosts in the radix test suite.

v2 changes:
Fixed missing symbols with added exports
Added 32bit detection in userspace
Modified tests to work on 32bit hosts

---
 include/linux/maple_tree.h                    |     7 +
 lib/Kconfig.debug                             |     4 +
 lib/Makefile                                  |     1 +
 lib/maple_tree.c                              |    35 +-
 lib/test_maple_tree.c                         | 37931 +---------------
 tools/testing/radix-tree/.gitignore           |     1 +
 tools/testing/radix-tree/Makefile             |    19 +-
 tools/testing/radix-tree/generated/autoconf.h |     2 +-
 tools/testing/radix-tree/linux.c              |     4 +
 tools/testing/radix-tree/maple.c              | 35777 ++++++++++++++-
 10 files changed, 37030 insertions(+), 36751 deletions(-)
include/linux/maple_tree.h +7 -0
index 2effab72add1..e594db58a0f1 100644
@@ -638,6 +638,12 @@ static inline void mt_set_in_rcu(struct maple_tree *mt)
 	}
 }
 
+static inline unsigned int mt_height(const struct maple_tree *mt)
+
+{
+	return (mt->ma_flags & MT_FLAGS_HEIGHT_MASK) >> MT_FLAGS_HEIGHT_OFFSET;
+}
+
 void *mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max);
 void *mt_find_after(struct maple_tree *mt, unsigned long *index,
 		    unsigned long max);
@@ -664,6 +670,7 @@ extern atomic_t maple_tree_tests_passed;
 
 void mt_dump(const struct maple_tree *mt);
 void mt_validate(struct maple_tree *mt);
+void mt_cache_shrink(void);
 #define MT_BUG_ON(__tree, __x) do {					\
 	atomic_inc(&maple_tree_tests_run);				\
 	if (__x) {							\
lib/Kconfig.debug +4 -0
index 0129bee7de01..8e625758b440 100644
@@ -2229,6 +2229,10 @@ config TEST_UUID
 config TEST_XARRAY
 	tristate "Test the XArray code at runtime"
 
+config TEST_MAPLE_TREE
+	select DEBUG_MAPLE_TREE
+	tristate "Test the Maple Tree code at runtime"
+
 config TEST_RHASHTABLE
 	tristate "Perform selftest on resizable hash table"
 	help
lib/Makefile +1 -0
index 42e185cdecd0..fb4aa9e984af 100644
@@ -84,6 +84,7 @@ obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
 obj-$(CONFIG_TEST_STRSCPY) += test_strscpy.o
 obj-$(CONFIG_TEST_UUID) += test_uuid.o
 obj-$(CONFIG_TEST_XARRAY) += test_xarray.o
+obj-$(CONFIG_TEST_MAPLE_TREE) += test_maple_tree.o
 obj-$(CONFIG_TEST_PARMAN) += test_parman.o
 obj-$(CONFIG_TEST_KMOD) += test_kmod.o
 obj-$(CONFIG_TEST_DEBUG_VIRTUAL) += test_debug_virtual.o
lib/maple_tree.c +30 -5
index 5b7bef3044a8..4c79c36868d8 100644
@@ -183,10 +183,6 @@ static void ma_free_rcu(struct maple_node *node)
 	call_rcu(&node->rcu, mt_free_rcu);
 }
 
-static unsigned int mt_height(const struct maple_tree *mt)
-{
-	return (mt->ma_flags & MT_FLAGS_HEIGHT_MASK) >> MT_FLAGS_HEIGHT_OFFSET;
-}
 
 static void mas_set_height(struct ma_state *mas)
 {
@@ -5066,6 +5062,7 @@ void *mas_walk(struct ma_state *mas)
 
 	return entry;
 }
+EXPORT_SYMBOL_GPL(mas_walk);
 
 static inline bool mas_rewind_node(struct ma_state *mas)
 {
@@ -5277,6 +5274,7 @@ int mas_empty_area(struct ma_state *mas, unsigned long min,
 	mas->last = mas->index + size - 1;
 	return 0;
 }
+EXPORT_SYMBOL_GPL(mas_empty_area);
 
 /*
  * mas_empty_area_rev() - Get the highest address within the range that is
@@ -5340,6 +5338,7 @@ int mas_empty_area_rev(struct ma_state *mas, unsigned long min,
 	mas->index = mas->last - size + 1;
 	return 0;
 }
+EXPORT_SYMBOL_GPL(mas_empty_area_rev);
 
 static inline int mas_alloc(struct ma_state *mas, void *entry,
 		unsigned long size, unsigned long *index)
@@ -5661,6 +5660,7 @@ void *mas_store(struct ma_state *mas, void *entry)
 	mas_wr_store_entry(&wr_mas);
 	return wr_mas.content;
 }
+EXPORT_SYMBOL_GPL(mas_store);
 
 /**
  * mas_store_gfp() - Store a value into the tree.
@@ -5687,6 +5687,7 @@ int mas_store_gfp(struct ma_state *mas, void *entry, gfp_t gfp)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(mas_store_gfp);
 
 /**
  * mas_store_prealloc() - Store a value into the tree using memory
@@ -5704,6 +5705,7 @@ void mas_store_prealloc(struct ma_state *mas, void *entry)
 	BUG_ON(mas_is_err(mas));
 	mas_destroy(mas);
 }
+EXPORT_SYMBOL_GPL(mas_store_prealloc);
 
 /**
  * mas_preallocate() - Preallocate enough nodes for a store operation
@@ -5773,6 +5775,7 @@ void mas_destroy(struct ma_state *mas)
 	}
 	mas->alloc = NULL;
 }
+EXPORT_SYMBOL_GPL(mas_destroy);
 
 /*
  * mas_expected_entries() - Set the expected number of entries that will be inserted.
@@ -5834,6 +5837,7 @@ int mas_expected_entries(struct ma_state *mas, unsigned long nr_entries)
 	return ret;
 
 }
+EXPORT_SYMBOL_GPL(mas_expected_entries);
 
 /**
  * mas_next() - Get the next entry.
@@ -6543,8 +6547,27 @@ static inline int mas_dead_node(struct ma_state *mas, unsigned long index)
 	mas_rewalk(mas, index);
 	return 1;
 }
-#endif /* not defined __KERNEL__ */
 
+void mt_cache_shrink(void)
+{
+}
+#else
+/*
+ * mt_cache_shrink() - For testing, don't use this.
+ *
+ * Certain testcases can trigger an OOM when combined with other memory
+ * debugging configuration options.  This function is used to reduce the
+ * possibility of an out of memory even due to kmem_cache objects remaining
+ * around for longer than usual.
+ */
+void mt_cache_shrink(void)
+{
+	kmem_cache_shrink(maple_node_cache);
+
+}
+EXPORT_SYMBOL_GPL(mt_cache_shrink);
+
+#endif /* not defined __KERNEL__ */
 /*
  * mas_get_slot() - Get the entry in the maple state node stored at @offset.
  * @mas: The maple state
@@ -6818,6 +6841,7 @@ void mt_dump(const struct maple_tree *mt)
 	else if (entry)
 		mt_dump_node(mt, entry, 0, mt_max[mte_node_type(entry)], 0);
 }
+EXPORT_SYMBOL_GPL(mt_dump);
 
 /*
  * Calculate the maximum gap in a node and check if that's what is reported in
@@ -7128,5 +7152,6 @@ void mt_validate(struct maple_tree *mt)
 	rcu_read_unlock();
 
 }
+EXPORT_SYMBOL_GPL(mt_validate);
 
 #endif /* CONFIG_DEBUG_MAPLE_TREE */
lib/test_maple_tree.c +1192 -36739

2,857 lines not on this page · raw message

tools/testing/radix-tree/.gitignore +1 -0
index c901d96dd013..49bccb90c35b 100644

Lines of this file are not shown. View the raw message.

tools/testing/radix-tree/Makefile +16 -3
index 89d613e0505b..caf32a9b9608 100644

Lines of this file are not shown. View the raw message.

tools/testing/radix-tree/generated/autoconf.h +1 -1
index e7da80350236..92dc474c349b 100644

Lines of this file are not shown. View the raw message.

tools/testing/radix-tree/linux.c +4 -0
index 2048d12c31df..d587a558997f 100644

Lines of this file are not shown. View the raw message.

tools/testing/radix-tree/maple.c +35774 -3

35,777 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.35.1

Part of the diff is not shown here. View the raw message.

maintainer
#1 lore raw
Quoted 7 lines · On Fri, 28 Oct 2022 18:04:30 +0000 Liam Howlett <[email protected]> wrote:

Along the development cycle, the testing code support for module/in-kernel compiles was removed. Restore this functionality by moving any internal API tests to the userspace side, as well as threading tests. Fix the lockdep issues and add a way to reduce memory usage so the tests can complete with KASAN + memleak detection. Make the tests work on 32 bit hosts where possible and detect 32 bit hosts in the radix test suite.

My x86_64 allmodconfig failed with

ERROR: modpost: "mas_find_rev" [lib/test_maple_tree.ko] undefined!

so I did this:

lib/maple_tree.c renamed from lib/maple_tree.c~maple_tree-reorganize-testing-to-restore-module-testing-fix +1 -1
@@ -6059,7 +6059,7 @@ void *mas_find_rev(struct ma_state *mas,
 	/* Retries on dead nodes handled by mas_next_entry */
 	return mas_prev_entry(mas, min);
 }
-EXPORT_SYMBOL_GPL(mas_find);
+EXPORT_SYMBOL_GPL(mas_find_rev);
 
 /**
  * mas_erase() - Find the range in which index resides and erase the entire

_

#2 lore raw
Quoted 27 lines · Andrew Morton
Quoted 7 lines · On Fri, 28 Oct 2022 18:04:30 +0000 Liam Howlett <[email protected]> wrote:

Along the development cycle, the testing code support for module/in-kernel compiles was removed. Restore this functionality by moving any internal API tests to the userspace side, as well as threading tests. Fix the lockdep issues and add a way to reduce memory usage so the tests can complete with KASAN + memleak detection. Make the tests work on 32 bit hosts where possible and detect 32 bit hosts in the radix test suite.

My x86_64 allmodconfig failed with

ERROR: modpost: "mas_find_rev" [lib/test_maple_tree.ko] undefined!

so I did this:

lib/maple_tree.c renamed from lib/maple_tree.c~maple_tree-reorganize-testing-to-restore-module-testing-fix +1 -1
@@ -6059,7 +6059,7 @@ void *mas_find_rev(struct ma_state *mas,
 	/* Retries on dead nodes handled by mas_next_entry */
 	return mas_prev_entry(mas, min);
 }
-EXPORT_SYMBOL_GPL(mas_find);
+EXPORT_SYMBOL_GPL(mas_find_rev);
 
 /**
  * mas_erase() - Find the range in which index resides and erase the entire
Quoted 2 lines

_

Thanks. It looks like I missed this in my squashing of commits.

Sorry about that.
Liam