Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Harry Yoo (Meta)" <harry@kernel.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Hocko" <mhocko@kernel.org>,
	"Shakeel Butt" <shakeel.butt@linux.dev>,
	"Roman Gushchin" <roman.gushchin@linux.dev>
Cc: "Hao Li" <hao.li@linux.dev>, "Christoph Lameter" <cl@gentwo.org>,
	"David Rientjes" <rientjes@google.com>,
	"Muchun Song" <muchun.song@linux.dev>,
	"Hao Ge" <hao.ge@linux.dev>, "Pedro Falcato" <pfalcato@suse.de>,
	linux-mm@kvack.org, kernel-team@meta.com
Subject: Re: [PATCH slab/for-next 14/14] mm/slab: do not set SLAB_MAY_ACCOUNT for all caches
Date: Thu, 22 Oct 2026 11:48:39 +0000	[thread overview]
Message-ID: <sashiko-outbox-181395@kernel.org> (raw)
In-Reply-To: <20261021-memalloc-prof-dont-waste-slabobj-ext-metadata-v1-14-096800aa3330@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mm/slab: missing SLAB_MAY_ACCOUNT in create_unique_id() causes sysfs collision
--

commit 51cadd40978b52beb867d85f64efe89a03c7cbf8
Author: Harry Yoo (Meta) <harry@kernel.org>

mm/slab: do not set SLAB_MAY_ACCOUNT for all caches

This commit stops setting SLAB_MAY_ACCOUNT unconditionally on all slab caches
when memcg kmem accounting is enabled, instead only setting it when
SLAB_ACCOUNT is specified or when the caller explicitly passes
SLAB_MAY_ACCOUNT.

> diff --git a/mm/slab_common.c b/mm/slab_common.c
> index e66c0778ee984..c69aac8bb0e41 100644
> --- a/mm/slab_common.c
> +++ b/mm/slab_common.c
> @@ -359,12 +359,10 @@ struct kmem_cache *__kmem_cache_create_args(const char *name,
>  		goto out_unlock;
>  	}
>  
> -	/*
> -	 * For now we assume any cache can be used with __GFP_ACCOUNT and thus
> -	 * may need to store objcg pointers for objects
> -	 */
> -	if (!mem_cgroup_kmem_disabled())
> +	if (flags & SLAB_ACCOUNT)
>  		flags |= SLAB_MAY_ACCOUNT;
> +	if (mem_cgroup_kmem_disabled())
> +		flags &= ~SLAB_MAY_ACCOUNT;

[Severity: High]
Does stopping __kmem_cache_create_args() in mm/slab_common.c from setting
SLAB_MAY_ACCOUNT on all caches cause a sysfs filename collision in
sysfs_slab_add() -> create_unique_id() for mergeable caches that differ only
by SLAB_MAY_ACCOUNT?

In mm/slab_common.c, SLAB_MERGE_SAME includes SLAB_MAY_ACCOUNT:

#define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \
			 SLAB_CACHE_DMA32 | SLAB_ACCOUNT | SLAB_MAY_ACCOUNT)

Previously, all mergeable caches had SLAB_MAY_ACCOUNT set whenever
!mem_cgroup_kmem_disabled(). With this change, find_mergeable() in
mm/slab_common.c will keep a mergeable cache created with SLAB_MAY_ACCOUNT
(and without SLAB_ACCOUNT, such as fanotify_mnt_event, fanotify_path_event,
fanotify_perm_event, or buffer_head) separate from a same-sized mergeable
cache created without SLAB_MAY_ACCOUNT.

However, when sysfs_slab_add() in mm/slub.c registers mergeable caches in
sysfs, create_unique_id() does not encode SLAB_MAY_ACCOUNT in the generated
name:

mm/slub.c:create_unique_id() {
	...
	if (s->flags & SLAB_CACHE_DMA)
		*p++ = 'd';
	if (s->flags & SLAB_CACHE_DMA32)
		*p++ = 'D';
	if (s->flags & SLAB_RECLAIM_ACCOUNT)
		*p++ = 'a';
	if (s->flags & SLAB_CONSISTENCY_CHECKS)
		*p++ = 'F';
	if (s->flags & SLAB_ACCOUNT)
		*p++ = 'A';
	if (p != name + 1)
		*p++ = '-';
	p += snprintf(p, ID_STR_LENGTH - (p - name), "%07u", s->size);
	...
}

