linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hyeonggon Yoo <42.hyeyoo@gmail.com>
To: "GONG, Ruiqi" <gongruiqi@huaweicloud.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org,
	Alexander Lobakin <aleksander.lobakin@intel.com>,
	kasan-dev@googlegroups.com,
	Wang Weiyang <wangweiyang2@huawei.com>,
	Xiu Jianfeng <xiujianfeng@huawei.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	Christoph Lameter <cl@linux.com>,
	David Rientjes <rientjes@google.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Pekka Enberg <penberg@kernel.org>,
	Kees Cook <keescook@chromium.org>,
	Paul Moore <paul@paul-moore.com>,
	James Morris <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Gong Ruiqi <gongruiqi1@huawei.com>
Subject: Re: [PATCH RFC v2] Randomized slab caches for kmalloc()
Date: Wed, 24 May 2023 14:54:33 +0900	[thread overview]
Message-ID: <ZG2mmWT5dxfMC3DW@debian-BULLSEYE-live-builder-AMD64> (raw)
In-Reply-To: <1cec95d5-5cd4-fbf9-754b-e6a1229d45c3@huaweicloud.com>

On Mon, May 22, 2023 at 04:58:25PM +0800, GONG, Ruiqi wrote:
> 
> 
> On 2023/05/22 16:03, Hyeonggon Yoo wrote:
> > On Mon, May 22, 2023 at 4:35 PM Gong Ruiqi <gongruiqi1@huawei.com> wrote:
> >> On 2023/05/17 6:35, Hyeonggon Yoo wrote:
> > [...]
> >>>>>> +#ifdef CONFIG_RANDOM_KMALLOC_CACHES
> >>>>>> +# define SLAB_RANDOMSLAB       ((slab_flags_t __force)0x01000000U)
> >>>>>> +#else
> >>>>>> +# define SLAB_RANDOMSLAB       0
> >>>>>> +#endif
> >>>
> >>> There is already the SLAB_KMALLOC flag that indicates if a cache is a
> >>> kmalloc cache. I think that would be enough for preventing merging
> >>> kmalloc caches?
> >>
> >> After digging into the code of slab merging (e.g. slab_unmergeable(),
> >> find_mergeable(), SLAB_NEVER_MERGE, SLAB_MERGE_SAME etc), I haven't
> >> found an existing mechanism that prevents normal kmalloc caches with
> >> SLAB_KMALLOC from being merged with other slab caches. Maybe I missed
> >> something?
> >>
> >> While SLAB_RANDOMSLAB, unlike SLAB_KMALLOC, is added into
> >> SLAB_NEVER_MERGE, which explicitly indicates the no-merge policy.
> > 
> > I mean, why not make slab_unmergable()/find_mergeable() not to merge kmalloc
> > caches when CONFIG_RANDOM_KMALLOC_CACHES is enabled, instead of a new flag?
> > 
> > Something like this:
> > 
> > diff --git a/mm/slab_common.c b/mm/slab_common.c
> > index 607249785c07..13ac08e3e6a0 100644
> > --- a/mm/slab_common.c
> > +++ b/mm/slab_common.c
> > @@ -140,6 +140,9 @@ int slab_unmergeable(struct kmem_cache *s)
> >   if (slab_nomerge || (s->flags & SLAB_NEVER_MERGE))
> >   return 1;
> > 
> > + if (IS_ENALBED(CONFIG_RANDOM_KMALLOC_CACHES) && (flags & SLAB_KMALLOC))
> > + return 1;
> > +
> >   if (s->ctor)
> >   return 1;
> > 
> > @@ -176,6 +179,9 @@ struct kmem_cache *find_mergeable(unsigned int
> > size, unsigned int align,
> >   if (flags & SLAB_NEVER_MERGE)
> >   return NULL;
> > 
> > + if (IS_ENALBED(CONFIG_RANDOM_KMALLOC_CACHES) && (flags & SLAB_KMALLOC))
> > + return NULL;
> > +
> >   list_for_each_entry_reverse(s, &slab_caches, list) {
> >   if (slab_unmergeable(s))
> >   continue;
> 
> Ah I see. My concern is that it would affect not only normal kmalloc
> caches, but kmalloc_{dma,cgroup,rcl} as well: since they were all marked
> with SLAB_KMALLOC when being created, this code could potentially change
> their mergeablity. I think it's better not to influence those irrelevant
> caches.

I see. no problem at all as we're not running out of cache flags.

By the way, is there any reason to only randomize normal caches
and not dma/cgroup/rcl caches?

Thanks,

-- 
Hyeonggon Yoo

Doing kernel stuff as a hobby
Undergraduate | Chungnam National University
Dept. Computer Science & Engineering


  reply	other threads:[~2023-05-24  5:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-08  7:55 GONG, Ruiqi
2023-05-10 18:43 ` Hyeonggon Yoo
2023-05-10 19:32   ` Pedro Falcato
2023-05-12 10:11   ` Gong Ruiqi
2023-05-14  9:30     ` Vlastimil Babka
2023-05-15  8:20       ` Gong Ruiqi
2023-05-16 22:35     ` Hyeonggon Yoo
2023-05-22  7:35       ` Gong Ruiqi
2023-05-22  8:03         ` Hyeonggon Yoo
2023-05-22  8:58           ` GONG, Ruiqi
2023-05-24  5:54             ` Hyeonggon Yoo [this message]
2023-05-31  3:47               ` GONG, Ruiqi
2023-05-11 12:30 ` xiujianfeng
2023-05-11 14:54 ` Alexander Lobakin
2023-05-15  6:26   ` Gong Ruiqi
2023-05-16 12:43     ` Alexander Lobakin
2023-05-16 19:34 ` Kees Cook
2023-05-31  7:59   ` Gong Ruiqi

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=ZG2mmWT5dxfMC3DW@debian-BULLSEYE-live-builder-AMD64 \
    --to=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=aleksander.lobakin@intel.com \
    --cc=cl@linux.com \
    --cc=gongruiqi1@huawei.com \
    --cc=gongruiqi@huaweicloud.com \
    --cc=gustavoars@kernel.org \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=jmorris@namei.org \
    --cc=kasan-dev@googlegroups.com \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=paul@paul-moore.com \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=serge@hallyn.com \
    --cc=vbabka@suse.cz \
    --cc=wangweiyang2@huawei.com \
    --cc=xiujianfeng@huawei.com \
    /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