Linux ACPI
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Yury Norov <ynorov@nvidia.com>,
	linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Gregory Price <gourry@gourry.net>, Zi Yan <ziy@nvidia.com>,
	Joshua Hahn <joshua.hahnjy@gmail.com>,
	Rakie Kim <rakie.kim@sk.com>,
	Ying Huang <ying.huang@linux.alibaba.com>,
	Muchun Song <muchun.song@linux.dev>,
	Oscar Salvador <osalvador@suse.de>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Kairui Song <kasong@tencent.com>,
	Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Len Brown <lenb@kernel.org>, Jens Axboe <axboe@kernel.dk>,
	Peter Zijlstra <peterz@infradead.org>,
	Mel Gorman <mgorman@suse.de>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-mips@vger.kernel.org, linux-acpi@vger.kernel.org,
	linux-block@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Cc: "Liam R. Howlett" <liam@infradead.org>,
	Axel Rasmussen <axelrasmussen@google.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Baoquan He <baoquan.he@linux.dev>, Barry Song <baohua@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Lorenzo Stoakes <ljs@kernel.org>, Michal Hocko <mhocko@suse.com>,
	Mike Rapoport <rppt@kernel.org>, Qi Zheng <qi.zheng@linux.dev>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Suren Baghdasaryan <surenb@google.com>,
	Vlastimil Babka <vbabka@kernel.org>, Wei Xu <weixugc@google.com>,
	Yuanchu Xie <yuanchu@google.com>,
	Yury Norov <yury.norov@gmail.com>
Subject: Re: [PATCH 04/11] mm/mempolicy: preserve full-width userspace nodemasks
Date: Tue, 1 Dec 2026 11:10:42 +0100	[thread overview]
Message-ID: <9492e5f2-13d2-4392-8d28-8bcf4fd4a411@kernel.org> (raw)
In-Reply-To: <20261127230128.111933-5-ynorov@nvidia.com>

On 11/28/26 00:01, Yury Norov wrote:
> This series switches nodemask API to runtime nr_node_ids.
> 
> Userspace mempolicy masks can contain static node IDs or relative
> indices above nr_node_ids. They must retain their full MAX_NUMNODES
> width when the nodemask helpers switch to runtime bounds.
> 
> For example, with MAX_NUMNODES=1024, nr_node_ids=2 and allowed
> memory nodes {0,1},
> 
>        set_mempolicy(MPOL_BIND | MPOL_F_RELATIVE_NODES, ...)
> 
> can specify a mask containing only bit 3. This is a relative
> index: folding it modulo the two allowed nodes maps it to node 1.
> 
> A runtime-bounded emptiness check would reject this valid mask,
> and a runtime-bounded fold would discard its only set bit.
> 
> Use underscored nodemask API with an explicit MAX_NUMNODES bound where
> needed.
> 
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
>  mm/mempolicy.c | 29 +++++++++++++++++++----------
>  1 file changed, 19 insertions(+), 10 deletions(-)
> 
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 67e258c62527..ed8b20b27753 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -396,7 +396,10 @@ static void mpol_relative_nodemask(nodemask_t *ret, const nodemask_t *orig,
>  				   const nodemask_t *rel)
>  {
>  	nodemask_t tmp;
> -	nodes_fold(tmp, *orig, nodes_weight(*rel));
> +
> +	/* Relative indices can exceed the runtime node ID limit. */
> +	__nodes_fold(&tmp, orig, nodes_weight(*rel), MAX_NUMNODES);

This is a bit shaky. It means that we can silently introduce new issues by using
the "obvious" helper.


Maybe we should just have a set of helpers for these cases

	__nodes_fold(&tmp, orig, nodes_weight(*rel), MAX_NUMNODES);
	__nodes_empty(nodes, MAX_NUMNODES
	__nodes_clear(nodes, MAX_NUMNODES)
	...

that embed in their name what they should be used for (I assume, whenever we are
interacting with user-space)?

-- 
Cheers,

David

  reply	other threads:[~2026-12-01 10:10 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 23:01 [PATCH 00/11] nodemask: switch to runtime nr_node_ids Yury Norov
2026-11-27 23:01 ` [PATCH 01/11] nodemask: add 'small' and 'large' compile-time sizes Yury Norov
2026-12-01 10:01   ` David Hildenbrand (Arm)
2026-11-27 23:01 ` [PATCH 02/11] nodemask: pass nodemask length to node search functions Yury Norov
2026-12-01 10:02   ` David Hildenbrand (Arm)
2026-11-27 23:01 ` [PATCH 03/11] mm/mempolicy: reject migrate_pages source IDs beyond nr_node_ids Yury Norov
2026-11-30 19:44   ` Gregory Price (Meta)
2026-12-01 10:02     ` David Hildenbrand (Arm)
2026-11-27 23:01 ` [PATCH 04/11] mm/mempolicy: preserve full-width userspace nodemasks Yury Norov
2026-12-01 10:10   ` David Hildenbrand (Arm) [this message]
2026-11-27 23:01 ` [PATCH 05/11] mm: switch to runtime nodemask length Yury Norov
2026-12-01  9:57   ` David Hildenbrand (Arm)
2026-11-27 23:01 ` [PATCH 06/11] MIPS: IP27: switch nmi_dump " Yury Norov
2026-12-01  9:58   ` David Hildenbrand (Arm)
2026-11-27 23:01 ` [PATCH 07/11] ACPI: NUMA: switch acpi_map_pxm_to_node " Yury Norov
2026-12-01  9:58   ` David Hildenbrand (Arm)
2026-11-27 23:01 ` [PATCH 08/11] mtip32xx: switch next_online_node() " Yury Norov
2026-12-01  9:58   ` David Hildenbrand (Arm)
2026-11-27 23:01 ` [PATCH 09/11] nodemask: add nodes_copy_and_extend() Yury Norov
2026-11-27 23:01 ` [PATCH 10/11] sched/numa: bound cpuset trace masks by nr_node_ids Yury Norov
2026-11-27 23:01 ` [PATCH 11/11] nodemask: add cpumask-style operation size bounds Yury Norov
2026-11-30 19:59   ` Gregory Price (Meta)
2026-11-28 23:40 ` [PATCH 00/11] nodemask: switch to runtime nr_node_ids Andrew Morton
2026-11-29  3:01   ` Yury Norov
2026-11-29  4:20     ` Andrew Morton
2026-11-29  4:21       ` Linus Torvalds
2026-11-29 22:05       ` Yury Norov
2026-11-30 11:51 ` Lorenzo Stoakes (ARM)
2026-11-30 12:17   ` David Hildenbrand (Arm)
2026-11-30 16:32     ` Yury Norov
2026-11-30 16:42       ` Lorenzo Stoakes (ARM)
2026-11-30 17:28         ` Yury Norov
2026-11-30 12:20   ` Lorenzo Stoakes (ARM)
2026-11-30 16:48 ` Joshua Hahn
2026-11-30 19:18   ` Joshua Hahn

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=9492e5f2-13d2-4392-8d28-8bcf4fd4a411@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=baoquan.he@linux.dev \
    --cc=gourry@gourry.net \
    --cc=hannes@cmpxchg.org \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kasong@tencent.com \
    --cc=lenb@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=ljs@kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mgorman@suse.de \
    --cc=mhiramat@kernel.org \
    --cc=mhocko@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=osalvador@suse.de \
    --cc=peterz@infradead.org \
    --cc=qi.zheng@linux.dev \
    --cc=rafael@kernel.org \
    --cc=rakie.kim@sk.com \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=torvalds@linux-foundation.org \
    --cc=tsbogend@alpha.franken.de \
    --cc=vbabka@kernel.org \
    --cc=weixugc@google.com \
    --cc=ying.huang@linux.alibaba.com \
    --cc=ynorov@nvidia.com \
    --cc=yuanchu@google.com \
    --cc=yury.norov@gmail.com \
    --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