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

Re: [PATCH 05/10] arm/mpu: Introduce frame_table, virt_to_page, maddr_to_virt


  • To: Julien Grall <julien@xxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Thu, 13 Mar 2025 11:51:50 +0000
  • Accept-language: en-GB, en-US
  • 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=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; 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=6IbuvHDi3IEbxpb97HACbzLYj7M9FxHnZIeq0kBOD9o=; b=qw+Z86qQJ9L5doTQ4NTqkU5qCWRODo0CuzYj53ZSNJ+KRUlnaj9g8IYjN9MI9OVQ2JRcVaNVxAkKuU5tRTVAh7cNC8EBaSwCcxmyFGqOqmrfdigLE5KswX43vjIS3zcT2dtwLHg1Tpplrk4y3y4X1WfsXDuJYpvpJvhh3brDdt9xopFyNvjqHnxcuY/DdO2oBcJV9Qr66t3R470Nwp9FOlUoFS+OEG33ytXpTXO81HNGaPHSikXTuQ8ZAsPUzhnb7bmkChuqB58n2pbz9YG2/Iz+d+ae+PSE5FOBrvzHuch7DTD2Jh6ppWbem664gUeEuwD/C/ElLewgUVnkTkeEXA==
  • 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=6IbuvHDi3IEbxpb97HACbzLYj7M9FxHnZIeq0kBOD9o=; b=QGc7DOnyCv/uc2LmpezlSjCs+1XGOqydO//tcgOJwc6ecPEL3J+l0sTy5mAgnYwUaLtkXZGc4YFCEoTP0d02R08EavlDX5pdIjAprM6AhGhLkSW4U2l4sePjvyzIzztDacBVn5ZQ3gHuCQ+f5GXr5H4CD3t3zNZtqKbqxNZY+G8Iy8O2sUGbYVel4bM5R+r7Nsg/xtxXcHuQE2tKedY54yyAd8m9n7+4YgqJSTD8hQWJrIy1XSxJsWBrzaENLwejzOPzsjLW5J8aSq41Lv5JYNc4BwjcCh38BdzhUAnchDAScHGQJlVttdvBUsIw7O3rS+XSav03hXsLQeofxcol3A==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=NpPTGAvwjMDaPZBGFm+RaIymSB9CuIILbirbHYV+M1+/ysdmBs8TAJmV94VnC8gYq2AVWdixJFBu4yVf6uonwAotbYwv1Pd+s9qOEASpMGsxFq5b9LEOkKgTJ5lAaniu0a8ELL28DQ2cLgKfAvhT0xHLaThKXGNAUXKBw8lFtOhA5pSqHwIhkr4PoioJz3QgCCu6JdplV4mIeBZFLmQiYnN1z9TW2v3p3lYi9KX+DLtkLnZQOazYzRUYGl/zrbgcLxeraz7K6vVS+9WOa1ctBLyKjNEo4b19Y/bRAb+SnzRrHVfyA9/mRf45DCktquxUL5KqA+OUF6S/Yk3WIq4FWQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=A2tX2+qSjmS4HlTBxBGf9kvpRPAousH8D6tkMdm9Hc0HI1MyNRhN/+UcjJF2JlFInCMsGqWM83qEfyTfSMTFqWf6LzTDAwDMk25h+IdmopZUAqef0VCQoIqfckf/i+9xv4nrzJyFTaBYys/sEcBqZXgERme8piuDfK7J6Boc78RmnxDnQMv6Gfp2nuR2sH3Ud7cBDl6NgbXxXGVw+kHQzd/C+Rip0bMSjWCV+TemC/NdtBL2XhNqIhpswaZPMj5teV2KC2TZGoRLIgP1rVFahPYN4xpP3qzy14qHtKEn7n1sOp5vNsnOp3VLWdMlGYtPccY+8n98l90pkcBJMpMhHg==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Thu, 13 Mar 2025 11:52:14 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHbk1YkGSTpa6yk5EqClFNNJd/JMbNwzCYAgAAppYA=
  • Thread-topic: [PATCH 05/10] arm/mpu: Introduce frame_table, virt_to_page, maddr_to_virt

Hi Julien,

> On 13 Mar 2025, at 09:22, Julien Grall <julien@xxxxxxx> wrote:
> 
> Hi,
> 
> On 12/03/2025 13:52, Luca Fancellu wrote:
>> Introduce variables and functions used in the common Arm code by
>> MPU memory management subsystem, provide struct page_info and
>> the MPU implementation for helpers and macros used in the common
>> arm code.
>> Moving virt_to_page helper to mmu/mpu part is not easy as it needs
>> visibility of 'struct page_info', so protect it with CONFIG_MMU
>> and provide the MPU variant in the #else branch.
> 
> Have you considered including "asm/{mmu,mpu}/mm.h" **after** struct page_info 
> is declared?

