]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: mana: hardening: Reject zero max_num_queues from GDMA_QUERY_MAX_RESOURCES
authorErni Sri Satya Vennela <ernis@linux.microsoft.com>
Thu, 30 Apr 2026 08:36:21 +0000 (01:36 -0700)
committerJakub Kicinski <kuba@kernel.org>
Tue, 5 May 2026 02:13:36 +0000 (19:13 -0700)
In a CVM environment, hardware responses cannot be trusted. The
GDMA_QUERY_MAX_RESOURCES command returns resource limits used to
determine the maximum number of queues.

In mana_gd_query_max_resources(), gc->max_num_queues is initialized
from num_online_cpus() and successively clamped by the hardware-reported
max_eq, max_cq, max_sq, max_rq, and num_msix_usable values. If any of
these hardware values is zero, gc->max_num_queues becomes zero and the
function returns success. This leads to a confusing failure later when
alloc_etherdev_mq() is called with zero queues, returning NULL and
producing a misleading -ENOMEM error.

Add an explicit zero check for gc->max_num_queues after all clamping
steps and return -ENOSPC for a clear early failure, consistent with the
existing gc->num_msix_usable <= 1 guard.

Signed-off-by: Erni Sri Satya Vennela <ernis@linux.microsoft.com>
Reviewed-by: Shradha Gupta <shradhagupta@linux.microsoft.com>
Link: https://patch.msgid.link/20260430083627.1873757-1-ernis@linux.microsoft.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/microsoft/mana/gdma_main.c

index 098fbda0d128a53d7d7f90ffc0838711792c1e22..f3316e929175adb6ac2d1f59e44d8ca45ab514e7 100644 (file)
@@ -194,6 +194,9 @@ static int mana_gd_query_max_resources(struct pci_dev *pdev)
        if (gc->max_num_queues > gc->num_msix_usable - 1)
                gc->max_num_queues = gc->num_msix_usable - 1;
 
+       if (gc->max_num_queues == 0)
+               return -ENOSPC;
+
        return 0;
 }