linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] ata: ahci: Add shutdown handler
@ 2019-12-09 16:32 Hanna Hawa
  2019-12-09 16:32 ` [PATCH 1/2] ata: libahci: move ahci platform shutdown function to libahci Hanna Hawa
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Hanna Hawa @ 2019-12-09 16:32 UTC (permalink / raw)
  To: axboe, hdegoede
  Cc: linux-ide, linux-kernel, dwmw, benh, ronenk, talel, jonnyc,
	hanochu, barakw, hhhawa

This series introduced AHCI shutdown handler for AHCI PCIe driver, to
disable host controller DMA and interrupts in order to avoid potentially
corrupting or otherwise interfering with a new kernel being started with
kexec.

Part of this patch move the common part between platform and pcie
drivers to libahci.c.

Hanna Hawa (2):
  ata: libahci: move ahci platform shutdown function to libahci
  ata: ahci: Add shutdown handler

 drivers/ata/ahci.c             |  9 +++++++++
 drivers/ata/ahci.h             |  1 +
 drivers/ata/libahci.c          | 33 +++++++++++++++++++++++++++++++++
 drivers/ata/libahci_platform.c | 20 +-------------------
 4 files changed, 44 insertions(+), 19 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] ata: libahci: move ahci platform shutdown function to libahci
  2019-12-09 16:32 [PATCH 0/2] ata: ahci: Add shutdown handler Hanna Hawa
@ 2019-12-09 16:32 ` Hanna Hawa
  2019-12-09 16:32 ` [PATCH 2/2] ata: ahci: Add shutdown handler Hanna Hawa
  2019-12-10  9:43 ` [PATCH 0/2] " Hans de Goede
  2 siblings, 0 replies; 4+ messages in thread
From: Hanna Hawa @ 2019-12-09 16:32 UTC (permalink / raw)
  To: axboe, hdegoede
  Cc: linux-ide, linux-kernel, dwmw, benh, ronenk, talel, jonnyc,
	hanochu, barakw, hhhawa

Move ahci platform shutdown function to libahci as preparation to add
shutdown handler for PCIe AHCI.

Signed-off-by: Hanna Hawa <hhhawa@amazon.com>
---
 drivers/ata/ahci.h             |  1 +
 drivers/ata/libahci.c          | 33 +++++++++++++++++++++++++++++++++
 drivers/ata/libahci_platform.c | 20 +-------------------
 3 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
index 3dbf398c92ea..df84dfdf9037 100644
--- a/drivers/ata/ahci.h
+++ b/drivers/ata/ahci.h
@@ -418,6 +418,7 @@ void ahci_set_em_messages(struct ahci_host_priv *hpriv,
 int ahci_reset_em(struct ata_host *host);
 void ahci_print_info(struct ata_host *host, const char *scc_s);
 int ahci_host_activate(struct ata_host *host, struct scsi_host_template *sht);
+void ahci_common_shutdown(struct ata_host *host);
 void ahci_error_handler(struct ata_port *ap);
 u32 ahci_handle_port_intr(struct ata_host *host, u32 irq_masked);
 
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index bff369d9a1a7..f5dd5d66c442 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -2602,6 +2602,39 @@ int ahci_host_activate(struct ata_host *host, struct scsi_host_template *sht)
 }
 EXPORT_SYMBOL_GPL(ahci_host_activate);
 
+/**
+ * ahci_common_shutdown - Disable interrupts and stop DMA for host ports
+ * @host: target ATA host
+ *
+ * This common function is called during system shutdown and performs the
+ * minimal deconfiguration required to ensure that an ahci host cannot corrupt
+ * or otherwise interfere with a new kernel being started with kexec.
+ */
+void ahci_common_shutdown(struct ata_host *host)
+{
+	struct ahci_host_priv *hpriv = host->private_data;
+	void __iomem *mmio = hpriv->mmio;
+	int i;
+
+	for (i = 0; i < host->n_ports; i++) {
+		struct ata_port *ap = host->ports[i];
+
+		/* Disable port interrupts */
+		if (ap->ops->freeze)
+			ap->ops->freeze(ap);
+
+		/* Stop the port DMA engines */
+		if (ap->ops->port_stop)
+			ap->ops->port_stop(ap);
+	}
+
+	/* Disable and clear host interrupts */
+	writel(readl(mmio + HOST_CTL) & ~HOST_IRQ_EN, mmio + HOST_CTL);
+	readl(mmio + HOST_CTL); /* flush */
+	writel(GENMASK(host->n_ports, 0), mmio + HOST_IRQ_STAT);
+}
+EXPORT_SYMBOL_GPL(ahci_common_shutdown);
+
 MODULE_AUTHOR("Jeff Garzik");
 MODULE_DESCRIPTION("Common AHCI SATA low-level routines");
 MODULE_LICENSE("GPL");
diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c
index 8befce036af8..dd2bfa3986f8 100644
--- a/drivers/ata/libahci_platform.c
+++ b/drivers/ata/libahci_platform.c
@@ -680,26 +680,8 @@ static void ahci_host_stop(struct ata_host *host)
 void ahci_platform_shutdown(struct platform_device *pdev)
 {
 	struct ata_host *host = platform_get_drvdata(pdev);
-	struct ahci_host_priv *hpriv = host->private_data;
-	void __iomem *mmio = hpriv->mmio;
-	int i;
-
-	for (i = 0; i < host->n_ports; i++) {
-		struct ata_port *ap = host->ports[i];
-
-		/* Disable port interrupts */
-		if (ap->ops->freeze)
-			ap->ops->freeze(ap);
 
-		/* Stop the port DMA engines */
-		if (ap->ops->port_stop)
-			ap->ops->port_stop(ap);
-	}
-
-	/* Disable and clear host interrupts */
-	writel(readl(mmio + HOST_CTL) & ~HOST_IRQ_EN, mmio + HOST_CTL);
-	readl(mmio + HOST_CTL); /* flush */
-	writel(GENMASK(host->n_ports, 0), mmio + HOST_IRQ_STAT);
+	ahci_common_shutdown(host);
 }
 EXPORT_SYMBOL_GPL(ahci_platform_shutdown);
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] ata: ahci: Add shutdown handler
  2019-12-09 16:32 [PATCH 0/2] ata: ahci: Add shutdown handler Hanna Hawa
  2019-12-09 16:32 ` [PATCH 1/2] ata: libahci: move ahci platform shutdown function to libahci Hanna Hawa
@ 2019-12-09 16:32 ` Hanna Hawa
  2019-12-10  9:43 ` [PATCH 0/2] " Hans de Goede
  2 siblings, 0 replies; 4+ messages in thread
From: Hanna Hawa @ 2019-12-09 16:32 UTC (permalink / raw)
  To: axboe, hdegoede
  Cc: linux-ide, linux-kernel, dwmw, benh, ronenk, talel, jonnyc,
	hanochu, barakw, hhhawa

An issue found while doing kexec on Annapurna Labs SoC: an AXI read
error occur due to an access from the interrupt handler of AHCI to the
AHCI controller.
This patch make sure that the interrupts are disabled for the controller
while doing kexec.

The shutdown handler is called during system shutdown to disable host
controller DMA and interrupts in order to avoid potentially corrupting
or otherwise interfering with a new kernel being started with kexec.

Signed-off-by: Hanna Hawa <hhhawa@amazon.com>
---
 drivers/ata/ahci.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 05c2b32dcc4d..34ddc259343a 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -80,6 +80,7 @@ enum board_ids {
 
 static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
 static void ahci_remove_one(struct pci_dev *dev);
+static void ahci_shutdown(struct pci_dev *dev);
 static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
 				 unsigned long deadline);
 static int ahci_avn_hardreset(struct ata_link *link, unsigned int *class,
@@ -593,6 +594,7 @@ static struct pci_driver ahci_pci_driver = {
 	.id_table		= ahci_pci_tbl,
 	.probe			= ahci_init_one,
 	.remove			= ahci_remove_one,
+	.shutdown		= ahci_shutdown,
 	.driver = {
 		.pm		= &ahci_pci_pm_ops,
 	},
@@ -1870,6 +1872,13 @@ static void ahci_remove_one(struct pci_dev *pdev)
 	ata_pci_remove_one(pdev);
 }
 
+static void ahci_shutdown(struct pci_dev *pdev)
+{
+	struct ata_host *host = pci_get_drvdata(pdev);
+
+	ahci_common_shutdown(host);
+}
+
 module_pci_driver(ahci_pci_driver);
 
 MODULE_AUTHOR("Jeff Garzik");
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] ata: ahci: Add shutdown handler
  2019-12-09 16:32 [PATCH 0/2] ata: ahci: Add shutdown handler Hanna Hawa
  2019-12-09 16:32 ` [PATCH 1/2] ata: libahci: move ahci platform shutdown function to libahci Hanna Hawa
  2019-12-09 16:32 ` [PATCH 2/2] ata: ahci: Add shutdown handler Hanna Hawa
@ 2019-12-10  9:43 ` Hans de Goede
  2 siblings, 0 replies; 4+ messages in thread
From: Hans de Goede @ 2019-12-10  9:43 UTC (permalink / raw)
  To: Hanna Hawa, axboe
  Cc: linux-ide, linux-kernel, dwmw, benh, ronenk, talel, jonnyc,
	hanochu, barakw

HI,

On 09-12-2019 17:32, Hanna Hawa wrote:
> This series introduced AHCI shutdown handler for AHCI PCIe driver, to
> disable host controller DMA and interrupts in order to avoid potentially
> corrupting or otherwise interfering with a new kernel being started with
> kexec.
> 
> Part of this patch move the common part between platform and pcie
> drivers to libahci.c.

Series looks good to me:

Acked-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans



> 
> Hanna Hawa (2):
>    ata: libahci: move ahci platform shutdown function to libahci
>    ata: ahci: Add shutdown handler
> 
>   drivers/ata/ahci.c             |  9 +++++++++
>   drivers/ata/ahci.h             |  1 +
>   drivers/ata/libahci.c          | 33 +++++++++++++++++++++++++++++++++
>   drivers/ata/libahci_platform.c | 20 +-------------------
>   4 files changed, 44 insertions(+), 19 deletions(-)
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-10  9:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-09 16:32 [PATCH 0/2] ata: ahci: Add shutdown handler Hanna Hawa
2019-12-09 16:32 ` [PATCH 1/2] ata: libahci: move ahci platform shutdown function to libahci Hanna Hawa
2019-12-09 16:32 ` [PATCH 2/2] ata: ahci: Add shutdown handler Hanna Hawa
2019-12-10  9:43 ` [PATCH 0/2] " Hans de Goede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).