mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	init_on_alloc: Optimize static branches
The state of CONFIG_INIT_ON_ALLOC_DEFAULT_ON (and ...ON_FREE...) did not change the assembly ordering of the static branches: they were always out of line. Use the new jump_label macros to check the CONFIG settings to default to the "expected" state, which slightly optimizes the resulting assembly code. Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Alexander Potapenko <glider@google.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> Link: https://lore.kernel.org/r/20210401232347.2791257-3-keescook@chromium.org
This commit is contained in:
		
							parent
							
								
									0d66ccc162
								
							
						
					
					
						commit
						51cba1ebc6
					
				
					 3 changed files with 12 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -2904,18 +2904,20 @@ static inline void kernel_poison_pages(struct page *page, int numpages) { }
 | 
			
		|||
static inline void kernel_unpoison_pages(struct page *page, int numpages) { }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
DECLARE_STATIC_KEY_FALSE(init_on_alloc);
 | 
			
		||||
DECLARE_STATIC_KEY_MAYBE(CONFIG_INIT_ON_ALLOC_DEFAULT_ON, init_on_alloc);
 | 
			
		||||
static inline bool want_init_on_alloc(gfp_t flags)
 | 
			
		||||
{
 | 
			
		||||
	if (static_branch_unlikely(&init_on_alloc))
 | 
			
		||||
	if (static_branch_maybe(CONFIG_INIT_ON_ALLOC_DEFAULT_ON,
 | 
			
		||||
				&init_on_alloc))
 | 
			
		||||
		return true;
 | 
			
		||||
	return flags & __GFP_ZERO;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
DECLARE_STATIC_KEY_FALSE(init_on_free);
 | 
			
		||||
DECLARE_STATIC_KEY_MAYBE(CONFIG_INIT_ON_FREE_DEFAULT_ON, init_on_free);
 | 
			
		||||
static inline bool want_init_on_free(void)
 | 
			
		||||
{
 | 
			
		||||
	return static_branch_unlikely(&init_on_free);
 | 
			
		||||
	return static_branch_maybe(CONFIG_INIT_ON_FREE_DEFAULT_ON,
 | 
			
		||||
				   &init_on_free);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern bool _debug_pagealloc_enabled_early;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -167,10 +167,10 @@ unsigned long totalcma_pages __read_mostly;
 | 
			
		|||
 | 
			
		||||
int percpu_pagelist_fraction;
 | 
			
		||||
gfp_t gfp_allowed_mask __read_mostly = GFP_BOOT_MASK;
 | 
			
		||||
DEFINE_STATIC_KEY_FALSE(init_on_alloc);
 | 
			
		||||
DEFINE_STATIC_KEY_MAYBE(CONFIG_INIT_ON_ALLOC_DEFAULT_ON, init_on_alloc);
 | 
			
		||||
EXPORT_SYMBOL(init_on_alloc);
 | 
			
		||||
 | 
			
		||||
DEFINE_STATIC_KEY_FALSE(init_on_free);
 | 
			
		||||
DEFINE_STATIC_KEY_MAYBE(CONFIG_INIT_ON_FREE_DEFAULT_ON, init_on_free);
 | 
			
		||||
EXPORT_SYMBOL(init_on_free);
 | 
			
		||||
 | 
			
		||||
static bool _init_on_alloc_enabled_early __read_mostly
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -601,7 +601,8 @@ static inline void cache_random_seq_destroy(struct kmem_cache *cachep) { }
 | 
			
		|||
 | 
			
		||||
static inline bool slab_want_init_on_alloc(gfp_t flags, struct kmem_cache *c)
 | 
			
		||||
{
 | 
			
		||||
	if (static_branch_unlikely(&init_on_alloc)) {
 | 
			
		||||
	if (static_branch_maybe(CONFIG_INIT_ON_ALLOC_DEFAULT_ON,
 | 
			
		||||
				&init_on_alloc)) {
 | 
			
		||||
		if (c->ctor)
 | 
			
		||||
			return false;
 | 
			
		||||
		if (c->flags & (SLAB_TYPESAFE_BY_RCU | SLAB_POISON))
 | 
			
		||||
| 
						 | 
				
			
			@ -613,7 +614,8 @@ static inline bool slab_want_init_on_alloc(gfp_t flags, struct kmem_cache *c)
 | 
			
		|||
 | 
			
		||||
static inline bool slab_want_init_on_free(struct kmem_cache *c)
 | 
			
		||||
{
 | 
			
		||||
	if (static_branch_unlikely(&init_on_free))
 | 
			
		||||
	if (static_branch_maybe(CONFIG_INIT_ON_FREE_DEFAULT_ON,
 | 
			
		||||
				&init_on_free))
 | 
			
		||||
		return !(c->ctor ||
 | 
			
		||||
			 (c->flags & (SLAB_TYPESAFE_BY_RCU | SLAB_POISON)));
 | 
			
		||||
	return false;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue