2024-03-12 14:13:58

by yangxingui

[permalink] [raw]
Subject: [PATCH v6 0/4] scsi: libsas: Fix the failure of adding phy with zero-address to port

This series is to solve the problem of a BUG() when adding phy with zero
address to a new port.

v5 -> v6
1. rename sas_add_parent_port() to sas_ex_add_parent_port() based on
John's suggestion.
2. Distill port settings into a single patch.
3. Update comments information.

v4 -> v5
1. Add new helper sas_port_add_ex_phy() based on John's suggestion.
2. Move sas_add_parent_port() to sas_expander.c based on John's suggestion.
3. Update the comments.

v3 -> v4:
1. Update patch title and comments based on John's suggestion.

v2 -> v3:
1. Set ex_dev->parent_port to NULL when the number of PHYs of the parent
port becomes 0.
2. Update the comments.

v1 -> v2:
1. Set ex_phy->port with parent_port when ex_phy is added to the parent
port.
2. Set ex_phy to NULL when free expander.
3. Update the comments.

Xingui Yang (4):
scsi: libsas: Add helper for port add ex_phy
scsi: libsas: Move sas_add_parent_port() to sas_expander.c
scsi: libsas: Set port when ex_phy is added or deleted
scsi: libsas: Fix the failure of adding phy with zero-address to port

drivers/scsi/libsas/sas_expander.c | 38 +++++++++++++++++++++++-------
drivers/scsi/libsas/sas_internal.h | 15 ------------
2 files changed, 30 insertions(+), 23 deletions(-)

--
2.17.1



2024-03-12 14:14:21

by yangxingui

[permalink] [raw]
Subject: [PATCH v6 3/4] scsi: libsas: Set port when ex_phy is added or deleted

We found that when ex_phy was attached and added to the parent wide port,
ex_phy->port was not set, resulting in sas_unregister_devs_sas_addr() not
calling sas_port_delete_phy() when deleting the phy, and the deleted phy
was still on the parent wide port's phy_list.

When we use sas_port_add_ex_phy() to set ex_phy->port to solve the above
problem, we find that after all the phys of the parent_port are removed and
the number of phy becomes 0, the parent_port will not be set to NULL.
Causes the freed parent port to be used when attaching a new ex_phy in
sas_ex_add_parent_port().

So use sas_port_add_ex_phy() instead of sas_port_add_phy() to set
ex_phy->port when ex_phy is added to the parent port, and set
ex_dev->parent_port to NULL when the number of phy on the port becomes 0.

Signed-off-by: Xingui Yang <[email protected]>
---
drivers/scsi/libsas/sas_expander.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index f28a83803947..77daae36232b 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -45,7 +45,7 @@ static void sas_ex_add_parent_port(struct domain_device *dev, int phy_id)
BUG_ON(sas_port_add(ex->parent_port));
sas_port_mark_backlink(ex->parent_port);
}
- sas_port_add_phy(ex->parent_port, ex_phy->phy);
+ sas_port_add_ex_phy(ex->parent_port, ex_phy);
}

/* ---------- SMP task management ---------- */
@@ -1879,9 +1879,12 @@ static void sas_unregister_devs_sas_addr(struct domain_device *parent,
if (phy->port) {
sas_port_delete_phy(phy->port, phy->phy);
sas_device_set_phy(found, phy->port);
- if (phy->port->num_phys == 0)
+ if (phy->port->num_phys == 0) {
list_add_tail(&phy->port->del_list,
&parent->port->sas_port_del_list);
+ if (ex_dev->parent_port == phy->port)
+ ex_dev->parent_port = NULL;
+ }
phy->port = NULL;
}
}
--
2.17.1


2024-03-12 14:14:29

by yangxingui

[permalink] [raw]
Subject: [PATCH v6 1/4] scsi: libsas: Add helper for port add ex_phy

This moves the process of adding ex_phy to a port into a new helper.

Signed-off-by: Xingui Yang <[email protected]>
Reviewed-by: John Garry <[email protected]>
---
drivers/scsi/libsas/sas_expander.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index ee3808bfd534..c8d4aef2f567 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -26,6 +26,13 @@ static int sas_configure_phy(struct domain_device *dev, int phy_id,
u8 *sas_addr, int include);
static int sas_disable_routing(struct domain_device *dev, u8 *sas_addr);

+static void sas_port_add_ex_phy(struct sas_port *port, struct ex_phy *ex_phy)
+{
+ sas_port_add_phy(port, ex_phy->phy);
+ ex_phy->port = port;
+ ex_phy->phy_state = PHY_DEVICE_DISCOVERED;
+}
+
/* ---------- SMP task management ---------- */

/* Give it some long enough timeout. In seconds. */
@@ -867,9 +874,7 @@ static bool sas_ex_join_wide_port(struct domain_device *parent, int phy_id)

if (!memcmp(phy->attached_sas_addr, ephy->attached_sas_addr,
SAS_ADDR_SIZE) && ephy->port) {
- sas_port_add_phy(ephy->port, phy->phy);
- phy->port = ephy->port;
- phy->phy_state = PHY_DEVICE_DISCOVERED;
+ sas_port_add_ex_phy(ephy->port, phy);
return true;
}
}
--
2.17.1


2024-04-20 14:45:44

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH v6 0/4] scsi: libsas: Fix the failure of adding phy with zero-address to port


Xingui,

> This series is to solve the problem of a BUG() when adding phy with zero
> address to a new port.

Applied to 6.10/scsi-staging, thanks!

--
Martin K. Petersen Oracle Linux Engineering

2024-05-07 02:02:29

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH v6 0/4] scsi: libsas: Fix the failure of adding phy with zero-address to port

On Tue, 12 Mar 2024 14:10:59 +0000, Xingui Yang wrote:

> This series is to solve the problem of a BUG() when adding phy with zero
> address to a new port.
>
> v5 -> v6
> 1. rename sas_add_parent_port() to sas_ex_add_parent_port() based on
> John's suggestion.
> 2. Distill port settings into a single patch.
> 3. Update comments information.
>
> [...]

Applied to 6.10/scsi-queue, thanks!

[1/4] scsi: libsas: Add helper for port add ex_phy
https://git.kernel.org/mkp/scsi/c/888ea1b12b06
[2/4] scsi: libsas: Move sas_add_parent_port() to sas_expander.c
https://git.kernel.org/mkp/scsi/c/48032c0be6c7
[3/4] scsi: libsas: Set port when ex_phy is added or deleted
https://git.kernel.org/mkp/scsi/c/7a165a81d55f
[4/4] scsi: libsas: Fix the failure of adding phy with zero-address to port
https://git.kernel.org/mkp/scsi/c/06036a0a5db3

--
Martin K. Petersen Oracle Linux Engineering