forked from mirrors/linux
		
	slab: Warn on duplicate cache names when DEBUG_VM=y
Duplicate slab cache names can create havoc for userspace tooling that expects slab cache names to be unique [1]. This is a reasonable expectation. Sadly, too many duplicate name problems are out there in the wild, so simply warn instead of pr_err() + failing the sanity check. [ vbabka@suse.cz: change to WARN_ON(), see the discussion at [2] ] Link: https://lore.kernel.org/linux-fsdevel/2d1d053da1cafb3e7940c4f25952da4f0af34e38.1722293276.git.osandov@fb.com/ [1] Link: https://lore.kernel.org/all/20240807090746.2146479-1-pedro.falcato@gmail.com/ [2] Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com> Acked-by: Christoph Lameter <cl@linux.com> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
This commit is contained in:
		
							parent
							
								
									5be63fc19f
								
							
						
					
					
						commit
						4c39529663
					
				
					 1 changed files with 17 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -88,6 +88,19 @@ unsigned int kmem_cache_size(struct kmem_cache *s)
 | 
			
		|||
EXPORT_SYMBOL(kmem_cache_size);
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_DEBUG_VM
 | 
			
		||||
 | 
			
		||||
static bool kmem_cache_is_duplicate_name(const char *name)
 | 
			
		||||
{
 | 
			
		||||
	struct kmem_cache *s;
 | 
			
		||||
 | 
			
		||||
	list_for_each_entry(s, &slab_caches, list) {
 | 
			
		||||
		if (!strcmp(s->name, name))
 | 
			
		||||
			return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int kmem_cache_sanity_check(const char *name, unsigned int size)
 | 
			
		||||
{
 | 
			
		||||
	if (!name || in_interrupt() || size > KMALLOC_MAX_SIZE) {
 | 
			
		||||
| 
						 | 
				
			
			@ -95,6 +108,10 @@ static int kmem_cache_sanity_check(const char *name, unsigned int size)
 | 
			
		|||
		return -EINVAL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* Duplicate names will confuse slabtop, et al */
 | 
			
		||||
	WARN(kmem_cache_is_duplicate_name(name),
 | 
			
		||||
			"kmem_cache of name '%s' already exists\n", name);
 | 
			
		||||
 | 
			
		||||
	WARN_ON(strchr(name, ' '));	/* It confuses parsers */
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue