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, 2 Oct 2020 17:21:56 +0000 (10:21 -0700)
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>
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 06f9bda47dcb9cbc2d82ecf9dd90917508f18b9b..b8321f5d8d347dedeab2b2d8093372225b5832fe 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 *);