Linux CXL
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rakie Kim" <rakie.kim@sk.com>
Cc: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev
Subject: Re: [PATCH 1/4] mm/numa: introduce nearest_nodes_nodemask()
Date: Thu, 06 Aug 2026 08:22:24 +0000	[thread overview]
Message-ID: <20260806082224.AFAC71F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260806080936.421-2-rakie.kim@sk.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The function fails silently if the input and output nodemasks alias, wiping the input.
- [Low] The non-NUMA fallback implementation incorrectly reports an empty mask for valid inputs.
--

--- Patch [1]: [PATCH 1/4] mm/numa: introduce nearest_nodes_nodemask() ---
commit 5ec50dc5c5bbc33fbae64a16296aa9f2dc086600
Author: Rakie Kim <rakie.kim@sk.com>

mm/numa: introduce nearest_nodes_nodemask()

This commit introduces nearest_nodes_nodemask(), a helper function that
finds all candidate nodes in a given nodemask located at the minimum
distance from a source node. It updates an output nodemask with the complete
set of nearest nodes, returning 0 on success.

> diff --git a/include/linux/numa.h b/include/linux/numa.h
> index e6baaf6051bcf..4f2a0c344122a 100644
> --- a/include/linux/numa.h
> +++ b/include/linux/numa.h
[ ... ]
> @@ -54,6 +56,15 @@ static inline int nearest_node_nodemask(int node, nodemask_t *mask)
>  	return NUMA_NO_NODE;
>  }
>  
> +static inline int nearest_nodes_nodemask(int node, const nodemask_t *mask,
> +					 nodemask_t *out)
> +{
> +	if (!out)
> +		return -EINVAL;
> +	nodes_clear(*out);

[Severity: Low]
On systems with CONFIG_NUMA disabled, there is only a single implicit node
(Node 0). If a caller passes an input mask containing Node 0, that node is
trivially the nearest.

Should this fallback stub preserve the valid node from the input mask
instead of unconditionally clearing the output mask and falsely reporting no
nearest nodes?

> +	return 0;
> +}
> +
>  static inline int memory_add_physaddr_to_nid(u64 start)
>  {
>  	return 0;
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 4e4421b22b59f..19417b0afc30b 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
[ ... ]
> +int nearest_nodes_nodemask(int node, const nodemask_t *mask, nodemask_t *out)
> +{
> +	int dist, n, min_dist = INT_MAX;
> +
> +	if (!out)
> +		return -EINVAL;
> +
> +	nodes_clear(*out);

[Severity: Medium]
What happens if a caller attempts to filter a nodemask in-place by passing
the same pointer for both the input and output masks?

In-place filtering is a common pattern in the kernel (for example, with
nodes_and()), but if nearest_nodes_nodemask(node, &my_mask, &my_mask) is
called, this initial nodes_clear(*out) will wipe out the input mask before
the loop even begins iterating.

> +
> +	for_each_node_mask(n, *mask) {
> +		dist = node_distance(node, n);
> +
> +		if (dist < min_dist) {
> +			min_dist = dist;
> +			nodes_clear(*out);

[Severity: Medium]
Similarly, if the input and output pointers alias, clearing the output mask
dynamically here destroys the remaining iteration state for the for_each
loop.

Could this be avoided by using a temporary nodemask on the stack,
and copying it to *out at the end of the function?

> +			node_set(n, *out);
> +		} else if (dist == min_dist) {
> +			node_set(n, *out);
> +		}
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(nearest_nodes_nodemask);
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260806080936.421-1-rakie.kim@sk.com?part=1

  reply	other threads:[~2026-08-06  8:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06  8:09 [PATCH 0/4] mm/mempolicy: introduce package-aware weighted interleave Rakie Kim
2026-08-06  8:09 ` [PATCH 1/4] mm/numa: introduce nearest_nodes_nodemask() Rakie Kim
2026-08-06  8:22   ` sashiko-bot [this message]
2026-08-06  8:09 ` [PATCH 2/4] mm/memory-tiers: introduce package-aware topology management for NUMA nodes Rakie Kim
2026-08-06  8:22   ` sashiko-bot
2026-08-06  8:09 ` [PATCH 3/4] mm/memory-tiers: register CXL nodes to memory packages via initiator Rakie Kim
2026-08-06  8:32   ` sashiko-bot
2026-08-06  8:09 ` [PATCH 4/4] mm/mempolicy: enhance weighted interleave with package-aware locality Rakie Kim
2026-08-06  8:28   ` sashiko-bot
2026-08-06 21:38 ` [PATCH 0/4] mm/mempolicy: introduce package-aware weighted interleave Andrew Morton
2026-08-07  4:07   ` Rakie Kim

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=20260806082224.AFAC71F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=rakie.kim@sk.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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