xen/arm: Split MMU code as the prepration of MPU work
v5 cover xen/arm: Split MMU code as the prepration of MPU work
Based on the discussion in the Xen Summit [1], sending this series out after addressing the comments in v4 [2] as the preparation work to add MPU support. Full series of single core MPU support to boot Linux guest can be found in [3], which passed the GitLab CI check in [4].
Mostly code movement, with some of Kconfig and build system (mainly Makefiles) adjustment. No functional change expected.
This series is based on:a9a3b432a8 x86: adjust comparison for earlier signedness change
[1] https://lore.kernel.org/xen-devel/AS8PR08MB799122F8B0CB841DED64F4819226A@AS8PR08MB7991.eurprd08.prod.outlook.com/
[2] https://lore.kernel.org/xen-devel/[email protected]/
[3] https://gitlab.com/xen-project/people/henryw/xen/-/commits/mpu_v5/
[4] https://gitlab.com/xen-project/people/henryw/xen/-/pipelines/966450933
Henry Wang (4):
xen/arm: Introduce CONFIG_MMU Kconfig option xen/arm64: Split and move MMU-specific head.S to mmu/head.S xen/arm64: Fold setup_fixmap() to create_page_tables() xen/arm: Extract MMU-specific code
Penny Zheng (6):
xen/arm: Fold pmap and fixmap into MMU system
xen/arm: mm: Use generic variable/function names for extendability xen/arm: mmu: move MMU-specific setup_mm to mmu/setup.c xen/arm: mmu: move MMU specific P2M code to mmu/p2m.{c,h} xen/arm: mmu: relocate copy_from_paddr() to setup.c xen/arm: mmu: enable SMMU subsystem only in MMU
Wei Chen (3):
xen/arm64: head.S: Introduce enable_{boot,secondary}_cpu_mm() xen/arm64: prepare for moving MMU related code from head.S xen/arm: Move MMU related definitions from config.h to mmu/layout.h
xen/arch/arm/Kconfig | 5 +-
xen/arch/arm/Makefile | 1 +
xen/arch/arm/arm32/head.S | 4 +-
xen/arch/arm/arm64/Makefile | 2 +-
xen/arch/arm/arm64/head.S | 496 +------
xen/arch/arm/arm64/mmu/Makefile | 2 +
xen/arch/arm/arm64/mmu/head.S | 460 ++++++
xen/arch/arm/arm64/{ => mmu}/mm.c | 11 +-
xen/arch/arm/arm64/smpboot.c | 6 +-
xen/arch/arm/include/asm/arm64/macros.h | 36 +
xen/arch/arm/include/asm/arm64/mm.h | 7 +-
xen/arch/arm/include/asm/config.h | 132 +-
xen/arch/arm/include/asm/fixmap.h | 7 +-
xen/arch/arm/include/asm/mm.h | 30 +-
xen/arch/arm/include/asm/mmu/layout.h | 146 ++
xen/arch/arm/include/asm/mmu/mm.h | 55 +
xen/arch/arm/include/asm/mmu/p2m.h | 18 +
xen/arch/arm/include/asm/p2m.h | 33 +-
xen/arch/arm/include/asm/page.h | 15 -
xen/arch/arm/include/asm/setup.h | 8 +-
xen/arch/arm/kernel.c | 27 -
xen/arch/arm/mm.c | 1119 --------------
xen/arch/arm/mmu/Makefile | 3 +
xen/arch/arm/mmu/mm.c | 1153 +++++++++++++++
xen/arch/arm/mmu/p2m.c | 1610 ++++++++++++++++++++
xen/arch/arm/mmu/setup.c | 366 +++++
xen/arch/arm/p2m.c | 1772 ++---------------------
xen/arch/arm/setup.c | 326 +----
xen/arch/arm/smpboot.c | 4 +-
xen/arch/arm/xen.lds.S | 1 +
xen/drivers/passthrough/Kconfig | 3 +-
31 files changed, 4042 insertions(+), 3816 deletions(-)
create mode 100644 xen/arch/arm/arm64/mmu/Makefile
create mode 100644 xen/arch/arm/arm64/mmu/head.S
rename xen/arch/arm/arm64/{ => mmu}/mm.c (95%)
create mode 100644 xen/arch/arm/include/asm/mmu/layout.h
create mode 100644 xen/arch/arm/include/asm/mmu/mm.h
create mode 100644 xen/arch/arm/include/asm/mmu/p2m.h
create mode 100644 xen/arch/arm/mmu/Makefile
create mode 100644 xen/arch/arm/mmu/mm.c
create mode 100644 xen/arch/arm/mmu/p2m.c
create mode 100644 xen/arch/arm/mmu/setup.cSignature · 1 line
2.25.1
PATCH v5 1/13 xen/arm64: head.S: Introduce enable_{boot,secondary}_cpu_mm()
From: Wei Chen <[email protected]>
At the moment, on MMU system, enable_mmu() will return to an address in the 1:1 mapping, then each path is responsible to switch to virtual runtime mapping. Then remove_identity_mapping() is called on the boot CPU to remove all 1:1 mapping.
Since remove_identity_mapping() is not necessary on Non-MMU system, and we also avoid creating empty function for Non-MMU system, trying to keep only one codeflow in arm64/head.S, we move path switch and remove_identity_mapping() in enable_mmu() on MMU system.
As the remove_identity_mapping should only be called for the boot CPU only, so we introduce enable_boot_cpu_mm() for boot CPU and enable_secondary_cpu_mm() for secondary CPUs in this patch.
---
v5:
- Add missing "()" in title.
- Use more generic comment in enable_{boot,secondary}_cpu_mm() to mention function will return to the vaddr requested by the caller.
- Move 'mov lr, x5' closer to 'b remove_identity_mapping'.
- Drop the 'b fail' for unreachable code in enable_boot_cpu_mm(). v4:
- Clarify remove_identity_mapping() is called on boot CPU and keep the function/proc format consistent in commit msg.
- Drop inaccurate (due to the refactor) in-code comment.
- Rename enable_{boot,runtime}_mmu to enable_{boot,secondary}_cpu_mm.
- Reword the in-code comment on top of enable_{boot,secondary}_cpu_mm.
- Call "fail" for unreachable code.
v3:
- new patch
--- xen/arch/arm/arm64/head.S | 83 ++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 19 deletions(-)
xen/arch/arm/arm64/head.S +64 -19
@@ -325,21 +325,11 @@ real_start_efi: bl check_cpu_mode bl cpu_init - bl create_page_tables - load_paddr x0, boot_pgtable - bl enable_mmu - /* We are still in the 1:1 mapping. Jump to the runtime Virtual Address. */ - ldr x0, =primary_switched - br x0 + ldr lr, =primary_switched + b enable_boot_cpu_mm + primary_switched: - /* - * The 1:1 map may clash with other parts of the Xen virtual memory - * layout. As it is not used anymore, remove it completely to - * avoid having to worry about replacing existing mapping - * afterwards. - */ - bl remove_identity_mapping bl setup_fixmap #ifdef CONFIG_EARLY_PRINTK /* Use a virtual address to access the UART. */
@@ -384,13 +374,10 @@ GLOBAL(init_secondary) #endif bl check_cpu_mode bl cpu_init - load_paddr x0, init_ttbr - ldr x0, [x0] - bl enable_mmu - /* We are still in the 1:1 mapping. Jump to the runtime Virtual Address. */ - ldr x0, =secondary_switched - br x0 + ldr lr, =secondary_switched + b enable_secondary_cpu_mm + secondary_switched: #ifdef CONFIG_EARLY_PRINTK /* Use a virtual address to access the UART. */
@@ -748,6 +735,64 @@ enable_mmu: ret ENDPROC(enable_mmu) +/* + * Enable mm (turn on the data cache and the MMU) for secondary CPUs. + * The function will return to the virtual address provided in LR (e.g. the + * runtime mapping). + * + * Inputs: + * lr : Virtual address to return to. + * + * Clobbers x0 - x5 + */ +enable_secondary_cpu_mm: + mov x5, lr + + load_paddr x0, init_ttbr + ldr x0, [x0] + + bl enable_mmu + mov lr, x5 + + /* Return to the virtual address requested by the caller. */ + ret +ENDPROC(enable_secondary_cpu_mm) + +/* + * Enable mm (turn on the data cache and the MMU) for the boot CPU. + * The function will return to the virtual address provided in LR (e.g. the + * runtime mapping). + * + * Inputs: + * lr : Virtual address to return to. + * + * Clobbers x0 - x5 + */ +enable_boot_cpu_mm: + mov x5, lr + + bl create_page_tables + load_paddr x0, boot_pgtable + + bl enable_mmu + + /* + * The MMU is turned on and we are in the 1:1 mapping. Switch + * to the runtime mapping. + */ + ldr x0, =1f + br x0 +1: + mov lr, x5 + /* + * The 1:1 map may clash with other parts of the Xen virtual memory + * layout. As it is not used anymore, remove it completely to avoid + * having to worry about replacing existing mapping afterwards. + * Function will return to the virtual address requested by the caller. + */ + b remove_identity_mapping +ENDPROC(enable_boot_cpu_mm) + /* * Remove the 1:1 map from the page-tables. It is not easy to keep track * where the 1:1 map was mapped, so we will look for the top-level entry
Signature · 1 line
2.25.1
Re: [PATCH v5 01/13] xen/arm64: head.S: Introduce enable_{boot,secondary}_cpu_mm()
Hi Henry,
Quoted 12 lines · Henry Wang
From: Wei Chen <[email protected]>
At the moment, on MMU system,
enable_mmu()will return to an address in the 1:1 mapping, then each path is responsible to switch to virtual runtime mapping. Thenremove_identity_mapping()is called on the boot CPU to remove all 1:1 mapping.Since
remove_identity_mapping()is not necessary on Non-MMU system, and we also avoid creating empty function for Non-MMU system, trying to keep only one codeflow inarm64/head.S, we move path switch andremove_identity_mapping()inenable_mmu()on MMU system.
Quoted 6 lines
As the
remove_identity_mappingshould only be called for the boot CPU only, so we introduceenable_boot_cpu_mm()for boot CPU andenable_secondary_cpu_mm()for secondary CPUs in this patch.Signed-off-by Wei Chen <[email protected]>
One remark below. With or without it addressed:
[...]
Quoted 12 lines
xen/arch/arm/arm64/head.S +12
-0+/* + * Enable mm (turn on the data cache and the MMU) for secondary CPUs. + * The function will return to the virtual address provided in LR (e.g. the + * runtime mapping). + * + * Inputs: + * lr : Virtual address to return to. + * + * Clobbers x0 - x5 + */ +enable_secondary_cpu_mm: + mov x5, lr
xen/arch/arm/arm64/head.S enable_mmu: · line 759
Quoted 10 lines
xen/arch/arm/arm64/head.S +10
-0+ + load_paddr x0, init_ttbr + ldr x0, [x0] + + bl enable_mmu + mov lr, x5 + + /* Return to the virtual address requested by the caller. */ + ret +ENDPROC(enable_secondary_cpu_mm)
NIT: enable_mmu() could directly return to the virtual address. This would reduce the function to:
load_paddr x0, init_ttbr
ldr x0, [x0]
/* Return to the virtual address requested by the caller. b enable_mmu
Quoted 29 lines
xen/arch/arm/arm64/head.S +29
-0+ +/* + * Enable mm (turn on the data cache and the MMU) for the boot CPU. + * The function will return to the virtual address provided in LR (e.g. the + * runtime mapping). + * + * Inputs: + * lr : Virtual address to return to. + * + * Clobbers x0 - x5 + */ +enable_boot_cpu_mm: + mov x5, lr + + bl create_page_tables + load_paddr x0, boot_pgtable + + bl enable_mmu + + /* + * The MMU is turned on and we are in the 1:1 mapping. Switch + * to the runtime mapping. + */ + ldr x0, =1f + br x0 +1: + mov lr, x5 + /* + * The 1:1 map may clash with other parts of the Xen virtual memory
xen/arch/arm/arm64/head.S enable_mmu: · line 798
Quoted 10 lines
xen/arch/arm/arm64/head.S +7
-0+ * layout. As it is not used anymore, remove it completely to avoid + * having to worry about replacing existing mapping afterwards. + * Function will return to the virtual address requested by the caller. + */ + b remove_identity_mapping +ENDPROC(enable_boot_cpu_mm) + /* * Remove the 1:1 map from the page-tables. It is not easy to keep track * where the 1:1 map was mapped, so we will look for the top-level entry
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 01/13] xen/arm64: head.S: Introduce enable_{boot,secondary}_cpu_mm()
Hi Julien,
Quoted 20 lines · Julien Grall
Hi Henry,
Quoted 12 lines · Henry Wang
From: Wei Chen <[email protected]>
At the moment, on MMU system,enable_mmu()will return to an address in the 1:1 mapping, then each path is responsible to switch to virtual runtime mapping. Thenremove_identity_mapping()is called on the boot CPU to remove all 1:1 mapping. Sinceremove_identity_mapping()is not necessary on Non-MMU system, and we also avoid creating empty function for Non-MMU system, trying to keep only one codeflow inarm64/head.S, we move path switch andremove_identity_mapping()inenable_mmu()on MMU system. As theremove_identity_mappingshould only be called for the boot CPU only, so we introduceenable_boot_cpu_mm()for boot CPU andenable_secondary_cpu_mm()for secondary CPUs in this patch.Quoted 2 lines
Signed-off-by Wei Chen <[email protected]>
Quoted 3 lines
One remark below. With or without it addressed:
Reviewed-by Julien Grall <[email protected]>
Thanks, I will take this tag with ...
Quoted 28 lines
[...]
Quoted 12 lines
xen/arch/arm/arm64/head.S +12
-0+/* + * Enable mm (turn on the data cache and the MMU) for secondary CPUs. + * The function will return to the virtual address provided in LR (e.g. the + * runtime mapping). + * + * Inputs: + * lr : Virtual address to return to. + * + * Clobbers x0 - x5 + */ +enable_secondary_cpu_mm: + mov x5, lrxen/arch/arm/arm64/head.S enable_mmu: · line 759
Quoted 10 lines
xen/arch/arm/arm64/head.S +10
-0+ + load_paddr x0, init_ttbr + ldr x0, [x0] + + bl enable_mmu + mov lr, x5 + + /* Return to the virtual address requested by the caller. */ + ret +ENDPROC(enable_secondary_cpu_mm)NIT:
enable_mmu()could directly return to the virtual address. This would reduce the function to:
Quoted 5 lines
load_paddrx0,init_ttbr
ldr x0, [x0]/* Return to the virtual address requested by the caller. b
enable_mmu
…this fixed in v6 since I think there is likely to be a v6, and I think I also need to address the commit message nit pointed out by Jan in the last patch.
Kind regards,
Henry
PATCH v5 2/13 xen/arm: Introduce CONFIG_MMU Kconfig option
In reply to Henry WangThere are two types of memory system architectures available for Arm-based systems, namely the Virtual Memory System Architecture (VMSA) and the Protected Memory System Architecture (PMSA). According to ARM DDI 0487G.a, A VMSA provides a Memory Management Unit (MMU) that controls address translation, access permissions, and memory attribute determination and checking, for memory accesses made by the PE. And refer to ARM DDI 0600A.c, the PMSA supports a unified memory protection scheme where an Memory Protection Unit (MPU) manages instruction and data access. Currently, Xen only suuports VMSA.
Introduce a Kconfig option CONFIG_MMU, which is currently default set to y and unselectable because currently only VMSA is supported.
---
v5:
- Only introduce the unselectable CONFIG_MMU, add the 'choice' in future commits.
v4:
- Completely rework "[v3,06/52] xen/arm: introduce CONFIG_HAS_MMU"
--- xen/arch/arm/Kconfig | 3 +++ 1 file changed, 3 insertions(+)
xen/arch/arm/Kconfig +3 -0
@@ -59,6 +59,9 @@ config PADDR_BITS default 40 if ARM_PA_BITS_40 default 48 if ARM_64 +config MMU + def_bool y + source "arch/Kconfig" config ACPI
Signature · 1 line
2.25.1
Re: [PATCH v5 02/13] xen/arm: Introduce CONFIG_MMU Kconfig option
Hi Henry,
Quoted 9 lines · Henry Wang
There are two types of memory system architectures available for Arm-based systems, namely the Virtual Memory System Architecture (VMSA) and the Protected Memory System Architecture (PMSA). According to ARM DDI 0487G.a, A VMSA provides a Memory Management Unit (MMU) that controls address translation, access permissions, and memory attribute determination and checking, for memory accesses made by the PE. And refer to ARM DDI
0600A.c, the PMSA supports a unified memory protection scheme where an Memory Protection Unit (MPU) manages instruction and data access. Currently, Xen only suuports VMSA.
Typo: s/suuports/supports/
Quoted 3 lines
Introduce a
KconfigoptionCONFIG_MMU, which is currently default set to y and unselectable because currently only VMSA is supported.
NIT: It would be worth to explicit mention that this will be used in follow-up patches. So one will wonder what's the goal of introducing an unused config.
Or it could have been merged in the first patch splitting the MMU code so we don't introduce a config without any use.
Quoted 3 lines
Suggested-by Julien Grall <[email protected]>Signed-off-by Henry Wang <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 02/13] xen/arm: Introduce CONFIG_MMU Kconfig option
Hi Julien,
Quoted 15 lines · Julien Grall
Hi Henry,
Quoted 9 lines · Henry Wang
There are two types of memory system architectures available for Arm-based systems, namely the Virtual Memory System Architecture (VMSA) and the Protected Memory System Architecture (PMSA). According to ARM DDI 0487G.a, A VMSA provides a Memory Management Unit (MMU) that controls address translation, access permissions, and memory attribute determination and checking, for memory accesses made by the PE. And refer to ARM DDI
0600A.c, the PMSA supports a unified memory protection scheme where an Memory Protection Unit (MPU) manages instruction and data access. Currently, Xen only suuports VMSA.
Quoted 1 line
Typo: s/suuports/supports/
Oops, sorry about this, will fix in v6.
Quoted 7 lines
Quoted 3 lines
Introduce a
KconfigoptionCONFIG_MMU, which is currently default set to y and unselectable because currently only VMSA is supported.NIT: It would be worth to explicit mention that this will be used in follow-up patches. So one will wonder what's the goal of introducing an unused config.
Or it could have been merged in the first patch splitting the MMU code so we don't introduce a config without any use.
Sure, I will think about this and fix in v6.
Quoted 5 lines
Quoted 3 lines
Suggested-by Julien Grall <[email protected]>Signed-off-by Henry Wang <[email protected]>Acked-by Julien Grall <[email protected]>
Thanks!
Kind regards,
Henry
Quoted 5 lines
Cheers,
Signature · 1 line
Julien Grall
PATCH v5 3/13 xen/arm64: prepare for moving MMU related code from head.S
In reply to Henry WangFrom: Wei Chen <[email protected]>
We want to reuse head.S for MPU systems, but there are some code are implemented for MMU systems only. We will move such code to another MMU specific file. But before that we will do some indentations fix in this patch to make them be easier for reviewing:
1. Fix the indentations and incorrect style of code comments.
2. Fix the indentations for .text.header section.
3. Rename puts() to asm_puts() for global export
---
v5:
- Use "must" in the code comment for asm_puts() to note that this function must be called from assembly.
- Add the Reviewed-by tags from Ayan and Julien.
v4:
- Rebase to pick the adr -> adr_l change in PRINT(_s).
- Correct in-code comment for asm_puts() and add a note to mention that asm_puts() should be only called from assembly.
- Drop redundant puts (now asm_puts) under CONFIG_EARLY_PRINTK. v3:
- fix commit message
- Rename puts() to asm_puts() for global export
v2:
- New patch.
--- xen/arch/arm/arm64/head.S | 46 ++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 22 deletions(-)
xen/arch/arm/arm64/head.S +24 -22
@@ -94,7 +94,7 @@ #define PRINT(_s) \ mov x3, lr ; \ adr_l x0, 98f ; \ - bl puts ; \ + bl asm_puts ; \ mov lr, x3 ; \ RODATA_STR(98, _s)
@@ -148,21 +148,21 @@ isb .endm - .section .text.header, "ax", %progbits - /*.aarch64*/ +.section .text.header, "ax", %progbits +/*.aarch64*/ - /* - * Kernel startup entry point. - * --------------------------- - * - * The requirements are: - * MMU = off, D-cache = off, I-cache = on or off, - * x0 = physical address to the FDT blob. - * - * This must be the very first address in the loaded image. - * It should be linked at XEN_VIRT_START, and loaded at any - * 4K-aligned address. - */ +/* + * Kernel startup entry point. + * --------------------------- + * + * The requirements are: + * MMU = off, D-cache = off, I-cache = on or off, + * x0 = physical address to the FDT blob. + * + * This must be the very first address in the loaded image. + * It should be linked at XEN_VIRT_START, and loaded at any + * 4K-aligned address. + */ GLOBAL(start) /*
@@ -547,7 +547,7 @@ ENDPROC(cpu_init) * Macro to create a mapping entry in \tbl to \phys. Only mapping in 3rd * level table (i.e page granularity) is supported. * - * ptbl: table symbol where the entry will be created + * ptbl: table symbol where the entry will be created * virt: virtual address * phys: physical address (should be page aligned) * tmp1: scratch register
@@ -965,19 +965,22 @@ init_uart: ret ENDPROC(init_uart) -/* Print early debug messages. +/* + * Print early debug messages. + * Note: This function must be called from assembly. * x0: Nul-terminated string to print. * x23: Early UART base address - * Clobbers x0-x1 */ -puts: + * Clobbers x0-x1 + */ +ENTRY(asm_puts) early_uart_ready x23, 1 ldrb w1, [x0], #1 /* Load next char */ cbz w1, 1f /* Exit on nul */ early_uart_transmit x23, w1 - b puts + b asm_puts 1: ret -ENDPROC(puts) +ENDPROC(asm_puts) /* * Print a 64-bit number in hex.
@@ -1007,7 +1010,6 @@ hex: .ascii "0123456789abcdef" ENTRY(early_puts) init_uart: -puts: putn: ret #endif /* !CONFIG_EARLY_PRINTK */
Signature · 1 line
2.25.1
Re: [PATCH v5 03/13] xen/arm64: prepare for moving MMU related code from head.S
Hi Henry,
Quoted 11 lines · Henry Wang
From: Wei Chen <[email protected]>
We want to reuse
head.Sfor MPU systems, but there are some code are implemented for MMU systems only. We will move such code to another MMU specific file. But before that we will do some indentations fix in this patch to make them be easier for reviewing:
1. Fix the indentations and incorrect style of code comments.
2. Fix the indentations for .text.header section.
3. Renameputs()toasm_puts()for global export
Quoted 5 lines
Signed-off-by Wei Chen <[email protected]>Signed-off-by Penny Zheng <[email protected]>Signed-off-by Henry Wang <[email protected]>Reviewed-by Ayan Kumar Halder <[email protected]>Reviewed-by Julien Grall <[email protected]>
Is this patch depends on the first two? If not, I will commit it before v6.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 03/13] xen/arm64: prepare for moving MMU related code from head.S
Hi Julien,
Quoted 20 lines · Julien Grall
Hi Henry,
Quoted 9 lines · Henry Wang
From: Wei Chen <[email protected]>
We want to reusehead.Sfor MPU systems, but there are some code are implemented for MMU systems only. We will move such code to another MMU specific file. But before that we will do some indentations fix in this patch to make them be easier for reviewing:
1. Fix the indentations and incorrect style of code comments.
2. Fix the indentations for .text.header section.
3. Renameputs()toasm_puts()for global exportQuoted 5 lines
Signed-off-by Wei Chen <[email protected]>Signed-off-by Penny Zheng <[email protected]>Signed-off-by Henry Wang <[email protected]>Reviewed-by Ayan Kumar Halder <[email protected]>Reviewed-by Julien Grall <[email protected]>
Quoted 1 line
Is this patch depends on the first two? If not, I will commit it before v6.
Good point, no this patch is independent from the first two. Also I just tested applying this patch on top of staging and building with and without Earlyprintk. Xen and Dom0 boot fine on FVP for both cases.
So please commit this patch if you have time. Thanks!
Kind regards,
Henry
Quoted 5 lines
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 03/13] xen/arm64: prepare for moving MMU related code from head.S
Hi Henry,
Quoted 17 lines · Henry Wang
Quoted 17 lines · Julien Grall
Quoted 14 lines · Henry Wang
From: Wei Chen <[email protected]>
We want to reusehead.Sfor MPU systems, but there are some code are implemented for MMU systems only. We will move such code to another MMU specific file. But before that we will do some indentations fix in this patch to make them be easier for reviewing:
1. Fix the indentations and incorrect style of code comments.
2. Fix the indentations for .text.header section.
3. Renameputs()toasm_puts()for global exportSigned-off-by Wei Chen <[email protected]>Signed-off-by Penny Zheng <[email protected]>Signed-off-by Henry Wang <[email protected]>Reviewed-by Ayan Kumar Halder <[email protected]>Reviewed-by Julien Grall <[email protected]>
Quoted 5 lines
Quoted 1 line
Is this patch depends on the first two? If not, I will commit it before v6.
Good point, no this patch is independent from the first two. Also I just tested applying this patch on top of staging and building with and without Earlyprintk. Xen and Dom0 boot fine on FVP for both cases.
Thanks for confirming. It is now ...
Quoted 2 lines
So please commit this patch if you have time. Thanks!
... committed.
Cheers,
Signature · 1 line
Julien Grall
PATCH v5 4/13 xen/arm64: Split and move MMU-specific head.S to mmu/head.S
In reply to Henry WangThe MMU specific code in head.S will not be used on MPU systems. Instead of introducing more #ifdefs which will bring complexity to the code, move MMU related code to mmu/head.S and keep common code in head.S. Two notes while moving:
- As "fail" in original head.S is very simple and this name is too easy to be conflicted, duplicate it in mmu/head.S instead of exporting it.
- Use ENTRY() for enable_secondary_cpu_mm, enable_boot_cpu_mm and setup_fixmap to please the compiler after the code movement.
Also move the assembly macros shared by head.S and mmu/head.S to macros.h.
Note that, only the first 4KB of Xen image will be mapped as identity (PA == VA). At the moment, Xen guarantees this by having everything that needs to be used in the identity mapping in .text.header section of head.S, and the size will be checked by _idmap_start and _idmap_end at link time if this fits in 4KB. Since we are introducing a new head.S in this patch, although we can add .text.header to the new file to guarantee all identity map code still in the first 4KB. However, the order of these two files on this 4KB depends on the build toolchains. Hence, introduce a new section named .text.idmap in the region between _idmap_start and _idmap_end. And in Xen linker script, we force the .text.idmap contents to linked after .text.header. This will ensure code of head.S always be at the top of Xen binary.
---
v5:
- Rebase on top of commit
"xen/arm64: head: Introduce a helper to flush local TLBs".
v4:
- Rework "[v3,08/52] xen/arm64: move MMU related code from head.S to mmu/head.S"
- Don't move the "yet to shared" macro such as print_reg.
- Fold "[v3,04/52] xen/arm: add .text.idmap in ld script for Xen identity map sections" to this patch. Rework commit msg.
--- xen/arch/arm/arm64/Makefile | 1 + xen/arch/arm/arm64/head.S | 492 +----------------------- xen/arch/arm/arm64/mmu/Makefile | 1 + xen/arch/arm/arm64/mmu/head.S | 488 +++++++++++++++++++++++ xen/arch/arm/include/asm/arm64/macros.h | 36 ++ xen/arch/arm/xen.lds.S | 1 + 6 files changed, 528 insertions(+), 491 deletions(-) create mode 100644 xen/arch/arm/arm64/mmu/Makefile create mode 100644 xen/arch/arm/arm64/mmu/head.S
xen/arch/arm/arm64/Makefile +1 -0
@@ -1,4 +1,5 @@ obj-y += lib/ +obj-$(CONFIG_MMU) += mmu/ obj-y += cache.o obj-y += cpufeature.o
xen/arch/arm/arm64/head.S +1 -491
527 lines not on this page · raw message
xen/arch/arm/arm64/mmu/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += head.o
xen/arch/arm/arm64/mmu/head.S new file +488 -0
488 lines not on this page · raw message
xen/arch/arm/include/asm/arm64/macros.h +36 -0
@@ -32,6 +32,42 @@ hint #22 .endm +#ifdef CONFIG_EARLY_PRINTK +/* +* Macro to print a string to the UART, if there is one. +* +* Clobbers x0 - x3 +*/ +#define #else /* CONFIG_EARLY_PRINTK */ +#define #endif /* !CONFIG_EARLY_PRINTK */ + +/* +* Pseudo-op for PC relative adr <reg>, <symbol> where <symbol> is +* within the range +/- 4GB of the PC. +* +* @dst: destination register (64 bit wide) +* @sym: name of the symbol +*/ +.macro adr_l, dst, sym + adrp \dst, \sym + add \dst, \dst, :lo12:\sym +.endm + +/* Load the physical address of a symbol into xb */ +.macro load_paddr xb, sym + ldr \xb, =\sym + add \xb, \xb, x20 +.endm +/* * Register aliases. */
xen/arch/arm/xen.lds.S +1 -0
@@ -34,6 +34,7 @@ SECTIONS _stext = .; /* Text section */ _idmap_start = .; *(.text.header) + *(.text.idmap) _idmap_end = .; *(.text.cold)
Signature · 1 line
2.25.1
Re: [PATCH v5 04/13] xen/arm64: Split and move MMU-specific head.S to mmu/head.S
Hi Henry,
Quoted 9 lines · Henry Wang
The MMU specific code in
head.Swill not be used on MPU systems. Instead of introducing more #ifdefs which will bring complexity to the code, move MMU related code tommu/head.Sand keep common code inhead.S. Two notes while moving:
- As "fail" in originalhead.Sis very simple and this name is too easy to be conflicted, duplicate it inmmu/head.Sinstead of exporting it.
- UseENTRY()forenable_secondary_cpu_mm,enable_boot_cpu_mmandsetup_fixmapto please the compiler after the code movement.
I am not sure I understand why you are saying "to please the compiler" here. Isn't it necessary for the linker (not the compiler) to find the function? And therefore there is no pleasing (as in this is not a bug in the toolchain).
Other than that, the split looks good to me.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 04/13] xen/arm64: Split and move MMU-specific head.S to mmu/head.S
Hi Julien,
Quoted 15 lines · Julien Grall
Hi Henry,
Quoted 9 lines · Henry Wang
The MMU specific code in
head.Swill not be used on MPU systems. Instead of introducing more #ifdefs which will bring complexity to the code, move MMU related code tommu/head.Sand keep common code inhead.S. Two notes while moving:
- As "fail" in originalhead.Sis very simple and this name is too easy to be conflicted, duplicate it inmmu/head.Sinstead of exporting it.
- UseENTRY()forenable_secondary_cpu_mm,enable_boot_cpu_mmandsetup_fixmapto please the compiler after the code movement.
Quoted 1 line
I am not sure I understand why you are saying "to please the compiler" here. Isn't it necessary for the linker (not the compiler) to find the function? And therefore there is no pleasing (as in this is not a bug in the toolchain).
Yes it meant to be linker, sorry for the confusion. What I want to express is without the ENTRY(), for example if we remove the ENTRY() around the setup_fixmap(), we will have:
``` aarch64-none-linux-gnu-ld: prelink.o: in function `primary_switched': /home/xinwan02/repos_for_development/xen_playground/xen/xen/arch/arm/arm64/head.S:278: undefined reference to `setup_fixmap' /home/xinwan02/repos_for_development/xen_playground/xen/xen/arch/arm/arm64/head.S:278:(.text.header+0x1a0): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `setup_fixmap' make[2]: *** [arch/arm/Makefile:95: xen-syms] Error 1 make[1]: *** [build.mk:90: xen] Error 2 make: *** [Makefile:598: xen] Error 2 ```
I will use the word “linker” in v6 if you agree.
Quoted 2 lines
Other than that, the split looks good to me.
May I please take this as a Reviewed-by tag? I will add the tag if you are happy with that.
Kind regards,
Henry
Quoted 5 lines
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 04/13] xen/arm64: Split and move MMU-specific head.S to mmu/head.S
Quoted 27 lines · Henry Wang
Quoted 12 lines · Julien Grall
Quoted 9 lines · Henry Wang
The MMU specific code in
head.Swill not be used on MPU systems. Instead of introducing more #ifdefs which will bring complexity to the code, move MMU related code tommu/head.Sand keep common code inhead.S. Two notes while moving:
- As "fail" in originalhead.Sis very simple and this name is too easy to be conflicted, duplicate it inmmu/head.Sinstead of exporting it.
- UseENTRY()forenable_secondary_cpu_mm,enable_boot_cpu_mmandsetup_fixmapto please the compiler after the code movement.Quoted 1 line
I am not sure I understand why you are saying "to please the compiler" here. Isn't it necessary for the linker (not the compiler) to find the function? And therefore there is no pleasing (as in this is not a bug in the toolchain).
Yes it meant to be linker, sorry for the confusion. What I want to express is without the
ENTRY(), for example if we remove theENTRY()around thesetup_fixmap(), we will have:``` aarch64-none-linux-gnu-ld: prelink.o: in function `primary_switched': /home/xinwan02/repos_for_development/xen_playground/xen/xen/arch/arm/arm64/head.S:278: undefined reference to `setup_fixmap' /home/xinwan02/repos_for_development/xen_playground/xen/xen/arch/arm/arm64/head.S:278:(.text.header+0x1a0): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `setup_fixmap' make[2]: *** [arch/arm/Makefile:95: xen-syms] Error 1 make[1]: *** [build.mk:90: xen] Error 2 make: *** [Makefile:598: xen] Error 2 ```
Quoted 1 line
I will use the word “linker” in v6 if you agree.
The sentence also need to be reworded. How about:
"Use ENTRY() for ... as they will be used externally."
Quoted 6 lines
Quoted 3 lines
Other than that, the split looks good to me.
May I please take this as a Reviewed-by tag? I will add the tag if you are happy with that.
Sure. Reviewed-by: Julien Grall <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 04/13] xen/arm64: Split and move MMU-specific head.S to mmu/head.S
Hi Julien,
Quoted 28 lines · Julien Grall
Quoted 24 lines · Henry Wang
Quoted 12 lines · Julien Grall
Quoted 9 lines · Henry Wang
The MMU specific code in
head.Swill not be used on MPU systems. Instead of introducing more #ifdefs which will bring complexity to the code, move MMU related code tommu/head.Sand keep common code inhead.S. Two notes while moving:
- As "fail" in originalhead.Sis very simple and this name is too easy to be conflicted, duplicate it inmmu/head.Sinstead of exporting it.
- UseENTRY()forenable_secondary_cpu_mm,enable_boot_cpu_mmandsetup_fixmapto please the compiler after the code movement.Quoted 1 line
I am not sure I understand why you are saying "to please the compiler" here. Isn't it necessary for the linker (not the compiler) to find the function? And therefore there is no pleasing (as in this is not a bug in the toolchain).
Yes it meant to be linker, sorry for the confusion. What I want to express is without the
ENTRY(), for example if we remove theENTRY()around thesetup_fixmap(), we will have:``` aarch64-none-linux-gnu-ld: prelink.o: in function `primary_switched': /home/xinwan02/repos_for_development/xen_playground/xen/xen/arch/arm/arm64/head.S:278: undefined reference to `setup_fixmap' /home/xinwan02/repos_for_development/xen_playground/xen/xen/arch/arm/arm64/head.S:278:(.text.header+0x1a0): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `setup_fixmap' make[2]: *** [arch/arm/Makefile:95: xen-syms] Error 1 make[1]: *** [build.mk:90: xen] Error 2 make: *** [Makefile:598: xen] Error 2 ```Quoted 1 line
I will use the word “linker” in v6 if you agree.
Quoted 3 lines
The sentence also need to be reworded. How about:
"Use
ENTRY()for ... as they will be used externally."
Sure, I will use the suggested sentence.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Other than that, the split looks good to me.
May I please take this as a Reviewed-by tag? I will add the tag if you are happy with that.
Sure. Reviewed-by: Julien Grall <[email protected]>
Thanks!
Kind regards,
Henry
Quoted 5 lines
Cheers,
Signature · 1 line
Julien Grall
PATCH v5 5/13 xen/arm: Move MMU related definitions from config.h to mmu/layout.h
In reply to Henry WangFrom: Wei Chen <[email protected]>
Xen defines some global configuration macros for Arm in config.h. However there are some address layout related definitions that are defined for MMU systems only, and these definitions could not be used by MPU systems. Adding ifdefs to differentiate the MPU from MMU layout will result in a messy and hard-to-read/maintain code.
So move all memory layout definitions to a new file, i.e. mmu/layout.h to avoid spreading "#ifdef" everywhere.
---
v5:
- Rework commit message.
- Add Reviewed-by tag from Julien
v4:
- Rebase on top of latest staging to pick the recent UBSAN change to the layout.
- Use #ifdef CONFIG_HAS_MMU instead of #ifndef CONFIG_HAS_MPU, add a #else case.
- Rework commit message.
v3:
- name the new header layout.h
v2:
- Remove duplicated FIXMAP definitions from config_mmu.h
--- xen/arch/arm/include/asm/config.h | 132 +---------------------- xen/arch/arm/include/asm/mmu/layout.h | 146 ++++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 129 deletions(-) create mode 100644 xen/arch/arm/include/asm/mmu/layout.h
xen/arch/arm/include/asm/config.h +3 -129
@@ -71,136 +71,10 @@#include <xen/const.h> #include <xen/page-size.h> -/* -* ARM32 layout: -* 0 - 2M Unmapped -* 2M - 10M Xen text, data, bss -* 10M - 12M Fixmap: special-purpose 4K mapping slots -* 12M - 16M Early boot mapping of FDT -* 16M - 18M Livepatch vmap (if compiled in) -* -* 32M - 128M Frametable: 32 bytes per page for 12GB of RAM -* 256M - 1G VMAP: ioremap and early_ioremap use this virtual address -* space -* -* 1G - 2G Xenheap: always-mapped memory -* 2G - 4G Domheap: on-demand-mapped -* -* ARM64 layout: -* 0x0000000000000000 - 0x000001ffffffffff (2TB, L0 slots [0..3]) -* -* Reserved to identity map Xen -* -* 0x0000020000000000 - 0x0000027fffffffff (512GB, L0 slot [4]) -* (Relative offsets) -* 0 - 2M Unmapped -* 2M - 10M Xen text, data, bss -* 10M - 12M Fixmap: special-purpose 4K mapping slots -* 12M - 16M Early boot mapping of FDT -* 16M - 18M Livepatch vmap (if compiled in) -* -* 1G - 2G VMAP: ioremap and early_ioremap -* -* 32G - 64G Frametable: 56 bytes per page for 2TB of RAM -* -* 0x0000028000000000 - 0x00007fffffffffff (125TB, L0 slots [5..255]) -* Unused -* -* 0x0000800000000000 - 0x000084ffffffffff (5TB, L0 slots [256..265]) -* 1:1 mapping of RAM -* -* 0x0000850000000000 - 0x0000ffffffffffff (123TB, L0 slots [266..511]) -* Unused -*/ - -#ifdef CONFIG_ARM_32 -#define XEN_VIRT_START _AT(vaddr_t, MB(2)) +#ifdef CONFIG_MMU +#include <asm/mmu/layout.h> #else - -#define SLOT0_ENTRY_BITS 39 -#define SLOT0 (slot) (_AT(vaddr_t,slot) << SLOT0_ENTRY_BITS) -#define SLOT0_ENTRY_SIZE SLOT0(1) - -#define XEN_VIRT_START (SLOT0(4) + _AT(vaddr_t, MB(2))) -#endif - -/* -* Reserve enough space so both UBSAN and GCOV can be enabled together -* plus some slack for future growth. -*/ -#define XEN_VIRT_SIZE _AT(vaddr_t, MB(8)) -#define XEN_NR_ENTRIES (lvl) (XEN_VIRT_SIZE / XEN_PT_LEVEL_SIZE(lvl)) - -#define FIXMAP_VIRT_START (XEN_VIRT_START + XEN_VIRT_SIZE) -#define FIXMAP_VIRT_SIZE _AT(vaddr_t, MB(2)) - -#define FIXMAP_ADDR (n) (FIXMAP_VIRT_START + (n) * PAGE_SIZE) - -#define BOOT_FDT_VIRT_START (FIXMAP_VIRT_START + FIXMAP_VIRT_SIZE) -#define BOOT_FDT_VIRT_SIZE _AT(vaddr_t, MB(4)) - -#ifdef CONFIG_LIVEPATCH -#define LIVEPATCH_VMAP_START (BOOT_FDT_VIRT_START + BOOT_FDT_VIRT_SIZE) -#define LIVEPATCH_VMAP_SIZE _AT(vaddr_t, MB(2)) -#endif - -#define HYPERVISOR_VIRT_START XEN_VIRT_START - -#ifdef CONFIG_ARM_32 - -#define CONFIG_SEPARATE_XENHEAP 1 - -#define FRAMETABLE_VIRT_START _AT(vaddr_t, MB(32)) -#define FRAMETABLE_SIZE MB(128-32) -#define FRAMETABLE_NR (FRAMETABLE_SIZE / sizeof(*frame_table)) - -#define VMAP_VIRT_START _AT(vaddr_t, MB(256)) -#define VMAP_VIRT_SIZE _AT(vaddr_t, GB(1) - MB(256)) - -#define XENHEAP_VIRT_START _AT(vaddr_t, GB(1)) -#define XENHEAP_VIRT_SIZE _AT(vaddr_t, GB(1)) - -#define DOMHEAP_VIRT_START _AT(vaddr_t, GB(2)) -#define DOMHEAP_VIRT_SIZE _AT(vaddr_t, GB(2)) - -#define DOMHEAP_ENTRIES 1024/* 1024 2MB mapping slots */ - -/* Number of domheap pagetable pages required at the second level (2MB mappings) */ -#define DOMHEAP_SECOND_PAGES (DOMHEAP_VIRT_SIZE >> FIRST_SHIFT) - -/* -* The temporary area is overlapping with the domheap area. This may -* be used to create an alias of the first slot containing Xen mappings -* when turning on/off the MMU. -*/ -#define TEMPORARY_AREA_FIRST_SLOT (first_table_offset(DOMHEAP_VIRT_START)) - -/* Calculate the address in the temporary area */ -#define TEMPORARY_AREA_ADDR (addr) \ - (((addr) & ~XEN_PT_LEVEL_MASK(1)) | \ - (TEMPORARY_AREA_FIRST_SLOT << XEN_PT_LEVEL_SHIFT(1))) - -#define TEMPORARY_XEN_VIRT_START TEMPORARY_AREA_ADDR(XEN_VIRT_START) - -#else /* ARM_64 */ - -#define IDENTITY_MAPPING_AREA_NR_L0 4 - -#define VMAP_VIRT_START (SLOT0(4) + GB(1)) -#define VMAP_VIRT_SIZE GB(1) - -#define FRAMETABLE_VIRT_START (SLOT0(4) + GB(32)) -#define FRAMETABLE_SIZE GB(32) -#define FRAMETABLE_NR (FRAMETABLE_SIZE / sizeof(*frame_table)) - -#define DIRECTMAP_VIRT_START SLOT0(256) -#define DIRECTMAP_SIZE (SLOT0_ENTRY_SIZE * (266 - 256)) -#define DIRECTMAP_VIRT_END (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE - 1) - -#define XENHEAP_VIRT_START directmap_virt_start - -#define HYPERVISOR_VIRT_END DIRECTMAP_VIRT_END - +# error "Unknown memory management layout"#endif #define NR_hypercalls 64
xen/arch/arm/include/asm/mmu/layout.h new file +146 -0
146 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v5 6/13 xen/arm64: Fold setup_fixmap() to create_page_tables()
In reply to Henry WangThe original assembly setup_fixmap() is actually doing two seperate tasks, one is enabling the early UART when earlyprintk on, and the other is to set up the fixmap (even when earlyprintk is off).
Per discussion in [1], since commit9d267c049d92 ("xen/arm64: Rework the memory layout"), there is no chance that the fixmap and the mapping of early UART will clash with the 1:1 mapping. Therefore the mapping of both the fixmap and the early UART can be moved to the end of create_pagetables().
No functional change intended.
[1] https://lore.kernel.org/xen-devel/[email protected]/
---
v5:
- Refine the title and commit message.
- Drop the "not applied" in-code comment about the 1:1 mapping clash on top of create_page_tables().
- Drop the unnecessary dsb and isb from the original setup_fixmap(). v4:
- Rework "[v3,12/52] xen/mmu: extract early uart mapping from setup_fixmap"
--- xen/arch/arm/arm64/head.S | 1 - xen/arch/arm/arm64/mmu/head.S | 48 ++++++++--------------------------- 2 files changed, 10 insertions(+), 39 deletions(-)
xen/arch/arm/arm64/head.S +0 -1
@@ -275,7 +275,6 @@ real_start_efi: b enable_boot_cpu_mm primary_switched: - bl setup_fixmap #ifdef CONFIG_EARLY_PRINTK /* Use a virtual address to access the UART. */ ldr x23, =EARLY_UART_VIRTUAL_ADDRESS
xen/arch/arm/arm64/mmu/head.S +10 -38
66 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v5 06/13] xen/arm64: Fold setup_fixmap() to create_page_tables()
Hi Henry,
Quoted 11 lines · Henry Wang
The original assembly
setup_fixmap()is actually doing two seperate tasks, one is enabling the early UART when earlyprintk on, and the other is to set up the fixmap (even when earlyprintk is off).Per discussion in [1], since commit
9d267c049d92("xen/arm64: Rework the memory layout"), there is no chance that the fixmap and the mapping of early UART will clash with the 1:1 mapping. Therefore the mapping of both the fixmap and the early UART can be moved to the end ofcreate_pagetables().No functional change intended.
I would drop this sentence because the fixmap is now prepared much earlier in the code. So there is technically some functional change.
Quoted 4 lines
[1] https://lore.kernel.org/xen-devel/[email protected]/
Signed-off-by Henry Wang <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 06/13] xen/arm64: Fold setup_fixmap() to create_page_tables()
Quoted 17 lines · Julien Grall
Hi Henry,
Quoted 9 lines · Henry Wang
The original assembly
setup_fixmap()is actually doing two seperate tasks, one is enabling the early UART when earlyprintk on, and the other is to set up the fixmap (even when earlyprintk is off). Per discussion in [1], since commit9d267c049d92("xen/arm64: Rework the memory layout"), there is no chance that the fixmap and the mapping of early UART will clash with the 1:1 mapping. Therefore the mapping of both the fixmap and the early UART can be moved to the end ofcreate_pagetables(). No functional change intended.
Quoted 1 line
I would drop this sentence because the fixmap is now prepared much earlier in the code. So there is technically some functional change.
Sure, I will drop this sentence in v6.
Quoted 5 lines
Quoted 3 lines
[1] https://lore.kernel.org/xen-devel/[email protected]/
Signed-off-by Henry Wang <[email protected]>Reviewed-by Julien Grall <[email protected]>
Thanks!
Kind regards,
Henry
Quoted 5 lines
Cheers,
Signature · 1 line
Julien Grall
PATCH v5 7/13 xen/arm: Extract MMU-specific code
In reply to Henry WangCurrently, most of the MMU-specific code is in mm.{c,h}. To make the mm extendable, this commit extract the MMU-specific code by firstly:
- Create a arch/arm/include/asm/mmu/ subdir.
- Create a arch/arm/mmu/ subdir.
Then move the MMU-specific code to above mmu subdir, which includes below changes:
- Move arch/arm/arm64/mm.c to arch/arm/arm64/mmu/mm.c
- Move MMU-related declaration in arch/arm/include/asm/mm.h to arch/arm/include/asm/mmu/mm.h
- Move the MMU-related declaration dump_pt_walk() in asm/page.h and pte_of_xenaddr() in asm/setup.h to the new asm/mmu/mm.h.
- Move MMU-related code in arch/arm/mm.c to arch/arm/mmu/mm.c.
Also modify the build system (Makefiles in this case) to pick above mentioned code changes.
This patch is a pure code movement, no functional change intended.
---
With the code movement of this patch, the descriptions on top of xen/arch/arm/mm.c and xen/arch/arm/mmu/mm.c might need some changes, suggestions?
v5:
- Rebase on top of xen/arm: Introduce CONFIG_MMU Kconfig option and xen/arm: mm: add missing extern variable declaration
v4:
- Rework "[v3,13/52] xen/mmu: extract mmu-specific codes from mm.c/mm.h" with the lastest staging branch, only do the code movement in this patch to ease the review.
---
xen/arch/arm/Makefile | 1 +
xen/arch/arm/arm64/Makefile | 1 -
xen/arch/arm/arm64/mmu/Makefile | 1 +
xen/arch/arm/arm64/{ => mmu}/mm.c | 0
xen/arch/arm/include/asm/mm.h | 20 +-
xen/arch/arm/include/asm/mmu/mm.h | 55 ++
xen/arch/arm/include/asm/page.h | 15 -
xen/arch/arm/include/asm/setup.h | 3 -
xen/arch/arm/mm.c | 1119 ----------------------------
xen/arch/arm/mmu/Makefile | 1 +
xen/arch/arm/mmu/mm.c | 1146 +++++++++++++++++++++++++++++
11 files changed, 1208 insertions(+), 1154 deletions(-)
rename xen/arch/arm/arm64/{ => mmu}/mm.c (100%)
create mode 100644 xen/arch/arm/include/asm/mmu/mm.h
create mode 100644 xen/arch/arm/mmu/Makefile
create mode 100644 xen/arch/arm/mmu/mm.cxen/arch/arm/Makefile +1 -0
@@ -1,6 +1,7 @@ obj-$(CONFIG_ARM_32) += arm32/ obj-$(CONFIG_ARM_64) += arm64/ obj-$(CONFIG_ACPI) += acpi/ +obj-$(CONFIG_MMU) += mmu/ obj-$(CONFIG_HAS_PCI) += pci/ ifneq ($(CONFIG_NO_PLAT),y) obj-y += platforms/
xen/arch/arm/arm64/Makefile +0 -1
@@ -11,7 +11,6 @@ obj-y += entry.o obj-y += head.o obj-y += insn.o obj-$(CONFIG_LIVEPATCH) += livepatch.o -obj-y += mm.o obj-y += smc.o obj-y += smpboot.o obj-$(CONFIG_ARM64_SVE) += sve.o sve-asm.o
xen/arch/arm/arm64/mmu/Makefile +1 -0
@@ -1 +1,2 @@ obj-y += head.o +obj-y += mm.o
xen/arch/arm/arm64/mmu/mm.c renamed from xen/arch/arm/arm64/mm.c +0 -0
xen/arch/arm/include/asm/mm.h +4 -16
@@ -14,6 +14,10 @@# error "unknown ARM variant"#endif +#ifdef CONFIG_MMU +#include <asm/mmu/mm.h> +#endif +/* Align Xen to a 2 MiB boundary. */ #define XEN_PADDR_ALIGN (1 << 21)
@@ -168,13 +172,6 @@ struct page_info/* Non-boot CPUs use this to find the correct pagetables. */ extern uint64_t init_ttbr; -extern mfn_t directmap_mfn_start, directmap_mfn_end; -extern vaddr_t directmap_virt_end; -#ifdef CONFIG_ARM_64 -extern vaddr_t directmap_virt_start; -extern unsigned long directmap_base_pdx; -#endif -#ifdef CONFIG_ARM_32 #define is_xen_heap_page (page) is_xen_heap_mfn(page_to_mfn(page))#define is_xen_heap_mfn (mfn) ({ \
@@ -197,7 +194,6 @@ extern unsigned long directmap_base_pdx;#define maddr_get_owner (ma) (page_get_owner(maddr_to_page((ma)))) -#define frame_table ((struct page_info *)FRAMETABLE_VIRT_START)/* PDX of the first page in the frame table. */ extern unsigned long frametable_base_pdx;
@@ -207,8 +203,6 @@ extern unsigned long frametable_base_pdx;extern void setup_pagetables (unsigned long boot_phys_offset);/* Map FDT in boot pagetable */ extern void *early_fdt_map (paddr_t fdt_paddr); -/* Switch to a new root page-tables */ -extern void switch_ttbr (uint64_t ttbr);/* Remove early mappings */ extern void remove_early_mappings (void );/* Allocate and initialise pagetables for a secondary CPU. Sets init_ttbr to the
@@ -216,12 +210,6 @@ extern void remove_early_mappings(void);extern int init_secondary_pagetables (int cpu);/* Switch secondary CPUS to its own pagetables and finalise MMU setup */ extern void mmu_init_secondary_cpu (void ); -/* -* For Arm32, set up the direct-mapped xenheap: up to 1GB of contiguous, -* always-mapped memory. Base must be 32MB aligned and size a multiple of 32MB. -* For Arm64, map the region in the directmap area. -*/ -extern void setup_directmap_mappings (unsigned long base_mfn,unsigned long nr_mfns);/* Map a frame table to cover physical addresses ps through pe */ extern void setup_frametable_mappings (paddr_t ps,paddr_t pe);/* map a physical range in virtual memory */
xen/arch/arm/include/asm/mmu/mm.h new file +55 -0
55 lines not on this page · raw message
xen/arch/arm/include/asm/page.h +0 -15
@@ -257,21 +257,6 @@ static inline void write_pte(lpae_t *p, lpae_t pte)/* Flush the dcache for an entire page. */ void flush_page_to_ram (unsigned long mfn,bool sync_icache); -/* -* Print a walk of a page table or p2m -* -* ttbr is the base address register (TTBR0_EL2 or VTTBR_EL2) -* addr is the PA or IPA to translate -* root_level is the starting level of the page table -* (e.g. TCR_EL2.SL0 or VTCR_EL2.SL0 ) -* nr_root_tables is the number of concatenated tables at the root. -* this can only be != 1 for P2M walks starting at the first or -* subsequent level. -*/ -void dump_pt_walk (paddr_t ttbr,paddr_t addr, -unsigned int root_level, -unsigned int nr_root_tables); -/* Print a walk of the hypervisor's page tables for a virtual addr. */ extern void dump_hyp_walk (vaddr_t addr);/* Print a walk of the p2m for a domain for a physical address. */
xen/arch/arm/include/asm/setup.h +0 -3
@@ -176,9 +176,6 @@ extern lpae_t boot_first_id[XEN_PT_LPAE_ENTRIES];extern lpae_t boot_second_id[XEN_PT_LPAE_ENTRIES ];extern lpae_t boot_third_id[XEN_PT_LPAE_ENTRIES ]; -/* Find where Xen will be residing at runtime and return a PT entry */ -lpae_t pte_of_xenaddr (vaddr_t ); -extern const char __ro_after_init_start[], __ro_after_init_end[];struct init_info
xen/arch/arm/mm.c +0 -1119
1,166 lines not on this page · raw message
xen/arch/arm/mmu/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += mm.o
xen/arch/arm/mmu/mm.c new file +1146 -0
1,146 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v5 07/13] xen/arm: Extract MMU-specific code
Hi Henry,
Quoted 11 lines · Henry Wang
Currently, most of the MMU-specific code is in mm.{c,h}. To make the mm extendable, this commit extract the MMU-specific code by firstly:
- Create aarch/arm/include/asm/mmu/subdir.
- Create aarch/arm/mmu/subdir.Then move the MMU-specific code to above mmu subdir, which includes below changes:
- Movearch/arm/arm64/mm.ctoarch/arm/arm64/mmu/mm.c
- Move MMU-related declaration inarch/arm/include/asm/mm.htoarch/arm/include/asm/mmu/mm.h
- Move the MMU-related declarationdump_pt_walk()inasm/page.h
While I agree that dump_pt_walk() is better to be defined in mm.h, I am not entirely sure for ...
Quoted 1 line
and
pte_of_xenaddr()inasm/setup.hto the newasm/mmu/mm.h.
... pte_of_xenaddr(). It was defined in setup.h because this is an helper that is only intended to be used during early boot.
That said, it is probably not worth creating a new helper for that. So I would suggest to at least mark pte_of_xenaddr() __init to make clear of the intended usage.
Quoted 19 lines
- Move MMU-related code in
arch/arm/mm.ctoarch/arm/mmu/mm.c.Also modify the build system (Makefiles in this case) to pick above mentioned code changes.
This patch is a pure code movement, no functional change intended.
Signed-off-by Henry Wang <[email protected]>---
With the code movement of this patch, the descriptions on top ofxen/arch/arm/mm.candxen/arch/arm/mmu/mm.cmight need some changes, suggestions?
v5:
- Rebase on top of xen/arm: IntroduceCONFIG_MMUKconfigoption and xen/arm: mm: add missing extern variable declaration
v4:
- Rework "[v3,13/52] xen/mmu: extract mmu-specific codes frommm.c/mm.h" with the lastest staging branch, only do the code movement in this patch to ease the review.
Quoted 12 lines
---
xen/arch/arm/Makefile | 1 +
xen/arch/arm/arm64/Makefile | 1 -
xen/arch/arm/arm64/mmu/Makefile | 1 +
xen/arch/arm/arm64/{ => mmu}/mm.c | 0
xen/arch/arm/include/asm/mm.h | 20 +-
xen/arch/arm/include/asm/mmu/mm.h | 55 ++
xen/arch/arm/include/asm/page.h | 15 -
xen/arch/arm/include/asm/setup.h | 3 -
xen/arch/arm/mm.c | 1119 ----------------------------
xen/arch/arm/mmu/Makefile | 1 +
xen/arch/arm/mmu/mm.c | 1146 +++++++++++++++++++++++++++++I noticed you transferred everything in mm.c But I think some part could go in arm{32,64}/mmu/mm.c.
Quoted 5 lines
11 files changed, 1208 insertions(+), 1154 deletions(-)rename xen/arch/arm/arm64/{ =>
mmu}/mm.c(100%) create mode 100644xen/arch/arm/include/asm/mmu/mm.hcreate mode 100644 xen/arch/arm/mmu/Makefile create mode 100644xen/arch/arm/mmu/mm.c
(I haven't checked if the code was moved correctly. I only checked if the split makes sense).
To ease the review, I think this patch can be split in a more piecemeal patches. The first two pieces would be :
* Patch #1 transfer xen_pt_update()/dump_pt_walk() and their dependencies
* Patch #2 transfer root page-table allocation
Then you can have some for each small functions.
[...]
Quoted 9 lines
xen/arch/arm/arm64/mmu/mm.c renamed from xen/arch/arm/arm64/mm.c +0
-0xen/arch/arm/include/asm/mm.h +0
-0
xen/arch/arm/include/asm/mm.h line 18
Quoted 5 lines
xen/arch/arm/include/asm/mm.h +2
-0@@ -14,6 +14,10 @@# error "unknown ARM variant"#endif +#ifdef CONFIG_MMU +#include <asm/mmu/mm.h>
I am guessing you will need to include <asm/mpu/mm.h> at some point. So I would add a:
#else
# error "Unknown memory management layout"
This would be easier to find out where includes might be missing.
[...]
Quoted 4 lines
xen/arch/arm/include/asm/mm.h +0
-0@@ -1233,11 +119,6 @@ int map_pages_to_xen(unsigned long virt,return xen_pt_update (virt, mfn, nr_mfns, flags); }
[...]
xen/arch/arm/include/asm/mm.h
Quoted 7 lines
xen/arch/arm/include/asm/mm.h +7
-0+/* MMU setup for secondary CPUS (which already have paging enabled) */ +void mmu_init_secondary_cpu (void ) +{ +xen_pt_enforce_wnx (); +} + +#ifdef CONFIG_ARM_32
Rather than #ifdef, I would prefer if we move each implementation to arm32/mmu/mm.c and ...
Quoted 11 lines
xen/arch/arm/include/asm/mm.h +11
-0+/* +* Set up the direct-mapped xenheap: +* up to 1GB of contiguous, always-mapped memory. +*/ +void __init setup_directmap_mappings (unsigned long base_mfn, +unsigned long nr_mfns) +{ +int rc; + + rc =map_pages_to_xen (XENHEAP_VIRT_START ,_mfn (base_mfn), nr_mfns, +PAGE_HYPERVISOR_RW | _PAGE_BLOCK);
xen/arch/arm/include/asm/mm.h
Quoted 10 lines
xen/arch/arm/include/asm/mm.h +10
-0+if ( rc ) +panic ("Unable to setup the directmap mappings.\n" ); + +/* Record where the directmap is, for translation routines. */ + directmap_virt_end = XENHEAP_VIRT_START + nr_mfns * PAGE_SIZE; +} +#else /* CONFIG_ARM_64 */ +/* Map the region in the directmap area. */ +void __init setup_directmap_mappings (unsigned long base_mfn, +unsigned long nr_mfns)
... arm64/mmu/mm.c.
Quoted 27 lines
xen/arch/arm/include/asm/mm.h +27
-0+{ +int rc; + +/* First call sets the directmap physical and virtual offset. */ +if (mfn_eq (directmap_mfn_start,INVALID_MFN ) ) + { +unsigned long mfn_gb = base_mfn & ~((FIRST_SIZE >>PAGE_SHIFT ) -1 ); + + directmap_mfn_start =_mfn (base_mfn); + directmap_base_pdx =mfn_to_pdx (_mfn (base_mfn)); +/* +* The base address may not be aligned to the first level +* size (e.g. 1GB when using 4KB pages). This would prevent +* superpage mappings for all the regions because the virtual +* address and machine address should both be suitably aligned. +* +* Prevent that by offsetting the start of the directmap virtual +* address. +*/ + directmap_virt_start =DIRECTMAP_VIRT_START + + (base_mfn - mfn_gb) *PAGE_SIZE ; + } + +if ( base_mfn <mfn_x (directmap_mfn_start) ) +panic ("cannot add directmap mapping at %lx below heap start %lx\n" , + base_mfn,mfn_x (directmap_mfn_start)); +
xen/arch/arm/include/asm/mm.h
Quoted 10 lines
xen/arch/arm/include/asm/mm.h +10
-0+ rc =map_pages_to_xen ((vaddr_t )__mfn_to_virt (base_mfn), +_mfn (base_mfn), nr_mfns, +PAGE_HYPERVISOR_RW | _PAGE_BLOCK); +if ( rc ) + panic("Unable to setup the directmap mappings.\n"); +} +#endif + +/* Map a frame table to cover physical addresses ps through pe */ +void __init setup_frametable_mappings (paddr_t ps,paddr_t pe)
I looked at the implement for the MPU and the code is mainly the same. So can we keep this code in common and just ...
Quoted 17 lines
xen/arch/arm/include/asm/mm.h +17
-0+{ +unsigned long nr_pdxs =mfn_to_pdx (mfn_add (maddr_to_mfn (pe),-1 )) - +mfn_to_pdx (maddr_to_mfn (ps)) +1 ; +unsigned long frametable_size = nr_pdxs *sizeof (struct page_info ); +mfn_t base_mfn; +const unsigned long mapping_size = frametable_size <MB (32 ) ?MB (2 ) :MB (32 ); +int rc; + +/* +* The size of paddr_t should be sufficient for the complete range of +* physical address. +*/ +BUILD_BUG_ON ((sizeof (paddr_t) *BITS_PER_BYTE ) <PADDR_BITS ); +BUILD_BUG_ON (sizeof (struct page_info ) !=PAGE_INFO_SIZE ); + +if ( frametable_size >FRAMETABLE_SIZE ) + panic("The frametable cannot cover the physical region %#"PRIpaddr" - %#"PRIpaddr"\n",
xen/arch/arm/include/asm/mm.h
Quoted 10 lines
xen/arch/arm/include/asm/mm.h +10
-0+ ps, pe); + + frametable_base_pdx =mfn_to_pdx (maddr_to_mfn (ps)); +/* Round up to 2M or 32M boundary, as appropriate. */ + frametable_size =ROUNDUP (frametable_size, mapping_size); + base_mfn =alloc_boot_pages (frametable_size >>PAGE_SHIFT ,32 <<(20 -12 )); + + rc =map_pages_to_xen (FRAMETABLE_VIRT_START , base_mfn, + frametable_size >>PAGE_SHIFT , +PAGE_HYPERVISOR_RW | _PAGE_BLOCK);
abstract the frametable mapping? THis would also make clear that the BUILD_BUG_ON() above are not specific to the MMU code.
Quoted 9 lines
xen/arch/arm/include/asm/mm.h +9
-0+if ( rc ) +panic ("Unable to setup the frametable mappings.\n" ); + +memset (&frame_table[0 ],0 , nr_pdxs *sizeof (struct page_info )); +memset (&frame_table[nr_pdxs],-1 , + frametable_size - (nr_pdxs *sizeof (struct page_info ))); + + frametable_virt_end =FRAMETABLE_VIRT_START + (nr_pdxs *sizeof (struct page_info )); +}
Signature · 1 line
Julien Grall
PATCH v5 8/13 xen/arm: Fold pmap and fixmap into MMU system
In reply to Henry WangFrom: Penny Zheng <[email protected]>
fixmap and pmap are MMU-specific features, so fold them to MMU system. Do the folding for pmap by moving the HAS_PMAP Kconfig selection under HAS_MMU. Do the folding for fixmap by moving the implementation of virt_to_fix() to mmu/mm.c, so that unnecessary stubs can be avoided.
---
v5:
- Rebase on top of xen/arm: Introduce CONFIG_MMU Kconfig option v4:
- Rework "[v3,11/52] xen/arm: mmu: fold FIXMAP into MMU system", change the order of this patch and avoid introducing stubs.
--- xen/arch/arm/Kconfig | 2 +- xen/arch/arm/include/asm/fixmap.h | 7 +------ xen/arch/arm/mmu/mm.c | 7 +++++++ 3 files changed, 9 insertions(+), 7 deletions(-)
xen/arch/arm/Kconfig +1 -1
@@ -15,7 +15,6 @@ config ARM select HAS_DEVICE_TREE select HAS_PASSTHROUGH select HAS_PDX - select HAS_PMAP select HAS_UBSAN select IOMMU_FORCE_PT_SHARE
@@ -61,6 +60,7 @@ config PADDR_BITS config MMU def_bool y + select HAS_PMAP source "arch/Kconfig"
xen/arch/arm/include/asm/fixmap.h +1 -6
@@ -36,12 +36,7 @@ extern void clear_fixmap(unsigned int map);#define fix_to_virt (slot) ((void *)FIXMAP_ADDR(slot)) -static inline unsigned int virt_to_fix (vaddr_t vaddr) -{ -BUG_ON (vaddr >=FIXADDR_TOP || vaddr <FIXADDR_START ); - -return ((vaddr -FIXADDR_START ) >>PAGE_SHIFT ); -} +extern unsigned int virt_to_fix (vaddr_t vaddr);#endif /* __ASSEMBLY__ */
xen/arch/arm/mmu/mm.c +7 -0
@@ -1136,6 +1136,13 @@ int __init populate_pt_range(unsigned long virt, unsigned long nr_mfns)return xen_pt_update (virt,INVALID_MFN , nr_mfns, _PAGE_POPULATE); } +unsigned int virt_to_fix (vaddr_t vaddr) +{ +BUG_ON (vaddr >=FIXADDR_TOP || vaddr <FIXADDR_START ); + +return ((vaddr -FIXADDR_START ) >>PAGE_SHIFT ); +} +/* * Local variables: * mode: C
Signature · 1 line
2.25.1
Re: [PATCH v5 08/13] xen/arm: Fold pmap and fixmap into MMU system
Hi Henry,
Quoted 46 lines · Henry Wang
From: Penny Zheng <[email protected]>
fixmap and pmap are MMU-specific features, so fold them to MMU system. Do the folding for pmap by moving the
HAS_PMAPKconfigselection underHAS_MMU. Do the folding for fixmap by moving the implementation ofvirt_to_fix()tommu/mm.c, so that unnecessary stubs can be avoided.Signed-off-by Penny Zheng <[email protected]>Signed-off-by Henry Wang <[email protected]>---
v5:
- Rebase on top of xen/arm: IntroduceCONFIG_MMUKconfigoption v4:
- Rework "[v3,11/52] xen/arm: mmu: fold FIXMAP into MMU system", change the order of this patch and avoid introducing stubs.--- xen/arch/arm/Kconfig | 2 +- xen/arch/arm/include/asm/fixmap.h | 7 +------ xen/arch/arm/mmu/mm.c | 7 +++++++ 3 files changed, 9 insertions(+), 7 deletions(-)xen/arch/arm/Kconfig +1
-1@@ -15,7 +15,6 @@ config ARM select HAS_DEVICE_TREE select HAS_PASSTHROUGH select HAS_PDX - select HAS_PMAP select HAS_UBSAN select IOMMU_FORCE_PT_SHARE@@ -61,6 +60,7 @@ config PADDR_BITS config MMU def_bool y + select HAS_PMAP source "arch/Kconfig"xen/arch/arm/include/asm/fixmap.h +0
-0
xen/arch/arm/include/asm/fixmap.h extern void clear_fixmap(unsigned int map); · line 39
Quoted 10 lines
xen/arch/arm/include/asm/fixmap.h +1
-6@@ -36,12 +36,7 @@ extern void clear_fixmap(unsigned int map);#define fix_to_virt (slot) ((void *)FIXMAP_ADDR(slot)) -static inline unsigned int virt_to_fix (vaddr_t vaddr) -{ -BUG_ON (vaddr >=FIXADDR_TOP || vaddr <FIXADDR_START ); - -return ((vaddr -FIXADDR_START ) >>PAGE_SHIFT ); -} +extern unsigned int virt_to_fix (vaddr_t vaddr);
AFAICT, virt_to_fix() is not going to be implemented for the MPU code. This implies that no-one should call it.
Also, none of the definitions in fixmap.h actually makes sense for the MPU. I would prefer if we instead try to lmit the include of fixmap to when this is strictly necessary. Looking for the inclusion in staging I could find:
42sh> ack "\#include" | ack "fixmap" | ack -v x86 arch/arm/acpi/lib.c:28:#include <asm/fixmap.h> arch/arm/kernel.c:19:#include <asm/fixmap.h> arch/arm/mm.c:27:#include <asm/fixmap.h> arch/arm/include/asm/fixmap.h:7:#include <xen/acpi.h> arch/arm/include/asm/fixmap.h:8:#include <xen/pmap.h> arch/arm/include/asm/pmap.h:6:#include <asm/fixmap.h> arch/arm/include/asm/early_printk.h:14:#include <asm/fixmap.h> common/efi/boot.c:30:#include <asm/fixmap.h> common/pmap.c:7:#include <asm/fixmap.h> drivers/acpi/apei/erst.c:36:#include <asm/fixmap.h> drivers/acpi/apei/apei-io.c:32:#include <asm/fixmap.h> drivers/char/xhci-dbc.c:30:#include <asm/fixmap.h> drivers/char/ehci-dbgp.c:16:#include <asm/fixmap.h> drivers/char/ns16550.c:40:#include <asm/fixmap.h> drivers/char/xen_pv_console.c:28:#include <asm/fixmap.h>
Some of them are gone after your rework. The only remaining that we care are in kernel.h (but I think it can be removed after your series).
So I think it would be feasible to not touch fixmap.h at all.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 08/13] xen/arm: Fold pmap and fixmap into MMU system
Hi Julien,
Quoted 42 lines · Julien Grall
Hi Henry,
Quoted 7 lines · Henry Wang
From: Penny Zheng <[email protected]>
diff --git
a/xen/arch/arm/include/asm/fixmap.hb/xen/arch/arm/include/asm/fixmap.h
index734eb9b1d4..5d5de6995a100644xen/arch/arm/include/asm/fixmap.h extern void clear_fixmap(unsigned int map); · line 38
Quoted 8 lines
xen/arch/arm/include/asm/fixmap.h +1
-5@@ -36,12 +36,7 @@ extern void clear_fixmap(unsigned int map);#define fix_to_virt (slot) ((void *)FIXMAP_ADDR(slot)) -static inline unsigned int virt_to_fix(vaddr_t vaddr) -{ -BUG_ON (vaddr >=FIXADDR_TOP || vaddr <FIXADDR_START ); - -return ((vaddr -FIXADDR_START ) >>PAGE_SHIFT ); -} +extern unsigned int virt_to_fix(vaddr_t vaddr);AFAICT,
virt_to_fix()is not going to be implemented for the MPU code. This implies that no-one should call it.Also, none of the definitions in
fixmap.hactually makes sense for the MPU. I would prefer if we instead try to lmit the include of fixmap to when this is strictly necessary. Looking for the inclusion in staging I could find:42sh> ack "\#include" | ack "fixmap" | ack -v x86 arch/arm/acpi/lib.c:28:#include <
asm/fixmap.h> arch/arm/kernel.c:19:#include <asm/fixmap.h> arch/arm/mm.c:27:#include <asm/fixmap.h> arch/arm/include/asm/fixmap.h:7:#include <xen/acpi.h> arch/arm/include/asm/fixmap.h:8:#include <xen/pmap.h> arch/arm/include/asm/pmap.h:6:#include <asm/fixmap.h> arch/arm/include/asm/early_printk.h:14:#include <asm/fixmap.h> common/efi/boot.c:30:#include <asm/fixmap.h> common/pmap.c:7:#include <asm/fixmap.h> drivers/acpi/apei/erst.c:36:#include <asm/fixmap.h> drivers/acpi/apei/apei-io.c:32:#include <asm/fixmap.h> drivers/char/xhci-dbc.c:30:#include <asm/fixmap.h> drivers/char/ehci-dbgp.c:16:#include <asm/fixmap.h> drivers/char/ns16550.c:40:#include <asm/fixmap.h> drivers/char/xen_pv_console.c:28:#include <asm/fixmap.h>
Quoted 1 line
Some of them are gone after your rework. The only remaining that we care are in
kernel.h(but I think it can be removed after your series).
I think you are correct, so I reverted the virt_to_fix() change from this patch, deleted the include of asm/fixmap.h in kernel.c and put this patch as the (last - 1)th patch of the series. The building of Xen works fine.
Does below updated patch look good to you?
```
diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
index eb0413336b..8a7b79b4b5 100644
--- a/xen/arch/arm/Kconfig
+++ b/xen/arch/arm/Kconfig
@@ -15,7 +15,6 @@ config ARM
select HAS_DEVICE_TREE
select HAS_PASSTHROUGH
select HAS_PDX
- select HAS_PMAP
select HAS_UBSAN
select IOMMU_FORCE_PT_SHARE
@@ -61,6 +60,7 @@ config PADDR_BITS
config MMU
def_bool y
+ select HAS_PMAP
source "arch/Kconfig"
diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c
index 0d433a32e7..bc3e5bd6f9 100644
--- a/xen/arch/arm/kernel.c
+++ b/xen/arch/arm/kernel.c
@@ -16,7 +16,6 @@
#include <xen/vmap.h>
#include <asm/byteorder.h>
-#include <asm/fixmap.h>
#include <asm/kernel.h>
#include <asm/setup.h>
```I will update the commit message accordingly.
Kind regards,
Henry
Quoted 8 lines
So I think it would be feasible to not touch
fixmap.hat all.Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 08/13] xen/arm: Fold pmap and fixmap into MMU system
Hi,
Quoted 11 lines · Henry Wang
xen/arch/arm/kernel.c +0
-1@@ -16,7 +16,6 @@#include <xen/vmap.h> #include <asm/byteorder.h> -#include <asm/fixmap.h> #include <asm/kernel.h> #include <asm/setup.h>
Quoted 1 line
```
The changes in kernel.c should go in patch #12 where the fixmap user is moved out.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 08/13] xen/arm: Fold pmap and fixmap into MMU system
Hi Julien,
Quoted 5 lines · Julien Grall
Hi,
On 22/08/2023 03:42, Henry Wang wrote:
Quoted 13 lines
Quoted 11 lines
xen/arch/arm/kernel.c +0
-1@@ -16,7 +16,6 @@#include <xen/vmap.h> #include <asm/byteorder.h> -#include <asm/fixmap.h> #include <asm/kernel.h> #include <asm/setup.h> ```
The changes in
kernel.cshould go in patch #12 where the fixmap user is moved out.
Thanks, sounds good. I will fix it in v6.
Kind regards,
Henry
Quoted 5 lines
Cheers,
Signature · 1 line
Julien Grall
PATCH v5 9/13 xen/arm: mm: Use generic variable/function names for extendability
In reply to Henry WangFrom: Penny Zheng <[email protected]>
As preparation for MPU support, which will use some variables/functions for both MMU and MPU system, We rename the affected variable/function to more generic names:
- init_ttbr -> init_mm,
- mmu_init_secondary_cpu() -> mm_init_secondary_cpu()
- init_secondary_pagetables() -> init_secondary_mm()
- Add a wrapper update_mm_mapping() for MMU system's update_identity_mapping()
Modify the related in-code comment to reflect above changes, take the opportunity to fix the incorrect coding style of the in-code comments.
---
v5:
- Rebase on top of xen/arm: mm: add missing extern variable declaration v4:
- Extract the renaming part from the original patch:
"[v3,13/52] xen/mmu: extract mmu-specific codes from mm.c/mm.h"
--- xen/arch/arm/arm32/head.S | 4 ++-- xen/arch/arm/arm64/mmu/head.S | 2 +- xen/arch/arm/arm64/mmu/mm.c | 11 ++++++++--- xen/arch/arm/arm64/smpboot.c | 6 +++--- xen/arch/arm/include/asm/arm64/mm.h | 7 ++++--- xen/arch/arm/include/asm/mm.h | 12 +++++++----- xen/arch/arm/mmu/mm.c | 20 ++++++++++---------- xen/arch/arm/smpboot.c | 4 ++-- 8 files changed, 37 insertions(+), 29 deletions(-)
xen/arch/arm/arm32/head.S +2 -2
@@ -238,11 +238,11 @@ GLOBAL(init_secondary) secondary_switched: /* * Non-boot CPUs need to move on to the proper pagetables, which were - * setup in init_secondary_pagetables. + * setup in init_secondary_mm. * * XXX: This is not compliant with the Arm Arm. */ - mov_w r4, init_ttbr /* VA of HTTBR value stashed by CPU 0 */ + mov_w r4, init_mm /* VA of HTTBR value stashed by CPU 0 */ ldrd r4, r5, [r4] /* Actual value */ dsb mcrr CP64(r4, r5, HTTBR)
xen/arch/arm/arm64/mmu/head.S +1 -1
@@ -302,7 +302,7 @@ ENDPROC(enable_mmu) ENTRY(enable_secondary_cpu_mm) mov x5, lr - load_paddr x0, init_ttbr + load_paddr x0, init_mm ldr x0, [x0] bl enable_mmu
xen/arch/arm/arm64/mmu/mm.c +8 -3
@@ -106,7 +106,7 @@ void __init arch_setup_page_tables(void)prepare_runtime_identity_mapping (); } -void update_identity_mapping (bool enable) +static void update_identity_mapping (bool enable) {paddr_t id_addr =virt_to_maddr (_start);int rc;
@@ -120,6 +120,11 @@ void update_identity_mapping(bool enable)BUG_ON (rc); } +void update_mm_mapping (bool enable) +{ +update_identity_mapping (enable); +} +extern void switch_ttbr_id (uint64_t ttbr);typedef void (switch_ttbr_fn )(uint64_t ttbr);
@@ -131,7 +136,7 @@ void __init switch_ttbr(uint64_t ttbr)lpae_t pte;/* Enable the identity mapping in the boot page tables */ -update_identity_mapping (true); +update_mm_mapping (true);/* Enable the identity mapping in the runtime page tables */ pte =pte_of_xenaddr ((vaddr_t )switch_ttbr_id);
@@ -148,7 +153,7 @@ void __init switch_ttbr(uint64_t ttbr)* Note it is not necessary to disable it in the boot page tables * because they are not going to be used by this CPU anymore. */ -update_identity_mapping (false); +update_mm_mapping (false); }/*
xen/arch/arm/arm64/smpboot.c +3 -3
@@ -111,18 +111,18 @@ int arch_cpu_up(int cpu)if ( !smp_enable_ops[cpu].prepare_cpu )return -ENODEV ; -update_identity_mapping (true); +update_mm_mapping (true); rc = smp_enable_ops[cpu].prepare_cpu (cpu);if ( rc ) -update_identity_mapping (false); +update_mm_mapping (false);return rc; }void arch_cpu_up_finish (void ) { -update_identity_mapping (false); +update_mm_mapping (false); }/*
xen/arch/arm/include/asm/arm64/mm.h +4 -3
@@ -15,13 +15,14 @@ static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long nr)void arch_setup_page_tables (void );/* -* Enable/disable the identity mapping in the live page-tables (i.e. -* the one pointed by TTBR_EL2). +* In MMU system, enable/disable the identity mapping in the live +* page-tables (i.e. the one pointed by TTBR_EL2) through +* update_identity_mapping(). * * Note that nested call (e.g. enable=true, enable=true) is not * supported. */ -void update_identity_mapping (bool enable); +void update_mm_mapping (bool enable);#endif /* __ARM_ARM64_MM_H__ */
xen/arch/arm/include/asm/mm.h +7 -5
@@ -170,7 +170,7 @@ struct page_info#define PGC_need_scrub PGC_allocated/* Non-boot CPUs use this to find the correct pagetables. */ -extern uint64_t init_ttbr; +extern uint64_t init_mm;#ifdef CONFIG_ARM_32 #define is_xen_heap_page (page) is_xen_heap_mfn(page_to_mfn(page))
@@ -205,11 +205,13 @@ extern void setup_pagetables(unsigned long boot_phys_offset);extern void *early_fdt_map (paddr_t fdt_paddr);/* Remove early mappings */ extern void remove_early_mappings (void ); -/* Allocate and initialise pagetables for a secondary CPU. Sets init_ttbr to the -* new page table */ -extern int init_secondary_pagetables (int cpu); +/* +* Allocate and initialise pagetables for a secondary CPU. Sets init_mm to the +* new page table +*/ +extern int init_secondary_mm (int cpu);/* Switch secondary CPUS to its own pagetables and finalise MMU setup */ -extern void mmu_init_secondary_cpu (void ); +extern void mm_init_secondary_cpu (void );/* Map a frame table to cover physical addresses ps through pe */ extern void setup_frametable_mappings (paddr_t ps,paddr_t pe);/* map a physical range in virtual memory */
xen/arch/arm/mmu/mm.c +10 -10
@@ -106,7 +106,7 @@ DEFINE_BOOT_PAGE_TABLE(xen_fixmap); static DEFINE_PAGE_TABLES(xen_xenmap, XEN_NR_ENTRIES(2)); /* Non-boot CPUs use this to find the correct pagetables. */ -uint64_t init_ttbr; +uint64_t init_mm; static paddr_t phys_offset;
@@ -492,18 +492,18 @@ static void clear_boot_pagetables(void) }#ifdef CONFIG_ARM_64 -int init_secondary_pagetables (int cpu) +int init_secondary_mm (int cpu) {clear_boot_pagetables (); -/* Set init_ttbr for this CPU coming up. All CPus share a single setof +/* Set init_mm for this CPU coming up. All CPus share a single setof * pagetables, but rewrite it each time for consistency with 32 bit. */ - init_ttbr = (uintptr_t ) xen_pgtable + phys_offset; -clean_dcache (init_ttbr); + init_mm = (uintptr_t ) xen_pgtable + phys_offset; +clean_dcache (init_mm);return 0 ; }#else -int init_secondary_pagetables (int cpu) +int init_secondary_mm (int cpu) {lpae_t *first;
@@ -529,16 +529,16 @@ int init_secondary_pagetables(int cpu)clear_boot_pagetables (); -/* Set init_ttbr for this CPU coming up */ - init_ttbr =__pa (first); -clean_dcache (init_ttbr); +/* Set init_mm for this CPU coming up */ + init_mm =__pa (first); +clean_dcache (init_mm); return 0; }#endif /* MMU setup for secondary CPUS (which already have paging enabled) */ -void mmu_init_secondary_cpu (void ) +void mm_init_secondary_cpu (void ) {xen_pt_enforce_wnx (); }
xen/arch/arm/smpboot.c +2 -2
@@ -359,7 +359,7 @@ void start_secondary(void)*/ update_system_features (¤t_cpu_data); -mmu_init_secondary_cpu (); +mm_init_secondary_cpu ();gic_init_secondary_cpu ();
@@ -448,7 +448,7 @@ int __cpu_up(unsigned int cpu)printk ("Bringing up CPU%d\n" , cpu); - rc =init_secondary_pagetables (cpu); + rc =init_secondary_mm (cpu);if ( rc <0 )return rc;
Signature · 1 line
2.25.1
Re: [PATCH v5 09/13] xen/arm: mm: Use generic variable/function names for extendability
Hi,
Quoted 6 lines · Henry Wang
From: Penny Zheng <[email protected]>
As preparation for MPU support, which will use some variables/functions for both MMU and MPU system, We rename the affected variable/function to more generic names:
-init_ttbr->init_mm,
You moved init_ttbr to mm/mmu.c. So why does this need to be renamed?
And if you really planned to use it for the MPU code. Then init_ttbr should not have been moved.
Quoted 2 lines
-
mmu_init_secondary_cpu()->mm_init_secondary_cpu()
-init_secondary_pagetables()->init_secondary_mm()
The original naming were not great but the new one are a lot more confusing as they seem to just be a reshuffle of word.
mm_init_secondary_cpu() is only setting the WxN bit. For the MMU, I think it can be done much earlier. Do you have anything to add in it? If not, then I would consider to get rid of it.
For init_secondary_mm(), I would renamed it to prepare_secondary_mm().
Quoted 61 lines
- Add a wrapper
update_mm_mapping()for MMU system'supdate_identity_mapping()Modify the related in-code comment to reflect above changes, take the opportunity to fix the incorrect coding style of the in-code comments.
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Henry Wang <[email protected]>---
v5:
- Rebase on top of xen/arm: mm: add missing extern variable declaration v4:
- Extract the renaming part from the original patch:"[v3,13/52] xen/mmu: extract mmu-specific codes from mm.c/mm.h" --- xen/arch/arm/arm32/head.S | 4 ++-- xen/arch/arm/arm64/mmu/head.S | 2 +- xen/arch/arm/arm64/mmu/mm.c | 11 ++++++++--- xen/arch/arm/arm64/smpboot.c | 6 +++--- xen/arch/arm/include/asm/arm64/mm.h | 7 ++++--- xen/arch/arm/include/asm/mm.h | 12 +++++++----- xen/arch/arm/mmu/mm.c | 20 ++++++++++---------- xen/arch/arm/smpboot.c | 4 ++-- 8 files changed, 37 insertions(+), 29 deletions(-)xen/arch/arm/arm32/head.S +2
-2@@ -238,11 +238,11 @@ GLOBAL(init_secondary) secondary_switched: /* * Non-boot CPUs need to move on to the proper pagetables, which were - * setup in init_secondary_pagetables. + * setup in init_secondary_mm. * * XXX: This is not compliant with the Arm Arm. */ - mov_w r4, init_ttbr /* VA of HTTBR value stashed by CPU 0 */ + mov_w r4, init_mm /* VA of HTTBR value stashed by CPU 0 */ ldrd r4, r5, [r4] /* Actual value */ dsb mcrr CP64(r4, r5, HTTBR)xen/arch/arm/arm64/mmu/head.S +1
-1@@ -302,7 +302,7 @@ ENDPROC(enable_mmu) ENTRY(enable_secondary_cpu_mm) mov x5, lr - load_paddr x0, init_ttbr + load_paddr x0, init_mm ldr x0, [x0] bl enable_mmuxen/arch/arm/arm64/mmu/mm.c +0
-0
xen/arch/arm/arm64/mmu/mm.c void __init arch_setup_page_tables(void) · line 109
Quoted 5 lines
xen/arch/arm/arm64/mmu/mm.c +1
-1@@ -106,7 +106,7 @@ void __init arch_setup_page_tables(void)prepare_runtime_identity_mapping (); } -void update_identity_mapping (bool enable) +static void update_identity_mapping (bool enable)
Why not simply renaming this function to update_mm_mapping()? But...
xen/arch/arm/arm64/mmu/mm.c void update_identity_mapping(bool enable) · line 123
Quoted 8 lines
xen/arch/arm/arm64/mmu/mm.c +1
-0{paddr_t id_addr =virt_to_maddr (_start);int rc;@@ -120,6 +120,11 @@ void update_identity_mapping(bool enable)BUG_ON (rc); } +void update_mm_mapping (bool enable)
... the new name it quite confusing. What is the mapping it is referring to?
If you don't want to keep update_identity_mapping(), then I would consider to simply wrap...
Quoted 30 lines
xen/arch/arm/arm64/mmu/mm.c +6
-2+{ +update_identity_mapping (enable); +} +extern void switch_ttbr_id (uint64_t ttbr);typedef void (switch_ttbr_fn )(uint64_t ttbr);@@ -131,7 +136,7 @@ void __init switch_ttbr(uint64_t ttbr)lpae_t pte;/* Enable the identity mapping in the boot page tables */ -update_identity_mapping (true); +update_mm_mapping (true);/* Enable the identity mapping in the runtime page tables */ pte =pte_of_xenaddr ((vaddr_t )switch_ttbr_id);@@ -148,7 +153,7 @@ void __init switch_ttbr(uint64_t ttbr)* Note it is not necessary to disable it in the boot page tables * because they are not going to be used by this CPU anymore. */ -update_identity_mapping (false); +update_mm_mapping (false); }/* xen/arch/arm/arm64/smpboot.c +0
-0
xen/arch/arm/arm64/smpboot.c int arch_cpu_up(int cpu) · line 114
Quoted 5 lines
xen/arch/arm/arm64/smpboot.c +1
-1@@ -111,18 +111,18 @@ int arch_cpu_up(int cpu)if ( !smp_enable_ops[cpu].prepare_cpu )return -ENODEV ; -update_identity_mapping (true); +update_mm_mapping (true);
... with #ifdef CONFIG_MMU here...
xen/arch/arm/arm64/smpboot.c int arch_cpu_up(int cpu) · line 118
Quoted 5 lines
xen/arch/arm/arm64/smpboot.c +1
-1rc = smp_enable_ops[cpu].prepare_cpu (cpu);if ( rc ) -update_identity_mapping (false); +update_mm_mapping (false);
... here and ...
xen/arch/arm/arm64/smpboot.c int arch_cpu_up(int cpu) · line 125
Quoted 8 lines
xen/arch/arm/arm64/smpboot.c +1
-1return rc; }void arch_cpu_up_finish (void ) { -update_identity_mapping (false); +update_mm_mapping (false);
... here.
Quoted 41 lines
xen/arch/arm/arm64/smpboot.c +0
-0}/* xen/arch/arm/include/asm/arm64/mm.h +4
-3@@ -15,13 +15,14 @@ static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long nr)void arch_setup_page_tables (void );/* -* Enable/disable the identity mapping in the live page-tables (i.e. -* the one pointed by TTBR_EL2). +* In MMU system, enable/disable the identity mapping in the live +* page-tables (i.e. the one pointed by TTBR_EL2) through +* update_identity_mapping(). * * Note that nested call (e.g. enable=true, enable=true) is not * supported. */ -void update_identity_mapping (bool enable); +void update_mm_mapping (bool enable);#endif /* __ARM_ARM64_MM_H__ */ xen/arch/arm/include/asm/mm.h +1
-1@@ -170,7 +170,7 @@ struct page_info#define PGC_need_scrub PGC_allocated/* Non-boot CPUs use this to find the correct pagetables. */ -extern uint64_t init_ttbr; +extern uint64_t init_mm;#ifdef CONFIG_ARM_32 #define is_xen_heap_page (page) is_xen_heap_mfn(page_to_mfn(page))@@ -205,11 +205,13 @@ extern void setup_pagetables(unsigned long boot_phys_offset);extern void *early_fdt_map (paddr_t fdt_paddr);/* Remove early mappings */
xen/arch/arm/include/asm/mm.h extern void setup_pagetables(unsigned long boot_phys_offset); · line 213
Quoted 10 lines
xen/arch/arm/include/asm/mm.h +5
-3extern void remove_early_mappings (void ); -/* Allocate and initialise pagetables for a secondary CPU. Sets init_ttbr to the -* new page table */ -extern int init_secondary_pagetables (int cpu); +/* +* Allocate and initialise pagetables for a secondary CPU. Sets init_mm to the +* new page table +*/ +extern int init_secondary_mm (int cpu);/* Switch secondary CPUS to its own pagetables and finalise MMU setup */
Regardless what I wrote above, this comment is not accurate anymore as we don't switch the page tables for the secondary CPUs. We are only enable WxN.
In any case, this comment would need to be reworded to be more generic.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 09/13] xen/arm: mm: Use generic variable/function names for extendability
Hi Julien,
Quoted 11 lines · Julien Grall
Hi,
Quoted 5 lines · Henry Wang
From: Penny Zheng <[email protected]>
As preparation for MPU support, which will use some variables/functions for both MMU and MPU system, We rename the affected variable/function to more generic names:
-init_ttbr->init_mm,
Quoted 3 lines
You moved
init_ttbrtomm/mmu.c. So why does this need to be renamed?And if you really planned to use it for the MPU code. Then
init_ttbrshould not have been moved.
You are correct. I think we need to use the “init_mm” for MPU SMP support, so I would not move this variable in v6.
Quoted 7 lines
Quoted 3 lines
-
mmu_init_secondary_cpu()->mm_init_secondary_cpu()
-init_secondary_pagetables()->init_secondary_mm()The original naming were not great but the new one are a lot more confusing as they seem to just be a reshuffle of word.
mm_init_secondary_cpu()is only setting the WxN bit. For the MMU, I think it can be done much earlier. Do you have anything to add in it? If not, then I would consider to get rid of it.
I’ve got rid of mmu_init_secondary_cpu() function in my local v6 as it is now folded to the assembly code.
Quoted 2 lines
For
init_secondary_mm(), I would renamed it toprepare_secondary_mm().
Sure, thanks for the name suggestion.
Quoted 6 lines
Quoted 3 lines
-void
update_identity_mapping(bool enable)
+static voidupdate_identity_mapping(bool enable)Why not simply renaming this function to
update_mm_mapping()? But...
Quoted 9 lines
xen/arch/arm/arm64/mmu/mm.c void update_identity_mapping(bool enable) · line 122
Quoted 7 lines
{ paddr_t id_addr = virt_to_maddr(_start); int rc;xen/arch/arm/arm64/mmu/mm.c +0
-0@@ -120,6 +120,11 @@ void update_identity_mapping(bool enable)BUG_ON (rc); } +void update_mm_mapping(bool enable)... the new name it quite confusing. What is the mapping it is referring to?
So I checked the MPU SMP support code and now I think I understand the reason why update_mm_mapping() was introduced:
In the future we eventually need to support SMP for MMU systems, which means we need to call arch_cpu_up() and arch_cpu_up_finish(). These two functions call update_identity_mapping(). Since we believe "identity mapping" is a MMU concept, we changed this to generic name "mm mapping” as arch_cpu_up() and arch_cpu_up_finish() is a shared path between MMU and MPU.
But I think MPU won’t use update_mm_mapping() function at all, so I wonder do you prefer creating an empty stub update_identity_mapping() for MPU? Or use #ifdef as suggested in your previous email...
Quoted 2 lines
If you don't want to keep
update_identity_mapping(), then I would consider to simply wrap...
…here and ...
Quoted 42 lines
Quoted 27 lines
xen/arch/arm/arm64/mmu/mm.c +6
-2+{ +update_identity_mapping (enable); +} +extern void switch_ttbr_id (uint64_t ttbr);typedef void (switch_ttbr_fn )(uint64_t ttbr);@@ -131,7 +136,7 @@ void __init switch_ttbr(uint64_t ttbr)lpae_t pte;/* Enable the identity mapping in the boot page tables */ -update_identity_mapping (true); +update_mm_mapping (true);/* Enable the identity mapping in the runtime page tables */ pte =pte_of_xenaddr ((vaddr_t )switch_ttbr_id);@@ -148,7 +153,7 @@ void __init switch_ttbr(uint64_t ttbr)* Note it is not necessary to disable it in the boot page tables * because they are not going to be used by this CPU anymore. */ -update_identity_mapping (false); +update_mm_mapping (false); }/* xen/arch/arm/arm64/smpboot.c +0
-0xen/arch/arm/arm64/smpboot.c int arch_cpu_up(int cpu) · line 114
Quoted 4 lines
xen/arch/arm/arm64/smpboot.c +1
-0@@ -111,18 +111,18 @@ int arch_cpu_up(int cpu)if ( !smp_enable_ops[cpu].prepare_cpu )return -ENODEV ; -update_identity_mapping (true); +update_mm_mapping (true);... with #ifdef
CONFIG_MMUhere...xen/arch/arm/arm64/smpboot.c int arch_cpu_up(int cpu) · line 118
Quoted 4 lines
xen/arch/arm/arm64/smpboot.c +1
-1rc = smp_enable_ops[cpu].prepare_cpu (cpu);if ( rc ) -update_identity_mapping (false); +update_mm_mapping (false);... here and ...
Quoted 8 lines
xen/arch/arm/arm64/smpboot.c int arch_cpu_up(int cpu) · line 125
Quoted 6 lines
xen/arch/arm/arm64/smpboot.c +1
-1return rc; }void arch_cpu_up_finish (void ) { -update_identity_mapping (false); +update_mm_mapping (false);... here.
…all here?
Kind regards,
Henry
Re: [PATCH v5 09/13] xen/arm: mm: Use generic variable/function names for extendability
Hi Henry,
Quoted 11 lines · Henry Wang
Quoted 11 lines · Julien Grall
Hi,
Quoted 5 lines · Henry Wang
From: Penny Zheng <[email protected]>
As preparation for MPU support, which will use some variables/functions for both MMU and MPU system, We rename the affected variable/function to more generic names:
-init_ttbr->init_mm,
Quoted 6 lines
Quoted 3 lines
You moved
init_ttbrtomm/mmu.c. So why does this need to be renamed?And if you really planned to use it for the MPU code. Then
init_ttbrshould not have been moved.You are correct. I think we need to use the “init_mm” for MPU SMP support, so I would not move this variable in v6.
Your branch mpu_v5 doesn't seem to contain any use. But I would expect that the common is never going to use the variable. Also, at the moment it is 64-bit but I don't see why it would be necessary to be bigger than 32-bit on 32-bit.
So I think it would be preferable if init_ttbr is move in mm/mmu.c. You can then introduce an MPU specific variable.
In general, only variables that will be used by common code should be defined in common. All the rest should be defined in their specific directory.
Quoted 31 lines
Quoted 6 lines
Quoted 2 lines
-
mmu_init_secondary_cpu()->mm_init_secondary_cpu()
-init_secondary_pagetables()->init_secondary_mm()The original naming were not great but the new one are a lot more confusing as they seem to just be a reshuffle of word.
mm_init_secondary_cpu()is only setting the WxN bit. For the MMU, I think it can be done much earlier. Do you have anything to add in it? If not, then I would consider to get rid of it.I’ve got rid of
mmu_init_secondary_cpu()function in my local v6 as it is now folded to the assembly code.Quoted 2 lines
For
init_secondary_mm(), I would renamed it toprepare_secondary_mm().Sure, thanks for the name suggestion.
Quoted 6 lines
Quoted 3 lines
-void
update_identity_mapping(bool enable)
+static voidupdate_identity_mapping(bool enable)Why not simply renaming this function to
update_mm_mapping()? But...Quoted 9 lines
xen/arch/arm/arm64/mmu/mm.c void update_identity_mapping(bool enable) · line 122
Quoted 7 lines
{ paddr_t id_addr = virt_to_maddr(_start); int rc;xen/arch/arm/arm64/mmu/mm.c +0
-0@@ -120,6 +120,11 @@ void update_identity_mapping(bool enable)BUG_ON (rc); } +void update_mm_mapping(bool enable)... the new name it quite confusing. What is the mapping it is referring to?
Quoted 8 lines
So I checked the MPU SMP support code and now I think I understand the reason why
update_mm_mapping()was introduced:In the future we eventually need to support SMP for MMU systems, which means we need to call
arch_cpu_up()andarch_cpu_up_finish(). These two functions callupdate_identity_mapping(). Since we believe "identity mapping" is a MMU concept, we changed this to generic name "mm mapping” asarch_cpu_up()andarch_cpu_up_finish()is a shared path between MMU and MPU.
The function is today called "update_identity_mapping()" because this is what the implementation does on arm64. But the goal of this function is to make sure that any mapping necessary for bring-up secondary CPUs are present.
So if you don't need similar work for the MPU then I would go with...
Quoted 4 lines
But I think MPU won’t use
update_mm_mapping()function at all, so I wonder do you prefer creating an empty stubupdate_identity_mapping()for MPU? Or use #ifdef as suggested in your previous email...
... #ifdef. I have some preliminary work where the call to update_identity_mapping() may end up to be moved somewhere else as the page-tables would not be shared between pCPU anymore. So the logic will not some rework (see [1]).
Cheers,
[1] https://lore.kernel.org/all/[email protected]/
Signature · 1 line
Julien Grall
Re: [PATCH v5 09/13] xen/arm: mm: Use generic variable/function names for extendability
Hi Julienm
Quoted 18 lines · Julien Grall
Hi Henry,
Quoted 13 lines · Henry Wang
Quoted 13 lines · Julien Grall
Hi,
Quoted 5 lines · Henry Wang
From: Penny Zheng <[email protected]>
As preparation for MPU support, which will use some variables/functions for both MMU and MPU system, We rename the affected variable/function to more generic names:
-init_ttbr->init_mm,You moved
init_ttbrtomm/mmu.c. So why does this need to be renamed?
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
And if you really planned to use it for the MPU code. Then
init_ttbrshould not have been moved.You are correct. I think we need to use the “init_mm” for MPU SMP support, so I would not move this variable in v6.
Your branch
mpu_v5doesn't seem to contain any use. But I would expect that the common is never going to use the variable. Also, at the moment it is 64-bit but I don't see why it would be necessary to be bigger than 32-bit on 32-bit.So I think it would be preferable if
init_ttbris move inmm/mmu.c. You can then introduce an MPU specific variable.
Sounds good to me.
Quoted 2 lines
In general, only variables that will be used by common code should be defined in common. All the rest should be defined in their specific directory.
Got it :))
Quoted 37 lines
Quoted 27 lines
Quoted 7 lines
Quoted 3 lines
-
mmu_init_secondary_cpu()->mm_init_secondary_cpu()
-init_secondary_pagetables()->init_secondary_mm()The original naming were not great but the new one are a lot more confusing as they seem to just be a reshuffle of word.
mm_init_secondary_cpu()is only setting the WxN bit. For the MMU, I think it can be done much earlier. Do you have anything to add in it? If not, then I would consider to get rid of it.I’ve got rid of
mmu_init_secondary_cpu()function in my local v6 as it is now folded to the assembly code.Quoted 2 lines
For
init_secondary_mm(), I would renamed it toprepare_secondary_mm().Sure, thanks for the name suggestion.
Quoted 6 lines
Quoted 3 lines
-void
update_identity_mapping(bool enable)
+static voidupdate_identity_mapping(bool enable)Why not simply renaming this function to
update_mm_mapping()? But...Quoted 9 lines
xen/arch/arm/arm64/mmu/mm.c void update_identity_mapping(bool enable) · line 122
Quoted 7 lines
{ paddr_t id_addr = virt_to_maddr(_start); int rc;xen/arch/arm/arm64/mmu/mm.c +0
-0@@ -120,6 +120,11 @@ void update_identity_mapping(bool enable)BUG_ON (rc); } +void update_mm_mapping(bool enable)... the new name it quite confusing. What is the mapping it is referring to?
Quoted 7 lines
So I checked the MPU SMP support code and now I think I understand the reason why
update_mm_mapping()was introduced:
In the future we eventually need to support SMP for MMU systems, which means we need to callarch_cpu_up()andarch_cpu_up_finish(). These two functions callupdate_identity_mapping(). Since we believe "identity mapping" is a MMU concept, we changed this to generic name "mm mapping” asarch_cpu_up()andarch_cpu_up_finish()is a shared path between MMU and MPU.The function is today called "
update_identity_mapping()" because this is what the implementation does on arm64. But the goal of this function is to make sure that any mapping necessary for bring-up secondary CPUs are present.
Quoted 8 lines
So if you don't need similar work for the MPU then I would go with...
Quoted 3 lines
But I think MPU won’t use
update_mm_mapping()function at all, so I wonder do you prefer creating an empty stubupdate_identity_mapping()for MPU? Or use #ifdef as suggested in your previous email...... #ifdef. I have some preliminary work where the call to
update_identity_mapping()may end up to be moved somewhere else as the page-tables would not be shared between pCPU anymore. So the logic will not some rework (see [1]).
Thanks for sharing this info, I will drop the modification to update_identity_mapping() from this patch.
Kind regards,
Henry
Quoted 8 lines
Cheers,
[1] https://lore.kernel.org/all/[email protected]/
Signature · 1 line
Julien Grall
PATCH v5 10/13 xen/arm: mmu: move MMU-specific setup_mm to mmu/setup.c
In reply to Henry WangFrom: Penny Zheng <[email protected]>
setup_mm is used for Xen to setup memory management subsystem at boot time, like boot allocator, direct-mapping, xenheap initialization, frametable and static memory pages.
We could inherit some components seamlessly in later MPU system like boot allocator, whilst we need to implement some components differently in MPU, like xenheap, etc. There are some components that is specific to MMU only, like direct-mapping.
In the commit, we move MMU-specific components into mmu/setup.c, in preparation of implementing MPU version of setup_mm later in future commit. Also, make init_pdx(), init_staticmem_pages(), setup_mm(), and populate_boot_allocator() public for future MPU inplementation.
---
v5:
- No change
v4:
- No change
--- xen/arch/arm/include/asm/setup.h | 5 + xen/arch/arm/mmu/Makefile | 1 + xen/arch/arm/mmu/setup.c | 339 +++++++++++++++++++++++++++++++ xen/arch/arm/setup.c | 326 +---------------------------- 4 files changed, 349 insertions(+), 322 deletions(-) create mode 100644 xen/arch/arm/mmu/setup.c
xen/arch/arm/include/asm/setup.h +5 -0
@@ -156,6 +156,11 @@ struct bootcmdline *boot_cmdline_find_by_kind(bootmodule_kind kind);struct bootcmdline *boot_cmdline_find_by_name (const char *name);const char *boot_module_kind_as_string (bootmodule_kind kind); +extern void init_pdx (void ); +extern void init_staticmem_pages (void ); +extern void populate_boot_allocator (void ); +extern void setup_mm (void ); +extern uint32_t hyp_traps_vector[];void init_traps (void );
xen/arch/arm/mmu/Makefile +1 -0
@@ -1 +1,2 @@ obj-y += mm.o +obj-y += setup.o
xen/arch/arm/mmu/setup.c new file +339 -0
339 lines not on this page · raw message
xen/arch/arm/setup.c +4 -322
368 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v5 10/13] xen/arm: mmu: move MMU-specific setup_mm to mmu/setup.c
Hi,
Quoted 11 lines · Henry Wang
From: Penny Zheng <[email protected]>
setup_mmis used for Xen to setup memory management subsystem at boot time, like boot allocator, direct-mapping, xenheap initialization, frametable and static memory pages.We could inherit some components seamlessly in later MPU system like boot allocator, whilst we need to implement some components differently in MPU, like xenheap, etc. There are some components that is specific to MMU only, like direct-mapping.
Quoted 4 lines
In the commit, we move MMU-specific components into
mmu/setup.c, in preparation of implementing MPU version ofsetup_mmlater in future commit. Also, makeinit_pdx(),init_staticmem_pages(),setup_mm(), andpopulate_boot_allocator()public for future MPU inplementation.
Typo: s/inplementation/implementation/
Quoted 22 lines
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>Signed-off-by Henry Wang <[email protected]>---
v5:
- No change
v4:
- No change--- xen/arch/arm/include/asm/setup.h | 5 + xen/arch/arm/mmu/Makefile | 1 + xen/arch/arm/mmu/setup.c | 339 +++++++++++++++++++++++++++++++ xen/arch/arm/setup.c | 326 +---------------------------- 4 files changed, 349 insertions(+), 322 deletions(-)create mode 100644
xen/arch/arm/mmu/setup.cxen/arch/arm/include/asm/setup.h +0
-0
xen/arch/arm/include/asm/setup.h struct bootcmdline *boot_cmdline_find_by_kind(bootmodule_kind kind); · line 162
Quoted 7 lines
xen/arch/arm/include/asm/setup.h +4
-0@@ -156,6 +156,11 @@ struct bootcmdline *boot_cmdline_find_by_kind(bootmodule_kind kind);struct bootcmdline *boot_cmdline_find_by_name (const char *name);const char *boot_module_kind_as_string (bootmodule_kind kind); +extern void init_pdx (void ); +extern void init_staticmem_pages (void ); +extern void populate_boot_allocator (void ); +extern void setup_mm (void );
Please avoid the 'extern' for new function declaration.
Quoted 17 lines
xen/arch/arm/include/asm/setup.h +1
-0+extern uint32_t hyp_traps_vector[];void init_traps (void );xen/arch/arm/mmu/Makefile +1
-0@@ -1 +1,2 @@ obj-y += mm.o +obj-y += setup.oxen/arch/arm/mmu/setup.c new file +0
-0
xen/arch/arm/mmu/setup.c line 5
Quoted 5 lines
xen/arch/arm/mmu/setup.c new file +5
-0@@ -0,0 +1,339 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* xen/arch/arm/mmu/setup.c +* +* MMU-specific early bringup code for an ARMv7-A with virt extensions.
You modify the comment in arm/setup.c to mention ARMv8 but not here. The former feels somewhat unrelated.
xen/arch/arm/mmu/setup.c line 18
Quoted 13 lines
xen/arch/arm/mmu/setup.c new file +13
-0+*/ + +#include <xen/init.h> +#include <xen/serial.h> +#include <xen/libfdt/libfdt-xen.h> +#include <xen/mm.h> +#include <xen/param.h> +#include <xen/pfn.h> +#include <asm/fixmap.h> +#include <asm/page.h> +#include <asm/setup.h> + +#ifdef CONFIG_ARM_32
AFAICT, mmu/mm.c has nothing common between arm32 and arm64. So can we introduce arm{32, 64}/mmu/setup.c and move the respective code there?
[...]
Quoted 4 lines
xen/arch/arm/mmu/setup.c new file +4
-0+void __init setup_mm (void ) +{ +paddr_t ram_start, ram_end, ram_size, e, bank_start, bank_end, bank_size; +paddr_t static_heap_end =0 , static_heap_size =0 ;
xen/arch/arm/mmu/setup.c line 165
Quoted 10 lines
xen/arch/arm/mmu/setup.c new file +10
-0+unsigned long heap_pages, xenheap_pages, domheap_pages; +unsigned int i; +const uint32_t ctr =READ_CP32 (CTR ); + +if ( !bootinfo.mem.nr_banks ) +panic ("No memory bank\n" ); + +/* We only supports instruction caches implementing the IVIPT extension. */ +if ( ((ctr >>CTR_L1IP_SHIFT ) &CTR_L1IP_MASK ) ==ICACHE_POLICY_AIVIVT ) +panic ("AIVIVT instruction cache not supported\n" );
Thi check is unlikely going to be MMU setup.c.
Quoted 39 lines
xen/arch/arm/mmu/setup.c new file +39
-0+ +init_pdx (); + + ram_start = bootinfo.mem.bank[0 ].start; + ram_size = bootinfo.mem.bank[0 ].size; + ram_end = ram_start + ram_size; + +for ( i =1 ; i < bootinfo.mem.nr_banks; i++ ) + { + bank_start = bootinfo.mem.bank[i].start; + bank_size = bootinfo.mem.bank[i].size; + bank_end = bank_start + bank_size; + + ram_size = ram_size + bank_size; + ram_start =min (ram_start,bank_start); + ram_end =max (ram_end,bank_end); + } + + total_pages = ram_size >>PAGE_SHIFT ; + +if ( bootinfo.static_heap ) + { +for ( i =0 ; i < bootinfo.reserved_mem.nr_banks; i++ ) + { +if ( bootinfo.reserved_mem.bank[i].type !=MEMBANK_STATIC_HEAP ) +continue ; + + bank_start = bootinfo.reserved_mem.bank[i].start; + bank_size = bootinfo.reserved_mem.bank[i].size; + bank_end = bank_start + bank_size; + + static_heap_size += bank_size; + static_heap_end =max (static_heap_end, bank_end); + } + + heap_pages = static_heap_size >>PAGE_SHIFT ; + } +else + heap_pages = total_pages;
xen/arch/arm/mmu/setup.c line 214
Quoted 10 lines
xen/arch/arm/mmu/setup.c new file +10
-0+ +/* +* If the user has not requested otherwise via the command line +* then locate the xenheap using these constraints: +* +* - must be contiguous +* - must be 32 MiB aligned +* - must not include Xen itself or the boot modules +* - must be at most 1GB or 1/32 the total RAM in the system (or static +heap if enabled) if less
While you are moving the code can you add '*'? Could be done as a follow-up patch as well.
[...[
Quoted 13 lines
xen/arch/arm/mmu/setup.c new file +8
-0+/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/ xen/arch/arm/setup.c +0
-0
xen/arch/arm/setup.c line 5
Quoted 5 lines
xen/arch/arm/setup.c +1
-1@@ -2,7 +2,7 @@/* * xen/arch/arm/setup.c * -* Early bringup code for an ARMv7-A with virt extensions. +* Early bringup code for an ARMv7-A/ARM64v8R with virt extensions.
You are not yet supporting ARMv8-R. But we are supporting ARMv8-A which is not mentioned here. That said, I don't really the benefits of mentioning the major revision of the Arm Arm we support. For instance, we are likely going to be able to boot on Armv9.
So I would just remove anything from 'for'.
Cheers,
Signature · 1 line
Julien Grall
PATCH v5 11/13 xen/arm: mmu: move MMU specific P2M code to mmu/p2m.{c,h}
In reply to Henry WangFrom: Penny Zheng <[email protected]>
Current P2M implementation is designed for MMU system only. We move the MMU-specific codes into mmu/p2m.c, and only keep generic codes in p2m.c, like VMID allocator, etc. We also move MMU-specific definitions and declarations to mmu/p2m.h, such as p2m_tlb_flush_sync(). Also expose previously static functions p2m_vmid_allocator_init(), p2m_alloc_vmid(), __p2m_set_entry() and setup_virt_paging_one() for futher MPU usage.
With the code movement, global variable max_vmid is used in multiple files instead of a single file (and will be used in MPU P2M implementation), declare it in the header and remove the "static" of this variable.
Add #ifdef CONFIG_HAS_MMU to p2m_write_unlock() since future MPU work does not need p2m_tlb_flush_sync().
---
v5:
- No change
v4:
- Rework the patch to drop the unnecessary changes.
- Rework the commit msg a bit.
v3:
- remove MPU stubs
- adapt to the introduction of new directories: mmu/ v2:
- new commit
--- xen/arch/arm/include/asm/mmu/p2m.h | 18 + xen/arch/arm/include/asm/p2m.h | 33 +- xen/arch/arm/mmu/Makefile | 1 + xen/arch/arm/mmu/p2m.c | 1610 +++++++++++++++++++++++++ xen/arch/arm/p2m.c | 1772 ++-------------------------- 5 files changed, 1745 insertions(+), 1689 deletions(-) create mode 100644 xen/arch/arm/include/asm/mmu/p2m.h create mode 100644 xen/arch/arm/mmu/p2m.c
xen/arch/arm/include/asm/mmu/p2m.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef __ARM_MMU_P2M_H__ +#define __ARM_MMU_P2M_H__ + +struct p2m_domain ; +void p2m_force_tlb_flush_sync (struct p2m_domain *p2m); +void p2m_tlb_flush_sync (struct p2m_domain *p2m); + +#endif /* __ARM_MMU_P2M_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
xen/arch/arm/include/asm/p2m.h +31 -2
@@ -19,6 +19,22 @@ extern unsigned int p2m_root_level;#define P2M_ROOT_ORDER p2m_root_order#define P2M_ROOT_LEVEL p2m_root_level +#define MAX_VMID_8_BIT (1UL << 8) +#define MAX_VMID_16_BIT (1UL << 16) + +#define INVALID_VMID 0/* VMID 0 is reserved */ + +#ifdef CONFIG_ARM_64 +extern unsigned int max_vmid; +/* VMID is by default 8 bit width on AArch64 */ +#define MAX_VMID max_vmid +#else +/* VMID is always 8 bit width on AArch32 */ +#define MAX_VMID MAX_VMID_8_BIT +#endif + +#define P2M_ROOT_PAGES (1<<P2M_ROOT_ORDER) +struct domain ;extern void memory_type_changed (struct domain *);
@@ -156,6 +172,10 @@ typedef enum {#endif #include <xen/p2m-common.h> +#ifdef CONFIG_MMU +#include <asm/mmu/p2m.h> +#endif +static inline bool arch_acquire_resource_check (struct domain *d) {/*
@@ -180,7 +200,11 @@ void p2m_altp2m_check(struct vcpu *v, uint16_t idx)*/ void p2m_restrict_ipa_bits (unsigned int ipa_bits); +void p2m_vmid_allocator_init (void ); +int p2m_alloc_vmid (struct domain *d); +/* Second stage paging setup, to be called on all CPUs */ +void setup_virt_paging_one (void *data);void setup_virt_paging (void );/* Init the datastructures for later use by the p2m code */
@@ -242,8 +266,6 @@ static inline int p2m_is_write_locked(struct p2m_domain *p2m)return rw_is_write_locked (&p2m->lock); } -void p2m_tlb_flush_sync (struct p2m_domain *p2m); -/* Look up the MFN corresponding to a domain's GFN. */ mfn_t p2m_lookup (struct domain *d,gfn_t gfn,p2m_type_t *t);
@@ -269,6 +291,13 @@ int p2m_set_entry(struct p2m_domain *p2m,p2m_type_t t, p2m_access_t a); +int __p2m_set_entry (struct p2m_domain *p2m, +gfn_t sgfn, +unsigned int page_order, +mfn_t smfn, +p2m_type_t t, +p2m_access_t a); +bool p2m_resolve_translation_fault (struct domain *d,gfn_t gfn);void p2m_clear_root_pages (struct p2m_domain *p2m);
xen/arch/arm/mmu/Makefile +1 -0
@@ -1,2 +1,3 @@ obj-y += mm.o +obj-y += p2m.o obj-y += setup.o
xen/arch/arm/mmu/p2m.c new file +1610 -0
1,610 lines not on this page · raw message
xen/arch/arm/p2m.c +85 -1687
1,305 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.25.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH v5 11/13] xen/arm: mmu: move MMU specific P2M code to mmu/p2m.{c,h}
Hi Henry,
Quoted 8 lines · Henry Wang
From: Penny Zheng <[email protected]>
Current P2M implementation is designed for MMU system only. We move the MMU-specific codes into
mmu/p2m.c, and only keep generic codes inp2m.c, like VMID allocator, etc. We also move MMU-specific definitions and declarations tommu/p2m.h, such asp2m_tlb_flush_sync(). Also expose previously static functionsp2m_vmid_allocator_init(),p2m_alloc_vmid(),__p2m_set_entry()andsetup_virt_paging_one()
Looking at the code, it seemsm that you need to keep expose __p2m_set_entry() because of p2m_relinquish_mapping(). However, it is not clear how this code is supposed to work for the MPU. So should we instead from p2m_relinquish_mapping() to mmu/p2m.c?
Other functions which doesn't seem to make sense in p2m.c are:
* p2m_clear_root_pages(): AFAIU there is no concept of root in the
MPU. This also means that we possibly want to move out anything specific to the MMU from 'struct p2m'. This could be done separately.
* p2m_flush_vm(): This is built with MMU in mind as we can use the
page-table to track access pages. You don't have that fine granularity in the MPU.
Quoted 1 line
for futher MPU usage.
typo: futher/further/
Quoted 8 lines
With the code movement, global variable
max_vmidis used in multiple files instead of a single file (and will be used in MPU P2M implementation), declare it in the header and remove the "static" of this variable.Add #ifdef
CONFIG_HAS_MMUtop2m_write_unlock()since future MPU work does not needp2m_tlb_flush_sync().
And there are no specific barrier required? Overall, I am not sure I like the #ifdef rather than providing a stub helper.
If the other like the idea of the #ifdef. I think a comment on top would be necessary to explain why there is nothing to do in the context of the MPU.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 11/13] xen/arm: mmu: move MMU specific P2M code to mmu/p2m.{c,h}
Hi Julien,
Quoted 13 lines · Julien Grall
Hi Henry,
Quoted 7 lines · Henry Wang
From: Penny Zheng <[email protected]>
Current P2M implementation is designed for MMU system only. We move the MMU-specific codes intommu/p2m.c, and only keep generic codes inp2m.c, like VMID allocator, etc. We also move MMU-specific definitions and declarations tommu/p2m.h, such asp2m_tlb_flush_sync(). Also expose previously static functionsp2m_vmid_allocator_init(),p2m_alloc_vmid(),__p2m_set_entry()andsetup_virt_paging_one()
Quoted 1 line
Looking at the code, it seemsm that you need to keep expose
__p2m_set_entry()because ofp2m_relinquish_mapping(). However, it is not clear how this code is supposed to work for the MPU. So should we instead fromp2m_relinquish_mapping()tommu/p2m.c?
Sure, I will try that.
Quoted 4 lines
Other functions which doesn't seem to make sense in
p2m.care:
*p2m_clear_root_pages(): AFAIU there is no concept of root in the MPU. This also means that we possibly want to move out anything specific to the MMU from 'struct p2m'. This could be done separately.
*p2m_flush_vm(): This is built with MMU in mind as we can use the page-table to track access pages. You don't have that fine granularity in the MPU.
I agree, will also move these to mmu/ in v6.
Quoted 4 lines
Quoted 2 lines
for futher MPU usage.
typo: futher/further/
Thanks, will fix.
Quoted 9 lines
Quoted 7 lines
With the code movement, global variable
max_vmidis used in multiple files instead of a single file (and will be used in MPU P2M implementation), declare it in the header and remove the "static" of this variable.
Add #ifdefCONFIG_HAS_MMUtop2m_write_unlock()since future MPU work does not needp2m_tlb_flush_sync().And there are no specific barrier required? Overall, I am not sure I like the #ifdef rather than providing a stub helper.
I think for MPU systems we don’t need to flush the TLB, hence the #ifdef. Do you mean we should provide a stub helper of p2m_tlb_flush_sync() for MPU? If so I think maybe the naming of this stub helper is not really ideal?
Kind regards,
Henry
Quoted 7 lines
If the other like the idea of the #ifdef. I think a comment on top would be necessary to explain why there is nothing to do in the context of the MPU.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 11/13] xen/arm: mmu: move MMU specific P2M code to mmu/p2m.{c,h}
Quoted 1 line · Henry Wang
Hi Julien,
Hi Henry,
Quoted 39 lines
Quoted 13 lines · Julien Grall
Hi Henry,
Quoted 7 lines · Henry Wang
From: Penny Zheng <[email protected]>
Current P2M implementation is designed for MMU system only. We move the MMU-specific codes intommu/p2m.c, and only keep generic codes inp2m.c, like VMID allocator, etc. We also move MMU-specific definitions and declarations tommu/p2m.h, such asp2m_tlb_flush_sync(). Also expose previously static functionsp2m_vmid_allocator_init(),p2m_alloc_vmid(),__p2m_set_entry()andsetup_virt_paging_one()Quoted 1 line
Looking at the code, it seemsm that you need to keep expose
__p2m_set_entry()because ofp2m_relinquish_mapping(). However, it is not clear how this code is supposed to work for the MPU. So should we instead fromp2m_relinquish_mapping()tommu/p2m.c?Sure, I will try that.
Quoted 4 lines
Other functions which doesn't seem to make sense in
p2m.care:
*p2m_clear_root_pages(): AFAIU there is no concept of root in the MPU. This also means that we possibly want to move out anything specific to the MMU from 'struct p2m'. This could be done separately.
*p2m_flush_vm(): This is built with MMU in mind as we can use the page-table to track access pages. You don't have that fine granularity in the MPU.I agree, will also move these to mmu/ in v6.
Quoted 4 lines
Quoted 2 lines
for futher MPU usage.
typo: futher/further/
Thanks, will fix.
Quoted 8 lines
Quoted 7 lines
With the code movement, global variable
max_vmidis used in multiple files instead of a single file (and will be used in MPU P2M implementation), declare it in the header and remove the "static" of this variable.
Add #ifdefCONFIG_HAS_MMUtop2m_write_unlock()since future MPU work does not needp2m_tlb_flush_sync().
Quoted 3 lines
Quoted 1 line
And there are no specific barrier required? Overall, I am not sure I like the #ifdef rather than providing a stub helper.
I think for MPU systems we don’t need to flush the TLB, hence the #ifdef.
I wasn't necessarily thinking about a TLB flush but instead a DSB/DMB. At least for the MMU case, I think that in theory we need a DSB when the there is no TLB flush to ensure new entry in the page-tables are seen before p2m_write_unlock() completes.
So far we are getting away because write_pte() always have a barrier after. But at some point, I would like to remove it as this is a massive hammer.
Quoted 3 lines
Do you mean we should
provide a stub helper ofp2m_tlb_flush_sync()for MPU? If so I think maybe the naming of this stub helper is not really ideal?
See above. I am trying to understand the expected sequence when updating the MPU tables. Are you going to add barriers after every update to the entry?
Having an helper would also be a good place to explain why some synchronization is not needed. I am not sure about a name though.
Maybe p2m_sync() and p2m_force_sync()?
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 11/13] xen/arm: mmu: move MMU specific P2M code to mmu/p2m.{c,h}
Hi,
Quoted 13 lines · Julien Grall
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
With the code movement, global variable
max_vmidis used in multiple files instead of a single file (and will be used in MPU P2M implementation), declare it in the header and remove the "static" of this variable.
Add #ifdefCONFIG_HAS_MMUtop2m_write_unlock()since future MPU work does not needp2m_tlb_flush_sync().And there are no specific barrier required? Overall, I am not sure I like the #ifdef rather than providing a stub helper.
I think for MPU systems we don’t need to flush the TLB, hence the #ifdef.
I wasn't necessarily thinking about a TLB flush but instead a DSB/DMB. At least for the MMU case, I think that in theory we need a DSB when the there is no TLB flush to ensure new entry in the page-tables are seen before
p2m_write_unlock()completes.
Quoted 7 lines
So far we are getting away because
write_pte()always have a barrier after. But at some point, I would like to remove it as this is a massive hammer.Quoted 3 lines
Do you mean we should
provide a stub helper ofp2m_tlb_flush_sync()for MPU? If so I think maybe the naming of this stub helper is not really ideal?See above. I am trying to understand the expected sequence when updating the MPU tables. Are you going to add barriers after every update to the entry?
I have looked at your branch mpu_v5. In theory the P2M can be modified at any point of the life-cycle of the domain. This means that another pCPU may have the regions loaded.
If that's the case then you would likely want to ensure the entries are synchronized. The easiest way would be to pause/unpause the domain when taking/releasing the lock. There might be other way, but this indicates that helper would be needed for the MPU.
That said, it is not clear to me if there is any use-case where you would want to update the P2M at runtime. If you have known, then you might be able to simply return an error if the P2M is modified after the domain was created.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 11/13] xen/arm: mmu: move MMU specific P2M code to mmu/p2m.{c,h}
In reply to Julien GrallHi Julien
Quoted 5 lines · Julien Grall
Hi Henry,
Quoted 2 lines · Henry Wang
From: Penny Zheng <[email protected]>
Quoted 9 lines
Quoted 6 lines
Current P2M implementation is designed for MMU system only. We move the MMU-specific codes into
mmu/p2m.c, and only keep generic codes inp2m.c, like VMID allocator, etc. We also move MMU-specific definitions and declarations tommu/p2m.h, such asp2m_tlb_flush_sync(). Also expose previously static functionsp2m_vmid_allocator_init(),p2m_alloc_vmid(),__p2m_set_entry()andsetup_virt_paging_one()Looking at the code, it seemsm that you need to keep expose
__p2m_set_entry()because ofp2m_relinquish_mapping(). However, it is not clear how this code is supposed to work for the MPU. So should we instead fromp2m_relinquish_mapping()tommu/p2m.c?
p2m->root stores per-domain P2M table, which is actually an array of MPU region(pr_t). So maybe we should relinquish mapping region by region, instead of page by page. Nevertheless, p2m_relinquish_mapping() shall be moved to mmu/p2m.c and we need MPU version of it.
Quoted 3 lines
Other functions which doesn't seem to make sense in
p2m.care:
*p2m_clear_root_pages(): AFAIU there is no concept of root in the
MPU. This also means that we possibly want to move out anything specific to the MMU from 'struct p2m'. This could be done separately.
Current MPU implementation is re-using p2m->root to store P2M table.
Do you agree on this, or should we create a new variable, like p2m->mpu_table, for MPU P2M table only? How we treat p2m_clear_root_pages also decides how we destroy P2M at domain destruction stage, current MPU flow is as follows:
```
PROGRESS(mapping):
ret = relinquish_p2m_mapping(d);
if ( ret )
return ret;
PROGRESS(p2m_root):
/*
* We are about to free the intermediate page-tables, so clear the
* root to prevent any walk to use them.
*/
p2m_clear_root_pages(&d->arch.p2m);
#ifdef CONFIG_HAS_PAGING_MEMPOOL
PROGRESS(p2m):
ret = p2m_teardown(d);
if ( ret )
return ret;
PROGRESS(p2m_pool):
ret = p2m_teardown_allocation(d);
if( ret )
return ret;
#endif
```We guard MMU-specific intermediate page-tables destroy with the new Kconfig CONFIG_HAS_PAGING_MEMPOOL, check https://gitlab.com/xen-project/people/henryw/xen/-/commit/7ff6d351e65f43fc34ea694adea0e030a51b1576
for more details.
If we destroy MPU P2M table in relinquish_p2m_mapping, region by region, we could provide empty stub for p2m_clear_root_pages, and move it to mmu/p2m.c
Quoted 3 lines
*
p2m_flush_vm(): This is built with MMU in mind as we can use the
page-table to track access pages. You don't have that fine granularity in the MPU.
Understood
Quoted 19 lines
Quoted 1 line
for futher MPU usage.
typo: futher/further/
Quoted 8 lines
With the code movement, global variable
max_vmidis used in multiple files instead of a single file (and will be used in MPU P2M implementation), declare it in the header and remove the "static" of this variable.Add #ifdef
CONFIG_HAS_MMUtop2m_write_unlock()since future MPU work does not needp2m_tlb_flush_sync().And there are no specific barrier required? Overall, I am not sure I like the #ifdef rather than providing a stub helper.
If the other like the idea of the #ifdef. I think a comment on top would be necessary to explain why there is nothing to do in the context of the MPU.
Cheers,
Re: [PATCH v5 11/13] xen/arm: mmu: move MMU specific P2M code to mmu/p2m.{c,h}
Quoted 1 line · Penny Zheng
Hi Julien
Hi Penny,
Quoted 21 lines · Julien Grall
Quoted 5 lines
Hi Henry,
Quoted 2 lines · Henry Wang
From: Penny Zheng <[email protected]>
Quoted 9 lines
Quoted 6 lines
Current P2M implementation is designed for MMU system only. We move the MMU-specific codes into
mmu/p2m.c, and only keep generic codes inp2m.c, like VMID allocator, etc. We also move MMU-specific definitions and declarations tommu/p2m.h, such asp2m_tlb_flush_sync(). Also expose previously static functionsp2m_vmid_allocator_init(),p2m_alloc_vmid(),__p2m_set_entry()andsetup_virt_paging_one()Looking at the code, it seemsm that you need to keep expose
__p2m_set_entry()because ofp2m_relinquish_mapping(). However, it is not clear how this code is supposed to work for the MPU. So should we instead fromp2m_relinquish_mapping()tommu/p2m.c?
p2m->rootstores per-domain P2M table, which is actually an array of MPUregion(pr_t). So maybe we should relinquish mapping region by region, instead of page by page. Nevertheless,p2m_relinquish_mapping()shall be moved tommu/p2m.cand we need MPU version of it.
Quoted 5 lines
Quoted 2 lines
Other functions which doesn't seem to make sense in
p2m.care:
*p2m_clear_root_pages(): AFAIU there is no concept of root in the MPU. This also means that we possibly want to move out anything specific to the MMU from 'struct p2m'. This could be done separately.Current MPU implementation is re-using
p2m->rootto store P2M table.
Do you agree on this, or should we create a new variable, likep2m->mpu_table, for MPU P2M table only?
I have looked at the mpu_v5 tree to check how you use p2m->root. The common pattern is:
table = (pr_t *)page_to_virt(p2m->root);
AFAICT the "root" is always mapped in your case. So this is a bit inneficient to have to convert from a page to virt every single time you need to modify the P2M.
Therefore it would be better to introduce something more specific to the MPU. Rather than introduce a field in the structure p2m, it would be better if we introduce a structure that would be defined in {mmu,mpu}/p2m.h, would include there specific fields and be embedded in struct p2m.
Quoted 26 lines
How we treat
p2m_clear_root_pagesalso decides how we destroy P2M at domain destruction stage, current MPU flow is as follows:``` PROGRESS(mapping): ret = relinquish_p2m_mapping(d); if ( ret ) return ret; PROGRESS(p2m_root): /* * We are about to free the intermediate page-tables, so clear the * root to prevent any walk to use them. */ p2m_clear_root_pages(&d->arch.p2m); #ifdef CONFIG_HAS_PAGING_MEMPOOL PROGRESS(p2m): ret = p2m_teardown(d); if ( ret ) return ret; PROGRESS(p2m_pool): ret = p2m_teardown_allocation(d); if( ret ) return ret; #endif ```
Quoted 4 lines
We guard MMU-specific intermediate page-tables destroy with the new
KconfigCONFIG_HAS_PAGING_MEMPOOL, check https://gitlab.com/xen-project/people/henryw/xen/-/commit/7ff6d351e65f43fc34ea694adea0e030a51b1576
for more details.If we destroy MPU P2M table in
relinquish_p2m_mapping, region by region,
It would seem to be better to handle it region by region. Note that you will still need to handle preemption and that may happen in the middle of the region (in particular if they are big).
Cheers,
Signature · 1 line
Julien Grall
PATCH v5 12/13 xen/arm: mmu: relocate copy_from_paddr() to setup.c
In reply to Henry WangFrom: Penny Zheng <[email protected]>
Function copy_from_paddr() is defined in asm/setup.h, so it is better to be implemented in setup.c.
Current copy_from_paddr() implementation is mmu-specific, so this commit moves copy_from_paddr() into mmu/setup.c, and it is also benefical for us to implement MPU version of copy_from_paddr() in later commit.
---
v5:
- No change
v4:
- No change
v3:
- new commit
--- xen/arch/arm/kernel.c | 27 --------------------------- xen/arch/arm/mmu/setup.c | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 27 deletions(-)
xen/arch/arm/kernel.c +0 -27
@@ -41,33 +41,6 @@ struct minimal_dtb_header {#define DTB_MAGIC 0xd00dfeedU -/** -* copy_from_paddr - copy data from a physical address -* @dst: destination virtual address -* @paddr: source physical address -* @len: length to copy -*/ -void __init copy_from_paddr (void *dst,paddr_t paddr,unsigned long len) -{ -void *src = (void *)FIXMAP_ADDR (FIXMAP_MISC ); - -while (len) { -unsigned long l, s; - - s = paddr & (PAGE_SIZE -1 ); - l =min (PAGE_SIZE - s, len); - -set_fixmap (FIXMAP_MISC ,maddr_to_mfn (paddr),PAGE_HYPERVISOR_WC ); -memcpy (dst, src + s, l); -clean_dcache_va_range (dst, l); -clear_fixmap (FIXMAP_MISC ); - - paddr += l; - dst += l; - len -= l; - } -} -static void __init place_modules (struct kernel_info *info,paddr_t kernbase,paddr_t kernend) {
xen/arch/arm/mmu/setup.c +27 -0
@@ -329,6 +329,33 @@ void __init setup_mm(void) }#endif +/* +* copy_from_paddr - copy data from a physical address +* @dst: destination virtual address +* @paddr: source physical address +* @len: length to copy +*/ +void __init copy_from_paddr (void *dst,paddr_t paddr,unsigned long len) +{ +void *src = (void *)FIXMAP_ADDR (FIXMAP_MISC ); + +while (len) { +unsigned long l, s; + + s = paddr & (PAGE_SIZE -1 ); + l =min (PAGE_SIZE - s, len); + +set_fixmap (FIXMAP_MISC ,maddr_to_mfn (paddr),PAGE_HYPERVISOR_WC ); +memcpy (dst, src + s, l); +clean_dcache_va_range (dst, l); +clear_fixmap (FIXMAP_MISC ); + + paddr += l; + dst += l; + len -= l; + } +} +/* * Local variables: * mode: C
Signature · 1 line
2.25.1
Re: [PATCH v5 12/13] xen/arm: mmu: relocate copy_from_paddr() to setup.c
Hi,
Quoted 4 lines · Henry Wang
From: Penny Zheng <[email protected]>
Function
copy_from_paddr()is defined inasm/setup.h, so it is better to be implemented insetup.c.
I don't agree with this reasoning. We used setup.h to declare prototype for function that are out of setup.c.
Looking at the overall of this series, it is unclear to me what is the difference between mmu/mm.c and mmu/setup.c. I know this is technically not a new problem but as we split the code, it would be a good opportunity to have a better split.
For instance, we have setup_mm() defined in setup.c but setup_pagetables() and mm.c. Both are technically related to the memory management. So having them in separate file is a bit odd.
I also don't like the idea of having again a massive mm.c files. So maybe we need a split like:
* File 1: Boot CPU0 MM bringup (mmu/setup.c)
* File 2: Secondary CPUs MM bringup (mmu/smpboot.c)
* File 3: Page tables update. (mmu/pt.c)
Ideally file 1 should contain only init code/data so it can be marked as .init. So the static pagetables may want to be defined in mmu/pt.c.
Bertrand, Stefano, any thoughts?
[...]
xen/arch/arm/mmu/setup.c void __init setup_mm(void) · line 332
Quoted 9 lines
xen/arch/arm/mmu/setup.c +1
-0@@ -329,6 +329,33 @@ void __init setup_mm(void) }#endif +/*
Why did the second '*' disappear?
Quoted 19 lines
xen/arch/arm/mmu/setup.c +19
-0+* copy_from_paddr - copy data from a physical address +* @dst: destination virtual address +* @paddr: source physical address +* @len: length to copy +*/ +void __init copy_from_paddr (void *dst,paddr_t paddr,unsigned long len) +{ +void *src = (void *)FIXMAP_ADDR (FIXMAP_MISC ); + +while (len) { +unsigned long l, s; + + s = paddr & (PAGE_SIZE -1 ); + l =min (PAGE_SIZE - s, len); + +set_fixmap (FIXMAP_MISC ,maddr_to_mfn (paddr),PAGE_HYPERVISOR_WC ); +memcpy (dst, src + s, l); +clean_dcache_va_range (dst, l); +clear_fixmap (FIXMAP_MISC );
xen/arch/arm/mmu/setup.c void __init setup_mm(void) · line 361
Quoted 10 lines
xen/arch/arm/mmu/setup.c +7
-0+ + paddr += l; + dst += l; + len -= l; + } +} +/* * Local variables: * mode: C
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 12/13] xen/arm: mmu: relocate copy_from_paddr() to setup.c
Hi Julien, Stefano, Bertrand,
Quoted 9 lines · Julien Grall
Hi,
Quoted 3 lines · Henry Wang
From: Penny Zheng <[email protected]>
Functioncopy_from_paddr()is defined inasm/setup.h, so it is better to be implemented insetup.c.
Quoted 5 lines
I don't agree with this reasoning. We used
setup.hto declare prototype for function that are out ofsetup.c.Looking at the overall of this series, it is unclear to me what is the difference between
mmu/mm.candmmu/setup.c. I know this is technically not a new problem but as we split the code, it would be a good opportunity to have a better split.For instance, we have
setup_mm()defined insetup.cbutsetup_pagetables()andmm.c. Both are technically related to the memory management. So having them in separate file is a bit odd.
Skimming through the comments, it looks like we have a common problem in patch 7, 9, 10, 12 about how to move/split the code. So instead of having the discussion in each patch, I would like to propose that we can discuss all of these in a common place here.
Quoted 7 lines
I also don't like the idea of having again a massive
mm.cfiles. So maybe we need a split like:
* File 1: Boot CPU0 MM bringup (mmu/setup.c)
* File 2: Secondary CPUs MM bringup (mmu/smpboot.c)
* File 3: Page tables update. (mmu/pt.c)Ideally file 1 should contain only init code/data so it can be marked as .init. So the static pagetables may want to be defined in
mmu/pt.c.
So based on Julien’s suggestion, Penny and I worked a bit on the current functions in “arch/arm/mm.c” and we would like to propose below split scheme, would you please comment on if below makes sense to you, thanks!
"""
static void __init __maybe_unused build_assertions() -> arch/arm/mm.c static lpae_t *xen_map_table() -> mmu/pt.c static void xen_unmap_table() -> mmu/pt.c void dump_pt_walk() -> mmu/pt.c void dump_hyp_walk() -> mmu/pt.c lpae_t mfn_to_xen_entry() -> mmu/pt.c void set_fixmap() -> mmu/pt.c void clear_fixmap() -> mmu/pt.c void flush_page_to_ram() -> arch/arm/mm.c? lpae_t pte_of_xenaddr() -> mmu/pt.c void * __init early_fdt_map() -> mmu/setup.c void __init remove_early_mappings() -> mmu/setup.c static void xen_pt_enforce_wnx() -> mmu/pt.c, export it static void clear_table() -> mmu/smpboot.c void __init setup_pagetables() -> mmu/setup.c static void clear_boot_pagetables() -> mmu/smpboot.c int init_secondary_pagetables() -> mmu/smpboot.c void mmu_init_secondary_cpu() -> mmu/smpboot.c void __init setup_directmap_mappings() -> mmu/setup.c void __init setup_frametable_mappings() -> mmu/setup.c void *__init arch_vmap_virt_end() -> arch/arm/mm.c or mmu/setup.c? void *ioremap_attr() -> mmu/pt.c void *ioremap() -> mmu/pt.c static int create_xen_table() -> mmu/pt.c static int xen_pt_next_level() -> mmu/pt.c static bool xen_pt_check_entry() -> mmu/pt.c static int xen_pt_update_entry() -> mmu/pt.c static int xen_pt_mapping_level() -> mmu/pt.c static unsigned int xen_pt_check_contig() -> mmu/pt.c static int xen_pt_update() -> mmu/pt.c int map_pages_to_xen() -> mmu/pt.c int __init populate_pt_range() -> mmu/pt.c int destroy_xen_mappings() -> mmu/pt.c int modify_xen_mappings() -> mmu/pt.c void free_init_memory() -> mmu/setup.c void arch_dump_shared_mem_info() -> arch/arm/mm.c int steal_page() -> arch/arm/mm.c int page_is_ram_type() -> arch/arm/mm.c unsigned long domain_get_maximum_gpfn() -> arch/arm/mm.c void share_xen_page_with_guest() -> arch/arm/mm.c int xenmem_add_to_physmap_one() -> arch/arm/mm.c long arch_memory_op() -> arch/arm/mm.c static struct domain *page_get_owner_and_nr_reference() -> arch/arm/mm.c struct domain *page_get_owner_and_reference() -> arch/arm/mm.c void put_page_nr() -> arch/arm/mm.c void put_page() -> arch/arm/mm.c bool get_page_nr() -> arch/arm/mm.c bool get_page() -> arch/arm/mm.c int get_page_type() -> arch/arm/mm.c void put_page_type() -> arch/arm/mm.c int create_grant_host_mapping() -> arch/arm/mm.c int replace_grant_host_mapping() -> arch/arm/mm.c bool is_iomem_page() -> arch/arm/mm.c void clear_and_clean_page() -> arch/arm/mm.c unsigned long get_upper_mfn_bound() -> arch/arm/mm.c
"""
Quoted 5 lines
Bertrand, Stefano, any thoughts?
[...]
Quoted 10 lines
xen/arch/arm/mmu/setup.c void __init setup_mm(void) · line 331
Quoted 8 lines
xen/arch/arm/mmu/setup.c +0
-0@@ -329,6 +329,33 @@ void __init setup_mm(void) }#endif +/*Why did the second '*' disappear?
According to the CODING_STYLE, we should use something like this:
/*
* Example, multi-line comment block.
*
* Note beginning and end markers on separate lines and leading '*'. */
Instead of "/**” in the beginning. But I think you made a point, I need to mention that I took the opportunity to fix the comment style in commit message.
Kind regards,
Henry
Quoted 14 lines
xen/arch/arm/mmu/setup.c void __init setup_mm(void)
Quoted 9 lines
xen/arch/arm/mmu/setup.c +7
-0+* copy_from_paddr - copy data from a physical address +* @dst: destination virtual address +* @paddr: source physical address +* @len: length to copy +*/ +void __init copy_from_paddr (void *dst,paddr_t paddr,unsigned long len) +{Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 12/13] xen/arm: mmu: relocate copy_from_paddr() to setup.c
Quoted 11 lines · Henry Wang
Quoted 11 lines · Julien Grall
Hi,
Quoted 3 lines · Henry Wang
From: Penny Zheng <[email protected]>
Functioncopy_from_paddr()is defined inasm/setup.h, so it is better to be implemented insetup.c.I don't agree with this reasoning. We used
setup.hto declare prototype for function that are out ofsetup.c.
Quoted 8 lines
Quoted 3 lines
Looking at the overall of this series, it is unclear to me what is the difference between
mmu/mm.candmmu/setup.c. I know this is technically not a new problem but as we split the code, it would be a good opportunity to have a better split.For instance, we have
setup_mm()defined insetup.cbutsetup_pagetables()andmm.c. Both are technically related to the memory management. So having them in separate file is a bit odd.Skimming through the comments, it looks like we have a common problem in patch 7, 9, 10, 12 about how to move/split the code. So instead of having the discussion in each patch, I would like to propose that we can discuss all of these in a common place here.
+1.
Quoted 9 lines
Quoted 8 lines
I also don't like the idea of having again a massive
mm.cfiles. So maybe we need a split like:
* File 1: Boot CPU0 MM bringup (mmu/setup.c)
* File 2: Secondary CPUs MM bringup (mmu/smpboot.c)
* File 3: Page tables update. (mmu/pt.c)Ideally file 1 should contain only init code/data so it can be marked as .init. So the static pagetables may want to be defined in
mmu/pt.c.
Quoted 7 lines
So based on Julien’s suggestion, Penny and I worked a bit on the current functions in “arch/arm/mm.c” and we would like to propose below split scheme, would you please comment on if below makes sense to you, thanks!
"""
static void__init__maybe_unusedbuild_assertions()->arch/arm/mm.c
All the existing build assertions seems to be MMU specific. So shouldn't they be moved to mmu/mm.c.
Quoted 8 lines
static lpae_t *xen_map_table() -> mmu/pt.c static void xen_unmap_table() -> mmu/pt.c void dump_pt_walk() -> mmu/pt.c void dump_hyp_walk() -> mmu/pt.c lpae_t mfn_to_xen_entry() -> mmu/pt.c void set_fixmap() -> mmu/pt.c void clear_fixmap() -> mmu/pt.c void flush_page_to_ram() -> arch/arm/mm.c?
I think it should stay in arch/arm/mm.c because you will probably need to clean a page even on MPU systems.
Quoted 4 lines
lpae_t pte_of_xenaddr() -> mmu/pt.c void * __init early_fdt_map() -> mmu/setup.c void __init remove_early_mappings() -> mmu/setup.c static void xen_pt_enforce_wnx() -> mmu/pt.c, export it
AFAIU, it would be called from smpboot.c and setup.c. For the former, the caller is mmu_init_secondary_cpu() which I think can be folded in head.S.
If we do that, then xen_pt_enforce_wnx() can be moved in setup.c and doesn't need to be exported.
Quoted 8 lines
static void clear_table() -> mmu/smpboot.c void __init setup_pagetables() -> mmu/setup.c static void clear_boot_pagetables() -> mmu/smpboot.c int init_secondary_pagetables() -> mmu/smpboot.c void mmu_init_secondary_cpu() -> mmu/smpboot.c void __init setup_directmap_mappings() -> mmu/setup.c void __init setup_frametable_mappings() -> mmu/setup.c void *__init arch_vmap_virt_end() -> arch/arm/mm.c or mmu/setup.c?
AFAIU, the VMAP will not be used for MPU systems. So this would want to go in mmu/. I am ok with setup.c.
Quoted 34 lines
void *ioremap_attr() -> mmu/pt.c void *ioremap() -> mmu/pt.c static int create_xen_table() -> mmu/pt.c static int xen_pt_next_level() -> mmu/pt.c static bool xen_pt_check_entry() -> mmu/pt.c static int xen_pt_update_entry() -> mmu/pt.c static int xen_pt_mapping_level() -> mmu/pt.c static unsigned int xen_pt_check_contig() -> mmu/pt.c static int xen_pt_update() -> mmu/pt.c int map_pages_to_xen() -> mmu/pt.c int __init populate_pt_range() -> mmu/pt.c int destroy_xen_mappings() -> mmu/pt.c int modify_xen_mappings() -> mmu/pt.c void free_init_memory() -> mmu/setup.c void arch_dump_shared_mem_info() -> arch/arm/mm.c int steal_page() -> arch/arm/mm.c int page_is_ram_type() -> arch/arm/mm.c unsigned long domain_get_maximum_gpfn() -> arch/arm/mm.c void share_xen_page_with_guest() -> arch/arm/mm.c int xenmem_add_to_physmap_one() -> arch/arm/mm.c long arch_memory_op() -> arch/arm/mm.c static struct domain *page_get_owner_and_nr_reference() -> arch/arm/mm.c struct domain *page_get_owner_and_reference() -> arch/arm/mm.c void put_page_nr() -> arch/arm/mm.c void put_page() -> arch/arm/mm.c bool get_page_nr() -> arch/arm/mm.c bool get_page() -> arch/arm/mm.c int get_page_type() -> arch/arm/mm.c void put_page_type() -> arch/arm/mm.c int create_grant_host_mapping() -> arch/arm/mm.c int replace_grant_host_mapping() -> arch/arm/mm.c bool is_iomem_page() -> arch/arm/mm.c void clear_and_clean_page() -> arch/arm/mm.c unsigned long get_upper_mfn_bound() -> arch/arm/mm.c
Quoted 1 line
"""
The placement of all the ones I didn't comment on look fine to me. It would be good to have a second opinion from either Bertrand or Stefano before you start moving the functions.
Quoted 19 lines
Quoted 10 lines
xen/arch/arm/mmu/setup.c void __init setup_mm(void) · line 331
Quoted 8 lines
xen/arch/arm/mmu/setup.c +0
-0@@ -329,6 +329,33 @@ void __init setup_mm(void) }#endif +/*Why did the second '*' disappear?
According to the
CODING_STYLE, we should use something like this:/*
* Example, multi-line comment block.
*
* Note beginning and end markers on separate lines and leading '*'. */
Quoted 3 lines
Instead of "/**” in the beginning. But I think you made a point, I need to mention that I took the opportunity to fix the comment style in commit message.
We have started to use /** which I think is for Doxygen (see the PDX series). So I think the CODING_STYLE needs to be updated rather than removing the extra *.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 12/13] xen/arm: mmu: relocate copy_from_paddr() to setup.c
Hi Julien,
Quoted 107 lines · Julien Grall
Quoted 11 lines · Henry Wang
Quoted 11 lines · Julien Grall
Hi,
Quoted 3 lines · Henry Wang
From: Penny Zheng <[email protected]>
Functioncopy_from_paddr()is defined inasm/setup.h, so it is better to be implemented insetup.c.I don't agree with this reasoning. We used
setup.hto declare prototype for function that are out ofsetup.c.Quoted 7 lines
Quoted 3 lines
Looking at the overall of this series, it is unclear to me what is the difference between
mmu/mm.candmmu/setup.c. I know this is technically not a new problem but as we split the code, it would be a good opportunity to have a better split.For instance, we have
setup_mm()defined insetup.cbutsetup_pagetables()andmm.c. Both are technically related to the memory management. So having them in separate file is a bit odd.Skimming through the comments, it looks like we have a common problem in patch 7, 9, 10, 12 about how to move/split the code. So instead of having the discussion in each patch, I would like to propose that we can discuss all of these in a common place here.
+1.
Quoted 6 lines
Quoted 6 lines
I also don't like the idea of having again a massive
mm.cfiles. So maybe we need a split like:
* File 1: Boot CPU0 MM bringup (mmu/setup.c)
* File 2: Secondary CPUs MM bringup (mmu/smpboot.c)
* File 3: Page tables update. (mmu/pt.c)Quoted 7 lines
Quoted 1 line
Ideally file 1 should contain only init code/data so it can be marked as .init. So the static pagetables may want to be defined in
mmu/pt.c.So based on Julien’s suggestion, Penny and I worked a bit on the current functions in “arch/arm/mm.c” and we would like to propose below split scheme, would you please comment on if below makes sense to you, thanks!
"""
static void__init__maybe_unusedbuild_assertions()->arch/arm/mm.cAll the existing build assertions seems to be MMU specific. So shouldn't they be moved to
mmu/mm.c.Quoted 8 lines
static lpae_t *xen_map_table() -> mmu/pt.c static void xen_unmap_table() -> mmu/pt.c void dump_pt_walk() -> mmu/pt.c void dump_hyp_walk() -> mmu/pt.c lpae_t mfn_to_xen_entry() -> mmu/pt.c void set_fixmap() -> mmu/pt.c void clear_fixmap() -> mmu/pt.c void flush_page_to_ram() -> arch/arm/mm.c?I think it should stay in
arch/arm/mm.cbecause you will probably need to clean a page even on MPU systems.Quoted 4 lines
lpae_t pte_of_xenaddr() -> mmu/pt.c void * __init early_fdt_map() -> mmu/setup.c void __init remove_early_mappings() -> mmu/setup.c static void xen_pt_enforce_wnx() -> mmu/pt.c, export itAFAIU, it would be called from
smpboot.candsetup.c. For the former, the caller ismmu_init_secondary_cpu()which I think can be folded inhead.S.If we do that, then
xen_pt_enforce_wnx()can be moved insetup.cand doesn't need to be exported.Quoted 8 lines
static void clear_table() -> mmu/smpboot.c void __init setup_pagetables() -> mmu/setup.c static void clear_boot_pagetables() -> mmu/smpboot.c int init_secondary_pagetables() -> mmu/smpboot.c void mmu_init_secondary_cpu() -> mmu/smpboot.c void __init setup_directmap_mappings() -> mmu/setup.c void __init setup_frametable_mappings() -> mmu/setup.c void *__init arch_vmap_virt_end() -> arch/arm/mm.c or mmu/setup.c?AFAIU, the VMAP will not be used for MPU systems. So this would want to go in mmu/. I am ok with
setup.c.Quoted 34 lines
void *ioremap_attr() -> mmu/pt.c void *ioremap() -> mmu/pt.c static int create_xen_table() -> mmu/pt.c static int xen_pt_next_level() -> mmu/pt.c static bool xen_pt_check_entry() -> mmu/pt.c static int xen_pt_update_entry() -> mmu/pt.c static int xen_pt_mapping_level() -> mmu/pt.c static unsigned int xen_pt_check_contig() -> mmu/pt.c static int xen_pt_update() -> mmu/pt.c int map_pages_to_xen() -> mmu/pt.c int __init populate_pt_range() -> mmu/pt.c int destroy_xen_mappings() -> mmu/pt.c int modify_xen_mappings() -> mmu/pt.c void free_init_memory() -> mmu/setup.c void arch_dump_shared_mem_info() -> arch/arm/mm.c int steal_page() -> arch/arm/mm.c int page_is_ram_type() -> arch/arm/mm.c unsigned long domain_get_maximum_gpfn() -> arch/arm/mm.c void share_xen_page_with_guest() -> arch/arm/mm.c int xenmem_add_to_physmap_one() -> arch/arm/mm.c long arch_memory_op() -> arch/arm/mm.c static struct domain *page_get_owner_and_nr_reference() -> arch/arm/mm.c struct domain *page_get_owner_and_reference() -> arch/arm/mm.c void put_page_nr() -> arch/arm/mm.c void put_page() -> arch/arm/mm.c bool get_page_nr() -> arch/arm/mm.c bool get_page() -> arch/arm/mm.c int get_page_type() -> arch/arm/mm.c void put_page_type() -> arch/arm/mm.c int create_grant_host_mapping() -> arch/arm/mm.c int replace_grant_host_mapping() -> arch/arm/mm.c bool is_iomem_page() -> arch/arm/mm.c void clear_and_clean_page() -> arch/arm/mm.c unsigned long get_upper_mfn_bound() -> arch/arm/mm.cQuoted 1 line
"""
Quoted 1 line
The placement of all the ones I didn't comment on look fine to me. It would be good to have a second opinion from either Bertrand or Stefano before you start moving the functions.
I agree to all your above comments, and sure I can wait for a few days for other maintainers opinion before start moving the code.
Quoted 21 lines
Quoted 11 lines
Quoted 11 lines
xen/arch/arm/mmu/setup.c void __init setup_mm(void) · line 331
Quoted 9 lines
xen/arch/arm/mmu/setup.c +0
-0@@ -329,6 +329,33 @@ void __init setup_mm(void) }#endif +/*Why did the second '*' disappear?
Quoted 9 lines
According to the
CODING_STYLE, we should use something like this:
/*
* Example, multi-line comment block.
*
* Note beginning and end markers on separate lines and leading '*'. */
Instead of "/**” in the beginning. But I think you made a point, I need to mention that I took the opportunity to fix the comment style in commit message.
Quoted 1 line
We have started to use /** which I think is for Doxygen (see the PDX series). So I think the
CODING_STYLEneeds to be updated rather than removing the extra *.
Ahhh thanks for the context, I totally forgot the Doxygen…Then I will use "/**” in v6.
Kind regards,
Henry
Quoted 5 lines
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 12/13] xen/arm: mmu: relocate copy_from_paddr() to setup.c
In reply to Julien GrallQuoted 29 lines · Julien Grall
Quoted 9 lines
Quoted 8 lines
I also don't like the idea of having again a massive
mm.cfiles. So maybe we need a split like:
* File 1: Boot CPU0 MM bringup (mmu/setup.c)
* File 2: Secondary CPUs MM bringup (mmu/smpboot.c)
* File 3: Page tables update. (mmu/pt.c)Ideally file 1 should contain only init code/data so it can be marked as .init. So the static pagetables may want to be defined in
mmu/pt.c.Quoted 7 lines
So based on Julien’s suggestion, Penny and I worked a bit on the current functions in “arch/arm/mm.c” and we would like to propose below split scheme, would you please comment on if below makes sense to you, thanks!
"""
static void__init__maybe_unusedbuild_assertions()->arch/arm/mm.cAll the existing build assertions seems to be MMU specific. So shouldn't they be moved to
mmu/mm.c.Quoted 8 lines
static lpae_t *xen_map_table() -> mmu/pt.c static void xen_unmap_table() -> mmu/pt.c void dump_pt_walk() -> mmu/pt.c void dump_hyp_walk() -> mmu/pt.c lpae_t mfn_to_xen_entry() -> mmu/pt.c void set_fixmap() -> mmu/pt.c void clear_fixmap() -> mmu/pt.c void flush_page_to_ram() -> arch/arm/mm.c?
Quoted 2 lines
I think it should stay in
arch/arm/mm.cbecause you will probably need to clean a page even on MPU systems.
I take you are referring to flush_page_to_ram() only, and not the other functions above
Quoted 6 lines
Quoted 5 lines
lpae_t pte_of_xenaddr() -> mmu/pt.c void * __init early_fdt_map() -> mmu/setup.c void __init remove_early_mappings() -> mmu/setup.c static void xen_pt_enforce_wnx() -> mmu/pt.c,export it
Quoted 9 lines
AFAIU, it would be called from
smpboot.candsetup.c. For the former, the caller ismmu_init_secondary_cpu()which I think can be folded inhead.S.If we do that, then
xen_pt_enforce_wnx()can be moved insetup.cand doesn't need to be exported.Quoted 3 lines
static void clear_table() -> mmu/smpboot.c void __init setup_pagetables() -> mmu/setup.c static void clear_boot_pagetables() -> mmu/smpboot.c
Why clear_table() and clear_boot_pagetables() in mmu/smpboot.c rather than mmu/setup.c ? It is OK either way as it does seem to make much of a difference but I am curious.
Quoted 46 lines
Quoted 6 lines
int init_secondary_pagetables() -> mmu/smpboot.c void mmu_init_secondary_cpu() -> mmu/smpboot.c void __init setup_directmap_mappings() -> mmu/setup.c void __init setup_frametable_mappings() -> mmu/setup.c void *__init arch_vmap_virt_end() -> arch/arm/mm.cor
mmu/setup.c?AFAIU, the VMAP will not be used for MPU systems. So this would want to go in mmu/. I am ok with
setup.c.Quoted 34 lines
void *ioremap_attr() -> mmu/pt.c void *ioremap() -> mmu/pt.c static int create_xen_table() -> mmu/pt.c static int xen_pt_next_level() -> mmu/pt.c static bool xen_pt_check_entry() -> mmu/pt.c static int xen_pt_update_entry() -> mmu/pt.c static int xen_pt_mapping_level() -> mmu/pt.c static unsigned int xen_pt_check_contig() -> mmu/pt.c static int xen_pt_update() -> mmu/pt.c int map_pages_to_xen() -> mmu/pt.c int __init populate_pt_range() -> mmu/pt.c int destroy_xen_mappings() -> mmu/pt.c int modify_xen_mappings() -> mmu/pt.c void free_init_memory() -> mmu/setup.c void arch_dump_shared_mem_info() -> arch/arm/mm.c int steal_page() -> arch/arm/mm.c int page_is_ram_type() -> arch/arm/mm.c unsigned long domain_get_maximum_gpfn() -> arch/arm/mm.c void share_xen_page_with_guest() -> arch/arm/mm.c int xenmem_add_to_physmap_one() -> arch/arm/mm.c long arch_memory_op() -> arch/arm/mm.c static struct domain *page_get_owner_and_nr_reference() -> arch/arm/mm.c struct domain *page_get_owner_and_reference() -> arch/arm/mm.c void put_page_nr() -> arch/arm/mm.c void put_page() -> arch/arm/mm.c bool get_page_nr() -> arch/arm/mm.c bool get_page() -> arch/arm/mm.c int get_page_type() -> arch/arm/mm.c void put_page_type() -> arch/arm/mm.c int create_grant_host_mapping() -> arch/arm/mm.c int replace_grant_host_mapping() -> arch/arm/mm.c bool is_iomem_page() -> arch/arm/mm.c void clear_and_clean_page() -> arch/arm/mm.c unsigned long get_upper_mfn_bound() -> arch/arm/mm.cQuoted 1 line
"""
Quoted 3 lines
The placement of all the ones I didn't comment on look fine to me. It would be good to have a second opinion from either Bertrand or Stefano before you start moving the functions.
It looks good in principle and it also looks like a great clean up. It is not always super clear to me the distinction between mmu/pt.c, mmu/smpboot.c and mmu/setup.c but it doesn't seem important. The distinction between mmu/* and arch/arm/mm.c is clear and looks fine to me.
I am looking forward to this!
Re: [PATCH v5 12/13] xen/arm: mmu: relocate copy_from_paddr() to setup.c
Hi Stefano,
Quoted 51 lines · Stefano Stabellini
Quoted 29 lines · Julien Grall
Quoted 9 lines
Quoted 8 lines
I also don't like the idea of having again a massive
mm.cfiles. So maybe we need a split like:
* File 1: Boot CPU0 MM bringup (mmu/setup.c)
* File 2: Secondary CPUs MM bringup (mmu/smpboot.c)
* File 3: Page tables update. (mmu/pt.c)Ideally file 1 should contain only init code/data so it can be marked as .init. So the static pagetables may want to be defined in
mmu/pt.c.Quoted 7 lines
So based on Julien’s suggestion, Penny and I worked a bit on the current functions in “arch/arm/mm.c” and we would like to propose below split scheme, would you please comment on if below makes sense to you, thanks!
"""
static void__init__maybe_unusedbuild_assertions()->arch/arm/mm.cAll the existing build assertions seems to be MMU specific. So shouldn't they be moved to
mmu/mm.c.Quoted 8 lines
static lpae_t *xen_map_table() -> mmu/pt.c static void xen_unmap_table() -> mmu/pt.c void dump_pt_walk() -> mmu/pt.c void dump_hyp_walk() -> mmu/pt.c lpae_t mfn_to_xen_entry() -> mmu/pt.c void set_fixmap() -> mmu/pt.c void clear_fixmap() -> mmu/pt.c void flush_page_to_ram() -> arch/arm/mm.c?Quoted 2 lines
I think it should stay in
arch/arm/mm.cbecause you will probably need to clean a page even on MPU systems.I take you are referring to
flush_page_to_ram()only, and not the other functions aboveQuoted 12 lines
Quoted 5 lines
lpae_t pte_of_xenaddr() -> mmu/pt.c void * __init early_fdt_map() -> mmu/setup.c void __init remove_early_mappings() -> mmu/setup.c static void xen_pt_enforce_wnx() -> mmu/pt.c,export it
AFAIU, it would be called from
smpboot.candsetup.c. For the former, the caller ismmu_init_secondary_cpu()which I think can be folded inhead.S.If we do that, then
xen_pt_enforce_wnx()can be moved insetup.cand doesn't need to be exported.
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
static void clear_table() -> mmu/smpboot.c void __init setup_pagetables() -> mmu/setup.c static void clear_boot_pagetables() -> mmu/smpboot.cWhy
clear_table()andclear_boot_pagetables()inmmu/smpboot.crather thanmmu/setup.c? It is OK either way as it does seem to make much of a difference but I am curious.
I think it is because below call sequence:init_secondary_mm() -> clear_boot_pagetables() -> clear_table()
We have the suggestion from Julien that:
"File 2: Secondary CPUs MM bringup (mmu/smpboot.c)”, and hence I suggested the smpboot.c
Quoted 10 lines
Quoted 4 lines
The placement of all the ones I didn't comment on look fine to me. It would be good to have a second opinion from either Bertrand or Stefano before you start moving the functions.
It looks good in principle and it also looks like a great clean up. It is not always super clear to me the distinction between
mmu/pt.c,mmu/smpboot.candmmu/setup.cbut it doesn't seem important. The distinction between mmu/* andarch/arm/mm.cis clear and looks fine to me.
I generally followed:
"* File 1: Boot CPU0 MM bringup (mmu/setup.c)
* File 2: Secondary CPUs MM bringup (mmu/smpboot.c)
* File 3: Page tables update. (mmu/pt.c)"
Quoted 2 lines
I am looking forward to this!
+1, will post the updated patch soon!
Kind regards,
Henry
Re: [PATCH v5 12/13] xen/arm: mmu: relocate copy_from_paddr() to setup.c
In reply to Stefano StabelliniHi Stefano,
Quoted 30 lines · Stefano Stabellini
Quoted 29 lines · Julien Grall
Quoted 9 lines
Quoted 8 lines
I also don't like the idea of having again a massive
mm.cfiles. So maybe we need a split like:
* File 1: Boot CPU0 MM bringup (mmu/setup.c)
* File 2: Secondary CPUs MM bringup (mmu/smpboot.c)
* File 3: Page tables update. (mmu/pt.c)Ideally file 1 should contain only init code/data so it can be marked as .init. So the static pagetables may want to be defined in
mmu/pt.c.Quoted 7 lines
So based on Julien’s suggestion, Penny and I worked a bit on the current functions in “arch/arm/mm.c” and we would like to propose below split scheme, would you please comment on if below makes sense to you, thanks!
"""
static void__init__maybe_unusedbuild_assertions()->arch/arm/mm.cAll the existing build assertions seems to be MMU specific. So shouldn't they be moved to
mmu/mm.c.Quoted 8 lines
static lpae_t *xen_map_table() -> mmu/pt.c static void xen_unmap_table() -> mmu/pt.c void dump_pt_walk() -> mmu/pt.c void dump_hyp_walk() -> mmu/pt.c lpae_t mfn_to_xen_entry() -> mmu/pt.c void set_fixmap() -> mmu/pt.c void clear_fixmap() -> mmu/pt.c void flush_page_to_ram() -> arch/arm/mm.c?
Quoted 5 lines
Quoted 2 lines
I think it should stay in
arch/arm/mm.cbecause you will probably need to clean a page even on MPU systems.I take you are referring to
flush_page_to_ram()only, and not the other functions above
That's correct.
Quoted 14 lines
Quoted 14 lines
Quoted 7 lines
lpae_t pte_of_xenaddr() -> mmu/pt.c void * __init early_fdt_map() -> mmu/setup.c void __init remove_early_mappings() -> mmu/setup.c static void xen_pt_enforce_wnx() -> mmu/pt.c,export it
AFAIU, it would be called from
smpboot.candsetup.c. For the former, the caller ismmu_init_secondary_cpu()which I think can be folded inhead.S.If we do that, then
xen_pt_enforce_wnx()can be moved insetup.cand doesn't need to be exported.
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
static void clear_table() -> mmu/smpboot.c void __init setup_pagetables() -> mmu/setup.c static void clear_boot_pagetables() -> mmu/smpboot.cWhy
clear_table()andclear_boot_pagetables()inmmu/smpboot.crather thanmmu/setup.c? It is OK either way as it does seem to make much of a difference but I am curious.
I initially wondered the same. But then I didn't comment because clear_boot_pagetables() is only used in order to prepare the page-tables for the secondary boot CPU.
Also, even if today we don't support CPU hotplug, there is nothing preventing us to do (in fact there was a series on the ML for that). This means clear_table() & co would need to be outside of the init section and we would need to remove the check that all variables/functions defined in setup.c are residing in it.
Saying that, we should not need to clear the boot page tables anymore for arm64 because secondary CPUs will directly jump to the runtime page-tables. So the code could be cleaned up a bit. Anyway, this is not a request for this series and could be done afterwards by someone else.
Cheers,
Signature · 1 line
Julien Grall
PATCH v5 13/13 xen/arm: mmu: enable SMMU subsystem only in MMU
In reply to Henry WangFrom: Penny Zheng <[email protected]>
SMMU subsystem is only supported in MMU system, so we make it dependent on CONFIG_HAS_MMU.
---
v5:
- Add Acked-by tag from Jan.
v4:
- No change
v3:
- new patch
--- xen/drivers/passthrough/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/drivers/passthrough/Kconfig +2 -1
@@ -5,6 +5,7 @@ config HAS_PASSTHROUGH if ARM config ARM_SMMU bool "ARM SMMUv1 and v2 driver" + depends on MMU default y ---help--- Support for implementations of the ARM System MMU architecture
@@ -15,7 +16,7 @@ config ARM_SMMU config ARM_SMMU_V3 bool "ARM Ltd. System MMU Version 3 (SMMUv3) Support" if EXPERT - depends on ARM_64 && (!ACPI || BROKEN) + depends on ARM_64 && (!ACPI || BROKEN) && MMU ---help--- Support for implementations of the ARM System MMU architecture version 3. Driver is in experimental stage and should not be used in
Signature · 1 line
2.25.1
Re: [PATCH v5 13/13] xen/arm: mmu: enable SMMU subsystem only in MMU
Quoted 4 lines · Henry Wang
From: Penny Zheng <[email protected]>
SMMU subsystem is only supported in MMU system, so we make it dependent on
CONFIG_HAS_MMU.
Nit: Stale "HAS" infix?
Jan
Quoted 36 lines
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>Signed-off-by Henry Wang <[email protected]>Acked-by Jan Beulich <[email protected]>---
v5:
- Add Acked-by tag from Jan.
v4:
- No change
v3:
- new patch--- xen/drivers/passthrough/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)xen/drivers/passthrough/Kconfig +2
-1@@ -5,6 +5,7 @@ config HAS_PASSTHROUGH if ARM config ARM_SMMU bool "ARM SMMUv1 and v2 driver" + depends on MMU default y ---help--- Support for implementations of the ARM System MMU architecture@@ -15,7 +16,7 @@ config ARM_SMMU config ARM_SMMU_V3 bool "ARM Ltd. System MMU Version 3 (SMMUv3) Support" if EXPERT - depends on ARM_64 && (!ACPI || BROKEN) + depends on ARM_64 && (!ACPI || BROKEN) && MMU ---help--- Support for implementations of the ARM System MMU architecture version 3. Driver is in experimental stage and should not be used in
Re: [PATCH v5 13/13] xen/arm: mmu: enable SMMU subsystem only in MMU
Hi Jan,
Quoted 9 lines · Jan Beulich
Quoted 4 lines · Henry Wang
From: Penny Zheng <[email protected]>
SMMU subsystem is only supported in MMU system, so we make it dependent on
CONFIG_HAS_MMU.Nit: Stale "HAS" infix?
Ah…Nice catch, sorry about that, will fix that in v6 if the series needs changes in other patches.
Kind regards,
Henry
Quoted 40 lines
Jan
Quoted 36 lines
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>Signed-off-by Henry Wang <[email protected]>Acked-by Jan Beulich <[email protected]>---
v5:
- Add Acked-by tag from Jan.
v4:
- No change
v3:
- new patch
---
xen/drivers/passthrough/Kconfig | 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)xen/drivers/passthrough/Kconfig +0
-0@@ -5,6 +5,7 @@ config HAS_PASSTHROUGHif ARM
configARM_SMMU
bool "ARM SMMUv1 and v2 driver"
+ depends on MMU
default y
---help---
Support for implementations of the ARM System MMU architecturexen/drivers/passthrough/Kconfig +0
-0@@ -15,7 +16,7 @@ config ARM_SMMUconfig
ARM_SMMU_V3
bool "ARM Ltd. System MMU Version 3 (SMMUv3) Support" if EXPERT- depends on ARM_64 && (!ACPI || BROKEN) + depends on ARM_64 && (!ACPI || BROKEN) && MMU---help---
Support for implementations of the ARM System MMU architecture version 3. Driver is in experimental stage and should not be used in
Re: [PATCH v5 13/13] xen/arm: mmu: enable SMMU subsystem only in MMU
In reply to Henry WangHi,
Quoted 4 lines · Henry Wang
From: Penny Zheng <[email protected]>
SMMU subsystem is only supported in MMU system, so we make it dependent on
CONFIG_HAS_MMU.
"only supported" as in it doesn't work with Xen or the HW is not supporting it?
Also, I am not entirely convinced that anything in passthrough would properly work with MPU. At least none of the IOMMU drivers are. So I would consider to completely disable HAS_PASSTHROUGH.
Quoted 29 lines
Signed-off-by Penny Zheng <[email protected]>Signed-off-by Wei Chen <[email protected]>Signed-off-by Henry Wang <[email protected]>Acked-by Jan Beulich <[email protected]>---
v5:
- Add Acked-by tag from Jan.
v4:
- No change
v3:
- new patch--- xen/drivers/passthrough/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)xen/drivers/passthrough/Kconfig +1
-0@@ -5,6 +5,7 @@ config HAS_PASSTHROUGH if ARM config ARM_SMMU bool "ARM SMMUv1 and v2 driver" + depends on MMU default y ---help--- Support for implementations of the ARM System MMU architecture
xen/drivers/passthrough/Kconfig config ARM_SMMU · line 22
Quoted 8 lines
xen/drivers/passthrough/Kconfig +1
-1@@ -15,7 +16,7 @@ config ARM_SMMU config ARM_SMMU_V3 bool "ARM Ltd. System MMU Version 3 (SMMUv3) Support" if EXPERT - depends on ARM_64 && (!ACPI || BROKEN) + depends on ARM_64 && (!ACPI || BROKEN) && MMU ---help--- Support for implementations of the ARM System MMU architecture version 3. Driver is in experimental stage and should not be used in
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 13/13] xen/arm: mmu: enable SMMU subsystem only in MMU
Hi Julien,
Quoted 10 lines · Julien Grall
Hi,
Quoted 3 lines · Henry Wang
From: Penny Zheng <[email protected]>
SMMU subsystem is only supported in MMU system, so we make it dependent onCONFIG_HAS_MMU."only supported" as in it doesn't work with Xen or the HW is not supporting it?
I think currently there are no hardware combination of MPU + SMMU, but theoretically I think this is a valid combination since SMMU supports the linear mapping. So would below reword looks good to you:
“Currently the hardware use case of connecting SMMU to MPU system is rarely seen, so we make CONFIG_ARM_SMMU and CONFIG_ARM_SMMU_V3 dependent on CONFIG_MMU."
Quoted 2 lines
Also, I am not entirely convinced that anything in passthrough would properly work with MPU. At least none of the IOMMU drivers are. So I would consider to completely disable
HAS_PASSTHROUGH.
I agree, do you think adding below addition diff to this patch makes sense to you? If so I guess would also need to mention this in commit message.
```
diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
index 8a7b79b4b5..fd29d14ed6 100644
--- a/xen/arch/arm/Kconfig
+++ b/xen/arch/arm/Kconfig
@@ -13,7 +13,7 @@ config ARM
def_bool y
select HAS_ALTERNATIVE
select HAS_DEVICE_TREE
- select HAS_PASSTHROUGH
+ select HAS_PASSTHROUGH if MMU
select HAS_PDX
select HAS_UBSAN
select IOMMU_FORCE_PT_SHARE
```Kind regards,
Henry
Re: [PATCH v5 13/13] xen/arm: mmu: enable SMMU subsystem only in MMU
Quoted 1 line · Henry Wang
Hi Julien,
Hi,
Quoted 11 lines
Quoted 10 lines · Julien Grall
Hi,
Quoted 3 lines · Henry Wang
From: Penny Zheng <[email protected]>
SMMU subsystem is only supported in MMU system, so we make it dependent onCONFIG_HAS_MMU."only supported" as in it doesn't work with Xen or the HW is not supporting it?
Quoted 7 lines
I think currently there are no hardware combination of MPU + SMMU, but theoretically I think this is a valid combination since SMMU supports the linear mapping. So would below reword looks good to you:
“Currently the hardware use case of connecting SMMU to MPU system is rarely seen, so we make
CONFIG_ARM_SMMUandCONFIG_ARM_SMMU_V3dependent onCONFIG_MMU."
I read this as there might be MPU system with SMMU in development. What you want to explain is why we can't let the developper to select the SMMU driver on an MPU system.
From my understanding this is because the drivers are expecting to use the page-tables and the concept doesn't exist in the MPU system. So the drivers are not ready for the MPU.
Quoted 5 lines
Quoted 3 lines
Also, I am not entirely convinced that anything in passthrough would properly work with MPU. At least none of the IOMMU drivers are. So I would consider to completely disable
HAS_PASSTHROUGH.I agree, do you think adding below addition diff to this patch makes sense to you?
I think it should be a replacement because none of the IOMMU drivers works for the MPU. So I would rather prefer if we avoid adding "depends on" on all of them (even if there are only 3) for now.
Quoted 1 line
If so I guess would also need to mention this in commit message.
Did you confirm that Xen MPU still build without HAS_PASSTHROUGH?
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 13/13] xen/arm: mmu: enable SMMU subsystem only in MMU
Hi Julien,
Quoted 24 lines · Julien Grall
Quoted 1 line · Henry Wang
Hi Julien,
Hi,
Quoted 9 lines
Quoted 9 lines · Julien Grall
Hi,
Quoted 3 lines · Henry Wang
From: Penny Zheng <[email protected]>
SMMU subsystem is only supported in MMU system, so we make it dependent onCONFIG_HAS_MMU.Quoted 7 lines
Quoted 1 line
"only supported" as in it doesn't work with Xen or the HW is not supporting it?
I think currently there are no hardware combination of MPU + SMMU, but theoretically I think this is a valid combination since SMMU supports the linear mapping. So would below reword looks good to you:
“Currently the hardware use case of connecting SMMU to MPU system is rarely seen, so we makeCONFIG_ARM_SMMUandCONFIG_ARM_SMMU_V3
dependent onCONFIG_MMU."
Quoted 3 lines
I read this as there might be MPU system with SMMU in development. What you want to explain is why we can't let the developper to select the SMMU driver on an MPU system.
From my understanding this is because the drivers are expecting to use the page-tables and the concept doesn't exist in the MPU system. So the drivers are not ready for the MPU.
I agree.
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Also, I am not entirely convinced that anything in passthrough would properly work with MPU. At least none of the IOMMU drivers are. So I would consider to completely disable
HAS_PASSTHROUGH.I agree, do you think adding below addition diff to this patch makes sense to you?
I think it should be a replacement because none of the IOMMU drivers works for the MPU. So I would rather prefer if we avoid adding "depends on" on all of them (even if there are only 3) for now.
I am a bit confused, I read your above explanation to the commit message as you agree with the idea that making SMMU driver not selectable by MPU system. If we replace this with “select HAS_PASSTHROUGH if MMU”, the SMMU driver will be selectable by MPU system.
But...
Quoted 4 lines
Quoted 2 lines
If so I guess would also need to mention this in commit message.
Did you confirm that Xen MPU still build without
HAS_PASSTHROUGH?
…this is a good catch, no MPU is not buildable without HAS_PASSTHROUGH, we will have:
``` In file included from ./include/xen/sched.h:12, from ./include/xen/iocap.h:10, from arch/arm/p2m.c:3: arch/arm/p2m.c: In function 'p2m_set_way_flush': ./include/xen/iommu.h:366:40: error: 'struct domain' has no member named 'iommu' 366 | #define dom_iommu(d) (&(d)->iommu) | ^~ ./include/xen/iommu.h:371:36: note: in expansion of macro 'dom_iommu' 371 | #define iommu_use_hap_pt(d) (dom_iommu(d)->hap_pt_share) | ^~~~~~~~~ arch/arm/p2m.c:617:10: note: in expansion of macro 'iommu_use_hap_pt' 617 | if ( iommu_use_hap_pt(current->domain) ) | ^~~~~~~~~~~~~~~~ In file included from ./include/xen/sched.h:12, from ./arch/arm/include/asm/grant_table.h:7, from ./include/xen/grant_table.h:29, from arch/arm/domain.c:4: arch/arm/domain.c: In function 'arch_domain_creation_finished': ./include/xen/iommu.h:366:40: error: 'struct domain' has no member named 'iommu' 366 | #define dom_iommu(d) (&(d)->iommu) | ^~ ./include/xen/iommu.h:371:36: note: in expansion of macro 'dom_iommu' 371 | #define iommu_use_hap_pt(d) (dom_iommu(d)->hap_pt_share) | ^~~~~~~~~ arch/arm/domain.c:880:11: note: in expansion of macro 'iommu_use_hap_pt' 880 | if ( !iommu_use_hap_pt(d) ) | ^~~~~~~~~~~~~~~~ CC arch/arm/shutdown.o CC lib/strlen.o CC arch/arm/smp.o CC arch/arm/smpboot.o CC common/xmalloc_tlsf.o CC lib/strncasecmp.o make[2]: *** [Rules.mk:247: arch/arm/p2m.o] Error 1 make[2]: *** Waiting for unfinished jobs.... ```
Kind regards,
Henry
Quoted 5 lines
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 13/13] xen/arm: mmu: enable SMMU subsystem only in MMU
Quoted 34 lines · Henry Wang
Hi Julien,
Quoted 24 lines · Julien Grall
Quoted 1 line · Henry Wang
Hi Julien,
Hi,
Quoted 9 lines
Quoted 9 lines · Julien Grall
Hi,
Quoted 3 lines · Henry Wang
From: Penny Zheng <[email protected]>
SMMU subsystem is only supported in MMU system, so we make it dependent onCONFIG_HAS_MMU.Quoted 7 lines
Quoted 1 line
"only supported" as in it doesn't work with Xen or the HW is not supporting it?
I think currently there are no hardware combination of MPU + SMMU, but theoretically I think this is a valid combination since SMMU supports the linear mapping. So would below reword looks good to you:
“Currently the hardware use case of connecting SMMU to MPU system is rarely seen, so we makeCONFIG_ARM_SMMUandCONFIG_ARM_SMMU_V3
dependent onCONFIG_MMU."Quoted 3 lines
I read this as there might be MPU system with SMMU in development. What you want to explain is why we can't let the developper to select the SMMU driver on an MPU system.
From my understanding this is because the drivers are expecting to use the page-tables and the concept doesn't exist in the MPU system. So the drivers are not ready for the MPU.
I agree.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
Also, I am not entirely convinced that anything in passthrough would properly work with MPU. At least none of the IOMMU drivers are. So I would consider to completely disable
HAS_PASSTHROUGH.I agree, do you think adding below addition diff to this patch makes sense to you?
I think it should be a replacement because none of the IOMMU drivers works for the MPU. So I would rather prefer if we avoid adding "depends on" on all of them (even if there are only 3) for now.
I am a bit confused, I read your above explanation to the commit message as you agree with the idea that making SMMU driver not selectable by MPU system.
No. I would rather prefer if HAS_PASSTHROUGH is completely disabled because I doubt the IOMMU infrastructure will work without any change for the MPU.
So it sounds incorrect to enable HAS_PASSTHROUGH until one of you confirm it works.
Cheers,
Signature · 1 line
Julien Grall