Commit b9e63d6c authored by Ranjan Kumar's avatar Ranjan Kumar Committed by Martin K. Petersen

scsi: mpi3mr: Validate SAS port assignments

A sanity check on phy_mask was added in commit 3668651d ("scsi:
mpi3mr: Sanitise num_phys"). This causes warning messages when more than
64 phys are detected and devices connected to phys greater than 64 are
dropped.

The phy_mask bitmap is only needed for controller phys and not required
for expander phys. Controller phys can go up to a maximum of 64 and
therefore u64 is good enough to contain phy_mask bitmap.

To suppress those warnings and allow devices to be discovered as before
the offending commit, restrict the phy_mask setting and lowest phy
setting only to the controller phys.

Fixes: 3668651d ("scsi: mpi3mr: Sanitise num_phys")
Cc: stable@vger.kernel.org
Reported-by: default avatarkernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202410051943.Mp9o5DlF-lkp@intel.com/Reported-by: default avatarAlexander Motin <mav@ixsystems.com>
Signed-off-by: default avatarRanjan Kumar <ranjan.kumar@broadcom.com>
Link: https://lore.kernel.org/r/20241008074353.200379-1-ranjan.kumar@broadcom.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 19a198b6
...@@ -542,8 +542,8 @@ struct mpi3mr_hba_port { ...@@ -542,8 +542,8 @@ struct mpi3mr_hba_port {
* @port_list: List of ports belonging to a SAS node * @port_list: List of ports belonging to a SAS node
* @num_phys: Number of phys associated with port * @num_phys: Number of phys associated with port
* @marked_responding: used while refresing the sas ports * @marked_responding: used while refresing the sas ports
* @lowest_phy: lowest phy ID of current sas port * @lowest_phy: lowest phy ID of current sas port, valid for controller port
* @phy_mask: phy_mask of current sas port * @phy_mask: phy_mask of current sas port, valid for controller port
* @hba_port: HBA port entry * @hba_port: HBA port entry
* @remote_identify: Attached device identification * @remote_identify: Attached device identification
* @rphy: SAS transport layer rphy object * @rphy: SAS transport layer rphy object
......
...@@ -590,12 +590,13 @@ static enum sas_linkrate mpi3mr_convert_phy_link_rate(u8 link_rate) ...@@ -590,12 +590,13 @@ static enum sas_linkrate mpi3mr_convert_phy_link_rate(u8 link_rate)
* @mrioc: Adapter instance reference * @mrioc: Adapter instance reference
* @mr_sas_port: Internal Port object * @mr_sas_port: Internal Port object
* @mr_sas_phy: Internal Phy object * @mr_sas_phy: Internal Phy object
* @host_node: Flag to indicate this is a host_node
* *
* Return: None. * Return: None.
*/ */
static void mpi3mr_delete_sas_phy(struct mpi3mr_ioc *mrioc, static void mpi3mr_delete_sas_phy(struct mpi3mr_ioc *mrioc,
struct mpi3mr_sas_port *mr_sas_port, struct mpi3mr_sas_port *mr_sas_port,
struct mpi3mr_sas_phy *mr_sas_phy) struct mpi3mr_sas_phy *mr_sas_phy, u8 host_node)
{ {
u64 sas_address = mr_sas_port->remote_identify.sas_address; u64 sas_address = mr_sas_port->remote_identify.sas_address;
...@@ -605,9 +606,13 @@ static void mpi3mr_delete_sas_phy(struct mpi3mr_ioc *mrioc, ...@@ -605,9 +606,13 @@ static void mpi3mr_delete_sas_phy(struct mpi3mr_ioc *mrioc,
list_del(&mr_sas_phy->port_siblings); list_del(&mr_sas_phy->port_siblings);
mr_sas_port->num_phys--; mr_sas_port->num_phys--;
if (host_node) {
mr_sas_port->phy_mask &= ~(1 << mr_sas_phy->phy_id); mr_sas_port->phy_mask &= ~(1 << mr_sas_phy->phy_id);
if (mr_sas_port->lowest_phy == mr_sas_phy->phy_id) if (mr_sas_port->lowest_phy == mr_sas_phy->phy_id)
mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1; mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1;
}
sas_port_delete_phy(mr_sas_port->port, mr_sas_phy->phy); sas_port_delete_phy(mr_sas_port->port, mr_sas_phy->phy);
mr_sas_phy->phy_belongs_to_port = 0; mr_sas_phy->phy_belongs_to_port = 0;
} }
...@@ -617,12 +622,13 @@ static void mpi3mr_delete_sas_phy(struct mpi3mr_ioc *mrioc, ...@@ -617,12 +622,13 @@ static void mpi3mr_delete_sas_phy(struct mpi3mr_ioc *mrioc,
* @mrioc: Adapter instance reference * @mrioc: Adapter instance reference
* @mr_sas_port: Internal Port object * @mr_sas_port: Internal Port object
* @mr_sas_phy: Internal Phy object * @mr_sas_phy: Internal Phy object
* @host_node: Flag to indicate this is a host_node
* *
* Return: None. * Return: None.
*/ */
static void mpi3mr_add_sas_phy(struct mpi3mr_ioc *mrioc, static void mpi3mr_add_sas_phy(struct mpi3mr_ioc *mrioc,
struct mpi3mr_sas_port *mr_sas_port, struct mpi3mr_sas_port *mr_sas_port,
struct mpi3mr_sas_phy *mr_sas_phy) struct mpi3mr_sas_phy *mr_sas_phy, u8 host_node)
{ {
u64 sas_address = mr_sas_port->remote_identify.sas_address; u64 sas_address = mr_sas_port->remote_identify.sas_address;
...@@ -632,9 +638,12 @@ static void mpi3mr_add_sas_phy(struct mpi3mr_ioc *mrioc, ...@@ -632,9 +638,12 @@ static void mpi3mr_add_sas_phy(struct mpi3mr_ioc *mrioc,
list_add_tail(&mr_sas_phy->port_siblings, &mr_sas_port->phy_list); list_add_tail(&mr_sas_phy->port_siblings, &mr_sas_port->phy_list);
mr_sas_port->num_phys++; mr_sas_port->num_phys++;
if (host_node) {
mr_sas_port->phy_mask |= (1 << mr_sas_phy->phy_id); mr_sas_port->phy_mask |= (1 << mr_sas_phy->phy_id);
if (mr_sas_phy->phy_id < mr_sas_port->lowest_phy) if (mr_sas_phy->phy_id < mr_sas_port->lowest_phy)
mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1; mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1;
}
sas_port_add_phy(mr_sas_port->port, mr_sas_phy->phy); sas_port_add_phy(mr_sas_port->port, mr_sas_phy->phy);
mr_sas_phy->phy_belongs_to_port = 1; mr_sas_phy->phy_belongs_to_port = 1;
} }
...@@ -675,7 +684,7 @@ static void mpi3mr_add_phy_to_an_existing_port(struct mpi3mr_ioc *mrioc, ...@@ -675,7 +684,7 @@ static void mpi3mr_add_phy_to_an_existing_port(struct mpi3mr_ioc *mrioc,
if (srch_phy == mr_sas_phy) if (srch_phy == mr_sas_phy)
return; return;
} }
mpi3mr_add_sas_phy(mrioc, mr_sas_port, mr_sas_phy); mpi3mr_add_sas_phy(mrioc, mr_sas_port, mr_sas_phy, mr_sas_node->host_node);
return; return;
} }
} }
...@@ -736,7 +745,7 @@ static void mpi3mr_del_phy_from_an_existing_port(struct mpi3mr_ioc *mrioc, ...@@ -736,7 +745,7 @@ static void mpi3mr_del_phy_from_an_existing_port(struct mpi3mr_ioc *mrioc,
mpi3mr_delete_sas_port(mrioc, mr_sas_port); mpi3mr_delete_sas_port(mrioc, mr_sas_port);
else else
mpi3mr_delete_sas_phy(mrioc, mr_sas_port, mpi3mr_delete_sas_phy(mrioc, mr_sas_port,
mr_sas_phy); mr_sas_phy, mr_sas_node->host_node);
return; return;
} }
} }
...@@ -1028,7 +1037,7 @@ mpi3mr_alloc_hba_port(struct mpi3mr_ioc *mrioc, u16 port_id) ...@@ -1028,7 +1037,7 @@ mpi3mr_alloc_hba_port(struct mpi3mr_ioc *mrioc, u16 port_id)
/** /**
* mpi3mr_get_hba_port_by_id - find hba port by id * mpi3mr_get_hba_port_by_id - find hba port by id
* @mrioc: Adapter instance reference * @mrioc: Adapter instance reference
* @port_id - Port ID to search * @port_id: Port ID to search
* *
* Return: mpi3mr_hba_port reference for the matched port * Return: mpi3mr_hba_port reference for the matched port
*/ */
...@@ -1367,7 +1376,8 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc, ...@@ -1367,7 +1376,8 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
mpi3mr_sas_port_sanity_check(mrioc, mr_sas_node, mpi3mr_sas_port_sanity_check(mrioc, mr_sas_node,
mr_sas_port->remote_identify.sas_address, hba_port); mr_sas_port->remote_identify.sas_address, hba_port);
if (mr_sas_node->num_phys >= sizeof(mr_sas_port->phy_mask) * 8) if (mr_sas_node->host_node && mr_sas_node->num_phys >=
sizeof(mr_sas_port->phy_mask) * 8)
ioc_info(mrioc, "max port count %u could be too high\n", ioc_info(mrioc, "max port count %u could be too high\n",
mr_sas_node->num_phys); mr_sas_node->num_phys);
...@@ -1377,7 +1387,7 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc, ...@@ -1377,7 +1387,7 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
(mr_sas_node->phy[i].hba_port != hba_port)) (mr_sas_node->phy[i].hba_port != hba_port))
continue; continue;
if (i >= sizeof(mr_sas_port->phy_mask) * 8) { if (mr_sas_node->host_node && (i >= sizeof(mr_sas_port->phy_mask) * 8)) {
ioc_warn(mrioc, "skipping port %u, max allowed value is %zu\n", ioc_warn(mrioc, "skipping port %u, max allowed value is %zu\n",
i, sizeof(mr_sas_port->phy_mask) * 8); i, sizeof(mr_sas_port->phy_mask) * 8);
goto out_fail; goto out_fail;
...@@ -1385,6 +1395,7 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc, ...@@ -1385,6 +1395,7 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
list_add_tail(&mr_sas_node->phy[i].port_siblings, list_add_tail(&mr_sas_node->phy[i].port_siblings,
&mr_sas_port->phy_list); &mr_sas_port->phy_list);
mr_sas_port->num_phys++; mr_sas_port->num_phys++;
if (mr_sas_node->host_node)
mr_sas_port->phy_mask |= (1 << i); mr_sas_port->phy_mask |= (1 << i);
} }
...@@ -1394,6 +1405,7 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc, ...@@ -1394,6 +1405,7 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
goto out_fail; goto out_fail;
} }
if (mr_sas_node->host_node)
mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1; mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1;
if (mr_sas_port->remote_identify.device_type == SAS_END_DEVICE) { if (mr_sas_port->remote_identify.device_type == SAS_END_DEVICE) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment