Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Nilay Shroff <nilay@linux.ibm.com>
To: Keith Busch <kbusch@kernel.org>
Cc: linux-nvme@lists.infradead.org, hch@lst.de, axboe@fb.com,
	sagi@grimberg.me, gjoyce@linux.ibm.com, mkchauras@linux.ibm.com
Subject: Re: [PATCH] nvme-multipath: fix flex array size in struct nvme_ns_head
Date: Wed, 27 May 2026 20:36:43 +0530	[thread overview]
Message-ID: <aa4f6003-ffce-41dd-8b79-1f0eaa3a40e6@linux.ibm.com> (raw)
In-Reply-To: <ahb2UTQsJywNagyk@kbusch-mbp>

On 5/27/26 7:19 PM, Keith Busch wrote:
> On Wed, May 27, 2026 at 11:50:00AM +0530, Nilay Shroff wrote:
>> Fix this by allocating the flexible array using nr_node_ids instead
>> of num_possible_nodes(). Since nr_node_ids represents the maximum
>> possible NUMA node IDs, indexing current_path[] using numa_node_id()
>> becomes safe even on systems with sparse node IDs.
> 
> What is the largest nr_node_ids we can reasonably expect to see? I don't
> want to end up trying to allocate a billion entry sparse array just to
> index a tiny fraction of them. Not that we didn't have a similar problem
> before, but this patch makes it clear we haven't been checking.

The nr_node_ids value is bounded by MAX_NUMNODES, which is a compile-time
constant derived from CONFIG_NODES_SHIFT:

#define MAX_NUMNODES    (1 << CONFIG_NODES_SHIFT)

nr_node_ids itself cannot exceed MAX_NUMNODES.

For example:

x86 (arch/x86/Kconfig):
config NODES_SHIFT
         int "Maximum NUMA Nodes (as a power of 2)" if !MAXSMP
         range 1 10
         default "10" if MAXSMP
         default "6" if X86_64
         default "3"
         depends on NUMA

arm64 (arch/arm64/Kconfig):
config NODES_SHIFT
         int "Maximum NUMA Nodes (as a power of 2)"
         range 1 10
         default "4"
         depends on NUMA

powerpc (arch/powerpc/Kconfig):
config NODES_SHIFT
         int
         default "8" if PPC64
         default "4"
         depends on NUMA

Looking across the architectures supported by Linux, CONFIG_NODES_SHIFT
appears to be capped at 10, which gives:

MAX_NUMNODES = 1 << 10 = 1024

So in practice, nr_node_ids should not exceed 1024.

This means the flexible array allocation remains bounded and should not grow
into an unreasonably large sparse allocation.

Thanks,
--Nilay



  reply	other threads:[~2026-05-27 15:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-27  6:20 [PATCH] nvme-multipath: fix flex array size in struct nvme_ns_head Nilay Shroff
2026-05-27  6:40 ` Christoph Hellwig
2026-05-27  7:30 ` John Garry
2026-05-27  8:04 ` Mukesh Kumar Chaurasiya
2026-05-27 13:36 ` Hannes Reinecke
2026-05-27 13:49 ` Keith Busch
2026-05-27 15:06   ` Nilay Shroff [this message]
2026-05-27 15:15     ` Keith Busch

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=aa4f6003-ffce-41dd-8b79-1f0eaa3a40e6@linux.ibm.com \
    --to=nilay@linux.ibm.com \
    --cc=axboe@fb.com \
    --cc=gjoyce@linux.ibm.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=mkchauras@linux.ibm.com \
    --cc=sagi@grimberg.me \
    /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