mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	lib/test_meminit: add a kmem_cache_alloc_bulk() test
Make sure allocations from kmem_cache_alloc_bulk() and kmem_cache_free_bulk() are properly initialized. Link: http://lkml.kernel.org/r/20191007091605.30530-2-glider@google.com Signed-off-by: Alexander Potapenko <glider@google.com> Cc: Kees Cook <keescook@chromium.org> Cc: Christoph Lameter <cl@linux.com> Cc: Laura Abbott <labbott@redhat.com> Cc: Thibaut Sautereau <thibaut@sautereau.fr> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									0f181f9fbe
								
							
						
					
					
						commit
						03a9349ac0
					
				
					 1 changed files with 27 additions and 0 deletions
				
			
		| 
						 | 
					@ -297,6 +297,32 @@ static int __init do_kmem_cache_rcu_persistent(int size, int *total_failures)
 | 
				
			||||||
	return 1;
 | 
						return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int __init do_kmem_cache_size_bulk(int size, int *total_failures)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct kmem_cache *c;
 | 
				
			||||||
 | 
						int i, iter, maxiter = 1024;
 | 
				
			||||||
 | 
						int num, bytes;
 | 
				
			||||||
 | 
						bool fail = false;
 | 
				
			||||||
 | 
						void *objects[10];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						c = kmem_cache_create("test_cache", size, size, 0, NULL);
 | 
				
			||||||
 | 
						for (iter = 0; (iter < maxiter) && !fail; iter++) {
 | 
				
			||||||
 | 
							num = kmem_cache_alloc_bulk(c, GFP_KERNEL, ARRAY_SIZE(objects),
 | 
				
			||||||
 | 
										    objects);
 | 
				
			||||||
 | 
							for (i = 0; i < num; i++) {
 | 
				
			||||||
 | 
								bytes = count_nonzero_bytes(objects[i], size);
 | 
				
			||||||
 | 
								if (bytes)
 | 
				
			||||||
 | 
									fail = true;
 | 
				
			||||||
 | 
								fill_with_garbage(objects[i], size);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (num)
 | 
				
			||||||
 | 
								kmem_cache_free_bulk(c, num, objects);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						*total_failures += fail;
 | 
				
			||||||
 | 
						return 1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Test kmem_cache allocation by creating caches of different sizes, with and
 | 
					 * Test kmem_cache allocation by creating caches of different sizes, with and
 | 
				
			||||||
 * without constructors, with and without SLAB_TYPESAFE_BY_RCU.
 | 
					 * without constructors, with and without SLAB_TYPESAFE_BY_RCU.
 | 
				
			||||||
| 
						 | 
					@ -318,6 +344,7 @@ static int __init test_kmemcache(int *total_failures)
 | 
				
			||||||
			num_tests += do_kmem_cache_size(size, ctor, rcu, zero,
 | 
								num_tests += do_kmem_cache_size(size, ctor, rcu, zero,
 | 
				
			||||||
							&failures);
 | 
												&failures);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							num_tests += do_kmem_cache_size_bulk(size, &failures);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	REPORT_FAILURES_IN_FN();
 | 
						REPORT_FAILURES_IN_FN();
 | 
				
			||||||
	*total_failures += failures;
 | 
						*total_failures += failures;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue