mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: "Gregory Price (Meta)" <gourry@gourry.net>,
	linux-mm@kvack.org, cgroups@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
	ridong.chen@linux.dev, tj@kernel.org, hannes@cmpxchg.org,
	mkoutny@suse.com, akpm@linux-foundation.org, vbabka@kernel.org,
	surenb@google.com, mhocko@suse.com, brendan.jackman@linux.dev,
	ziy@nvidia.com, david@kernel.org, mgorman@techsingularity.net
Subject: Re: [PATCH 2/2] cgroup/cpuset: use mems_allowed_seq when checking a policy nodemask
Date: Mon, 19 Oct 2026 10:53:41 -0400	[thread overview]
Message-ID: <1bae2a1a-e4fd-4f11-94e3-c9ff9b37a399@redhat.com> (raw)
In-Reply-To: <20261014222456.2318284-3-gourry@gourry.net>

On 10/14/26 6:24 PM, Gregory Price (Meta) wrote:
> A cpuset update changes the task's mems_allowed and rebinds its
> mempolicy in separate steps under mems_allowed_seq, but the check
> reads both without it.  This can cause a spurious numa placement
> miss under some cpuset/mempolicy combinations.
>
> A reader that loads one mask before the update and the other after
> it can see a spurious empty intersection and drop the nodemask.
>
> For example, a task with cpuset.mems={0} and MPOL_BIND={0}.  If the
> cpuset moves to mems={1,2}, the policy is rebound to {1}.
>
> The allocator can race and compare the old mems_allowed {0} against
> the new policy {1} - which will result in a dropped nodemask and a
> misplaced allocation on node 2.
>
> Simply retry the intersection until mems_allowed_seq is stable.
>
> This covers the task policy, which is rebound under mems_allowed_seq.
> VMA policies are rebound afterwards by mpol_rebind_mm(), outside
> mems_allowed_seq, and are not covered by this change.
>
> Fixes: cc9a6c877661 ("cpuset: mm: reduce large amounts of memory barrier related damage v3")
> Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
> ---
>   kernel/cgroup/cpuset.c | 13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 3f52717c19654..8ee239d5c6b48 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -4354,10 +4354,21 @@ nodemask_t cpuset_mems_allowed(struct task_struct *tsk)
>    * @nodemask: the nodemask to be checked
>    *
>    * Are any of the nodes in the nodemask allowed in current->mems_allowed?
> + *
> + * A cpuset update rebinds the task's mempolicy and changes mems_allowed in
> + * separate steps, so retry if an update raced with the check.
>    */
>   int cpuset_nodemask_valid_mems_allowed(const nodemask_t *nodemask)
>   {
> -	return nodes_intersects(*nodemask, current->mems_allowed);
> +	unsigned int seq;
> +	int ret;
> +
> +	do {
> +		seq = read_mems_allowed_begin();
> +		ret = nodes_intersects(*nodemask, current->mems_allowed);
> +	} while (read_mems_allowed_retry(seq));
> +
> +	return ret;
>   }
>   
>   /*
Reviewed-by: Waiman Long <longman@redhat.com>


  parent reply	other threads:[~2026-10-19 14:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 22:24 [PATCH 0/2] mm: fix two allocator races with zonelist and cpuset updates Gregory Price (Meta)
2026-10-14 22:24 ` [PATCH 1/2] mm/page_alloc: detect zonelist rebuilds from memory hot-add Gregory Price (Meta)
2026-10-15  7:51   ` Vlastimil Babka (SUSE)
2026-10-14 22:24 ` [PATCH 2/2] cgroup/cpuset: use mems_allowed_seq when checking a policy nodemask Gregory Price (Meta)
2026-10-15  7:59   ` Vlastimil Babka (SUSE)
2026-10-15 13:38     ` Gregory Price
2026-10-15 13:49       ` Vlastimil Babka (SUSE)
2026-10-19 14:53   ` Waiman Long [this message]
2026-10-16 16:44 ` [PATCH 0/2] mm: fix two allocator races with zonelist and cpuset updates Gregory Price

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=1bae2a1a-e4fd-4f11-94e3-c9ff9b37a399@redhat.com \
    --to=longman@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=brendan.jackman@linux.dev \
    --cc=cgroups@vger.kernel.org \
    --cc=david@kernel.org \
    --cc=gourry@gourry.net \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=mkoutny@suse.com \
    --cc=ridong.chen@linux.dev \
    --cc=surenb@google.com \
    --cc=tj@kernel.org \
    --cc=vbabka@kernel.org \
    --cc=ziy@nvidia.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

all inboxes | Powered by JetHome®