2019-12-09 16:33:19

by Hanna Hawa

[permalink] [raw]
Subject: [PATCH 0/2] ata: ahci: Add shutdown handler

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


2019-12-09 16:34:16

by Hanna Hawa

[permalink] [raw]
Subject: [PATCH 2/2] ata: ahci: Add shutdown handler

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 <[email protected]>
---
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

2019-12-09 16:34:23

by Hanna Hawa

[permalink] [raw]
Subject: [PATCH 1/2] ata: libahci: move ahci platform shutdown function to libahci

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

Signed-off-by: Hanna Hawa <[email protected]>
---
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

2019-12-10 09:45:14

by Hans de Goede

[permalink] [raw]
Subject: Re: [PATCH 0/2] ata: ahci: Add shutdown handler

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 <[email protected]>

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(-)
>