xen/riscv: introduce identity mapping
v2 cover xen/riscv: introduce identity mapping
The patch series introduces things necessary to implement identity mapping:
1. Make identity mapping for the entire Xen.
2. Enable MMU.
3. Jump to the virtual address world
4. Remove identity mapping.
Also current patch series introduces the calculation of physical offset before MMU is enabled as access to physical offset will be calculated wrong after MMU will be enabled because access to phys_off variable is PC-relative and in the case when linker address != load address, it will cause MMU fault.
One more thing that was done is:
* Added SPDX tags.
* move extern of cpu0_boot_stack to a header.
The reason for this patch series can be found here:
https://lore.kernel.org/xen-devel/[email protected]/
---
Changes in V2:
- update the patch series message.
- drop patches from the previous version of the patch series:
* xen/riscv: add __ASSEMBLY__ guards". ( merged )
* xen/riscv: make sure that identity mapping isn't bigger then page size ( entire Xen is 1:1 mapped so there is no need for the checks from the patch )
- add .sbss.* and put it befor .bss* .
- move out reset_stack() to .text section.
- add '__ro_after_init' for phys_offset variable.
- add '__init' for calc_phys_offset().
- declaring variable phys_off as non static as it will be used in head.S.
- update definition of PGTBL_INITIAL_COUNT and the comment above.
- code style fixes.
- remove id_addrs array becase entire Xen is mapped.
- reverse condition for cycle inside remove_identity_mapping().
- fix page table walk in remove_identity_mapping().
- save hart_id and dtb_addr before call MMU related C functions
- use phys_offset variable instead of doing calcultations to get phys offset in head.S file. ( it can be easily done as entire Xen is 1:1 mapped now )
- declare enable_muu() as __init.
- Update SPDX tags.
- Add Review-By/Suggested-By for some patches.
- code style fixes.
Oleksii Kurochko (6):
xen/riscv: add .sbss section to .bss
xen/riscv: introduce reset_stack() function xen/riscv: introduce function for physical offset calculation xen/riscv: introduce identity mapping
xen/riscv: add SPDX tags
xen/riscv: move extern of cpu0_boot_stack to header
xen/arch/riscv/include/asm/config.h | 2 + xen/arch/riscv/include/asm/current.h | 2 + xen/arch/riscv/include/asm/early_printk.h | 2 + xen/arch/riscv/include/asm/mm.h | 9 +- xen/arch/riscv/include/asm/page-bits.h | 2 + xen/arch/riscv/include/asm/page.h | 2 + xen/arch/riscv/include/asm/traps.h | 2 + xen/arch/riscv/include/asm/types.h | 2 + xen/arch/riscv/mm.c | 104 +++++++++++++--------- xen/arch/riscv/riscv64/head.S | 46 +++++++++- xen/arch/riscv/setup.c | 16 +--- xen/arch/riscv/xen.lds.S | 2 +- 12 files changed, 136 insertions(+), 55 deletions(-)
Signature · 1 line
2.40.1
PATCH v2 1/6 xen/riscv: add .sbss section to .bss
Sometimes variables are located in .sbss section but it won't be mapped after MMU will be enabled.
To avoid MMU failures .sbss should be mapped
---
Changes in V2:
- add .sbss.*.
- move .sbss* ahead of .bss*.
- add Acked-by: Alistair Francis <[email protected]>
--- xen/arch/riscv/xen.lds.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/riscv/xen.lds.S +1 -1
@@ -149,7 +149,7 @@ SECTIONS *(.bss.percpu.read_mostly) . = ALIGN(SMP_CACHE_BYTES); __per_cpu_data_end = .; - *(.bss .bss.*) + *(.sbss .sbss.* .bss .bss.*) . = ALIGN(POINTER_ALIGN); __bss_end = .; } :text
Signature · 1 line
2.40.1
PATCH v2 2/6 xen/riscv: introduce reset_stack() function
In reply to Oleksii KurochkoThe reason for reset_stack() introduction is that stack should be reset twice:
1. Before jumping to C world at the start of _start() function.
2. After jumping from 1:1 mapping world.
---
Changes in V2:
- update the commit message.
- move out reset_stack() from .text.header to .text.
- add Reviewed-by: Alistair Francis <[email protected]>.
--- xen/arch/riscv/riscv64/head.S | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
xen/arch/riscv/riscv64/head.S +9 -1
@@ -27,8 +27,16 @@ ENTRY(start) add t3, t3, __SIZEOF_POINTER__ bltu t3, t4, .L_clear_bss + jal reset_stack + + tail start_xen + + .section .text, "ax", %progbits + +ENTRY(reset_stack) la sp, cpu0_boot_stack li t0, STACK_SIZE add sp, sp, t0 - tail start_xen + ret +
Signature · 1 line
2.40.1
Re: [PATCH v2 2/6] xen/riscv: introduce reset_stack() function
Quoted 10 lines · Oleksii Kurochko
xen/arch/riscv/riscv64/head.S +4
-0@@ -27,8 +27,16 @@ ENTRY(start) add t3, t3, __SIZEOF_POINTER__ bltu t3, t4, .L_clear_bss + jal reset_stack + + tail start_xen +
xen/arch/riscv/riscv64/head.S ENTRY(start) · line 42
Quoted 10 lines
xen/arch/riscv/riscv64/head.S +5
-1+ .section .text, "ax", %progbits + +ENTRY(reset_stack) la sp, cpu0_boot_stack li t0, STACK_SIZE add sp, sp, t0 - tail start_xen + ret +
Looking at patch 4 you will want to add a comment here to emphasize that a0 and a1 have to remain unclobbered.
Jan
Re: [PATCH v2 2/6] xen/riscv: introduce reset_stack() function
Quoted 16 lines · Jan Beulich
Quoted 15 lines · Oleksii Kurochko
xen/arch/riscv/riscv64/head.S +0
-0@@ -27,8 +27,16 @@ ENTRY(start)add t3, t3,
__SIZEOF_POINTER__
bltu t3, t4, .L_clear_bss
+ jalreset_stackxen/arch/riscv/riscv64/head.S +6
-0+ + tail start_xen + + .section .text, "ax", %progbits + +ENTRY(reset_stack)la sp,
cpu0_boot_stack
li t0,STACK_SIZE
Quoted 8 lines
Quoted 5 lines
add sp, sp, t0
- tailstart_xen
+ ret
+Looking at patch 4 you will want to add a comment here to emphasize that a0 and a1 have to remain unclobbered.
Thanks for a note. I'll add it in the new patch version
~ Oleksii
Re: [PATCH v2 2/6] xen/riscv: introduce reset_stack() function
Quoted 25 lines · Oleksii
Quoted 16 lines · Jan Beulich
Quoted 15 lines · Oleksii Kurochko
xen/arch/riscv/riscv64/head.S +0
-0@@ -27,8 +27,16 @@ ENTRY(start)add t3, t3,
__SIZEOF_POINTER__
bltu t3, t4, .L_clear_bss
+ jalreset_stackxen/arch/riscv/riscv64/head.S +6
-0+ + tail start_xen + + .section .text, "ax", %progbits + +ENTRY(reset_stack)la sp,
cpu0_boot_stack
li t0,STACK_SIZEQuoted 8 lines
Quoted 5 lines
add sp, sp, t0
- tailstart_xen
+ ret
+Looking at patch 4 you will want to add a comment here to emphasize that a0 and a1 have to remain unclobbered.
Quoted 1 line
Thanks for a note. I'll add it in the new patch version
Having seen how things end up by the end of the series, there's an
alternative: You could save a0 and a1 ahead of the 1st call to reset_stack, rather than immediately afterwards.
Jan
Re: [PATCH v2 2/6] xen/riscv: introduce reset_stack() function
Quoted 27 lines · Jan Beulich
Quoted 26 lines · Oleksii
Quoted 25 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
xen/arch/riscv/riscv64/head.S +0
-0@@ -27,8 +27,16 @@ ENTRY(start)add t3, t3,
__SIZEOF_POINTER__
bltu t3, t4, .L_clear_bss
+ jalreset_stackxen/arch/riscv/riscv64/head.S +6
-0+ + tail start_xen + + .section .text, "ax", %progbits + +ENTRY(reset_stack)Quoted 7 lines
la sp,
cpu0_boot_stack
li t0,STACK_SIZE
add sp, sp, t0
- tailstart_xen
+ ret
+Looking at patch 4 you will want to add a comment here to emphasize
that a0 and a1 have to remain unclobbered.
Quoted 5 lines
Quoted 1 line
Thanks for a note. I'll add it in the new patch version
Having seen how things end up by the end of the series, there's an
alternative: You could save a0 and a1 ahead of the 1st call toreset_stack, rather than immediately afterwards.
It makes sense. So lets stick to saving of a0 and a1 before 1st call of reset_stack().
~ Oleksii
PATCH v2 3/6 xen/riscv: introduce function for physical offset calculation
In reply to Oleksii KurochkoThe function was introduced to calculate and save physical offset before MMU is enabled because access to start() is PC-relative and in case of linker_addr != load_addr it will result in incorrect value in phys_offset.
---
Changes in V2:
- add __ro_after_init for phys_offset variable.
- remove double blank lines.
- add __init for calc_phys_offset().
- update the commit message.
- declaring variable phys_off as non static as it will be used in head.S.
--- xen/arch/riscv/include/asm/mm.h | 2 ++ xen/arch/riscv/mm.c | 18 +++++++++++++++--- xen/arch/riscv/riscv64/head.S | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-)
xen/arch/riscv/include/asm/mm.h +2 -0
@@ -11,4 +11,6 @@ void setup_initial_pagetables(void);void enable_mmu (void );void cont_after_mmu_is_enabled (void ); +void calc_phys_offset (void ); +#endif /* _ASM_RISCV_MM_H */
xen/arch/riscv/mm.c +15 -3
@@ -1,3 +1,4 @@ +#include <xen/cache.h> #include <xen/compiler.h> #include <xen/init.h> #include <xen/kernel.h>
@@ -19,9 +20,10 @@ struct mmu_desc {extern unsigned char cpu0_boot_stack[STACK_SIZE ]; -#define PHYS_OFFSET ((unsigned long)_start - XEN_VIRT_START) -#define LOAD_TO_LINK (addr) ((addr) - PHYS_OFFSET) -#define LINK_TO_LOAD (addr) ((addr) + PHYS_OFFSET) +unsigned long __ro_after_init phys_offset; + +#define LOAD_TO_LINK (addr) ((unsigned long)(addr) - phys_offset) +#define LINK_TO_LOAD (addr) ((unsigned long)(addr) + phys_offset)/* * It is expected that Xen won't be more then 2 MB.
@@ -273,3 +275,13 @@ void __init noreturn noinline enable_mmu()switch_stack_and_jump ((unsigned long )cpu0_boot_stack +STACK_SIZE , cont_after_mmu_is_enabled); } + +/* +* calc_phys_offset() should be used before MMU is enabled because access to +* start() is PC-relative and in case when load_addr != linker_addr phys_offset +* will have an incorrect value +*/ +void __init calc_phys_offset (void ) +{ + phys_offset = (unsigned long )start -XEN_VIRT_START ; +}
xen/arch/riscv/riscv64/head.S +2 -0
@@ -29,6 +29,8 @@ ENTRY(start) jal reset_stack + jal calc_phys_offset + tail start_xen .section .text, "ax", %progbits
Signature · 1 line
2.40.1
Re: [PATCH v2 3/6] xen/riscv: introduce function for physical offset calculation
xen/arch/riscv/riscv64/head.S ENTRY(start) · line 36
Quoted 11 lines · Oleksii Kurochko
xen/arch/riscv/riscv64/head.S +2
-0@@ -29,6 +29,8 @@ ENTRY(start) jal reset_stack + jal calc_phys_offset + tail start_xen .section .text, "ax", %progbits
Since you call a C function, the code to save/restore a0/a1 needs to move here (from patch 4).
Jan
Re: [PATCH v2 3/6] xen/riscv: introduce function for physical offset calculation
Quoted 15 lines · Jan Beulich
Quoted 11 lines · Oleksii Kurochko
xen/arch/riscv/riscv64/head.S +0
-0@@ -29,6 +29,8 @@ ENTRY(start)
jalreset_stack
+ jalcalc_phys_offset
+
tailstart_xen
.section .text, "ax", %progbitsSince you call a C function, the code to save/restore a0/a1 needs to move here (from patch 4).
Thanks. It makes sense.
It would be better to move save/restore a0/a1 ( from patch 4 )code here.
The only one reason I didn't do that before that calc_phys_offset doesn't touch that and it is guaranteed that it will not ( as it doesn't have arguments )
~ Oleksii
Re: [PATCH v2 3/6] xen/riscv: introduce function for physical offset calculation
Quoted 16 lines · Oleksii
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Oleksii Kurochko
xen/arch/riscv/riscv64/head.S +0
-0@@ -29,6 +29,8 @@ ENTRY(start) jal reset_stackQuoted 8 lines
xen/arch/riscv/riscv64/head.S ENTRY(start) · line 36
Quoted 5 lines
xen/arch/riscv/riscv64/head.S +2
-0+ jal calc_phys_offset + tail start_xen .section .text, "ax", %progbitsSince you call a C function, the code to save/restore a0/a1 needs to move here (from patch 4).
Quoted 7 lines
Thanks. It makes sense.
It would be better to move save/restore a0/a1 ( from patch 4 )code here.The only one reason I didn't do that before that
calc_phys_offsetdoesn't touch that and it is guaranteed that it will not ( as it doesn't have arguments )
IIUC, the calling convention requires a0/a1 to be caller saved. So even if they are not used for arguments, such callee is still free to use them for internal purpose.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 3/6] xen/riscv: introduce function for physical offset calculation
Quoted 24 lines · Julien Grall
Quoted 21 lines · Oleksii
Quoted 16 lines · Jan Beulich
Quoted 11 lines · Oleksii Kurochko
xen/arch/riscv/riscv64/head.S +0
-0@@ -29,6 +29,8 @@ ENTRY(start)
jalreset_stack
+ jalcalc_phys_offset
+
tailstart_xen
.section .text, "ax", %progbitsSince you call a C function, the code to save/restore a0/a1 needs to
move here (from patch 4).Thanks. It makes sense.
It would be better to move save/restore a0/a1 ( from patch 4 )code here.
Quoted 8 lines
Quoted 3 lines
The only one reason I didn't do that before that
calc_phys_offsetdoesn't touch that and it is guaranteed that it will not ( as it doesn't have arguments )IIUC, the calling convention requires a0/a1 to be caller saved. So even
if they are not used for arguments, such callee is still free to use them for internal purpose.
You are right.
I haven't seen that compiler use them if 'void' is passed to function as an argument. But I agree that we have to follow the calling convention to be sure that all is fine.
~ Oleksii
Re: [PATCH v2 3/6] xen/riscv: introduce function for physical offset calculation
In reply to OleksiiQuoted 16 lines · Oleksii
Quoted 15 lines · Jan Beulich
Quoted 11 lines · Oleksii Kurochko
xen/arch/riscv/riscv64/head.S +0
-0@@ -29,6 +29,8 @@ ENTRY(start)
jalreset_stack
+ jalcalc_phys_offset
+
tailstart_xen
.section .text, "ax", %progbitsSince you call a C function, the code to save/restore a0/a1 needs to move here (from patch 4).
Quoted 7 lines
Thanks. It makes sense.
It would be better to move save/restore a0/a1 ( from patch 4 )code here.The only one reason I didn't do that before that
calc_phys_offsetdoesn't touch that and it is guaranteed that it will not ( as it doesn't have arguments )
How does a function not having parameters guarantee that registers used for parameter passing aren't touched? Inside a function, the compiler is free to use argument-passing registers just like other temporary ones; their values don't need preserving, from all I know (otherwise the RISC-V ABI would be different to all other ABIs I know of).
Jan
Re: [PATCH v2 3/6] xen/riscv: introduce function for physical offset calculation
Quoted 26 lines · Jan Beulich
Quoted 17 lines · Oleksii
Quoted 16 lines · Jan Beulich
Quoted 11 lines · Oleksii Kurochko
xen/arch/riscv/riscv64/head.S +0
-0@@ -29,6 +29,8 @@ ENTRY(start)
jalreset_stack
+ jalcalc_phys_offset
+
tailstart_xen
.section .text, "ax", %progbitsSince you call a C function, the code to save/restore a0/a1 needs to
move here (from patch 4).Quoted 7 lines
Thanks. It makes sense.
It would be better to move save/restore a0/a1 ( from patch 4 )code here.The only one reason I didn't do that before that
calc_phys_offsetdoesn't touch that and it is guaranteed that it will not ( as it doesn't have arguments )
Quoted 6 lines
How does a function not having parameters guarantee that registers used for parameter passing aren't touched? Inside a function, the compiler is free to use argument-passing registers just like other temporary ones; their values don't need preserving, from all I know (otherwise the RISC-V ABI would be different to all other ABIs I know of).
Well, you are right that it doesn't guarantee and the calling convention tells that arg registers should be saved/restored before/after function call.
But I haven't seen yet that compiler touch arg registers if function accepts 'void' as an function argument. So 'guarantee' isn't correct word.
Thanks for the note.
~ Oleksii
PATCH v2 4/6 xen/riscv: introduce identity mapping
In reply to Oleksii KurochkoThe way how switch to virtual address was implemented in the commit e66003e7be ("xen/riscv: introduce setup_initial_pages") isn't safe enough as:
* enable_mmu() depends on hooking all exceptions
and pagefault.
* Any exception other than pagefault, or not taking a pagefault causes it to malfunction, which means you will fail to boot depending on where Xen was loaded into memory.
Instead of the proposed way of switching to virtual addresses was decided to use identity mapping of the entrire Xen and after switching to virtual addresses identity mapping is removed from page-tables.
Since it is not easy to keep track where the identity map was mapped, so we will look for the top-level entry exclusive to the identity map and remove it.
---
Changes in V2:
- update definition of PGTBL_INITIAL_COUNT and the comment above.
- code style fixes.
- 1:1 mapping for entire Xen.
- remove id_addrs array becase entire Xen is mapped.
- reverse condition for cycle inside remove_identity_mapping().
- fix page table walk in remove_identity_mapping().
- update the commit message.
- add Suggested-by: Andrew Cooper <[email protected]>
- save hart_id and dtb_addr before call MMU related C functions.
- use phys_offset variable instead of doing calcultations to get phys offset in head.S file. ( it can be easily done as entire Xen is 1:1 mapped )
- declare enable_muu() as __init.
--- xen/arch/riscv/include/asm/config.h | 2 + xen/arch/riscv/include/asm/mm.h | 3 +- xen/arch/riscv/mm.c | 84 ++++++++++++++++------------- xen/arch/riscv/riscv64/head.S | 34 ++++++++++++ xen/arch/riscv/setup.c | 14 +---- 5 files changed, 88 insertions(+), 49 deletions(-)
xen/arch/riscv/include/asm/config.h +2 -0
@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __RISCV_CONFIG_H__#define __RISCV_CONFIG_H__
xen/arch/riscv/include/asm/mm.h +2 -1
@@ -9,7 +9,8 @@void setup_initial_pagetables (void );void enable_mmu (void ); -void cont_after_mmu_is_enabled (void ); + +void remove_identity_mapping (void );void calc_phys_offset (void );
xen/arch/riscv/mm.c +48 -36
131 lines not on this page · raw message
xen/arch/riscv/riscv64/head.S +34 -0
@@ -29,8 +29,42 @@ ENTRY(start) jal reset_stack + /* + * save hart_id and dtb_base as a0 and a1 register can be used + * by C code ( f.e. setup_initial_pagetables will update a0 and + * a1 ) + */ + mv s0, a0 + mv s1, a1 + jal calc_phys_offset + jal setup_initial_pagetables + + jal enable_mmu + + la t1, phys_offset + REG_L t1, (t1) + + /* Calculate proper VA after jump from 1:1 mapping */ + la t0, .L_primary_switched + sub t0, t0, t1 + + /* Jump from 1:1 mapping world */ + jr t0 + +.L_primary_switched: + /* + * cpu0_boot_stack address is 1:1 mapping related so it should be + * recalculated after jump from 1:1 mapping world as 1:1 mapping + * will be removed soon in start_xen(). + */ + jal reset_stack + + /* restore bootcpu_id and dtb address */ + mv a0, s0 + mv a1, s1 + tail start_xen .section .text, "ax", %progbits
xen/arch/riscv/setup.c +2 -12
@@ -11,20 +11,10 @@ unsigned char __initdata cpu0_boot_stack[STACK_SIZE]void __init noreturnstart_xen (unsigned long bootcpu_id,paddr_t dtb_addr) { -early_printk ("Hello from C env\n" ); - -setup_initial_pagetables (); - -enable_mmu (); - -for ( ;; ) - asmvolatile ("wfi" ); +remove_identity_mapping (); -unreachable (); -} +early_printk ("Hello from C env\n" ); -void __init noreturncont_after_mmu_is_enabled (void ) -{early_printk ("All set up\n" );for ( ;; )
Signature · 1 line
2.40.1
Quoted 3 lines · Oleksii Kurochko
Since it is not easy to keep track where the identity map was mapped, so we will look for the top-level entry exclusive to the identity map and remove it.
I think you mean "top-most" or some such, as it's not necessarily the top-level entry you zap.
xen/arch/riscv/include/asm/config.h line 5
Quoted 8 lines
xen/arch/riscv/include/asm/config.h +2
-0@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __RISCV_CONFIG_H__#define __RISCV_CONFIG_H__
Unrelated change?
Quoted 16 lines
xen/arch/riscv/mm.c +6
-0@@ -25,6 +25,12 @@ unsigned long __ro_after_init phys_offset;#define LOAD_TO_LINK (addr) ((unsigned long)(addr) - phys_offset)#define LINK_TO_LOAD (addr) ((unsigned long)(addr) + phys_offset) +/* +* Should be removed as soon as enough headers will be merged for inclusion of +* <xen/lib.h>. +*/ +#define ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0])) +/* * It is expected that Xen won't be more then 2 MB. * The check in xen.lds.S guarantees that.
xen/arch/riscv/mm.c unsigned long __ro_after_init phys_offset; · line 47
Quoted 8 lines
xen/arch/riscv/mm.c +3
-1@@ -35,8 +41,10 @@ unsigned long __ro_after_init phys_offset;* * It might be needed one more page table in case when Xen load address * isn't 2 MB aligned. +* +* (CONFIG_PAGING_LEVELS - 1) page tables are needed for identity mapping. */ -#define PGTBL_INITIAL_COUNT ((CONFIG_PAGING_LEVELS - 1) + 1) +#define PGTBL_INITIAL_COUNT ((CONFIG_PAGING_LEVELS - 1) * 2 + 1)
How come the extra page (see the comment sentence in context) isn't needed for the identity-mapping case?
Quoted 22 lines
xen/arch/riscv/mm.c +2
-15@@ -255,25 +262,30 @@ void __init noreturn noinline enable_mmu()csr_write (CSR_SATP ,PFN_DOWN ((unsigned long )stage1_pgtbl_root) |RV_STAGE1_MODE <<SATP_MODE_SHIFT ); +} - asmvolatile (".p2align 2" ); - mmu_is_enabled: -/* -* Stack should be re-inited as: -* 1. Right now an address of the stack is relative to load time -* addresses what will cause an issue in case of load start address -* isn't equal to linker start address. -* 2. Addresses in stack are all load time relative which can be an -* issue in case when load start address isn't equal to linker -* start address. -* -* We can't return to the caller because the stack was reseted -* and it may have stash some variable on the stack. -* Jump to a brand new function as the stack was reseted -*/ +void __init remove_identity_mapping (void )
xen/arch/riscv/mm.c void __init noreturn noinline enable_mmu() · line 275
Quoted 10 lines
xen/arch/riscv/mm.c +7
-2+{ +unsigned int i; +pte_t *pgtbl; +unsigned int index, xen_index; +unsigned long load_addr =LINK_TO_LOAD (_start); -switch_stack_and_jump ((unsigned long )cpu0_boot_stack +STACK_SIZE , - cont_after_mmu_is_enabled); + for ( pgtbl = stage1_pgtbl_root, i = 0; + i <= (CONFIG_PAGING_LEVELS - 1);
i < CONFIG_PAGING_LEVELS ? But maybe it would be easier for i to start at CONFIG_PAGING_LEVELS and be decremented, simplifying ...
xen/arch/riscv/mm.c void __init noreturn noinline enable_mmu() · line 279
Quoted 4 lines
xen/arch/riscv/mm.c +4
-0+ i++ ) + { + index =pt_index (CONFIG_PAGING_LEVELS -1 - i, load_addr); + xen_index =pt_index (CONFIG_PAGING_LEVELS -1 - i,XEN_VIRT_START );
... these two expressions?
xen/arch/riscv/mm.c void __init noreturn noinline enable_mmu() · line 285
Quoted 5 lines
xen/arch/riscv/mm.c +5
-0+if ( index != xen_index ) + { + pgtbl[index].pte =0 ; +break ; + }
Is this enough? When load and link address are pretty close (but not overlapping), can't they share a leaf table, in which case you need to clear more than just a single entry? The present overlap check looks to be 4k-granular, not 2M (in which case this couldn't happen; IOW adjusting the overlap check may also be a way out).
Jan
Quoted 8 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
Since it is not easy to keep track where the identity map was mapped,
so we will look for the top-level entry exclusive to the identity map and remove it.I think you mean "top-most" or some such, as it's not necessarily the top-level entry you zap.
Yeah, 'top-most' is more appropriate in this context.
Quoted 11 lines
Quoted 9 lines
xen/arch/riscv/include/asm/config.h +2
-0@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + #ifndef __RISCV_CONFIG_H__ #define __RISCV_CONFIG_H__Unrelated change?
It should be part of [PATCH v2 5/6] xen/riscv: introduce identity mapping.
Quoted 24 lines
Quoted 24 lines
xen/arch/riscv/mm.c +0
-0@@ -25,6 +25,12 @@ unsigned long __ro_after_init phys_offset; #define LOAD_TO_LINK(addr) ((unsigned long)(addr) - phys_offset) #define LINK_TO_LOAD(addr) ((unsigned long)(addr) + phys_offset)
+/*
+ * Should be removed as soon as enough headers will be merged for inclusion of
+ * <xen/lib.h>.
+ */
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
/*
* It is expected that Xen won't be more then 2 MB.
* The check inxen.lds.Sguarantees that.xen/arch/riscv/mm.c +0
-0@@ -35,8 +41,10 @@ unsigned long __ro_after_init phys_offset; * * It might be needed one more page table in case when Xen loadaddress
* isn't 2 MB aligned.
+ *
Quoted 8 lines
xen/arch/riscv/mm.c unsigned long __ro_after_init phys_offset; · line 47
Quoted 5 lines
+ * (
CONFIG_PAGING_LEVELS- 1) page tables are needed for identity mapping.
*/xen/arch/riscv/mm.c +1
-1-#define PGTBL_INITIAL_COUNT ((CONFIG_PAGING_LEVELS - 1) + 1) +#define PGTBL_INITIAL_COUNT ((CONFIG_PAGING_LEVELS - 1) * 2 + 1)How come the extra page (see the comment sentence in context) isn't needed for the identity-mapping case?
It is needed to allocate no more than two 'nonroot' page tables (L0 and L1 in case of Sv39 ) as page 'root' table ( L2 in case of Sv39 ) is always re-used.
The same ( only 'nonroot' page tables might be needed to allocate ) works for any MMU mode.
Quoted 43 lines
Quoted 32 lines
xen/arch/riscv/mm.c +0
-0@@ -255,25 +262,30 @@ void __init noreturn noinline enable_mmu() csr_write(CSR_SATP,
PFN_DOWN((unsigned long)stage1_pgtbl_root)|RV_STAGE1_MODE<<SATP_MODE_SHIFT);
+}
- asm volatile ( ".p2align 2" );
-mmu_is_enabled:
- /*
- * Stack should be re-inited as:
- * 1. Right now an address of the stack is relative to load time
- * addresses what will cause an issue in case of load start address
- * isn't equal to linker start address.
- * 2. Addresses in stack are all load time relative which can be an
- * issue in case when load start address isn't equal to linker
- * start address.
- *
- * We can't return to the caller because the stack was reseted - * and it may have stash some variable on the stack. - * Jump to a brand new function as the stack was reseted - */xen/arch/riscv/mm.c +6
-0+void __init remove_identity_mapping (void ) +{ + unsigned int i; + pte_t *pgtbl; + unsigned int index, xen_index; + unsigned long load_addr = LINK_TO_LOAD(_start);Quoted 6 lines
- switch_stack_and_jump((unsigned long)cpu0_boot_stack +STACK_SIZE,
-cont_after_mmu_is_enabled); + for ( pgtbl =stage1_pgtbl_root, i = 0;
+ i <= (CONFIG_PAGING_LEVELS- 1);i <
CONFIG_PAGING_LEVELS? But maybe it would be easier for i to start
atCONFIG_PAGING_LEVELSand be decremented, simplifying ...
Quoted 7 lines
Quoted 5 lines
+ i++ )
+ {
+ index =pt_index(CONFIG_PAGING_LEVELS - 1 - i, load_addr); +xen_index=pt_index(CONFIG_PAGING_LEVELS - 1 - i, XEN_VIRT_START);... these two expressions?
It makes sense. I'll update this part of the code.
Quoted 7 lines
Quoted 6 lines
+ if ( index !=
xen_index)
+ {
+ pgtbl[index].pte = 0;
+ break;
+ }
Quoted 5 lines
Is this enough? When load and link address are pretty close (but not overlapping), can't they share a leaf table, in which case you need to clear more than just a single entry? The present overlap check looks to be 4k-granular, not 2M (in which case this couldn't happen; IOW adjusting the overlap check may also be a way out).
At the start of setup_initial_pagetables() there is a code which checks that load and link address don't overlap:
if ( (linker_start != load_start) &&
(linker_start <= load_end) && (load_start <= linker_end) )
{
early_printk("(XEN) linker and load address ranges overlap\n");
die();
}So the closest difference between load and link address can be 4kb. Otherwise load and link address ranges are equal ( as we can't map less then 4kb).
Let's take concrete examples:
Load address range is 0x8020_0000 - 0x8020_0FFF
Linker address range is 0x8020_1000 - 0x8020_1FFF MMU mode: Sv39 ( so we have 3 page tables )
So we have:
* L2 index = 2, L1 index = 1, L0 index = 0 for load address
* L2 index = 2, L1 index = 1, L0 index = 1 for linker address
Thereby we have two different L0 tables for load and linker address
ranges.
And it looks like it is pretty safe to remove only one L0 index that
was used for identity mapping.
Is it possible that I missed something?
~ Oleksii
Quoted 12 lines · Oleksii
Quoted 11 lines · Jan Beulich
Quoted 8 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/config.h +2
-0@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + #ifndef __RISCV_CONFIG_H__ #define __RISCV_CONFIG_H__Unrelated change?
Quoted 2 lines
It should be part of [PATCH v2 5/6] xen/riscv: introduce identity mapping.
Hmm, here we're discussing "[PATCH v2 4/6] xen/riscv: introduce identity mapping". I'm confused, I guess.
Quoted 31 lines
Quoted 23 lines
Quoted 23 lines
xen/arch/riscv/mm.c +0
-0@@ -25,6 +25,12 @@ unsigned long __ro_after_init phys_offset; #define LOAD_TO_LINK(addr) ((unsigned long)(addr) - phys_offset) #define LINK_TO_LOAD(addr) ((unsigned long)(addr) + phys_offset)
+/*
+ * Should be removed as soon as enough headers will be merged for inclusion of
+ * <xen/lib.h>.
+ */
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
/*
* It is expected that Xen won't be more then 2 MB.
* The check inxen.lds.Sguarantees that.xen/arch/riscv/mm.c +0
-0@@ -35,8 +41,10 @@ unsigned long __ro_after_init phys_offset; * * It might be needed one more page table in case when Xen loadaddress
* isn't 2 MB aligned.
+ *Quoted 8 lines
xen/arch/riscv/mm.c unsigned long __ro_after_init phys_offset; · line 47
Quoted 5 lines
+ * (
CONFIG_PAGING_LEVELS- 1) page tables are needed for identity mapping.
*/xen/arch/riscv/mm.c +1
-1-#define PGTBL_INITIAL_COUNT ((CONFIG_PAGING_LEVELS - 1) + 1) +#define PGTBL_INITIAL_COUNT ((CONFIG_PAGING_LEVELS - 1) * 2 + 1)How come the extra page (see the comment sentence in context) isn't needed for the identity-mapping case?
Quoted 6 lines
It is needed to allocate no more than two 'nonroot' page tables (L0 and L1 in case of Sv39 ) as page 'root' table ( L2 in case of Sv39 ) is always re-used.
The same ( only 'nonroot' page tables might be needed to allocate ) works for any MMU mode.
Of course, but if you cross a 2Mb boundary you'll need 2 L0 tables.
Quoted 90 lines
Quoted 42 lines
Quoted 31 lines
xen/arch/riscv/mm.c +0
-0@@ -255,25 +262,30 @@ void __init noreturn noinline enable_mmu() csr_write(CSR_SATP,
PFN_DOWN((unsigned long)stage1_pgtbl_root)|RV_STAGE1_MODE<<SATP_MODE_SHIFT);
+}
- asm volatile ( ".p2align 2" );
-mmu_is_enabled:
- /*
- * Stack should be re-inited as:
- * 1. Right now an address of the stack is relative to load time
- * addresses what will cause an issue in case of load start address
- * isn't equal to linker start address.
- * 2. Addresses in stack are all load time relative which can be an
- * issue in case when load start address isn't equal to linker
- * start address.
- *
- * We can't return to the caller because the stack was reseted - * and it may have stash some variable on the stack. - * Jump to a brand new function as the stack was reseted - */xen/arch/riscv/mm.c +6
-0+void __init remove_identity_mapping (void ) +{ + unsigned int i; + pte_t *pgtbl; + unsigned int index, xen_index; + unsigned long load_addr = LINK_TO_LOAD(_start);Quoted 6 lines
- switch_stack_and_jump((unsigned long)cpu0_boot_stack +STACK_SIZE,
-cont_after_mmu_is_enabled); + for ( pgtbl =stage1_pgtbl_root, i = 0;
+ i <= (CONFIG_PAGING_LEVELS- 1);i <
CONFIG_PAGING_LEVELS? But maybe it would be easier for i to start
atCONFIG_PAGING_LEVELSand be decremented, simplifying ...Quoted 7 lines
Quoted 5 lines
+ i++ )
+ {
+ index =pt_index(CONFIG_PAGING_LEVELS - 1 - i, load_addr); +xen_index=pt_index(CONFIG_PAGING_LEVELS - 1 - i, XEN_VIRT_START);... these two expressions?
It makes sense. I'll update this part of the code.
Quoted 7 lines
Quoted 6 lines
+ if ( index !=
xen_index)
+ {
+ pgtbl[index].pte = 0;
+ break;
+ }Quoted 5 lines
Is this enough? When load and link address are pretty close (but not overlapping), can't they share a leaf table, in which case you need to clear more than just a single entry? The present overlap check looks to be 4k-granular, not 2M (in which case this couldn't happen; IOW adjusting the overlap check may also be a way out).
At the start of
setup_initial_pagetables()there is a code which checks that load and link address don't overlap:if ( (linker_start != load_start) && (linker_start <= load_end) && (load_start <= linker_end) ) { early_printk("(XEN) linker and load address ranges overlap\n"); die(); }So the closest difference between load and link address can be 4kb. Otherwise load and link address ranges are equal ( as we can't map less then 4kb).
Let's take concrete examples:
Load address range is 0x8020_0000 - 0x8020_0FFF
Linker address range is 0x8020_1000 - 0x8020_1FFF MMU mode: Sv39 ( so we have 3 page tables )So we have:
* L2 index = 2, L1 index = 1, L0 index = 0 for load address
* L2 index = 2, L1 index = 1, L0 index = 1 for linker address
Thereby we have two different L0 tables for load and linker address
ranges.
And it looks like it is pretty safe to remove only one L0 index that
was used for identity mapping.
Quoted 1 line
Is it possible that I missed something?
Looks as if you are thinking of only a Xen which fits in 4k. The code here wants to cope with Xen getting quite a bit bigger.
Jan
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Oleksii
Quoted 11 lines · Jan Beulich
Quoted 8 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/config.h +2
-0@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + #ifndef __RISCV_CONFIG_H__ #define __RISCV_CONFIG_H__Unrelated change?
Quoted 6 lines
Quoted 2 lines
It should be part of [PATCH v2 5/6] xen/riscv: introduce identity mapping.
Hmm, here we're discussing "[PATCH v2 4/6] xen/riscv: introduce identity
mapping". I'm confused, I guess.
Sorry for confusion. i meant the patch: [PATCH v2 5/6] xen/riscv: add SPDX tags.
Quoted 44 lines
Quoted 44 lines
Quoted 31 lines
Quoted 31 lines
xen/arch/riscv/mm.c +0
-0@@ -25,6 +25,12 @@ unsigned long __ro_after_init phys_offset; #define LOAD_TO_LINK(addr) ((unsigned long)(addr) - phys_offset) #define LINK_TO_LOAD(addr) ((unsigned long)(addr) + phys_offset)
+/*
+ * Should be removed as soon as enough headers will be merged for
inclusion of
+ * <xen/lib.h>.
+ */
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
/*
* It is expected that Xen won't be more then 2 MB.
* The check inxen.lds.Sguarantees that.xen/arch/riscv/mm.c +0
-0@@ -35,8 +41,10 @@ unsigned long __ro_after_init phys_offset; * * It might be needed one more page table in case when Xenload
address
* isn't 2 MB aligned.
+ *
+ * (CONFIG_PAGING_LEVELS- 1) page tables are needed for identity
mapping.Quoted 8 lines
Quoted 4 lines
*/
xen/arch/riscv/mm.c +1
-1-#define PGTBL_INITIAL_COUNT ((CONFIG_PAGING_LEVELS - 1) + 1) +#define PGTBL_INITIAL_COUNT ((CONFIG_PAGING_LEVELS - 1) * 2 +1)
How come the extra page (see the comment sentence in context) isn't
needed for the identity-mapping case?It is needed to allocate no more than two 'nonroot' page tables (L0 and
L1 in case of Sv39 ) as page 'root' table ( L2 in case of Sv39 ) is always re-used.
Quoted 4 lines
Quoted 2 lines
The same ( only 'nonroot' page tables might be needed to allocate ) works for any MMU mode.
Of course, but if you cross a 2Mb boundary you'll need 2 L0 tables.
Yes, in the case of crossing a 2Mb boundary, it will require 2 L0 tables.
Then, the number of required page tables is needed depending on Xen size and load address alignment. Because for each 2Mb, we need a new L0 table.
Sure, this is not needed now ( as in xen.lds.S, we have a Xen size check ), but if someone increases Xen size binary to 4Mb, then the amount of page tables should be updated too.
Should we take into account that?
Quoted 105 lines
Quoted 105 lines
Quoted 48 lines
Quoted 37 lines
xen/arch/riscv/mm.c +0
-0@@ -255,25 +262,30 @@ void __init noreturn noinline enable_mmu() csr_write(CSR_SATP,
PFN_DOWN((unsigned long)stage1_pgtbl_root)|RV_STAGE1_MODE<<SATP_MODE_SHIFT);
+}
- asm volatile ( ".p2align 2" );
-mmu_is_enabled:
- /*
- * Stack should be re-inited as:
- * 1. Right now an address of the stack is relative to load
time
- * addresses what will cause an issue in case of load start
address
- * isn't equal to linker start address.
- * 2. Addresses in stack are all load time relative which can
be an
- * issue in case when load start address isn't equal to linker
- * start address.
- *
- * We can't return to the caller because the stack was reseted
- * and it may have stash some variable on the stack. - * Jump to a brand new function as the stack was reseted - */xen/arch/riscv/mm.c +6
-0+void __init remove_identity_mapping (void ) +{ + unsigned int i; + pte_t *pgtbl; + unsigned int index, xen_index; + unsigned long load_addr = LINK_TO_LOAD(_start);Quoted 6 lines
- switch_stack_and_jump((unsigned long)cpu0_boot_stack +STACK_SIZE,
-cont_after_mmu_is_enabled); + for ( pgtbl =stage1_pgtbl_root, i = 0;
+ i <= (CONFIG_PAGING_LEVELS- 1);i <
CONFIG_PAGING_LEVELS? But maybe it would be easier for i to start
atCONFIG_PAGING_LEVELSand be decremented, simplifying ...Quoted 8 lines
Quoted 6 lines
+ i++ )
+ {
+ index =pt_index(CONFIG_PAGING_LEVELS - 1 - i, load_addr);
+xen_index=pt_index(CONFIG_PAGING_LEVELS - 1 - i, XEN_VIRT_START);... these two expressions?
It makes sense. I'll update this part of the code.
Quoted 7 lines
Quoted 6 lines
+ if ( index !=
xen_index)
+ {
+ pgtbl[index].pte = 0;
+ break;
+ }Quoted 8 lines
Is this enough? When load and link address are pretty close (but not
overlapping), can't they share a leaf table, in which case you need
to clear more than just a single entry? The present overlap check looks to be 4k-granular, not 2M (in which case this couldn't happen;
IOW adjusting the overlap check may also be a way out).At the start of
setup_initial_pagetables()there is a code which checks
that load and link address don't overlap:if ( (
linker_start!=load_start) &&
(linker_start<=load_end) && (load_start<=linker_end) ) {
early_printk("(XEN) linker and load address ranges overlap\n");
die();
}So the closest difference between load and link address can be 4kb. Otherwise load and link address ranges are equal ( as we can't map less
then 4kb).Let's take concrete examples:
Load address range is 0x8020_0000 - 0x8020_0FFF Linker address range is 0x8020_1000 - 0x8020_1FFF MMU mode: Sv39 ( so we have 3 page tables )So we have:
* L2 index = 2, L1 index = 1, L0 index = 0 for load address
* L2 index = 2, L1 index = 1, L0 index = 1 for linker address Thereby we have two different L0 tables for load and linker address
ranges.
And it looks like it is pretty safe to remove only one L0 index that
was used for identity mapping.
Quoted 4 lines
Quoted 1 line
Is it possible that I missed something?
Looks as if you are thinking of only a Xen which fits in 4k. The code here wants to cope with Xen getting quite a bit bigger.
Yeah, I missed that when I tried to come up with an example.
So it will probably be more universal if we recursively go through the whole identity mapping and unmap each pte individually.
Quoted 54 lines · Oleksii
Quoted 46 lines · Jan Beulich
Quoted 45 lines · Oleksii
Quoted 31 lines · Jan Beulich
Quoted 30 lines · Oleksii Kurochko
xen/arch/riscv/mm.c +0
-0@@ -25,6 +25,12 @@ unsigned long __ro_after_init phys_offset; #define LOAD_TO_LINK(addr) ((unsigned long)(addr) - phys_offset) #define LINK_TO_LOAD(addr) ((unsigned long)(addr) + phys_offset)
+/*
+ * Should be removed as soon as enough headers will be merged for
inclusion of
+ * <xen/lib.h>.
+ */
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
/*
* It is expected that Xen won't be more then 2 MB.
* The check inxen.lds.Sguarantees that.xen/arch/riscv/mm.c +0
-0@@ -35,8 +41,10 @@ unsigned long __ro_after_init phys_offset; * * It might be needed one more page table in case when Xenload
address
* isn't 2 MB aligned.
+ *
+ * (CONFIG_PAGING_LEVELS- 1) page tables are needed for identity
mapping.Quoted 8 lines
Quoted 4 lines
*/
xen/arch/riscv/mm.c +1
-1-#define PGTBL_INITIAL_COUNT ((CONFIG_PAGING_LEVELS - 1) + 1) +#define PGTBL_INITIAL_COUNT ((CONFIG_PAGING_LEVELS - 1) * 2 +1)
How come the extra page (see the comment sentence in context) isn't
needed for the identity-mapping case?It is needed to allocate no more than two 'nonroot' page tables (L0 and
L1 in case of Sv39 ) as page 'root' table ( L2 in case of Sv39 ) is always re-used.Quoted 4 lines
Quoted 2 lines
The same ( only 'nonroot' page tables might be needed to allocate ) works for any MMU mode.
Of course, but if you cross a 2Mb boundary you'll need 2 L0 tables.
Yes, in the case of crossing a 2Mb boundary, it will require 2 L0 tables.
Quoted 8 lines
Then, the number of required page tables is needed depending on Xen size and load address alignment. Because for each 2Mb, we need a new L0 table.
Sure, this is not needed now ( as in
xen.lds.S, we have a Xen size check ), but if someone increases Xen size binary to 4Mb, then the amount of page tables should be updated too.
Should we take into account that?
Perhaps by way of a BUILD_BUG_ON(), yes. We want to avoid setting up a (runtime) trap for someone to fall into.
Jan
PATCH v2 5/6 xen/riscv: add SPDX tags
In reply to Oleksii Kurochko---
Changes in V2:
- change SPDX tags from GPL-2.0-or-later to GPL-2.0-only.
- add Suggested-by: Andrew Cooper <[email protected]>.
--- xen/arch/riscv/include/asm/current.h | 2 ++ xen/arch/riscv/include/asm/early_printk.h | 2 ++ xen/arch/riscv/include/asm/mm.h | 2 ++ xen/arch/riscv/include/asm/page-bits.h | 2 ++ xen/arch/riscv/include/asm/page.h | 2 ++ xen/arch/riscv/include/asm/traps.h | 2 ++ xen/arch/riscv/include/asm/types.h | 2 ++ xen/arch/riscv/mm.c | 2 ++ xen/arch/riscv/setup.c | 2 ++ 9 files changed, 18 insertions(+)
xen/arch/riscv/include/asm/current.h +2 -0
@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_CURRENT_H#define __ASM_CURRENT_H
xen/arch/riscv/include/asm/early_printk.h +2 -0
@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __EARLY_PRINTK_H__#define __EARLY_PRINTK_H__
xen/arch/riscv/include/asm/mm.h +2 -0
@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_RISCV_MM_H#define _ASM_RISCV_MM_H
xen/arch/riscv/include/asm/page-bits.h +2 -0
@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __RISCV_PAGE_BITS_H__#define __RISCV_PAGE_BITS_H__
xen/arch/riscv/include/asm/page.h +2 -0
@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_RISCV_PAGE_H#define _ASM_RISCV_PAGE_H
xen/arch/riscv/include/asm/traps.h +2 -0
@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_TRAPS_H__#define __ASM_TRAPS_H__
xen/arch/riscv/include/asm/types.h +2 -0
@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __RISCV_TYPES_H__#define __RISCV_TYPES_H__
xen/arch/riscv/mm.c +2 -0
@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include <xen/cache.h> #include <xen/compiler.h> #include <xen/init.h>
xen/arch/riscv/setup.c +2 -0
@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include <xen/compile.h> #include <xen/init.h>
Signature · 1 line
2.40.1
Re: [PATCH v2 5/6] xen/riscv: add SPDX tags
Quoted 3 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>Suggested-by Andrew Cooper <[email protected]>
Alistair
Quoted 110 lines
---
Changes in V2:
- change SPDX tags from GPL-2.0-or-later to GPL-2.0-only.
- add Suggested-by: Andrew Cooper <[email protected]>.--- xen/arch/riscv/include/asm/current.h | 2 ++ xen/arch/riscv/include/asm/early_printk.h | 2 ++ xen/arch/riscv/include/asm/mm.h | 2 ++ xen/arch/riscv/include/asm/page-bits.h | 2 ++ xen/arch/riscv/include/asm/page.h | 2 ++ xen/arch/riscv/include/asm/traps.h | 2 ++ xen/arch/riscv/include/asm/types.h | 2 ++ xen/arch/riscv/mm.c | 2 ++ xen/arch/riscv/setup.c | 2 ++ 9 files changed, 18 insertions(+)xen/arch/riscv/include/asm/current.h +2
-0@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_CURRENT_H#define __ASM_CURRENT_Hxen/arch/riscv/include/asm/early_printk.h +2
-0@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __EARLY_PRINTK_H__#define __EARLY_PRINTK_H__xen/arch/riscv/include/asm/mm.h +2
-0@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_RISCV_MM_H#define _ASM_RISCV_MM_Hxen/arch/riscv/include/asm/page-bits.h +2
-0@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __RISCV_PAGE_BITS_H__#define __RISCV_PAGE_BITS_H__xen/arch/riscv/include/asm/page.h +2
-0@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_RISCV_PAGE_H#define _ASM_RISCV_PAGE_Hxen/arch/riscv/include/asm/traps.h +2
-0@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_TRAPS_H__#define __ASM_TRAPS_H__xen/arch/riscv/include/asm/types.h +2
-0@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __RISCV_TYPES_H__#define __RISCV_TYPES_H__xen/arch/riscv/mm.c +2
-0@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include <xen/cache.h> #include <xen/compiler.h> #include <xen/init.h> xen/arch/riscv/setup.c +2
-1@@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include <xen/compile.h> #include <xen/init.h> --2.40.1
PATCH v2 6/6 xen/riscv: move extern of cpu0_boot_stack to header
In reply to Oleksii Kurochko---
Changes in V2:
- add Suggested-by: Andrew Cooper <[email protected]>.
--- xen/arch/riscv/include/asm/mm.h | 2 ++ xen/arch/riscv/mm.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-)
xen/arch/riscv/include/asm/mm.h +2 -0
@@ -8,6 +8,8 @@#define pfn_to_paddr (pfn) ((paddr_t)(pfn) << PAGE_SHIFT)#define paddr_to_pfn (pa) ((unsigned long)((pa) >> PAGE_SHIFT)) +extern unsigned char cpu0_boot_stack[]; +void setup_initial_pagetables (void );void enable_mmu (void );
xen/arch/riscv/mm.c +0 -2
@@ -20,8 +20,6 @@ struct mmu_desc {pte_t *pgtbl_base; }; -extern unsigned char cpu0_boot_stack[STACK_SIZE ]; -unsigned long __ro_after_init phys_offset;#define LOAD_TO_LINK (addr) ((unsigned long)(addr) - phys_offset)
Signature · 1 line
2.40.1
Re: [PATCH v2 6/6] xen/riscv: move extern of cpu0_boot_stack to header
Quoted 3 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>Suggested-by Andrew Cooper <[email protected]>
Alistair
Quoted 38 lines
---
Changes in V2:
- add Suggested-by: Andrew Cooper <[email protected]>.--- xen/arch/riscv/include/asm/mm.h | 2 ++ xen/arch/riscv/mm.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-)xen/arch/riscv/include/asm/mm.h +2
-0@@ -8,6 +8,8 @@#define pfn_to_paddr (pfn) ((paddr_t)(pfn) << PAGE_SHIFT)#define paddr_to_pfn (pa) ((unsigned long)((pa) >> PAGE_SHIFT)) +extern unsigned char cpu0_boot_stack[]; +void setup_initial_pagetables (void );void enable_mmu (void );xen/arch/riscv/mm.c +0
-3@@ -20,8 +20,6 @@ struct mmu_desc {pte_t *pgtbl_base; }; -extern unsigned char cpu0_boot_stack[STACK_SIZE ]; -unsigned long __ro_after_init phys_offset;#define LOAD_TO_LINK (addr) ((unsigned long)(addr) - phys_offset) --2.40.1
Hello Bobby and Alistair,
Some patches of the current patch series were merged, but some still require your Ack-by/Reviewed-by.
Could you please look at the following patches:
1. [PATCH v2 3/6] xen/riscv: introduce function for physical offset calculation
2. [PATCH v2 4/6] xen/riscv: introduce identity mapping
Thank you so much for your attention and participation.
~ Oleksii
Quoted 76 lines · Oleksii Kurochko
The patch series introduces things necessary to implement identity mapping:
1. Make identity mapping for the entire Xen.
2. Enable MMU.
3. Jump to the virtual address world
4. Remove identity mapping.Also current patch series introduces the calculation of physical offset before
MMU is enabled as access to physical offset will be calculated wrong after
MMU will be enabled because access tophys_offvariable is PC- relative and
in the case when linker address != load address, it will cause MMU fault.One more thing that was done is:
* Added SPDX tags.
* move extern ofcpu0_boot_stackto a header.The reason for this patch series can be found here:
https://lore.kernel.org/xen-devel/[email protected]/---
Changes in V2:
- update the patch series message.
- drop patches from the previous version of the patch series:
* xen/riscv: add__ASSEMBLY__guards". ( merged )
* xen/riscv: make sure that identity mapping isn't bigger then page size
( entire Xen is 1:1 mapped so there is no need for the checks from the patch )
- add .sbss.* and put it befor .bss* .
- move outreset_stack()to .text section.
- add '__ro_after_init' forphys_offsetvariable.
- add '__init' forcalc_phys_offset().
- declaring variablephys_offas non static as it will be used inhead.S.
- update definition ofPGTBL_INITIAL_COUNTand the comment above.
- code style fixes.
- removeid_addrsarray becase entire Xen is mapped.
- reverse condition for cycle insideremove_identity_mapping().
- fix page table walk inremove_identity_mapping().
- savehart_idanddtb_addrbefore call MMU related C functions
- usephys_offsetvariable instead of doing calcultations to get phys offset
inhead.Sfile. ( it can be easily done as entire Xen is 1:1 mapped now )
- declareenable_muu()as__init.
- Update SPDX tags.
- Add Review-By/Suggested-By for some patches.
- code style fixes.Oleksii Kurochko (6):
xen/riscv: add .sbss section to .bss
xen/riscv: introducereset_stack()function xen/riscv: introduce function for physical offset calculation xen/riscv: introduce identity mapping
xen/riscv: add SPDX tags
xen/riscv: move extern ofcpu0_boot_stackto headerxen/arch/riscv/include/asm/config.h | 2 + xen/arch/riscv/include/asm/current.h | 2 +
xen/arch/riscv/include/asm/early_printk.h| 2 + xen/arch/riscv/include/asm/mm.h | 9 +- xen/arch/riscv/include/asm/page-bits.h | 2 + xen/arch/riscv/include/asm/page.h | 2 + xen/arch/riscv/include/asm/traps.h | 2 + xen/arch/riscv/include/asm/types.h | 2 + xen/arch/riscv/mm.c | 104 +++++++++++++------- --
xen/arch/riscv/riscv64/head.S | 46 +++++++++- xen/arch/riscv/setup.c | 16 +--- xen/arch/riscv/xen.lds.S | 2 +-12 files changed, 136 insertions(+), 55 deletions(-)