[PATCH 6/6] arm/mpu: Map domain page in AArch64 MPU systems

Harry Ramsey posted 6 patches 2 months, 1 week ago
There is a newer version of this series
[PATCH 6/6] arm/mpu: Map domain page in AArch64 MPU systems
Posted by Harry Ramsey 2 months, 1 week ago
From: Penny Zheng <Penny.Zheng@arm.com>

In MPU systems, we implement map_domain_page()/unmap_domain_page()
through mapping the domain page with a MPU region on demand.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Signed-off-by: Wei Chen <wei.chen@arm.com>
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Signed-off-by: Harry Ramsey <harry.ramsey@arm.com>
---
 xen/arch/arm/Kconfig           |  1 +
 xen/arch/arm/mpu/Makefile      |  1 +
 xen/arch/arm/mpu/domain-page.c | 53 ++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+)
 create mode 100644 xen/arch/arm/mpu/domain-page.c

diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
index a5c111e08e..dac9a16c28 100644
--- a/xen/arch/arm/Kconfig
+++ b/xen/arch/arm/Kconfig
@@ -91,6 +91,7 @@ config MMU
 
 config MPU
 	bool "MPU" if UNSUPPORTED
+	select ARCH_MAP_DOMAIN_PAGE if ARM_64
 	select ARM_SECURE_STATE if ARM_64
 	select STATIC_MEMORY
 	help
diff --git a/xen/arch/arm/mpu/Makefile b/xen/arch/arm/mpu/Makefile
index 4963c8b550..940297af3f 100644
--- a/xen/arch/arm/mpu/Makefile
+++ b/xen/arch/arm/mpu/Makefile
@@ -1,5 +1,6 @@
 obj-$(CONFIG_ARM_32) += arm32/
 obj-$(CONFIG_ARM_64) += arm64/
+obj-$(CONFIG_ARM_64) += domain-page.o
 obj-y += mm.o
 obj-y += p2m.o
 obj-y += setup.init.o
