From: Michal Hocko <mhocko@suse.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Chen Yu <yu.c.chen@intel.com>, Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
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>,
Andrew Morton <akpm@linux-foundation.org>,
Tim Chen <tim.c.chen@intel.com>,
linux-kernel@vger.kernel.org, Jirka Hladky <jhladky@redhat.com>,
Srikanth Aithal <Srikanth.Aithal@amd.com>,
Suneeth D <Suneeth.D@amd.com>, Libo Chen <libo.chen@oracle.com>
Subject: Re: [PATCH] sched/numa: Fix NULL pointer access to mm_struct durng task swap
Date: Thu, 3 Jul 2025 11:28:46 +0200 [thread overview]
Message-ID: <aGZNTtJuCyHJE_25@tiehlicka> (raw)
In-Reply-To: <20250703072608.GS1613200@noisy.programming.kicks-ass.net>
On Thu 03-07-25 09:26:08, Peter Zijlstra wrote:
> On Thu, Jul 03, 2025 at 12:32:47AM +0800, Chen Yu wrote:
>
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index 8988d38d46a3..4e06bb955dad 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -3364,7 +3364,14 @@ static void __migrate_swap_task(struct task_struct *p, int cpu)
> > {
> > __schedstat_inc(p->stats.numa_task_swapped);
> > count_vm_numa_event(NUMA_TASK_SWAP);
> > - count_memcg_event_mm(p->mm, NUMA_TASK_SWAP);
> > + /* exiting task has NULL mm */
> > + if (!(p->flags & PF_EXITING)) {
> > + WARN_ONCE(!p->mm, "swap task %d %s %x has no mm\n",
> > + p->pid, p->comm, p->flags);
> > +
> > + if (p->mm)
> > + count_memcg_event_mm(p->mm, NUMA_TASK_SWAP);
> > + }
>
> Aside from the things already mentioned by Andrew and Michal; why not
> simply do something like:
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index 87b6688f124a..8396ebfab0d5 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -969,7 +969,7 @@ static inline void count_memcg_events_mm(struct mm_struct *mm,
> {
> struct mem_cgroup *memcg;
>
> - if (mem_cgroup_disabled())
> + if (mem_cgroup_disabled() || !mm)
> return;
This would imply mm check for all other users that know their mm is
valid as they are operating on vma->mm or current task.
But thinking about this some more, this would be racy same as the
PF_EXITING check. This is not my area but is this performance sensitive
path that couldn't live with the proper find_lock_task_mm?
I do not see other race free way to deal with a remote task exit race.
--
Michal Hocko
SUSE Labs
next prev parent reply other threads:[~2025-07-03 9:28 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-02 16:32 [PATCH] sched/numa: Fix NULL pointer access to mm_struct durng task swap Chen Yu
2025-07-02 21:08 ` Andrew Morton
2025-07-03 9:24 ` Chen, Yu C
2025-07-03 7:18 ` Michal Hocko
2025-07-03 9:37 ` Chen, Yu C
2025-07-03 11:51 ` Michal Hocko
2025-07-03 11:55 ` Peter Zijlstra
2025-07-03 7:26 ` Peter Zijlstra
2025-07-03 9:28 ` Michal Hocko [this message]
2025-07-03 11:50 ` Peter Zijlstra
2025-07-03 12:01 ` Michal Hocko
2025-07-03 12:04 ` Chen, Yu C
2025-07-03 12:20 ` Libo Chen
2025-07-03 12:36 ` Peter Zijlstra
2025-07-03 13:38 ` Chen, Yu C
2025-07-03 14:01 ` Peter Zijlstra
2025-07-04 5:57 ` Chen, Yu C
2025-07-03 13:57 ` Libo Chen
2025-07-03 14:18 ` Peter Zijlstra
2025-07-03 23:35 ` Libo Chen
2025-07-04 8:26 ` Peter Zijlstra
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=aGZNTtJuCyHJE_25@tiehlicka \
--to=mhocko@suse.com \
--cc=Srikanth.Aithal@amd.com \
--cc=Suneeth.D@amd.com \
--cc=akpm@linux-foundation.org \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=jhladky@redhat.com \
--cc=juri.lelli@redhat.com \
--cc=libo.chen@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tim.c.chen@intel.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=yu.c.chen@intel.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