When CONFIG_MEMCG=y and cgroup kmem accounting is enabled, won't two
mergeable caches of the same size that differ only by SLAB_MAY_ACCOUNT
receive the exact same sysfs ID (for example, :0000056, :0000064, or
:a-0000104), causing kobject_init_and_add() in sysfs_slab_add() to fail with
-EEXIST and trigger a duplicate sysfs filename warning during boot?

>  
>  	/* Fail closed on bad usersize of useroffset values. */
>  	if (!IS_ENABLED(CONFIG_HARDENED_USERCOPY) ||

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261021-memalloc-prof-dont-waste-slabobj-ext-metadata-v1-0-096800aa3330@kernel.org?part=14


  reply	other threads:[~2026-10-22 11:48 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21 11:46 [PATCH slab/for-next 00/14] mm/slab: mandate SLAB_MAY_ACCOUNT for __GFP_ACCOUNT allocations to avoid wasting memory for slab metadata Harry Yoo (Meta)
2026-10-21 11:46 ` [PATCH slab/for-next 01/14] mm/slab: allow passing SLAB_MAY_ACCOUNT to kmem_cache_create() Harry Yoo (Meta)
2026-10-22 11:48   ` sashiko-bot
2026-10-21 11:46 ` [PATCH slab/for-next 02/14] lib/maple_tree: specify SLAB_MAY_ACCOUNT for maple_node cache Harry Yoo (Meta)
2026-10-22 11:48   ` sashiko-bot
2026-10-21 11:46 ` [PATCH slab/for-next 03/14] lib/xarray: specify SLAB_MAY_ACCOUNT for radix_tree_node cache Harry Yoo (Meta)
2026-10-22 11:48   ` sashiko-bot
2026-10-21 11:46 ` [PATCH slab/for-next 04/14] fs/buffer: specify SLAB_MAY_ACCOUNT for buffer_head cache Harry Yoo (Meta)
2026-10-21 11:46 ` [PATCH slab/for-next 05/14] net: skbuff: specify SLAB_MAY_ACCOUNT for skbuff_head_cache Harry Yoo (Meta)
2026-10-21 19:19   ` Jakub Kicinski
2026-10-22 13:43     ` Harry Yoo
2026-10-23 17:56       ` Jakub Kicinski
2026-10-21 11:46 ` [PATCH slab/for-next 06/14] kernel/fork: specify SLAB_MAY_ACCOUNT for thread_stack cache Harry Yoo (Meta)
2026-10-21 11:46 ` [PATCH slab/for-next 07/14] arm64/mm: specify SLAB_MAY_ACCOUNT for pgd_cache Harry Yoo (Meta)
2026-10-21 11:46 ` [PATCH slab/for-next 08/14] powerpc/mm: specify SLAB_MAY_ACCOUNT for pgtable caches Harry Yoo (Meta)
2026-10-21 11:46 ` [PATCH slab/for-next 09/14] iommu: specify SLAB_MAY_ACCOUNT for slab-backed page table caches Harry Yoo (Meta)
2026-10-21 11:46 ` [PATCH slab/for-next 10/14] fanotify: specify SLAB_MAY_ACCOUNT for event caches Harry Yoo (Meta)
2026-10-21 11:46 ` [PATCH slab/for-next 11/14] smack: specify SLAB_MAY_ACCOUNT for smack_rule cache Harry Yoo (Meta)
2026-10-21 16:59   ` Casey Schaufler
2026-10-21 18:48     ` Harry Yoo
2026-10-21 19:14       ` Casey Schaufler
2026-10-22 12:54         ` Harry Yoo
2026-10-21 11:46 ` [PATCH slab/for-next 12/14] hostfs: specify SLAB_MAY_ACCOUNT for inode cache Harry Yoo (Meta)
2026-10-21 11:46 ` [PATCH slab/for-next 13/14] mm/memcontrol: do not allow charging objects without SLAB_MAY_ACCOUNT Harry Yoo (Meta)
2026-10-21 11:46 ` [PATCH slab/for-next 14/14] mm/slab: do not set SLAB_MAY_ACCOUNT for all caches Harry Yoo (Meta)
2026-10-22 11:48   ` sashiko-bot [this message]
2026-10-26  1:02   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-181395@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=cl@gentwo.org \
    --cc=hannes@cmpxchg.org \
    --cc=hao.ge@linux.dev \
    --cc=hao.li@linux.dev \
    --cc=harry@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=pfalcato@suse.de \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox