scsi: libsas: Fix the failure of adding phy with zero-address to port
Subsystems (2)
v6 cover 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(-)
Signature · 1 line
2.17.1
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.
--- drivers/scsi/libsas/sas_expander.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/scsi/libsas/sas_expander.c +8 -3
@@ -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; } }
Signature · 1 line
2.17.1
PATCH v6 2/4 scsi: libsas: Move sas_add_parent_port() to sas_expander.c
In reply to Xingui YangMove 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.
--- drivers/scsi/libsas/sas_expander.c | 19 +++++++++++++++++-- drivers/scsi/libsas/sas_internal.h | 15 --------------- 2 files changed, 17 insertions(+), 17 deletions(-)
drivers/scsi/libsas/sas_expander.c +17 -2
@@ -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 ;
drivers/scsi/libsas/sas_internal.h +0 -15
@@ -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 );
Signature · 1 line
2.17.1
PATCH v6 3/4 scsi: libsas: Set port when ex_phy is added or deleted
In reply to Xingui YangWe 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.
--- drivers/scsi/libsas/sas_expander.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/scsi/libsas/sas_expander.c +5 -2
@@ -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 ; } }
Signature · 1 line
2.17.1
PATCH v6 4/4 scsi: libsas: Fix the failure of adding phy with zero-address to port
In reply to Xingui YangAs 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.
--- drivers/scsi/libsas/sas_expander.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/libsas/sas_expander.c +1 -2
@@ -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 );
Signature · 1 line
2.17.1
Martin K. Petersen
AppliedXingui,
Quoted 2 lines
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!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Martin K. Petersen
AppliedQuoted 10 lines · Xingui Yang
This series is to solve the problem of a
BUG()when adding phy with zero address to a new port.v5 -> v6
1. renamesas_add_parent_port()tosas_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
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering