Skip to content

Commit 120b116

Browse files
howlettakpm00
authored andcommitted
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. [[email protected]: fix module export] [[email protected]: fix it some more] [[email protected]: fix compile warnings on 32bit build in check_find()] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Liam R. Howlett <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 9a88787 commit 120b116

File tree

10 files changed

+37029
-36743
lines changed

10 files changed

+37029
-36743
lines changed

include/linux/maple_tree.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,12 @@ static inline void mt_set_in_rcu(struct maple_tree *mt)
638638
}
639639
}
640640

641+
static inline unsigned int mt_height(const struct maple_tree *mt)
642+
643+
{
644+
return (mt->ma_flags & MT_FLAGS_HEIGHT_MASK) >> MT_FLAGS_HEIGHT_OFFSET;
645+
}
646+
641647
void *mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max);
642648
void *mt_find_after(struct maple_tree *mt, unsigned long *index,
643649
unsigned long max);
@@ -664,6 +670,7 @@ extern atomic_t maple_tree_tests_passed;
664670

665671
void mt_dump(const struct maple_tree *mt);
666672
void mt_validate(struct maple_tree *mt);
673+
void mt_cache_shrink(void);
667674
#define MT_BUG_ON(__tree, __x) do { \
668675
atomic_inc(&maple_tree_tests_run); \
669676
if (__x) { \

lib/Kconfig.debug

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,6 +2241,10 @@ config TEST_UUID
22412241
config TEST_XARRAY
22422242
tristate "Test the XArray code at runtime"
22432243

2244+
config TEST_MAPLE_TREE
2245+
select DEBUG_MAPLE_TREE
2246+
tristate "Test the Maple Tree code at runtime"
2247+
22442248
config TEST_RHASHTABLE
22452249
tristate "Perform selftest on resizable hash table"
22462250
help

lib/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
8585
obj-$(CONFIG_TEST_STRSCPY) += test_strscpy.o
8686
obj-$(CONFIG_TEST_UUID) += test_uuid.o
8787
obj-$(CONFIG_TEST_XARRAY) += test_xarray.o
88+
obj-$(CONFIG_TEST_MAPLE_TREE) += test_maple_tree.o
8889
obj-$(CONFIG_TEST_PARMAN) += test_parman.o
8990
obj-$(CONFIG_TEST_KMOD) += test_kmod.o
9091
obj-$(CONFIG_TEST_DEBUG_VIRTUAL) += test_debug_virtual.o

lib/maple_tree.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ static void ma_free_rcu(struct maple_node *node)
183183
call_rcu(&node->rcu, mt_free_rcu);
184184
}
185185

186-
static unsigned int mt_height(const struct maple_tree *mt)
187-
{
188-
return (mt->ma_flags & MT_FLAGS_HEIGHT_MASK) >> MT_FLAGS_HEIGHT_OFFSET;
189-
}
190186

191187
static void mas_set_height(struct ma_state *mas)
192188
{
@@ -5061,6 +5057,7 @@ void *mas_walk(struct ma_state *mas)
50615057

50625058
return entry;
50635059
}
5060+
EXPORT_SYMBOL_GPL(mas_walk);
50645061

