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

Re: [PATCH v2 7/7] arm/mpu: Implement setup_mpu for MPU system


  • To: Luca Fancellu <luca.fancellu@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Ayan Kumar Halder <ayankuma@xxxxxxx>
  • Date: Tue, 8 Apr 2025 14:32:32 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Ovz1kL9uMFYdJIeklY8U5I6Lw46F+90lnw4iMlcW7JY=; b=LTWGTPbvIxrvoXYuoYL1+67Mi+lMeMKbBQA0bmKjky1P+wGshJqW/JWIiNch6y1vnwTWp8WC4aFgf/L654+/3ZYNdOQFTV3M0MAP3IUxq8yWSOr35xPRvFvRONaTs0XDyI08oQb7T5jw8m6aigAp5XCQL+whUpVK9DdUdXFKQyJQavCzUwiH0gMueG1DQiulm1j2YSSMQ/yI+HOps+sa3kAi1wX8AcQ+tIJ0Ad/22anrCgMzHA2s3Eliw/higCTL2CauBRWfOfY0+hlKCPxAWtoTjSbyyMW4OkTM0TS9TdDFyIdXkXJydvcd5P4Z9XfRtDE0I4VAcS/YAgbZSQDiQg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TImPp3t8GTzsmLF8vvGHziD2ZMdOlKeLcneRs2cyfjt99Zvbp/5dLes66pLfNmfaeFct5znaTxRYnSrl2FmeNzppkodSGBHqw+SGwWECLvH7YfX643oA76g7nlKLgmBsxrNkm6IkiHVdCQ2E+61jIxxj9RU8PhFBUPabbr+YBpC5VuHAGMTG3+X6xnJB+OwrMcSvOS5NHyNkMrVk1mOjbDP0lVaJM8V4av9pROrHtQjJSwSLOgMoQYp6criOiMR8ywvaDP5MdtLPM/2M6SOs2CKb3+HfCFNbKKlNuTBKqM0Iv4ncUelQ5R9NnI1F7donynDMnY13kPPS+ICDnNvEiA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Tue, 08 Apr 2025 13:32:55 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Luca,

On 07/04/2025 10:14, Luca Fancellu 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.


Implement the function setup_mpu that will logically track the MPU
regions defined by hardware registers, start introducing data
structures and functions to track the status from the C world.

The xen_mpumap_mask bitmap is used to track which MPU region are
enabled at runtime.

This function is called from setup_mm() which full implementation
will be provided in a later stage.

Signed-off-by: Luca Fancellu <luca.fancellu@xxxxxxx>
---
  xen/arch/arm/include/asm/arm64/mpu.h |  2 ++
  xen/arch/arm/mpu/mm.c                | 49 +++++++++++++++++++++++++++-
  2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/include/asm/arm64/mpu.h 
b/xen/arch/arm/include/asm/arm64/mpu.h
index 7cf8d355a1af..ff5a957bf085 100644
--- a/xen/arch/arm/include/asm/arm64/mpu.h
+++ b/xen/arch/arm/include/asm/arm64/mpu.h
@@ -6,6 +6,8 @@
  #ifndef __ARM_ARM64_MPU_H__
  #define __ARM_ARM64_MPU_H__

+#define PRENR_MASK  GENMASK(31, 0)
This can be moved to xen/arch/arm/include/asm/mpu.h
+
  /*
   * Excute never.
   * Stage 1 EL2 translation regime.
diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c
index 2c5820a44f13..fe05c8097155 100644
--- a/xen/arch/arm/mpu/mm.c
+++ b/xen/arch/arm/mpu/mm.c
@@ -14,6 +14,17 @@

  struct page_info *frame_table;

+/* 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.
+ */
+DECLARE_BITMAP(xen_mpumap_mask, MAX_MPU_REGIONS);
+
  /* EL2 Xen MPU memory region mapping table. */
  pr_t xen_mpumap[MAX_MPU_REGIONS];

@@ -224,9 +235,45 @@ pr_t pr_of_xenaddr(paddr_t base, paddr_t limit, unsigned 
attr)
      return region;
  }

+/*
+ * The code in this function needs to track the regions programmed in
+ * arm64/mpu/head.S
+ */
+static void __init setup_mpu(void)
+{
+    register_t prenr;
+    unsigned int 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) & NUM_MPU_REGIONS_MASK);
+
+    /* PRENR_EL2 has the N bit set if the N region is enabled, N < 32 */
+    prenr = (READ_SYSREG(PRENR_EL2) & PRENR_MASK);
+
+    /*
+     * Set the bitfield for regions enabled in assembly boot-time.
+     * This code works under the assumption that the code in head.S has
+     * allocated and enabled regions below 32 (N < 32).
+     */
+    while ( prenr > 0 )
+    {
+        if (prenr & 0x1)
+        {
+            set_bit(i, xen_mpumap_mask);
+            read_protection_region(&xen_mpumap[i], i);
+        }
+
+        prenr >>= 1;
+        i++;
+    }
+}
+
  void __init setup_mm(void)
  {
-    BUG_ON("unimplemented");
+    setup_mpu();
  }

  int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)
--
2.34.1
- Ayan




 


Rackspace

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