[patch 65/73] libata: port and host should be stopped before hardware resources are released

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-kernel@...>, <stable@...>
Cc: Justin Forbes <jmforbes@...>, Zwane Mwaikambo <zwane@...>, Theodore Ts'o <tytso@...>, Randy Dunlap <rdunlap@...>, Dave Jones <davej@...>, Chuck Wolber <chuckw@...>, Chris Wedgwood <reviews@...>, Michael Krufky <mkrufky@...>, Chuck Ebbert <cebbert@...>, Domenico Andreoli <cavokz@...>, <torvalds@...>, <akpm@...>, <alan@...>, Tomasz Chmielewski <mangoo@...>, Mark Lord <liml@...>, Tejun Heo <htejun@...>, Jeff Garzik <jeff@...>
Date: Wednesday, February 6, 2008 - 7:54 pm

2.6.23-stable review patch.  If anyone has any objections, please let us know.
------------------
From: Tejun Heo <htejun@gmail.com>

This is backport of 32ebbc0c0d5d18c0135b55d1eb0029f48c54aff0 and fixes
oops on driver module unload.

Port / host stop calls used to be made from ata_host_release() which
is called after all hardware resources acquired after host allocation
are released.  This is wrong as port and host stop routines often
access the hardware.

Add separate devres for port / host stop which is invoked right after
IRQ is released but with all other hardware resources intact.  The
devres is added iff ->host_stop and/or ->port_stop exist.

This problem has been spotted by Mark Lord.

Signed-off-by: Tejun Heo <htejun@gmail.com>
Cc: Mark Lord <liml@rtr.ca>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/ata/libata-core.c |   52 ++++++++++++++++++++++++++++++++++------------
 1 file changed, 39 insertions(+), 13 deletions(-)

--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -6121,19 +6121,6 @@ static void ata_host_release(struct devi
 		if (!ap)
 			continue;
 
-		if ((host->flags & ATA_HOST_STARTED) && ap->ops->port_stop)
-			ap->ops->port_stop(ap);
-	}
-
-	if ((host->flags & ATA_HOST_STARTED) && host->ops->host_stop)
-		host->ops->host_stop(host);
-
-	for (i = 0; i < host->n_ports; i++) {
-		struct ata_port *ap = host->ports[i];
-
-		if (!ap)
-			continue;
-
 		if (ap->scsi_host)
 			scsi_host_put(ap->scsi_host);
 
@@ -6258,6 +6245,24 @@ struct ata_host *ata_host_alloc_pinfo(st
 	return host;
 }
 
+static void ata_host_stop(struct device *gendev, void *res)
+{
+	struct ata_host *host = dev_get_drvdata(gendev);
+	int i;
+
+	WARN_ON(!(host->flags & ATA_HOST_STARTED));
+
+	for (i = 0; i < host->n_ports; i++) {
+		struct ata_port *ap = host->ports[i];
+
+		if (ap->ops->port_stop)
+			ap->ops->port_stop(ap);
+	}
+
+	if (host->ops->host_stop)
+		host->ops->host_stop(host);
+}
+
 /**
  *	ata_host_start - start and freeze ports of an ATA host
  *	@host: ATA host to start ports for
@@ -6276,6 +6281,8 @@ struct ata_host *ata_host_alloc_pinfo(st
  */
 int ata_host_start(struct ata_host *host)
 {
+	int have_stop = 0;
+	void *start_dr = NULL;
 	int i, rc;
 
 	if (host->flags & ATA_HOST_STARTED)
@@ -6287,6 +6294,22 @@ int ata_host_start(struct ata_host *host
 		if (!host->ops && !ata_port_is_dummy(ap))
 			host->ops = ap->ops;
 
+		if (ap->ops->port_stop)
+			have_stop = 1;
+	}
+
+	if (host->ops->host_stop)
+		have_stop = 1;
+
+	if (have_stop) {
+		start_dr = devres_alloc(ata_host_stop, 0, GFP_KERNEL);
+		if (!start_dr)
+			return -ENOMEM;
+	}
+
+	for (i = 0; i < host->n_ports; i++) {
+		struct ata_port *ap = host->ports[i];
+
 		if (ap->ops->port_start) {
 			rc = ap->ops->port_start(ap);
 			if (rc) {
@@ -6299,6 +6322,8 @@ int ata_host_start(struct ata_host *host
 		ata_eh_freeze_port(ap);
 	}
 
+	if (start_dr)
+		devres_add(host->dev, start_dr);
 	host->flags |= ATA_HOST_STARTED;
 	return 0;
 
@@ -6309,6 +6334,7 @@ int ata_host_start(struct ata_host *host
 		if (ap->ops->port_stop)
 			ap->ops->port_stop(ap);
 	}
+	devres_free(start_dr);
 	return rc;
 }
 

-- 
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch 00/73] 2.6.23-stable review, Greg KH, (Wed Feb 6, 7:50 pm)
[patch 73/73] PCI: Fix fakephp deadlock, Greg KH, (Wed Feb 6, 7:54 pm)
[patch 72/73] ACPI: sync blacklist w/ latest, Greg KH, (Wed Feb 6, 7:54 pm)
[patch 71/73] atl1: fix frame length bug, Greg KH, (Wed Feb 6, 7:54 pm)
[patch 70/73] forcedeth: mac address mcp77/79, Greg KH, (Wed Feb 6, 7:54 pm)
[patch 66/73] fix oops on rmmod capidrv, Greg KH, (Wed Feb 6, 7:54 pm)
[patch 65/73] libata: port and host should be stopped before..., Greg KH, (Wed Feb 6, 7:54 pm)
[patch 64/73] spi: omap2_mcspi PIO RX fix, Greg KH, (Wed Feb 6, 7:54 pm)
[patch 55/73] m68k: Export cachectl.h, Greg KH, (Wed Feb 6, 7:53 pm)
[patch 47/73] cxgb: fix stats, Greg KH, (Wed Feb 6, 7:53 pm)
[patch 46/73] cxgb: fix T2 GSO, Greg KH, (Wed Feb 6, 7:53 pm)
[patch 45/73] chelsio: Fix skb-&gt;dev setting, Greg KH, (Wed Feb 6, 7:53 pm)
[patch 28/73] CASSINI: Fix endianness bug., Greg KH, (Wed Feb 6, 7:52 pm)
[patch 16/73] X25: Add missing x25_neigh_put, Greg KH, (Wed Feb 6, 7:51 pm)
[patch 14/73] sky2: RX lockup fix, Greg KH, (Wed Feb 6, 7:51 pm)
[patch 04/73] dm crypt: use bio_add_page, Greg KH, (Wed Feb 6, 7:50 pm)
[patch 03/73] dm crypt: fix write endio, Greg KH, (Wed Feb 6, 7:50 pm)