I didn’t tried that, but if we do that we solve all the issues (I don’t like 
#includes in the middle of headers,
because of that I didn’t try).

This is what it looks like:

diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h
index 9bf5c846c86c..b49ec9c3dd1a 100644
--- a/xen/arch/arm/include/asm/mm.h
+++ b/xen/arch/arm/include/asm/mm.h
@@ -14,14 +14,6 @@
 # error "unknown ARM variant"
 #endif
 
-#if defined(CONFIG_MMU)
-# include <asm/mmu/mm.h>
-#elif defined(CONFIG_MPU)
-# include <asm/mpu/mm.h>
-#else
-#error "Unknown memory management layout"
-#endif
-
 /* Align Xen to a 2 MiB boundary. */
 #define XEN_PADDR_ALIGN (1 << 21)
 
@@ -264,53 +256,13 @@ static inline void __iomem *ioremap_wc(paddr_t start, 
size_t len)
 #define paddr_to_pfn_aligned(paddr)    paddr_to_pfn(PAGE_ALIGN(paddr))
 
 #if defined(CONFIG_MMU)
-
-#ifdef CONFIG_ARM_32
-/**
- * Find the virtual address corresponding to a machine address
- *
- * Only memory backing the XENHEAP has a corresponding virtual address to
- * be found. This is so we can save precious virtual space, as it's in
- * short supply on arm32. This mapping is not subject to PDX compression
- * because XENHEAP is known to be physically contiguous and can't hence
- * jump over the PDX hole. This means we can avoid the roundtrips
- * converting to/from pdx.
- *
- * @param ma Machine address
- * @return Virtual address mapped to `ma`
- */
-static inline void *maddr_to_virt(paddr_t ma)
-{
-    ASSERT(is_xen_heap_mfn(maddr_to_mfn(ma)));
-    ma -= mfn_to_maddr(directmap_mfn_start);
-    return (void *)(unsigned long) ma + XENHEAP_VIRT_START;
-}
+# include <asm/mmu/mm.h>
+#elif defined(CONFIG_MPU)
+# include <asm/mpu/mm.h>
 #else
-/**
- * Find the virtual address corresponding to a machine address
- *
- * The directmap covers all conventional memory accesible by the
- * hypervisor. This means it's subject to PDX compression.
- *
- * Note there's an extra offset applied (directmap_base_pdx) on top of the
- * regular PDX compression logic. Its purpose is to skip over the initial
- * range of non-existing memory, should there be one.
- *
- * @param ma Machine address
- * @return Virtual address mapped to `ma`
- */
-static inline void *maddr_to_virt(paddr_t ma)
-{
-    ASSERT((mfn_to_pdx(maddr_to_mfn(ma)) - directmap_base_pdx) <
-           (DIRECTMAP_SIZE >> PAGE_SHIFT));
-    return (void *)(XENHEAP_VIRT_START -
-                    (directmap_base_pdx << PAGE_SHIFT) +
-                    maddr_to_directmapoff(ma));
-}
+#error "Unknown memory management layout"
 #endif
 
