Skip to content

Commit

Permalink
maple_tree: reorganize testing to restore module testing
Browse files Browse the repository at this point in the history
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.

Link: https://lkml.kernel.org/r/20221028180415.3074673-1-Liam.Howlett@oracle.com
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
howlett authored and akpm00 committed Oct 28, 2022
1 parent a87d0d7 commit d9c0ca7
Show file tree
Hide file tree
Showing 10 changed files with 37,030 additions and 36,751 deletions.
7 changes: 7 additions & 0 deletions include/linux/maple_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) { \
Expand Down
4 changes: 4 additions & 0 deletions lib/Kconfig.debug
Original file line number Diff line number Diff line change
Expand Up @@ -2241,6 +2241,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
Expand Down
1 change: 1 addition & 0 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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
Expand Down
35 changes: 30 additions & 5 deletions lib/maple_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -5061,6 +5057,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)
{
Expand Down Expand Up @@ -5272,6 +5269,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
Expand Down Expand Up @@ -5335,6 +5333,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)
Expand Down Expand Up @@ -5656,6 +5655,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.
Expand All @@ -5682,6 +5682,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
Expand All @@ -5699,6 +5700,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
Expand Down Expand Up @@ -5768,6 +5770,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.
Expand Down Expand Up @@ -5829,6 +5832,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.
Expand Down Expand Up @@ -6537,8 +6541,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
Expand Down Expand Up @@ -6812,6 +6835,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
Expand Down Expand Up @@ -7122,5 +7146,6 @@ void mt_validate(struct maple_tree *mt)
rcu_read_unlock();

}
EXPORT_SYMBOL_GPL(mt_validate);

#endif /* CONFIG_DEBUG_MAPLE_TREE */

0 comments on commit d9c0ca7

Please sign in to comment.