aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/libata-core.c
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2010-09-06 11:57:14 -0400
committerJeff Garzik <jgarzik@redhat.com>2010-10-21 20:21:05 -0400
commitc0c362b60e259e3480a36ef70280d545818844f0 (patch)
treed9871b719cd76f9f683278f938662e080a6ad9d7 /drivers/ata/libata-core.c
parent97750cebb3000a9cc08f8ce8dc8c7143be7d7201 (diff)
libata: implement cross-port EH exclusion
In libata, the non-EH code paths should always take and release ap->lock explicitly when accessing hardware or shared data structures. However, once EH is active, it's assumed that the port is owned by EH and EH methods don't explicitly take ap->lock unless race from irq handler or other code paths are expected. However, libata EH didn't guarantee exclusion among EHs for ports of the same host. IOW, multiple EHs may execute in parallel on multiple ports of the same controller. In many cases, especially in SATA, the ports are completely independent of each other and this doesn't cause problems; however, there are cases where different ports share the same resource, which lead to obscure timing related bugs such as the one fixed by commit 213373cf (ata_piix: fix locking around SIDPR access). This patch implements exclusion among EHs of the same host. When EH begins, it acquires per-host EH ownership by calling ata_eh_acquire(). When EH finishes, the ownership is released by calling ata_eh_release(). EH ownership is also released whenever the EH thread goes to sleep from ata_msleep() or explicitly and reacquired after waking up. This ensures that while EH is actively accessing the hardware, it has exclusive access to it while allowing EHs to interleave and progress in parallel as they hit waiting stages, which dominate the time spent in EH. This achieves cross-port EH exclusion without pervasive and fragile changes while still allowing parallel EH for the most part. This was first reported by yuanding02@gmail.com more than three years ago in the following bugzilla. :-) https://bugzilla.kernel.org/show_bug.cgi?id=8223 Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Reported-by: yuanding02@gmail.com Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
Diffstat (limited to 'drivers/ata/libata-core.c')
-rw-r--r--drivers/ata/libata-core.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 42d9ce29f50d..7f77c67d267c 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -1628,8 +1628,14 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
1628 } 1628 }
1629 } 1629 }
1630 1630
1631 if (ap->ops->error_handler)
1632 ata_eh_release(ap);
1633
1631 rc = wait_for_completion_timeout(&wait, msecs_to_jiffies(timeout)); 1634 rc = wait_for_completion_timeout(&wait, msecs_to_jiffies(timeout));
1632 1635
1636 if (ap->ops->error_handler)
1637 ata_eh_acquire(ap);
1638
1633 ata_sff_flush_pio_task(ap); 1639 ata_sff_flush_pio_task(ap);
1634 1640
1635 if (!rc) { 1641 if (!rc) {
@@ -5570,6 +5576,7 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
5570 dev_set_drvdata(dev, host); 5576 dev_set_drvdata(dev, host);
5571 5577
5572 spin_lock_init(&host->lock); 5578 spin_lock_init(&host->lock);
5579 mutex_init(&host->eh_mutex);
5573 host->dev = dev; 5580 host->dev = dev;
5574 host->n_ports = max_ports; 5581 host->n_ports = max_ports;
5575 5582
@@ -5867,6 +5874,7 @@ void ata_host_init(struct ata_host *host, struct device *dev,
5867 unsigned long flags, struct ata_port_operations *ops) 5874 unsigned long flags, struct ata_port_operations *ops)
5868{ 5875{
5869 spin_lock_init(&host->lock); 5876 spin_lock_init(&host->lock);
5877 mutex_init(&host->eh_mutex);
5870 host->dev = dev; 5878 host->dev = dev;
5871 host->flags = flags; 5879 host->flags = flags;
5872 host->ops = ops; 5880 host->ops = ops;
@@ -6483,9 +6491,31 @@ int ata_ratelimit(void)
6483 return __ratelimit(&ratelimit); 6491 return __ratelimit(&ratelimit);
6484} 6492}
6485 6493
6494/**
6495 * ata_msleep - ATA EH owner aware msleep
6496 * @ap: ATA port to attribute the sleep to
6497 * @msecs: duration to sleep in milliseconds
6498 *
6499 * Sleeps @msecs. If the current task is owner of @ap's EH, the
6500 * ownership is released before going to sleep and reacquired
6501 * after the sleep is complete. IOW, other ports sharing the
6502 * @ap->host will be allowed to own the EH while this task is
6503 * sleeping.
6504 *
6505 * LOCKING:
6506 * Might sleep.
6507 */
6486void ata_msleep(struct ata_port *ap, unsigned int msecs) 6508void ata_msleep(struct ata_port *ap, unsigned int msecs)
6487{ 6509{
6510 bool owns_eh = ap && ap->host->eh_owner == current;
6511
6512 if (owns_eh)
6513 ata_eh_release(ap);
6514
6488 msleep(msecs); 6515 msleep(msecs);
6516
6517 if (owns_eh)
6518 ata_eh_acquire(ap);
6489} 6519}
6490 6520
6491/** 6521/**