xen/arm: Split MMU code as the prepration of MPU work form Arm32
cover xen/arm: Split MMU code as the prepration of MPU work form Arm32
Hi,
These are the set of patches based on top of
"[PATCH v6 00/13] xen/arm: Split MMU code as the prepration of MPU work". These patches aim to do similar MMU rework for Arm32.
Similar to the former series, this is the preparation work to add MPU support for Arm32.
Ayan Kumar Halder (4):
xen/arm: arm32: Move pt_enforce_wxn() so that it can be bundled with
other MMU functionality
xen/arm32: head.S: Introduce enable_{boot,secondary}_cpu_mm() xen/arm32: Split and move MMU-specific head.S to mmu/head.S xen/arm: traps.c: Enclose VMSA specific registers within CONFIG_MMU
xen/arch/arm/arm32/head.S | 567 +----------------------- xen/arch/arm/arm32/mmu/Makefile | 1 + xen/arch/arm/arm32/mmu/head.S | 556 +++++++++++++++++++++++ xen/arch/arm/include/asm/arm32/macros.h | 62 +++ xen/arch/arm/traps.c | 17 +- 5 files changed, 639 insertions(+), 564 deletions(-) create mode 100644 xen/arch/arm/arm32/mmu/head.S
Signature · 1 line
2.25.1
PATCH 1/4 xen/arm: arm32: Move pt_enforce_wxn() so that it can be bundled with other MMU functionality
pt_enforce_wxn() is moved up (as the previous instruction ie mov_w has no effect on this). This way it is grouped with other MMU related functions so that they can be moved together in the subsequent patch.
---
This is based on my comment on
"[PATCH v6 08/13] xen/arm: Fold mmu_init_secondary_cpu() to head.S". This patch can be ignored if the comment is addressed.
xen/arch/arm/arm32/head.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/arm32/head.S +1 -1
@@ -268,12 +268,12 @@ secondary_switched: dsb isb flush_xen_tlb_local r0 + pt_enforce_wxn r0 #ifdef CONFIG_EARLY_PRINTK /* Use a virtual address to access the UART. */ mov_w r11, EARLY_UART_VIRTUAL_ADDRESS #endif - pt_enforce_wxn r0 PRINT("- Ready -\r\n") /* Jump to C world */ mov_w r2, start_secondary
Signature · 1 line
2.25.1
PATCH 2/4 xen/arm32: head.S: Introduce enable_{boot,secondary}_cpu_mm()
In reply to Ayan Kumar HalderThis is based on:-
"[PATCH v6 01/13] xen/arm64: head.S: Introduce enable_{boot,secondary}_cpu_mm()"
https://www.mail-archive.com/[email protected]/msg151918.html
This is being done for Arm32 as MPU support will be added for Arm32 as well.
--- xen/arch/arm/arm32/head.S | 90 +++++++++++++++++++++++++++++---------- 1 file changed, 67 insertions(+), 23 deletions(-)
xen/arch/arm/arm32/head.S +67 -23
@@ -201,13 +201,10 @@ past_zImage: bl check_cpu_mode bl cpu_init - bl create_page_tables + ldr lr, =primary_switched + b enable_boot_cpu_mm - /* Address in the runtime mapping to jump to after the MMU is enabled */ - mov_w lr, primary_switched - b enable_mmu primary_switched: - bl setup_fixmap #ifdef CONFIG_EARLY_PRINTK /* Use a virtual address to access the UART. */ mov_w r11, EARLY_UART_VIRTUAL_ADDRESS
@@ -249,27 +246,11 @@ GLOBAL(init_secondary) #endif bl check_cpu_mode bl cpu_init - bl create_page_tables - /* Address in the runtime mapping to jump to after the MMU is enabled */ mov_w lr, secondary_switched - b enable_mmu -secondary_switched: - /* - * Non-boot CPUs need to move on to the proper pagetables, which were - * setup in prepare_secondary_mm. - * - * XXX: This is not compliant with the Arm Arm. - */ - mov_w r4, init_ttbr /* VA of HTTBR value stashed by CPU 0 */ - ldrd r4, r5, [r4] /* Actual value */ - dsb - mcrr CP64(r4, r5, HTTBR) - dsb - isb - flush_xen_tlb_local r0 - pt_enforce_wxn r0 + b enable_secondary_cpu_mm +secondary_switched: #ifdef CONFIG_EARLY_PRINTK /* Use a virtual address to access the UART. */ mov_w r11, EARLY_UART_VIRTUAL_ADDRESS
@@ -692,6 +673,69 @@ ready_to_switch: mov pc, lr ENDPROC(switch_to_runtime_mapping) +/* + * 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 r0 - r6 + */ +enable_secondary_cpu_mm: + mov r6, lr + bl create_page_tables + + mov_w lr, secondary_cpu_mmu_on + b enable_mmu +secondary_cpu_mmu_on: + /* + * Non-boot CPUs need to move on to the proper pagetables, which were + * setup in prepare_secondary_mm. + * + * XXX: This is not compliant with the Arm Arm. + */ + mov_w r4, init_ttbr /* VA of HTTBR value stashed by CPU 0 */ + ldrd r4, r5, [r4] /* Actual value */ + dsb + mcrr CP64(r4, r5, HTTBR) + dsb + isb + flush_xen_tlb_local r0 + pt_enforce_wxn r0 + mov lr, r6 + + /* Return to the virtual address requested by the caller. */ + mov pc, lr +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 r0 - r6 + */ +enable_boot_cpu_mm: + mov r6, lr + bl create_page_tables + + /* Address in the runtime mapping to jump to after the MMU is enabled */ + mov_w lr, boot_cpu_mmu_on + b enable_mmu +boot_cpu_mmu_on: + bl setup_fixmap + + mov lr, r6 + + /* Return to the virtual address requested by the caller. */ + mov pc, lr +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: [XEN v1 2/4] xen/arm32: head.S: Introduce enable_{boot,secondary}_cpu_mm()
Hi Ayan,
Quoted 3 lines · Ayan Kumar Halder
This is based on:-
"[PATCH v6 01/13] xen/arm64:head.S: Introduce enable_{boot,secondary}_cpu_mm()"
https://www.mail-archive.com/[email protected]/msg151918.html
Most of the explanation in that commit message doesn't apply here. You also move call like setup_fixmap without explaining why.
Also, if you want to refer to the arm64 patch in the commit message (I think it would be better after ---), then it is best to point ot the now committed patch.
Quoted 13 lines
This is being done for Arm32 as MPU support will be added for Arm32 as well.
Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/arm32/head.S | 90 +++++++++++++++++++++++++++++---------- 1 file changed, 67 insertions(+), 23 deletions(-)xen/arch/arm/arm32/head.S +0
-0
xen/arch/arm/arm32/head.S past_zImage: · line 203
Quoted 3 lines
xen/arch/arm/arm32/head.S +0
-0@@ -201,13 +201,10 @@ past_zImage: bl check_cpu_mode bl cpu_init
NIT: I would add a newline to make it clearer.
xen/arch/arm/arm32/head.S past_zImage: · line 204
Quoted 2 lines
xen/arch/arm/arm32/head.S +1
-1- bl create_page_tables + ldr lr, =primary_switched
The existing code was using 'mov_w ...' to avoid load from memory. Can you explain why you switched to 'ldr'?
Quoted 46 lines
xen/arch/arm/arm32/head.S +5
-22+ b enable_boot_cpu_mm - /* Address in the runtime mapping to jump to after the MMU is enabled */ - mov_w lr, primary_switched - b enable_mmu primary_switched: - bl setup_fixmap #ifdef CONFIG_EARLY_PRINTK /* Use a virtual address to access the UART. */ mov_w r11, EARLY_UART_VIRTUAL_ADDRESS@@ -249,27 +246,11 @@ GLOBAL(init_secondary) #endif bl check_cpu_mode bl cpu_init - bl create_page_tables - /* Address in the runtime mapping to jump to after the MMU is enabled */ mov_w lr, secondary_switched - b enable_mmu -secondary_switched: - /* - * Non-boot CPUs need to move on to the proper pagetables, which were - * setup in prepare_secondary_mm. - * - * XXX: This is not compliant with the Arm Arm. - */ - mov_w r4, init_ttbr /* VA of HTTBR value stashed by CPU 0 */ - ldrd r4, r5, [r4] /* Actual value */ - dsb - mcrr CP64(r4, r5, HTTBR) - dsb - isb - flush_xen_tlb_local r0 - pt_enforce_wxn r0 + b enable_secondary_cpu_mm +secondary_switched: #ifdef CONFIG_EARLY_PRINTK /* Use a virtual address to access the UART. */ mov_w r11, EARLY_UART_VIRTUAL_ADDRESS@@ -692,6 +673,69 @@ ready_to_switch: mov pc, lr ENDPROC(switch_to_runtime_mapping) +/* + * Enable mm (turn on the data cache and the MMU) for secondary CPUs.
xen/arch/arm/arm32/head.S ready_to_switch: · line 687
Quoted 10 lines
xen/arch/arm/arm32/head.S +10
-0+ * The function will return to the virtual address provided in LR (e.g. the + * runtime mapping). + * + * Inputs: + * lr : Virtual address to return to. + * + * Clobbers r0 - r6 + */ +enable_secondary_cpu_mm: + mov r6, lr
NIT: I would add a newline to make it clearer.
xen/arch/arm/arm32/head.S ready_to_switch: · line 689
Quoted 2 lines
xen/arch/arm/arm32/head.S +2
-0+ bl create_page_tables +
I think the comment on top of "mov_w lr, secondary_switched" should be moved here.
xen/arch/arm/arm32/head.S ready_to_switch: · line 692
Quoted 3 lines
xen/arch/arm/arm32/head.S +3
-0+ mov_w lr, secondary_cpu_mmu_on + b enable_mmu +secondary_cpu_mmu_on:
I would prefer if we use 1 to avoid introducing local label.
Quoted 8 lines
xen/arch/arm/arm32/head.S +8
-0+ /* + * Non-boot CPUs need to move on to the proper pagetables, which were + * setup in prepare_secondary_mm. + * + * XXX: This is not compliant with the Arm Arm. + */ + mov_w r4, init_ttbr /* VA of HTTBR value stashed by CPU 0 */ + ldrd r4, r5, [r4] /* Actual value */
xen/arch/arm/arm32/head.S ready_to_switch: · line 710
Quoted 10 lines
xen/arch/arm/arm32/head.S +10
-0+ dsb + mcrr CP64(r4, r5, HTTBR) + dsb + isb + flush_xen_tlb_local r0 + pt_enforce_wxn r0 + mov lr, r6 + + /* Return to the virtual address requested by the caller. */ + mov pc, lr
The above two instructions can be combined to:
/* Return to the virtual address requested by the caller (r6). */ mov pc, r6
Quoted 4 lines
xen/arch/arm/arm32/head.S +4
-0+ENDPROC(enable_secondary_cpu_mm) + +/* + * Enable mm (turn on the data cache and the MMU) for the boot CPU.
xen/arch/arm/arm32/head.S ready_to_switch: · line 724
Quoted 10 lines
xen/arch/arm/arm32/head.S +10
-0+ * The function will return to the virtual address provided in LR (e.g. the + * runtime mapping). + * + * Inputs: + * lr : Virtual address to return to. + * + * Clobbers r0 - r6 + */ +enable_boot_cpu_mm: + mov r6, lr
NIT: I would add a newline to make it clearer.
xen/arch/arm/arm32/head.S ready_to_switch: · line 730
Quoted 6 lines
xen/arch/arm/arm32/head.S +6
-0+ bl create_page_tables + + /* Address in the runtime mapping to jump to after the MMU is enabled */ + mov_w lr, boot_cpu_mmu_on + b enable_mmu +boot_cpu_mmu_on:
Same as the lable secondary_cpu_mmu_on.
xen/arch/arm/arm32/head.S ready_to_switch: · line 736
Quoted 6 lines
xen/arch/arm/arm32/head.S +6
-0+ bl setup_fixmap + + mov lr, r6 + + /* Return to the virtual address requested by the caller. */ + mov pc, lr
In this case the 3 instructions can be replaced to:
mov lr, r6
b setup_fixmap
xen/arch/arm/arm32/head.S ready_to_switch: · line 741
Quoted 5 lines
xen/arch/arm/arm32/head.S +2
-0+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
PATCH 3/4 xen/arm32: Split and move MMU-specific head.S to mmu/head.S
In reply to Ayan Kumar HalderThis is based on
"[PATCH v6 03/13] xen/arm64: Split and move MMU-specific head.S to mmu/head.S"
https://www.mail-archive.com/[email protected]/msg151920.html
--- xen/arch/arm/arm32/head.S | 603 +----------------------- xen/arch/arm/arm32/mmu/Makefile | 1 + xen/arch/arm/arm32/mmu/head.S | 556 ++++++++++++++++++++++ xen/arch/arm/include/asm/arm32/macros.h | 62 +++ 4 files changed, 620 insertions(+), 602 deletions(-) create mode 100644 xen/arch/arm/arm32/mmu/head.S
xen/arch/arm/arm32/head.S +1 -602
@@ -22,86 +22,10 @@ #define ZIMAGE_MAGIC_NUMBER 0x016f2818 -#define PT_PT 0xf7f /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=1 P=1 */ -#define PT_MEM 0xf7d /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=0 P=1 */ -#define PT_MEM_L3 0xf7f /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=1 P=1 */ -#define PT_DEV 0xe71 /* nG=1 AF=1 SH=10 AP=01 NS=1 ATTR=100 T=0 P=1 */ -#define PT_DEV_L3 0xe73 /* nG=1 AF=1 SH=10 AP=01 NS=1 ATTR=100 T=1 P=1 */ - -#define PT_UPPER(x) (PT_##x & 0xf00) -#define PT_LOWER(x) (PT_##x & 0x0ff) - -/* Convenience defines to get slot used by Xen mapping. */ -#define XEN_FIRST_SLOT first_table_offset(XEN_VIRT_START) -#define XEN_SECOND_SLOT second_table_offset(XEN_VIRT_START) - -/* Offset between the early boot xen mapping and the runtime xen mapping */ -#define XEN_TEMPORARY_OFFSET (TEMPORARY_XEN_VIRT_START - XEN_VIRT_START) - #if defined(CONFIG_EARLY_PRINTK) && defined(CONFIG_EARLY_PRINTK_INC) #include CONFIG_EARLY_PRINTK_INC #endif -/* - * Move an immediate constant into a 32-bit register using movw/movt - * instructions. - */ -.macro mov_w reg, word - movw \reg, #:lower16:\word - movt \reg, #:upper16:\word -.endm - -/* - * Pseudo-op for PC relative adr <reg>, <symbol> where <symbol> is - * within the range +/- 4GB of the PC. - * - * @dst: destination register - * @sym: name of the symbol - */ -.macro adr_l, dst, sym - mov_w \dst, \sym - .Lpc\@ - .set .Lpc\@, .+ 8 /* PC bias */ - add \dst, \dst, pc -.endm - -.macro load_paddr rb, sym - mov_w \rb, \sym - add \rb, \rb, r10 -.endm - -/* - * Flush local TLBs - * - * @tmp: Scratch register - * - * See asm/arm32/flushtlb.h for the explanation of the sequence. - */ -.macro flush_xen_tlb_local tmp - dsb nshst - mcr CP32(\tmp, TLBIALLH) - dsb nsh - isb -.endm - -/* - * Enforce Xen page-tables do not contain mapping that are both - * Writable and eXecutables. - * - * This should be called on each secondary CPU. - */ -.macro pt_enforce_wxn tmp - mrc CP32(\tmp, HSCTLR) - orr \tmp, \tmp, #SCTLR_Axx_ELx_WXN - dsb - mcr CP32(\tmp, HSCTLR) - /* - * The TLBs may cache SCTLR_EL2.WXN. So ensure it is synchronized - * before flushing the TLBs. - */ - isb - flush_xen_tlb_local \tmp -.endm - /* * Common register usage in this file: * r0 -
@@ -121,38 +45,6 @@ * r14 - LR * r15 - PC */ -#ifdef CONFIG_EARLY_PRINTK -/* - * Macro to print a string to the UART, if there is one. - * - * Clobbers r0 - r3 - */ -#define PRINT(_s) \ - mov r3, lr ;\ - adr_l r0, 98f ;\ - bl puts ;\ - mov lr, r3 ;\ - RODATA_STR(98, _s) - -/* - * Macro to print the value of register \rb - * - * Clobbers r0 - r4 - */ -.macro print_reg rb - mov r0, \rb - mov r4, lr - bl putn - mov lr, r4 -.endm - -#else /* CONFIG_EARLY_PRINTK */ -#define PRINT(s) - -.macro print_reg rb -.endm - -#endif /* !CONFIG_EARLY_PRINTK */ .section .text.header, "ax", %progbits .arm
@@ -354,467 +246,6 @@ cpu_init_done: mov pc, r5 /* Return address is in r5 */ ENDPROC(cpu_init) -/* - * Macro to find the slot number at a given page-table level - * - * slot: slot computed - * virt: virtual address - * lvl: page-table level - * - * Note that ubxf is unpredictable when the end bit is above 32-bit. So we - * can't use it for first level offset. - */ -.macro get_table_slot, slot, virt, lvl - .if \lvl == 1 - lsr \slot, \virt, #XEN_PT_LEVEL_SHIFT(\lvl) - .else - ubfx \slot, \virt, #XEN_PT_LEVEL_SHIFT(\lvl), #XEN_PT_LPAE_SHIFT - .endif -.endm - -/* - * Macro to create a page table entry in \ptbl to \tbl (physical - * address) - * - * ptbl: table symbol where the entry will be created - * tbl: physical address of the table to point to - * virt: virtual address - * lvl: page-table level - * - * Preserves \virt - * Clobbers \tbl, r1 - r3 - * - * Note that \tbl and \virt should be in a register other than r1 - r3 - */ -.macro create_table_entry_from_paddr, ptbl, tbl, virt, lvl - get_table_slot r1, \virt, \lvl /* r1 := slot in \tbl */ - lsl r1, r1, #3 /* r1 := slot offset in \tbl */ - - movw r2, #PT_PT /* r2:r3 := right for linear PT */ - orr r2, r2, \tbl /* + \tbl paddr */ - mov r3, #0 - - adr_l \tbl, \ptbl /* \tbl := (v,p)addr of \ptbl */ - - strd r2, r3, [\tbl, r1] -.endm - - -/* - * Macro to create a page table entry in \ptbl to \tbl (symbol) - * - * ptbl: table symbol where the entry will be created - * tbl: table symbol to point to - * virt: virtual address - * lvl: page-table level - * - * Preserves \virt - * Clobbers r1 - r4 - * - * Also use r10 for the phys offset. - * - * Note that \virt should be in a register other than r1 - r4 - */ -.macro create_table_entry, ptbl, tbl, virt, lvl - load_paddr r4, \tbl - create_table_entry_from_paddr \ptbl, r4, \virt, \lvl - .endm - -/* - * Macro to create a mapping entry in \tbl to \paddr. Only mapping in 3rd - * level table (i.e page granularity) is supported. - * - * ptbl: table symbol where the entry will be created - * virt: virtual address - * phys: physical address - * type: mapping type. If not specified it will be normal memory (PT_MEM_L3) - * - * Preserves \virt, \phys - * Clobbers r1 - r4 - * - * Note that \virt and \paddr should be in other registers than r1 - r4 - * and be distinct. - */ -.macro create_mapping_entry, ptbl, virt, phys, type=PT_MEM_L3 - mov_w r2, XEN_PT_LPAE_ENTRY_MASK - lsr r1, \virt, #THIRD_SHIFT - and r1, r1, r2 /* r1 := slot in \tlb */ - lsl r1, r1, #3 /* r1 := slot offset in \tlb */ - - lsr r4, \phys, #THIRD_SHIFT - lsl r4, r4, #THIRD_SHIFT /* r4 := PAGE_ALIGNED(phys) */ - - movw r2, #\type /* r2:r3 := right for section PT */ - orr r2, r2, r4 /* + PAGE_ALIGNED(phys) */ - mov r3, #0 - - adr_l r4, \ptbl - - strd r2, r3, [r4, r1] -.endm - -/* - * Rebuild the boot pagetable's first-level entries. The structure - * is described in mm.c. - * - * After the CPU enables paging it will add the fixmap mapping - * to these page tables, however this may clash with the 1:1 - * mapping. So each CPU must rebuild the page tables here with - * the 1:1 in place. - * - * Inputs: - * r9 : paddr(start) - * r10: phys offset - * - * Output: - * r12: Was a temporary mapping created? - * - * Clobbers r0 - r5 - */ -create_page_tables: - /* Prepare the page-tables for mapping Xen */ - mov_w r0, XEN_VIRT_START - - /* - * We need to use a stash register because - * create_table_entry_paddr() will clobber the register storing - * the physical address of the table to point to. - */ - load_paddr r5, boot_third - mov_w r4, XEN_VIRT_START -.rept XEN_NR_ENTRIES(2) - mov r0, r5 /* r0 := paddr(l3 table) */ - create_table_entry_from_paddr boot_second, r0, r4, 2 - add r4, r4, #XEN_PT_LEVEL_SIZE(2) /* r4 := Next vaddr */ - add r5, r5, #PAGE_SIZE /* r5 := Next table */ -.endr - - /* - * Find the size of Xen in pages and multiply by the size of a - * PTE. This will then be compared in the mapping loop below. - * - * Note the multiplication is just to avoid using an extra - * register/instruction per iteration. - */ - mov_w r0, _start /* r0 := vaddr(_start) */ - mov_w r1, _end /* r1 := vaddr(_end) */ - sub r0, r1, r0 /* r0 := effective size of Xen */ - lsr r0, r0, #PAGE_SHIFT /* r0 := Number of pages for Xen */ - lsl r0, r0, #3 /* r0 := Number of pages * PTE size */ - - /* Setup boot_third: */ - adr_l r4, boot_third - - lsr r2, r9, #THIRD_SHIFT /* Base address for 4K mapping */ - lsl r2, r2, #THIRD_SHIFT - orr r2, r2, #PT_UPPER(MEM_L3) /* r2:r3 := map */ - orr r2, r2, #PT_LOWER(MEM_L3) - mov r3, #0x0 - - /* ... map of vaddr(start) in boot_third */ - mov r1, #0 -1: strd r2, r3, [r4, r1] /* Map vaddr(start) */ - add r2, r2, #PAGE_SIZE /* Next page */ - add r1, r1, #8 /* Next slot */ - cmp r1, r0 /* Loop until we map all of Xen */ - blo 1b - - /* - * Setup the 1:1 mapping so we can turn the MMU on. Note that - * only the first page of Xen will be part of the 1:1 mapping. - */ - create_table_entry boot_pgtable, boot_second_id, r9, 1 - create_table_entry boot_second_id, boot_third_id, r9, 2 - create_mapping_entry boot_third_id, r9, r9 - - /* - * Find the first slot used. If the slot is not the same - * as TEMPORARY_AREA_FIRST_SLOT, then we will want to switch - * to the temporary mapping before jumping to the runtime - * virtual mapping. - */ - get_table_slot r1, r9, 1 /* r1 := first slot */ - cmp r1, #TEMPORARY_AREA_FIRST_SLOT - bne use_temporary_mapping - - mov_w r0, XEN_VIRT_START - create_table_entry boot_pgtable, boot_second, r0, 1 - mov r12, #0 /* r12 := temporary mapping not created */ - mov pc, lr - -use_temporary_mapping: - /* - * The identity mapping is not using the first slot - * TEMPORARY_AREA_FIRST_SLOT. Create a temporary mapping. - * See switch_to_runtime_mapping for more details. - */ - PRINT("- Create temporary mapping -\r\n") - - /* Map boot_second (cover Xen mappings) to the temporary 1st slot */ - mov_w r0, TEMPORARY_XEN_VIRT_START - create_table_entry boot_pgtable, boot_second, r0, 1 - - mov r12, #1 /* r12 := temporary mapping created */ - mov pc, lr -ENDPROC(create_page_tables) - -/* - * Turn on the Data Cache and the MMU. The function will return - * to the virtual address provided in LR (e.g. the runtime mapping). - * - * Inputs: - * r9 : paddr(start) - * r12 : Was the temporary mapping created? - * lr : Virtual address to return to - * - * Clobbers r0 - r5 - */ -enable_mmu: - PRINT("- Turning on paging -\r\n") - - /* - * The state of the TLBs is unknown before turning on the MMU. - * Flush them to avoid stale one. - */ - flush_xen_tlb_local r0 - - /* Write Xen's PT's paddr into the HTTBR */ - load_paddr r0, boot_pgtable - mov r1, #0 /* r0:r1 is paddr (boot_pagetable) */ - mcrr CP64(r0, r1, HTTBR) - isb - - mrc CP32(r0, HSCTLR) - /* Enable MMU and D-cache */ - orr r0, r0, #(SCTLR_Axx_ELx_M|SCTLR_Axx_ELx_C) - dsb /* Flush PTE writes and finish reads */ - mcr CP32(r0, HSCTLR) /* now paging is enabled */ - isb /* Now, flush the icache */ - - /* - * The MMU is turned on and we are in the 1:1 mapping. Switch - * to the runtime mapping. - */ - mov r5, lr /* Save LR before overwritting it */ - mov_w lr, 1f /* Virtual address in the runtime mapping */ - b switch_to_runtime_mapping -1: - mov lr, r5 /* Restore LR */ - /* - * At this point, either the 1:1 map or the temporary mapping - * will be present. The former may clash with other parts of the - * Xen virtual memory layout. As both of them are not used - * anymore, remove them completely to avoid having to worry - * about replacing existing mapping afterwards. - * - * On return this will jump to the virtual address requested by - * the caller. - */ - teq r12, #0 - beq remove_identity_mapping - b remove_temporary_mapping -ENDPROC(enable_mmu) - -/* - * Switch to the runtime mapping. The logic depends on whether the - * runtime virtual region is clashing with the physical address - * - * - If it is not clashing, we can directly jump to the address in - * the runtime mapping. - * - If it is clashing, create_page_tables() would have mapped Xen to - * a temporary virtual address. We need to switch to the temporary - * mapping so we can remove the identity mapping and map Xen at the - * correct position. - * - * Inputs - * r9: paddr(start) - * r12: Was a temporary mapping created? - * lr: Address in the runtime mapping to jump to - * - * Clobbers r0 - r4 - */ -switch_to_runtime_mapping: - /* - * Jump to the runtime mapping if the virt and phys are not - * clashing - */ - teq r12, #0 - beq ready_to_switch - - /* We are still in the 1:1 mapping. Jump to the temporary Virtual address. */ - mov_w r0, 1f - add r0, r0, #XEN_TEMPORARY_OFFSET /* r0 := address in temporary mapping */ - mov pc, r0 - -1: - /* Remove boot_second_id */ - mov r2, #0 - mov r3, #0 - adr_l r0, boot_pgtable - get_table_slot r1, r9, 1 /* r1 := first slot */ - lsl r1, r1, #3 /* r1 := first slot offset */ - strd r2, r3, [r0, r1] - - flush_xen_tlb_local r0 - - /* Map boot_second into boot_pgtable */ - mov_w r0, XEN_VIRT_START - create_table_entry boot_pgtable, boot_second, r0, 1 - - /* Ensure any page table updates are visible before continuing */ - dsb nsh - /* - * The function will return on the runtime mapping. So we want - * to prevent instruction fetch before the dsb completes. - */ - isb - -ready_to_switch: - mov pc, lr -ENDPROC(switch_to_runtime_mapping) - -/* - * 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 r0 - r6 - */ -enable_secondary_cpu_mm: - mov r6, lr - bl create_page_tables - - mov_w lr, secondary_cpu_mmu_on - b enable_mmu -secondary_cpu_mmu_on: - /* - * Non-boot CPUs need to move on to the proper pagetables, which were - * setup in prepare_secondary_mm. - * - * XXX: This is not compliant with the Arm Arm. - */ - mov_w r4, init_ttbr /* VA of HTTBR value stashed by CPU 0 */ - ldrd r4, r5, [r4] /* Actual value */ - dsb - mcrr CP64(r4, r5, HTTBR) - dsb - isb - flush_xen_tlb_local r0 - pt_enforce_wxn r0 - mov lr, r6 - - /* Return to the virtual address requested by the caller. */ - mov pc, lr -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 r0 - r6 - */ -enable_boot_cpu_mm: - mov r6, lr - bl create_page_tables - - /* Address in the runtime mapping to jump to after the MMU is enabled */ - mov_w lr, boot_cpu_mmu_on - b enable_mmu -boot_cpu_mmu_on: - bl setup_fixmap - - mov lr, r6 - - /* Return to the virtual address requested by the caller. */ - mov pc, lr -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 - * exclusive to the 1:1 map and remove it. - * - * Inputs: - * r9 : paddr(start) - * - * Clobbers r0 - r3 - */ -remove_identity_mapping: - /* r2:r3 := invalid page-table entry */ - mov r2, #0x0 - mov r3, #0x0 - - /* Find the first slot used and remove it */ - get_table_slot r1, r9, 1 /* r1 := first slot */ - mov_w r0, boot_pgtable /* r0 := root table */ - lsl r1, r1, #3 /* r1 := Slot offset */ - strd r2, r3, [r0, r1] - - flush_xen_tlb_local r0 - mov pc, lr -ENDPROC(remove_identity_mapping) - -/* - * Remove the temporary mapping of Xen starting at TEMPORARY_XEN_VIRT_START. - * - * Clobbers r0 - r3 - */ -remove_temporary_mapping: - /* r2:r3 := invalid page-table entry */ - mov r2, #0 - mov r3, #0 - - adr_l r0, boot_pgtable - mov_w r1, TEMPORARY_XEN_VIRT_START - get_table_slot r1, r1, 1 /* r1 := first slot */ - lsl r1, r1, #3 /* r1 := first slot offset */ - strd r2, r3, [r0, r1] - - flush_xen_tlb_local r0 - - mov pc, lr -ENDPROC(remove_temporary_mapping) - -/* - * Map the UART in the fixmap (when earlyprintk is used) and hook the - * fixmap table in the page tables. - * - * The fixmap cannot be mapped in create_page_tables because it may - * clash with the 1:1 mapping. - * - * Inputs: - * r10: Physical offset - * r11: Early UART base physical address - * - * Clobbers r0 - r4 - */ -setup_fixmap: -#if defined(CONFIG_EARLY_PRINTK) - /* Add UART to the fixmap table */ - mov_w r0, EARLY_UART_VIRTUAL_ADDRESS - create_mapping_entry xen_fixmap, r0, r11, type=PT_DEV_L3 -#endif - /* Map fixmap into boot_second */ - mov_w r0, FIXMAP_ADDR(0) - create_table_entry boot_second, xen_fixmap, r0, 2 - /* Ensure any page table updates made above have occurred. */ - dsb nshst - /* - * The fixmap area will be used soon after. So ensure no hardware - * translation happens before the dsb completes. - */ - isb - - mov pc, lr -ENDPROC(setup_fixmap) - /* * Setup the initial stack and jump to the C world *
@@ -842,38 +273,6 @@ fail: PRINT("- Boot failed -\r\n") b 1b ENDPROC(fail) -/* - * Switch TTBR - * r1:r0 ttbr - * - * TODO: This code does not comply with break-before-make. - */ -ENTRY(switch_ttbr) - dsb /* Ensure the flushes happen before - * continuing */ - isb /* Ensure synchronization with previous - * changes to text */ - mcr CP32(r0, TLBIALLH) /* Flush hypervisor TLB */ - mcr CP32(r0, ICIALLU) /* Flush I-cache */ - mcr CP32(r0, BPIALL) /* Flush branch predictor */ - dsb /* Ensure completion of TLB+BP flush */ - isb - - mcrr CP64(r0, r1, HTTBR) - - dsb /* ensure memory accesses do not cross - * over the TTBR0 write */ - isb /* Ensure synchronization with previous - * changes to text */ - mcr CP32(r0, TLBIALLH) /* Flush hypervisor TLB */ - mcr CP32(r0, ICIALLU) /* Flush I-cache */ - mcr CP32(r0, BPIALL) /* Flush branch predictor */ - dsb /* Ensure completion of TLB+BP flush */ - isb - - mov pc, lr -ENDPROC(switch_ttbr) - #ifdef CONFIG_EARLY_PRINTK /* * Initialize the UART. Should only be called on the boot CPU.
@@ -898,7 +297,7 @@ ENDPROC(init_uart) * r11: Early UART base address * Clobbers r0-r1 */ -puts: +ENTRY(puts) early_uart_ready r11, r1 ldrb r1, [r0], #1 /* Load next char */ teq r1, #0 /* Exit on nul */
xen/arch/arm/arm32/mmu/Makefile +1 -0
@@ -1 +1,2 @@ obj-y += mm.o +obj-y += head.o
xen/arch/arm/arm32/mmu/head.S new file +556 -0
556 lines not on this page · raw message
xen/arch/arm/include/asm/arm32/macros.h +62 -0
70 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [XEN v1 3/4] xen/arm32: Split and move MMU-specific head.S to mmu/head.S
Hi,
Quoted 4 lines · Ayan Kumar Halder
This is based on
"[PATCH v6 03/13] xen/arm64: Split and move MMU-specifichead.Stommu/head.S"https://www.mail-archive.com/[email protected]/msg151920.html
Same remark as patch #1. Please provide a proper commit message.
[...]
Quoted 31 lines
xen/arch/arm/include/asm/arm32/macros.h +19
-0@@ -1,8 +1,70 @@#ifndef __ASM_ARM_ARM32_MACROS_H#define __ASM_ARM_ARM32_MACROS_H +/* Offset between the early boot xen mapping and the runtime xen mapping */ +#define XEN_TEMPORARY_OFFSET (TEMPORARY_XEN_VIRT_START - XEN_VIRT_START) + .macro ret mov pc, lr .endm +/* + * Move an immediate constant into a 32-bit register using movw/movt + * instructions. + */ +.macro mov_w reg, word + movw \reg, #:lower16:\word + movt \reg, #:upper16:\word +.endm + +/* +* Pseudo-op for PC relative adr <reg>, <symbol> where <symbol> is +* within the range +/- 4GB of the PC. +* +* @dst: destination register +* @sym: name of the symbol +*/
xen/arch/arm/include/asm/arm32/macros.h line 36
Quoted 10 lines
xen/arch/arm/include/asm/arm32/macros.h +10
-0+.macro adr_l, dst, sym + mov_w \dst, \sym - .Lpc\@ + .set .Lpc\@, .+ 8 /* PC bias */ + add \dst, \dst, pc +.endm + +.macro load_paddr rb, sym + mov_w \rb, \sym + add \rb, \rb, r10 +.endm
I see that we are still using load_paddr in arm64/head.S. But I don't think it makes entirely sense as r10 (x20) would always be 0 for the MPU.
In fact all the use in arm{32, 64}/head.S after this patch could be easily replaced with adr_l because they are called when the MMU is off so the return address will be a physical address.
So can you add a prequisite patch for arm32 to replace the remaining some of the load_paddr? With that, load_paddr can be moved in mmu/head.S.
I will take care of the arm64 part.
Cheers,
Signature · 1 line
Julien Grall
Re: [XEN v1 3/4] xen/arm32: Split and move MMU-specific head.S to mmu/head.S
Quoted 1 line · Julien Grall
Hi,
Hi Julien,
Quoted 55 lines · Ayan Kumar Halder
Quoted 5 lines
This is based on
"[PATCH v6 03/13] xen/arm64: Split and move MMU-specifichead.Stommu/head.S"https://www.mail-archive.com/[email protected]/msg151920.html
Same remark as patch #1. Please provide a proper commit message.
[...]
Quoted 30 lines
xen/arch/arm/include/asm/arm32/macros.h +0
-0@@ -1,8 +1,70 @@ #ifndef __ASM_ARM_ARM32_MACROS_H #define __ASM_ARM_ARM32_MACROS_H+/* Offset between the early boot xen mapping and the runtime xen mapping */ +#define XEN_TEMPORARY_OFFSET (
TEMPORARY_XEN_VIRT_START-XEN_VIRT_START)
+
.macro ret
mov pc, lr
.endm
+/*
+ * Move an immediate constant into a 32-bit register using movw/movt
+ * instructions.
+ */
+.macromov_wreg, word
+ movw \reg, #:lower16:\word
+ movt \reg, #:upper16:\word
+.endmxen/arch/arm/include/asm/arm32/macros.h +8
-0+ +/* +* Pseudo-op for PC relative adr <reg>, <symbol> where <symbol> is +* within the range +/- 4GB of the PC. +* +* @dst: destination register +* @sym: name of the symbol +*/ xen/arch/arm/include/asm/arm32/macros.h line 36
Quoted 10 lines
xen/arch/arm/include/asm/arm32/macros.h +10
-0+.macro adr_l, dst, sym + mov_w \dst, \sym - .Lpc\@ + .set .Lpc\@, .+ 8 /* PC bias */ + add \dst, \dst, pc +.endm + +.macro load_paddr rb, sym + mov_w \rb, \sym + add \rb, \rb, r10 +.endmI see that we are still using
load_paddrinarm64/head.S. But I don't think it makes entirely sense as r10 (x20) would always be 0 for the MPU.
Quoted 3 lines
In fact all the use in arm{32,
64}/head.Safter this patch could be easily replaced withadr_lbecause they are called when the MMU is off so the return address will be a physical address.So can you add a prequisite patch for arm32 to replace the remaining some of the
load_paddr? With that,load_paddrcan be moved inmmu/head.S.
Sure, I am doing this. I will send you a patch in next few days.
Quoted 2 lines
I will take care of the arm64 part.
I see you have already sent the patch. :)
- Ayan
Quoted 3 lines
Cheers,
PATCH 4/4 xen/arm: traps.c: Enclose VMSA specific registers within CONFIG_MMU
In reply to Ayan Kumar HalderThe VMSA specific registers (ie TCR, TTBR0, TTBR1, VTTBR, etc) are valid when MMU is used, thus we can enclose them with CONFIG_MMU.
--- xen/arch/arm/traps.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
xen/arch/arm/traps.c +15 -2
@@ -698,8 +698,10 @@ static void __do_trap_serror(struct cpu_user_regs *regs, bool guest)struct reg_ctxt {/* Guest-side state */ register_t sctlr_el1; +#ifdef CONFIG_MMU register_t tcr_el1;uint64_t ttbr0_el1, ttbr1_el1; +#endif #ifdef CONFIG_ARM_32 uint32_t dfsr, ifsr;uint32_t dfar, ifar;
@@ -801,9 +803,11 @@ static void show_registers_32(const struct cpu_user_regs *regs,if ( guest_mode_on ) {printk (" SCTLR: %" PRIregister"\n" , ctxt->sctlr_el1); +#ifdef CONFIG_MMU printk (" TCR: %" PRIregister"\n" , ctxt->tcr_el1);printk (" TTBR0: %016" PRIx64"\n" , ctxt->ttbr0_el1);printk (" TTBR1: %016" PRIx64"\n" , ctxt->ttbr1_el1); +#endif printk(" IFAR: %08"PRIx32", IFSR: %08"PRIx32"\n" " DFAR: %08"PRIx32", DFSR: %08"PRIx32"\n",#ifdef CONFIG_ARM_64
@@ -873,9 +877,11 @@ static void show_registers_64(const struct cpu_user_regs *regs,printk (" FAR_EL1: %016" PRIx64"\n" , ctxt->far);printk ("\n" );printk (" SCTLR_EL1: %" PRIregister"\n" , ctxt->sctlr_el1); +#ifdef CONFIG_MMU printk (" TCR_EL1: %" PRIregister"\n" , ctxt->tcr_el1);printk (" TTBR0_EL1: %016" PRIx64"\n" , ctxt->ttbr0_el1);printk (" TTBR1_EL1: %016" PRIx64"\n" , ctxt->ttbr1_el1); +#endif printk ("\n" ); } }
@@ -907,13 +913,15 @@ static void _show_registers(const struct cpu_user_regs *regs,show_registers_32 (regs, ctxt, guest_mode_on, v);#endif } +#ifdef CONFIG_MMU printk (" VTCR_EL2: %" PRIregister"\n" ,READ_SYSREG (VTCR_EL2 ));printk (" VTTBR_EL2: %016" PRIx64"\n" , ctxt->vttbr_el2); +printk (" TTBR0_EL2: %016" PRIx64"\n" ,READ_SYSREG64 (TTBR0_EL2 ));printk ("\n" ); +#endif printk (" SCTLR_EL2: %" PRIregister"\n" ,READ_SYSREG (SCTLR_EL2 ));printk (" HCR_EL2: %" PRIregister"\n" ,READ_SYSREG (HCR_EL2 )); -printk (" TTBR0_EL2: %016" PRIx64"\n" ,READ_SYSREG64 (TTBR0_EL2 ));printk ("\n" );printk (" ESR_EL2: %" PRIregister"\n" , regs->hsr);printk (" HPFAR_EL2: %" PRIregister"\n" ,READ_SYSREG (HPFAR_EL2 ));
@@ -931,9 +939,13 @@ void show_registers(const struct cpu_user_regs *regs) {struct reg_ctxt ctxt; ctxt.sctlr_el1 =READ_SYSREG (SCTLR_EL1 ); +#ifdef CONFIG_MMU ctxt.tcr_el1 =READ_SYSREG (TCR_EL1 ); ctxt.ttbr0_el1 =READ_SYSREG64 (TTBR0_EL1 ); ctxt.ttbr1_el1 =READ_SYSREG64 (TTBR1_EL1 ); + ctxt.vttbr_el2 =READ_SYSREG64 (VTTBR_EL2 ); +#endif +#ifdef CONFIG_ARM_32 ctxt.dfar =READ_CP32 (DFAR ); ctxt.ifar =READ_CP32 (IFAR );
@@ -945,7 +957,6 @@ void show_registers(const struct cpu_user_regs *regs)if (guest_mode (regs) &&is_32bit_domain (current->domain) ) ctxt.ifsr32_el2 =READ_SYSREG (IFSR32_EL2 );#endif - ctxt.vttbr_el2 =READ_SYSREG64 (VTTBR_EL2 );_show_registers (regs, &ctxt,guest_mode (regs), current); }
@@ -954,9 +965,11 @@ void vcpu_show_registers(const struct vcpu *v) {struct reg_ctxt ctxt; ctxt.sctlr_el1 = v->arch.sctlr; +#ifdef CONFIG_MMU ctxt.tcr_el1 = v->arch.ttbcr; ctxt.ttbr0_el1 = v->arch.ttbr0; ctxt.ttbr1_el1 = v->arch.ttbr1; +#endif #ifdef CONFIG_ARM_32 ctxt.dfar = v->arch.dfar; ctxt.ifar = v->arch.ifar;
Signature · 1 line
2.25.1
Re: [XEN v1 4/4] xen/arm: traps.c: Enclose VMSA specific registers within CONFIG_MMU
Hi, Ayan
Quoted 24 lines · Ayan Kumar Halder
The VMSA specific registers (ie TCR, TTBR0, TTBR1, VTTBR, etc) are valid when MMU is used, thus we can enclose them with
CONFIG_MMU.Signed-off-by Ayan Kumar Halder <[email protected]>--- xen/arch/arm/traps.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)xen/arch/arm/traps.c +2
-0@@ -698,8 +698,10 @@ static void __do_trap_serror(struct cpu_user_regs *regs, bool guest)struct reg_ctxt {/* Guest-side state */ register_t sctlr_el1; +#ifdef CONFIG_MMU register_t tcr_el1;uint64_t ttbr0_el1, ttbr1_el1; +#endif #ifdef CONFIG_ARM_32 uint32_t dfsr, ifsr;uint32_t dfar, ifar;
xen/arch/arm/traps.c static void show_registers_32(const struct cpu_user_regs *regs, · line 810
Quoted 8 lines
xen/arch/arm/traps.c +2
-0@@ -801,9 +803,11 @@ static void show_registers_32(const struct cpu_user_regs *regs,if ( guest_mode_on ) {printk (" SCTLR: %" PRIregister"\n" , ctxt->sctlr_el1); +#ifdef CONFIG_MMU printk (" TCR: %" PRIregister"\n" , ctxt->tcr_el1);printk (" TTBR0: %016" PRIx64"\n" , ctxt->ttbr0_el1);printk (" TTBR1: %016" PRIx64"\n" , ctxt->ttbr1_el1); +#endif
FWIS, on v8R-AArch64, with MPU on EL2, we could still support VMSA on EL1, so registers like TTBR0_EL1/TCR_EL1 are valid. See ARM DDI 0600B.a Table G1-2 Alphabetical index of modified AArch64 System registers (continued) for detailed info.
Quoted 66 lines
xen/arch/arm/traps.c +11
-2printk(" IFAR: %08"PRIx32", IFSR: %08"PRIx32"\n" " DFAR: %08"PRIx32", DFSR: %08"PRIx32"\n",#ifdef CONFIG_ARM_64 @@ -873,9 +877,11 @@ static void show_registers_64(const struct cpu_user_regs *regs,printk (" FAR_EL1: %016" PRIx64"\n" , ctxt->far);printk ("\n" );printk (" SCTLR_EL1: %" PRIregister"\n" , ctxt->sctlr_el1); +#ifdef CONFIG_MMU printk (" TCR_EL1: %" PRIregister"\n" , ctxt->tcr_el1);printk (" TTBR0_EL1: %016" PRIx64"\n" , ctxt->ttbr0_el1);printk (" TTBR1_EL1: %016" PRIx64"\n" , ctxt->ttbr1_el1); +#endif printk ("\n" ); } }@@ -907,13 +913,15 @@ static void _show_registers(const struct cpu_user_regs *regs,show_registers_32 (regs, ctxt, guest_mode_on, v);#endif } +#ifdef CONFIG_MMU printk (" VTCR_EL2: %" PRIregister"\n" ,READ_SYSREG (VTCR_EL2 ));printk (" VTTBR_EL2: %016" PRIx64"\n" , ctxt->vttbr_el2); +printk (" TTBR0_EL2: %016" PRIx64"\n" ,READ_SYSREG64 (TTBR0_EL2 ));printk ("\n" ); +#endif printk (" SCTLR_EL2: %" PRIregister"\n" ,READ_SYSREG (SCTLR_EL2 ));printk (" HCR_EL2: %" PRIregister"\n" ,READ_SYSREG (HCR_EL2 )); -printk (" TTBR0_EL2: %016" PRIx64"\n" ,READ_SYSREG64 (TTBR0_EL2 ));printk ("\n" );printk (" ESR_EL2: %" PRIregister"\n" , regs->hsr);printk (" HPFAR_EL2: %" PRIregister"\n" ,READ_SYSREG (HPFAR_EL2 ));@@ -931,9 +939,13 @@ void show_registers(const struct cpu_user_regs *regs) {struct reg_ctxt ctxt; ctxt.sctlr_el1 =READ_SYSREG (SCTLR_EL1 ); +#ifdef CONFIG_MMU ctxt.tcr_el1 =READ_SYSREG (TCR_EL1 ); ctxt.ttbr0_el1 =READ_SYSREG64 (TTBR0_EL1 ); ctxt.ttbr1_el1 =READ_SYSREG64 (TTBR1_EL1 ); + ctxt.vttbr_el2 =READ_SYSREG64 (VTTBR_EL2 ); +#endif +#ifdef CONFIG_ARM_32 ctxt.dfar =READ_CP32 (DFAR ); ctxt.ifar =READ_CP32 (IFAR );@@ -945,7 +957,6 @@ void show_registers(const struct cpu_user_regs *regs)if (guest_mode (regs) &&is_32bit_domain (current->domain) ) ctxt.ifsr32_el2 =READ_SYSREG (IFSR32_EL2 );#endif - ctxt.vttbr_el2 =READ_SYSREG64 (VTTBR_EL2 );_show_registers (regs, &ctxt,guest_mode (regs), current); }@@ -954,9 +965,11 @@ void vcpu_show_registers(const struct vcpu *v) {struct reg_ctxt ctxt; ctxt.sctlr_el1 = v->arch.sctlr; +#ifdef CONFIG_MMU ctxt.tcr_el1 = v->arch.ttbcr; ctxt.ttbr0_el1 = v->arch.ttbr0; ctxt.ttbr1_el1 = v->arch.ttbr1; +#endif #ifdef CONFIG_ARM_32 ctxt.dfar = v->arch.dfar; ctxt.ifar = v->arch.ifar;
Re: [XEN v1 4/4] xen/arm: traps.c: Enclose VMSA specific registers within CONFIG_MMU
Quoted 1 line · Penny Zheng
Hi, Ayan
Hi Penny,
Quoted 31 lines · Ayan Kumar Halder
Quoted 29 lines
The VMSA specific registers (ie TCR, TTBR0, TTBR1, VTTBR, etc) are valid when MMU is used, thus we can enclose them with
CONFIG_MMU.Signed-off-by Ayan Kumar Halder <[email protected]>---
xen/arch/arm/traps.c| 17 +++++++++++++++--1 file changed, 15 insertions(+), 2 deletions(-)xen/arch/arm/traps.c +2
-0@@ -698,8 +698,10 @@ static void __do_trap_serror(struct cpu_user_regs *regs, bool guest) struct reg_ctxt { /* Guest-side state */ register_t sctlr_el1; +#ifdef CONFIG_MMU register_t tcr_el1; uint64_t ttbr0_el1, ttbr1_el1; +#endif #ifdef CONFIG_ARM_32 uint32_t dfsr, ifsr;
uint32_tdfar, ifar;xen/arch/arm/traps.c +0
-0@@ -801,9 +803,11 @@ static void show_registers_32(const struct cpu_user_regs *regs, if ( guest_mode_on ) { printk(" SCTLR: %"PRIregister"\n", ctxt->sctlr_el1);
Quoted 8 lines
xen/arch/arm/traps.c static void show_registers_32(const struct cpu_user_regs *regs, · line 810
Quoted 5 lines
xen/arch/arm/traps.c +2
-0+#ifdef CONFIG_MMU printk(" TCR: %"PRIregister"\n", ctxt->tcr_el1); printk(" TTBR0: %016"PRIx64"\n", ctxt->ttbr0_el1); printk(" TTBR1: %016"PRIx64"\n", ctxt->ttbr1_el1); +#endif FWIS, on v8R-AArch64, with MPU on EL2, we could still support VMSA on EL1, so registers like TTBR0_EL1/TCR_EL1 are valid. See ARM DDI 0600B.a Table G1-2 Alphabetical index of modified AArch64 System registers (continued) for detailed info.
Actually, you are correct. And, we should not be using CONFIG_MMU to enclose VMSA EL1 registers. I am ok to drop this patch.
However, refer G1.3.7 "ID_AA64MMFR0_EL1, AArch64 Memory Model Feature Register 0"
When MSA_frac, bits [55:52] == 0b0001, then there is no support for VMSAv8-64. IIUC, VMSA EL1 registers will not be present.
If this is correct, then we might need to have AARCH64_V8R specific config as ID_AA64MMFR0_EL1 can be interpreted for this configuration only.
Appreciate your comments.
- Ayan
Quoted 69 lines
Quoted 69 lines
printk(" IFAR: %08"PRIx32", IFSR: %08"PRIx32"\n" " DFAR: %08"PRIx32", DFSR: %08"PRIx32"\n", #ifdef
CONFIG_ARM_64xen/arch/arm/traps.c +2
-0@@ -873,9 +877,11 @@ static void show_registers_64(const struct cpu_user_regs *regs, printk(" FAR_EL1: %016"PRIx64"\n", ctxt->far); printk("\n"); printk(" SCTLR_EL1: %"PRIregister"\n", ctxt->sctlr_el1); +#ifdef CONFIG_MMU printk(" TCR_EL1: %"PRIregister"\n", ctxt->tcr_el1); printk(" TTBR0_EL1: %016"PRIx64"\n", ctxt->ttbr0_el1); printk(" TTBR1_EL1: %016"PRIx64"\n", ctxt->ttbr1_el1); +#endif printk("\n"); }}
xen/arch/arm/traps.c +7
-1@@ -907,13 +913,15 @@ static void _show_registers(const structcpu_user_regs *regs, show_registers_32(regs, ctxt, guest_mode_on, v); #endif } +#ifdef CONFIG_MMU printk(" VTCR_EL2: %"PRIregister"\n", READ_SYSREG(VTCR_EL2)); printk(" VTTBR_EL2: %016"PRIx64"\n", ctxt->vttbr_el2); + printk(" TTBR0_EL2: %016"PRIx64"\n", READ_SYSREG64(TTBR0_EL2)); printk("\n"); +#endif printk(" SCTLR_EL2: %"PRIregister"\n", READ_SYSREG(SCTLR_EL2)); printk(" HCR_EL2: %"PRIregister"\n", READ_SYSREG(HCR_EL2)); - printk(" TTBR0_EL2: %016"PRIx64"\n", READ_SYSREG64(TTBR0_EL2)); printk("\n"); printk(" ESR_EL2: %"PRIregister"\n", regs->hsr); printk(" HPFAR_EL2: %"PRIregister"\n", READ_SYSREG(HPFAR_EL2));@@ -931,9 +939,13 @@ void show_registers(const struct cpu_user_regs *regs) { struct reg_ctxt ctxt; ctxt.sctlr_el1 = READ_SYSREG(SCTLR_EL1); +#ifdef CONFIG_MMU ctxt.tcr_el1 = READ_SYSREG(TCR_EL1); ctxt.ttbr0_el1 = READ_SYSREG64(TTBR0_EL1); ctxt.ttbr1_el1 = READ_SYSREG64(TTBR1_EL1); + ctxt.vttbr_el2 = READ_SYSREG64(VTTBR_EL2); +#endif + #ifdef CONFIG_ARM_32 ctxt.dfar = READ_CP32(DFAR);ctxt.ifar =
READ_CP32(IFAR);xen/arch/arm/traps.c +2
-1@@ -945,7 +957,6 @@ void show_registers(const struct cpu_user_regs *regs) if ( guest_mode(regs) && is_32bit_domain(current->domain) ) ctxt.ifsr32_el2 = READ_SYSREG(IFSR32_EL2); #endif - ctxt.vttbr_el2 = READ_SYSREG64(VTTBR_EL2); _show_registers(regs, &ctxt, guest_mode(regs), current); }@@ -954,9 +965,11 @@ void vcpu_show_registers(const struct vcpu *v) { struct reg_ctxt ctxt; ctxt.sctlr_el1 = v->arch.sctlr; +#ifdef CONFIG_MMU ctxt.tcr_el1 = v->arch.ttbcr; ctxt.ttbr0_el1 = v->arch.ttbr0; ctxt.ttbr1_el1 = v->arch.ttbr1; +#endif #ifdef CONFIG_ARM_32 ctxt.dfar = v->arch.dfar; ctxt.ifar = v->arch.ifar;