forked from mirrors/linux
		
	kunit, slub: add test_kfree_rcu() and test_leak_destroy()
Add a test that will create cache, allocate one object, kfree_rcu() it and attempt to destroy it. As long as the usage of kvfree_rcu_barrier() in kmem_cache_destroy() works correctly, there should be no warnings in dmesg and the test should pass. Additionally add a test_leak_destroy() test that leaks an object on purpose and verifies that kmem_cache_destroy() catches it. Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
This commit is contained in:
		
							parent
							
								
									6c6c47b063
								
							
						
					
					
						commit
						4e1c44b3db
					
				
					 1 changed files with 31 additions and 0 deletions
				
			
		|  | @ -5,6 +5,7 @@ | ||||||
| #include <linux/slab.h> | #include <linux/slab.h> | ||||||
| #include <linux/module.h> | #include <linux/module.h> | ||||||
| #include <linux/kernel.h> | #include <linux/kernel.h> | ||||||
|  | #include <linux/rcupdate.h> | ||||||
| #include "../mm/slab.h" | #include "../mm/slab.h" | ||||||
| 
 | 
 | ||||||
| static struct kunit_resource resource; | static struct kunit_resource resource; | ||||||
|  | @ -157,6 +158,34 @@ static void test_kmalloc_redzone_access(struct kunit *test) | ||||||
| 	kmem_cache_destroy(s); | 	kmem_cache_destroy(s); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | struct test_kfree_rcu_struct { | ||||||
|  | 	struct rcu_head rcu; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | static void test_kfree_rcu(struct kunit *test) | ||||||
|  | { | ||||||
|  | 	struct kmem_cache *s = test_kmem_cache_create("TestSlub_kfree_rcu", | ||||||
|  | 				sizeof(struct test_kfree_rcu_struct), | ||||||
|  | 				SLAB_NO_MERGE); | ||||||
|  | 	struct test_kfree_rcu_struct *p = kmem_cache_alloc(s, GFP_KERNEL); | ||||||
|  | 
 | ||||||
|  | 	kfree_rcu(p, rcu); | ||||||
|  | 	kmem_cache_destroy(s); | ||||||
|  | 
 | ||||||
|  | 	KUNIT_EXPECT_EQ(test, 0, slab_errors); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void test_leak_destroy(struct kunit *test) | ||||||
|  | { | ||||||
|  | 	struct kmem_cache *s = test_kmem_cache_create("TestSlub_kfree_rcu", | ||||||
|  | 							64, SLAB_NO_MERGE); | ||||||
|  | 	kmem_cache_alloc(s, GFP_KERNEL); | ||||||
|  | 
 | ||||||
|  | 	kmem_cache_destroy(s); | ||||||
|  | 
 | ||||||
|  | 	KUNIT_EXPECT_EQ(test, 1, slab_errors); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static int test_init(struct kunit *test) | static int test_init(struct kunit *test) | ||||||
| { | { | ||||||
| 	slab_errors = 0; | 	slab_errors = 0; | ||||||
|  | @ -177,6 +206,8 @@ static struct kunit_case test_cases[] = { | ||||||
| 
 | 
 | ||||||
| 	KUNIT_CASE(test_clobber_redzone_free), | 	KUNIT_CASE(test_clobber_redzone_free), | ||||||
| 	KUNIT_CASE(test_kmalloc_redzone_access), | 	KUNIT_CASE(test_kmalloc_redzone_access), | ||||||
|  | 	KUNIT_CASE(test_kfree_rcu), | ||||||
|  | 	KUNIT_CASE(test_leak_destroy), | ||||||
| 	{} | 	{} | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Vlastimil Babka
						Vlastimil Babka