Re: [PATCH v6 2/6] init_on_alloc: Optimize static branches

2021-03-18 Thread Vlastimil Babka
On 3/15/21 7:02 PM, Kees Cook wrote:
> 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.
> 
> Reviewed-by: Alexander Potapenko 
> Link: 
> https://lore.kernel.org/lkml/CAG_fn=x0dvwqlahjto6jw7tgcmsm77gkhinrd0m_6y0szwo...@mail.gmail.com/
> Signed-off-by: Kees Cook 

For the fixed version

Acked-by: Vlastimil Babka 


Re: [PATCH v6 2/6] init_on_alloc: Optimize static branches

2021-03-15 Thread Kees Cook
On Mon, Mar 15, 2021 at 11:02:25AM -0700, Kees Cook wrote:
> diff --git a/mm/slab.h b/mm/slab.h
> index 076582f58f68..b0977d525c06 100644
> --- a/mm/slab.h
> +++ b/mm/slab.h
> @@ -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_FREE_DEFAULT_ON,

Gah, this should be CONFIG_INIT_ON_ALLOC_DEFAULT_ON.

I'll see if there are any more comments before sending a v7...

-Kees

> + &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;
> -- 
> 2.25.1
> 

-- 
Kees Cook