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

[PATCH v6 10/11] xen/arm64: introduce helpers for MPU enable/disable


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Wei Chen <wei.chen@xxxxxxx>
  • Date: Fri, 4 Nov 2022 18:07:40 +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=CMfl5+3GdSMw3LrCIRYTsE7TNrypLt4CfBNsRud2G8c=; b=DgU1HGMhsPTUCOpdZTROseHWww2A3MAGcS7fH2EBLD8t+mB8Mdev89CFfpI3P5T4/csNnQbczKjcSCVtPdv80jNP6I0YGX3rCyxk3+al3iPl2sXCZRyvf7gZcLlmGY8C0El3A76gDAVAf0hiousdwZFZ1FvRaogMsQxr6e2LusAsKgkQupo7o7C6R4hp828JquKR48dbnCsZofocIPZgLakWz8uu1Cd0s4Ry+Ah+zD0uqBIbQMIbwp0vlWRZX3XMMonG5ikBoUoVb1ogRWO06cTlzLoLXMB86JRcPp5AOgfRcY+I3utFj61U+IJRq8v+QIMbDU65/AKhXYAEaLfS9w==
  • 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=CMfl5+3GdSMw3LrCIRYTsE7TNrypLt4CfBNsRud2G8c=; b=mB45yfV83gTxveVnhgXIxH/P9WFelYD/YkwuG6cczHpCyuPkbzdc9Icuk2luTbZR5YxBlCL22qjNB3m7P+mevTnIIqeSdbWCf/eE0LyyrOQmCMpBRxU4Aa2YrWV2NczUbpJzqKVj76MsyjDxqxvphtkr4i93l+knfou0MI8f76xvEy8Sid4zeObqnbkJ5xhnFMyZjm3cSEAqUie/ZuxfJIN37t1BujTlRtRY1qdhzEo4bxlmZxjCZXsuGFbZQbxmS0lx6woWlkz+lhSSFs5sMmRI8DDv/ftyWeHrVqDZp17m6GqqyAoiGt4EA/426LLFyzI0qge+NjYgXLlXRhvHiw==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=eDjEirHGu+btAIGZUxhGQ62kpA+tyYQoJwIWJwei/E8KLoK9NmsYzOM4cXpLw5MAU5Uj1sIEX0vUrkP9SKwRXs7fDC7GjBYjBXfMEatoq8DHcrQFKGF+aI0aXV68xHuA2gaZ4iwGxtQnDrurKmOJOgEf3sf/ynnFiB9nmu/C7jlbjjV9LMiz65Iao8Vp0Z4kkzfA0wkkAGYBDqxCkF9jlioB5ZlG1Z4Jw/qPWdalZynMIi6zNdXaz2paZc9adfpzZ+gv8zSaq6nFUkSVeg0YqmowLGRDISaHnZ2BBce6n6x+3A7FElEOQ6pns0DpU/FF97XIHuwNnPgItLBV+Mi58Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VqGjtyfsbyx/rE3GMZVK//3szsOcLNjMnbslH0JniCwHsYgc+EJAdMWQmkxW46CpX9QjjFnkB4LFSr2ZphwIC8lMoTc0OE7AUyhkAPDYFaTBv7qCwa+z6uJcruVIE/rw2+7ibJxW8SjM5+mhBJ5lFeBWJQ8/wrsLTLKPvSEe9c7bw9PfNTGZKuKEC78ZSYYDVVIg/ei7+G/s4uciD7wSXawfgWG2ugMdJDYXMPTnM6b2cAgCkloQlo/7peld0TXDMymdbqTo05jQu2+onuJW55Alic4+oB1OXHVaAkS4P9HOQDTPvz7zHLHVZ+IPpJxveEKZFdDocQw4I+AuwfglIQ==
  • 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:19:47 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true

From: Penny Zheng <penny.zheng@xxxxxxx>

We need some helpers for Xen to enable/disable MPU in boot-time
and runtime. For MPU enable helper, we know that it's an
essential requirement of MPU system. But for MPU disable,
we need to use it for some special situations. For example,
in the progress of tranferring from boot-time to runtime,
we need to update the MPU protection regions configuration,
but we can't modify an MPU protection region if there is some
data accessed by Xen. But in boot-time all of Xen text, data
and BSS are in one MPU protection region, if Xen want to update
this protection region, above restriction will be triggered.
So in this situation, we need to disable the whole MPU to update
the protection regions.

In these helper, enable/disable MPU will also enable/disable
the D-cache. There are two reasons for it:
1. Make the function semantic be consistent with enable_mmu.
   For MMU systems, enable_mmu will turn MMU and D-Cache at
   the same time.
