[PATCH slab/for-next v2 10/14] fanotify: specify SLAB_MAY_ACCOUNT for event caches

Jan Kara jack at suse.cz
Thu Nov 26 09:06:42 UTC 2026


On Wed 25-11-26 21:37:11, Harry Yoo (Meta) wrote:
> fanotify events are allocated with GFP_KERNEL_ACCOUNT and charged to
> the memcg of the listener. Specify SLAB_MAY_ACCOUNT when the object
> may be charged to a memcg. __GFP_ACCOUNT without SLAB_MAY_ACCOUNT
> will not be allowed.
> 
> Path: fsnotify() -> fanotify_handle_event()
>   -> fanotify_alloc_event(GFP_KERNEL_ACCOUNT)
>   -> kmem_cache_alloc(fanotify_{fid,path,perm,mnt}_event_cachep)
> 
> Cc: Jan Kara <jack at suse.cz>
> Cc: Amir Goldstein <amir73il at gmail.com>
> Cc: linux-fsdevel at vger.kernel.org
> Signed-off-by: Harry Yoo (Meta) <harry at kernel.org>

Looks good. Feel free to add:

Acked-by: Jan Kara <jack at suse.cz>

								Honza

> ---
>  fs/notify/fanotify/fanotify_user.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index 63c9759fc3b0..3575c681abc1 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -2184,14 +2184,16 @@ static int __init fanotify_user_setup(void)
>  	fanotify_mark_cache = KMEM_CACHE(fanotify_mark,
>  					 SLAB_PANIC|SLAB_ACCOUNT);
>  	fanotify_fid_event_cachep = KMEM_CACHE(fanotify_fid_event,
> -					       SLAB_PANIC);
> +					       SLAB_PANIC|SLAB_MAY_ACCOUNT);
>  	fanotify_path_event_cachep = KMEM_CACHE(fanotify_path_event,
> -						SLAB_PANIC);
> +						SLAB_PANIC|SLAB_MAY_ACCOUNT);
>  	if (IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS)) {
>  		fanotify_perm_event_cachep =
> -			KMEM_CACHE(fanotify_perm_event, SLAB_PANIC);
> +			KMEM_CACHE(fanotify_perm_event,
> +				   SLAB_PANIC|SLAB_MAY_ACCOUNT);
>  	}
> -	fanotify_mnt_event_cachep = KMEM_CACHE(fanotify_mnt_event, SLAB_PANIC);
> +	fanotify_mnt_event_cachep = KMEM_CACHE(fanotify_mnt_event,
> +					       SLAB_PANIC|SLAB_MAY_ACCOUNT);
>  
>  	fanotify_max_queued_events = FANOTIFY_DEFAULT_MAX_EVENTS;
>  	init_user_ns.ucount_max[UCOUNT_FANOTIFY_GROUPS] =
> 
> -- 
> 2.54.0
> 
-- 
Jan Kara <jack at suse.com>
SUSE Labs, CR



More information about the Linux-security-module-archive mailing list