qla2x00t-32gbit: Clamp max_npiv_vports to VP_CTRL bitmap capacity

ha->max_npiv_vports is taken from firmware (mcp->mb[11]) and only
constrained so that (max_npiv_vports + 1) is a multiple of
MIN_MULTI_ID_FABRIC, which permits values of 63, 127, 191 and 255.
NPIV vports are then allocated up to that count.

VP enable uses the VP_CONFIG IOCB, which addresses a vport through a
plain vp_index byte, so a vp_index beyond 128 is enabled without issue.
VP disable, however, uses the VP_CTRL IOCB, which selects target vports
through the fixed 128-bit vp_idx_map bitmap. qla24xx_control_vp()
rejects a vp_index past that bitmap and the IOCB builder cannot set a bit
beyond 127, yet qla24xx_vport_delete() frees the local state regardless.
A vport with vp_index > 128 can therefore be created and enabled but
never disabled, leaving it permanently active in firmware: a resource
leak.

Cap ha->max_npiv_vports at init to the vp_idx_map capacity so such
vports are never created. This collapses 191/255 to 127 (still
modulo-valid) and leaves the real-world 63/127 cases unaffected.

Fixes: 4d0ea24769c8 ("[SCSI] qla2xxx: Retrieve max-NPIV support capabilities from FW.")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-dev@google.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Link: https://patch.msgid.link/20260730155838.2119230-20-njavali@marvell.com
Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>

[ commit 2ac6a829843cf3df522d19e091276109b94c4c7a upstream ]
This commit is contained in:
Nilesh Javali
2026-10-19 18:07:58 +03:00
committed by Gleb Chesnokov
parent bc8ceb8a60
commit c76c32f94d
3 changed files with 18 additions and 1 deletions
+4
View File
@@ -1452,6 +1452,10 @@ struct vp_ctrl_entry_24xx {
uint8_t reserved_5[24];
};
/* vp_idx_map is a 128-bit (16-byte) bitmap selecting target VPs. */
#define VP_CTRL_IDX_MAP_BITS \
(sizeof_field(struct vp_ctrl_entry_24xx, vp_idx_map) * 8)
/*
* Modify Virtual Port Configuration IOCB
*/
+13
View File
@@ -4416,6 +4416,19 @@ enable_82xx_npiv:
MIN_MULTI_ID_FABRIC))
ha->max_npiv_vports =
MIN_MULTI_ID_FABRIC - 1;
/*
* The VP_CTRL IOCB selects target VPs
* through the fixed vp_idx_map bitmap,
* so a vp_index beyond it can be enabled
* via VP_CONFIG but never disabled via
* VP_CTRL, leaking the VP. Cap the count
* to the bitmap capacity.
*/
if (ha->max_npiv_vports >=
VP_CTRL_IDX_MAP_BITS)
ha->max_npiv_vports =
VP_CTRL_IDX_MAP_BITS - 1;
}
qlt_config_nvram_with_fw_version(vha);
qla2x00_get_resource_cnts(vha);
+1 -1
View File
@@ -996,7 +996,7 @@ int qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
* (16-byte) vp_idx_map bitmap, so vp_index must fit within it even
* if firmware advertises more NPIV vports.
*/
if (vp_index > sizeof_field(struct vp_ctrl_entry_24xx, vp_idx_map) * 8)
if (vp_index > VP_CTRL_IDX_MAP_BITS)
return QLA_PARAMETER_ERROR;
/* ref: INIT */