arm,smmu: match start level of page table walk with P2M
authorLaurentiu Tudor <laurentiu.tudor@nxp.com>
Fri, 2 Oct 2020 10:33:44 +0000 (13:33 +0300)
committerStefano Stabellini <sstabellini@kernel.org>
Fri, 6 Nov 2020 01:49:54 +0000 (17:49 -0800)
Don't hardcode the lookup start level of the page table walk to 1
and instead match the one used in P2M. This should fix scenarios
involving SMMU where the start level is different than 1.
In order for the SMMU driver to also compile on arm32 move the
P2M_ROOT_LEVEL in the p2m header file (while at it, for
consistency also P2M_ROOT_ORDER) and use the macro in the smmu
driver.

Signed-off-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>
Acked-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
(cherry picked from commit 9ae1197582798b394d696cff94c4d742319bdbbf)

xen/arch/arm/p2m.c
xen/drivers/passthrough/arm/smmu.c
xen/include/asm-arm/p2m.h

index ce59f2b503b29f1e830421b7492de9cd902b88be..4eeb867ca1d1c719793fa3d919d2b86dbf1f61bc 100644 (file)
 #define INVALID_VMID 0 /* VMID 0 is reserved */
 
 #ifdef CONFIG_ARM_64
-static unsigned int __read_mostly p2m_root_order;
-static unsigned int __read_mostly p2m_root_level;
-#define P2M_ROOT_ORDER    p2m_root_order
-#define P2M_ROOT_LEVEL p2m_root_level
+unsigned int __read_mostly p2m_root_order;
+unsigned int __read_mostly p2m_root_level;
 static unsigned int __read_mostly max_vmid = MAX_VMID_8_BIT;
 /* VMID is by default 8 bit width on AArch64 */
 #define MAX_VMID       max_vmid
 #else
-/* First level P2M is always 2 consecutive pages */
-#define P2M_ROOT_LEVEL 1
-#define P2M_ROOT_ORDER    1
 /* VMID is always 8 bit width on AArch32 */
 #define MAX_VMID        MAX_VMID_8_BIT
 #endif
index 94662a850187b2d07e788a69027ac67e0e5b848d..4ba6d3ab94a8e5acfcb36cb4222dc59caf56aef6 100644 (file)
@@ -1152,7 +1152,7 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain)
              (TTBCR_RGN_WBWA << TTBCR_IRGN0_SHIFT);
 
        if (!stage1)
-               reg |= (TTBCR_SL0_LVL_1 << TTBCR_SL0_SHIFT);
+               reg |= (2 - P2M_ROOT_LEVEL) << TTBCR_SL0_SHIFT;
 
        writel_relaxed(reg, cb_base + ARM_SMMU_CB_TTBCR);
 
index 5fdb6e81834847fc1cedad3fbff7da780945a201..28ca9a838e0d61b8d9fafc304df5d3bd750364f5 100644 (file)
 /* Holds the bit size of IPAs in p2m tables.  */
 extern unsigned int p2m_ipa_bits;
 
+#ifdef CONFIG_ARM_64
+extern unsigned int p2m_root_order;
+extern unsigned int p2m_root_level;
+#define P2M_ROOT_ORDER    p2m_root_order
+#define P2M_ROOT_LEVEL p2m_root_level
+#else
+/* First level P2M is always 2 consecutive pages */
+#define P2M_ROOT_ORDER    1
+#define P2M_ROOT_LEVEL 1
+#endif
+
 struct domain;
 
 extern void memory_type_changed(struct domain *);