libsas fixlets for 2.6.40
Subsystems (4)
PATCH 1/3 libsas: flush initial device discovery before completing ->scan_finished()
In reply to Dan WilliamsDuring initial scan libsas drivers start their phys and notify libsas with PORTE_BYTES_DMAED events as port links are established. This notification in turn causes libsas to post DISCE_DISCOVER_DOMAIN events to the queue. Calling scsi_flush_work() at the end of scan_finished guarantees that all preceding PORTE_BYTES_DMAED events have been registered in the queue, but it does not guarantee that the resulting DISCE_DISCOVER_DOMAIN events have been processed because flush_workqueue() explicitly avoids live-locking with incoming work.
Introduce sas_flush_discovery() to guarantee that all initial discovery events have completed. It is called after the driver determines all initial PORTE_BYTES_DMAED events have had a chance to enter the queue. This does not cover BCNs that are generated during expander bring up, only the initial sas_discover_domain() event.
--- drivers/scsi/aic94xx/aic94xx_init.c | 2 +- drivers/scsi/mvsas/mv_sas.c | 2 +- drivers/scsi/pm8001/pm8001_sas.c | 2 +- include/scsi/libsas.h | 13 +++++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-)
drivers/scsi/aic94xx/aic94xx_init.c +1 -1
@@ -972,7 +972,7 @@ static int asd_scan_finished(struct Scsi_Host *shost, unsigned long time)if (time <HZ )return 0 ;/* Wait for discovery to finish */ -scsi_flush_work (shost); +sas_flush_discovery (shost);return 1 ; }
drivers/scsi/mvsas/mv_sas.c +1 -1
@@ -440,7 +440,7 @@ int mvs_scan_finished(struct Scsi_Host *shost, unsigned long time)if (time <HZ )return 0 ;/* Wait for discovery to finish */ -scsi_flush_work (shost); +sas_flush_discovery (shost);return 1 ; }
drivers/scsi/pm8001/pm8001_sas.c +1 -1
@@ -253,7 +253,7 @@ int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time)if (time <HZ )return 0 ;/* Wait for discovery to finish */ -scsi_flush_work (shost); +sas_flush_discovery (shost);return 1 ; }
include/scsi/libsas.h +13 -0
@@ -405,6 +405,19 @@ static inline void sas_phy_disconnected(struct asd_sas_phy *phy) phy->linkrate =SAS_LINK_RATE_UNKNOWN ; } +/* Before returning from ->scan_finished() an LLDD calls this routine to +* ensure that all port notifications have been promoted to domain +* discovery events, and that initial domain discovery has completed +*/ +static inline void sas_flush_discovery (struct Scsi_Host *shost) +{ +/* flush port events */ +scsi_flush_work (shost); + +/* flush domain discovery events queued by the port events */ +scsi_flush_work (shost); +} +/* ---------- Tasks ---------- */ /* service_response | SAS_TASK_COMPLETE | SAS_TASK_UNDELIVERED |
cover libsas fixlets for 2.6.40
Cleanup hotplug handling (issuing i/o to 'gone' devices), and fix pre-mature completion of the initial domain scan.
Checked out with the isci driver on 2.6.39-rc5.
---
Dan Williams (3):
libsas: flush initial device discovery before completing ->scan_finished()
libsas: fix/amend device gone notification in sas_deform_port()
libsas: check dev->gone before submitting sata i/odrivers/scsi/aic94xx/aic94xx_init.c | 2 +- drivers/scsi/libsas/sas_expander.c | 20 +++++++++++++++++--- drivers/scsi/libsas/sas_internal.h | 3 ++- drivers/scsi/libsas/sas_phy.c | 4 ++-- drivers/scsi/libsas/sas_port.c | 21 ++++++++++++--------- drivers/scsi/libsas/sas_scsi_host.c | 14 +++++++------- drivers/scsi/mvsas/mv_sas.c | 2 +- drivers/scsi/pm8001/pm8001_sas.c | 2 +- include/scsi/libsas.h | 13 +++++++++++++ 9 files changed, 56 insertions(+), 25 deletions(-)
PATCH 2/3 libsas: fix/amend device gone notification in sas_deform_port()
Commit 56dd2c06 "libsas: Don't issue commands to devices that have been hot-removed" edited Darrick's original patch to remove setting 'gone' in the sas_deform_port() path because that prevented scsi sync cache commands from being issued when the driver was unloaded. However, this allows true device gone notifications (as signaled port phy events) to trigger sync cache commands to devices that are known to be unreachable.
Teach libsas which sas_deform_port() invocations are likely device gone events.
This patch also introduces sas_device_gone() which hopefully allows subtle/tricky locking to be dropped from lldd drivers, like the following in mvsas which is broken if the ata path is ever converted to call lldd_execute_task() with irqs enabled:
flags_libsas = 0; [...] spin_unlock_irqrestore(dev->sata_dev.ap->lock, flags_libsas); spin_unlock_irqrestore(&mvi->lock, flags); t->task_done(t); spin_lock_irqsave(&mvi->lock, flags); spin_lock_irqsave(dev->sata_dev.ap->lock, flags_libsas);
--- drivers/scsi/libsas/sas_expander.c | 20 +++++++++++++++++--- drivers/scsi/libsas/sas_internal.h | 3 ++- drivers/scsi/libsas/sas_phy.c | 4 ++-- drivers/scsi/libsas/sas_port.c | 21 ++++++++++++--------- 4 files changed, 33 insertions(+), 15 deletions(-)
drivers/scsi/libsas/sas_expander.c +17 -3
@@ -1721,13 +1721,27 @@ out:return res; } +/* FIXME: delete this routine when/if sas_ata stops submitting tasks +* with host_lock held +*/ +void sas_device_gone (struct domain_device *dev) +{ +struct sas_rphy *rphy = dev->rphy; +struct Scsi_Host *shost =dev_to_shost (rphy->dev.parent); + +/* take the lock to synchronize against incoming sata i/o */ +spin_lock_irq (shost->host_lock); + dev->gone =1 ; +spin_unlock_irq (shost->host_lock); +} +static void sas_unregister_ex_tree (struct domain_device *dev) {struct expander_device *ex = &dev->ex_dev;struct domain_device *child, *n;list_for_each_entry_safe (child, n, &ex->children, siblings) { - child->gone =1 ; +sas_device_gone (child);if (child->dev_type ==EDGE_DEV || child->dev_type ==FANOUT_DEV )sas_unregister_ex_tree (child);
@@ -1748,7 +1762,7 @@ static void sas_unregister_devs_sas_addr(struct domain_device *parent, &ex_dev->children, siblings) {if (SAS_ADDR (child->sas_addr) ==SAS_ADDR (phy->attached_sas_addr)) { - child->gone =1 ; +sas_device_gone (child);if (child->dev_type ==EDGE_DEV || child->dev_type ==FANOUT_DEV )sas_unregister_ex_tree (child);
@@ -1757,7 +1771,7 @@ static void sas_unregister_devs_sas_addr(struct domain_device *parent,break ; } } - parent->gone =1 ; +sas_device_gone (parent);sas_disable_routing (parent, phy->attached_sas_addr); }memset (phy->attached_sas_addr,0 ,SAS_ADDR_SIZE );
drivers/scsi/libsas/sas_internal.h +2 -1
@@ -61,7 +61,7 @@ int sas_init_queue(struct sas_ha_struct *sas_ha);int sas_init_events (struct sas_ha_struct *sas_ha);void sas_shutdown_queue (struct sas_ha_struct *sas_ha); -void sas_deform_port (struct asd_sas_phy *phy); +void sas_deform_port (struct asd_sas_phy *phy,int gone);void sas_porte_bytes_dmaed (struct work_struct *work);void sas_porte_broadcast_rcvd (struct work_struct *work);
@@ -71,6 +71,7 @@ void sas_porte_hard_reset(struct work_struct *work);int sas_notify_lldd_dev_found (struct domain_device *);void sas_notify_lldd_dev_gone (struct domain_device *); +void sas_device_gone (struct domain_device *dev);int sas_smp_phy_control (struct domain_device *dev,int phy_id,enum phy_func phy_func,struct sas_phy_linkrates *);
drivers/scsi/libsas/sas_phy.c +2 -2
@@ -39,7 +39,7 @@ static void sas_phye_loss_of_signal(struct work_struct *work)sas_begin_event (PHYE_LOSS_OF_SIGNAL , &phy->ha->event_lock, &phy->phy_events_pending); phy->error =0 ; -sas_deform_port (phy); +sas_deform_port (phy,1 ); }static void sas_phye_oob_done (struct work_struct *work)
@@ -66,7 +66,7 @@ static void sas_phye_oob_error(struct work_struct *work)sas_begin_event (PHYE_OOB_ERROR , &phy->ha->event_lock, &phy->phy_events_pending); -sas_deform_port (phy); +sas_deform_port (phy,1 );if (!port && phy->enabled && i->dft->lldd_control_phy) { phy->error++;
drivers/scsi/libsas/sas_port.c +12 -9
@@ -57,7 +57,7 @@ static void sas_form_port(struct asd_sas_phy *phy)if (port) {if (!phy_is_wideport_member (port, phy)) -sas_deform_port (phy); +sas_deform_port (phy,0 );else { SAS_DPRINTK("%s: phy%d belongs to port%d already(%d)!\n", __func__, phy->id, phy->port->id,
@@ -153,28 +153,31 @@ static void sas_form_port(struct asd_sas_phy *phy)* This is called when the physical link to the other phy has been * lost (on this phy), in Event thread context. We cannot delay here. */ -void sas_deform_port (struct asd_sas_phy *phy) +void sas_deform_port (struct asd_sas_phy *phy,int gone) {struct sas_ha_struct *sas_ha = phy->ha;struct asd_sas_port *port = phy->port;struct sas_internal *si =to_sas_internal (sas_ha->core.shost->transportt); +struct domain_device *dev;unsigned long flags;if (!port)return ;/* done by a phy event */ -if (port->port_dev) - port->port_dev->pathways--; + dev = port->port_dev; +if (dev) + dev->pathways--;if (port->num_phys ==1 ) { +if (dev && gone) +sas_device_gone (dev);sas_unregister_domain_devices (port);sas_port_delete (port->port); port->port =NULL ; }else sas_port_delete_phy (port->port, phy->phy); -if (si->dft->lldd_port_deformed) si->dft->lldd_port_deformed (phy);
@@ -244,7 +247,7 @@ void sas_porte_link_reset_err(struct work_struct *work)sas_begin_event (PORTE_LINK_RESET_ERR , &phy->ha->event_lock, &phy->port_events_pending); -sas_deform_port (phy); +sas_deform_port (phy,1 ); }void sas_porte_timer_event (struct work_struct *work)
@@ -256,7 +259,7 @@ void sas_porte_timer_event(struct work_struct *work)sas_begin_event (PORTE_TIMER_EVENT , &phy->ha->event_lock, &phy->port_events_pending); -sas_deform_port (phy); +sas_deform_port (phy,1 ); }void sas_porte_hard_reset (struct work_struct *work)
@@ -268,7 +271,7 @@ void sas_porte_hard_reset(struct work_struct *work)sas_begin_event (PORTE_HARD_RESET , &phy->ha->event_lock, &phy->port_events_pending); -sas_deform_port (phy); +sas_deform_port (phy,1 ); }/* ---------- SAS port registration ---------- */
@@ -306,6 +309,6 @@ void sas_unregister_ports(struct sas_ha_struct *sas_ha)for (i =0 ; i < sas_ha->num_phys; i++)if (sas_ha->sas_phy[i]->port) -sas_deform_port (sas_ha->sas_phy[i]); +sas_deform_port (sas_ha->sas_phy[i],0 ); }
PATCH 3/3 libsas: check dev->gone before submitting sata i/o
In reply to Dan WilliamsHead off doomed-to-fail i/o in sas_queuecommand before sending it down the ata path.
Before:
sd 7:0:0:0: [sdd] Synchronizing SCSI cache
ata8: no sense translation for status: 0x00
ata8: translated ATA stat/err 0x00/00 to SCSI SK/ASC/ASCQ 0xb/00/00 ata8.00: device reported invalid CHS sector 0
ata8: status=0x00 { }
ata8: no sense translation for status: 0x00
ata8: translated ATA stat/err 0x00/00 to SCSI SK/ASC/ASCQ 0xb/00/00 ata8.00: device reported invalid CHS sector 0
ata8: status=0x00 { }
ata8: no sense translation for status: 0x00
ata8: translated ATA stat/err 0x00/00 to SCSI SK/ASC/ASCQ 0xb/00/00 ata8.00: device reported invalid CHS sector 0
ata8: status=0x00 { }
sd 7:0:0:0: [sdd] Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE sd 7:0:0:0: [sdd] Sense Key : Aborted Command [current] [descriptor] sd 7:0:0:0: [sdd] Add. Sense: No additional sense information
sd 7:0:0:0: [sdd] Stopping disk
After:
sd 9:0:0:0: [sdd] Synchronizing SCSI cache
sd 9:0:0:0: [sdd] Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK sd 9:0:0:0: [sdd] Stopping disk
sd 9:0:0:0: [sdd] START_STOP FAILED
sd 9:0:0:0: [sdd] Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
This is a cosmetic change as sata i/o can still leak to a gone device, but this addresses the nominal hotplug case when releasing the target.
--- drivers/scsi/libsas/sas_scsi_host.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
drivers/scsi/libsas/sas_scsi_host.c +7 -7
@@ -218,6 +218,13 @@ int sas_queuecommand(struct scsi_cmnd *cmd,struct sas_ha_struct *sas_ha = dev->port->ha;struct sas_task *task; +/* If the device fell off, no sense in issuing commands */ +if (dev->gone) { + cmd->result =DID_BAD_TARGET <<16 ; +scsi_done (cmd); + goto out; + } +if (dev_is_sata (dev)) {unsigned long flags;
@@ -228,13 +235,6 @@ int sas_queuecommand(struct scsi_cmnd *cmd, goto out; } -/* If the device fell off, no sense in issuing commands */ -if (dev->gone) { - cmd->result =DID_BAD_TARGET <<16 ; -scsi_done (cmd); - goto out; - } - res = -ENOMEM ; task =sas_create_task (cmd, dev,GFP_ATOMIC );if (!task)
RE: [PATCH 1/3] libsas: flush initial device discovery before completing->scan_finished()
In reply to Dan WilliamsThanks!
drivers/scsi/mvsas/mv_sas.c int mvs_scan_finished(struct Scsi_Host *shost,
Quoted 48 lines
During initial scan libsas drivers start their phys and notify libsas with
PORTE_BYTES_DMAEDevents as port links are established. This notification in turn causes libsas to postDISCE_DISCOVER_DOMAINevents to the queue. Callingscsi_flush_work()at the end ofscan_finishedguarantees that all precedingPORTE_BYTES_DMAEDevents have been registered in the queue, but it does not guarantee that the resultingDISCE_DISCOVER_DOMAINevents have been processed becauseflush_workqueue()explicitly avoids live-locking with incoming work.Introduce
sas_flush_discovery()to guarantee that all initial discovery events have completed. It is called after the driver determines all initialPORTE_BYTES_DMAEDevents have had a chance to enter the queue. This does not cover BCNs that are generated during expander bring up, only the initialsas_discover_domain()event.Cc David Milburn <[email protected]>Cc Srinivas <[email protected]>Signed-off-by Dan Williams <[email protected]>--- drivers/scsi/aic94xx/aic94xx_init.c | 2 +- drivers/scsi/mvsas/mv_sas.c | 2 +- drivers/scsi/pm8001/pm8001_sas.c | 2 +- include/scsi/libsas.h | 13 +++++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-)drivers/scsi/aic94xx/aic94xx_init.c +1
-1@@ -972,7 +972,7 @@ static int asd_scan_finished(struct Scsi_Host *shost, unsigned long time)if (time <HZ )return 0 ;/* Wait for discovery to finish */ -scsi_flush_work (shost); +sas_flush_discovery (shost);return 1 ; }drivers/scsi/mvsas/mv_sas.c +0
-0@@ -440,7 +440,7 @@ int mvs_scan_finished(struct Scsi_Host *shost,
unsigned
drivers/scsi/pm8001/pm8001_sas.c int pm8001_scan_finished(struct Scsi_Host *shost,
Quoted 15 lines
drivers/scsi/mvsas/mv_sas.c +1
-1long time)if (time <HZ )return 0 ;/* Wait for discovery to finish */ -scsi_flush_work (shost); +sas_flush_discovery (shost);return 1 ; }drivers/scsi/pm8001/pm8001_sas.c +0
-0@@ -253,7 +253,7 @@ int pm8001_scan_finished(struct Scsi_Host *shost,
unsigned
Quoted 39 lines
drivers/scsi/pm8001/pm8001_sas.c +1
-1long time)if (time <HZ )return 0 ;/* Wait for discovery to finish */ -scsi_flush_work (shost); +sas_flush_discovery (shost);return 1 ; }include/scsi/libsas.h +13
-0@@ -405,6 +405,19 @@ static inline void sas_phy_disconnected(struct asd_sas_phy *phy) phy->linkrate = SAS_LINK_RATE_UNKNOWN; } +/* Before returning from ->scan_finished() an LLDD calls this routine to +* ensure that all port notifications have been promoted to domain +* discovery events, and that initial domain discovery has completed +*/ +static inline void sas_flush_discovery (struct Scsi_Host *shost) +{ +/* flush port events */ +scsi_flush_work (shost); + +/* flush domain discovery events queued by the port events */ +scsi_flush_work (shost); +} +/* ---------- Tasks ---------- */ /*
service_response|SAS_TASK_COMPLETE|SAS_TASK_UNDELIVERED|--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/3] libsas: fix/amend device gone notification in sas_deform_port()
In reply to Dan WilliamsQuoted 4 lines · Dan Williams
This patch also introduces
sas_device_gone()which hopefully allows subtle/tricky locking to be dropped from lldd drivers, like the following in mvsas which is broken if the ata path is ever converted to calllldd_execute_task()with irqs enabled:
[..]
Quoted 11 lines
drivers/scsi/libsas/sas_expander.c +3
-0@@ -1721,13 +1721,27 @@ out: return res; } +/* FIXME: delete this routine when/if sas_ata stops submitting tasks +* with host_lock held +*/
drivers/scsi/libsas/sas_expander.c out: · line 1736
Quoted 10 lines
drivers/scsi/libsas/sas_expander.c +10
-0+void sas_device_gone (struct domain_device *dev) +{ + struct sas_rphy *rphy = dev->rphy; + struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent); + + /* take the lock to synchronize against incoming sata i/o */ + spin_lock_irq(shost->host_lock); + dev->gone = 1; + spin_unlock_irq(shost->host_lock); +}
Commit a29b5dad "libata: fix locking for sas paths" has gone in since this patch was created so this locking no longer has any effect.
Now needs to be dev->sata_dev.ap->lock, will resubmit.
--
Dan
Re: [PATCH 2/3] libsas: fix/amend device gone notification in sas_deform_port()
In reply to Dan WilliamsQuoted 1 line
From
0326887e94470d693cf5d10b37058a8b472b046bMon Sep 17 00:00:00 2001
From: Dan Williams <[email protected]>
Date: Fri, 18 Feb 2011 09:22:43 -0800
Subject: [PATCH v2] libsas: fix/amend device gone notification in sas_deform_port()
Commit 56dd2c06 "libsas: Don't issue commands to devices that have been hot-removed" edited Darrick's original patch to remove setting 'gone' in the sas_deform_port() path because that prevented scsi sync cache commands from being issued when the driver was unloaded. However, this allows true device gone notifications (as signaled port phy events) to trigger sync cache commands to devices that are known to be unreachable.
Teach libsas which sas_deform_port() invocations are likely device gone events.
---
Version 2: drop sas_device_gone(). It did not eliminate scenarios where an lldd might need to return i/o from ->lldd_execute_task, and after the locking change in 2.6.39 we needed to dig into the sata_dev to take the lock. It can be reintroduced later, but for now do the simple fix by itself.
drivers/scsi/libsas/sas_internal.h +1 -1
@@ -61,7 +61,7 @@ int sas_init_queue(struct sas_ha_struct *sas_ha);int sas_init_events (struct sas_ha_struct *sas_ha);void sas_shutdown_queue (struct sas_ha_struct *sas_ha); -void sas_deform_port (struct asd_sas_phy *phy); +void sas_deform_port (struct asd_sas_phy *phy,int gone);void sas_porte_bytes_dmaed (struct work_struct *work);void sas_porte_broadcast_rcvd (struct work_struct *work);
drivers/scsi/libsas/sas_phy.c +2 -2
@@ -39,7 +39,7 @@ static void sas_phye_loss_of_signal(struct work_struct *work)sas_begin_event (PHYE_LOSS_OF_SIGNAL , &phy->ha->event_lock, &phy->phy_events_pending); phy->error =0 ; -sas_deform_port (phy); +sas_deform_port (phy,1 ); }static void sas_phye_oob_done (struct work_struct *work)
@@ -66,7 +66,7 @@ static void sas_phye_oob_error(struct work_struct *work)sas_begin_event (PHYE_OOB_ERROR , &phy->ha->event_lock, &phy->phy_events_pending); -sas_deform_port (phy); +sas_deform_port (phy,1 );if (!port && phy->enabled && i->dft->lldd_control_phy) { phy->error++;
drivers/scsi/libsas/sas_port.c +12 -9
@@ -57,7 +57,7 @@ static void sas_form_port(struct asd_sas_phy *phy)if (port) {if (!phy_is_wideport_member (port, phy)) -sas_deform_port (phy); +sas_deform_port (phy,0 );else { SAS_DPRINTK("%s: phy%d belongs to port%d already(%d)!\n", __func__, phy->id, phy->port->id,
@@ -153,28 +153,31 @@ static void sas_form_port(struct asd_sas_phy *phy)* This is called when the physical link to the other phy has been * lost (on this phy), in Event thread context. We cannot delay here. */ -void sas_deform_port (struct asd_sas_phy *phy) +void sas_deform_port (struct asd_sas_phy *phy,int gone) {struct sas_ha_struct *sas_ha = phy->ha;struct asd_sas_port *port = phy->port;struct sas_internal *si =to_sas_internal (sas_ha->core.shost->transportt); +struct domain_device *dev;unsigned long flags;if (!port)return ;/* done by a phy event */ -if (port->port_dev) - port->port_dev->pathways--; + dev = port->port_dev; +if (dev) + dev->pathways--;if (port->num_phys ==1 ) { +if (dev && gone) + dev->gone =1 ;sas_unregister_domain_devices (port);sas_port_delete (port->port); port->port =NULL ; }else sas_port_delete_phy (port->port, phy->phy); -if (si->dft->lldd_port_deformed) si->dft->lldd_port_deformed (phy);
@@ -244,7 +247,7 @@ void sas_porte_link_reset_err(struct work_struct *work)sas_begin_event (PORTE_LINK_RESET_ERR , &phy->ha->event_lock, &phy->port_events_pending); -sas_deform_port (phy); +sas_deform_port (phy,1 ); }void sas_porte_timer_event (struct work_struct *work)
@@ -256,7 +259,7 @@ void sas_porte_timer_event(struct work_struct *work)sas_begin_event (PORTE_TIMER_EVENT , &phy->ha->event_lock, &phy->port_events_pending); -sas_deform_port (phy); +sas_deform_port (phy,1 ); }void sas_porte_hard_reset (struct work_struct *work)
@@ -268,7 +271,7 @@ void sas_porte_hard_reset(struct work_struct *work)sas_begin_event (PORTE_HARD_RESET , &phy->ha->event_lock, &phy->port_events_pending); -sas_deform_port (phy); +sas_deform_port (phy,1 ); }/* ---------- SAS port registration ---------- */
@@ -306,6 +309,6 @@ void sas_unregister_ports(struct sas_ha_struct *sas_ha)for (i =0 ; i < sas_ha->num_phys; i++)if (sas_ha->sas_phy[i]->port) -sas_deform_port (sas_ha->sas_phy[i]); +sas_deform_port (sas_ha->sas_phy[i],0 ); }