[PATCH v6] numa: make node_to_cpumask_map() NUMA_NO_NODE aware
Paul Burton
paul.burton at mips.com
Sun Sep 22 08:38:20 AEST 2019
Hi Yunsheng,
On Tue, Sep 17, 2019 at 08:48:54PM +0800, Yunsheng Lin wrote:
> When passing the return value of dev_to_node() to cpumask_of_node()
> without checking if the device's node id is NUMA_NO_NODE, there is
> global-out-of-bounds detected by KASAN.
>
> From the discussion [1], NUMA_NO_NODE really means no node affinity,
> which also means all cpus should be usable. So the cpumask_of_node()
> should always return all cpus online when user passes the node id as
> NUMA_NO_NODE, just like similar semantic that page allocator handles
> NUMA_NO_NODE.
>
> But we cannot really copy the page allocator logic. Simply because the
> page allocator doesn't enforce the near node affinity. It just picks it
> up as a preferred node but then it is free to fallback to any other numa
> node. This is not the case here and node_to_cpumask_map will only restrict
> to the particular node's cpus which would have really non deterministic
> behavior depending on where the code is executed. So in fact we really
> want to return cpu_online_mask for NUMA_NO_NODE.
>
> Also there is a debugging version of node_to_cpumask_map() for x86 and
> arm64, which is only used when CONFIG_DEBUG_PER_CPU_MAPS is defined, this
> patch changes it to handle NUMA_NO_NODE as normal node_to_cpumask_map().
>
> [1] https://lore.kernel.org/patchwork/patch/1125789/
> Signed-off-by: Yunsheng Lin <linyunsheng at huawei.com>
> Suggested-by: Michal Hocko <mhocko at kernel.org>
> Acked-by: Michal Hocko <mhocko at suse.com>
If you end up sending another revision then I think it would be worth
replacing -1 with NUMA_NO_NODE in
arch/mips/include/asm/mach-ip27/topology.h for consistency, but in any
case:
Acked-by: Paul Burton <paul.burton at mips.com> # MIPS bits
Thanks,
Paul
> ---
> V6: Drop the cpu_all_mask -> cpu_online_mask change for it seems a
> little controversial, may need deeper investigation, and rebased
> on the latest linux-next.
> V5: Drop unsigned "fix" change for x86/arm64, and change comment log
> according to Michal's comment.
> V4: Have all these changes in a single patch.
> V3: Change to only handle NUMA_NO_NODE, and return cpu_online_mask
> for NUMA_NO_NODE case, and change the commit log to better justify
> the change.
> V2: make the node id checking change to other arches too.
> ---
> arch/arm64/include/asm/numa.h | 3 +++
> arch/arm64/mm/numa.c | 3 +++
> arch/mips/include/asm/mach-loongson64/topology.h | 4 +++-
> arch/s390/include/asm/topology.h | 3 +++
> arch/x86/include/asm/topology.h | 3 +++
> arch/x86/mm/numa.c | 3 +++
> 6 files changed, 18 insertions(+), 1 deletion(-)
More information about the Linuxppc-dev
mailing list