diff --git a/xen/arch/arm/mpu/domain-page.c b/xen/arch/arm/mpu/domain-page.c
new file mode 100644
index 0000000000..9248053ff5
--- /dev/null
+++ b/xen/arch/arm/mpu/domain-page.c
@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/bug.h>
+#include <xen/domain_page.h>
+#include <xen/mm.h>
+#include <xen/mm-frame.h>
+#include <xen/types.h>
+
+void *map_domain_page_global(mfn_t mfn)
+{
+    BUG_ON("unimplemented");
+    return NULL;
+}
+
+/* Map a page of domheap memory */
+void *map_domain_page(mfn_t mfn)
+{
+    paddr_t pa = mfn_to_maddr(mfn);
+
+    if ( map_pages_to_xen((unsigned long)pa, mfn, 1, PAGE_HYPERVISOR_RW) )
+        return NULL;
+
+    return maddr_to_virt(pa);
+}
+
+/* Release a mapping taken with map_domain_page() */
+void unmap_domain_page(const void *ptr)
+{
+    paddr_t base = virt_to_maddr(ptr);
+
+    if ( destroy_entire_xen_mapping(base) )
+        panic("Failed to unmap domain page\n");
+}
+
+mfn_t domain_page_map_to_mfn(const void *ptr)
+{
+    BUG_ON("unimplemented");
+    return INVALID_MFN;
+}
+
+void unmap_domain_page_global(const void *va)
+{
+    BUG_ON("unimplemented");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
-- 
2.43.0
Re: [PATCH 6/6] arm/mpu: Map domain page in AArch64 MPU systems
Posted by Orzel, Michal 1 month, 3 weeks ago

On 28/11/2025 10:58, Harry Ramsey wrote:
> From: Penny Zheng <Penny.Zheng@arm.com>
> 
> In MPU systems, we implement map_domain_page()/unmap_domain_page()
> through mapping the domain page with a MPU region on demand.
What prevents you from implementing the remaining few helpers?

~Michal

> 
> Signed-off-by: Penny Zheng <penny.zheng@arm.com>
> Signed-off-by: Wei Chen <wei.chen@arm.com>
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
> Signed-off-by: Harry Ramsey <harry.ramsey@arm.com>
> ---
>  xen/arch/arm/Kconfig           |  1 +
>  xen/arch/arm/mpu/Makefile      |  1 +
>  xen/arch/arm/mpu/domain-page.c | 53 ++++++++++++++++++++++++++++++++++
>  3 files changed, 55 insertions(+)
>  create mode 100644 xen/arch/arm/mpu/domain-page.c
> 
> diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
> index a5c111e08e..dac9a16c28 100644
> --- a/xen/arch/arm/Kconfig
> +++ b/xen/arch/arm/Kconfig
> @@ -91,6 +91,7 @@ config MMU
>  
>  config MPU
>  	bool "MPU" if UNSUPPORTED
> +	select ARCH_MAP_DOMAIN_PAGE if ARM_64
>  	select ARM_SECURE_STATE if ARM_64
>  	select STATIC_MEMORY
>  	help
> diff --git a/xen/arch/arm/mpu/Makefile b/xen/arch/arm/mpu/Makefile
> index 4963c8b550..940297af3f 100644
> --- a/xen/arch/arm/mpu/Makefile
> +++ b/xen/arch/arm/mpu/Makefile
> @@ -1,5 +1,6 @@
>  obj-$(CONFIG_ARM_32) += arm32/
>  obj-$(CONFIG_ARM_64) += arm64/
> +obj-$(CONFIG_ARM_64) += domain-page.o
>  obj-y += mm.o
>  obj-y += p2m.o
>  obj-y += setup.init.o
> diff --git a/xen/arch/arm/mpu/domain-page.c b/xen/arch/arm/mpu/domain-page.c
> new file mode 100644
> index 0000000000..9248053ff5
> --- /dev/null
> +++ b/xen/arch/arm/mpu/domain-page.c
> @@ -0,0 +1,53 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#include <xen/bug.h>
> +#include <xen/domain_page.h>
> +#include <xen/mm.h>
> +#include <xen/mm-frame.h>
> +#include <xen/types.h>
> +
> +void *map_domain_page_global(mfn_t mfn)
> +{
> +    BUG_ON("unimplemented");
> +    return NULL;
> +}
> +
> +/* Map a page of domheap memory */
> +void *map_domain_page(mfn_t mfn)
> +{
> +    paddr_t pa = mfn_to_maddr(mfn);
> +
> +    if ( map_pages_to_xen((unsigned long)pa, mfn, 1, PAGE_HYPERVISOR_RW) )
> +        return NULL;
> +
> +    return maddr_to_virt(pa);
> +}
> +
> +/* Release a mapping taken with map_domain_page() */
> +void unmap_domain_page(const void *ptr)
> +{
> +    paddr_t base = virt_to_maddr(ptr);
> +
> +    if ( destroy_entire_xen_mapping(base) )
> +        panic("Failed to unmap domain page\n");
> +}
> +
> +mfn_t domain_page_map_to_mfn(const void *ptr)
> +{
> +    BUG_ON("unimplemented");
> +    return INVALID_MFN;
> +}
> +
> +void unmap_domain_page_global(const void *va)
> +{
> +    BUG_ON("unimplemented");
> +}
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * indent-tabs-mode: nil
> + * End:
> + */
Re: [PATCH 6/6] arm/mpu: Map domain page in AArch64 MPU systems
Posted by Luca Fancellu 1 month, 3 weeks ago
Hi Michael,

> On 16 Dec 2025, at 09:26, Orzel, Michal <Michal.Orzel@amd.com> wrote:
> 
> 
> 
> On 28/11/2025 10:58, Harry Ramsey wrote:
>> From: Penny Zheng <Penny.Zheng@arm.com>
>> 
>> In MPU systems, we implement map_domain_page()/unmap_domain_page()
>> through mapping the domain page with a MPU region on demand.
> What prevents you from implementing the remaining few helpers?

Only the fact that they are not used at this stage, otherwise we would have seen
a panic while running Linux.

Cheers,
Luca
Re: [PATCH 6/6] arm/mpu: Map domain page in AArch64 MPU systems
Posted by Orzel, Michal 1 month, 3 weeks ago

On 16/12/2025 10:29, Luca Fancellu wrote:
> Hi Michael,
> 
>> On 16 Dec 2025, at 09:26, Orzel, Michal <Michal.Orzel@amd.com> wrote:
>>
>>
>>
>> On 28/11/2025 10:58, Harry Ramsey wrote:
>>> From: Penny Zheng <Penny.Zheng@arm.com>
>>>
>>> In MPU systems, we implement map_domain_page()/unmap_domain_page()
>>> through mapping the domain page with a MPU region on demand.
>> What prevents you from implementing the remaining few helpers?
> 
> Only the fact that they are not used at this stage, otherwise we would have seen
> a panic while running Linux.
Sure but it looks like that they would also be a few-liners hence there is a
feeling that they could all be done in one go for completeness sake.

~Michal
Re: [PATCH 6/6] arm/mpu: Map domain page in AArch64 MPU systems
Posted by Luca Fancellu 1 month, 3 weeks ago

> On 16 Dec 2025, at 09:32, Orzel, Michal <Michal.Orzel@amd.com> wrote:
> 
> 
> 
> On 16/12/2025 10:29, Luca Fancellu wrote:
>> Hi Michael,
>> 
>>> On 16 Dec 2025, at 09:26, Orzel, Michal <Michal.Orzel@amd.com> wrote:
>>> 
>>> 
>>> 
>>> On 28/11/2025 10:58, Harry Ramsey wrote:
>>>> From: Penny Zheng <Penny.Zheng@arm.com>
>>>> 
>>>> In MPU systems, we implement map_domain_page()/unmap_domain_page()
>>>> through mapping the domain page with a MPU region on demand.
>>> What prevents you from implementing the remaining few helpers?
>> 
>> Only the fact that they are not used at this stage, otherwise we would have seen
>> a panic while running Linux.
> Sure but it looks like that they would also be a few-liners hence there is a
> feeling that they could all be done in one go for completeness sake.

yeah but we don’t have the confidence it works because we can’t test

Cheers,
Luca