All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Chen <wei.chen@arm.com>
To: <xen-devel@lists.xenproject.org>
Cc: <nd@arm.com>, Penny Zheng <penny.zheng@arm.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
	Wei Chen <wei.chen@arm.com>
Subject: [PATCH v6 10/11] xen/arm64: introduce helpers for MPU enable/disable
Date: Fri, 4 Nov 2022 18:07:40 +0800	[thread overview]
Message-ID: <20221104100741.2176307-11-wei.chen@arm.com> (raw)
In-Reply-To: <20221104100741.2176307-1-wei.chen@arm.com>

From: Penny Zheng <penny.zheng@arm.com>

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@arm.com>
Signed-off-by: Penny Zheng <penny.zheng@arm.com>
---
 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



  parent reply	other threads:[~2022-11-04 10:19 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-04 10:07 [PATCH v6 00/11] xen/arm: Add Armv8-R64 MPU support to Xen - Part#1 Wei Chen
2022-11-04 10:07 ` [PATCH v6 01/11] xen/arm: remove xen_phys_start and xenheap_phys_end from config.h Wei Chen
2022-11-06 18:42   ` Julien Grall
2022-11-04 10:07 ` [PATCH v6 02/11] xen/arm: add iounmap after initrd has been loaded in domain_build Wei Chen
2022-11-06 18:55   ` Julien Grall
2022-11-07  1:33     ` Henry Wang
2022-11-07  9:09       ` Julien Grall
2022-11-07  9:11         ` Henry Wang
2022-11-07 19:00     ` Julien Grall
2022-11-08  2:14     ` Wei Chen
2022-11-08  2:24       ` Wei Chen
2022-11-04 10:07 ` [PATCH v6 03/11] xen/arm: disable EFI boot services for MPU systems Wei Chen
2022-11-06 19:12   ` Julien Grall
2022-11-06 19:13     ` Julien Grall
2022-11-08  3:02     ` Wei Chen
2022-11-15  8:21     ` Wei Chen
2022-11-04 10:07 ` [PATCH v6 04/11] xen/arm: adjust Xen TLB helpers for Armv8-R64 PMSA Wei Chen
2022-11-04 10:07 ` [PATCH v6 05/11] xen/arm: define Xen start address for FVP BaseR platform Wei Chen
2022-11-06 19:19   ` Julien Grall
2022-11-09  4:55     ` Wei Chen
2022-11-09 18:24       ` Julien Grall
2022-11-10 22:12         ` Stefano Stabellini
2022-11-11 10:13           ` Wei Chen
2022-11-11 20:15             ` Stefano Stabellini
2022-12-05 10:17         ` Wei Chen
2022-12-05 11:02           ` Julien Grall
2022-11-14 18:52   ` Ayan Kumar Halder
2022-11-15  5:42     ` Wei Chen
2022-11-04 10:07 ` [PATCH v6 06/11] xen/arm: split MMU and MPU config files from config.h Wei Chen
2022-11-04 10:07 ` [PATCH v6 07/11] xen/arm: implement FIXMAP_ADDR for MPU systems Wei Chen
2022-11-06 19:44   ` Julien Grall
2022-11-09  6:46     ` Wei Chen
2022-11-09 18:30       ` Julien Grall
2022-11-11  7:56         ` Wei Chen
2022-11-11  9:40           ` Julien Grall
2022-11-04 10:07 ` [PATCH v6 08/11] xen/arm64: move MMU related code from head.S to head_mmu.S Wei Chen
2022-11-06 20:06   ` Julien Grall
2022-11-07  9:34     ` Julien Grall
2022-11-09  7:36     ` Wei Chen
2022-11-09 18:33       ` Julien Grall
2022-11-13 21:42       ` Julien Grall
2022-11-14  5:36         ` Wei Chen
2022-11-04 10:07 ` [PATCH v6 09/11] xen/arm64: create boot-time MPU protection regions Wei Chen
2022-11-06 20:46   ` Julien Grall
2022-11-07  6:59     ` Penny Zheng
2022-11-07  9:29       ` Julien Grall
2022-11-07 10:17         ` Penny Zheng
2022-11-04 10:07 ` Wei Chen [this message]
2022-11-06 20:56   ` [PATCH v6 10/11] xen/arm64: introduce helpers for MPU enable/disable Julien Grall
2022-11-07  9:57     ` Penny Zheng
2022-11-07 10:38       ` Julien Grall
2022-11-08  3:01         ` Penny Zheng
2022-11-04 10:07 ` [PATCH v6 11/11] xen/arm64: add setup_fixmap and remove_identity_mapping for MPU Wei Chen
2022-11-06 21:02   ` Julien Grall
2022-11-07  8:13     ` Penny Zheng
2022-11-07  9:32       ` Julien Grall
2022-11-04 10:29 ` [PATCH v6 00/11] xen/arm: Add Armv8-R64 MPU support to Xen - Part#1 Wei Chen
2022-11-06 19:02 ` Julien Grall
2022-11-07  9:52   ` Wei Chen
2022-11-07 10:16     ` Julien Grall
2022-11-07 10:30       ` Wei Chen
2022-11-10 22:25         ` Stefano Stabellini
2022-11-11 10:41           ` Wei Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221104100741.2176307-11-wei.chen@arm.com \
    --to=wei.chen@arm.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=nd@arm.com \
    --cc=penny.zheng@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.