Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: libsas: Defer works of new phys during suspend

During the processing of event PORT_BYTES_DMAED, the driver queues work
DISCE_DISCOVER_DOMAIN and then flushes workqueue ha->disco_q. If a new
phyup event occurs during resuming the controller, the work
PORTE_BYTES_DMAED of new phy occurs before suspended phy's. The work
DISCE_DISCOVER_DOMAIN of new phy requires an active SAS controller (it
needs to resume SAS controller by function scsi_sysfs_add_sdev() and some
other functions such as function add_device_link()). However, the
activation of the SAS controller requires completion of work
PORTE_BYTES_DMAED of suspended phys while it is blocked by new phy's work
on ha->event_q. So there is a deadlock and it is released only after resume
timeout.

To solve the issue, defer works of new phys during suspend and queue those
defer works after SAS controller becomes active.

Link: https://lore.kernel.org/r/1639999298-244569-13-git-send-email-chenxiang66@hisilicon.com
Reviewed-by: John Garry <john.garry@huawei.com>
Signed-off-by: Xiang Chen <chenxiang66@hisilicon.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Xiang Chen and committed by
Martin K. Petersen
bf19aea4 1bc35475

+25
+24
drivers/scsi/libsas/sas_event.c
··· 139 139 sas_free_event(ev); 140 140 } 141 141 142 + /* defer works of new phys during suspend */ 143 + static bool sas_defer_event(struct asd_sas_phy *phy, struct asd_sas_event *ev) 144 + { 145 + struct sas_ha_struct *ha = phy->ha; 146 + unsigned long flags; 147 + bool deferred = false; 148 + 149 + spin_lock_irqsave(&ha->lock, flags); 150 + if (test_bit(SAS_HA_RESUMING, &ha->state) && !phy->suspended) { 151 + struct sas_work *sw = &ev->work; 152 + 153 + list_add_tail(&sw->drain_node, &ha->defer_q); 154 + deferred = true; 155 + } 156 + spin_unlock_irqrestore(&ha->lock, flags); 157 + return deferred; 158 + } 159 + 142 160 int sas_notify_port_event(struct asd_sas_phy *phy, enum port_event event, 143 161 gfp_t gfp_flags) 144 162 { ··· 171 153 return -ENOMEM; 172 154 173 155 INIT_SAS_EVENT(ev, sas_port_event_worker, phy, event); 156 + 157 + if (sas_defer_event(phy, ev)) 158 + return 0; 174 159 175 160 ret = sas_queue_event(event, &ev->work, ha); 176 161 if (ret != 1) ··· 197 176 return -ENOMEM; 198 177 199 178 INIT_SAS_EVENT(ev, sas_phy_event_worker, phy, event); 179 + 180 + if (sas_defer_event(phy, ev)) 181 + return 0; 200 182 201 183 ret = sas_queue_event(event, &ev->work, ha); 202 184 if (ret != 1)
+1
drivers/scsi/libsas/sas_init.c
··· 446 446 sas_drain_work(ha); 447 447 clear_bit(SAS_HA_RESUMING, &ha->state); 448 448 449 + sas_queue_deferred_work(ha); 449 450 /* send event PORTE_BROADCAST_RCVD to identify some new inserted 450 451 * disks for expander 451 452 */