Re: [PATCH 11/11] nodemask: add cpumask-style operation size bounds

From: Yury Norov

Date: Fri Dec 04 2026 - 10:59:04 EST


On Thu, Dec 03, 2026 at 10:36:45PM -0500, Gregory Price (Meta) wrote:
> On 2026-12-01 19:01 -0500, Yury Norov wrote:
> > > This breaks cpuset.mems :
> > >
> > > 2 node host - {0,1}
> > >
> > > echo 0-3:1/4 > cpuset.mems
> > > before: succeeds - result: {0}
> > > now: ERANGE
> >
> > Here user explicitly refers non-existing nodes 2 and 3. So, as for the
> > patch #3, it's unclear, do we erroneously accept the invalid input?
> >
>
> You assume they're non-existing. They're not presently hotplugged.
>
> cpuset.mems can contain valid but empty nodes, and this is allowed.

Not sure I understand... Unplugging a node doesn't change nr_node_ids.
It is defined as last possible node ID plus 1.

Even if your topology has 4 possible nodes "0-1,4-5", the nr_node_ids
would be 6 in this example. (Notice, there's no real example of
non-dense node_possible_map.) That wouldn't change if you unplug
any node. In fact, nr_node_ids should be declared as ro_after_init to
highlight it.

> > Any example with explicit boundaries is vulnerable. The above 0-3:1/4
> > would work fine for 2-node machine with MAX_NUMNODES == 1024. But if I
> > will recompile my kernel with MAX_NUMNODES == 2, it will return ERANGE.
> > It already happens on master, and nobody complains.
> >
> > > echo 0-1:1/_ > cpuset.mems
> > > before: succeeds - result: {0}
> > > now: {0,1}
> >
> > Did you mean 0-1:1/N?
> >
> > I'm one of those who invented that N notation, and I'm pretty
> > confident that "2 nodes and 0-1:1/N" simply means all node".
> >
>
> Before the patch, cpuset.mems parsed range endpoints against
> MAX_NUMNODES, then checked which nodes the pattern actually selected.
>
> After the patch, it rejects anything in [nr_node_ids, MAX_NUMNODES)
> before applying the pattern.
>
> For example MAX_NUMNODES=1024 and nr_node_ids=2, 0-3:1/4 used to succeed
> and selected only {0}. Now it fails with ERANGE because the endpoint on
> the range is 3.

This is another example: nr_node_ids=2, 0-3:1/4 and MAX_NUMNODES == 2 or 3.
It would fail with ERANGE on master just as well, and this configuration
makes more sense than 1K MAX_NUMNODES.

>From user perspective, MAX_NUMNODES is a random non-exported parameter.
It's unsafe to assume that it wold have any specific number on any
particular kernel. The only portable way to avoid ERANGE is checking
/sys/devices/system/node/possible and /proc/<pid>/status:Mems_allowed

> Maybe we want that, maybe we don't. We should be open about the change.
>
> Another scan, this can also affect the tmpfs mpol= mount option.

mpol_parse_str() already requires every listed node to belong to
node_states[N_MEMORY]. It seems like both mpol=bind and relative are
first checked against N_MEMORY before doing mapping.

I'll check carefully on it.

> At the very least, please note this in the changelog and make it
> obvious. I will likely test this all a bit further.

Yes, I'll mention that, and update the documentation.

> > I asked AI to find an example of using N in the group part of nodelist
> > description, and it found nothing deployed. I asked to check all distros
> > and major apps that would immediately observe this switch to runtime
> > nr_node_ids, and it found nothing again.
> >
>
> "clanker says this breaks nothing in distro code" is not good evidence
> because we don't know else is using these interfaces.
>
> It's good data, but not itself an argument to go forcefully changing the
> ABI without discussion.
>
> I'm otherwise ok with the overall direction of this, I just don't want
> to overlook these rough edges.

We've got our own judgment, clanker's opinion, then -next, then 2 month of
RCs, and almost a year on master before this change gets to major distros.
We can revert or fix any regression anytime during deployment cycle.