]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
iommu/arm-smmu-v3: Abort all transactions if SMMU is enabled in kdump kernel
authorWill Deacon <will.deacon@arm.com>
Mon, 3 Jun 2019 21:16:00 +0000 (23:16 +0200)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Tue, 2 Jul 2019 12:18:49 +0000 (14:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1828868
If we find that the SMMU is enabled during probe, we reset it by
re-initialising its registers and either enabling translation or placing
it into bypass based on the disable_bypass commandline option.

In the case of a kdump kernel, the SMMU won't have been shutdown cleanly
by the previous kernel and there may be concurrent DMA through the SMMU.
Rather than reset the SMMU to bypass, which would likely lead to rampant
data corruption, we can instead configure the SMMU to abort all incoming
transactions when we find that it is enabled from within a kdump kernel.

Reported-by: Sameer Goel <sgoel@codeaurora.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(backported from commit b63b3439b85609338e4faabd5d2588dbda137e5c)
[ dannf: trivial offset adjustment in #include section ]
Signed-off-by: dann frazier <dann.frazier@canonical.com>
Acked-by: Connor Kuehl <connor.kuehl@canonical.com>
Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
drivers/iommu/arm-smmu-v3.c

index c6e844ca416b4269debe9da0a607ab2d37191b05..0366c2aaba29b9a3b36ef045081bb93d5b6c566c 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <linux/acpi.h>
 #include <linux/acpi_iort.h>
+#include <linux/crash_dump.h>
 #include <linux/delay.h>
 #include <linux/dma-iommu.h>
 #include <linux/err.h>
@@ -2328,8 +2329,12 @@ static int arm_smmu_update_gbpa(struct arm_smmu_device *smmu, u32 set, u32 clr)
        reg &= ~clr;
        reg |= set;
        writel_relaxed(reg | GBPA_UPDATE, gbpa);
-       return readl_relaxed_poll_timeout(gbpa, reg, !(reg & GBPA_UPDATE),
-                                         1, ARM_SMMU_POLL_TIMEOUT_US);
+       ret = readl_relaxed_poll_timeout(gbpa, reg, !(reg & GBPA_UPDATE),
+                                        1, ARM_SMMU_POLL_TIMEOUT_US);
+
+       if (ret)
+               dev_err(smmu->dev, "GBPA not responding to update\n");
+       return ret;
 }
 
 static void arm_smmu_free_msis(void *data)
@@ -2498,8 +2503,15 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu, bool bypass)
 
        /* Clear CR0 and sync (disables SMMU and queue processing) */
        reg = readl_relaxed(smmu->base + ARM_SMMU_CR0);
-       if (reg & CR0_SMMUEN)
+       if (reg & CR0_SMMUEN) {
+               if (is_kdump_kernel()) {
+                       arm_smmu_update_gbpa(smmu, GBPA_ABORT, 0);
+                       arm_smmu_device_disable(smmu);
+                       return -EBUSY;
+               }
+
                dev_warn(smmu->dev, "SMMU currently enabled! Resetting...\n");
+       }
 
        ret = arm_smmu_device_disable(smmu);
        if (ret)
@@ -2597,10 +2609,8 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu, bool bypass)
                enables |= CR0_SMMUEN;
        } else {
                ret = arm_smmu_update_gbpa(smmu, 0, GBPA_ABORT);
-               if (ret) {
-                       dev_err(smmu->dev, "GBPA not responding to update\n");
+               if (ret)
                        return ret;
-               }
        }
        ret = arm_smmu_write_reg_sync(smmu, enables, ARM_SMMU_CR0,
                                      ARM_SMMU_CR0ACK);