mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scsi: mpt3sas: Fix invalid NUMA node index
@ 2025-12-30  3:14 Haotian Zhang
  2025-12-30  7:45 ` John Garry
  0 siblings, 1 reply; 4+ messages in thread
From: Haotian Zhang @ 2025-12-30  3:14 UTC (permalink / raw)
  To: Sathya Prakash, Sreekanth Reddy, Suganath Prabu Subramani,
	James E . J . Bottomley, Martin K . Petersen
  Cc: MPT-FusionLinux.pdl, linux-scsi, linux-kernel, Haotian Zhang

When dev_to_node() returns NUMA_NO_NODE (-1), passing it directly to
cpumask_of_node() causes an array index out-of-bounds access.

Check for NUMA_NO_NODE and fall back to node 0 if detected.

Fixes: fdb8ed13a772 ("scsi: mpt3sas: Use irq_set_affinity_and_hint()")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 0d652db8fe24..3fe071e8490d 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -3238,7 +3238,11 @@ _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc)
 		 * corresponding to high iops queues.
 		 */
 		if (ioc->high_iops_queues) {
-			mask = cpumask_of_node(dev_to_node(&ioc->pdev->dev));
+			int nid = dev_to_node(&ioc->pdev->dev);
+
+			if (nid == NUMA_NO_NODE)
+				nid = 0;
+			mask = cpumask_of_node(nid);
 			for (index = 0; index < ioc->high_iops_queues;
 			    index++) {
 				irq = pci_irq_vector(ioc->pdev, index);
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scsi: mpt3sas: Fix invalid NUMA node index
  2025-12-30  3:14 [PATCH] scsi: mpt3sas: Fix invalid NUMA node index Haotian Zhang
@ 2025-12-30  7:45 ` John Garry
       [not found]   ` <SE5P216MB338083B78B7FFF35811F70A3FCBCA@SE5P216MB3380.KORP216.PROD.OUTLOOK.COM>
  0 siblings, 1 reply; 4+ messages in thread
From: John Garry @ 2025-12-30  7:45 UTC (permalink / raw)
  To: Haotian Zhang, Sathya Prakash, Sreekanth Reddy,
	Suganath Prabu Subramani, James E . J . Bottomley,
	Martin K . Petersen
  Cc: MPT-FusionLinux.pdl, linux-scsi, linux-kernel

On 30/12/2025 03:14, Haotian Zhang wrote:
> When dev_to_node() returns NUMA_NO_NODE (-1), passing it directly to
> cpumask_of_node() causes an array index out-of-bounds access.
> 
> Check for NUMA_NO_NODE and fall back to node 0 if detected.
> 
> Fixes: fdb8ed13a772 ("scsi: mpt3sas: Use irq_set_affinity_and_hint()")
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
> ---
>   drivers/scsi/mpt3sas/mpt3sas_base.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
> index 0d652db8fe24..3fe071e8490d 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
> @@ -3238,7 +3238,11 @@ _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc)
>   		 * corresponding to high iops queues.
>   		 */
>   		if (ioc->high_iops_queues) {
> -			mask = cpumask_of_node(dev_to_node(&ioc->pdev->dev));
> +			int nid = dev_to_node(&ioc->pdev->dev);
> +
> +			if (nid == NUMA_NO_NODE)
> +				nid = 0;
> +			mask = cpumask_of_node(nid);

Some versions of cpumask_of_node() handle NUMA_NO_NODE gracefully and 
some don't.

For the core drivers/base/arch_numa.c version, it returns cpu_all_mask 
(for NUMA_NO_NODE) - so your behaviour here is different.

Anyway, how about audit all versions of cpumask_of_node() to handle 
NUMA_NO_NODE gracefully?

>   			for (index = 0; index < ioc->high_iops_queues;
>   			    index++) {
>   				irq = pci_irq_vector(ioc->pdev, index);


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: 回复: [PATCH] scsi: mpt3sas: Fix invalid NUMA node index
       [not found]   ` <SE5P216MB338083B78B7FFF35811F70A3FCBCA@SE5P216MB3380.KORP216.PROD.OUTLOOK.COM>
