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

Re: [PATCH v3 27/52] xen/mpu: introduce setup_mm_mappings


  • To: Ayan Kumar Halder <ayankuma@xxxxxxx>, Julien Grall <julien@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Penny Zheng <penny.zheng@xxxxxxx>
  • Date: Fri, 30 Jun 2023 10:41:42 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=amd.com 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=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=+xK1rqn9juYvQui7SX4KohYH8BQLQSbt3eja544/6ak=; b=gpuknF934OqdxeU+UbhxwOLf3xnojMsU63fVjf49O0ztess4zH3sQeeDOTUAOAhtOJCX9S/eqj/JD1x08hyHc3ORBic9Y+7/tqxnb6nfTX4fhNYZ+nbhiQJTJ1/SWKu5s+uJJ+ja89zOx5jrDeEfpz6559v6sfvB6lpscSsoUDYkBAGeUEkEOdBPXI0hfou5I8VedmyWeURp+tsDDr5mARCUWv5UJLP1w5qzURAp8Arc71Qui0YMyP2afRs1lsbliJYAuO7lqjjEanSO6nv3yPreMmH8QFTU8VlFell915wbWmZKGYZU8+JbJAvyNgsZfM5a3Nv9WVJfjwFH4UuflA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KoQsQ5sJ1HBvjGTuqtKSHDHwj8uKK60r6M2F8tHeZ9sUPfiRyrgSPrcoBkYY2JNWWJdEkLYrpwv2Tg7WdU9BQDwJFCW7SBynG0zmgc3WYS15MpJSfTTGu9/V8NX1keNJUCo6f99dCd18grw9xpHNK2YwkukU5Stj/rHGu/HuHwjbj95Pb5+n5jbVPCYVSCDm7mXVrwCpw5XN1/TWDnVU0LgKAvmbMNZDBJFKd9p4hcrfoZ+zBsUcr450Sy3CoPM/wJ6ZlIZjcPV6vMhArbw0szaqGBRPY20xS9qeFOae1O+pHJ11UX1bfNPwkLNU1uIJj/xCBVXNYoSivH0ccDosyg==
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Wei Chen <wei.chen@xxxxxxx>
  • Delivery-date: Fri, 30 Jun 2023 02:42:16 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true

Hi,


On 2023/6/29 22:50, Ayan Kumar Halder wrote:

On 29/06/2023 15:29, Julien Grall wrote:
Hi,

On 29/06/2023 15:05, Ayan Kumar Halder wrote:
On 26/06/2023 04:34, Penny Zheng wrote:
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.


Function setup_pagetables is responsible for boot-time pagetable setup
in MMU system at C world.
In MPU system, as we have already built up start-of-day Xen MPU memory
region mapping in assembly boot-time, here we only need to do a few
memory management data initializtion, including reading the number of
maximum MPU regions supported by the EL2 MPU, and setting the according
bitfield for regions enabled in assembly boot-time, in bitmap xen_mpumap_mask. This bitmap xen_mpumap_mask is responsible for recording the usage of EL2 MPU
memory regions.

In order to keep only one codeflow in arm/setup.c, setup_mm_mappings
, with a more generic name, is introduced to replace setup_pagetables.

Signed-off-by: Penny Zheng <penny.zheng@xxxxxxx>
Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
---
v3:
- introduce bitmap xen_mpumap_mask for dynamic allocation on MPU regions
---
  xen/arch/arm/include/asm/arm64/mpu.h     |  1 +
  xen/arch/arm/include/asm/arm64/sysregs.h |  3 +++
  xen/arch/arm/include/asm/mm.h            |  4 ++--
  xen/arch/arm/mmu/mm.c                    |  7 +++++-
  xen/arch/arm/mpu/mm.c                    | 30 ++++++++++++++++++++++++
  xen/arch/arm/setup.c                     |  2 +-
  6 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/xen/arch/arm/include/asm/arm64/mpu.h b/xen/arch/arm/include/asm/arm64/mpu.h
index 6ec2c10b14..407fec66c9 100644
--- a/xen/arch/arm/include/asm/arm64/mpu.h
+++ b/xen/arch/arm/include/asm/arm64/mpu.h
@@ -19,6 +19,7 @@
   * or it needs adjustment.
   */
  #define REGION_UART_SEL            0x07
+#define MPUIR_REGION_MASK          ((_AC(1, UL) << 8) - 1)

May be this is simpler to read

#define MPUIR_REGION_MASK _AC(0xFF, UL)

Also, you can move it to xen/arch/arm/include/asm/mpu.h as it is common between R52 and R82.

I would actually prefer if we use GENMASK(...).

[...]

Sure, I'll switch to use GENMASK(...).


diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c
index fb6bb721b1..e06a6e5810 100644
--- a/xen/arch/arm/mpu/mm.c
+++ b/xen/arch/arm/mpu/mm.c
@@ -20,6 +20,7 @@
   */

  #include <xen/init.h>
+#include <xen/mm.h>
  #include <xen/page-size.h>
  #include <asm/arm64/mpu.h>

@@ -27,6 +28,35 @@
  pr_t __aligned(PAGE_SIZE) __section(".data.page_aligned")
       xen_mpumap[ARM_MAX_MPU_MEMORY_REGIONS];

+/* Maximum number of supported MPU memory regions by the EL2 MPU. */
+uint8_t __ro_after_init max_xen_mpumap;
+
+/*
+ * Bitmap xen_mpumap_mask is to record the usage of EL2 MPU memory regions.
+ * Bit 0 represents MPU memory region 0, bit 1 represents MPU memory
+ * region 1, ..., and so on.
+ * If a MPU memory region gets enabled, set the according bit to 1.
+ */
+static DECLARE_BITMAP(xen_mpumap_mask, ARM_MAX_MPU_MEMORY_REGIONS);
+
+void __init setup_mm_mappings(unsigned long boot_phys_offset)
+{
+    unsigned int nr_regions = REGION_UART_SEL, i = 0;
+
+    /*
+     * MPUIR_EL2.Region[0:7] identifies the number of regions supported by
+     * the EL2 MPU.
+     */
+    max_xen_mpumap = (uint8_t)(READ_SYSREG(MPUIR_EL2) & MPUIR_REGION_MASK);

NIT:- You may dop "& MPUIR_REGION_MASK " as the other bits are RES0

From the Arm Arm (look for the definition of RES0 in the glossary):

"
To preserve forward compatibility, software:
• Must not rely on the bit reading as 0.
• Must use an SBZP policy to write to the bit.
"

So we should not drop "& MPUIR_REGION_MASK".

Yes, you are correct.

Penny, please disregard my NIT.

- Ayan


Cheers,




 


Rackspace

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