* [PATCH v6 0/4] scsi: libsas: Fix the failure of adding phy with zero-address to port
@ 2024-03-12 14:10 Xingui Yang
2024-03-12 14:11 ` [PATCH v6 1/4] scsi: libsas: Add helper for port add ex_phy Xingui Yang
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Xingui Yang @ 2024-03-12 14:10 UTC (permalink / raw)
To: john.g.garry, yanaijie, jejb, martin.petersen, damien.lemoal
Cc: linux-scsi, linux-kernel, linuxarm, prime.zeng, chenxiang66,
kangfenglong
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v6 1/4] scsi: libsas: Add helper for port add ex_phy
2024-03-12 14:10 [PATCH v6 0/4] scsi: libsas: Fix the failure of adding phy with zero-address to port Xingui Yang
@ 2024-03-12 14:11 ` Xingui Yang
2024-03-12 14:11 ` [PATCH v6 2/4] scsi: libsas: Move sas_add_parent_port() to sas_expander.c Xingui Yang
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Xingui Yang @ 2024-03-12 14:11 UTC (permalink / raw)
To: john.g.garry, yanaijie, jejb, martin.petersen, damien.lemoal
Cc: linux-scsi, linux-kernel, linuxarm, prime.zeng, chenxiang66,
kangfenglong
This moves the process of adding ex_phy to a port into a new helper.
Signed-off-by: Xingui Yang <yangxingui@huawei.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
---
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v6 2/4] scsi: libsas: Move sas_add_parent_port() to sas_expander.c
2024-03-12 14:10 [PATCH v6 0/4] scsi: libsas: Fix the failure of adding phy with zero-address to port Xingui Yang
2024-03-12 14:11 ` [PATCH v6 1/4] scsi: libsas: Add helper for port add ex_phy Xingui Yang
@ 2024-03-12 14:11 ` Xingui Yang
2024-03-12 14:11 ` [PATCH v6 3/4] scsi: libsas: Set port when ex_phy is added or deleted Xingui Yang
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Xingui Yang @ 2024-03-12 14:11 UTC (permalink / raw)
To: john.g.garry, yanaijie, jejb, martin.petersen, damien.lemoal
Cc: linux-scsi, linux-kernel, linuxarm, prime.zeng, chenxiang66,
kangfenglong
Move sas_add_parent_port() to sas_expander.c and rename it to
sas_ex_add_parent_port() as it is only used in this file.
Signed-off-by: Xingui Yang <yangxingui@huawei.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
---
drivers/scsi/libsas/sas_expander.c | 19 +++++++++++++++++--
drivers/scsi/libsas/sas_internal.h | 15 ---------------
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index c8d4aef2f567..f28a83803947 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -33,6 +33,21 @@ static void sas_port_add_ex_phy(struct sas_port *port, struct ex_phy *ex_phy)
ex_phy->phy_state = PHY_DEVICE_DISCOVERED;
}
+static void sas_ex_add_parent_port(struct domain_device *dev, int phy_id)
+{
+ struct expander_device *ex = &dev->ex_dev;
+ struct ex_phy *ex_phy = &ex->ex_phy[phy_id];
+
+ if (!ex->parent_port) {
+ ex->parent_port = sas_port_alloc(&dev->rphy->dev, phy_id);
+ /* FIXME: error handling */
+ BUG_ON(!ex->parent_port);
+ 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);
+}
+
/* ---------- SMP task management ---------- */
/* Give it some long enough timeout. In seconds. */
@@ -978,11 +993,11 @@ static int sas_ex_discover_dev(struct domain_device *dev, int phy_id)
/* Parent and domain coherency */
if (!dev->parent && sas_phy_match_port_addr(dev->port, ex_phy)) {
- sas_add_parent_port(dev, phy_id);
+ sas_ex_add_parent_port(dev, phy_id);
return 0;
}
if (dev->parent && sas_phy_match_dev_addr(dev->parent, ex_phy)) {
- sas_add_parent_port(dev, phy_id);
+ sas_ex_add_parent_port(dev, phy_id);
if (ex_phy->routing_attr == TABLE_ROUTING)
sas_configure_phy(dev, phy_id, dev->port->sas_addr, 1);
return 0;
diff --git a/drivers/scsi/libsas/sas_internal.h b/drivers/scsi/libsas/sas_internal.h
index 3804aef165ad..85948963fb97 100644
--- a/drivers/scsi/libsas/sas_internal.h
+++ b/drivers/scsi/libsas/sas_internal.h
@@ -189,21 +189,6 @@ static inline void sas_phy_set_target(struct asd_sas_phy *p, struct domain_devic
}
}
-static inline void sas_add_parent_port(struct domain_device *dev, int phy_id)
-{
- struct expander_device *ex = &dev->ex_dev;
- struct ex_phy *ex_phy = &ex->ex_phy[phy_id];
-
- if (!ex->parent_port) {
- ex->parent_port = sas_port_alloc(&dev->rphy->dev, phy_id);
- /* FIXME: error handling */
- BUG_ON(!ex->parent_port);
- 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);
-}
-
static inline struct domain_device *sas_alloc_device(void)
{
struct domain_device *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v6 3/4] scsi: libsas: Set port when ex_phy is added or deleted
2024-03-12 14:10 [PATCH v6 0/4] scsi: libsas: Fix the failure of adding phy with zero-address to port Xingui Yang
2024-03-12 14:11 ` [PATCH v6 1/4] scsi: libsas: Add helper for port add ex_phy Xingui Yang
2024-03-12 14:11 ` [PATCH v6 2/4] scsi: libsas: Move sas_add_parent_port() to sas_expander.c Xingui Yang
@ 2024-03-12 14:11 ` Xingui Yang
2024-03-12 14:11 ` [PATCH v6 4/4] scsi: libsas: Fix the failure of adding phy with zero-address to port Xingui Yang
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Xingui Yang @ 2024-03-12 14:11 UTC (permalink / raw)
To: john.g.garry, yanaijie, jejb, martin.petersen, damien.lemoal
Cc: linux-scsi, linux-kernel, linuxarm, prime.zeng, chenxiang66,
kangfenglong
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 <yangxingui@huawei.com>
---
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v6 4/4] scsi: libsas: Fix the failure of adding phy with zero-address to port
2024-03-12 14:10 [PATCH v6 0/4] scsi: libsas: Fix the failure of adding phy with zero-address to port Xingui Yang
` (2 preceding siblings ...)
2024-03-12 14:11 ` [PATCH v6 3/4] scsi: libsas: Set port when ex_phy is added or deleted Xingui Yang
@ 2024-03-12 14:11 ` Xingui Yang
2024-04-20 14:44 ` [PATCH v6 0/4] " Martin K. Petersen
2024-05-07 1:59 ` Martin K. Petersen
5 siblings, 0 replies; 7+ messages in thread
From: Xingui Yang @ 2024-03-12 14:11 UTC (permalink / raw)
To: john.g.garry, yanaijie, jejb, martin.petersen, damien.lemoal
Cc: linux-scsi, linux-kernel, linuxarm, prime.zeng, chenxiang66,
kangfenglong
As of commit 7d1d86518118 ("[SCSI] libsas: fix false positive 'device
attached' conditions"), reset the phy->entacted_sas_addr address to a
zero-address when the link rate is less than 1.5G.
Currently we find that when a new device is attached, and the link rate is
less than 1.5G, but the device type is not NO_DEVICE, for example: the link
rate is SAS_PHY_RESET_IN_PROGRESS and the device type is stp. After setting
the phy->entacted_sas_addr address to the zero address, the port will
continue to be created for the phy with the zero-address, and other phys
with the zero-address will be tried to be added to the new port:
[562240.051197] sas: ex 500e004aaaaaaa1f phy19:U:0 attached: 0000000000000000 (no device)
// phy19 is deleted but still on the parent port's phy_list
[562240.062536] sas: ex 500e004aaaaaaa1f phy0 new device attached
[562240.062616] sas: ex 500e004aaaaaaa1f phy00:U:5 attached: 0000000000000000 (stp)
[562240.062680] port-7:7:0: trying to add phy phy-7:7:19 fails: it's already part of another port
Therefore, it should be the same as sas_get_phy_attached_dev(). Only when
device_type is SAS_PHY_UNUSED, sas_address is set to the 0 address.
Fixes: 7d1d86518118 ("[SCSI] libsas: fix false positive 'device attached' conditions")
Signed-off-by: Xingui Yang <yangxingui@huawei.com>
---
drivers/scsi/libsas/sas_expander.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index 77daae36232b..430575b86e3e 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -271,8 +271,7 @@ static void sas_set_ex_phy(struct domain_device *dev, int phy_id,
/* help some expanders that fail to zero sas_address in the 'no
* device' case
*/
- if (phy->attached_dev_type == SAS_PHY_UNUSED ||
- phy->linkrate < SAS_LINK_RATE_1_5_GBPS)
+ if (phy->attached_dev_type == SAS_PHY_UNUSED)
memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE);
else
memcpy(phy->attached_sas_addr, dr->attached_sas_addr, SAS_ADDR_SIZE);
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v6 0/4] scsi: libsas: Fix the failure of adding phy with zero-address to port
2024-03-12 14:10 [PATCH v6 0/4] scsi: libsas: Fix the failure of adding phy with zero-address to port Xingui Yang
` (3 preceding siblings ...)
2024-03-12 14:11 ` [PATCH v6 4/4] scsi: libsas: Fix the failure of adding phy with zero-address to port Xingui Yang
@ 2024-04-20 14:44 ` Martin K. Petersen
2024-05-07 1:59 ` Martin K. Petersen
5 siblings, 0 replies; 7+ messages in thread
From: Martin K. Petersen @ 2024-04-20 14:44 UTC (permalink / raw)
To: Xingui Yang
Cc: john.g.garry, yanaijie, jejb, martin.petersen, damien.lemoal,
linux-scsi, linux-kernel, linuxarm, prime.zeng, chenxiang66,
kangfenglong
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v6 0/4] scsi: libsas: Fix the failure of adding phy with zero-address to port
2024-03-12 14:10 [PATCH v6 0/4] scsi: libsas: Fix the failure of adding phy with zero-address to port Xingui Yang
` (4 preceding siblings ...)
2024-04-20 14:44 ` [PATCH v6 0/4] " Martin K. Petersen
@ 2024-05-07 1:59 ` Martin K. Petersen
5 siblings, 0 replies; 7+ messages in thread
From: Martin K. Petersen @ 2024-05-07 1:59 UTC (permalink / raw)
To: john.g.garry, yanaijie, jejb, damien.lemoal, Xingui Yang
Cc: Martin K . Petersen, linux-scsi, linux-kernel, linuxarm,
prime.zeng, chenxiang66, kangfenglong
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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-05-07 2:01 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-12 14:10 [PATCH v6 0/4] scsi: libsas: Fix the failure of adding phy with zero-address to port Xingui Yang
2024-03-12 14:11 ` [PATCH v6 1/4] scsi: libsas: Add helper for port add ex_phy Xingui Yang
2024-03-12 14:11 ` [PATCH v6 2/4] scsi: libsas: Move sas_add_parent_port() to sas_expander.c Xingui Yang
2024-03-12 14:11 ` [PATCH v6 3/4] scsi: libsas: Set port when ex_phy is added or deleted Xingui Yang
2024-03-12 14:11 ` [PATCH v6 4/4] scsi: libsas: Fix the failure of adding phy with zero-address to port Xingui Yang
2024-04-20 14:44 ` [PATCH v6 0/4] " Martin K. Petersen
2024-05-07 1:59 ` Martin K. Petersen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.