[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v6 11/11] xen/arm64: add setup_fixmap and remove_identity_mapping for MPU


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Wei Chen <wei.chen@xxxxxxx>
  • Date: Fri, 4 Nov 2022 18:07:41 +0800
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tU2PchcbobCINE1Reghr/rSLoGA3tFIJcSeA7caa+8c=; b=Ps0q4SG+8dViYEb73/yI63YJLRrXjdFOb4yuMMo6OeQY/ZR+L6rrZHK1yVQWg+JWuthEXO1TCk7Wq1b432uCFkr4rTo4Rzm7WyZR5G8UNyhmoCdvwV/GajP5EpIwGf4MkFAqmZ0cDeApw5Zfod7VAqUnlYi2cYkKwyAHDFt+ljvOymjjPwJtBtzj5LW46CIQi4atoTll41+mtRXZRit4fM5XUQIeHy4Tbptixlep3Try75Oe8daHyrWvJ6r8FY4iAvrXG+OCRswlSTvwnd1Hn5dtSaG/ab6pLzDmf8bB1j3FDDii5kplOqatxjB6S/+PH0xgIgNMxeWs5REIeV+wSA==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tU2PchcbobCINE1Reghr/rSLoGA3tFIJcSeA7caa+8c=; b=T790q2uyZMvlJyYZsZFRmP14GPJvqnUeFp3gpTzz1IJG4LkdpHmX46cq/A3l8FSLeI6J0lgrxtp8DGjj+w/bTsUiYfxxmkK+kNjEdbpp4sAqmbdSkJC3uYh6Itfl6HZsHqtYd7FiIRE/T1lTewPnMpEAscOTW/IgqGEDGdnC1nZDAMe3tI66YsQoPFSQUTyfQHp7yfT0rXKkShV6KNHeIb5iTIljUQ8NE49CZgEh9yiKv9p+RcCRU4cKgJrfvp/4iMtu+iHwrRMrR8nR9BYGpt5+tHJ/Tdb2Af+wZQWwevlSJjQc05eLo1VmheGGkQKzuwVX+eL5tHDxscobIy5L8g==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=V3ZI84t8WVOeWA6xyAcbkwF3iBj6VO7/bqg3+QK8MkjPl6MFappBM2YKQ21KaiIRVgx8Vj1E+gMI6kt6olwVyHkZFfbqI+RJsZadCM1+PpwKVXzUqE05xBqq1epSMsVVgR3ofiNXBU76O6Cfc2FeOZr66Hll3ldx3jn7HBte1xfx2S0d1GlywiE4rC00DQZ+iDXZTIOaL9VL9yHTsAL4l41+02yngT2fkSZAsDbA2oMvBfKHw/Vm1LII0gBR0FXQA81isDKeYk4Lb4+aHPvx2C3tqyWtO9pCj24gV4+s0Ez64rQafFpUmU5C+wj11TpehsH2+tuBpFzjeMkRlLA8DQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=irLl3wBBEqQ3cPGX7OkB0CW0Cg5rbgnOHYG5Unk8qqy62HOCImcSaV7t1uVF/+hLnxEBFhdREDGk848bKrEb30z9ikMXFNtdSv8UAnZ/XywBNXfBGwZ2k3INemY/DBlVLLViyDV57yu+S+WFhBcnuStOkh3Bhw+K4KTnKb91ZpT4pd3G6P+x/xG3ZXYYkTj7vlye2/wkJi/SFl73KzDZpnnNlUKN6O9/+nSuoa6gw44mh4PfGeOnddIXwHPkLdraWGuMKgfFd45sDCQ9pmZqk59DXhezVmmHYdBS9iSectEkz+qgX8uAAkU0jZM4fz4SP3iZkcjyGGMHcBmZdiri7A==
  • Cc: <nd@xxxxxxx>, Penny Zheng <penny.zheng@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Wei Chen <wei.chen@xxxxxxx>
  • Delivery-date: Fri, 04 Nov 2022 10:15:12 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true

From: Penny Zheng <penny.zheng@xxxxxxx>

setup_fixmap and remove_identity_mapping are two functions that
are used in Xen boot-time code flow. We implement these two
functions for MPU system, in this case, the code flow in head.S
doesn't need to use #ifdef to gate MPU/MMU code.

In MMU system, setup_fixmap is used for Xen to map some essentail
data or devices in boot-time. For MPU system, we still have this
requirement, we map the early UART to MPU protection region when
earlyprintk is enabled. This also means PRINT can't be used after
turning on MPU but before setup_fixmap. This restriction is the
same as MMU system.

