]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/5.1.12/iommu-arm-smmu-avoid-constant-zero-in-tlbi-writes.patch
Linux 5.1.12
[thirdparty/kernel/stable-queue.git] / releases / 5.1.12 / iommu-arm-smmu-avoid-constant-zero-in-tlbi-writes.patch
CommitLineData
1085140b
GKH
1From 4e4abae311e4b44aaf61f18a826fd7136037f199 Mon Sep 17 00:00:00 2001
2From: Robin Murphy <robin.murphy@arm.com>
3Date: Mon, 3 Jun 2019 14:15:37 +0200
4Subject: iommu/arm-smmu: Avoid constant zero in TLBI writes
5
6From: Robin Murphy <robin.murphy@arm.com>
7
8commit 4e4abae311e4b44aaf61f18a826fd7136037f199 upstream.
9
10Apparently, some Qualcomm arm64 platforms which appear to expose their
11SMMU global register space are still, in fact, using a hypervisor to
12mediate it by trapping and emulating register accesses. Sadly, some
13deployed versions of said trapping code have bugs wherein they go
14horribly wrong for stores using r31 (i.e. XZR/WZR) as the source
15register.
16
17While this can be mitigated for GCC today by tweaking the constraints
18for the implementation of writel_relaxed(), to avoid any potential
19arms race with future compilers more aggressively optimising register
20allocation, the simple way is to just remove all the problematic
21constant zeros. For the write-only TLB operations, the actual value is
22irrelevant anyway and any old nearby variable will provide a suitable
23GPR to encode. The one point at which we really do need a zero to clear
24a context bank happens before any of the TLB maintenance where crashes
25have been reported, so is apparently not a problem... :/
26
27Reported-by: AngeloGioacchino Del Regno <kholk11@gmail.com>
28Tested-by: Marc Gonzalez <marc.w.gonzalez@free.fr>
29Signed-off-by: Robin Murphy <robin.murphy@arm.com>
30Signed-off-by: Marc Gonzalez <marc.w.gonzalez@free.fr>
31Acked-by: Will Deacon <will.deacon@arm.com>
32Cc: stable@vger.kernel.org
33Signed-off-by: Joerg Roedel <jroedel@suse.de>
34Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
35
36---
37 drivers/iommu/arm-smmu.c | 15 ++++++++++++---
38 1 file changed, 12 insertions(+), 3 deletions(-)
39
40--- a/drivers/iommu/arm-smmu.c
41+++ b/drivers/iommu/arm-smmu.c
42@@ -59,6 +59,15 @@
43
44 #include "arm-smmu-regs.h"
45
46+/*
47+ * Apparently, some Qualcomm arm64 platforms which appear to expose their SMMU
48+ * global register space are still, in fact, using a hypervisor to mediate it
49+ * by trapping and emulating register accesses. Sadly, some deployed versions
50+ * of said trapping code have bugs wherein they go horribly wrong for stores
51+ * using r31 (i.e. XZR/WZR) as the source register.
52+ */
53+#define QCOM_DUMMY_VAL -1
54+
55 #define ARM_MMU500_ACTLR_CPRE (1 << 1)
56
57 #define ARM_MMU500_ACR_CACHE_LOCK (1 << 26)
58@@ -422,7 +431,7 @@ static void __arm_smmu_tlb_sync(struct a
59 {
60 unsigned int spin_cnt, delay;
61
62- writel_relaxed(0, sync);
63+ writel_relaxed(QCOM_DUMMY_VAL, sync);
64 for (delay = 1; delay < TLB_LOOP_TIMEOUT; delay *= 2) {
65 for (spin_cnt = TLB_SPIN_COUNT; spin_cnt > 0; spin_cnt--) {
66 if (!(readl_relaxed(status) & sTLBGSTATUS_GSACTIVE))
67@@ -1760,8 +1769,8 @@ static void arm_smmu_device_reset(struct
68 }
69
70 /* Invalidate the TLB, just in case */
71- writel_relaxed(0, gr0_base + ARM_SMMU_GR0_TLBIALLH);
72- writel_relaxed(0, gr0_base + ARM_SMMU_GR0_TLBIALLNSNH);
73+ writel_relaxed(QCOM_DUMMY_VAL, gr0_base + ARM_SMMU_GR0_TLBIALLH);
74+ writel_relaxed(QCOM_DUMMY_VAL, gr0_base + ARM_SMMU_GR0_TLBIALLNSNH);
75
76 reg = readl_relaxed(ARM_SMMU_GR0_NS(smmu) + ARM_SMMU_GR0_sCR0);
77