@ 2026-01-02 10:33     ` John Garry
  2026-01-26  8:33     ` John Garry
  1 sibling, 0 replies; 4+ messages in thread
From: John Garry @ 2026-01-02 10:33 UTC (permalink / raw)
  To: vulab
  Cc: sathya.prakash, sreekanth.reddy, suganath-prabu.subramani,
	James.Bottomley, martin.petersen, MPT-FusionLinux.pdl,
	linux-scsi, linux-kernel

On 31/12/2025 01:19, vulab@iscas.ac.cn wrote:
> Hi John,
> 
> Thank you for the feedback.
> 
> Regarding the suggestion to audit all cpumask_of_node() implementations:
> 
> I noticed that a very similar issue was recently fixed in the
> megaraid_sas driver (commit 752eb816b55a, "scsi: megaraid_sas: Fix
> invalid node index"), where an UBSAN array-index-out-of-bounds warning
> was addressed by handling NUMA_NO_NODE locally in the driver.
> 
> Following that approach, it seems reasonable for mpt3sas to handle
> this case locally as well, while leaving any broader unification of
> cpumask_of_node() semantics across architectures as a separate
> discussion, since changes in the x86 topology headers may have wider
> impact.
> 
> Regarding the fallback behavior:
> 
> The existing megaraid_sas fix falls back to node 0, but as you pointed
> out, some implementations (e.g. drivers/base/arch_numa.c) treat
> NUMA_NO_NODE as indicating no specific NUMA locality and return
> cpu_all_mask. Forcing node 0 in this case may unnecessarily constrain
> interrupt affinity on NUMA systems.
> 
> For a v2, I propose to:
> 
> 
>    1.
> Fix the issue locally in the mpt3sas driver (similar to
> 
> megaraid_sas); and
> 
> 
>    1.
> Use cpu_online_mask as the fallback when dev_to_node() returns
> 
> NUMA_NO_NODE, to  better match the intended semantics, while still
> preventing out-of-bounds access.
> 
> Please let me know if this sounds acceptable.

I am not the driver maintainer, so it is not my choice.

But I will try to remedy this in the per-arch code if you don't want to.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: 回复: [PATCH] scsi: mpt3sas: Fix invalid NUMA node index
       [not found]   ` <SE5P216MB338083B78B7FFF35811F70A3FCBCA@SE5P216MB3380.KORP216.PROD.OUTLOOK.COM>
  2026-01-02 10:33     ` 回复: " John Garry
@ 2026-01-26  8:33     ` John Garry
  1 sibling, 0 replies; 4+ messages in thread
From: John Garry @ 2026-01-26  8:33 UTC (permalink / raw)
  To: vulab
  Cc: sathya.prakash, sreekanth.reddy, suganath-prabu.subramani,
	James.Bottomley, martin.petersen, MPT-FusionLinux.pdl,
	linux-scsi, linux-kernel

>>                  */
>>                 if (ioc->high_iops_queues) {
>> -                     mask = cpumask_of_node(dev_to_node(&ioc->pdev->dev));
>> +                     int nid = dev_to_node(&ioc->pdev->dev);
>> +
>> +                     if (nid == NUMA_NO_NODE)
>> +                             nid = 0;
>> +                     mask = cpumask_of_node(nid);
> 
> Some versions of cpumask_of_node() handle NUMA_NO_NODE gracefully and
> some don't.
> 
> For the core drivers/base/arch_numa.c version, it returns cpu_all_mask
> (for NUMA_NO_NODE) - so your behaviour here is different.

I sent a series to make all versions of cpumask_of_node() handle 
NUMA_NO_NODE:
https://lore.kernel.org/lkml/20260107094007.966496-1-john.g.garry@oracle.com/

Please check it and provide Tested-by/Reviewed-by tags if you are happy 
with it.

Thanks,
John

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-26  8:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-30  3:14 [PATCH] scsi: mpt3sas: Fix invalid NUMA node index Haotian Zhang
2025-12-30  7:45 ` John Garry
     [not found]   ` <SE5P216MB338083B78B7FFF35811F70A3FCBCA@SE5P216MB3380.KORP216.PROD.OUTLOOK.COM>
2026-01-02 10:33     ` 回复: " John Garry
2026-01-26  8:33     ` John Garry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®