For remove_identity_mapping, we just need an empty function to
make head.S code flow happy.

Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
Signed-off-by: Penny Zheng <penny.zheng@xxxxxxx>
---
 xen/arch/arm/arm64/head_mpu.S                 | 49 +++++++++++++++++++
 .../arm/include/asm/platforms/fvp_baser.h     |  4 ++
 2 files changed, 53 insertions(+)

diff --git a/xen/arch/arm/arm64/head_mpu.S b/xen/arch/arm/arm64/head_mpu.S
index 5a1b03e293..336c0a630f 100644
--- a/xen/arch/arm/arm64/head_mpu.S
+++ b/xen/arch/arm/arm64/head_mpu.S
@@ -20,13 +20,20 @@
 /*
  * In boot stage, we will use 1 MPU region:
  * Region#0: Normal memory for Xen text + data + bss (2MB)
+ * Region#1: Device memory for EARLY UART, size is defined
+ *           by platform's EARLY_UART_SIZE
  */
 #define BOOT_NORMAL_REGION_IDX  0x0
+#define BOOT_DEVICE_REGION_IDX  0x1
 
 /* MPU normal memory attributes. */
 #define PRBAR_NORMAL_MEM        0x30    /* SH=11 AP=00 XN=00 */
 #define PRLAR_NORMAL_MEM        0x0f    /* NS=0 ATTR=111 EN=1 */
 
+/* MPU device memory attributes. */
+#define PRBAR_DEVICE_MEM        0x20    /* SH=10 AP=00 XN=00 */
+#define PRLAR_DEVICE_MEM        0x09    /* NS=0 ATTR=100 EN=1 */
+
 .macro write_pr, sel, prbar, prlar
     msr   PRSELR_EL2, \sel
     dsb   sy
@@ -69,6 +76,48 @@ ENTRY(prepare_early_mappings)
     ret
 ENDPROC(prepare_early_mappings)
 
+/*
+ * In MMU system, setup_fixmap is used for Xen to map some essential data
+ * or devices in boot-time. In order to be consistent with MMU system, we
+ * inherit the function name for MPU system.
+ * setup_fixmap of MPU system will:
+ * - Map the early UART to MPU protection region when earlyprintk is
+ *   enabled (The PRINT can't be used after turning on MPU but before
+ *   setup_fixmap).
+ *
+ * Clobbers x0 - x3
+ */
+ENTRY(setup_fixmap)
+#ifdef CONFIG_EARLY_PRINTK
+    /* Map early uart to MPU device region for early printk. */
+    mov x0, #BOOT_DEVICE_REGION_IDX
+    ldr x1, =CONFIG_EARLY_UART_BASE_ADDRESS
+    and x1, x1, #MPU_REGION_MASK
+    mov x3, #PRBAR_DEVICE_MEM
+    orr x1, x1, x3
+
+    ldr x2, =CONFIG_EARLY_UART_BASE_ADDRESS
+    ldr x3, =(CONFIG_EARLY_UART_BASE_ADDRESS + EARLY_UART_SIZE - 1)
+    add x2, x2, x3
+    and x2, x2, #MPU_REGION_MASK
+    mov x3, #PRLAR_DEVICE_MEM
+    orr x2, x2, x3
+
+    /*
+     * Write to MPU protection region:
+     * x0 for pr_sel, x1 for prbar x2 for prlar
+     */
+    write_pr x0, x1, x2
+#endif
+
+    ret
+ENDPROC(setup_fixmap)
+
+/* Stub of remove_identity_mapping for MPU systems */
+ENTRY(remove_identity_mapping)
+    ret
+ENDPROC(remove_identity_mapping)
+
 /*
  * Enable EL2 MPU and data cache. Because we will disable cache
  * with MPU at the same time, in accordance with that, we have
diff --git a/xen/arch/arm/include/asm/platforms/fvp_baser.h 
b/xen/arch/arm/include/asm/platforms/fvp_baser.h
index 9450a411a9..acde3541a1 100644
--- a/xen/arch/arm/include/asm/platforms/fvp_baser.h
+++ b/xen/arch/arm/include/asm/platforms/fvp_baser.h
@@ -11,4 +11,8 @@
 #define XEN_START_ADDRESS CONFIG_XEN_START_ADDRESS
 #endif
 
+#ifdef CONFIG_EARLY_PRINTK
+#define EARLY_UART_SIZE   0x1000
+#endif
+
 #endif /* __ASM_ARM_PLATFORMS_FVP_BASER_H__ */
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.