From: Tim Chen <tim.c.chen@linux.intel.com>
To: Fengyu Wang <wangfengyu@hygon.cn>, Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
Chen Yu <yu.c.chen@intel.com>,
Shrikanth Hegde <sshegde@linux.ibm.com>,
linux-kernel@vger.kernel.org, wujianyong@hygon.cn,
zhongyuan@hygon.cn, huangsj@hygon.cn
Subject: Re: [PATCH] sched/topology: Free NUMA masks on topology allocation failure
Date: Mon, 03 Aug 2026 18:15:08 -0700 [thread overview]
Message-ID: <911d52f3a1a3040ffe447dde3f4a71b68da9f9f0.camel@linux.intel.com> (raw)
In-Reply-To: <20260731081413.5505-1-wangfengyu@hygon.cn>
On Fri, 2026-07-31 at 16:14 +0800, Fengyu Wang wrote:
> sched_init_numa() publishes sched_domains_numa_masks before it
> allocates the topology array. When that allocation fails, the early
> return leaves the masks published while sched_domains_numa_levels is
> still zero: nothing dereferences them, but nothing can free them
> either, and the topology they were built for is never installed.
> Unpublish and free them instead.
>
> Fixes: cb83b629bae0 ("sched/numa: Rewrite the CONFIG_NUMA sched domain support")
> Signed-off-by: Fengyu Wang <wangfengyu@hygon.cn>
> ---
> Tested by hardcoding tl to NULL right after the kzalloc() to force the
> failure path; the masks are released and the machine boots normally.
>
> kernel/sched/topology.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
> index 622e2e01974c..208fdc52f52d 100644
> --- a/kernel/sched/topology.c
> +++ b/kernel/sched/topology.c
> @@ -2403,8 +2403,17 @@ void sched_init_numa(int offline_node)
>
> tl = kzalloc((i + nr_levels + 1) *
> sizeof(struct sched_domain_topology_level), GFP_KERNEL);
> - if (!tl)
> + if (!tl) {
> + rcu_assign_pointer(sched_domains_numa_masks, NULL);
> + synchronize_rcu();
> + for (i = 0; i < nr_levels; i++) {
> + for_each_node(j)
> + kfree(masks[i][j]);
> + kfree(masks[i]);
> + }
> + kfree(masks);
> return;
> + }
The code is cleaner without the synchronize_rcu() and set to null dance if we do
rcu_assign_pointer(sched_domains_numa_masks, masks);
after the tl check.
Thanks.
Tim
>
> /*
> * Copy the default topology bits..
next prev parent reply other threads:[~2026-08-04 1:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 8:14 [PATCH] sched/topology: Free NUMA masks on topology allocation failure Fengyu Wang
2026-08-04 1:15 ` Tim Chen [this message]
2026-08-04 7:08 ` 回复: " Fengyu Wang
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=911d52f3a1a3040ffe447dde3f4a71b68da9f9f0.camel@linux.intel.com \
--to=tim.c.chen@linux.intel.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=huangsj@hygon.cn \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sshegde@linux.ibm.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=wangfengyu@hygon.cn \
--cc=wujianyong@hygon.cn \
--cc=yu.c.chen@intel.com \
--cc=zhongyuan@hygon.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.