2. When MPU is disabled, the MPU background attributes will
   be used. On some platforms, the background will treat all
   memory as device memory. The access to device memory will
   bypass the cache, even if the C bit is enabled in SCTLR.
   To avoid this implicit behavior, we disable cache with MPU
   explicitly to tell user that when MPU is disabled, the
   memory access is uncacheable.

In this patch, we also introduce a neutral name enable_mm for
Xen to enable MMU/MPU. This can help us to keep one code flow
in head.S

Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
Signed-off-by: Penny Zheng <penny.zheng@xxxxxxx>
---
 xen/arch/arm/arm64/head.S     |  5 +++--
 xen/arch/arm/arm64/head_mmu.S |  4 ++--
 xen/arch/arm/arm64/head_mpu.S | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S
index 6c1a5f74a1..228f01db69 100644
--- a/xen/arch/arm/arm64/head.S
+++ b/xen/arch/arm/arm64/head.S
@@ -255,7 +255,8 @@ real_start_efi:
          * and protection regions for MPU systems.
          */
         bl    prepare_early_mappings
-        bl    enable_mmu
+        /* Turn on MMU or MPU */
+        bl    enable_mm
 
         /* We are still in the 1:1 mapping. Jump to the runtime Virtual 
Address. */
         ldr   x0, =primary_switched
@@ -313,7 +314,7 @@ GLOBAL(init_secondary)
         bl    check_cpu_mode
         bl    cpu_init
         bl    prepare_early_mappings
-        bl    enable_mmu
+        bl    enable_mm
 
         /* We are still in the 1:1 mapping. Jump to the runtime Virtual 
Address. */
         ldr   x0, =secondary_switched
diff --git a/xen/arch/arm/arm64/head_mmu.S b/xen/arch/arm/arm64/head_mmu.S
index fc64819a98..b542755bd2 100644
--- a/xen/arch/arm/arm64/head_mmu.S
+++ b/xen/arch/arm/arm64/head_mmu.S
@@ -217,7 +217,7 @@ ENDPROC(prepare_early_mappings)
  *
  * Clobbers x0 - x3
  */
-ENTRY(enable_mmu)
+ENTRY(enable_mm)
         PRINT("- Turning on paging -\r\n")
 
         /*
@@ -239,7 +239,7 @@ ENTRY(enable_mmu)
         msr   SCTLR_EL2, x0          /* now paging is enabled */
         isb                          /* Now, flush the icache */
         ret
-ENDPROC(enable_mmu)
+ENDPROC(enable_mm)
 
 /*
  * Remove the 1:1 map from the page-tables. It is not easy to keep track
diff --git a/xen/arch/arm/arm64/head_mpu.S b/xen/arch/arm/arm64/head_mpu.S
index f60611b556..5a1b03e293 100644
--- a/xen/arch/arm/arm64/head_mpu.S
+++ b/xen/arch/arm/arm64/head_mpu.S
@@ -68,3 +68,38 @@ ENTRY(prepare_early_mappings)
 
     ret
 ENDPROC(prepare_early_mappings)
+
+/*
+ * Enable EL2 MPU and data cache. Because we will disable cache
+ * with MPU at the same time, in accordance with that, we have
+ * to enable cache with MPU at the same time in this function.
+ * When MPU is disabled, the MPU background attributes will
+ * be used. On some platform, the background will treat all
+ * memory as IO memory. The access to IO memory will bypass
+ * the cache, even you have enabled the C bit in SCTLR.
+ * To avoid this implicit behavior, we disable cache with MPU
+ * explicitly to tell user that when MPU is disabled, the memory
+ * access is uncacheable.
+ */
+ENTRY(enable_mm)
+    mrs   x0, SCTLR_EL2
+    mov   x1, #(SCTLR_Axx_ELx_M | SCTLR_Axx_ELx_C)
+    /* Enable EL2 MPU and D-cache */
+    orr   x0, x0, x1
+    dsb   sy
+    msr   SCTLR_EL2, x0
+    isb
+    ret
+ENDPROC(enable_mm)
+
+/* Disable MPU system, including data cache. */
+ENTRY(disable_mm)
+    mrs   x0, SCTLR_EL2
+    mov   x1, #~(SCTLR_Axx_ELx_M | SCTLR_Axx_ELx_C)
+    /* Disable EL2 MPU and D-cache */
+    and   x0, x0, x1
+    dsb   sy
+    msr   SCTLR_EL2, x0
+    isb
+    ret
+ENDPROC(disable_mm)
-- 
2.25.1




 


Rackspace

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