50655062
static inline bool mas_rewind_node(struct ma_state *mas)
50665063
{
@@ -5272,6 +5269,7 @@ int mas_empty_area(struct ma_state *mas, unsigned long min,
52725269
mas->last = mas->index + size - 1;
52735270
return 0;
52745271
}
5272+
EXPORT_SYMBOL_GPL(mas_empty_area);
52755273

52765274
/*
52775275
* mas_empty_area_rev() - Get the highest address within the range that is
@@ -5335,6 +5333,7 @@ int mas_empty_area_rev(struct ma_state *mas, unsigned long min,
53355333
mas->index = mas->last - size + 1;
53365334
return 0;
53375335
}
5336+
EXPORT_SYMBOL_GPL(mas_empty_area_rev);
53385337

53395338
static inline int mas_alloc(struct ma_state *mas, void *entry,
53405339
unsigned long size, unsigned long *index)
@@ -5656,6 +5655,7 @@ void *mas_store(struct ma_state *mas, void *entry)
56565655
mas_wr_store_entry(&wr_mas);
56575656
return wr_mas.content;
56585657
}
5658+
EXPORT_SYMBOL_GPL(mas_store);
56595659

56605660
/**
56615661
* mas_store_gfp() - Store a value into the tree.
@@ -5682,6 +5682,7 @@ int mas_store_gfp(struct ma_state *mas, void *entry, gfp_t gfp)
56825682

56835683
return 0;
56845684
}
5685+
EXPORT_SYMBOL_GPL(mas_store_gfp);
56855686

56865687
/**
56875688
* mas_store_prealloc() - Store a value into the tree using memory
@@ -5699,6 +5700,7 @@ void mas_store_prealloc(struct ma_state *mas, void *entry)
56995700
BUG_ON(mas_is_err(mas));
57005701
mas_destroy(mas);
57015702
}
5703+
EXPORT_SYMBOL_GPL(mas_store_prealloc);
57025704

57035705
/**
57045706
* mas_preallocate() - Preallocate enough nodes for a store operation
@@ -5768,6 +5770,7 @@ void mas_destroy(struct ma_state *mas)
57685770
}
57695771
mas->alloc = NULL;
57705772
}
5773+
EXPORT_SYMBOL_GPL(mas_destroy);
57715774

57725775
/*
57735776
* mas_expected_entries() - Set the expected number of entries that will be inserted.
@@ -5829,6 +5832,7 @@ int mas_expected_entries(struct ma_state *mas, unsigned long nr_entries)
58295832
return ret;
58305833

58315834
}
5835+
EXPORT_SYMBOL_GPL(mas_expected_entries);
58325836

58335837
/**
58345838
* mas_next() - Get the next entry.
@@ -6009,6 +6013,7 @@ void *mas_find(struct ma_state *mas, unsigned long max)
60096013
/* Retries on dead nodes handled by mas_next_entry */
60106014
return mas_next_entry(mas, max);
60116015
}
6016+
EXPORT_SYMBOL_GPL(mas_find);
60126017

60136018
/**
60146019
* mas_find_rev: On the first call, find the first non-null entry at or below
@@ -6055,7 +6060,7 @@ void *mas_find_rev(struct ma_state *mas, unsigned long min)
60556060
/* Retries on dead nodes handled by mas_next_entry */
60566061
return mas_prev_entry(mas, min);
60576062
}
6058-
EXPORT_SYMBOL_GPL(mas_find);
6063+
EXPORT_SYMBOL_GPL(mas_find_rev);
60596064

60606065
/**
60616066
* mas_erase() - Find the range in which index resides and erase the entire
@@ -6537,8 +6542,27 @@ static inline int mas_dead_node(struct ma_state *mas, unsigned long index)
65376542
mas_rewalk(mas, index);
65386543
return 1;
65396544
}
6540-
#endif /* not defined __KERNEL__ */
65416545

6546+
void mt_cache_shrink(void)
6547+
{
6548+
}
6549+
#else
6550+
/*
6551+
* mt_cache_shrink() - For testing, don't use this.
6552+
*
6553+
* Certain testcases can trigger an OOM when combined with other memory
6554+
* debugging configuration options. This function is used to reduce the
6555+
* possibility of an out of memory even due to kmem_cache objects remaining
6556+
* around for longer than usual.
6557+
*/
6558+
void mt_cache_shrink(void)
6559+
{
6560+
kmem_cache_shrink(maple_node_cache);
6561+
6562+
}
6563+
EXPORT_SYMBOL_GPL(mt_cache_shrink);
6564+
6565+
#endif /* not defined __KERNEL__ */
65426566
/*
65436567
* mas_get_slot() - Get the entry in the maple state node stored at @offset.
65446568
* @mas: The maple state
@@ -6812,6 +6836,7 @@ void mt_dump(const struct maple_tree *mt)
68126836
else if (entry)
68136837
mt_dump_node(mt, entry, 0, mt_max[mte_node_type(entry)], 0);
68146838
}
6839+
EXPORT_SYMBOL_GPL(mt_dump);
68156840

68166841
/*
68176842
* Calculate the maximum gap in a node and check if that's what is reported in
@@ -7122,5 +7147,6 @@ void mt_validate(struct maple_tree *mt)
71227147
rcu_read_unlock();
71237148

71247149
}
7150+
EXPORT_SYMBOL_GPL(mt_validate);
71257151

71267152
#endif /* CONFIG_DEBUG_MAPLE_TREE */

0 commit comments

Comments
 (0)