* [PATCH v4 1/3] xen/arm: Move some of the functions to common file
2025-04-03 17:12 [PATCH v4 0/3] Enable early bootup of Armv8-R AArch32 systems Ayan Kumar Halder
@ 2025-04-03 17:12 ` Ayan Kumar Halder
2025-04-04 9:06 ` Luca Fancellu
2025-04-07 9:04 ` Orzel, Michal
2025-04-03 17:12 ` [PATCH v4 2/3] xen/arm32: Create the same boot-time MPU regions as arm64 Ayan Kumar Halder
` (2 subsequent siblings)
3 siblings, 2 replies; 16+ messages in thread
From: Ayan Kumar Halder @ 2025-04-03 17:12 UTC (permalink / raw)
To: xen-devel
Cc: Ayan Kumar Halder, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Michal Orzel, Volodymyr Babchuk
Added a new file prepare_xen_region.inc to hold the common earlyboot MPU regions
configurations across arm64 and arm32.
prepare_xen_region, fail_insufficient_regions() will be used by both arm32 and
arm64. Thus, they have been moved to prepare_xen_region.inc.
enable_secondary_cpu_mm() is a stub which is moved to prepare_xen_region.inc as
SMP is currently not supported for MPU.
*_PRBAR are moved to arm64/sysregs.h.
*_PRLAR are moved to prepare_xen_region.inc as they are common between arm32
and arm64.
Introduce WRITE_SYSREG_ASM to write to the system registers from the common asm
file.
Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
---
Changes from
v1 -
1. enable_mpu() now sets HMAIR{0,1} registers. This is similar to what is
being done in enable_mmu(). All the mm related configurations happen in this
function.
2. Fixed some typos.
v2 -
1. Extracted the arm64 head.S functions/macros in a common file.
v3 -
1. Moved *_PRLAR are moved to prepare_xen_region.inc
2. enable_boot_cpu_mm() is preserved in mpu/head.S.
3. STORE_SYSREG is renamed as WRITE_SYSREG_ASM()
4. LOAD_SYSREG is removed.
5. No need to save/restore lr in enable_boot_cpu_mm(). IOW, keep it as it was
in the original code.
xen/arch/arm/arm64/mpu/head.S | 88 +-----------------
xen/arch/arm/include/asm/arm64/sysregs.h | 11 +++
.../include/asm/mpu/prepare_xen_region.inc | 89 +++++++++++++++++++
3 files changed, 101 insertions(+), 87 deletions(-)
create mode 100644 xen/arch/arm/include/asm/mpu/prepare_xen_region.inc
diff --git a/xen/arch/arm/arm64/mpu/head.S b/xen/arch/arm/arm64/mpu/head.S
index ed01993d85..8cd8107a13 100644
--- a/xen/arch/arm/arm64/mpu/head.S
+++ b/xen/arch/arm/arm64/mpu/head.S
@@ -3,83 +3,7 @@
* Start-of-day code for an Armv8-R MPU system.
*/
-#include <asm/early_printk.h>
-#include <asm/mpu.h>
-
-/* Backgroud region enable/disable */
-#define SCTLR_ELx_BR BIT(17, UL)
-
-#define REGION_TEXT_PRBAR 0x38 /* SH=11 AP=10 XN=00 */
-#define REGION_RO_PRBAR 0x3A /* SH=11 AP=10 XN=10 */
-#define REGION_DATA_PRBAR 0x32 /* SH=11 AP=00 XN=10 */
-#define REGION_DEVICE_PRBAR 0x22 /* SH=10 AP=00 XN=10 */
-
-#define REGION_NORMAL_PRLAR 0x0f /* NS=0 ATTR=111 EN=1 */
-#define REGION_DEVICE_PRLAR 0x09 /* NS=0 ATTR=100 EN=1 */
-
-/*
- * Macro to prepare and set a EL2 MPU memory region.
- * We will also create an according MPU memory region entry, which
- * is a structure of pr_t, in table \prmap.
- *
- * sel: region selector
- * base: reg storing base address
- * limit: reg storing limit address
- * prbar: store computed PRBAR_EL2 value
- * prlar: store computed PRLAR_EL2 value
- * maxcount: maximum number of EL2 regions supported
- * attr_prbar: PRBAR_EL2-related memory attributes. If not specified it will be
- * REGION_DATA_PRBAR
- * attr_prlar: PRLAR_EL2-related memory attributes. If not specified it will be
- * REGION_NORMAL_PRLAR
- *
- * Preserves \maxcount
- * Output:
- * \sel: Next available region selector index.
- * Clobbers \base, \limit, \prbar, \prlar
- *
- * Note that all parameters using registers should be distinct.
- */
-.macro prepare_xen_region, sel, base, limit, prbar, prlar, maxcount, attr_prbar=REGION_DATA_PRBAR, attr_prlar=REGION_NORMAL_PRLAR
- /* Check if the region is empty */
- cmp \base, \limit
- beq 1f
-
- /* Check if the number of regions exceeded the count specified in MPUIR_EL2 */
- cmp \sel, \maxcount
- bge fail_insufficient_regions
-
- /* Prepare value for PRBAR_EL2 reg and preserve it in \prbar.*/
- and \base, \base, #MPU_REGION_MASK
- mov \prbar, #\attr_prbar
- orr \prbar, \prbar, \base
-
- /* Limit address should be inclusive */
- sub \limit, \limit, #1
- and \limit, \limit, #MPU_REGION_MASK
- mov \prlar, #\attr_prlar
- orr \prlar, \prlar, \limit
-
- msr PRSELR_EL2, \sel
- isb
- msr PRBAR_EL2, \prbar
- msr PRLAR_EL2, \prlar
- dsb sy
- isb
-
- add \sel, \sel, #1
-
-1:
-.endm
-
-/*
- * Failure caused due to insufficient MPU regions.
- */
-FUNC_LOCAL(fail_insufficient_regions)
- PRINT("- Selected MPU region is above the implemented number in MPUIR_EL2 -\r\n")
-1: wfe
- b 1b
-END(fail_insufficient_regions)
+#include <asm/mpu/prepare_xen_region.inc>
/*
* Enable EL2 MPU and data cache
@@ -154,16 +78,6 @@ FUNC(enable_boot_cpu_mm)
ret
END(enable_boot_cpu_mm)
-/*
- * We don't yet support secondary CPUs bring-up. Implement a dummy helper to
- * please the common code.
- */
-FUNC(enable_secondary_cpu_mm)
- PRINT("- SMP not enabled yet -\r\n")
-1: wfe
- b 1b
-END(enable_secondary_cpu_mm)
-
/*
* Local variables:
* mode: ASM
diff --git a/xen/arch/arm/include/asm/arm64/sysregs.h b/xen/arch/arm/include/asm/arm64/sysregs.h
index b593e4028b..3ee3715430 100644
--- a/xen/arch/arm/include/asm/arm64/sysregs.h
+++ b/xen/arch/arm/include/asm/arm64/sysregs.h
@@ -462,6 +462,15 @@
#define ZCR_ELx_LEN_SIZE 9
#define ZCR_ELx_LEN_MASK 0x1ff
+#define REGION_TEXT_PRBAR 0x38 /* SH=11 AP=10 XN=00 */
+#define REGION_RO_PRBAR 0x3A /* SH=11 AP=10 XN=10 */
+#define REGION_DATA_PRBAR 0x32 /* SH=11 AP=00 XN=10 */
+#define REGION_DEVICE_PRBAR 0x22 /* SH=10 AP=00 XN=10 */
+
+#define WRITE_SYSREG_ASM(v, name) "msr " __stringify(name,) #v;
+
+#ifndef __ASSEMBLY__
+
/* Access to system registers */
#define WRITE_SYSREG64(v, name) do { \
@@ -481,6 +490,8 @@
#define WRITE_SYSREG_LR(v, index) WRITE_SYSREG(v, ICH_LR_REG(index))
#define READ_SYSREG_LR(index) READ_SYSREG(ICH_LR_REG(index))
+#endif /* __ASSEMBLY__ */
+
#endif /* _ASM_ARM_ARM64_SYSREGS_H */
/*
diff --git a/xen/arch/arm/include/asm/mpu/prepare_xen_region.inc b/xen/arch/arm/include/asm/mpu/prepare_xen_region.inc
new file mode 100644
index 0000000000..8af44d5669
--- /dev/null
+++ b/xen/arch/arm/include/asm/mpu/prepare_xen_region.inc
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <asm/mpu.h>
+#include <asm/sysregs.h>
+
+/* Backgroud region enable/disable */
+#define SCTLR_ELx_BR BIT(17, UL)
+
+#define REGION_NORMAL_PRLAR 0x0f /* NS=0 ATTR=111 EN=1 */
+#define REGION_DEVICE_PRLAR 0x09 /* NS=0 ATTR=100 EN=1 */
+
+/*
+ * Macro to prepare and set a EL2 MPU memory region.
+ * We will also create an according MPU memory region entry, which
+ * is a structure of pr_t, in table \prmap.
+ *
+ * sel: region selector
+ * base: reg storing base address
+ * limit: reg storing limit address
+ * prbar: store computed PRBAR_EL2 value
+ * prlar: store computed PRLAR_EL2 value
+ * maxcount: maximum number of EL2 regions supported
+ * attr_prbar: PRBAR_EL2-related memory attributes. If not specified it will be
+ * REGION_DATA_PRBAR
+ * attr_prlar: PRLAR_EL2-related memory attributes. If not specified it will be
+ * REGION_NORMAL_PRLAR
+ *
+ * Preserves maxcount
+ * Output:
+ * sel: Next available region selector index.
+ * Clobbers base, limit, prbar, prlar
+ *
+ * Note that all parameters using registers should be distinct.
+ */
+.macro prepare_xen_region, sel, base, limit, prbar, prlar, maxcount, attr_prbar=REGION_DATA_PRBAR, attr_prlar=REGION_NORMAL_PRLAR
+ /* Check if the region is empty */
+ cmp \base, \limit
+ beq 1f
+
+ /* Check if the number of regions exceeded the count specified in MPUIR_EL2 */
+ cmp \sel, \maxcount
+ bge fail_insufficient_regions
+
+ /* Prepare value for PRBAR_EL2 reg and preserve it in \prbar.*/
+ and \base, \base, #MPU_REGION_MASK
+ mov \prbar, #\attr_prbar
+ orr \prbar, \prbar, \base
+
+ /* Limit address should be inclusive */
+ sub \limit, \limit, #1
+ and \limit, \limit, #MPU_REGION_MASK
+ mov \prlar, #\attr_prlar
+ orr \prlar, \prlar, \limit
+
+ WRITE_SYSREG_ASM(\sel, PRSELR_EL2)
+ isb
+ WRITE_SYSREG_ASM(\prbar, PRBAR_EL2)
+ WRITE_SYSREG_ASM(\prlar, PRLAR_EL2)
+ dsb sy
+ isb
+
+ add \sel, \sel, #1
+
+1:
+.endm
+
+/* Failure caused due to insufficient MPU regions. */
+FUNC_LOCAL(fail_insufficient_regions)
+ PRINT("- Selected MPU region is above the implemented number in MPUIR_EL2 -\r\n")
+1: wfe
+ b 1b
+END(fail_insufficient_regions)
+
+/*
+ * We don't yet support secondary CPUs bring-up. Implement a dummy helper to
+ * please the common code.
+ */
+FUNC(enable_secondary_cpu_mm)
+ PRINT("- SMP not enabled yet -\r\n")
+1: wfe
+ b 1b
+END(enable_secondary_cpu_mm)
+
+/*
+ * Local variables:
+ * mode: ASM
+ * indent-tabs-mode: nil
+ * End:
+ */
--
2.25.1
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH v4 1/3] xen/arm: Move some of the functions to common file
2025-04-03 17:12 ` [PATCH v4 1/3] xen/arm: Move some of the functions to common file Ayan Kumar Halder
@ 2025-04-04 9:06 ` Luca Fancellu
2025-04-07 14:29 ` Ayan Kumar Halder
2025-04-07 9:04 ` Orzel, Michal
1 sibling, 1 reply; 16+ messages in thread
From: Luca Fancellu @ 2025-04-04 9:06 UTC (permalink / raw)
To: Ayan Kumar Halder
Cc: xen-devel@lists.xenproject.org, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Michal Orzel, Volodymyr Babchuk
Hi Ayan,
> On 3 Apr 2025, at 18:12, Ayan Kumar Halder <ayan.kumar.halder@amd.com> wrote:
>
> Added a new file prepare_xen_region.inc to hold the common earlyboot MPU regions
> configurations across arm64 and arm32.
>
> prepare_xen_region, fail_insufficient_regions() will be used by both arm32 and
> arm64. Thus, they have been moved to prepare_xen_region.inc.
>
> enable_secondary_cpu_mm() is a stub which is moved to prepare_xen_region.inc as
> SMP is currently not supported for MPU.
>
> *_PRBAR are moved to arm64/sysregs.h.
> *_PRLAR are moved to prepare_xen_region.inc as they are common between arm32
> and arm64.
>
> Introduce WRITE_SYSREG_ASM to write to the system registers from the common asm
> file.
>
> Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
> ---
The split for the common code seems ok to me, but this patch is introducing an issue for the arm64 compilation,
I’ve done an experiment and with these changes I’m able to compile both, but feel free to ignore if it’s no what you
had in mind.
diff --git a/xen/arch/arm/include/asm/arm32/sysregs.h b/xen/arch/arm/include/asm/arm32/sysregs.h
index 22871999afb3..a90d1610a155 100644
--- a/xen/arch/arm/include/asm/arm32/sysregs.h
+++ b/xen/arch/arm/include/asm/arm32/sysregs.h
@@ -20,6 +20,13 @@
* uses r0 as a placeholder register. */
#define CMD_CP32(name...) "mcr " __stringify(CP32(r0, name)) ";"
+#define REGION_TEXT_PRBAR 0x18 /* SH=11 AP=10 XN=0 */
+#define REGION_RO_PRBAR 0x1D /* SH=11 AP=10 XN=1 */
+#define REGION_DATA_PRBAR 0x19 /* SH=11 AP=00 XN=1 */
+#define REGION_DEVICE_PRBAR 0x11 /* SH=10 AP=00 XN=1 */
+
+#define WRITE_SYSREG_ASM(v, name) mcr CP32(v, name)
+
#ifndef __ASSEMBLY__
/* C wrappers */
diff --git a/xen/arch/arm/include/asm/cpregs.h b/xen/arch/arm/include/asm/cpregs.h
index 6019a2cbdd89..b909adc102a5 100644
--- a/xen/arch/arm/include/asm/cpregs.h
+++ b/xen/arch/arm/include/asm/cpregs.h
@@ -1,10 +1,6 @@
#ifndef __ASM_ARM_CPREGS_H
#define __ASM_ARM_CPREGS_H
-#ifdef CONFIG_MPU
-#include <asm/mpu/cpregs.h>
-#endif
-
/*
* AArch32 Co-processor registers.
*
@@ -502,6 +498,12 @@
#define MVFR0_EL1 MVFR0
#define MVFR1_EL1 MVFR1
#define MVFR2_EL1 MVFR2
+#define HMPUIR p15,4,c0,c0,4
+#define HPRSELR p15,4,c6,c2,1
+#define PRBAR_EL2 p15,4,c6,c3,0
+#define PRLAR_EL2 p15,4,c6,c8,1
+#define MPUIR_EL2 HMPUIR
+#define PRSELR_EL2 HPRSELR
#endif
#endif
diff --git a/xen/arch/arm/include/asm/mpu/cpregs.h b/xen/arch/arm/include/asm/mpu/cpregs.h
deleted file mode 100644
index 66871379a53b..000000000000
--- a/xen/arch/arm/include/asm/mpu/cpregs.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-
-#ifndef __ASM_ARM_MPU_CPREGS_H
-#define __ASM_ARM_MPU_CPREGS_H
-
-#define REGION_TEXT_PRBAR 0x18 /* SH=11 AP=10 XN=0 */
-#define REGION_RO_PRBAR 0x1D /* SH=11 AP=10 XN=1 */
-#define REGION_DATA_PRBAR 0x19 /* SH=11 AP=00 XN=1 */
-#define REGION_DEVICE_PRBAR 0x11 /* SH=10 AP=00 XN=1 */
-
-#define HMPUIR p15,4,c0,c0,4
-
-/* CP15 CR6: MPU Protection Region Base/Limit/Select Address Register */
-#define HPRSELR p15,4,c6,c2,1
-#define PRBAR_EL2 p15,4,c6,c3,0
-#define PRLAR_EL2 p15,4,c6,c8,1
-
-#define MPUIR_EL2 HMPUIR
-#define PRSELR_EL2 HPRSELR
-
-#define WRITE_SYSREG_ASM(v, name) mcr CP32(v, name)
-
-#endif /* __ASM_ARM_MPU_CPREGS_H */
-
-/*
- * Local variables:
- * mode: ASM
- * indent-tabs-mode: nil
- * End:
- */
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH v4 1/3] xen/arm: Move some of the functions to common file
2025-04-04 9:06 ` Luca Fancellu
@ 2025-04-07 14:29 ` Ayan Kumar Halder
2025-04-07 14:34 ` Luca Fancellu
0 siblings, 1 reply; 16+ messages in thread
From: Ayan Kumar Halder @ 2025-04-07 14:29 UTC (permalink / raw)
To: Luca Fancellu, Ayan Kumar Halder
Cc: xen-devel@lists.xenproject.org, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Michal Orzel, Volodymyr Babchuk
Hi Luca,
On 04/04/2025 10:06, Luca Fancellu wrote:
> Hi Ayan,
>
>> On 3 Apr 2025, at 18:12, Ayan Kumar Halder <ayan.kumar.halder@amd.com> wrote:
>>
>> Added a new file prepare_xen_region.inc to hold the common earlyboot MPU regions
>> configurations across arm64 and arm32.
>>
>> prepare_xen_region, fail_insufficient_regions() will be used by both arm32 and
>> arm64. Thus, they have been moved to prepare_xen_region.inc.
>>
>> enable_secondary_cpu_mm() is a stub which is moved to prepare_xen_region.inc as
>> SMP is currently not supported for MPU.
>>
>> *_PRBAR are moved to arm64/sysregs.h.
>> *_PRLAR are moved to prepare_xen_region.inc as they are common between arm32
>> and arm64.
>>
>> Introduce WRITE_SYSREG_ASM to write to the system registers from the common asm
>> file.
>>
>> Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
>> ---
> The split for the common code seems ok to me, but this patch is introducing an issue for the arm64 compilation,
Sorry, I moved something at the last moment without testing. :(
> I’ve done an experiment and with these changes I’m able to compile both, but feel free to ignore if it’s no what you
> had in mind.
The change looks good. However, ...
>
> diff --git a/xen/arch/arm/include/asm/arm32/sysregs.h b/xen/arch/arm/include/asm/arm32/sysregs.h
> index 22871999afb3..a90d1610a155 100644
> --- a/xen/arch/arm/include/asm/arm32/sysregs.h
> +++ b/xen/arch/arm/include/asm/arm32/sysregs.h
> @@ -20,6 +20,13 @@
> * uses r0 as a placeholder register. */
> #define CMD_CP32(name...) "mcr " __stringify(CP32(r0, name)) ";"
>
> +#define REGION_TEXT_PRBAR 0x18 /* SH=11 AP=10 XN=0 */
> +#define REGION_RO_PRBAR 0x1D /* SH=11 AP=10 XN=1 */
> +#define REGION_DATA_PRBAR 0x19 /* SH=11 AP=00 XN=1 */
> +#define REGION_DEVICE_PRBAR 0x11 /* SH=10 AP=00 XN=1 */
> +
> +#define WRITE_SYSREG_ASM(v, name) mcr CP32(v, name)
> +
> #ifndef __ASSEMBLY__
>
> /* C wrappers */
> diff --git a/xen/arch/arm/include/asm/cpregs.h b/xen/arch/arm/include/asm/cpregs.h
> index 6019a2cbdd89..b909adc102a5 100644
> --- a/xen/arch/arm/include/asm/cpregs.h
> +++ b/xen/arch/arm/include/asm/cpregs.h
> @@ -1,10 +1,6 @@
> #ifndef __ASM_ARM_CPREGS_H
> #define __ASM_ARM_CPREGS_H
>
> -#ifdef CONFIG_MPU
> -#include <asm/mpu/cpregs.h>
> -#endif
> -
> /*
> * AArch32 Co-processor registers.
> *
> @@ -502,6 +498,12 @@
> #define MVFR0_EL1 MVFR0
> #define MVFR1_EL1 MVFR1
> #define MVFR2_EL1 MVFR2
> +#define HMPUIR p15,4,c0,c0,4
> +#define HPRSELR p15,4,c6,c2,1
> +#define PRBAR_EL2 p15,4,c6,c3,0
> +#define PRLAR_EL2 p15,4,c6,c8,1
> +#define MPUIR_EL2 HMPUIR
> +#define PRSELR_EL2 HPRSELR
Considering that there will be lots of arm32 MPU specific registers, do
you want to move them to mpu/cpregs.h ?
That would be my style preference.
This issue does not occur with arm64 as compiler provides most of them.
Michal or Julien - thoughts ?
Rest look ok.
- Ayan
> #endif
>
> #endif
> diff --git a/xen/arch/arm/include/asm/mpu/cpregs.h b/xen/arch/arm/include/asm/mpu/cpregs.h
> deleted file mode 100644
> index 66871379a53b..000000000000
> --- a/xen/arch/arm/include/asm/mpu/cpregs.h
> +++ /dev/null
> @@ -1,30 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0-only */
> -
> -#ifndef __ASM_ARM_MPU_CPREGS_H
> -#define __ASM_ARM_MPU_CPREGS_H
> -
> -#define REGION_TEXT_PRBAR 0x18 /* SH=11 AP=10 XN=0 */
> -#define REGION_RO_PRBAR 0x1D /* SH=11 AP=10 XN=1 */
> -#define REGION_DATA_PRBAR 0x19 /* SH=11 AP=00 XN=1 */
> -#define REGION_DEVICE_PRBAR 0x11 /* SH=10 AP=00 XN=1 */
> -
> -#define HMPUIR p15,4,c0,c0,4
> -
> -/* CP15 CR6: MPU Protection Region Base/Limit/Select Address Register */
> -#define HPRSELR p15,4,c6,c2,1
> -#define PRBAR_EL2 p15,4,c6,c3,0
> -#define PRLAR_EL2 p15,4,c6,c8,1
> -
> -#define MPUIR_EL2 HMPUIR
> -#define PRSELR_EL2 HPRSELR
> -
> -#define WRITE_SYSREG_ASM(v, name) mcr CP32(v, name)
> -
> -#endif /* __ASM_ARM_MPU_CPREGS_H */
> -
> -/*
> - * Local variables:
> - * mode: ASM
> - * indent-tabs-mode: nil
> - * End:
> - */
>
>
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v4 1/3] xen/arm: Move some of the functions to common file
2025-04-07 14:29 ` Ayan Kumar Halder
@ 2025-04-07 14:34 ` Luca Fancellu
2025-04-07 14:57 ` Orzel, Michal
0 siblings, 1 reply; 16+ messages in thread
From: Luca Fancellu @ 2025-04-07 14:34 UTC (permalink / raw)
To: Ayan Kumar Halder
Cc: Ayan Kumar Halder, xen-devel@lists.xenproject.org,
Stefano Stabellini, Julien Grall, Bertrand Marquis, Michal Orzel,
Volodymyr Babchuk
Hi Ayan,
> On 7 Apr 2025, at 15:29, Ayan Kumar Halder <ayankuma@amd.com> wrote:
>
> Hi Luca,
>
> On 04/04/2025 10:06, Luca Fancellu wrote:
>> Hi Ayan,
>>
>>> On 3 Apr 2025, at 18:12, Ayan Kumar Halder <ayan.kumar.halder@amd.com> wrote:
>>>
>>> Added a new file prepare_xen_region.inc to hold the common earlyboot MPU regions
>>> configurations across arm64 and arm32.
>>>
>>> prepare_xen_region, fail_insufficient_regions() will be used by both arm32 and
>>> arm64. Thus, they have been moved to prepare_xen_region.inc.
>>>
>>> enable_secondary_cpu_mm() is a stub which is moved to prepare_xen_region.inc as
>>> SMP is currently not supported for MPU.
>>>
>>> *_PRBAR are moved to arm64/sysregs.h.
>>> *_PRLAR are moved to prepare_xen_region.inc as they are common between arm32
>>> and arm64.
>>>
>>> Introduce WRITE_SYSREG_ASM to write to the system registers from the common asm
>>> file.
>>>
>>> Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
>>> ---
>> The split for the common code seems ok to me, but this patch is introducing an issue for the arm64 compilation,
> Sorry, I moved something at the last moment without testing. :(
>> I’ve done an experiment and with these changes I’m able to compile both, but feel free to ignore if it’s no what you
>> had in mind.
> The change looks good. However, ...
>>
>> diff --git a/xen/arch/arm/include/asm/arm32/sysregs.h b/xen/arch/arm/include/asm/arm32/sysregs.h
>> index 22871999afb3..a90d1610a155 100644
>> --- a/xen/arch/arm/include/asm/arm32/sysregs.h
>> +++ b/xen/arch/arm/include/asm/arm32/sysregs.h
>> @@ -20,6 +20,13 @@
>> * uses r0 as a placeholder register. */
>> #define CMD_CP32(name...) "mcr " __stringify(CP32(r0, name)) ";"
>> +#define REGION_TEXT_PRBAR 0x18 /* SH=11 AP=10 XN=0 */
>> +#define REGION_RO_PRBAR 0x1D /* SH=11 AP=10 XN=1 */
>> +#define REGION_DATA_PRBAR 0x19 /* SH=11 AP=00 XN=1 */
>> +#define REGION_DEVICE_PRBAR 0x11 /* SH=10 AP=00 XN=1 */
>> +
>> +#define WRITE_SYSREG_ASM(v, name) mcr CP32(v, name)
>> +
>> #ifndef __ASSEMBLY__
>> /* C wrappers */
>> diff --git a/xen/arch/arm/include/asm/cpregs.h b/xen/arch/arm/include/asm/cpregs.h
>> index 6019a2cbdd89..b909adc102a5 100644
>> --- a/xen/arch/arm/include/asm/cpregs.h
>> +++ b/xen/arch/arm/include/asm/cpregs.h
>> @@ -1,10 +1,6 @@
>> #ifndef __ASM_ARM_CPREGS_H
>> #define __ASM_ARM_CPREGS_H
>> -#ifdef CONFIG_MPU
>> -#include <asm/mpu/cpregs.h>
>> -#endif
>> -
>> /*
>> * AArch32 Co-processor registers.
>> *
>> @@ -502,6 +498,12 @@
>> #define MVFR0_EL1 MVFR0
>> #define MVFR1_EL1 MVFR1
>> #define MVFR2_EL1 MVFR2
>> +#define HMPUIR p15,4,c0,c0,4
>> +#define HPRSELR p15,4,c6,c2,1
>> +#define PRBAR_EL2 p15,4,c6,c3,0
>> +#define PRLAR_EL2 p15,4,c6,c8,1
>> +#define MPUIR_EL2 HMPUIR
>> +#define PRSELR_EL2 HPRSELR
>
> Considering that there will be lots of arm32 MPU specific registers, do you want to move them to mpu/cpregs.h ?
>
> That would be my style preference.
I don’t have any strong opinion so it’s fine if you want them in cpregs.h.
Cheers,
Luca
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v4 1/3] xen/arm: Move some of the functions to common file
2025-04-07 14:34 ` Luca Fancellu
@ 2025-04-07 14:57 ` Orzel, Michal
0 siblings, 0 replies; 16+ messages in thread
From: Orzel, Michal @ 2025-04-07 14:57 UTC (permalink / raw)
To: Luca Fancellu, Ayan Kumar Halder
Cc: Ayan Kumar Halder, xen-devel@lists.xenproject.org,
Stefano Stabellini, Julien Grall, Bertrand Marquis,
Volodymyr Babchuk
On 07/04/2025 16:34, Luca Fancellu wrote:
>
>
> Hi Ayan,
>
>
>> On 7 Apr 2025, at 15:29, Ayan Kumar Halder <ayankuma@amd.com> wrote:
>>
>> Hi Luca,
>>
>> On 04/04/2025 10:06, Luca Fancellu wrote:
>>> Hi Ayan,
>>>
>>>> On 3 Apr 2025, at 18:12, Ayan Kumar Halder <ayan.kumar.halder@amd.com> wrote:
>>>>
>>>> Added a new file prepare_xen_region.inc to hold the common earlyboot MPU regions
>>>> configurations across arm64 and arm32.
>>>>
>>>> prepare_xen_region, fail_insufficient_regions() will be used by both arm32 and
>>>> arm64. Thus, they have been moved to prepare_xen_region.inc.
>>>>
>>>> enable_secondary_cpu_mm() is a stub which is moved to prepare_xen_region.inc as
>>>> SMP is currently not supported for MPU.
>>>>
>>>> *_PRBAR are moved to arm64/sysregs.h.
>>>> *_PRLAR are moved to prepare_xen_region.inc as they are common between arm32
>>>> and arm64.
>>>>
>>>> Introduce WRITE_SYSREG_ASM to write to the system registers from the common asm
>>>> file.
>>>>
>>>> Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
>>>> ---
>>> The split for the common code seems ok to me, but this patch is introducing an issue for the arm64 compilation,
>> Sorry, I moved something at the last moment without testing. :(
>>> I’ve done an experiment and with these changes I’m able to compile both, but feel free to ignore if it’s no what you
>>> had in mind.
>> The change looks good. However, ...
>>>
>>> diff --git a/xen/arch/arm/include/asm/arm32/sysregs.h b/xen/arch/arm/include/asm/arm32/sysregs.h
>>> index 22871999afb3..a90d1610a155 100644
>>> --- a/xen/arch/arm/include/asm/arm32/sysregs.h
>>> +++ b/xen/arch/arm/include/asm/arm32/sysregs.h
>>> @@ -20,6 +20,13 @@
>>> * uses r0 as a placeholder register. */
>>> #define CMD_CP32(name...) "mcr " __stringify(CP32(r0, name)) ";"
>>> +#define REGION_TEXT_PRBAR 0x18 /* SH=11 AP=10 XN=0 */
>>> +#define REGION_RO_PRBAR 0x1D /* SH=11 AP=10 XN=1 */
>>> +#define REGION_DATA_PRBAR 0x19 /* SH=11 AP=00 XN=1 */
>>> +#define REGION_DEVICE_PRBAR 0x11 /* SH=10 AP=00 XN=1 */
>>> +
>>> +#define WRITE_SYSREG_ASM(v, name) mcr CP32(v, name)
>>> +
>>> #ifndef __ASSEMBLY__
>>> /* C wrappers */
>>> diff --git a/xen/arch/arm/include/asm/cpregs.h b/xen/arch/arm/include/asm/cpregs.h
>>> index 6019a2cbdd89..b909adc102a5 100644
>>> --- a/xen/arch/arm/include/asm/cpregs.h
>>> +++ b/xen/arch/arm/include/asm/cpregs.h
>>> @@ -1,10 +1,6 @@
>>> #ifndef __ASM_ARM_CPREGS_H
>>> #define __ASM_ARM_CPREGS_H
>>> -#ifdef CONFIG_MPU
>>> -#include <asm/mpu/cpregs.h>
>>> -#endif
>>> -
>>> /*
>>> * AArch32 Co-processor registers.
>>> *
>>> @@ -502,6 +498,12 @@
>>> #define MVFR0_EL1 MVFR0
>>> #define MVFR1_EL1 MVFR1
>>> #define MVFR2_EL1 MVFR2
>>> +#define HMPUIR p15,4,c0,c0,4
>>> +#define HPRSELR p15,4,c6,c2,1
>>> +#define PRBAR_EL2 p15,4,c6,c3,0
>>> +#define PRLAR_EL2 p15,4,c6,c8,1
>>> +#define MPUIR_EL2 HMPUIR
>>> +#define PRSELR_EL2 HPRSELR
>>
>> Considering that there will be lots of arm32 MPU specific registers, do you want to move them to mpu/cpregs.h ?
>>
>> That would be my style preference.
>
> I don’t have any strong opinion so it’s fine if you want them in cpregs.h.
If there are really a lot of new additions and the movement improves
readability, I'm ok with them being stored in mpu/cpregs.h
~Michal
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v4 1/3] xen/arm: Move some of the functions to common file
2025-04-03 17:12 ` [PATCH v4 1/3] xen/arm: Move some of the functions to common file Ayan Kumar Halder
2025-04-04 9:06 ` Luca Fancellu
@ 2025-04-07 9:04 ` Orzel, Michal
2025-04-07 13:18 ` Ayan Kumar Halder
1 sibling, 1 reply; 16+ messages in thread
From: Orzel, Michal @ 2025-04-07 9:04 UTC (permalink / raw)
To: Ayan Kumar Halder, xen-devel
Cc: Stefano Stabellini, Julien Grall, Bertrand Marquis,
Volodymyr Babchuk
On 03/04/2025 19:12, Ayan Kumar Halder wrote:
> Added a new file prepare_xen_region.inc to hold the common earlyboot MPU regions
> configurations across arm64 and arm32.
>
> prepare_xen_region, fail_insufficient_regions() will be used by both arm32 and
> arm64. Thus, they have been moved to prepare_xen_region.inc.
>
> enable_secondary_cpu_mm() is a stub which is moved to prepare_xen_region.inc as
> SMP is currently not supported for MPU.
This does not sound right. If you want a place to keep some common MPU stuff
between Arm64 and Arm32, you need to come up with better name for a file. SMP
has nothing to do here with preparing regions so it feels odd to have
enable_secondary_cpu_mm stub there.
Also, new files should use dashes '-' and not underscores '_'.
~Michal
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v4 1/3] xen/arm: Move some of the functions to common file
2025-04-07 9:04 ` Orzel, Michal
@ 2025-04-07 13:18 ` Ayan Kumar Halder
2025-04-07 13:31 ` Luca Fancellu
0 siblings, 1 reply; 16+ messages in thread
From: Ayan Kumar Halder @ 2025-04-07 13:18 UTC (permalink / raw)
To: Orzel, Michal, Ayan Kumar Halder, xen-devel
Cc: Stefano Stabellini, Julien Grall, Bertrand Marquis,
Volodymyr Babchuk
Hi Michal,
On 07/04/2025 10:04, Orzel, Michal wrote:
>
> On 03/04/2025 19:12, Ayan Kumar Halder wrote:
>> Added a new file prepare_xen_region.inc to hold the common earlyboot MPU regions
>> configurations across arm64 and arm32.
>>
>> prepare_xen_region, fail_insufficient_regions() will be used by both arm32 and
>> arm64. Thus, they have been moved to prepare_xen_region.inc.
>>
>> enable_secondary_cpu_mm() is a stub which is moved to prepare_xen_region.inc as
>> SMP is currently not supported for MPU.
> This does not sound right. If you want a place to keep some common MPU stuff
> between Arm64 and Arm32, you need to come up with better name for a file. SMP
> has nothing to do here with preparing regions so it feels odd to have
> enable_secondary_cpu_mm stub there.
Can I rename prepare-xen-region.inc to mpu.inc ?
Julien/Luca - any thoughts ?
>
> Also, new files should use dashes '-' and not underscores '_'.
Ack
- Ayan
>
> ~Michal
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v4 1/3] xen/arm: Move some of the functions to common file
2025-04-07 13:18 ` Ayan Kumar Halder
@ 2025-04-07 13:31 ` Luca Fancellu
2025-04-07 14:07 ` Ayan Kumar Halder
0 siblings, 1 reply; 16+ messages in thread
From: Luca Fancellu @ 2025-04-07 13:31 UTC (permalink / raw)
To: Ayan Kumar Halder
Cc: Orzel, Michal, Ayan Kumar Halder, xen-devel@lists.xenproject.org,
Stefano Stabellini, Julien Grall, Bertrand Marquis,
Volodymyr Babchuk
Hi Ayan,
> On 7 Apr 2025, at 14:18, Ayan Kumar Halder <ayankuma@amd.com> wrote:
>
> Hi Michal,
>
> On 07/04/2025 10:04, Orzel, Michal wrote:
>>
>> On 03/04/2025 19:12, Ayan Kumar Halder wrote:
>>> Added a new file prepare_xen_region.inc to hold the common earlyboot MPU regions
>>> configurations across arm64 and arm32.
>>>
>>> prepare_xen_region, fail_insufficient_regions() will be used by both arm32 and
>>> arm64. Thus, they have been moved to prepare_xen_region.inc.
>>>
>>> enable_secondary_cpu_mm() is a stub which is moved to prepare_xen_region.inc as
>>> SMP is currently not supported for MPU.
>> This does not sound right. If you want a place to keep some common MPU stuff
>> between Arm64 and Arm32, you need to come up with better name for a file. SMP
>> has nothing to do here with preparing regions so it feels odd to have
>> enable_secondary_cpu_mm stub there.
>
> Can I rename prepare-xen-region.inc to mpu.inc ?
>
> Julien/Luca - any thoughts ?
I would say we leave the SMP stuff out from the common file, at some point we could start working on the
SMP support and maybe there would be difference between arm64 and arm32.
what about common-cpu.inc?
>
>>
>> Also, new files should use dashes '-' and not underscores '_'.
>
> Ack
>
> - Ayan
>
>>
>> ~Michal
>>
>
Cheers,
Luca
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v4 1/3] xen/arm: Move some of the functions to common file
2025-04-07 13:31 ` Luca Fancellu
@ 2025-04-07 14:07 ` Ayan Kumar Halder
2025-04-07 14:55 ` Orzel, Michal
0 siblings, 1 reply; 16+ messages in thread
From: Ayan Kumar Halder @ 2025-04-07 14:07 UTC (permalink / raw)
To: Luca Fancellu
Cc: Orzel, Michal, Ayan Kumar Halder, xen-devel@lists.xenproject.org,
Stefano Stabellini, Julien Grall, Bertrand Marquis,
Volodymyr Babchuk
On 07/04/2025 14:31, Luca Fancellu wrote:
> Hi Ayan,
Hi,
>
>> On 7 Apr 2025, at 14:18, Ayan Kumar Halder <ayankuma@amd.com> wrote:
>>
>> Hi Michal,
>>
>> On 07/04/2025 10:04, Orzel, Michal wrote:
>>> On 03/04/2025 19:12, Ayan Kumar Halder wrote:
>>>> Added a new file prepare_xen_region.inc to hold the common earlyboot MPU regions
>>>> configurations across arm64 and arm32.
>>>>
>>>> prepare_xen_region, fail_insufficient_regions() will be used by both arm32 and
>>>> arm64. Thus, they have been moved to prepare_xen_region.inc.
>>>>
>>>> enable_secondary_cpu_mm() is a stub which is moved to prepare_xen_region.inc as
>>>> SMP is currently not supported for MPU.
>>> This does not sound right. If you want a place to keep some common MPU stuff
>>> between Arm64 and Arm32, you need to come up with better name for a file. SMP
>>> has nothing to do here with preparing regions so it feels odd to have
>>> enable_secondary_cpu_mm stub there.
>> Can I rename prepare-xen-region.inc to mpu.inc ?
>>
>> Julien/Luca - any thoughts ?
> I would say we leave the SMP stuff out from the common file, at some point we could start working on the
> SMP support and maybe there would be difference between arm64 and arm32.
Do you want to duplicate enable_secondary_cpu_mm() in arm32 and arm64 ?
I am fine with that.
>
> what about common-cpu.inc?
Sounds ok.
Michal or Julien should comment as well.
- Ayan
>
>>> Also, new files should use dashes '-' and not underscores '_'.
>> Ack
>>
>> - Ayan
>>
>>> ~Michal
>>>
> Cheers,
> Luca
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v4 1/3] xen/arm: Move some of the functions to common file
2025-04-07 14:07 ` Ayan Kumar Halder
@ 2025-04-07 14:55 ` Orzel, Michal
0 siblings, 0 replies; 16+ messages in thread
From: Orzel, Michal @ 2025-04-07 14:55 UTC (permalink / raw)
To: Ayan Kumar Halder, Luca Fancellu
Cc: Ayan Kumar Halder, xen-devel@lists.xenproject.org,
Stefano Stabellini, Julien Grall, Bertrand Marquis,
Volodymyr Babchuk
On 07/04/2025 16:07, Ayan Kumar Halder wrote:
>
> On 07/04/2025 14:31, Luca Fancellu wrote:
>> Hi Ayan,
> Hi,
>>
>>> On 7 Apr 2025, at 14:18, Ayan Kumar Halder <ayankuma@amd.com> wrote:
>>>
>>> Hi Michal,
>>>
>>> On 07/04/2025 10:04, Orzel, Michal wrote:
>>>> On 03/04/2025 19:12, Ayan Kumar Halder wrote:
>>>>> Added a new file prepare_xen_region.inc to hold the common earlyboot MPU regions
>>>>> configurations across arm64 and arm32.
>>>>>
>>>>> prepare_xen_region, fail_insufficient_regions() will be used by both arm32 and
>>>>> arm64. Thus, they have been moved to prepare_xen_region.inc.
>>>>>
>>>>> enable_secondary_cpu_mm() is a stub which is moved to prepare_xen_region.inc as
>>>>> SMP is currently not supported for MPU.
>>>> This does not sound right. If you want a place to keep some common MPU stuff
>>>> between Arm64 and Arm32, you need to come up with better name for a file. SMP
>>>> has nothing to do here with preparing regions so it feels odd to have
>>>> enable_secondary_cpu_mm stub there.
>>> Can I rename prepare-xen-region.inc to mpu.inc ?
>>>
>>> Julien/Luca - any thoughts ?
>> I would say we leave the SMP stuff out from the common file, at some point we could start working on the
>> SMP support and maybe there would be difference between arm64 and arm32.
> Do you want to duplicate enable_secondary_cpu_mm() in arm32 and arm64 ?
> I am fine with that.
+1
>>
>> what about common-cpu.inc?
>
> Sounds ok.
common.inc should suffice. Let's not split hairs.
~Michal
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v4 2/3] xen/arm32: Create the same boot-time MPU regions as arm64
2025-04-03 17:12 [PATCH v4 0/3] Enable early bootup of Armv8-R AArch32 systems Ayan Kumar Halder
2025-04-03 17:12 ` [PATCH v4 1/3] xen/arm: Move some of the functions to common file Ayan Kumar Halder
@ 2025-04-03 17:12 ` Ayan Kumar Halder
2025-04-03 17:12 ` [PATCH v4 3/3] xen/arm32: mpu: Stubs to build MPU for arm32 Ayan Kumar Halder
2025-04-04 8:47 ` [PATCH v4 0/3] Enable early bootup of Armv8-R AArch32 systems Luca Fancellu
3 siblings, 0 replies; 16+ messages in thread
From: Ayan Kumar Halder @ 2025-04-03 17:12 UTC (permalink / raw)
To: xen-devel
Cc: Ayan Kumar Halder, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Michal Orzel, Volodymyr Babchuk
We have created the same boot-time MPU protection regions as Armv8-R AArch64.
Also, we have defined *_PRBAR macros for arm32. The only difference from
arm64 is that XN is 1-bit for arm32.
The macros have been defined in mpu/cpregs.h.
Also defined WRITE_SYSREG_ASM() to write to system registers in assembly.
Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
---
Changes from
v1 -
1. enable_mpu() now sets HMAIR{0,1} registers. This is similar to what is
being done in enable_mmu(). All the mm related configurations happen in this
function.
2. Fixed some typos.
v2 -
1. Include the common prepare_xen_region.inc in head.S.
2. Define LOAD_SYSREG()/STORE_SYSREG() for arm32.
v3 -
1. Rename STORE_SYSREG() as WRITE_SYSREG_ASM()
2. enable_boot_cpu_mm() is defined in head.S
xen/arch/arm/arm32/Makefile | 1 +
xen/arch/arm/arm32/mpu/Makefile | 1 +
xen/arch/arm/arm32/mpu/head.S | 91 +++++++++++++++++++++++++++
xen/arch/arm/include/asm/cpregs.h | 4 ++
xen/arch/arm/include/asm/mpu/cpregs.h | 30 +++++++++
5 files changed, 127 insertions(+)
create mode 100644 xen/arch/arm/arm32/mpu/Makefile
create mode 100644 xen/arch/arm/arm32/mpu/head.S
create mode 100644 xen/arch/arm/include/asm/mpu/cpregs.h
diff --git a/xen/arch/arm/arm32/Makefile b/xen/arch/arm/arm32/Makefile
index 40a2b4803f..537969d753 100644
--- a/xen/arch/arm/arm32/Makefile
+++ b/xen/arch/arm/arm32/Makefile
@@ -1,5 +1,6 @@
obj-y += lib/
obj-$(CONFIG_MMU) += mmu/
+obj-$(CONFIG_MPU) += mpu/
obj-$(CONFIG_EARLY_PRINTK) += debug.o
obj-y += domctl.o
diff --git a/xen/arch/arm/arm32/mpu/Makefile b/xen/arch/arm/arm32/mpu/Makefile
new file mode 100644
index 0000000000..3340058c08
--- /dev/null
+++ b/xen/arch/arm/arm32/mpu/Makefile
@@ -0,0 +1 @@
+obj-y += head.o
diff --git a/xen/arch/arm/arm32/mpu/head.S b/xen/arch/arm/arm32/mpu/head.S
new file mode 100644
index 0000000000..719ae3624e
--- /dev/null
+++ b/xen/arch/arm/arm32/mpu/head.S
@@ -0,0 +1,91 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Start-of-day code for an Armv8-R MPU system.
+ */
+
+#include <asm/arm32/macros.h>
+#include <asm/mpu/prepare_xen_region.inc>
+#include <asm/page.h>
+
+/*
+ * Set up the memory attribute type tables and enable EL2 MPU and data cache.
+ * If the Background region is enabled, then the MPU uses the default memory
+ * map as the Background region for generating the memory
+ * attributes when MPU is disabled.
+ * Since the default memory map of the Armv8-R AArch32 architecture is
+ * IMPLEMENTATION DEFINED, we intend to turn off the Background region here.
+ *
+ * Clobbers r0 - r1
+ */
+FUNC_LOCAL(enable_mpu)
+ /* Set up memory attribute type tables */
+ mov_w r0, MAIR0VAL
+ mov_w r1, MAIR1VAL
+ mcr CP32(r0, HMAIR0)
+ mcr CP32(r1, HMAIR1)
+
+ mrc CP32(r0, HSCTLR)
+ bic r0, r0, #SCTLR_ELx_BR /* Disable Background region */
+ orr r0, r0, #SCTLR_Axx_ELx_M /* Enable MPU */
+ orr r0, r0, #SCTLR_Axx_ELx_C /* Enable D-cache */
+ mcr CP32(r0, HSCTLR)
+ isb
+
+ ret
+END(enable_mpu)
+
+/*
+ * Maps the various sections of Xen (described in xen.lds.S) as different MPU
+ * regions.
+ *
+ * Clobbers r0 - r5
+ *
+ */
+FUNC(enable_boot_cpu_mm)
+ /* Get the number of regions specified in MPUIR_EL2 */
+ mrc CP32(r5, MPUIR_EL2)
+ and r5, r5, #NUM_MPU_REGIONS_MASK
+
+ /* x0: region sel */
+ mov r0, #0
+ /* Xen text section. */
+ mov_w r1, _stext
+ mov_w r2, _etext
+ prepare_xen_region r0, r1, r2, r3, r4, r5, attr_prbar=REGION_TEXT_PRBAR
+
+ /* Xen read-only data section. */
+ mov_w r1, _srodata
+ mov_w r2, _erodata
+ prepare_xen_region r0, r1, r2, r3, r4, r5, attr_prbar=REGION_RO_PRBAR
+
+ /* Xen read-only after init and data section. (RW data) */
+ mov_w r1, __ro_after_init_start
+ mov_w r2, __init_begin
+ prepare_xen_region r0, r1, r2, r3, r4, r5
+
+ /* Xen code section. */
+ mov_w r1, __init_begin
+ mov_w r2, __init_data_begin
+ prepare_xen_region r0, r1, r2, r3, r4, r5, attr_prbar=REGION_TEXT_PRBAR
+
+ /* Xen data and BSS section. */
+ mov_w r1, __init_data_begin
+ mov_w r2, __bss_end
+ prepare_xen_region r0, r1, r2, r3, r4, r5
+
+#ifdef CONFIG_EARLY_PRINTK
+ /* Xen early UART section. */
+ mov_w r1, CONFIG_EARLY_UART_BASE_ADDRESS
+ mov_w r2, (CONFIG_EARLY_UART_BASE_ADDRESS + CONFIG_EARLY_UART_SIZE)
+ prepare_xen_region r0, r1, r2, r3, r4, r5, attr_prbar=REGION_DEVICE_PRBAR, attr_prlar=REGION_DEVICE_PRLAR
+#endif
+
+ b enable_mpu
+END(enable_boot_cpu_mm)
+
+/*
+ * Local variables:
+ * mode: ASM
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/arch/arm/include/asm/cpregs.h b/xen/arch/arm/include/asm/cpregs.h
index aec9e8f329..6019a2cbdd 100644
--- a/xen/arch/arm/include/asm/cpregs.h
+++ b/xen/arch/arm/include/asm/cpregs.h
@@ -1,6 +1,10 @@
#ifndef __ASM_ARM_CPREGS_H
#define __ASM_ARM_CPREGS_H
+#ifdef CONFIG_MPU
+#include <asm/mpu/cpregs.h>
+#endif
+
/*
* AArch32 Co-processor registers.
*
diff --git a/xen/arch/arm/include/asm/mpu/cpregs.h b/xen/arch/arm/include/asm/mpu/cpregs.h
new file mode 100644
index 0000000000..66871379a5
--- /dev/null
+++ b/xen/arch/arm/include/asm/mpu/cpregs.h
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __ASM_ARM_MPU_CPREGS_H
+#define __ASM_ARM_MPU_CPREGS_H
+
+#define REGION_TEXT_PRBAR 0x18 /* SH=11 AP=10 XN=0 */
+#define REGION_RO_PRBAR 0x1D /* SH=11 AP=10 XN=1 */
+#define REGION_DATA_PRBAR 0x19 /* SH=11 AP=00 XN=1 */
+#define REGION_DEVICE_PRBAR 0x11 /* SH=10 AP=00 XN=1 */
+
+#define HMPUIR p15,4,c0,c0,4
+
+/* CP15 CR6: MPU Protection Region Base/Limit/Select Address Register */
+#define HPRSELR p15,4,c6,c2,1
+#define PRBAR_EL2 p15,4,c6,c3,0
+#define PRLAR_EL2 p15,4,c6,c8,1
+
+#define MPUIR_EL2 HMPUIR
+#define PRSELR_EL2 HPRSELR
+
+#define WRITE_SYSREG_ASM(v, name) mcr CP32(v, name)
+
+#endif /* __ASM_ARM_MPU_CPREGS_H */
+
+/*
+ * Local variables:
+ * mode: ASM
+ * indent-tabs-mode: nil
+ * End:
+ */
--
2.25.1
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v4 3/3] xen/arm32: mpu: Stubs to build MPU for arm32
2025-04-03 17:12 [PATCH v4 0/3] Enable early bootup of Armv8-R AArch32 systems Ayan Kumar Halder
2025-04-03 17:12 ` [PATCH v4 1/3] xen/arm: Move some of the functions to common file Ayan Kumar Halder
2025-04-03 17:12 ` [PATCH v4 2/3] xen/arm32: Create the same boot-time MPU regions as arm64 Ayan Kumar Halder
@ 2025-04-03 17:12 ` Ayan Kumar Halder
2025-04-04 9:11 ` Luca Fancellu
2025-04-04 8:47 ` [PATCH v4 0/3] Enable early bootup of Armv8-R AArch32 systems Luca Fancellu
3 siblings, 1 reply; 16+ messages in thread
From: Ayan Kumar Halder @ 2025-04-03 17:12 UTC (permalink / raw)
To: xen-devel
Cc: Ayan Kumar Halder, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Michal Orzel, Volodymyr Babchuk
Add stubs to enable compilation
Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
---
Changes from :-
v1, v2 -
1. New patch introduced in v3.
2. Should be applied on top of
https://patchwork.kernel.org/project/xen-devel/cover/20250316192445.2376484-1-luca.fancellu@arm.com/
v3 -
1. Add stubs for map_domain_page() and similar functions.
2. 'BUG_ON("unimplemented")' is kept in all the stubs.
xen/arch/arm/arm32/mpu/Makefile | 2 ++
xen/arch/arm/arm32/mpu/p2m.c | 18 ++++++++++++++
xen/arch/arm/arm32/mpu/smpboot.c | 23 ++++++++++++++++++
xen/arch/arm/include/asm/mm.h | 5 ++++
xen/arch/arm/mpu/Makefile | 1 +
xen/arch/arm/mpu/domain_page.c | 40 ++++++++++++++++++++++++++++++++
6 files changed, 89 insertions(+)
create mode 100644 xen/arch/arm/arm32/mpu/p2m.c
create mode 100644 xen/arch/arm/arm32/mpu/smpboot.c
create mode 100644 xen/arch/arm/mpu/domain_page.c
diff --git a/xen/arch/arm/arm32/mpu/Makefile b/xen/arch/arm/arm32/mpu/Makefile
index 3340058c08..38797f28af 100644
--- a/xen/arch/arm/arm32/mpu/Makefile
+++ b/xen/arch/arm/arm32/mpu/Makefile
@@ -1 +1,3 @@
obj-y += head.o
+obj-y += smpboot.o
+obj-y += p2m.o
diff --git a/xen/arch/arm/arm32/mpu/p2m.c b/xen/arch/arm/arm32/mpu/p2m.c
new file mode 100644
index 0000000000..df8de5c7d8
--- /dev/null
+++ b/xen/arch/arm/arm32/mpu/p2m.c
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/init.h>
+#include <asm/p2m.h>
+
+void __init setup_virt_paging(void)
+{
+ BUG_ON("unimplemented");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/arch/arm/arm32/mpu/smpboot.c b/xen/arch/arm/arm32/mpu/smpboot.c
new file mode 100644
index 0000000000..3f3e54294e
--- /dev/null
+++ b/xen/arch/arm/arm32/mpu/smpboot.c
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/mm.h>
+
+int prepare_secondary_mm(int cpu)
+{
+ BUG_ON("unimplemented");
+ return -EINVAL;
+}
+
+void update_boot_mapping(bool enable)
+{
+ BUG_ON("unimplemented");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h
index fbffaccef4..2a52cf530f 100644
--- a/xen/arch/arm/include/asm/mm.h
+++ b/xen/arch/arm/include/asm/mm.h
@@ -171,12 +171,17 @@ struct page_info
#define PGC_need_scrub PGC_allocated
#ifdef CONFIG_ARM_32
+#ifdef CONFIG_MPU
+#define is_xen_heap_page(page) ({ BUG_ON("unimplemented"); false; })
+#define is_xen_heap_mfn(mfn) ({ BUG_ON("unimplemented"); false; })
+#else /* !CONFIG_MPU */
#define is_xen_heap_page(page) is_xen_heap_mfn(page_to_mfn(page))
#define is_xen_heap_mfn(mfn) ({ \
unsigned long mfn_ = mfn_x(mfn); \
(mfn_ >= mfn_x(directmap_mfn_start) && \
mfn_ < mfn_x(directmap_mfn_end)); \
})
+#endif /* !CONFIG_MPU */
#else
#define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap)
#define is_xen_heap_mfn(mfn) \
diff --git a/xen/arch/arm/mpu/Makefile b/xen/arch/arm/mpu/Makefile
index 21bbc517b5..ff221011d5 100644
--- a/xen/arch/arm/mpu/Makefile
+++ b/xen/arch/arm/mpu/Makefile
@@ -2,3 +2,4 @@ obj-y += mm.o
obj-y += p2m.o
obj-y += setup.init.o
obj-y += vmap.o
+obj-$(CONFIG_ARM_32) += domain_page.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..b9ebb03d67
--- /dev/null
+++ b/xen/arch/arm/mpu/domain_page.c
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include <xen/domain_page.h>
+
+void *map_domain_page_global(mfn_t mfn)
+{
+ BUG_ON("unimplemented");
+ return (void*)0;
+}
+
+/* Map a page of domheap memory */
+void *map_domain_page(mfn_t mfn)
+{
+ BUG_ON("unimplemented");
+ return (void*)0;
+}
+
+/* Release a mapping taken with map_domain_page() */
+void unmap_domain_page(const void *ptr)
+{
+ BUG_ON("unimplemented");
+}
+
+mfn_t domain_page_map_to_mfn(const void *ptr)
+{
+ BUG_ON("unimplemented");
+}
+
+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.25.1
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH v4 3/3] xen/arm32: mpu: Stubs to build MPU for arm32
2025-04-03 17:12 ` [PATCH v4 3/3] xen/arm32: mpu: Stubs to build MPU for arm32 Ayan Kumar Halder
@ 2025-04-04 9:11 ` Luca Fancellu
2025-04-07 18:29 ` Ayan Kumar Halder
0 siblings, 1 reply; 16+ messages in thread
From: Luca Fancellu @ 2025-04-04 9:11 UTC (permalink / raw)
To: Ayan Kumar Halder
Cc: xen-devel@lists.xenproject.org, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Michal Orzel, Volodymyr Babchuk
Hi Ayan,
> On 3 Apr 2025, at 18:12, Ayan Kumar Halder <ayan.kumar.halder@amd.com> wrote:
>
> Add stubs to enable compilation
>
> Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
> ---
>
> Changes from :-
>
> v1, v2 -
> 1. New patch introduced in v3.
> 2. Should be applied on top of
> https://patchwork.kernel.org/project/xen-devel/cover/20250316192445.2376484-1-luca.fancellu@arm.com/
>
> v3 -
> 1. Add stubs for map_domain_page() and similar functions.
>
> 2. 'BUG_ON("unimplemented")' is kept in all the stubs.
>
> xen/arch/arm/arm32/mpu/Makefile | 2 ++
> xen/arch/arm/arm32/mpu/p2m.c | 18 ++++++++++++++
> xen/arch/arm/arm32/mpu/smpboot.c | 23 ++++++++++++++++++
> xen/arch/arm/include/asm/mm.h | 5 ++++
> xen/arch/arm/mpu/Makefile | 1 +
> xen/arch/arm/mpu/domain_page.c | 40 ++++++++++++++++++++++++++++++++
> 6 files changed, 89 insertions(+)
> create mode 100644 xen/arch/arm/arm32/mpu/p2m.c
> create mode 100644 xen/arch/arm/arm32/mpu/smpboot.c
> create mode 100644 xen/arch/arm/mpu/domain_page.c
>
>
> diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h
> index fbffaccef4..2a52cf530f 100644
> --- a/xen/arch/arm/include/asm/mm.h
> +++ b/xen/arch/arm/include/asm/mm.h
> @@ -171,12 +171,17 @@ struct page_info
> #define PGC_need_scrub PGC_allocated
>
> #ifdef CONFIG_ARM_32
> +#ifdef CONFIG_MPU
> +#define is_xen_heap_page(page) ({ BUG_ON("unimplemented"); false; })
> +#define is_xen_heap_mfn(mfn) ({ BUG_ON("unimplemented"); false; })
> +#else /* !CONFIG_MPU */
> #define is_xen_heap_page(page) is_xen_heap_mfn(page_to_mfn(page))
> #define is_xen_heap_mfn(mfn) ({ \
> unsigned long mfn_ = mfn_x(mfn); \
> (mfn_ >= mfn_x(directmap_mfn_start) && \
> mfn_ < mfn_x(directmap_mfn_end)); \
> })
> +#endif /* !CONFIG_MPU */
> #else
> #define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap)
> #define is_xen_heap_mfn(mfn) \
I’ve had a look on this, if we want to get rid of some #ifdef we could do this:
diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h
index 2a52cf530f25..5b67c0f8bb1c 100644
--- a/xen/arch/arm/include/asm/mm.h
+++ b/xen/arch/arm/include/asm/mm.h
@@ -170,19 +170,7 @@ struct page_info
#define _PGC_need_scrub _PGC_allocated
#define PGC_need_scrub PGC_allocated
-#ifdef CONFIG_ARM_32
-#ifdef CONFIG_MPU
-#define is_xen_heap_page(page) ({ BUG_ON("unimplemented"); false; })
-#define is_xen_heap_mfn(mfn) ({ BUG_ON("unimplemented"); false; })
-#else /* !CONFIG_MPU */
-#define is_xen_heap_page(page) is_xen_heap_mfn(page_to_mfn(page))
-#define is_xen_heap_mfn(mfn) ({ \
- unsigned long mfn_ = mfn_x(mfn); \
- (mfn_ >= mfn_x(directmap_mfn_start) && \
- mfn_ < mfn_x(directmap_mfn_end)); \
-})
-#endif /* !CONFIG_MPU */
-#else
+#ifdef CONFIG_ARM_64
#define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap)
#define is_xen_heap_mfn(mfn) \
(mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(mfn)))
diff --git a/xen/arch/arm/include/asm/mmu/mm.h b/xen/arch/arm/include/asm/mmu/mm.h
index caba987edc85..9b98d12b076b 100644
--- a/xen/arch/arm/include/asm/mmu/mm.h
+++ b/xen/arch/arm/include/asm/mmu/mm.h
@@ -21,6 +21,15 @@ extern unsigned long directmap_base_pdx;
#define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)
+#ifdef CONFIG_ARM_32
+#define is_xen_heap_page(page) is_xen_heap_mfn(page_to_mfn(page))
+#define is_xen_heap_mfn(mfn) ({ \
+ unsigned long mfn_ = mfn_x(mfn); \
+ (mfn_ >= mfn_x(directmap_mfn_start) && \
+ mfn_ < mfn_x(directmap_mfn_end)); \
+})
+#endif
+
#define virt_to_maddr(va) ({ \
vaddr_t va_ = (vaddr_t)(va); \
(paddr_t)((va_to_par(va_) & PADDR_MASK & PAGE_MASK) | (va_ & ~PAGE_MASK)); \
diff --git a/xen/arch/arm/include/asm/mpu/mm.h b/xen/arch/arm/include/asm/mpu/mm.h
index 86f33d9836b7..bfd840fa5d31 100644
--- a/xen/arch/arm/include/asm/mpu/mm.h
+++ b/xen/arch/arm/include/asm/mpu/mm.h
@@ -13,6 +13,11 @@ extern struct page_info *frame_table;
#define virt_to_maddr(va) ((paddr_t)((vaddr_t)(va) & PADDR_MASK))
+#ifdef CONFIG_ARM_32
+#define is_xen_heap_page(page) ({ BUG_ON("unimplemented"); false; })
+#define is_xen_heap_mfn(mfn) ({ BUG_ON("unimplemented"); false; })
+#endif
+
/* On MPU systems there is no translation, ma == va. */
static inline void *maddr_to_virt(paddr_t ma)
{
But feel free to ignore if it’s not desirable.
> diff --git a/xen/arch/arm/mpu/Makefile b/xen/arch/arm/mpu/Makefile
> index 21bbc517b5..ff221011d5 100644
> --- a/xen/arch/arm/mpu/Makefile
> +++ b/xen/arch/arm/mpu/Makefile
> @@ -2,3 +2,4 @@ obj-y += mm.o
> obj-y += p2m.o
> obj-y += setup.init.o
> obj-y += vmap.o
> +obj-$(CONFIG_ARM_32) += domain_page.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..b9ebb03d67
> --- /dev/null
> +++ b/xen/arch/arm/mpu/domain_page.c
> @@ -0,0 +1,40 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +#include <xen/domain_page.h>
> +
> +void *map_domain_page_global(mfn_t mfn)
> +{
> + BUG_ON("unimplemented");
> + return (void*)0;
return NULL? here and below
> +}
> +
> +/* Map a page of domheap memory */
> +void *map_domain_page(mfn_t mfn)
> +{
> + BUG_ON("unimplemented");
> + return (void*)0;
> +}
> +
> +/* Release a mapping taken with map_domain_page() */
> +void unmap_domain_page(const void *ptr)
> +{
> + BUG_ON("unimplemented");
> +}
> +
> +mfn_t domain_page_map_to_mfn(const void *ptr)
> +{
> + BUG_ON("unimplemented");
Not really necessary, but if you want: 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.25.1
>
>
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH v4 3/3] xen/arm32: mpu: Stubs to build MPU for arm32
2025-04-04 9:11 ` Luca Fancellu
@ 2025-04-07 18:29 ` Ayan Kumar Halder
0 siblings, 0 replies; 16+ messages in thread
From: Ayan Kumar Halder @ 2025-04-07 18:29 UTC (permalink / raw)
To: Luca Fancellu, Ayan Kumar Halder
Cc: xen-devel@lists.xenproject.org, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Michal Orzel, Volodymyr Babchuk
On 04/04/2025 10:11, Luca Fancellu wrote:
> Hi Ayan,
Hi Luca,
>
>> On 3 Apr 2025, at 18:12, Ayan Kumar Halder <ayan.kumar.halder@amd.com> wrote:
>>
>> Add stubs to enable compilation
>>
>> Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
>> ---
>>
>> Changes from :-
>>
>> v1, v2 -
>> 1. New patch introduced in v3.
>> 2. Should be applied on top of
>> https://patchwork.kernel.org/project/xen-devel/cover/20250316192445.2376484-1-luca.fancellu@arm.com/
>>
>> v3 -
>> 1. Add stubs for map_domain_page() and similar functions.
>>
>> 2. 'BUG_ON("unimplemented")' is kept in all the stubs.
>>
>> xen/arch/arm/arm32/mpu/Makefile | 2 ++
>> xen/arch/arm/arm32/mpu/p2m.c | 18 ++++++++++++++
>> xen/arch/arm/arm32/mpu/smpboot.c | 23 ++++++++++++++++++
>> xen/arch/arm/include/asm/mm.h | 5 ++++
>> xen/arch/arm/mpu/Makefile | 1 +
>> xen/arch/arm/mpu/domain_page.c | 40 ++++++++++++++++++++++++++++++++
>> 6 files changed, 89 insertions(+)
>> create mode 100644 xen/arch/arm/arm32/mpu/p2m.c
>> create mode 100644 xen/arch/arm/arm32/mpu/smpboot.c
>> create mode 100644 xen/arch/arm/mpu/domain_page.c
>>
>>
>> diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h
>> index fbffaccef4..2a52cf530f 100644
>> --- a/xen/arch/arm/include/asm/mm.h
>> +++ b/xen/arch/arm/include/asm/mm.h
>> @@ -171,12 +171,17 @@ struct page_info
>> #define PGC_need_scrub PGC_allocated
>>
>> #ifdef CONFIG_ARM_32
>> +#ifdef CONFIG_MPU
>> +#define is_xen_heap_page(page) ({ BUG_ON("unimplemented"); false; })
>> +#define is_xen_heap_mfn(mfn) ({ BUG_ON("unimplemented"); false; })
>> +#else /* !CONFIG_MPU */
>> #define is_xen_heap_page(page) is_xen_heap_mfn(page_to_mfn(page))
>> #define is_xen_heap_mfn(mfn) ({ \
>> unsigned long mfn_ = mfn_x(mfn); \
>> (mfn_ >= mfn_x(directmap_mfn_start) && \
>> mfn_ < mfn_x(directmap_mfn_end)); \
>> })
>> +#endif /* !CONFIG_MPU */
>> #else
>> #define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap)
>> #define is_xen_heap_mfn(mfn) \
> I’ve had a look on this, if we want to get rid of some #ifdef we could do this:
>
> diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h
> index 2a52cf530f25..5b67c0f8bb1c 100644
> --- a/xen/arch/arm/include/asm/mm.h
> +++ b/xen/arch/arm/include/asm/mm.h
> @@ -170,19 +170,7 @@ struct page_info
> #define _PGC_need_scrub _PGC_allocated
> #define PGC_need_scrub PGC_allocated
>
> -#ifdef CONFIG_ARM_32
> -#ifdef CONFIG_MPU
> -#define is_xen_heap_page(page) ({ BUG_ON("unimplemented"); false; })
> -#define is_xen_heap_mfn(mfn) ({ BUG_ON("unimplemented"); false; })
> -#else /* !CONFIG_MPU */
> -#define is_xen_heap_page(page) is_xen_heap_mfn(page_to_mfn(page))
> -#define is_xen_heap_mfn(mfn) ({ \
> - unsigned long mfn_ = mfn_x(mfn); \
> - (mfn_ >= mfn_x(directmap_mfn_start) && \
> - mfn_ < mfn_x(directmap_mfn_end)); \
> -})
> -#endif /* !CONFIG_MPU */
> -#else
> +#ifdef CONFIG_ARM_64
> #define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap)
> #define is_xen_heap_mfn(mfn) \
> (mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(mfn)))
> diff --git a/xen/arch/arm/include/asm/mmu/mm.h b/xen/arch/arm/include/asm/mmu/mm.h
> index caba987edc85..9b98d12b076b 100644
> --- a/xen/arch/arm/include/asm/mmu/mm.h
> +++ b/xen/arch/arm/include/asm/mmu/mm.h
> @@ -21,6 +21,15 @@ extern unsigned long directmap_base_pdx;
>
> #define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)
>
> +#ifdef CONFIG_ARM_32
> +#define is_xen_heap_page(page) is_xen_heap_mfn(page_to_mfn(page))
> +#define is_xen_heap_mfn(mfn) ({ \
> + unsigned long mfn_ = mfn_x(mfn); \
> + (mfn_ >= mfn_x(directmap_mfn_start) && \
> + mfn_ < mfn_x(directmap_mfn_end)); \
> +})
> +#endif
> +
> #define virt_to_maddr(va) ({ \
> vaddr_t va_ = (vaddr_t)(va); \
> (paddr_t)((va_to_par(va_) & PADDR_MASK & PAGE_MASK) | (va_ & ~PAGE_MASK)); \
> diff --git a/xen/arch/arm/include/asm/mpu/mm.h b/xen/arch/arm/include/asm/mpu/mm.h
> index 86f33d9836b7..bfd840fa5d31 100644
> --- a/xen/arch/arm/include/asm/mpu/mm.h
> +++ b/xen/arch/arm/include/asm/mpu/mm.h
> @@ -13,6 +13,11 @@ extern struct page_info *frame_table;
>
> #define virt_to_maddr(va) ((paddr_t)((vaddr_t)(va) & PADDR_MASK))
>
> +#ifdef CONFIG_ARM_32
> +#define is_xen_heap_page(page) ({ BUG_ON("unimplemented"); false; })
> +#define is_xen_heap_mfn(mfn) ({ BUG_ON("unimplemented"); false; })
> +#endif
> +
> /* On MPU systems there is no translation, ma == va. */
> static inline void *maddr_to_virt(paddr_t ma)
> {
>
> But feel free to ignore if it’s not desirable.
Actually, makes sense. I have included this in my v5.
>
>
>> diff --git a/xen/arch/arm/mpu/Makefile b/xen/arch/arm/mpu/Makefile
>> index 21bbc517b5..ff221011d5 100644
>> --- a/xen/arch/arm/mpu/Makefile
>> +++ b/xen/arch/arm/mpu/Makefile
>> @@ -2,3 +2,4 @@ obj-y += mm.o
>> obj-y += p2m.o
>> obj-y += setup.init.o
>> obj-y += vmap.o
>> +obj-$(CONFIG_ARM_32) += domain_page.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..b9ebb03d67
>> --- /dev/null
>> +++ b/xen/arch/arm/mpu/domain_page.c
>> @@ -0,0 +1,40 @@
>> +/* SPDX-License-Identifier: GPL-2.0-or-later */
>> +#include <xen/domain_page.h>
>> +
>> +void *map_domain_page_global(mfn_t mfn)
>> +{
>> + BUG_ON("unimplemented");
>> + return (void*)0;
> return NULL? here and below
>
>> +}
>> +
>> +/* Map a page of domheap memory */
>> +void *map_domain_page(mfn_t mfn)
>> +{
>> + BUG_ON("unimplemented");
>> + return (void*)0;
>> +}
>> +
>> +/* Release a mapping taken with map_domain_page() */
>> +void unmap_domain_page(const void *ptr)
>> +{
>> + BUG_ON("unimplemented");
>> +}
>> +
>> +mfn_t domain_page_map_to_mfn(const void *ptr)
>> +{
>> + BUG_ON("unimplemented");
> Not really necessary, but if you want: return INVALID_MFN;
The function is still technically unimplemented, so I will keep that and
add return INVALID_MFN;
The rest of your suggestions are perfect. :)
I have incorporated them in v5.
- Ayan
>
>> +}
>> +
>> +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.25.1
>>
>>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v4 0/3] Enable early bootup of Armv8-R AArch32 systems
2025-04-03 17:12 [PATCH v4 0/3] Enable early bootup of Armv8-R AArch32 systems Ayan Kumar Halder
` (2 preceding siblings ...)
2025-04-03 17:12 ` [PATCH v4 3/3] xen/arm32: mpu: Stubs to build MPU for arm32 Ayan Kumar Halder
@ 2025-04-04 8:47 ` Luca Fancellu
3 siblings, 0 replies; 16+ messages in thread
From: Luca Fancellu @ 2025-04-04 8:47 UTC (permalink / raw)
To: Ayan Kumar Halder
Cc: xen-devel@lists.xenproject.org, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Michal Orzel, Volodymyr Babchuk
Hi Ayan,
> On 3 Apr 2025, at 18:12, Ayan Kumar Halder <ayan.kumar.halder@amd.com> wrote:
>
> Enable early booting of Armv8-R AArch32 based systems.
>
> Ayan Kumar Halder (3):
> xen/arm: Move some of the functions to common file
> xen/arm32: Create the same boot-time MPU regions as arm64
> xen/arm32: mpu: Stubs to build MPU for arm32
the serie is breaking the compilation of Arm64 MPU:
[…]
xen/arch/arm/include/asm/mpu/cpregs.h:6: error: "REGION_TEXT_PRBAR" redefined [-Werror]
6 | #define REGION_TEXT_PRBAR 0x18 /* SH=11 AP=10 XN=0 */
|
[…]
Cheers,
Luca
^ permalink raw reply [flat|nested] 16+ messages in thread