From: Yi Zhang <yi.zhang@redhat.com>
To: Nilay Shroff <nilay@linux.ibm.com>
Cc: linux-mm@kvack.org, linux-block@vger.kernel.org, vbabka@suse.cz,
akpm@linux-foundation.org, cl@linux.com, penberg@kernel.org,
rientjes@google.com, iamjoonsoo.kim@lge.com,
roman.gushchin@linux.dev, 42.hyeyoo@gmail.com,
shinichiro.kawasaki@wdc.com, axboe@kernel.dk,
gjoyce@linux.ibm.com
Subject: Re: [PATCH] mm, slab: fix use of SLAB_SUPPORTS_SYSFS in kmem_cache_release()
Date: Tue, 1 Oct 2024 23:59:34 +0800 [thread overview]
Message-ID: <CAHj4cs9Avm=CGfnJrwB5LJvXiW9-soozMhjYhWFAmdUPe_OyKQ@mail.gmail.com> (raw)
In-Reply-To: <20241001140245.306087-1-nilay@linux.ibm.com>
On Tue, Oct 1, 2024 at 10:03 PM Nilay Shroff <nilay@linux.ibm.com> wrote:
>
> The fix implemented in commit 4ec10268ed98 ("mm, slab: unlink slabinfo,
> sysfs and debugfs immediately") caused a subtle side effect due to which
> while destroying the kmem cache, the code path would never get into
> sysfs_slab_release() function even though SLAB_SUPPORTS_SYSFS is defined
> and slab state is FULL. Due to this side effect, we would never release
> kobject defined for kmem cache and leak the associated memory.
>
> The issue here's with the use of __is_defined() macro in kmem_cache_
> release(). The __is_defined() macro expands to __take_second_arg(
> arg1_or_junk 1, 0). If "arg1_or_junk" is defined to 1 then it expands to
> __take_second_arg(0, 1, 0) and returns 1. If "arg1_or_junk" is NOT defined
> to any value then it expands to __take_second_arg(... 1, 0) and returns 0.
>
> In this particular issue, SLAB_SUPPORTS_SYSFS is defined without any
> associated value and that causes __is_defined(SLAB_SUPPORTS_SYSFS) to
> always evaluate to 0 and hence it would never invoke sysfs_slab_release().
>
> This patch helps fix this issue by defining SLAB_SUPPORTS_SYSFS to 1.
>
> Fixes: 4ec10268ed98 ("mm, slab: unlink slabinfo, sysfs and debugfs immediately")
> Reported-by: Yi Zhang <yi.zhang@redhat.com>
> Closes: https://lore.kernel.org/all/CAHj4cs9YCCcfmdxN43-9H3HnTYQsRtTYw1Kzq-L468GfLKAENA@mail.gmail.com/
> Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
Tested-by: Yi Zhang <yi.zhang@redhat.com>
> ---
> mm/slab.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/slab.h b/mm/slab.h
> index f22fb760b286..3e0a08ea4c42 100644
> --- a/mm/slab.h
> +++ b/mm/slab.h
> @@ -310,7 +310,7 @@ struct kmem_cache {
> };
>
> #if defined(CONFIG_SYSFS) && !defined(CONFIG_SLUB_TINY)
> -#define SLAB_SUPPORTS_SYSFS
> +#define SLAB_SUPPORTS_SYSFS 1
> void sysfs_slab_unlink(struct kmem_cache *s);
> void sysfs_slab_release(struct kmem_cache *s);
> #else
> --
> 2.45.2
>
--
Best Regards,
Yi Zhang
next prev parent reply other threads:[~2024-10-01 15:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-01 14:02 Nilay Shroff
2024-10-01 14:50 ` Hyeonggon Yoo
2024-10-01 15:39 ` Vlastimil Babka
2024-10-01 15:51 ` Hyeonggon Yoo
2024-10-01 15:59 ` Yi Zhang [this message]
2024-10-01 16:27 ` Vlastimil Babka
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='CAHj4cs9Avm=CGfnJrwB5LJvXiW9-soozMhjYhWFAmdUPe_OyKQ@mail.gmail.com' \
--to=yi.zhang@redhat.com \
--cc=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=cl@linux.com \
--cc=gjoyce@linux.ibm.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nilay@linux.ibm.com \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=shinichiro.kawasaki@wdc.com \
--cc=vbabka@suse.cz \
/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