From: Luca Fancellu <luca.fancellu@arm.com>
To: xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
Bertrand Marquis <bertrand.marquis@arm.com>,
Michal Orzel <michal.orzel@amd.com>,
Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: [PATCH v3 3/7] xen/arm: Introduce frame_table and virt_to_page
Date: Mon, 17 Mar 2025 20:07:23 +0000 [thread overview]
Message-ID: <20250317200727.798696-4-luca.fancellu@arm.com> (raw)
In-Reply-To: <20250317200727.798696-1-luca.fancellu@arm.com>
Introduce frame_table in order to provide the implementation of
virt_to_page for MPU system, move the MMU variant in mmu/mm.h.
Introduce FRAMETABLE_NR that is required for 'pdx_group_valid' in
pdx.c, but leave the initialisation of the frame table to a later
stage.
Define FRAMETABLE_SIZE for MPU to support up to 1TB of ram at this
stage, as the only current implementation of armv8-r aarch64, which
is cortex R82, can support 1TB or 256TB (r82 TRM r3p1
ID_AA64MMFR0_EL1.PARange).
Take the occasion to sort alphabetically the headers following
the Xen code style and add the emacs footer in mpu/mm.c.
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
---
v3 changes:
- Simplified MPU virt_to_page conversions (Michal suggested)
- Mentioned r82 TRM source for frame table size (Michal)
- Add Michal R-by
v2 changes:
- sorted headers in mm.c
- modified commit message
- moved virt_to_page to MMU and MPU
- removed frametable_pdx_end, used mfn_valid
---
xen/arch/arm/include/asm/mm.h | 14 --------------
xen/arch/arm/include/asm/mmu/mm.h | 14 ++++++++++++++
xen/arch/arm/include/asm/mpu/layout.h | 3 +++
xen/arch/arm/include/asm/mpu/mm.h | 14 ++++++++++++++
xen/arch/arm/mpu/mm.c | 14 +++++++++++++-
5 files changed, 44 insertions(+), 15 deletions(-)
diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h
index 444fd03823ec..fbffaccef49b 100644
--- a/xen/arch/arm/include/asm/mm.h
+++ b/xen/arch/arm/include/asm/mm.h
@@ -294,20 +294,6 @@ static inline uint64_t gvirt_to_maddr(vaddr_t va, paddr_t *pa,
#error "Unknown memory management layout"
#endif
-/* Convert between Xen-heap virtual addresses and page-info structures. */
-static inline struct page_info *virt_to_page(const void *v)
-{
- unsigned long va = (unsigned long)v;
- unsigned long pdx;
-
- ASSERT(va >= XENHEAP_VIRT_START);
- ASSERT(va < directmap_virt_end);
-
- pdx = (va - XENHEAP_VIRT_START) >> PAGE_SHIFT;
- pdx += mfn_to_pdx(directmap_mfn_start);
- return frame_table + pdx - frametable_base_pdx;
-}
-
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/mmu/mm.h b/xen/arch/arm/include/asm/mmu/mm.h
index 6737c3ede783..caba987edc85 100644
--- a/xen/arch/arm/include/asm/mmu/mm.h
+++ b/xen/arch/arm/include/asm/mmu/mm.h
@@ -70,6 +70,20 @@ static inline void *maddr_to_virt(paddr_t ma)
}
#endif
+/* Convert between Xen-heap virtual addresses and page-info structures. */
+static inline struct page_info *virt_to_page(const void *v)
+{
+ unsigned long va = (unsigned long)v;
+ unsigned long pdx;
+
+ ASSERT(va >= XENHEAP_VIRT_START);
+ ASSERT(va < directmap_virt_end);
+
+ pdx = (va - XENHEAP_VIRT_START) >> PAGE_SHIFT;
+ pdx += mfn_to_pdx(directmap_mfn_start);
+ return frame_table + pdx - frametable_base_pdx;
+}
+
/*
* Print a walk of a page table or p2m
*
diff --git a/xen/arch/arm/include/asm/mpu/layout.h b/xen/arch/arm/include/asm/mpu/layout.h
index 248e55f8882d..c331d1feaa84 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(16)
+#define FRAMETABLE_NR (FRAMETABLE_SIZE / sizeof(*frame_table))
+
#define XEN_START_ADDRESS CONFIG_XEN_START_ADDRESS
/*
diff --git a/xen/arch/arm/include/asm/mpu/mm.h b/xen/arch/arm/include/asm/mpu/mm.h
index 6cfd0f5cd2c2..86f33d9836b7 100644
--- a/xen/arch/arm/include/asm/mpu/mm.h
+++ b/xen/arch/arm/include/asm/mpu/mm.h
@@ -3,9 +3,13 @@
#ifndef __ARM_MPU_MM_H__
#define __ARM_MPU_MM_H__
+#include <xen/bug.h>
#include <xen/macros.h>
#include <xen/page-size.h>
#include <xen/types.h>
+#include <asm/mm.h>
+
+extern struct page_info *frame_table;
#define virt_to_maddr(va) ((paddr_t)((vaddr_t)(va) & PADDR_MASK))
@@ -15,6 +19,16 @@ static inline void *maddr_to_virt(paddr_t ma)
return _p(ma);
}
+/* Convert between virtual address to page-info structure. */
+static inline struct page_info *virt_to_page(const void *v)
+{
+ mfn_t mfn = _mfn(virt_to_mfn(v));
+
+ ASSERT(mfn_valid(mfn));
+
+ return mfn_to_page(mfn);
+}
+
#endif /* __ARM_MPU_MM_H__ */
/*
diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c
index 0b8748e57598..3632011c1013 100644
--- a/xen/arch/arm/mpu/mm.c
+++ b/xen/arch/arm/mpu/mm.c
@@ -1,9 +1,12 @@
/* SPDX-License-Identifier: GPL-2.0-only */
-#include <xen/lib.h>
#include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/mm.h>
#include <xen/sizes.h>
+struct page_info *frame_table;
+
static void __init __maybe_unused build_assertions(void)
{
/*
@@ -13,3 +16,12 @@ static void __init __maybe_unused build_assertions(void)
*/
BUILD_BUG_ON(PAGE_SIZE != SZ_4K);
}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
2.34.1
next prev parent reply other threads:[~2025-03-17 20:07 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-17 20:07 [PATCH v3 0/7] MPU mm subsystem skeleton Luca Fancellu
2025-03-17 20:07 ` [PATCH v3 1/7] arm/mpu: Add HYPERVISOR_VIRT_START and avoid a check in xen.lds.S Luca Fancellu
2025-03-17 20:07 ` [PATCH v3 2/7] xen/arm: Implement virt/maddr conversion in MPU system Luca Fancellu
2025-03-17 20:07 ` Luca Fancellu [this message]
2025-03-17 20:07 ` [PATCH v3 4/7] arm/mpu: Kconfig symbols for MPU build Luca Fancellu
2025-03-17 20:07 ` [PATCH v3 5/7] arm/mpu: Implement stubs for ioremap_attr on MPU Luca Fancellu
2025-03-17 20:07 ` [PATCH v3 6/7] xen: introduce Kconfig ARCH_PAGING_MEMPOOL Luca Fancellu
2025-03-18 9:11 ` Orzel, Michal
2025-03-18 13:05 ` Oleksii Kurochko
2025-03-19 11:35 ` Jan Beulich
2025-03-19 12:18 ` Luca Fancellu
2025-03-19 12:24 ` Luca Fancellu
2025-03-19 12:26 ` Luca Fancellu
2025-03-19 16:31 ` Oleksii Kurochko
2025-03-20 7:32 ` Jan Beulich
2025-03-26 9:39 ` Orzel, Michal
2025-03-26 9:46 ` Oleksii Kurochko
2025-03-26 9:53 ` Orzel, Michal
2025-03-26 9:54 ` Jan Beulich
2025-03-26 9:59 ` Orzel, Michal
2025-03-26 10:04 ` Jan Beulich
2025-03-17 20:07 ` [PATCH v3 7/7] arm/mpu: Create the skeleton for MPU compilation Luca Fancellu
2025-03-18 9:27 ` Orzel, Michal
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=20250317200727.798696-4-luca.fancellu@arm.com \
--to=luca.fancellu@arm.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=bertrand.marquis@arm.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.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.