-#endif /* CONFIG_MMU */
-
 /*
  * Translate a guest virtual address to a machine address.
  * Return the fault information if the translation has failed else 0.
diff --git a/xen/arch/arm/include/asm/mmu/mm.h 
b/xen/arch/arm/include/asm/mmu/mm.h
index 5ff2071133ee..9557f632d8e6 100644
--- a/xen/arch/arm/include/asm/mmu/mm.h
+++ b/xen/arch/arm/include/asm/mmu/mm.h
@@ -21,6 +21,50 @@ extern unsigned long directmap_base_pdx;
     (paddr_t)((va_to_par(va_) & PADDR_MASK & PAGE_MASK) | (va_ & ~PAGE_MASK)); 
\
 })
 
+#ifdef CONFIG_ARM_32
+/**
+ * Find the virtual address corresponding to a machine address
+ *
+ * Only memory backing the XENHEAP has a corresponding virtual address to
+ * be found. This is so we can save precious virtual space, as it's in
+ * short supply on arm32. This mapping is not subject to PDX compression
+ * because XENHEAP is known to be physically contiguous and can't hence
+ * jump over the PDX hole. This means we can avoid the roundtrips
+ * converting to/from pdx.
+ *
+ * @param ma Machine address
+ * @return Virtual address mapped to `ma`
+ */
+static inline void *maddr_to_virt(paddr_t ma)
+{
+    ASSERT(is_xen_heap_mfn(maddr_to_mfn(ma)));
+    ma -= mfn_to_maddr(directmap_mfn_start);
+    return (void *)(unsigned long) ma + XENHEAP_VIRT_START;
+}
+#else
+/**
+ * Find the virtual address corresponding to a machine address
+ *
+ * The directmap covers all conventional memory accesible by the
+ * hypervisor. This means it's subject to PDX compression.
+ *
+ * Note there's an extra offset applied (directmap_base_pdx) on top of the
+ * regular PDX compression logic. Its purpose is to skip over the initial
+ * range of non-existing memory, should there be one.
+ *
+ * @param ma Machine address
+ * @return Virtual address mapped to `ma`
+ */
+static inline void *maddr_to_virt(paddr_t ma)
+{
+    ASSERT((mfn_to_pdx(maddr_to_mfn(ma)) - directmap_base_pdx) <
+           (DIRECTMAP_SIZE >> PAGE_SHIFT));
+    return (void *)(XENHEAP_VIRT_START -
+                    (directmap_base_pdx << PAGE_SHIFT) +
+                    maddr_to_directmapoff(ma));
+}
+#endif
+
 /*
  * Print a walk of a page table or p2m
  *



>> Introduce FRAMETABLE_NR that is required for 'pdx_group_valid' in
>> pdx.c.
> 
> 
> Maybe clarify in the commit message that the frametable will be setup at a 
> later stage?

Sure

> 
>> Signed-off-by: Luca Fancellu <luca.fancellu@xxxxxxx>
>> ---
>>  xen/arch/arm/include/asm/mm.h         | 18 ++++++++++++++++++
>>  xen/arch/arm/include/asm/mpu/layout.h |  3 +++
>>  xen/arch/arm/include/asm/mpu/mm.h     |  3 +++
>>  xen/arch/arm/mpu/mm.c                 |  4 ++++
>>  4 files changed, 28 insertions(+)
>> diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h
>> index e7767cdab493..c96d33aceaf0 100644
>> --- a/xen/arch/arm/include/asm/mm.h
>> +++ b/xen/arch/arm/include/asm/mm.h
>> @@ -341,6 +341,8 @@ static inline uint64_t gvirt_to_maddr(vaddr_t va, 
>> paddr_t *pa,
>>  #define virt_to_mfn(va)     __virt_to_mfn(va)
>>  #define mfn_to_virt(mfn)    __mfn_to_virt(mfn)
>>  +#ifdef CONFIG_MMU
>> +
>>  /* Convert between Xen-heap virtual addresses and page-info structures. */
>>  static inline struct page_info *virt_to_page(const void *v)
>>  {
>> @@ -355,6 +357,22 @@ static inline struct page_info *virt_to_page(const void 
>> *v)
>>      return frame_table + pdx - frametable_base_pdx;
>>  }
>>  +#else /* !CONFIG_MMU */
>> +
>> +/* Convert between virtual address to page-info structure. */
>> +static inline struct page_info *virt_to_page(const void *v)
>> +{
>> +    unsigned long pdx;
>> +
>> +    pdx = paddr_to_pdx(virt_to_maddr(v));
>> +    ASSERT(pdx >= frametable_base_pdx);
>> +    ASSERT(pdx < frametable_pdx_end);
>> +
>> +    return frame_table + pdx - frametable_base_pdx;
>> +}
>> +
>> +#endif /* CONFIG_MMU */
>> +
>>  static inline void *page_to_virt(const struct page_info *pg)
>>  {
>>      return mfn_to_virt(mfn_x(page_to_mfn(pg)));
>> diff --git a/xen/arch/arm/include/asm/mpu/layout.h 
>> b/xen/arch/arm/include/asm/mpu/layout.h
>> index 248e55f8882d..c46b634c9c15 100644
>> --- a/xen/arch/arm/include/asm/mpu/layout.h
>> +++ b/xen/arch/arm/include/asm/mpu/layout.h
>> @@ -3,6 +3,9 @@
>>  #ifndef __ARM_MPU_LAYOUT_H__
>>  #define __ARM_MPU_LAYOUT_H__
>>  +#define FRAMETABLE_SIZE   GB(32)
> 
> I guess you copied the value for the MMU code for arm64. But is this value 
> still sensible for MPU? What about arm32?
> 
> In any case, some documentation would be useful.

Yes I took the one from arm64, here I probably need some help as there are not 
too many
informations about how to size this.



 


Rackspace

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