From: Enze Li <enze.li@linux.dev>
To: Aveline Noir <jm5905938@gmail.com>, SJ Park <sj@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Lian Wang <lianux.mm@gmail.com>,
Dawei Li <set_pte_at@outlook.com>,
damon@lists.linux.dev, linux-mm@kvack.org
Subject: Re: [PATCH] mm/damon/sysfs: skip registration if DAMON core init fails
Date: Tue, 24 Nov 2026 20:18:19 +0800 [thread overview]
Message-ID: <1739306a-9fa7-403c-a2da-b44f623b9445@linux.dev> (raw)
In-Reply-To: <20261123-damon-sysfs-init-guard-v1-1-a2a6ca65693a@gmail.com>
Hi Aveline,
On 11/23/26 15:51, Aveline Noir wrote:
> Hi SJ,
>
> Here's the sysfs fix I mentioned in the report queue review.
>
> -- >8 --
>
> While reviewing the DAMON report queue series, I noticed that DAMON
> sysfs still registers its interface if DAMON core initialization fails.
> If damon_init() fails to allocate damon_region_cache, starting a
> kdamond with an initial region can pass a NULL cache to
> kmem_cache_alloc() via damon_new_region().
>
> Check damon_initialized() before creating the DAMON sysfs directory and
> return -ENOMEM if the core is unavailable.
>
> Fixes: a18709442869 ("mm/damon: improve damon_new_region strategy")
> Signed-off-by: Aveline Noir <jm5905938@gmail.com>
> ---
> Tests passed in x86-64 QEMU TCG guests on 9f004372ebeb.
I gave this patch a try and it works.
I forced damon_init() to fail with the following modification on an
x86_64 VM,
8<------------------------------------------------------
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 986404b547eb..194b30731572 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -4313,6 +4313,10 @@ bool damon_initialized(void)
static int __init damon_init(void)
{
damon_region_cache = KMEM_CACHE(damon_region, 0);
+ if (damon_region_cache) {
+ kmem_cache_destroy(damon_region_cache);
+ damon_region_cache = NULL;
+ }
if (unlikely(!damon_region_cache)) {
pr_err("creating damon_region_cache fails\n");
return -ENOMEM;
------------------------------------------------------>8
then ran `damo start paddr --regions 0-10000`. On the unpatched kernel
that immediately Oops,
8<------------------------------------------------------
[ 461.012857] BUG: kernel NULL pointer dereference, address:
000000000000001c
[ 461.012881] #PF: supervisor read access in kernel mode
[ 461.012891] #PF: error_code(0x0000) - not-present page
[ 461.012901] PGD 139e4f067 P4D 139e4f067 PUD 124048067 PMD 0
[ 461.012913] Oops: Oops: 0000 [#1] SMP NOPTI
[ 461.012924] CPU: 3 UID: 0 PID: 1610 Comm: python3 Tainted: G E
7.4.0-rc3-new+ #2 PREEMPT(lazy)
[ 461.012938] Tainted: [E]=UNSIGNED_MODULE
[ 461.012945] Hardware name: Red Hat KVM, BIOS
rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014
[ 461.012956] RIP: 0010:kmem_cache_alloc_noprof+0x16/0x400
[ 461.013083] Call Trace:
[ 461.013088] <TASK>
[ 461.013094] damon_new_region+0x22/0x60
[ 461.013104] damon_set_regions+0x38a/0x4e0
[ 461.013112] ? damon_sysfs_build_ctx+0x32c/0x400
[ 461.013123] damon_sysfs_build_ctx+0x391/0x400
[ 461.013133] state_store+0x30e/0x3f0
[ 461.013141] ? __kmalloc_noprof+0x292/0x590
[ 461.013151] kernfs_fop_write_iter+0x14a/0x200
[ 461.013160] vfs_write+0x25d/0x440
[ 461.013170] ksys_write+0x6b/0xe0
[ 461.013178] do_syscall_64+0xc4/0x570
[ 461.013188] ? __x64_sys_close+0x3d/0x80
[ 461.013196] ? do_syscall_64+0x101/0x570
[ 461.013205] ? do_syscall_64+0x101/0x570
[ 461.013213] ? do_syscall_64+0x35/0x570
[ 461.013221] entry_SYSCALL_64_after_hwframe+0x76/0x7e
[ 461.013230] RIP: 0033:0x7fbdeba26a02
------------------------------------------------------>8
With your patch, /sys/kernel/mm/damon/ simply doesn't show up when core
init fails, and the same damo command just errors out. No Oops, no NULL
deref in dmesg. That's exactly the behaviour we want.
Feel free to add:
Tested-by: Enze Li <lienze@kylinos.cn>
Reviewed-by: Enze Li <lienze@kylinos.cn>
Thanks,
Enze
prev parent reply other threads:[~2026-11-24 12:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 7:51 [PATCH] mm/damon/sysfs: skip registration if DAMON core init fails Aveline Noir
2026-11-23 15:36 ` SJ Park
2026-11-24 12:31 ` Enze Li
2026-11-24 12:18 ` Enze Li [this message]
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=1739306a-9fa7-403c-a2da-b44f623b9445@linux.dev \
--to=enze.li@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=jm5905938@gmail.com \
--cc=lianux.mm@gmail.com \
--cc=linux-mm@kvack.org \
--cc=set_pte_at@outlook.com \
--cc=sj@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