mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ridong Chen <ridong.chen@linux.dev>
To: "Waiman Long" <longman@redhat.com>, "Tejun Heo" <tj@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>,
	"Shuah Khan" <shuah@kernel.org>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	Guopeng Zhang <guopeng.zhang@linux.dev>,
	Sashiko <sashiko-bot@kernel.org>
Subject: Re: [PATCH-next v2 4/5] cgroup/cpuset: Protect current->mems_allowed read in cpuset_fork()
Date: Tue, 10 Nov 2026 19:24:07 +0800	[thread overview]
Message-ID: <cfa85d13-1da7-45ad-9dd8-208e1267000e@linux.dev> (raw)
In-Reply-To: <20261109190955.1398611-5-longman@redhat.com>



On 11/10/2026 3:09 AM, Waiman Long wrote:
> Reading mems_allowed of the current task outside of cpuset_mutex critical
> section should be protected by using mems_allowed_seq seqlock as the
> nodemask can be updated concurrently leading to a torn read. Such
> protection is currently not implemented in cpuset_fork() for the
> !CLONE_INTO_CGROUP case. As a result, the child task may inherit an empty
> or corrupted mems_allowed nodemask. This violates NUMA memory policy
> constraints and causes subsequent page allocations to unconditionally
> fail, potentially leading to crashes or spurious OOM killer invocations
> for the child task.
> 
> Fix that by using a read_mems_allowed_begin/read_mems_allowed_retry()
> loop to protect the mems_allowed read.
> 
> Fixes: 06f4e9489891 ("cpuset: make sure new tasks conform to the current config of the cpuset")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Link: https://sashiko.dev/#/bug/linux-601100b4-fa77-45fd-99f9-bfbd4385201f
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
>   kernel/cgroup/cpuset.c | 11 ++++++++++-
>   1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index e9b84671af21..7aa614c6ac4d 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -3868,11 +3868,20 @@ static void cpuset_fork(struct task_struct *task)
>   	rcu_read_unlock();
>   
>   	if (cs == oldcs) {
> +		unsigned int seq;
> +
>   		if (cs == &top_cpuset)
>   			return;
>   
>   		set_cpus_allowed_ptr(task, current->cpus_ptr);
> -		task->mems_allowed = current->mems_allowed;
> +		/*
> +		 * A cpuset.mems update can update current->mems_allowed
> +		 * concurrently, so retry it again if it really happens.
> +		 */
> +		do {
> +			seq = read_mems_allowed_begin();
> +			task->mems_allowed = current->mems_allowed;
> +		} while (read_mems_allowed_retry(seq));
>   		return;
>   	}
>   

Reviewed-by: Ridong Chen <ridong.chen@linux.dev>
Thanks.
-- 
Best regards
Ridong


  reply	other threads:[~2026-11-10 11:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 19:09 [PATCH-next v2 0/5] More fix patches Waiman Long
2026-11-09 19:09 ` [PATCH-next v2 1/5] selftests/cgroup: Fix "test_cpuset_prs.sh -v" failures Waiman Long
2026-11-10  7:56   ` Ridong Chen
2026-11-09 19:09 ` [PATCH-next v2 2/5] cgroup/cpuset: Correctly set cpus_updated in cpuset_hotplug_update_tasks() Waiman Long
2026-11-10  8:40   ` Ridong Chen
2026-11-09 19:09 ` [PATCH-next v2 3/5] cgroup/cpuset: Fix incorrect partition invalidation logic " Waiman Long
2026-11-10  8:51   ` Ridong Chen
2026-11-09 19:09 ` [PATCH-next v2 4/5] cgroup/cpuset: Protect current->mems_allowed read in cpuset_fork() Waiman Long
2026-11-10 11:24   ` Ridong Chen [this message]
2026-11-09 19:09 ` [PATCH-next v2 5/5] cgroup/cpuset: Correctly set isolated_cpus when switching partition state Waiman Long
2026-11-10  2:23   ` Waiman Long
2026-11-10  2:24   ` [PATCH-next v2.1 " Waiman Long
2026-11-10 11:40   ` [PATCH-next v2 " Ridong Chen
2026-11-10 13:02     ` Ridong Chen

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=cfa85d13-1da7-45ad-9dd8-208e1267000e@linux.dev \
    --to=ridong.chen@linux.dev \
    --cc=cgroups@vger.kernel.org \
    --cc=guopeng.zhang@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mkoutny@suse.com \
    --cc=sashiko-bot@kernel.org \
    --cc=shuah@kernel.org \
    --cc=tj@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

all inboxes | Powered by JetHome®