RISCV device tree mapping
v2 cover RISCV device tree mapping
Current patch series introduces device tree mapping for RISC-V and necessary things for that such as:
- Fixmap mapping
- pmap
- Xen page table processing
Also, it introduces common stuff for working with fdt which is
based on the patches from [1]:
[PATCH v4 2/6] xen/device-tree: Move Arm's setup.c bootinfo functions to common [PATCH v4 3/6] xen/common: Move Arm's bootfdt.c
All changes which were done on top of Shawn's patches please find in "Changes" section of each patch.
Also there is another one depenency:
RISCV basic exception handling implementation [2]
[1] https://lore.kernel.org/xen-devel/[email protected]/
[2] https://lore.kernel.org/xen-devel/[email protected]/T/#t
---
Changes in v2:
- Update the cover letter message
- introduce fixmap mapping
- introduce pmap
- introduce CONFIG_GENREIC_PT
- update use early_fdt_map() after MMU is enabled.
---
Oleksii Kurochko (6):
xen/riscv: enable CONFIG_HAS_DEVICE_TREE xen/riscv: setup fixmap mapping
xen/riscv: introduce asm/pmap.h header xen/riscv: introduce generic Xen page table handling xen/riscv: select CONFIG_GENREIC_PT xen/riscv: introduce early_fdt_map()
Shawn Anastasio (2):
xen/device-tree: Move Arm's setup.c bootinfo functions to common xen/common: Move Arm's bootfdt.c to common
MAINTAINERS | 2 + xen/arch/arm/Makefile | 1 - xen/arch/arm/bootfdt.c | 622 ------------------------ xen/arch/arm/include/asm/setup.h | 200 +------- xen/arch/arm/setup.c | 432 ----------------- xen/arch/riscv/Kconfig | 3 + xen/arch/riscv/include/asm/config.h | 9 + xen/arch/riscv/include/asm/fixmap.h | 48 ++ xen/arch/riscv/include/asm/mm.h | 13 + xen/arch/riscv/include/asm/page-bits.h | 45 ++ xen/arch/riscv/include/asm/page.h | 82 +++- xen/arch/riscv/include/asm/pmap.h | 28 ++ xen/arch/riscv/mm.c | 167 ++++++- xen/arch/riscv/setup.c | 11 + xen/arch/riscv/xen.lds.S | 2 +- xen/common/Kconfig | 5 + xen/common/Makefile | 2 + xen/common/device-tree/Makefile | 2 + xen/common/device-tree/bootfdt.c | 635 +++++++++++++++++++++++++ xen/common/device-tree/bootinfo.c | 459 ++++++++++++++++++ xen/common/mmu/pt.c | 441 +++++++++++++++++ xen/include/xen/bootfdt.h | 210 ++++++++ xen/include/xen/mm.h | 24 + 23 files changed, 2181 insertions(+), 1262 deletions(-) delete mode 100644 xen/arch/arm/bootfdt.c create mode 100644 xen/arch/riscv/include/asm/fixmap.h create mode 100644 xen/arch/riscv/include/asm/pmap.h create mode 100644 xen/common/device-tree/Makefile create mode 100644 xen/common/device-tree/bootfdt.c create mode 100644 xen/common/device-tree/bootinfo.c create mode 100644 xen/common/mmu/pt.c create mode 100644 xen/include/xen/bootfdt.h
Signature · 1 line
2.45.2
PATCH v2 3/8 xen/riscv: enable CONFIG_HAS_DEVICE_TREE
---
Changes in V2:
- move 'select HAS_DEVICE_TREE' to CONFIG_RISCV.
---
Changes in V1:
- new patch
--- xen/arch/riscv/Kconfig | 1 + 1 file changed, 1 insertion(+)
xen/arch/riscv/Kconfig +1 -0
@@ -2,6 +2,7 @@ config RISCV def_bool y select FUNCTION_ALIGNMENT_16B select GENERIC_BUG_FRAME + select HAS_DEVICE_TREE config RISCV_64 def_bool y
Signature · 1 line
2.45.2
Re: [PATCH v2 3/8] xen/riscv: enable CONFIG_HAS_DEVICE_TREE
Quoted 1 line · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>
Albeit a little reluctantly, seeing the once again entirely missing description. Please can you get used to not leaving that out, unless the title really says _all_ that's wanted / needed?
Jan
Quoted 10 lines
xen/arch/riscv/Kconfig +1
-0@@ -2,6 +2,7 @@ config RISCV def_bool y select FUNCTION_ALIGNMENT_16B select GENERIC_BUG_FRAME + select HAS_DEVICE_TREE config RISCV_64 def_bool y
PATCH v2 4/8 xen/riscv: setup fixmap mapping
In reply to Oleksii KurochkoIntroduce a function to set up fixmap mappings and L0 page table for fixmap.
Additionally, defines were introduced in riscv/config.h to calculate the FIXMAP_BASE address.
This involved introducing BOOT_FDT_VIRT_{START, SIZE} and XEN_SIZE, XEN_VIRT_END.
Also, the check of Xen size was updated in the riscv/lds.S script to use XEN_SIZE instead of a hardcoded constant.
---
Changes in V2:
- newly introduced patch
--- xen/arch/riscv/include/asm/config.h | 9 ++++++ xen/arch/riscv/include/asm/fixmap.h | 48 +++++++++++++++++++++++++++++ xen/arch/riscv/include/asm/mm.h | 2 ++ xen/arch/riscv/include/asm/page.h | 7 +++++ xen/arch/riscv/mm.c | 35 +++++++++++++++++++++ xen/arch/riscv/setup.c | 2 ++ xen/arch/riscv/xen.lds.S | 2 +- 7 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 xen/arch/riscv/include/asm/fixmap.h
xen/arch/riscv/include/asm/config.h +9 -0
@@ -74,11 +74,20 @@#error "unsupported RV_STAGE1_MODE"#endif +#define XEN_SIZE MB(2) +#define XEN_VIRT_END (XEN_VIRT_START + XEN_SIZE) + +#define BOOT_FDT_VIRT_START XEN_VIRT_END +#define BOOT_FDT_VIRT_SIZE MB(4) +#define DIRECTMAP_SLOT_END 509#define DIRECTMAP_SLOT_START 200#define DIRECTMAP_VIRT_START SLOTN(DIRECTMAP_SLOT_START)#define DIRECTMAP_SIZE (SLOTN(DIRECTMAP_SLOT_END) - SLOTN(DIRECTMAP_SLOT_START)) +#define FIXMAP_BASE (BOOT_FDT_VIRT_START + BOOT_FDT_VIRT_SIZE) +#define FIXMAP_ADDR (n) (FIXMAP_BASE + (n) * PAGE_SIZE) +#define FRAMETABLE_SCALE_FACTOR (PAGE_SIZE/sizeof(struct page_info))#define FRAMETABLE_SIZE_IN_SLOTS (((DIRECTMAP_SIZE / SLOTN(1)) / FRAMETABLE_SCALE_FACTOR) + 1)
xen/arch/riscv/include/asm/fixmap.h new file +48 -0
48 lines not on this page · raw message
xen/arch/riscv/include/asm/mm.h +2 -0
@@ -255,4 +255,6 @@ static inline unsigned int arch_get_dma_bitsize(void) return 32; /* TODO */ } +void setup_fixmap_mappings (void ); +#endif /* _ASM_RISCV_MM_H */
xen/arch/riscv/include/asm/page.h +7 -0
@@ -81,6 +81,13 @@ static inline void flush_page_to_ram(unsigned long mfn, bool sync_icache)BUG_ON ("unimplemented" ); } +/* Write a pagetable entry. */ +static inline void write_pte (pte_t *p,pte_t pte) +{ + *p = pte; + asmvolatile ("sfence.vma" ); +} +#endif /* __ASSEMBLY__ */ #endif /* _ASM_RISCV_PAGE_H */
xen/arch/riscv/mm.c +35 -0
@@ -49,6 +49,9 @@ stage1_pgtbl_root[PAGETABLE_ENTRIES]; pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) stage1_pgtbl_nonroot[PGTBL_INITIAL_COUNT *PAGETABLE_ENTRIES ]; +pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) +xen_fixmap[PAGETABLE_ENTRIES ]; +#define HANDLE_PGTBL (curr_lvl_num) \ index = pt_index(curr_lvl_num, page_addr); \ if ( pte_is_valid(pgtbl[index]) ) \
@@ -191,6 +194,38 @@ static bool __init check_pgtbl_mode_support(struct mmu_desc *mmu_desc,return is_mode_supported; } +void __init setup_fixmap_mappings (void ) +{ +pte_t *pte; +unsigned int i; + + pte = &stage1_pgtbl_root[pt_index (HYP_PT_ROOT_LEVEL ,FIXMAP_ADDR (0 ))]; + +for ( i =HYP_PT_ROOT_LEVEL -1 ; i !=0 ; i-- ) + { +BUG_ON (!pte_is_valid (*pte)); + + pte = (pte_t *)LOAD_TO_LINK (pte_to_paddr (*pte)); + pte = &pte[pt_index (i,FIXMAP_ADDR (0 ))]; + } + +BUG_ON (pte_is_valid (*pte) ); + +if ( !pte_is_valid (*pte) ) + { +pte_t tmp =paddr_to_pte (LINK_TO_LOAD ((unsigned long )&xen_fixmap),PTE_TABLE ); + +write_pte (pte, tmp); + +printk ("(XEN) fixmap is mapped\n" ); + } + +/* +* We only need the zeroeth table allocated, but not the PTEs set, because +* set_fixmap() will set them on the fly. +*/ +} +/* * setup_initial_pagetables: *
xen/arch/riscv/setup.c +2 -0
@@ -46,6 +46,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id,test_macros_from_bug_h ();#endif +setup_fixmap_mappings (); +printk ("All set up\n" );for ( ;; )
xen/arch/riscv/xen.lds.S +1 -1
@@ -181,6 +181,6 @@ ASSERT(!SIZEOF(.got.plt), ".got.plt non-empty") * Changing the size of Xen binary can require an update of * PGTBL_INITIAL_COUNT. */ -ASSERT(_end - _start <= MB(2), "Xen too large for early-boot assumptions") +ASSERT(_end - _start <= XEN_SIZE, "Xen too large for early-boot assumptions") ASSERT(_ident_end - _ident_start <= IDENT_AREA_SIZE, "identity region is too big");
Signature · 1 line
2.45.2
Re: [PATCH v2 4/8] xen/riscv: setup fixmap mapping
Hi Oleksii,
Quoted 31 lines · Oleksii Kurochko
Introduce a function to set up fixmap mappings and L0 page table for fixmap.
Additionally, defines were introduced in
riscv/config.hto calculate theFIXMAP_BASEaddress.
This involved introducing BOOT_FDT_VIRT_{START, SIZE} andXEN_SIZE,XEN_VIRT_END.Also, the check of Xen size was updated in the
riscv/lds.Sscript to useXEN_SIZEinstead of a hardcoded constant.Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V2:
- newly introduced patch--- xen/arch/riscv/include/asm/config.h | 9 ++++++ xen/arch/riscv/include/asm/fixmap.h | 48 +++++++++++++++++++++++++++++ xen/arch/riscv/include/asm/mm.h | 2 ++ xen/arch/riscv/include/asm/page.h | 7 +++++ xen/arch/riscv/mm.c | 35 +++++++++++++++++++++ xen/arch/riscv/setup.c | 2 ++ xen/arch/riscv/xen.lds.S | 2 +- 7 files changed, 104 insertions(+), 1 deletion(-)create mode 100644
xen/arch/riscv/include/asm/fixmap.hxen/arch/riscv/include/asm/config.h +0
-0
xen/arch/riscv/include/asm/config.h line 77
Quoted 4 lines
xen/arch/riscv/include/asm/config.h +1
-0@@ -74,11 +74,20 @@#error "unsupported RV_STAGE1_MODE"#endif +#define XEN_SIZE MB(2)
NIT: I would name it XEN_VIRT_SIZE to be consistent with the start/end.
xen/arch/riscv/include/asm/config.h line 78
Quoted 1 line
xen/arch/riscv/include/asm/config.h +1
-0+#define XEN_VIRT_END (XEN_VIRT_START + XEN_SIZE)
Can we get away with not introducing *_END and just use START, SIZE? The reason I am asking is with "end" it is never clear whether it is inclusive or exclusive. For instance, here you use an exclusive range but ...
Quoted 26 lines
xen/arch/riscv/include/asm/config.h +7
-0+ +#define BOOT_FDT_VIRT_START XEN_VIRT_END +#define BOOT_FDT_VIRT_SIZE MB(4) +#define DIRECTMAP_SLOT_END 509#define DIRECTMAP_SLOT_START 200#define DIRECTMAP_VIRT_START SLOTN(DIRECTMAP_SLOT_START)#define DIRECTMAP_SIZE (SLOTN(DIRECTMAP_SLOT_END) - SLOTN(DIRECTMAP_SLOT_START)) +#define FIXMAP_BASE (BOOT_FDT_VIRT_START + BOOT_FDT_VIRT_SIZE) +#define FIXMAP_ADDR (n) (FIXMAP_BASE + (n) * PAGE_SIZE) +#define FRAMETABLE_SCALE_FACTOR (PAGE_SIZE/sizeof(struct page_info))#define FRAMETABLE_SIZE_IN_SLOTS (((DIRECTMAP_SIZE / SLOTN(1)) / FRAMETABLE_SCALE_FACTOR) + 1)xen/arch/riscv/include/asm/fixmap.h new file +5
-0@@ -0,0 +1,48 @@ +/* +* fixmap.h: compile-time virtual memory allocation +*/ +#ifndef __ASM_FIXMAP_H +#define __ASM_FIXMAP_H
xen/arch/riscv/include/asm/fixmap.h line 15
Quoted 10 lines
xen/arch/riscv/include/asm/fixmap.h new file +10
-0+ +#include <xen/bug.h> +#include <xen/page-size.h> +#include <xen/pmap.h> + +#include <asm/page.h> + +/* Fixmap slots */ +#define FIX_PMAP_BEGIN (0)/* Start of PMAP */ +#define FIX_PMAP_END (FIX_PMAP_BEGIN + NUM_FIX_PMAP - 1)/* End of PMAP */
... here is seems to be inclusive. Furthermore if you had 32-bit address space, it is also quite easy to have to create a region right at the top of it. So when END is exclusive, it would become 0.
So on Arm, we decided to start to get rid of "end". I would consider to do the same on RISC-V for new functions.
xen/arch/riscv/include/asm/fixmap.h line 16
Quoted 1 line
xen/arch/riscv/include/asm/fixmap.h new file +1
-0+#define FIX_MISC (FIX_PMAP_END + 1)/* Ephemeral mappings of hardware */
Are you going to use this fixmap? If not, then I would consider to remove it.
Quoted 9 lines
xen/arch/riscv/include/asm/fixmap.h new file +9
-0+ +#define FIX_LAST FIX_MISC + +#define FIXADDR_START FIXMAP_ADDR(0) +#define FIXADDR_TOP FIXMAP_ADDR(FIX_LAST) + +#ifndef __ASSEMBLY__ + +/*
xen/arch/riscv/include/asm/fixmap.h line 35
Quoted 10 lines
xen/arch/riscv/include/asm/fixmap.h new file +10
-0+* Direct access to xen_fixmap[] should only happen when {set, +* clear}_fixmap() is unusable (e.g. where we would end up to +* recursively call the helpers). +*/ +extern pte_t xen_fixmap[]; + +/* Map a page in a fixmap entry */ +extern void set_fixmap (unsigned int map,mfn_t mfn,unsigned int attributes); +/* Remove a mapping from a fixmap entry */ +extern void clear_fixmap (unsigned int map);
Neither of the functions seem to be implemented in this patch. Can you clarify what's the plan for them?
Also, I know that for x86/arm, we have some function prefixed with extern. But AFAIK, we are trying to get rid of them.
In any case, I think for RISC-V we need some consistency. For instance, here you define with extern but...
Quoted 18 lines
xen/arch/riscv/include/asm/fixmap.h new file +13
-0+ +#define fix_to_virt (slot) ((void *)FIXMAP_ADDR(slot)) + +static inline unsigned int virt_to_fix (vaddr_t vaddr) +{ +BUG_ON (vaddr >=FIXADDR_TOP || vaddr <FIXADDR_START ); + +return ((vaddr -FIXADDR_START ) >>PAGE_SHIFT ); +} + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_FIXMAP_H */ xen/arch/riscv/include/asm/mm.h +0
-0
xen/arch/riscv/include/asm/mm.h static inline unsigned int arch_get_dma_bitsize(void) · line 258
Quoted 4 lines
xen/arch/riscv/include/asm/mm.h +1
-0@@ -255,4 +255,6 @@ static inline unsigned int arch_get_dma_bitsize(void)return 32 ;/* TODO */ } +void setup_fixmap_mappings (void );
... here it is without.
Quoted 25 lines
xen/arch/riscv/include/asm/mm.h +1
-0+#endif /* _ASM_RISCV_MM_H */ xen/arch/riscv/include/asm/page.h +7
-0@@ -81,6 +81,13 @@ static inline void flush_page_to_ram(unsigned long mfn, bool sync_icache)BUG_ON ("unimplemented" ); } +/* Write a pagetable entry. */ +static inline void write_pte (pte_t *p,pte_t pte) +{ + *p = pte; + asmvolatile ("sfence.vma" ); +} +#endif /* __ASSEMBLY__ */ #endif /* _ASM_RISCV_PAGE_H */ xen/arch/riscv/mm.c +0
-0
xen/arch/riscv/mm.c stage1_pgtbl_root[PAGETABLE_ENTRIES]; · line 53
Quoted 5 lines
xen/arch/riscv/mm.c +2
-0@@ -49,6 +49,9 @@ stage1_pgtbl_root[PAGETABLE_ENTRIES]; pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) stage1_pgtbl_nonroot[PGTBL_INITIAL_COUNT *PAGETABLE_ENTRIES ]; +pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) +xen_fixmap[PAGETABLE_ENTRIES ];
Can you add a BUILD_BUG_ON() to check that the number of entries in the fixmap will never be above PAGETABLE_ENTRIES?
Quoted 6 lines
xen/arch/riscv/mm.c +1
-0+#define HANDLE_PGTBL (curr_lvl_num) \ index = pt_index(curr_lvl_num, page_addr); \ if ( pte_is_valid(pgtbl[index]) ) \@@ -191,6 +194,38 @@ static bool __init check_pgtbl_mode_support(struct mmu_desc *mmu_desc,return is_mode_supported;
xen/arch/riscv/mm.c static bool __init check_pgtbl_mode_support(struct mmu_desc *mmu_desc, · line 204
Quoted 10 lines
xen/arch/riscv/mm.c +8
-0} +void __init setup_fixmap_mappings (void ) +{ +pte_t *pte; +unsigned int i; + + pte = &stage1_pgtbl_root[pt_index (HYP_PT_ROOT_LEVEL ,FIXMAP_ADDR (0 ))]; + +for ( i =HYP_PT_ROOT_LEVEL -1 ; i !=0 ; i-- )
I am a little bit confused with the - 1. Is this because you only want to map at L1 (I am not sure if this is the correct naming for RISC-V)?
In any case, I think it would be worth a comment.
xen/arch/riscv/mm.c static bool __init check_pgtbl_mode_support(struct mmu_desc *mmu_desc, · line 212
Quoted 8 lines
xen/arch/riscv/mm.c +8
-0+ { +BUG_ON (!pte_is_valid (*pte)); + + pte = (pte_t *)LOAD_TO_LINK (pte_to_paddr (*pte)); + pte = &pte[pt_index (i,FIXMAP_ADDR (0 ))]; + } + +BUG_ON (pte_is_valid (*pte) );
Coding style: BUG_ON(pte_is_valid(*pte));
xen/arch/riscv/mm.c static bool __init check_pgtbl_mode_support(struct mmu_desc *mmu_desc, · line 214
Quoted 2 lines
xen/arch/riscv/mm.c +2
-0+ +if ( !pte_is_valid (*pte) )
I am a bit confused with this check. Above, Xen will crash if the PTE is valid. So why do we need a runtime check?
xen/arch/riscv/mm.c static bool __init check_pgtbl_mode_support(struct mmu_desc *mmu_desc, · line 225
Quoted 11 lines
xen/arch/riscv/mm.c +11
-0+ { +pte_t tmp =paddr_to_pte (LINK_TO_LOAD ((unsigned long )&xen_fixmap),PTE_TABLE ); + +write_pte (pte, tmp); + +printk ("(XEN) fixmap is mapped\n" ); + } + +/* +* We only need the zeroeth table allocated, but not the PTEs set, because +* set_fixmap() will set them on the fly.
This function doesn't seem to exists yet (?).
Quoted 24 lines
xen/arch/riscv/mm.c +3
-0+*/ +} +/* * setup_initial_pagetables: * xen/arch/riscv/setup.c +2
-0@@ -46,6 +46,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id,test_macros_from_bug_h ();#endif +setup_fixmap_mappings (); +printk ("All set up\n" );for ( ;; )xen/arch/riscv/xen.lds.S +0
-0
xen/arch/riscv/xen.lds.S ASSERT(!SIZEOF(.got.plt), ".got.plt non-empty") · line 186
Quoted 7 lines
xen/arch/riscv/xen.lds.S +1
-1@@ -181,6 +181,6 @@ ASSERT(!SIZEOF(.got.plt), ".got.plt non-empty") * Changing the size of Xen binary can require an update of * PGTBL_INITIAL_COUNT. */ -ASSERT(_end - _start <= MB(2), "Xen too large for early-boot assumptions") +ASSERT(_end - _start <= XEN_SIZE, "Xen too large for early-boot assumptions") ASSERT(_ident_end - _ident_start <= IDENT_AREA_SIZE, "identity region is too big");
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 4/8] xen/riscv: setup fixmap mapping
Hi Julien,
Quoted 100 lines · Julien Grall
Hi Oleksii,
Quoted 35 lines · Oleksii Kurochko
Introduce a function to set up fixmap mappings and L0 page table for fixmap.
Additionally, defines were introduced in
riscv/config.hto calculate theFIXMAP_BASEaddress.
This involved introducing BOOT_FDT_VIRT_{START, SIZE} andXEN_SIZE,XEN_VIRT_END.Also, the check of Xen size was updated in the
riscv/lds.Sscript to useXEN_SIZEinstead of a hardcoded constant.Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V2:
- newly introduced patch
---
xen/arch/riscv/include/asm/config.h| 9 ++++++xen/arch/riscv/include/asm/fixmap.h| 48
+++++++++++++++++++++++++++++
xen/arch/riscv/include/asm/mm.h | 2 ++ xen/arch/riscv/include/asm/page.h | 7 +++++ xen/arch/riscv/mm.c | 35 +++++++++++++++++++++ xen/arch/riscv/setup.c | 2 ++ xen/arch/riscv/xen.lds.S | 2 +-7 files changed, 104 insertions(+), 1 deletion(-)create mode 100644
xen/arch/riscv/include/asm/fixmap.hxen/arch/riscv/include/asm/config.h +0
-0@@ -74,11 +74,20 @@ #error "unsupported RV_STAGE1_MODE" #endifQuoted 2 lines
+#define XEN_SIZE MB(2)NIT: I would name it
XEN_VIRT_SIZEto be consistent with the start/end.Quoted 1 line
+#define XEN_VIRT_END (
XEN_VIRT_START+XEN_SIZE)Can we get away with not introducing
*_ENDand just use START, SIZE? The
reason I am asking is with "end" it is never clear whether it is inclusive or exclusive. For instance, here you use an exclusive range but ...Quoted 41 lines
xen/arch/riscv/include/asm/config.h +4
-0+ +#define BOOT_FDT_VIRT_START XEN_VIRT_END +#define BOOT_FDT_VIRT_SIZE MB(4) +#define DIRECTMAP_SLOT_END 509
#define DIRECTMAP_SLOT_START 200
#define DIRECTMAP_VIRT_STARTSLOTN(DIRECTMAP_SLOT_START)#define DIRECTMAP_SIZE (SLOTN(DIRECTMAP_SLOT_END)-SLOTN(DIRECTMAP_SLOT_START))
+#define FIXMAP_BASE (BOOT_FDT_VIRT_START+BOOT_FDT_VIRT_SIZE)xen/arch/riscv/include/asm/config.h +2
-0+#define FIXMAP_ADDR (n) (FIXMAP_BASE + (n) * PAGE_SIZE) +#define FRAMETABLE_SCALE_FACTOR (PAGE_SIZE/sizeof(struct
page_info))
#defineFRAMETABLE_SIZE_IN_SLOTS(((DIRECTMAP_SIZE/ SLOTN(1)) /FRAMETABLE_SCALE_FACTOR) + 1)xen/arch/riscv/include/asm/fixmap.h new file +15
-0@@ -0,0 +1,48 @@ +/* +* fixmap.h: compile-time virtual memory allocation +*/ +#ifndef __ASM_FIXMAP_H +#define __ASM_FIXMAP_H + +#include <xen/bug.h> +#include <xen/page-size.h> +#include <xen/pmap.h> + +#include <asm/page.h> + +/* Fixmap slots */ +#define FIX_PMAP_BEGIN (0)/* Start of PMAP */ +#define FIX_PMAP_END (FIX_PMAP_BEGIN + NUM_FIX_PMAP - 1)/* End of Quoted 1 line
PMAP */
... here is seems to be inclusive. Furthermore if you had 32-bit address
space, it is also quite easy to have to create a region right at the top
of it. So when END is exclusive, it would become 0.
Quoted 3 lines
So on Arm, we decided to start to get rid of "end". I would consider to
do the same on RISC-V for new functions.
I will refactor the code and get rid of "end".
Quoted 6 lines
Quoted 3 lines
+#define
FIX_MISC(FIX_PMAP_END+ 1) /* Ephemeral mappings of hardware */Are you going to use this fixmap? If not, then I would consider to remove it.
Yes, it used now in copy_from_paddr():
/**
* copy_from_paddr - copy data from a physical address
* @dst: destination virtual address
* @paddr: source physical address
* @len: length to copy
*/
void __init copy_from_paddr(void *dst, paddr_t paddr, unsigned long len)
{
void *src = (void *)FIXMAP_ADDR(FIXMAP_MISC);
while (len) {
unsigned long l, s;
s = paddr & (PAGE_SIZE-1);
l = min(PAGE_SIZE - s, len);
set_fixmap(FIXMAP_MISC, maddr_to_mfn(paddr),
PAGE_HYPERVISOR_WC);
memcpy(dst, src + s, l);
clear_fixmap(FIXMAP_MISC);
paddr += l;
dst += l;
len -= l;
}}
Quoted 17 lines
Quoted 17 lines
xen/arch/riscv/include/asm/fixmap.h new file +16
-0+ +#define FIX_LAST FIX_MISC + +#define FIXADDR_START FIXMAP_ADDR(0) +#define FIXADDR_TOP FIXMAP_ADDR(FIX_LAST) + +#ifndef __ASSEMBLY__ + +/* +* Direct access to xen_fixmap[] should only happen when {set, +* clear}_fixmap() is unusable (e.g. where we would end up to +* recursively call the helpers). +*/ +extern pte_t xen_fixmap[]; + +/* Map a page in a fixmap entry */
Quoted 8 lines
xen/arch/riscv/include/asm/fixmap.h line 35
Quoted 4 lines
+extern void
set_fixmap(unsigned int map, mfn_t mfn, unsigned int attributes);xen/arch/riscv/include/asm/fixmap.h new file +2
-0+/* Remove a mapping from a fixmap entry */ +extern void clear_fixmap (unsigned int map);Neither of the functions seem to be implemented in this patch. Can you
clarify what's the plan for them?
You are right, it could be dropped now. But in future this functions are used for copy_from_paddr(). Look at the code above.
Quoted 63 lines
Also, I know that for x86/arm, we have some function prefixed with extern. But AFAIK, we are trying to get rid of them.
In any case, I think for RISC-V we need some consistency. For instance,
here you define with extern but...Quoted 20 lines
xen/arch/riscv/include/asm/fixmap.h new file +13
-0+ +#define fix_to_virt (slot) ((void *)FIXMAP_ADDR(slot)) + +static inline unsigned int virt_to_fix (vaddr_t vaddr) +{ + BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START); + + return ((vaddr - FIXADDR_START) >> PAGE_SHIFT); +} + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_FIXMAP_H */ xen/arch/riscv/include/asm/mm.h +0
-0@@ -255,4 +255,6 @@ static inline unsigned intarch_get_dma_bitsize (void)Quoted 4 lines
return 32; /* TODO */
}
+voidsetup_fixmap_mappings(void);... here it is without.
Quoted 28 lines
+
#endif /*_ASM_RISCV_MM_H*/xen/arch/riscv/include/asm/page.h +0
-0@@ -81,6 +81,13 @@ static inline void flush_page_to_ram(unsigned long mfn, bool sync_icache) BUG_ON("unimplemented"); }xen/arch/riscv/include/asm/page.h +7
-0+/* Write a pagetable entry. */ +static inline void write_pte (pte_t *p,pte_t pte) +{ + *p = pte; + asm volatile ("sfence.vma"); +} +#endif /*
__ASSEMBLY__*/
#endif /*_ASM_RISCV_PAGE_H*/xen/arch/riscv/mm.c +0
-0@@ -49,6 +49,9 @@ stage1_pgtbl_root[PAGETABLE_ENTRIES]; pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE)
Quoted 8 lines
xen/arch/riscv/mm.c stage1_pgtbl_root[PAGETABLE_ENTRIES]; · line 53
Quoted 4 lines
xen/arch/riscv/mm.c +0
-0stage1_pgtbl_nonroot[PGTBL_INITIAL_COUNT * PAGETABLE_ENTRIES];xen/arch/riscv/mm.c +2
-0+pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) +xen_fixmap[PAGETABLE_ENTRIES ];Can you add a
BUILD_BUG_ON()to check that the number of entries in the
fixmap will never be abovePAGETABLE_ENTRIES?
Sure. What is the best place? Somewhere in setup_fixmap_mappings()?
Quoted 20 lines
Quoted 20 lines
+
#defineHANDLE_PGTBL(curr_lvl_num)
\
index = pt_index(curr_lvl_num,
page_addr); \
if (pte_is_valid(pgtbl[index])
) \xen/arch/riscv/mm.c +0
-0@@ -191,6 +194,38 @@ static bool __init check_pgtbl_mode_support(struct mmu_desc *mmu_desc, return is_mode_supported; }xen/arch/riscv/mm.c +6
-0+void __init setup_fixmap_mappings (void ) +{ + pte_t *pte; + unsigned int i; + + pte = &stage1_pgtbl_root[pt_index(HYP_PT_ROOT_LEVEL,
Quoted 8 lines
Quoted 3 lines
FIXMAP_ADDR(0))];
+
+ for ( i =HYP_PT_ROOT_LEVEL- 1; i != 0; i-- )I am a little bit confused with the - 1. Is this because you only want
to map at L1 (I am not sure if this is the correct naming for RISC- V)?
Yes, the idea is that I want to stop in L1 ( 2Mb pages ) as this mapping is already exist and there will not be need to create a new table. ( what will fail because boot allocator isn't initialized yet and alloc_boot_pages() will start to alarm because of BUG_ON(!nr_bootmem_regions) ).
RISC-V also uses word levels, but the order is an opposite to Arm.
Quoted 2 lines
In any case, I think it would be worth a comment.
Sure, I will add it.
Quoted 12 lines
xen/arch/riscv/mm.c static bool __init check_pgtbl_mode_support(struct mmu_desc *mmu_desc, · line 212
Quoted 9 lines
+ {
+ BUG_ON(!pte_is_valid(*pte));xen/arch/riscv/mm.c +6
-0+ + pte = (pte_t *)LOAD_TO_LINK(pte_to_paddr(*pte)); + pte = &pte[pt_index(i, FIXMAP_ADDR(0))]; + } + + BUG_ON( pte_is_valid(*pte) );Coding style: BUG_ON(pte_is_valid(*pte));
Quoted 6 lines
Quoted 2 lines
+
+ if ( !pte_is_valid(*pte) )I am a bit confused with this check. Above, Xen will crash if the PTE is
valid. So why do we need a runtime check?
You are right, there is no any sense. We should drop it.
Quoted 16 lines
Quoted 12 lines
+ {
+pte_ttmp =paddr_to_pte(LINK_TO_LOAD((unsigned long)&xen_fixmap), PTE_TABLE);xen/arch/riscv/mm.c +8
-0+ + write_pte(pte, tmp); + + printk("(XEN) fixmap is mapped\n"); + } + + /* +* We only need the zeroeth table allocated, but not the PTEs Quoted 2 lines
set, because
+ *set_fixmap()will set them on the fly.This function doesn't seem to exists yet (?).
Not yet. It will be introduced later...
~ Oleksii
Quoted 40 lines
Quoted 33 lines
+ */
xen/arch/riscv/mm.c +2
-0+} +/*
*setup_initial_pagetables:
*xen/arch/riscv/setup.c +0
-0@@ -46,6 +46,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id, test_macros_from_bug_h(); #endif
+setup_fixmap_mappings();
+
printk("All set up\n");
for ( ;; )xen/arch/riscv/xen.lds.S +1
-1@@ -181,6 +181,6 @@ ASSERT(!SIZEOF(.got.plt), ".got.plt non- empty") * Changing the size of Xen binary can require an update of * PGTBL_INITIAL_COUNT. */ -ASSERT(_end - _start <= MB(2), "Xen too large for early-boot assumptions") +ASSERT(_end - _start <= XEN_SIZE, "Xen too large for early-bootQuoted 4 lines
assumptions")
ASSERT(_ident_end - _ident_start <= IDENT_AREA_SIZE, "identity region is too big");Cheers,
Re: [PATCH v2 4/8] xen/riscv: setup fixmap mapping
Quoted 1 line · Oleksii
Hi Julien,
Hi Oleksii,
Quoted 166 lines · Julien Grall
Quoted 100 lines
Hi Oleksii,
Quoted 33 lines · Oleksii Kurochko
Introduce a function to set up fixmap mappings and L0 page table for fixmap.
Additionally, defines were introduced in
riscv/config.hto calculate theFIXMAP_BASEaddress.
This involved introducing BOOT_FDT_VIRT_{START, SIZE} andXEN_SIZE,XEN_VIRT_END.Also, the check of Xen size was updated in the
riscv/lds.Sscript to useXEN_SIZEinstead of a hardcoded constant.Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V2:
- newly introduced patch--- xen/arch/riscv/include/asm/config.h | 9 ++++++ xen/arch/riscv/include/asm/fixmap.h | 48 +++++++++++++++++++++++++++++ xen/arch/riscv/include/asm/mm.h | 2 ++ xen/arch/riscv/include/asm/page.h | 7 +++++ xen/arch/riscv/mm.c | 35 +++++++++++++++++++++ xen/arch/riscv/setup.c | 2 ++ xen/arch/riscv/xen.lds.S | 2 +- 7 files changed, 104 insertions(+), 1 deletion(-)create mode 100644
xen/arch/riscv/include/asm/fixmap.hxen/arch/riscv/include/asm/config.h +0
-0xen/arch/riscv/include/asm/config.h line 77
Quoted 4 lines
xen/arch/riscv/include/asm/config.h +1
-0@@ -74,11 +74,20 @@ #error "unsupported RV_STAGE1_MODE" #endif +#define XEN_SIZE MB(2)NIT: I would name it
XEN_VIRT_SIZEto be consistent with the start/end.xen/arch/riscv/include/asm/config.h line 78
Quoted 1 line
xen/arch/riscv/include/asm/config.h +1
-0+#define XEN_VIRT_END (XEN_VIRT_START + XEN_SIZE)Can we get away with not introducing
*_ENDand just use START, SIZE? The
reason I am asking is with "end" it is never clear whether it is inclusive or exclusive. For instance, here you use an exclusive range but ...Quoted 41 lines
xen/arch/riscv/include/asm/config.h +7
-0+ +#define BOOT_FDT_VIRT_START XEN_VIRT_END +#define BOOT_FDT_VIRT_SIZE MB(4) + #define DIRECTMAP_SLOT_END 509 #define DIRECTMAP_SLOT_START 200 #define DIRECTMAP_VIRT_START SLOTN(DIRECTMAP_SLOT_START) #define DIRECTMAP_SIZE (SLOTN(DIRECTMAP_SLOT_END) - SLOTN(DIRECTMAP_SLOT_START)) +#define FIXMAP_BASE (BOOT_FDT_VIRT_START + BOOT_FDT_VIRT_SIZE) +#define FIXMAP_ADDR (n) (FIXMAP_BASE + (n) * PAGE_SIZE) + #define FRAMETABLE_SCALE_FACTOR (PAGE_SIZE/sizeof(struct
page_info))
#defineFRAMETABLE_SIZE_IN_SLOTS(((DIRECTMAP_SIZE/ SLOTN(1)) /FRAMETABLE_SCALE_FACTOR) + 1)xen/arch/riscv/include/asm/fixmap.h new file +15
-0@@ -0,0 +1,48 @@ +/* +* fixmap.h: compile-time virtual memory allocation +*/ +#ifndef __ASM_FIXMAP_H +#define __ASM_FIXMAP_H + +#include <xen/bug.h> +#include <xen/page-size.h> +#include <xen/pmap.h> + +#include <asm/page.h> + +/* Fixmap slots */ +#define FIX_PMAP_BEGIN (0)/* Start of PMAP */ +#define FIX_PMAP_END (FIX_PMAP_BEGIN + NUM_FIX_PMAP - 1)/* End of Quoted 1 line
PMAP */
... here is seems to be inclusive. Furthermore if you had 32-bit address
space, it is also quite easy to have to create a region right at the top
of it. So when END is exclusive, it would become 0.Quoted 3 lines
So on Arm, we decided to start to get rid of "end". I would consider to
do the same on RISC-V for new functions.I will refactor the code and get rid of "end".
Quoted 6 lines
Quoted 3 lines
+#define
FIX_MISC(FIX_PMAP_END+ 1) /* Ephemeral mappings of hardware */Are you going to use this fixmap? If not, then I would consider to remove it.
Yes, it used now in
copy_from_paddr():/** * copy_from_paddr - copy data from a physical address * @dst: destination virtual address * @paddr: source physical address * @len: length to copy */ void __init copy_from_paddr(void *dst, paddr_t paddr, unsigned long len) { void *src = (void *)FIXMAP_ADDR(FIXMAP_MISC); while (len) { unsigned long l, s; s = paddr & (PAGE_SIZE-1); l = min(PAGE_SIZE - s, len); set_fixmap(FIXMAP_MISC, maddr_to_mfn(paddr), PAGE_HYPERVISOR_WC); memcpy(dst, src + s, l); clear_fixmap(FIXMAP_MISC); paddr += l; dst += l; len -= l; } }Quoted 17 lines
Quoted 17 lines
xen/arch/riscv/include/asm/fixmap.h new file +16
-0+ +#define FIX_LAST FIX_MISC + +#define FIXADDR_START FIXMAP_ADDR(0) +#define FIXADDR_TOP FIXMAP_ADDR(FIX_LAST) + +#ifndef __ASSEMBLY__ + +/* +* Direct access to xen_fixmap[] should only happen when {set, +* clear}_fixmap() is unusable (e.g. where we would end up to +* recursively call the helpers). +*/ +extern pte_t xen_fixmap[]; + +/* Map a page in a fixmap entry */ Quoted 8 lines
xen/arch/riscv/include/asm/fixmap.h line 35
Quoted 4 lines
+extern void
set_fixmap(unsigned int map, mfn_t mfn, unsigned int attributes);xen/arch/riscv/include/asm/fixmap.h new file +2
-0+/* Remove a mapping from a fixmap entry */ +extern void clear_fixmap (unsigned int map);Neither of the functions seem to be implemented in this patch. Can you
clarify what's the plan for them?
Quoted 2 lines
You are right, it could be dropped now. But in future this functions are used for
copy_from_paddr(). Look at the code above.
Right, to me it is just odd we are definition prototype for functions that don't yet exist.
Quoted 65 lines
Quoted 65 lines
Also, I know that for x86/arm, we have some function prefixed with extern. But AFAIK, we are trying to get rid of them.
In any case, I think for RISC-V we need some consistency. For instance,
here you define with extern but...Quoted 19 lines
xen/arch/riscv/include/asm/fixmap.h new file +13
-0+ +#define fix_to_virt (slot) ((void *)FIXMAP_ADDR(slot)) + +static inline unsigned int virt_to_fix (vaddr_t vaddr) +{ + BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START); + + return ((vaddr - FIXADDR_START) >> PAGE_SHIFT); +} + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_FIXMAP_H */ xen/arch/riscv/include/asm/mm.h +0
-0xen/arch/riscv/include/asm/mm.h static inline unsigned int · line 259
Quoted 5 lines
xen/arch/riscv/include/asm/mm.h +1
-0@@ -255,4 +255,6 @@ static inline unsigned int arch_get_dma_bitsize(void) return 32; /* TODO */ } +void setup_fixmap_mappings (void );... here it is without.
Quoted 30 lines
xen/arch/riscv/include/asm/mm.h +1
-0+#endif /*
_ASM_RISCV_MM_H*/xen/arch/riscv/include/asm/page.h +7
-0@@ -81,6 +81,13 @@ static inline void flush_page_to_ram(unsigned long mfn, bool sync_icache) BUG_ON("unimplemented"); } +/* Write a pagetable entry. */ +static inline void write_pte (pte_t *p,pte_t pte) +{ + *p = pte; + asm volatile ("sfence.vma"); +} + #endif /* __ASSEMBLY__ */#endif /*
_ASM_RISCV_PAGE_H*/xen/arch/riscv/mm.c +0
-0@@ -49,6 +49,9 @@ stage1_pgtbl_root[PAGETABLE_ENTRIES]; pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) stage1_pgtbl_nonroot[PGTBL_INITIAL_COUNT * PAGETABLE_ENTRIES];
Quoted 7 lines
Quoted 6 lines
xen/arch/riscv/mm.c stage1_pgtbl_root[PAGETABLE_ENTRIES]; · line 53
Quoted 2 lines
xen/arch/riscv/mm.c +2
-0+pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) +xen_fixmap[PAGETABLE_ENTRIES ];Can you add a
BUILD_BUG_ON()to check that the number of entries in the
fixmap will never be abovePAGETABLE_ENTRIES?Sure. What is the best place? Somewhere in
setup_fixmap_mappings()?
I think so.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 4/8] xen/riscv: setup fixmap mapping
In reply to Julien GrallHi Julien,
Quoted 11 lines · Julien Grall
Quoted 4 lines
xen/arch/riscv/include/asm/fixmap.h new file +3
-0+/* Fixmap slots */ +#define FIX_PMAP_BEGIN (0)/* Start of PMAP */ +#define FIX_PMAP_END (FIX_PMAP_BEGIN + NUM_FIX_PMAP - 1)/* End of PMAP */
... here is seems to be inclusive. Furthermore if you had 32-bit address
space, it is also quite easy to have to create a region right at the top
of it. So when END is exclusive, it would become 0.
Quoted 3 lines
So on Arm, we decided to start to get rid of "end". I would consider to
do the same on RISC-V for new functions.
I assume that you wrote here just as an example of confusion occurs because of using *_END but just to be clear I have to leave FIXMAP_MAP_END as-is because it is used now by common code.
~ Oleksii
Re: [PATCH v2 4/8] xen/riscv: setup fixmap mapping
Quoted 1 line · On 23/07/2024 13:58, [email protected] wrote:
Hi Julien,
Hi Oleksii,
Quoted 12 lines · Julien Grall
Quoted 11 lines
Quoted 4 lines
xen/arch/riscv/include/asm/fixmap.h new file +3
-0+/* Fixmap slots */ +#define FIX_PMAP_BEGIN (0)/* Start of PMAP */ +#define FIX_PMAP_END (FIX_PMAP_BEGIN + NUM_FIX_PMAP - 1)/* End of PMAP */
... here is seems to be inclusive. Furthermore if you had 32-bit address
space, it is also quite easy to have to create a region right at the top
of it. So when END is exclusive, it would become 0.
Quoted 6 lines
Quoted 3 lines
So on Arm, we decided to start to get rid of "end". I would consider to
do the same on RISC-V for new functions.I assume that you wrote here just as an example of confusion occurs because of using
*_ENDbut just to be clear I have to leaveFIXMAP_MAP_ENDas-is because it is used now by common code.
Indeed. FIXMAP_PMAP_END should stay for now.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 4/8] xen/riscv: setup fixmap mapping
In reply to Julien GrallHello Julien,
Quoted 6 lines · Julien Grall
Quoted 6 lines
xen/arch/riscv/mm.c +0
-0@@ -49,6 +49,9 @@ stage1_pgtbl_root[PAGETABLE_ENTRIES]; pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE)
Quoted 8 lines
xen/arch/riscv/mm.c stage1_pgtbl_root[PAGETABLE_ENTRIES]; · line 53
Quoted 4 lines
xen/arch/riscv/mm.c +0
-0stage1_pgtbl_nonroot[PGTBL_INITIAL_COUNT * PAGETABLE_ENTRIES];xen/arch/riscv/mm.c +2
-0+pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) +xen_fixmap[PAGETABLE_ENTRIES ];Can you add a
BUILD_BUG_ON()to check that the number of entries in the
fixmap will never be abovePAGETABLE_ENTRIES?
I just realized that we don't have the information about how many entries has been used. Am I confusing something?
~ Oleksii
Re: [PATCH v2 4/8] xen/riscv: setup fixmap mapping
Quoted 1 line · On 23/07/2024 14:27, [email protected] wrote:
Hello Julien,
Hi Oleksii,
Quoted 9 lines · Julien Grall
Quoted 8 lines
Quoted 8 lines
xen/arch/riscv/mm.c +0
-0@@ -49,6 +49,9 @@ stage1_pgtbl_root[PAGETABLE_ENTRIES]; pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) stage1_pgtbl_nonroot[PGTBL_INITIAL_COUNT * PAGETABLE_ENTRIES];
Quoted 8 lines
Quoted 6 lines
xen/arch/riscv/mm.c stage1_pgtbl_root[PAGETABLE_ENTRIES]; · line 53
Quoted 2 lines
xen/arch/riscv/mm.c +2
-0+pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) +xen_fixmap[PAGETABLE_ENTRIES ];Can you add a
BUILD_BUG_ON()to check that the number of entries in the
fixmap will never be abovePAGETABLE_ENTRIES?I just realized that we don't have the information about how many entries has been used. Am I confusing something?
I think we do. It is FIX_LAST.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 4/8] xen/riscv: setup fixmap mapping
Quoted 23 lines · Julien Grall
Quoted 1 line · On 23/07/2024 14:27, [email protected] wrote:
Hello Julien,
Hi Oleksii,
Quoted 17 lines · Julien Grall
Quoted 16 lines
xen/arch/riscv/mm.c stage1_pgtbl_root[PAGETABLE_ENTRIES]; · line 53
Quoted 11 lines
xen/arch/riscv/mm.c +0
-0@@ -49,6 +49,9 @@ stage1_pgtbl_root[PAGETABLE_ENTRIES]; pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE)stage1_pgtbl_nonroot[PGTBL_INITIAL_COUNT *
PAGETABLE_ENTRIES];xen/arch/riscv/mm.c +2
-0+pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) +xen_fixmap[PAGETABLE_ENTRIES ];Can you add a
BUILD_BUG_ON()to check that the number of entries in
the
fixmap will never be abovePAGETABLE_ENTRIES?
Quoted 4 lines
Quoted 2 lines
I just realized that we don't have the information about how many entries has been used. Am I confusing something?
I think we do. It is
FIX_LAST.
Sure. We have FIX_LAST. Thanks
~ Oleksii
Re: [PATCH v2 4/8] xen/riscv: setup fixmap mapping
In reply to Oleksii KurochkoQuoted 9 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/config.h +3
-0@@ -74,11 +74,20 @@#error "unsupported RV_STAGE1_MODE"#endif +#define XEN_SIZE MB(2) +#define XEN_VIRT_END (XEN_VIRT_START + XEN_SIZE) +
xen/arch/riscv/include/asm/config.h line 89
Quoted 10 lines
xen/arch/riscv/include/asm/config.h +5
-0+#define BOOT_FDT_VIRT_START XEN_VIRT_END +#define BOOT_FDT_VIRT_SIZE MB(4) +#define DIRECTMAP_SLOT_END 509#define DIRECTMAP_SLOT_START 200#define DIRECTMAP_VIRT_START SLOTN(DIRECTMAP_SLOT_START)#define DIRECTMAP_SIZE (SLOTN(DIRECTMAP_SLOT_END) - SLOTN(DIRECTMAP_SLOT_START)) +#define FIXMAP_BASE (BOOT_FDT_VIRT_START + BOOT_FDT_VIRT_SIZE) +#define FIXMAP_ADDR (n) (FIXMAP_BASE + (n) * PAGE_SIZE)
Why exactly do you insert this here, and not adjacent to BOOT_FDT_VIRT_*, which it actually is adjacent with? Then ...
xen/arch/riscv/include/asm/config.h line 92
Quoted 2 lines
xen/arch/riscv/include/asm/config.h +0
-0#define FRAMETABLE_SCALE_FACTOR (PAGE_SIZE/sizeof(struct page_info))#define FRAMETABLE_SIZE_IN_SLOTS (((DIRECTMAP_SIZE / SLOTN(1)) / FRAMETABLE_SCALE_FACTOR) + 1)
... this would also stay next to DIRECTMAP_*, which it uses.
xen/arch/riscv/include/asm/page.h static inline void flush_page_to_ram(unsigned long mfn, bool sync_icache) · line 88
Quoted 11 lines
xen/arch/riscv/include/asm/page.h +5
-0@@ -81,6 +81,13 @@ static inline void flush_page_to_ram(unsigned long mfn, bool sync_icache)BUG_ON ("unimplemented" ); } +/* Write a pagetable entry. */ +static inline void write_pte (pte_t *p,pte_t pte) +{ + *p = pte; + asmvolatile ("sfence.vma" );
When they don't have operands, asm()-s are volatile anyway (being explicit about this may still be desirable, yes). But: Can you get away without operands here? Don't you need a memory clobber for the fence to actually remain where it is needed?
Also, nit (style): Blanks missing.
xen/arch/riscv/mm.c stage1_pgtbl_root[PAGETABLE_ENTRIES]; · line 53
Quoted 8 lines
xen/arch/riscv/mm.c +2
-0@@ -49,6 +49,9 @@ stage1_pgtbl_root[PAGETABLE_ENTRIES]; pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) stage1_pgtbl_nonroot[PGTBL_INITIAL_COUNT *PAGETABLE_ENTRIES ]; +pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) +xen_fixmap[PAGETABLE_ENTRIES ];
Any reason this cannot be static?
Jan
Re: [PATCH v2 4/8] xen/riscv: setup fixmap mapping
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/config.h +0
-0@@ -74,11 +74,20 @@ #error "unsupported RV_STAGE1_MODE" #endifxen/arch/riscv/include/asm/config.h +6
-0+#define XEN_SIZE MB(2) +#define XEN_VIRT_END (XEN_VIRT_START + XEN_SIZE) + +#define BOOT_FDT_VIRT_START XEN_VIRT_END +#define BOOT_FDT_VIRT_SIZE MB(4) +#define DIRECTMAP_SLOT_END 509
#define DIRECTMAP_SLOT_START 200
#define DIRECTMAP_VIRT_STARTSLOTN(DIRECTMAP_SLOT_START)#define DIRECTMAP_SIZE (SLOTN(DIRECTMAP_SLOT_END)-SLOTN(DIRECTMAP_SLOT_START))
Quoted 8 lines
Quoted 4 lines
+#define FIXMAP_BASE (BOOT_FDT_VIRT_START+BOOT_FDT_VIRT_SIZE)
+#define FIXMAP_ADDR(n) (FIXMAP_BASE+ (n) *PAGE_SIZE)Why exactly do you insert this here, and not adjacent to BOOT_FDT_VIRT_*,
which it actually is adjacent with?
I tried to follow alphabetical order.
Quoted 22 lines
Then ...
Quoted 4 lines
#define FRAMETABLE_SCALE_FACTOR (PAGE_SIZE/sizeof(struct
page_info))
#defineFRAMETABLE_SIZE_IN_SLOTS(((DIRECTMAP_SIZE/ SLOTN(1)) /FRAMETABLE_SCALE_FACTOR) + 1)... this would also stay next to DIRECTMAP_*, which it uses.
xen/arch/riscv/include/asm/page.h static inline void flush_page_to_ram(unsigned long mfn, bool sync_icache) · line 88
Quoted 12 lines
xen/arch/riscv/include/asm/page.h +0
-0@@ -81,6 +81,13 @@ static inline void flush_page_to_ram(unsigned long mfn, bool sync_icache) BUG_ON("unimplemented"); }xen/arch/riscv/include/asm/page.h +5
-0+/* Write a pagetable entry. */ +static inline void write_pte (pte_t *p,pte_t pte) +{ + *p = pte; + asm volatile ("sfence.vma");
Quoted 7 lines
When they don't have operands, asm()-s are volatile anyway (being explicit
about this may still be desirable, yes). But: Can you get away without
operands here? Don't you need a memory clobber for the fence to actually
remain where it is needed?
It should be "::memory" here. Thanks.
Quoted 13 lines
Also, nit (style): Blanks missing.
xen/arch/riscv/mm.c stage1_pgtbl_root[PAGETABLE_ENTRIES]; · line 53
Quoted 8 lines
xen/arch/riscv/mm.c +0
-0@@ -49,6 +49,9 @@ stage1_pgtbl_root[PAGETABLE_ENTRIES]; pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) stage1_pgtbl_nonroot[PGTBL_INITIAL_COUNT * PAGETABLE_ENTRIES];xen/arch/riscv/mm.c +2
-0+pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) +xen_fixmap[PAGETABLE_ENTRIES ];Any reason this cannot be static?
It will be used by pmap:
static inline void arch_pmap_map(unsigned int slot, mfn_t mfn)
{
pte_t *entry = &xen_fixmap[slot];
pte_t pte;
ASSERT(!pte_is_valid(*entry));
pte = mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW);
pte.pte |= PTE_LEAF_DEFAULT;
write_pte(entry, pte);}
static inline void arch_pmap_unmap(unsigned int slot)
{
pte_t pte = {};write_pte(&xen_fixmap[slot], pte);
}
~ Oleksii
Re: [PATCH v2 4/8] xen/riscv: setup fixmap mapping
Quoted 27 lines · Oleksii
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/config.h +0
-0@@ -74,11 +74,20 @@ #error "unsupported RV_STAGE1_MODE" #endifxen/arch/riscv/include/asm/config.h +6
-0+#define XEN_SIZE MB(2) +#define XEN_VIRT_END (XEN_VIRT_START + XEN_SIZE) + +#define BOOT_FDT_VIRT_START XEN_VIRT_END +#define BOOT_FDT_VIRT_SIZE MB(4) +#define DIRECTMAP_SLOT_END 509
#define DIRECTMAP_SLOT_START 200
#define DIRECTMAP_VIRT_STARTSLOTN(DIRECTMAP_SLOT_START)#define DIRECTMAP_SIZE (SLOTN(DIRECTMAP_SLOT_END)-SLOTN(DIRECTMAP_SLOT_START))Quoted 8 lines
Quoted 4 lines
+#define FIXMAP_BASE (BOOT_FDT_VIRT_START+BOOT_FDT_VIRT_SIZE)
+#define FIXMAP_ADDR(n) (FIXMAP_BASE+ (n) *PAGE_SIZE)Why exactly do you insert this here, and not adjacent to BOOT_FDT_VIRT_*,
which it actually is adjacent with?
Quoted 1 line
I tried to follow alphabetical order.
Oh, X before B (just making fun) ... Anyway, my take here is that sorting by address is going to be more helpful.
Quoted 21 lines
Quoted 10 lines
xen/arch/riscv/mm.c stage1_pgtbl_root[PAGETABLE_ENTRIES]; · line 53
Quoted 8 lines
xen/arch/riscv/mm.c +0
-0@@ -49,6 +49,9 @@ stage1_pgtbl_root[PAGETABLE_ENTRIES]; pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) stage1_pgtbl_nonroot[PGTBL_INITIAL_COUNT * PAGETABLE_ENTRIES];xen/arch/riscv/mm.c +2
-0+pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) +xen_fixmap[PAGETABLE_ENTRIES ];Any reason this cannot be static?
It will be used by pmap:
static inline void arch_pmap_map(unsigned int slot, mfn_t mfn) { pte_t *entry = &xen_fixmap[slot]; pte_t pte; ASSERT(!pte_is_valid(*entry)); pte = mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW); pte.pte |= PTE_LEAF_DEFAULT; write_pte(entry, pte);
Quoted 8 lines
}
static inline void arch_pmap_unmap(unsigned int slot)
{
pte_t pte = {};
write_pte(&xen_fixmap[slot], pte);
}Yet as asked there - shouldn't that be set_fixmap() and clear_fixmap()?
Jan
Re: [PATCH v2 4/8] xen/riscv: setup fixmap mapping
Quoted 65 lines · Jan Beulich
Quoted 28 lines · Oleksii
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/config.h +0
-0@@ -74,11 +74,20 @@ #error "unsupported RV_STAGE1_MODE" #endifxen/arch/riscv/include/asm/config.h +6
-0+#define XEN_SIZE MB(2) +#define XEN_VIRT_END (XEN_VIRT_START + XEN_SIZE) + +#define BOOT_FDT_VIRT_START XEN_VIRT_END +#define BOOT_FDT_VIRT_SIZE MB(4) +#define DIRECTMAP_SLOT_END 509
#define DIRECTMAP_SLOT_START 200
#define DIRECTMAP_VIRT_STARTSLOTN(DIRECTMAP_SLOT_START)#define DIRECTMAP_SIZE (SLOTN(DIRECTMAP_SLOT_END)-SLOTN(DIRECTMAP_SLOT_START))Quoted 8 lines
Quoted 4 lines
+#define FIXMAP_BASE (
BOOT_FDT_VIRT_START+BOOT_FDT_VIRT_SIZE)
+#define FIXMAP_ADDR(n) (FIXMAP_BASE+ (n) *PAGE_SIZE)Why exactly do you insert this here, and not adjacent to BOOT_FDT_VIRT_*,
which it actually is adjacent with?Quoted 1 line
I tried to follow alphabetical order.
Oh, X before B (just making fun) ... Anyway, my take here is that sorting
by address is going to be more helpful.Quoted 21 lines
Quoted 10 lines
xen/arch/riscv/mm.c stage1_pgtbl_root[PAGETABLE_ENTRIES]; · line 53
Quoted 8 lines
xen/arch/riscv/mm.c +0
-0@@ -49,6 +49,9 @@ stage1_pgtbl_root[PAGETABLE_ENTRIES]; pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) stage1_pgtbl_nonroot[PGTBL_INITIAL_COUNT * PAGETABLE_ENTRIES];xen/arch/riscv/mm.c +2
-0+pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) +xen_fixmap[PAGETABLE_ENTRIES ];Any reason this cannot be static?
It will be used by pmap:
static inline voidarch_pmap_map(unsigned int slot, mfn_t mfn){
pte_t*entry = &xen_fixmap[slot];
pte_tpte;
ASSERT(!pte_is_valid(*entry));
pte =mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW); pte.pte |=PTE_LEAF_DEFAULT;
write_pte(entry, pte);Quoted 8 lines
}
static inline voidarch_pmap_unmap(unsigned int slot){
pte_tpte = {};
write_pte(&xen_fixmap[slot], pte);
}
Quoted 2 lines
Yet as asked there - shouldn't that be
set_fixmap()andclear_fixmap()?
It should be, I'll rework that in the next patch version.
~ Oleksii
Re: [PATCH v2 4/8] xen/riscv: setup fixmap mapping
Quoted 67 lines · On Mon, 2024-07-22 at 19:04 +0200, [email protected] wrote:
Quoted 66 lines · Jan Beulich
Quoted 28 lines · Oleksii
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/config.h +0
-0@@ -74,11 +74,20 @@ #error "unsupported RV_STAGE1_MODE" #endifxen/arch/riscv/include/asm/config.h +6
-0+#define XEN_SIZE MB(2) +#define XEN_VIRT_END (XEN_VIRT_START + XEN_SIZE) + +#define BOOT_FDT_VIRT_START XEN_VIRT_END +#define BOOT_FDT_VIRT_SIZE MB(4) +#define DIRECTMAP_SLOT_END 509
#define DIRECTMAP_SLOT_START 200
#define DIRECTMAP_VIRT_STARTSLOTN(DIRECTMAP_SLOT_START)#define DIRECTMAP_SIZE (SLOTN(DIRECTMAP_SLOT_END)-SLOTN(DIRECTMAP_SLOT_START))Quoted 8 lines
Quoted 4 lines
+#define FIXMAP_BASE (
BOOT_FDT_VIRT_START+BOOT_FDT_VIRT_SIZE)
+#define FIXMAP_ADDR(n) (FIXMAP_BASE+ (n) *PAGE_SIZE)Why exactly do you insert this here, and not adjacent to BOOT_FDT_VIRT_*,
which it actually is adjacent with?Quoted 1 line
I tried to follow alphabetical order.
Oh, X before B (just making fun) ... Anyway, my take here is that sorting
by address is going to be more helpful.Quoted 30 lines
Quoted 11 lines
xen/arch/riscv/mm.c stage1_pgtbl_root[PAGETABLE_ENTRIES]; · line 53
Quoted 9 lines
xen/arch/riscv/mm.c +0
-0@@ -49,6 +49,9 @@ stage1_pgtbl_root[PAGETABLE_ENTRIES]; pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE)stage1_pgtbl_nonroot[PGTBL_INITIAL_COUNT *
PAGETABLE_ENTRIES];xen/arch/riscv/mm.c +2
-0+pte_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) +xen_fixmap[PAGETABLE_ENTRIES ];Any reason this cannot be static?
It will be used by pmap:
static inline voidarch_pmap_map(unsigned int slot, mfn_t mfn){
pte_t*entry = &xen_fixmap[slot];
pte_tpte;
ASSERT(!pte_is_valid(*entry));
pte =mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW); pte.pte |=PTE_LEAF_DEFAULT;
write_pte(entry, pte);
}
static inline voidarch_pmap_unmap(unsigned int slot){
pte_tpte = {};
write_pte(&xen_fixmap[slot], pte);
}
Quoted 3 lines
Quoted 2 lines
Yet as asked there - shouldn't that be
set_fixmap()andclear_fixmap()?It should be, I'll rework that in the next patch version.
It couldn't be set_fixmap() and clear_fixmap() as I am going to implement them using map_pages_to_xen() because:
...
/*
* We cannot use set_fixmap() here. We use PMAP when the domain map
* page infrastructure is not yet initialized, somap_pages_to_xen() called
* by set_fixmap() needs to map pages on demand, which then callspmap()
* again, resulting in a loop. Modify the PTEs directly instead.
The same
* is true for pmap_unmap().
*/
arch_pmap_map(slot, mfn);...
~ Oleksii
PATCH v2 5/8 xen/riscv: introduce asm/pmap.h header
In reply to Oleksii KurochkoIntroduces arch_pmap_{un}map functions and select HAS_PMAP for CONFIG_RISCV.
Additionaly it was necessary to introduce functions:
- mfn_to_xen_entry
- mfn_to_pte
---
Changes in V2:
- newly introduced patch
--- xen/arch/riscv/Kconfig | 1 + xen/arch/riscv/include/asm/page.h | 2 ++ xen/arch/riscv/include/asm/pmap.h | 28 ++++++++++++++++++++++++++++ xen/arch/riscv/mm.c | 14 ++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 xen/arch/riscv/include/asm/pmap.h
xen/arch/riscv/Kconfig +1 -0
@@ -3,6 +3,7 @@ config RISCV select FUNCTION_ALIGNMENT_16B select GENERIC_BUG_FRAME select HAS_DEVICE_TREE + select HAS_PMAP config RISCV_64 def_bool y
xen/arch/riscv/include/asm/page.h +2 -0
@@ -51,6 +51,8 @@ typedef struct {#endif } pte_t; +pte_t mfn_to_xen_entry (mfn_t mfn,unsigned int attr); +static inline pte_t paddr_to_pte (paddr_t paddr,unsigned int permissions) {
xen/arch/riscv/include/asm/pmap.h new file +28 -0
@@ -0,0 +1,28 @@ +#ifndef __ASM_PMAP_H__ +#define __ASM_PMAP_H__ + +#include <xen/bug.h> +#include <xen/mm.h> + +#include <asm/fixmap.h> + +static inline void arch_pmap_map (unsigned int slot,mfn_t mfn) +{ +pte_t *entry = &xen_fixmap[slot]; +pte_t pte; + +ASSERT (!pte_is_valid (*entry)); + + pte =mfn_to_xen_entry (mfn,PAGE_HYPERVISOR_RW ); + pte.pte |=PTE_LEAF_DEFAULT ; +write_pte (entry, pte); +} + +static inline void arch_pmap_unmap (unsigned int slot) +{ +pte_t pte = {}; + +write_pte (&xen_fixmap[slot], pte); +} + +#endif /* __ASM_PMAP_H__ */
xen/arch/riscv/mm.c +14 -0
@@ -370,3 +370,17 @@ int map_pages_to_xen(unsigned long virt,BUG_ON ("unimplemented" );return -1 ; } + +static inline pte_t mfn_to_pte (mfn_t mfn) +{ +unsigned long pte =mfn_x (mfn) <<PTE_PPN_SHIFT ; +return (pte_t ){ .pte = pte}; +} + +inline pte_t mfn_to_xen_entry (mfn_t mfn,unsigned int attr) +{ +/* there is no attr field in RISC-V's pte */ + (void ) attr; + +return mfn_to_pte (mfn); +}
Signature · 1 line
2.45.2
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Hi Oleksii,
Quoted 87 lines · Oleksii Kurochko
Introduces arch_pmap_{un}map functions and select
HAS_PMAPforCONFIG_RISCV.Additionaly it was necessary to introduce functions:
-mfn_to_xen_entry
-mfn_to_pteSigned-off-by Oleksii Kurochko <[email protected]>---
Changes in V2:
- newly introduced patch--- xen/arch/riscv/Kconfig | 1 + xen/arch/riscv/include/asm/page.h | 2 ++ xen/arch/riscv/include/asm/pmap.h | 28 ++++++++++++++++++++++++++++ xen/arch/riscv/mm.c | 14 ++++++++++++++ 4 files changed, 45 insertions(+)create mode 100644
xen/arch/riscv/include/asm/pmap.hxen/arch/riscv/Kconfig +1
-0@@ -3,6 +3,7 @@ config RISCV select FUNCTION_ALIGNMENT_16B select GENERIC_BUG_FRAME select HAS_DEVICE_TREE + select HAS_PMAP config RISCV_64 def_bool yxen/arch/riscv/include/asm/page.h +2
-0@@ -51,6 +51,8 @@ typedef struct {#endif } pte_t; +pte_t mfn_to_xen_entry (mfn_t mfn,unsigned int attr); +static inline pte_t paddr_to_pte (paddr_t paddr,unsigned int permissions) {xen/arch/riscv/include/asm/pmap.h new file +28
-0@@ -0,0 +1,28 @@ +#ifndef __ASM_PMAP_H__ +#define __ASM_PMAP_H__ + +#include <xen/bug.h> +#include <xen/mm.h> + +#include <asm/fixmap.h> + +static inline void arch_pmap_map (unsigned int slot,mfn_t mfn) +{ +pte_t *entry = &xen_fixmap[slot]; +pte_t pte; + +ASSERT (!pte_is_valid (*entry)); + + pte =mfn_to_xen_entry (mfn,PAGE_HYPERVISOR_RW ); + pte.pte |=PTE_LEAF_DEFAULT ; +write_pte (entry, pte); +} + +static inline void arch_pmap_unmap (unsigned int slot) +{ +pte_t pte = {}; + +write_pte (&xen_fixmap[slot], pte); +} + +#endif /* __ASM_PMAP_H__ */ xen/arch/riscv/mm.c +1
-0@@ -370,3 +370,17 @@ int map_pages_to_xen(unsigned long virt,BUG_ON ("unimplemented" );return -1 ; } +
xen/arch/riscv/mm.c int map_pages_to_xen(unsigned long virt, · line 383
Quoted 10 lines
xen/arch/riscv/mm.c +10
-0+static inline pte_t mfn_to_pte (mfn_t mfn) +{ +unsigned long pte =mfn_x (mfn) <<PTE_PPN_SHIFT ; +return (pte_t ){ .pte = pte}; +} + +inline pte_t mfn_to_xen_entry (mfn_t mfn,unsigned int attr) +{ +/* there is no attr field in RISC-V's pte */ + (void ) attr;
Surely you have a way to say indicate whether an entry is readable/writable?
xen/arch/riscv/mm.c int map_pages_to_xen(unsigned long virt, · line 386
Quoted 3 lines
xen/arch/riscv/mm.c +3
-0+ +return mfn_to_pte (mfn); +}
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Quoted 7 lines · Julien Grall
xen/arch/riscv/mm.c int map_pages_to_xen(unsigned long virt, · line 383
Quoted 4 lines · Oleksii Kurochko
xen/arch/riscv/mm.c +4
-0+inline pte_t mfn_to_xen_entry (mfn_t mfn,unsigned int attr) +{ +/* there is no attr field in RISC-V's pte */ + (void ) attr;Surely you have a way to say indicate whether an entry is readable/writable?
I'm puzzled by this question. The sole outlier in Arm code is pmap.h, in passing PAGE_HYPERVISOR_RW to this function when all others pass memory types (MT_*). Afaics only the low three bits are then used in the function, discarding access control bits altogether. R/W access appears to be implied.
Jan
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Quoted 9 lines · Jan Beulich
Quoted 7 lines · Julien Grall
xen/arch/riscv/mm.c int map_pages_to_xen(unsigned long virt, · line 383
Quoted 4 lines · Oleksii Kurochko
xen/arch/riscv/mm.c +4
-0+inline pte_t mfn_to_xen_entry (mfn_t mfn,unsigned int attr) +{ +/* there is no attr field in RISC-V's pte */ + (void ) attr;Surely you have a way to say indicate whether an entry is readable/writable?
Quoted 5 lines
I'm puzzled by this question. The sole outlier in Arm code is
pmap.h, in passingPAGE_HYPERVISOR_RWto this function when all others pass memory types (MT_*). > Afaics only the low three bits are then used in the function, discarding access control bits altogether. R/W access appears to be implied.
Arm is not exempt of odd interfaces. However, from just this patch, it is not clear why RISC-V would continue to use the same appropach if the attributes doesn't exist.
Looking at the rest of the series, it seems to be because we wanted to have a generic page-table code. If there are a desire to continue towards this direction, then I would assume we would need a arch specific way to set the read/write bit.
At which point it makes a lot more sense to push setting the access bits in mfn_to_xen_entry().
Even if we don't do any code consolidation, I think it is odd for Arm that a caller will assume mfn_to_xen_entry() will always return a read-writable page and update as necessary. It would be nicer to push this decision to mfn_to_xen_entry().
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
In reply to Julien GrallHi Julien,
Quoted 98 lines · Julien Grall
Hi Oleksii,
Quoted 95 lines · Oleksii Kurochko
Introduces arch_pmap_{un}map functions and select
HAS_PMAPforCONFIG_RISCV.Additionaly it was necessary to introduce functions:
-mfn_to_xen_entry
-mfn_to_pteSigned-off-by Oleksii Kurochko <[email protected]>---
Changes in V2:
- newly introduced patch
---
xen/arch/riscv/Kconfig | 1 +xen/arch/riscv/include/asm/page.h| 2 ++xen/arch/riscv/include/asm/pmap.h| 28
++++++++++++++++++++++++++++
xen/arch/riscv/mm.c | 14 ++++++++++++++4 files changed, 45 insertions(+)create mode 100644
xen/arch/riscv/include/asm/pmap.hxen/arch/riscv/Kconfig +0
-0@@ -3,6 +3,7 @@ config RISCVselect
FUNCTION_ALIGNMENT_16B
selectGENERIC_BUG_FRAME
selectHAS_DEVICE_TREExen/arch/riscv/Kconfig +1
-0+ select HAS_PMAP
configRISCV_64
def_boolyxen/arch/riscv/include/asm/page.h +0
-0@@ -51,6 +51,8 @@ typedef struct { #endif } pte_t;xen/arch/riscv/include/asm/page.h +2
-0+pte_t mfn_to_xen_entry (mfn_t mfn,unsigned int attr); +static inline
pte_tpaddr_to_pte(paddr_t paddr, unsigned int permissions){xen/arch/riscv/include/asm/pmap.h new file +28
-0@@ -0,0 +1,28 @@ +#ifndef __ASM_PMAP_H__ +#define __ASM_PMAP_H__ + +#include <xen/bug.h> +#include <xen/mm.h> + +#include <asm/fixmap.h> + +static inline void arch_pmap_map (unsigned int slot,mfn_t mfn) +{ + pte_t *entry = &xen_fixmap[slot]; + pte_t pte; + + ASSERT(!pte_is_valid(*entry)); + + pte = mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW); + pte.pte |= PTE_LEAF_DEFAULT; + write_pte(entry, pte); +} + +static inline void arch_pmap_unmap (unsigned int slot) +{ + pte_t pte = {}; + + write_pte(&xen_fixmap[slot], pte); +} + +#endif /* __ASM_PMAP_H__ */ xen/arch/riscv/mm.c +6
-0@@ -370,3 +370,17 @@ int map_pages_to_xen(unsigned long virt, BUG_ON("unimplemented"); return -1; } + +static inline pte_t mfn_to_pte (mfn_t mfn) +{ + unsigned long pte = mfn_x(mfn) << PTE_PPN_SHIFT; + return (pte_t){ .pte = pte}; +}
Quoted 8 lines
xen/arch/riscv/mm.c int map_pages_to_xen(unsigned long virt, · line 383
Quoted 5 lines
xen/arch/riscv/mm.c +5
-0+ +inline pte_t mfn_to_xen_entry (mfn_t mfn,unsigned int attr) +{ + /* there is no attr field in RISC-V's pte */ + (void) attr;Surely you have a way to say indicate whether an entry is readable/writable?
Sure, there is a way. But probably I misinterpreted attr for Arm and decided not to use them here. By that I mean, that Arm has MT_NORMAL, MT_DEVICE which RISC-V doesn't have.
If it is about readable/writable then for sure, I will start to use attr.
~ Oleksii
Quoted 7 lines
xen/arch/riscv/mm.c int map_pages_to_xen(unsigned long virt, · line 386
Quoted 4 lines
xen/arch/riscv/mm.c +3
-0+ + return mfn_to_pte(mfn); +}Cheers,
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
In reply to Oleksii KurochkoQuoted 19 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/pmap.h new file +16
-0@@ -0,0 +1,28 @@ +#ifndef __ASM_PMAP_H__ +#define __ASM_PMAP_H__ + +#include <xen/bug.h> +#include <xen/mm.h> + +#include <asm/fixmap.h> + +static inline void arch_pmap_map (unsigned int slot,mfn_t mfn) +{ +pte_t *entry = &xen_fixmap[slot]; +pte_t pte; + +ASSERT (!pte_is_valid (*entry)); + + pte =mfn_to_xen_entry (mfn,PAGE_HYPERVISOR_RW );
xen/arch/riscv/include/asm/pmap.h line 26
Quoted 10 lines
xen/arch/riscv/include/asm/pmap.h new file +10
-0+ pte.pte |=PTE_LEAF_DEFAULT ; +write_pte (entry, pte); +} + +static inline void arch_pmap_unmap (unsigned int slot) +{ +pte_t pte = {}; + +write_pte (&xen_fixmap[slot], pte); +}
Why are these not using set_fixmap() / clear_fixmap() respectively?
xen/arch/riscv/mm.c int map_pages_to_xen(unsigned long virt, · line 374
Quoted 8 lines
xen/arch/riscv/mm.c +2
-0@@ -370,3 +370,17 @@ int map_pages_to_xen(unsigned long virt,BUG_ON ("unimplemented" );return -1 ; } + +static inline pte_t mfn_to_pte (mfn_t mfn)
This name suggests (to me) that you're getting _the_ (single) PTE for a given MFN. However, what the function is doing is make a PTE using the given MFN. On x86 at least the common way to name such a function would be pte_from_mfn().
xen/arch/riscv/mm.c int map_pages_to_xen(unsigned long virt, · line 377
Quoted 3 lines
xen/arch/riscv/mm.c +3
-0+{ +unsigned long pte =mfn_x (mfn) <<PTE_PPN_SHIFT ; +return (pte_t ){ .pte = pte};
Nit: Blank missing.
Jan
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Quoted 24 lines · Jan Beulich
Quoted 23 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/pmap.h new file +20
-0@@ -0,0 +1,28 @@ +#ifndef __ASM_PMAP_H__ +#define __ASM_PMAP_H__ + +#include <xen/bug.h> +#include <xen/mm.h> + +#include <asm/fixmap.h> + +static inline void arch_pmap_map (unsigned int slot,mfn_t mfn) +{ + pte_t *entry = &xen_fixmap[slot]; + pte_t pte; + + ASSERT(!pte_is_valid(*entry)); + + pte = mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW); + pte.pte |= PTE_LEAF_DEFAULT; + write_pte(entry, pte); +} +
Quoted 8 lines
xen/arch/riscv/include/asm/pmap.h line 26
Quoted 6 lines
xen/arch/riscv/include/asm/pmap.h new file +6
-0+static inline void arch_pmap_unmap (unsigned int slot) +{ + pte_t pte = {}; + + write_pte(&xen_fixmap[slot], pte); +}Why are these not using
set_fixmap()/clear_fixmap()respectively?
They haven't been introduced yet. And I thought that these fucntion are used only in pmap_{un}map() and that is the reason why I decided to not introduce them. But while writing the answer on another comment, I found other places where set_fixmap() / clear_fixmap() are used, so I will introduce them and reuse here.
Quoted 14 lines
xen/arch/riscv/mm.c int map_pages_to_xen(unsigned long virt, · line 374
Quoted 9 lines
xen/arch/riscv/mm.c +2
-0@@ -370,3 +370,17 @@ int map_pages_to_xen(unsigned long virt, BUG_ON("unimplemented"); return -1; } + +static inline pte_t mfn_to_pte (mfn_t mfn)This name suggests (to me) that you're getting _the_ (single) PTE for a given MFN. However, what the function is doing is make a PTE using the given MFN. On x86 at least the common way to name such a function would be
pte_from_mfn().
If it is a common way then I will rename it. Thanks.
~ Oleksii
Quoted 8 lines
xen/arch/riscv/mm.c int map_pages_to_xen(unsigned long virt, · line 377
Quoted 4 lines
xen/arch/riscv/mm.c +3
-0+{ + unsigned long pte = mfn_x(mfn) << PTE_PPN_SHIFT; + return (pte_t){ .pte = pte};Nit: Blank missing.
Jan
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Hi,
Quoted 33 lines · Oleksii Kurochko
Quoted 24 lines · Jan Beulich
Quoted 23 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/pmap.h new file +20
-0@@ -0,0 +1,28 @@ +#ifndef __ASM_PMAP_H__ +#define __ASM_PMAP_H__ + +#include <xen/bug.h> +#include <xen/mm.h> + +#include <asm/fixmap.h> + +static inline void arch_pmap_map (unsigned int slot,mfn_t mfn) +{ + pte_t *entry = &xen_fixmap[slot]; + pte_t pte; + + ASSERT(!pte_is_valid(*entry)); + + pte = mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW); + pte.pte |= PTE_LEAF_DEFAULT; + write_pte(entry, pte); +} +Quoted 8 lines
xen/arch/riscv/include/asm/pmap.h line 26
Quoted 6 lines
xen/arch/riscv/include/asm/pmap.h new file +6
-0+static inline void arch_pmap_unmap (unsigned int slot) +{ + pte_t pte = {}; + + write_pte(&xen_fixmap[slot], pte); +}Why are these not using
set_fixmap()/clear_fixmap()respectively?
Quoted 5 lines
They haven't been introduced yet. And I thought that these fucntion are used only in pmap_{un}map() and that is the reason why I decided to not introduce them. But while writing the answer on another comment, I found other places where
set_fixmap()/clear_fixmap()are used, so I will introduce them and reuse here.
I am guessing you are going to implement set_fixmap()/clear_fixmap() using map_pages_to_xen(). If so, for early boot you are going to end up in a circular loop because map_pages_to_xen() will likely use pmap() which will call set_fixmap().
There is a big comment in common/pmap.c which explain why arch_pmap_* was introduced rather than calling *_fixmap() directly:
/*
* We cannot use set_fixmap() here. We use PMAP when the domain map
* page infrastructure is not yet initialized, somap_pages_to_xen() called
* by set_fixmap() needs to map pages on demand, which then callspmap()
* again, resulting in a loop. Modify the PTEs directly instead.
The same
* is true for pmap_unmap().
*/
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Quoted 46 lines · Julien Grall
Hi,
Quoted 34 lines · Oleksii Kurochko
Quoted 25 lines · Jan Beulich
Quoted 24 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/pmap.h new file +21
-0@@ -0,0 +1,28 @@ +#ifndef __ASM_PMAP_H__ +#define __ASM_PMAP_H__ + +#include <xen/bug.h> +#include <xen/mm.h> + +#include <asm/fixmap.h> + +static inline void arch_pmap_map (unsigned int slot,mfn_t mfn) +{ + pte_t *entry = &xen_fixmap[slot]; + pte_t pte; + + ASSERT(!pte_is_valid(*entry)); + + pte = mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW); + pte.pte |= PTE_LEAF_DEFAULT; + write_pte(entry, pte); +} + +static inline void arch_pmap_unmap (unsigned int slot)Quoted 8 lines
xen/arch/riscv/include/asm/pmap.h line 26
Quoted 5 lines
xen/arch/riscv/include/asm/pmap.h new file +5
-0+{ + pte_t pte = {}; + + write_pte(&xen_fixmap[slot], pte); +}Why are these not using
set_fixmap()/clear_fixmap()respectively?Quoted 8 lines
They haven't been introduced yet. And I thought that these fucntion are
used only in pmap_{un}map() and that is the reason why I decided to not
introduce them. But while writing the answer on another comment, I found other places whereset_fixmap()/clear_fixmap()are used, so I
will introduce them and reuse here.
Quoted 5 lines
I am guessing you are going to implement set_fixmap()/clear_fixmap() using
map_pages_to_xen(). If so, for early boot you are going to end up
in a circular loop becausemap_pages_to_xen()will likely usepmap()which will callset_fixmap().
I am going to implement that in the following way as I faced the described by you issue when I first time tried to implement it using map_pages_to_xen():
/* Map a 4k page in a fixmap entry */
void set_fixmap(unsigned map, mfn_t mfn, unsigned int flags)
{
pte_t pte;
pte = mfn_to_xen_entry(mfn, flags);
pte.pte |= PTE_LEAF_DEFAULT;
write_pte(&xen_fixmap[pt_index(0, FIXMAP_ADDR(map))], pte);}
/* Remove a mapping from a fixmap entry */
void clear_fixmap(unsigned map)
{
pte_t pte = {0};
write_pte(&xen_fixmap[pt_index(0, FIXMAP_ADDR(map))], pte);
}~ Oleksii
Quoted 19 lines
There is a big comment in
common/pmap.cwhich explain why arch_pmap_* was introduced rather than calling*_fixmap()directly:/*
* We cannot useset_fixmap()here. We use PMAP when the domain map
* page infrastructure is not yet initialized, somap_pages_to_xen()called
* byset_fixmap()needs to map pages on demand, which then callspmap()
* again, resulting in a loop. Modify the PTEs directly instead. The same
* is true forpmap_unmap().
*/Cheers,
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Hi,
Quoted 47 lines · Oleksii Kurochko
Quoted 46 lines · Julien Grall
Hi,
Quoted 42 lines · Oleksii Kurochko
Quoted 25 lines · Jan Beulich
Quoted 24 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/pmap.h new file +21
-0@@ -0,0 +1,28 @@ +#ifndef __ASM_PMAP_H__ +#define __ASM_PMAP_H__ + +#include <xen/bug.h> +#include <xen/mm.h> + +#include <asm/fixmap.h> + +static inline void arch_pmap_map (unsigned int slot,mfn_t mfn) +{ + pte_t *entry = &xen_fixmap[slot]; + pte_t pte; + + ASSERT(!pte_is_valid(*entry)); + + pte = mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW); + pte.pte |= PTE_LEAF_DEFAULT; + write_pte(entry, pte); +} + +static inline void arch_pmap_unmap (unsigned int slot)Quoted 8 lines
xen/arch/riscv/include/asm/pmap.h line 26
Quoted 5 lines
xen/arch/riscv/include/asm/pmap.h new file +5
-0+{ + pte_t pte = {}; + + write_pte(&xen_fixmap[slot], pte); +}Why are these not using
set_fixmap()/clear_fixmap()respectively?They haven't been introduced yet. And I thought that these fucntion are
used only in pmap_{un}map() and that is the reason why I decided to not
introduce them. But while writing the answer on another comment, I found other places whereset_fixmap()/clear_fixmap()are used, so I
will introduce them and reuse here.
Quoted 8 lines
Quoted 5 lines
I am guessing you are going to implement set_fixmap()/clear_fixmap() using
map_pages_to_xen(). If so, for early boot you are going to end up
in a circular loop becausemap_pages_to_xen()will likely usepmap()which will callset_fixmap().I am going to implement that in the following way as I faced the described by you issue when I first time tried to implement it using
map_pages_to_xen():
What's wrong with keeping the arch_pmap_*() as-is and call map_pages_to_xen() in the fixmap?
At least this would be consistent with what other architectures does and less risky (see below).
Quoted 8 lines
/* Map a 4k page in a fixmap entry */
void set_fixmap(unsigned map, mfn_t mfn, unsigned int flags)
{
pte_t pte;
pte = mfn_to_xen_entry(mfn, flags);
pte.pte |= PTE_LEAF_DEFAULT;
write_pte(&xen_fixmap[pt_index(0, FIXMAP_ADDR(map))], pte);It would be saner to check if you are not overwriting any existing mapping as otherwise you will probably need a TLB flush.
Quoted 7 lines
}
/* Remove a mapping from a fixmap entry */
void clear_fixmap(unsigned map)
{
pte_t pte = {0};
write_pte(&xen_fixmap[pt_index(0, FIXMAP_ADDR(map))], pte);Don't you need a TLB flush?
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Hi Julien,
Quoted 51 lines · Julien Grall
Hi,
Quoted 49 lines
Quoted 49 lines · Oleksii Kurochko
Quoted 34 lines · Jan Beulich
Quoted 25 lines · Oleksii Kurochko
Quoted 24 lines
xen/arch/riscv/include/asm/pmap.h new file +21
-0@@ -0,0 +1,28 @@ +#ifndef __ASM_PMAP_H__ +#define __ASM_PMAP_H__ + +#include <xen/bug.h> +#include <xen/mm.h> + +#include <asm/fixmap.h> + +static inline void arch_pmap_map (unsigned int slot,mfn_t mfn) +{ +pte_t *entry = &xen_fixmap[slot]; +pte_t pte; + +ASSERT (!pte_is_valid (*entry)); + + pte =mfn_to_xen_entry (mfn,PAGE_HYPERVISOR_RW ); + pte.pte |=PTE_LEAF_DEFAULT ; +write_pte (entry, pte); +} + +static inline void arch_pmap_unmap (unsigned int slot)Quoted 8 lines
xen/arch/riscv/include/asm/pmap.h line 26
Quoted 5 lines
xen/arch/riscv/include/asm/pmap.h new file +5
-0+{ +pte_t pte = {}; + +write_pte (&xen_fixmap[slot], pte); +}Why are these not using
set_fixmap()/clear_fixmap()respectively?Quoted 8 lines
They haven't been introduced yet. And I thought that these fucntion are
used only in pmap_{un}map() and that is the reason why I decided to not
introduce them. But while writing the answer on another comment, I found other places whereset_fixmap()/clear_fixmap()are used, so I
will introduce them and reuse here.I am guessing you are going to implement set_fixmap()/clear_fixmap() using
map_pages_to_xen(). If so, for early boot you are going to end up
in a circular loop becausemap_pages_to_xen()will likely usepmap()which will callset_fixmap().
Quoted 9 lines
Quoted 3 lines
I am going to implement that in the following way as I faced the described by you issue when I first time tried to implement it using
map_pages_to_xen():What's wrong with keeping the arch_pmap_*() as-is and call
map_pages_to_xen()in the fixmap?At least this would be consistent with what other architectures does and less risky (see below).
Then I misunderstood you, if not to use {set/clear}_fixmap() in arch_pmap() then everything should be fine.
Then I think it is needed to add the comment also above arch_pmap_*() function why it isn't used {set/clear}_fixmap()
inside. ( or update the commit message )
Quoted 15 lines
Quoted 9 lines
/* Map a 4k page in a fixmap entry */ void set_fixmap(unsigned map, mfn_t mfn, unsigned int flags) { pte_t pte; pte = mfn_to_xen_entry(mfn, flags); pte.pte |= PTE_LEAF_DEFAULT; write_pte(&xen_fixmap[pt_index(0, FIXMAP_ADDR(map))], pte);It would be saner to check if you are not overwriting any existing mapping as otherwise you will probably need a TLB flush.
Quoted 2 lines
}
Quoted 8 lines
Quoted 5 lines
/* Remove a mapping from a fixmap entry */ void clear_fixmap(unsigned map) { pte_t pte = {0}; write_pte(&xen_fixmap[pt_index(0, FIXMAP_ADDR(map))], pte);Don't you need a TLB flush?
Inside write_pte() there is "sfence.vma".
But probably it would be better to add flush_xen_tlb_range_va_local() or something similar here in case if someone will decide to update write_pte().
~ Oleksii
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Quoted 22 lines · Oleksii Kurochko
Quoted 21 lines · Julien Grall
Quoted 9 lines
Quoted 1 line · Oleksii Kurochko
/* Map a 4k page in a fixmap entry */ void set_fixmap(unsigned map, mfn_t mfn, unsigned int flags) { pte_t pte; pte = mfn_to_xen_entry(mfn, flags); pte.pte |= PTE_LEAF_DEFAULT; write_pte(&xen_fixmap[pt_index(0, FIXMAP_ADDR(map))], pte);It would be saner to check if you are not overwriting any existing mapping as otherwise you will probably need a TLB flush.
Quoted 7 lines
} /* Remove a mapping from a fixmap entry */ void clear_fixmap(unsigned map) { pte_t pte = {0}; write_pte(&xen_fixmap[pt_index(0, FIXMAP_ADDR(map))], pte);
Quoted 3 lines
Quoted 2 lines
Don't you need a TLB flush?
Inside
write_pte()there is "sfence.vma".
That's just a fence though, not a TLB flush.
Jan
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Quoted 28 lines · Jan Beulich
Quoted 27 lines · Oleksii Kurochko
Quoted 25 lines · Julien Grall
Quoted 11 lines
Quoted 1 line · Oleksii Kurochko
/* Map a 4k page in a fixmap entry */
voidset_fixmap(unsigned map, mfn_t mfn, unsigned int flags)
{
pte_tpte;pte =
mfn_to_xen_entry(mfn, flags);
pte.pte |=PTE_LEAF_DEFAULT;write_pte(&xen_fixmap[pt_index(0, FIXMAP_ADDR(map))], pte);It would be saner to check if you are not overwriting any existing
mapping as otherwise you will probably need a TLB flush.Quoted 8 lines
}
/* Remove a mapping from a fixmap entry */
voidclear_fixmap(unsigned map)
{
pte_tpte = {0};write_pte(&xen_fixmap[pt_index(0, FIXMAP_ADDR(map))], pte);
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Don't you need a TLB flush?
Inside
write_pte()there is "sfence.vma".That's just a fence though, not a TLB flush.
From the privileged doc:
``` SFENCE.VMA is also used to invalidate entries in the address-translation cache associated with a hart (see Section 4.3.2). ... The SFENCE.VMA is used to flush any local hardware caches related to address translation. It is specified as a fence rather than a TLB flush to provide cleaner semantics with respect to which instructions are affected by the flush operation and to support a wider variety of dynamic caching structures and memory-management schemes. SFENCE.VMA is also used by higher privilege levels to synchronize page table writes and the address translation hardware. ... ```
I read this as SFENCE.VMA is used not only for ordering of load/stores, but also to flush TLB ( which is a type of more general term as address-translation cache, IIUIC ).
Also, Linux kernel uses sfence.vma to flush TLB:
https://elixir.bootlin.com/linux/v6.0/source/arch/riscv/include/asm/tlbflush.h#L23
~ Oleksii
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Quoted 51 lines · On 23.07.2024 10:55, [email protected] wrote:
Quoted 28 lines · Jan Beulich
Quoted 27 lines · Oleksii Kurochko
Quoted 25 lines · Julien Grall
Quoted 11 lines
Quoted 1 line · Oleksii Kurochko
/* Map a 4k page in a fixmap entry */
voidset_fixmap(unsigned map, mfn_t mfn, unsigned int flags)
{
pte_tpte;pte =
mfn_to_xen_entry(mfn, flags);
pte.pte |=PTE_LEAF_DEFAULT;write_pte(&xen_fixmap[pt_index(0, FIXMAP_ADDR(map))], pte);It would be saner to check if you are not overwriting any existing
mapping as otherwise you will probably need a TLB flush.Quoted 8 lines
}
/* Remove a mapping from a fixmap entry */
voidclear_fixmap(unsigned map)
{
pte_tpte = {0};write_pte(&xen_fixmap[pt_index(0, FIXMAP_ADDR(map))], pte);Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Don't you need a TLB flush?
Inside
write_pte()there is "sfence.vma".That's just a fence though, not a TLB flush.
From the privileged doc:
``` SFENCE.VMA is also used to invalidate entries in the address-translation cache associated with a hart (see Section 4.3.2). ... The SFENCE.VMA is used to flush any local hardware caches related to address translation. It is specified as a fence rather than a TLB flush to provide cleaner semantics with respect to which instructions are affected by the flush operation and to support a wider variety of dynamic caching structures and memory-management schemes. SFENCE.VMA is also used by higher privilege levels to synchronize page table writes and the address translation hardware. ... ```
Quoted 3 lines
I read this as SFENCE.VMA is used not only for ordering of load/stores, but also to flush TLB ( which is a type of more general term as address-translation cache, IIUIC ).
Oh, I see. Kind of unexpected for an instruction of that name. Yet note how they talk about the local hart only. You need a wider scope TLB flush here.
Jan
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Quoted 65 lines · Jan Beulich
Quoted 59 lines · On 23.07.2024 10:55, [email protected] wrote:
Quoted 30 lines · Jan Beulich
Quoted 29 lines · Oleksii Kurochko
Quoted 27 lines · Julien Grall
Quoted 7 lines
Quoted 1 line · Oleksii Kurochko
/* Map a 4k page in a fixmap entry */
voidset_fixmap(unsigned map, mfn_t mfn, unsigned int flags)
{
pte_tpte;Quoted 5 lines
pte =
mfn_to_xen_entry(mfn, flags);
pte.pte |=PTE_LEAF_DEFAULT;
write_pte(&xen_fixmap[pt_index(0,FIXMAP_ADDR(map))],
pte);It would be saner to check if you are not overwriting any existing
mapping as otherwise you will probably need a TLB flush.Quoted 9 lines
}
/* Remove a mapping from a fixmap entry */
voidclear_fixmap(unsigned map)
{
pte_tpte = {0};
write_pte(&xen_fixmap[pt_index(0,FIXMAP_ADDR(map))],
pte);Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Don't you need a TLB flush?
Inside
write_pte()there is "sfence.vma".That's just a fence though, not a TLB flush.
From the privileged doc:
``` SFENCE.VMA is also used to invalidate entries in the address-translation cache associated with a hart (see Section 4.3.2). ... The SFENCE.VMA is used to flush any local hardware caches related to address translation. It is specified as a fence rather than a TLB flush to provide cleaner semantics with respect to which instructions are affected by the flush operation and to support a wider variety of dynamic caching structures and memory-management schemes. SFENCE.VMA is also used by higher privilege levels to synchronize page table writes and the address translation hardware. ... ```Quoted 4 lines
I read this as SFENCE.VMA is used not only for ordering of load/stores,
but also to flush TLB ( which is a type of more general term as address-translation cache, IIUIC ).
Quoted 4 lines
Oh, I see. Kind of unexpected for an instruction of that name. Yet note
how they talk about the local hart only. You need a wider scope TLB flush here.
Could you please clarify why it is needed wider?
Arm Xen flushed only local TLB.
RISC-V Linux kernel for fixmap also uses: local_flush_tlb_page().
~ Oleksii
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Hi Oleksii,
Quoted 57 lines · On 23/07/2024 16:36, [email protected] wrote:
Quoted 56 lines · Jan Beulich
Quoted 55 lines · On 23.07.2024 10:55, [email protected] wrote:
Quoted 30 lines · Jan Beulich
Quoted 29 lines · Oleksii Kurochko
Quoted 27 lines · Julien Grall
Quoted 7 lines
Quoted 1 line · Oleksii Kurochko
/* Map a 4k page in a fixmap entry */
void set_fixmap(unsigned map,mfn_tmfn, unsigned int
flags)
{
pte_tpte;Quoted 5 lines
pte =
mfn_to_xen_entry(mfn, flags);
pte.pte |=PTE_LEAF_DEFAULT;
write_pte(&xen_fixmap[pt_index(0,FIXMAP_ADDR(map))],
pte);It would be saner to check if you are not overwriting any existing
mapping as otherwise you will probably need a TLB flush.Quoted 9 lines
}
/* Remove a mapping from a fixmap entry */
voidclear_fixmap(unsigned map)
{
pte_tpte = {0};
write_pte(&xen_fixmap[pt_index(0,FIXMAP_ADDR(map))],
pte);Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Don't you need a TLB flush?
Inside
write_pte()there is "sfence.vma".That's just a fence though, not a TLB flush.
From the privileged doc:
```
SFENCE.VMA is also used to invalidate entries in the address-translation cache associated with a hart (see Section
4.3.2).
...
The SFENCE.VMA is used to flush any local hardware caches
related to
address translation.
It is specified as a fence rather than a TLB flush to provide
cleaner
semantics with respect to
which instructions are affected by the flush operation and to
support a
wider variety of dynamic
caching structures and memory-management schemes. SFENCE.VMA is
also
used by higher
privilege levels to synchronize page table writes and the
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
address
translation hardware.
...
```
I read this as SFENCE.VMA is used not only for ordering of load/stores,
but also to flush TLB ( which is a type of more general term as address-translation cache, IIUIC ).
I have to admit, I am a little because concerned with calling sfence.vma in write_pte() (this may only be because I am not very familiar with RISC-V).
We have cases where multiple entry will be written in a single map_pages_to_xen() call. So wouldn't this means that the local TLBs would be nuked for every write rather than once?
Quoted 8 lines
Quoted 5 lines
Oh, I see. Kind of unexpected for an instruction of that name. Yet note
how they talk about the local hart only. You need a wider scope TLB flush here.Could you please clarify why it is needed wider?
Arm Xen flushed only local TLB.
Which code are you looking at? set_fixmap() will propagate the TLB flush to all innershareable CPUs.
The PMAP interface will do a local TLB flush because the interface can only be used during early boot where there is a single CPU running.
Quoted 1 line
RISC-V Linux kernel for fixmap also uses:
local_flush_tlb_page().
I don't know how Linux is using set_fixmap(). But what matters is how Xen is using set_fixmap(). We have a couple of places in Xen where the fixmap needs to be accessed by all the CPUs.
Given this is a common interface in Xen, I think it makes sense to follow the same approach to avoid any confusion.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Quoted 74 lines · Julien Grall
Hi Oleksii,
Quoted 63 lines · On 23/07/2024 16:36, [email protected] wrote:
Quoted 62 lines · Jan Beulich
Quoted 61 lines · On 23.07.2024 10:55, [email protected] wrote:
Quoted 32 lines · Jan Beulich
Quoted 31 lines · Oleksii Kurochko
Quoted 28 lines · Julien Grall
Quoted 8 lines
Quoted 1 line · Oleksii Kurochko
/* Map a 4k page in a fixmap entry */ void set_fixmap(unsigned map,
mfn_tmfn, unsigned int
flags)
{
pte_tpte;Quoted 5 lines
pte =
mfn_to_xen_entry(mfn, flags);
pte.pte |=PTE_LEAF_DEFAULT;
write_pte(&xen_fixmap[pt_index(0,FIXMAP_ADDR(map))],
pte);It would be saner to check if you are not overwriting any existing
mapping as otherwise you will probably need a TLB flush.Quoted 9 lines
}
/* Remove a mapping from a fixmap entry */
voidclear_fixmap(unsigned map)
{
pte_tpte = {0};
write_pte(&xen_fixmap[pt_index(0,FIXMAP_ADDR(map))],
pte);Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Don't you need a TLB flush?
Inside
write_pte()there is "sfence.vma".That's just a fence though, not a TLB flush.
From the privileged doc:
```
SFENCE.VMA is also used to invalidate entries in the address-translation cache associated with a hart (see Section
4.3.2).
...
The SFENCE.VMA is used to flush any local hardware caches related to
address translation.
It is specified as a fence rather than a TLB flush to provide
cleaner
semantics with respect to
which instructions are affected by the flush operation and to
support a
wider variety of dynamic
caching structures and memory-management schemes. SFENCE.VMA is
also
used by higher
privilege levels to synchronize page table writes and theQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
address
translation hardware.
...
```
I read this as SFENCE.VMA is used not only for ordering of load/stores,
but also to flush TLB ( which is a type of more general term as address-translation cache, IIUIC ).
Quoted 8 lines
I have to admit, I am a little because concerned with calling sfence.vma
inwrite_pte()(this may only be because I am not very familiar with RISC-V).We have cases where multiple entry will be written in a single
map_pages_to_xen()call. So wouldn't this means that the local TLBs would be nuked for every write rather than once?
Yes, it will be nuked. It is bad from perfomance point of view. I just wanted to be sure that I won't miss to put sfence.vma when it is necessary and then reworked that a little bit after. But it seems it would be better not to call sfence.vma in write_pte() just from the start.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Oh, I see. Kind of unexpected for an instruction of that name. Yet
note
how they talk about the local hart only. You need a wider scope TLB
flush here.
Quoted 7 lines
Quoted 3 lines
Could you please clarify why it is needed wider?
Arm Xen flushed only local TLB.
Which code are you looking at?
set_fixmap()will propagate the TLB flush
to all innershareable CPUs.
Yes, here I agree that set_fixmap() uses map_pages_to_xen which somewhere inside uses flush_xen_tlb_range_va() ( not flush_xen_tlb_range_va() ) so TLB flush will happen for all innershareable CPUs.
Quoted 4 lines
The PMAP interface will do a local TLB flush because the interface can
only be used during early boot where there is a single CPU running.
Yes, I am looking at PMAP:
static inline void arch_pmap_unmap(unsigned int slot)
{
lpae_t pte = {};
write_pte(&xen_fixmap[slot], pte);
flush_xen_tlb_range_va(FIXMAP_ADDR(slot), PAGE_SIZE); }
IIUC, originaly Jan told about arch_pmap_unmap() case so that is why I decided to clarify additionaly.
Quoted 10 lines
Quoted 2 lines
RISC-V Linux kernel for fixmap also uses:
local_flush_tlb_page().I don't know how Linux is using
set_fixmap(). But what matters is how Xen is usingset_fixmap(). We have a couple of places in Xen where the
fixmap needs to be accessed by all the CPUs.Given this is a common interface in Xen, I think it makes sense to follow the same approach to avoid any confusion.
Sure. Thanks for claryfying. I will flush_xen_tlb_range_va() for set_fixmap().
~ Oleksii
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Quoted 122 lines · On Tue, 2024-07-23 at 19:25 +0200, [email protected] wrote:
Quoted 85 lines · Julien Grall
Hi Oleksii,
Quoted 68 lines · On 23/07/2024 16:36, [email protected] wrote:
Quoted 67 lines · Jan Beulich
Quoted 66 lines · On 23.07.2024 10:55, [email protected] wrote:
Quoted 35 lines · Jan Beulich
Quoted 34 lines · Oleksii Kurochko
Quoted 31 lines · Julien Grall
Quoted 9 lines
Quoted 1 line · Oleksii Kurochko
/* Map a 4k page in a fixmap entry */
void set_fixmap(unsigned map,mfn_tmfn,
unsigned
int
flags)
{
pte_tpte;Quoted 5 lines
pte =
mfn_to_xen_entry(mfn, flags);
pte.pte |=PTE_LEAF_DEFAULT;
write_pte(&xen_fixmap[pt_index(0,FIXMAP_ADDR(map))],
pte);It would be saner to check if you are not overwriting any
existing
mapping as otherwise you will probably need a TLB flush.Quoted 9 lines
}
/* Remove a mapping from a fixmap entry */
voidclear_fixmap(unsigned map)
{
pte_tpte = {0};
write_pte(&xen_fixmap[pt_index(0,FIXMAP_ADDR(map))],
pte);Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Don't you need a TLB flush?
Inside
write_pte()there is "sfence.vma".That's just a fence though, not a TLB flush.
From the privileged doc:
```
SFENCE.VMA is also used to invalidate entries in the address-translation cache associated with a hart (see Section
4.3.2).
...
The SFENCE.VMA is used to flush any local hardware caches related to
address translation.
It is specified as a fence rather than a TLB flush to provide
cleaner
semantics with respect to
which instructions are affected by the flush operation and
to
support a
wider variety of dynamic
caching structures and memory-management schemes. SFENCE.VMA is
also
used by higher
privilege levels to synchronize page table writes and the addressQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
translation hardware.
...
```
I read this as SFENCE.VMA is used not only for ordering of load/stores,
but also to flush TLB ( which is a type of more general term as
address-translation cache, IIUIC ).I have to admit, I am a little because concerned with calling sfence.vma
inwrite_pte()(this may only be because I am not very familiar with
RISC-V).Quoted 3 lines
We have cases where multiple entry will be written in a single
map_pages_to_xen()call. So wouldn't this means that the local TLBs would be nuked for every write rather than once?Yes, it will be nuked. It is bad from perfomance point of view. I just wanted to be sure that I won't miss to put sfence.vma when it is
necessary and then reworked that a little bit after. But it seems it would be better not to call sfence.vma inwrite_pte()just from the start.Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Oh, I see. Kind of unexpected for an instruction of that name. Yet
note
how they talk about the local hart only. You need a wider scope TLB
flush here.Quoted 7 lines
Quoted 3 lines
Could you please clarify why it is needed wider?
Arm Xen flushed only local TLB.
Which code are you looking at?
set_fixmap()will propagate the TLB flush
to all innershareable CPUs.Yes, here I agree that
set_fixmap()usesmap_pages_to_xenwhich somewhere inside usesflush_xen_tlb_range_va()( notflush_xen_tlb_range_va()) so TLB flush will happen for all innershareable CPUs.Quoted 4 lines
The PMAP interface will do a local TLB flush because the interface can
only be used during early boot where there is a single CPU running.
Quoted 12 lines
Yes, I am looking at PMAP:
static inline voidarch_pmap_unmap(unsigned int slot){
lpae_tpte = {};
write_pte(&xen_fixmap[slot], pte);
flush_xen_tlb_range_va(FIXMAP_ADDR(slot), PAGE_SIZE); }
IIUC, originaly Jan told aboutarch_pmap_unmap()case so that is why I
decided to clarify additionaly.
Julien,
I have a questation related to Arm's version of arch_pmap_map():
static inline void arch_pmap_map(unsigned int slot, mfn_t mfn)
{
lpae_t *entry = &xen_fixmap[slot];
lpae_t pte; ASSERT(!lpae_is_valid(*entry));
pte = mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW);
pte.pt.table = 1;
write_pte(entry, pte);
/*
* The new entry will be used very soon after arch_pmap_map()
returns.
* So ensure the DSB in write_pte() has completed before
continuing.
*/
isb();}
Is the code above isb() is correct? is it insure the DSB not ISB? And isn't need to do TLB flush here?
~ Oleksii
Quoted 17 lines
Quoted 4 lines
Quoted 3 lines
RISC-V Linux kernel for fixmap also uses:
local_flush_tlb_page().Quoted 8 lines
I don't know how Linux is using
set_fixmap(). But what matters is how
Xen is usingset_fixmap(). We have a couple of places in Xen where the
fixmap needs to be accessed by all the CPUs.Given this is a common interface in Xen, I think it makes sense to follow the same approach to avoid any confusion.
Sure. Thanks for claryfying. I will
flush_xen_tlb_range_va()forset_fixmap().~ Oleksii
Re: [PATCH v2 5/8] xen/riscv: introduce asm/pmap.h header
Quoted 158 lines · On 23/07/2024 18:28, [email protected] wrote:
Quoted 127 lines · On Tue, 2024-07-23 at 19:25 +0200, [email protected] wrote:
Quoted 85 lines · Julien Grall
Hi Oleksii,
Quoted 68 lines · On 23/07/2024 16:36, [email protected] wrote:
Quoted 67 lines · Jan Beulich
Quoted 66 lines · On 23.07.2024 10:55, [email protected] wrote:
Quoted 35 lines · Jan Beulich
Quoted 34 lines · Oleksii Kurochko
Quoted 31 lines · Julien Grall
Quoted 9 lines
Quoted 1 line · Oleksii Kurochko
/* Map a 4k page in a fixmap entry */
void set_fixmap(unsigned map,mfn_tmfn,
unsigned
int
flags)
{
pte_tpte;Quoted 5 lines
pte =
mfn_to_xen_entry(mfn, flags);
pte.pte |=PTE_LEAF_DEFAULT;
write_pte(&xen_fixmap[pt_index(0,FIXMAP_ADDR(map))],
pte);It would be saner to check if you are not overwriting any
existing
mapping as otherwise you will probably need a TLB flush.Quoted 9 lines
}
/* Remove a mapping from a fixmap entry */
voidclear_fixmap(unsigned map)
{
pte_tpte = {0};
write_pte(&xen_fixmap[pt_index(0,FIXMAP_ADDR(map))],
pte);Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Don't you need a TLB flush?
Inside
write_pte()there is "sfence.vma".That's just a fence though, not a TLB flush.
From the privileged doc:
```
SFENCE.VMA is also used to invalidate entries in the address-translation cache associated with a hart (see
Section
4.3.2).
...
The SFENCE.VMA is used to flush any local hardware caches
related to
address translation.
It is specified as a fence rather than a TLB flush to
provide
cleaner
semantics with respect to
which instructions are affected by the flush operation
and
to
support a
wider variety of dynamic
caching structures and memory-management schemes.
SFENCE.VMA is
also
used by higher
privilege levels to synchronize page table writes and the
addressQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
translation hardware.
...
```
I read this as SFENCE.VMA is used not only for ordering of load/stores,
but also to flush TLB ( which is a type of more general term as
address-translation cache, IIUIC ).I have to admit, I am a little because concerned with calling sfence.vma
inwrite_pte()(this may only be because I am not very familiar with
RISC-V).Quoted 3 lines
We have cases where multiple entry will be written in a single
map_pages_to_xen()call. So wouldn't this means that the local TLBs would be nuked for every write rather than once?Yes, it will be nuked. It is bad from perfomance point of view. I just wanted to be sure that I won't miss to put sfence.vma when it is
necessary and then reworked that a little bit after. But it seems it would be better not to call sfence.vma inwrite_pte()just from the start.Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Oh, I see. Kind of unexpected for an instruction of that name. Yet
note
how they talk about the local hart only. You need a wider scope TLB
flush here.Quoted 7 lines
Quoted 3 lines
Could you please clarify why it is needed wider?
Arm Xen flushed only local TLB.
Which code are you looking at?
set_fixmap()will propagate the TLB flush
to all innershareable CPUs.Yes, here I agree that
set_fixmap()usesmap_pages_to_xenwhich somewhere inside usesflush_xen_tlb_range_va()( notflush_xen_tlb_range_va()) so TLB flush will happen for all innershareable CPUs.Quoted 4 lines
The PMAP interface will do a local TLB flush because the interface can
only be used during early boot where there is a single CPU running.Yes, I am looking at PMAP:
static inline voidarch_pmap_unmap(unsigned int slot){
lpae_tpte = {};Quoted 7 lines
write_pte(&xen_fixmap[slot], pte);
flush_xen_tlb_range_va(FIXMAP_ADDR(slot), PAGE_SIZE); }
IIUC, originaly Jan told aboutarch_pmap_unmap()case so that is why I
decided to clarify additionaly.Julien,
I have a questation related to Arm's version ofarch_pmap_map():static inline void arch_pmap_map(unsigned int slot, mfn_t mfn) { lpae_t *entry = &xen_fixmap[slot]; lpae_t pte; ASSERT(!lpae_is_valid(*entry)); pte = mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW); pte.pt.table = 1; write_pte(entry, pte); /* * The new entry will be used very soon after arch_pmap_map() returns. * So ensure the DSB in write_pte() has completed before continuing. */ isb(); }
Quoted 1 line
Is the code above
isb()is correct? is it insure the DSB not ISB?
I guess you mean comment. If so, yes it is correct. write_pte() has a dsb() just after the PTE. This is to guarantee that implicit memory access (instruction fetch or from the Hardware translation table access) will only happen *after* the dsb() has completed.
I am not 100% sure whether the isb() is required for arch_pmap_map(). But I took the safest approach when implementing it.
Quoted 1 line
And isn't need to do TLB flush here?
It is not. On Arm, we have a strict policy that every unmap will be followed by a TLB flush and you can't modify an existing entry (see ASSERT a few lines above). So the TLBs will not contain an entry for mapping.
This policy was mainly dictacted by the Arm Arm because when modifying the output address you need to follow the break-before-make sequence which means you have to transition to an invalid mapping and flush the TLBs before the new entry is added. For simplicity, we decided to just not bother with trying to implement break-before-make for the hypervisor page-tables. But we do for the P2M.
Note that newer revision of the Armv8 spec relaxed the requirement (see FEAT_BBM).
Cheers,
Signature · 1 line
Julien Grall
PATCH v6 1/8 xen/device-tree: Move Arm's setup.c bootinfo functions to common
In reply to Oleksii KurochkoFrom: Shawn Anastasio <[email protected]>
Arm's setup.c contains a collection of functions for parsing memory map and other boot information from a device tree. Since these routines are generally useful on any architecture that supports device tree booting, move them into xen/common/device-tree.
---
Changes in V6:
- update the version of the patch to v6, to show that it is based
on the work done by Shawn in the patch v4.
---
Changes in V5:
- add xen/include/xen/bootfdt.h to MAINTAINERS file.
- drop message "Early device tree parsing and".
- After rebase on top of the current staging the following changes were done:
- init bootinfo variable in <common/device-tree/bootinfo.c> with BOOTINFO_INIT;
- update the code of dt_unreserved_regions():
CONFIG_STATIC_SHM related changes and getting of reserved_mem bootinfo_get_shmem() ??
- update the code of meminfo_overlap_check():
add check ( INVALID_PADDR == bank_start ) to if case.
- update the code of check_reserved_regions_overlap():
CONFIG_STATIC_SHM related changes.
- struct bootinfo was updated ( CONFIG_STATIC_SHM changes )
- add shared_meminfo ( because of CONFIG_STATIC_SHM )
- struct struct membanks was update with __struct group so <xen/kernel> is neeeded to be included in bootfdt.h
- move BOOTINFO_ACPI_INIT, BOOTINFO_SHMEM_INIT, BOOTINFO_INIT to generic bootfdt.h
- bootinfo_get_reserved_mem(), bootinfo_get_mem(), bootinfo_get_acpi(), bootinfo_get_shmem() and bootinfo_get_shmem_extra() were moved to xen/bootfdt.h
- s/arm32/CONFIG_SEPARATE_XENHEAP/
- add inclusion of <xen/macros.h> because there are function in <xen/bootfdt.h> which are using container_of().
---
Changes in v4:
- create new xen/include/bootinfo.h rather than relying on arch's asm/setup.h to provide required definitions for bootinfo.c
- build bootinfo.c as .init.o
- clean up and sort bootinfo.c's #includes
- use CONFIG_SEPARATE_XENHEAP rather than CONFIG_ARM_32 to guard xenheap-specific behavior of populate_boot_allocator
- (MAINTAINERS) include all of common/device-tree rather than just bootinfo.c
--- MAINTAINERS | 2 + xen/arch/arm/include/asm/setup.h | 187 +----------- xen/arch/arm/setup.c | 432 ---------------------------- xen/common/Makefile | 1 + xen/common/device-tree/Makefile | 1 + xen/common/device-tree/bootinfo.c | 459 ++++++++++++++++++++++++++++++ xen/include/xen/bootfdt.h | 196 +++++++++++++ 7 files changed, 660 insertions(+), 618 deletions(-) create mode 100644 xen/common/device-tree/Makefile create mode 100644 xen/common/device-tree/bootinfo.c create mode 100644 xen/include/xen/bootfdt.h
MAINTAINERS +2 -0
@@ -295,9 +295,11 @@ M: Stefano Stabellini <[email protected]> M: Julien Grall <[email protected]> S: Supported F: xen/common/libfdt/ +F: xen/common/device-tree/ F: xen/common/device_tree.c F: xen/common/dt-overlay.c F: xen/include/xen/libfdt/ +F: xen/include/xen/bootfdt.h F: xen/include/xen/device_tree.h F: xen/drivers/passthrough/device_tree.c
xen/arch/arm/include/asm/setup.h +1 -186
215 lines not on this page · raw message
xen/arch/arm/setup.c +0 -432
456 lines not on this page · raw message
xen/common/Makefile +1 -0
@@ -77,6 +77,7 @@ obj-$(CONFIG_UBSAN) += ubsan/ obj-$(CONFIG_NEEDS_LIBELF) += libelf/ obj-$(CONFIG_HAS_DEVICE_TREE) += libfdt/ +obj-$(CONFIG_HAS_DEVICE_TREE) += device-tree/ CONF_FILE := $(if $(patsubst /%,,$(KCONFIG_CONFIG)),$(objtree)/)$(KCONFIG_CONFIG) $(obj)/config.gz: $(CONF_FILE)
xen/common/device-tree/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += bootinfo.init.o
xen/common/device-tree/bootinfo.c new file +459 -0
459 lines not on this page · raw message
xen/include/xen/bootfdt.h new file +196 -0
196 lines not on this page · raw message
Signature · 1 line
2.45.2
Re: [PATCH v6 1/8] xen/device-tree: Move Arm's setup.c bootinfo functions to common
On 12.07.2024 18:22, Oleksii Kurochko wrote:> --- a/xen/common/Makefile
xen/common/Makefile obj-$(CONFIG_UBSAN) += ubsan/ · line 83
Quoted 9 lines
+++ b/xen/common/Makefile
xen/common/Makefile +1
-0@@ -77,6 +77,7 @@ obj-$(CONFIG_UBSAN) += ubsan/ obj-$(CONFIG_NEEDS_LIBELF) += libelf/ obj-$(CONFIG_HAS_DEVICE_TREE) += libfdt/ +obj-$(CONFIG_HAS_DEVICE_TREE) += device-tree/ CONF_FILE := $(if $(patsubst /%,,$(KCONFIG_CONFIG)),$(objtree)/)$(KCONFIG_CONFIG) $(obj)/config.gz: $(CONF_FILE)
I think it would be nice for the bad placement of the two lib*/ entries to not lead to further bad placements. Imo your addition wants to go ahead of the
obj-$(CONFIG_HAS_DEVICE_TREE) += device_tree.o
line. (Eventually I expect common/device_tree.c would then also want to move there, probably at the same time renaming it.)
Jan
Re: [PATCH v6 1/8] xen/device-tree: Move Arm's setup.c bootinfo functions to common
In reply to Oleksii KurochkoHi Oleksii,
In general, the patch looks ok (apart from Jan comments). Just a couple of remarks.
Quoted 62 lines · Oleksii Kurochko
From: Shawn Anastasio <[email protected]>
Arm's
setup.ccontains a collection of functions for parsing memory map and other boot information from a device tree. Since these routines are generally useful on any architecture that supports device tree booting, move them into xen/common/device-tree.Suggested-by Julien Grall <[email protected]>Signed-off-by Shawn Anastasio <[email protected]>Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V6:
- update the version of the patch to v6, to show that it is based
on the work done by Shawn in the patch v4.
---
Changes in V5:
- addxen/include/xen/bootfdt.htoMAINTAINERSfile.
- drop message "Early device tree parsing and".
- After rebase on top of the current staging the following changes were done:
- init bootinfo variable in <common/device-tree/bootinfo.c> withBOOTINFO_INIT;
- update the code ofdt_unreserved_regions():
CONFIG_STATIC_SHMrelated changes and getting ofreserved_membootinfo_get_shmem()??
- update the code ofmeminfo_overlap_check():add check ( INVALID_PADDR == bank_start ) to if case.- update the code of
check_reserved_regions_overlap():
CONFIG_STATIC_SHMrelated changes.
- struct bootinfo was updated (CONFIG_STATIC_SHMchanges )
- addshared_meminfo( because ofCONFIG_STATIC_SHM)
- struct struct membanks was update with__structgroup so <xen/kernel> is neeeded to be included inbootfdt.h
- moveBOOTINFO_ACPI_INIT,BOOTINFO_SHMEM_INIT,BOOTINFO_INITto genericbootfdt.h
-bootinfo_get_reserved_mem(),bootinfo_get_mem(),bootinfo_get_acpi(),bootinfo_get_shmem()andbootinfo_get_shmem_extra()were moved toxen/bootfdt.h
- s/arm32/CONFIG_SEPARATE_XENHEAP/
- add inclusion of <xen/macros.h> because there are function in <xen/bootfdt.h> which are usingcontainer_of().
---
Changes in v4:
- create newxen/include/bootinfo.hrather than relying on arch'sasm/setup.hto provide required definitions forbootinfo.c
- buildbootinfo.cas .init.o
- clean up and sort bootinfo.c's #includes
- useCONFIG_SEPARATE_XENHEAPrather thanCONFIG_ARM_32to guard xenheap-specific behavior ofpopulate_boot_allocator
- (MAINTAINERS) include all of common/device-tree rather than justbootinfo.c--- MAINTAINERS | 2 + xen/arch/arm/include/asm/setup.h | 187 +----------- xen/arch/arm/setup.c | 432 ---------------------------- xen/common/Makefile | 1 + xen/common/device-tree/Makefile | 1 + xen/common/device-tree/bootinfo.c | 459 ++++++++++++++++++++++++++++++ xen/include/xen/bootfdt.h | 196 +++++++++++++ 7 files changed, 660 insertions(+), 618 deletions(-) create mode 100644 xen/common/device-tree/Makefile create mode 100644 xen/common/device-tree/bootinfo.c create mode 100644 xen/include/xen/bootfdt.h
[...]
xen/include/xen/bootfdt.h line 1
Quoted 7 lines
xen/include/xen/bootfdt.h new file +1
-0@@ -0,0 +1,196 @@ +#ifndef __XEN_BOOTFDT_H__
AFAIR, to avoid violating MISRA rule 21.1, we should avoid introducing new macros with double underscore.
xen/include/xen/bootfdt.h line 9
Quoted 8 lines
xen/include/xen/bootfdt.h new file +8
-0+#define __XEN_BOOTFDT_H__ + +#include <xen/types.h> +#include <xen/kernel.h> +#include <xen/macros.h> + +#define MIN_FDT_ALIGN 8 +#define MAX_FDT_SIZE SZ_2M
2M blob limit is Arm64 specific. What will be the limit on RISCV? Shouldn't it be moved to some arch specific file?
~Michal
Re: [PATCH v6 1/8] xen/device-tree: Move Arm's setup.c bootinfo functions to common
Hi Michal,
Quoted 85 lines · Michal Orzel
Hi Oleksii,
In general, the patch looks ok (apart from Jan comments). Just a couple of remarks.
Quoted 76 lines · Oleksii Kurochko
From: Shawn Anastasio <[email protected]>
Arm's
setup.ccontains a collection of functions for parsing memory map
and other boot information from a device tree. Since these routines are
generally useful on any architecture that supports device tree booting,
move them into xen/common/device-tree.Suggested-by Julien Grall <[email protected]>Signed-off-by Shawn Anastasio <[email protected]>Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V6:
- update the version of the patch to v6, to show that it is based on the work done by Shawn in the patch v4.
---
Changes in V5:
- addxen/include/xen/bootfdt.htoMAINTAINERSfile.
- drop message "Early device tree parsing and".
- After rebase on top of the current staging the following changes were done:
- init bootinfo variable in <common/device-tree/bootinfo.c> withBOOTINFO_INIT;
- update the code ofdt_unreserved_regions():
CONFIG_STATIC_SHMrelated changes and getting ofreserved_mem
bootinfo_get_shmem()??
- update the code ofmeminfo_overlap_check():
add check (INVALID_PADDR==bank_start) to if case.
- update the code ofcheck_reserved_regions_overlap():
CONFIG_STATIC_SHMrelated changes.
- struct bootinfo was updated (CONFIG_STATIC_SHMchanges )
- addshared_meminfo( because ofCONFIG_STATIC_SHM)
- struct struct membanks was update with__structgroup so <xen/kernel> is
neeeded to be included inbootfdt.h
- moveBOOTINFO_ACPI_INIT,BOOTINFO_SHMEM_INIT,BOOTINFO_INITto genericbootfdt.h
-bootinfo_get_reserved_mem(),bootinfo_get_mem(),bootinfo_get_acpi(),
bootinfo_get_shmem()andbootinfo_get_shmem_extra()were moved toxen/bootfdt.h
- s/arm32/CONFIG_SEPARATE_XENHEAP/
- add inclusion of <xen/macros.h> because there are function in <xen/bootfdt.h> which
are usingcontainer_of().
---
Changes in v4:
- create newxen/include/bootinfo.hrather than relying on arch'sasm/setup.hto provide required definitions forbootinfo.c
- buildbootinfo.cas .init.o
- clean up and sort bootinfo.c's #includes
- useCONFIG_SEPARATE_XENHEAPrather thanCONFIG_ARM_32to guard xenheap-specific behavior ofpopulate_boot_allocator
- (MAINTAINERS) include all of common/device-tree rather than just
bootinfo.c
---
MAINTAINERS | 2 + xen/arch/arm/include/asm/setup.h | 187 +----------- xen/arch/arm/setup.c | 432 -------------------------- --
xen/common/Makefile | 1 + xen/common/device-tree/Makefile | 1 +xen/common/device-tree/bootinfo.c| 459
++++++++++++++++++++++++++++++
xen/include/xen/bootfdt.h | 196 +++++++++++++7 files changed, 660 insertions(+), 618 deletions(-)create mode 100644 xen/common/device-tree/Makefile create mode 100644
xen/common/device-tree/bootinfo.ccreate mode 100644xen/include/xen/bootfdt.h[...]
Quoted 9 lines
xen/include/xen/bootfdt.h line 1
Quoted 7 lines
xen/include/xen/bootfdt.h new file +1
-0@@ -0,0 +1,196 @@ +#ifndef __XEN_BOOTFDT_H__AFAIR, to avoid violating MISRA rule 21.1, we should avoid introducing new macros with double underscore.
I will update that in the next patch version.
Quoted 11 lines
xen/include/xen/bootfdt.h line 9
Quoted 9 lines
xen/include/xen/bootfdt.h new file +8
-0+#define __XEN_BOOTFDT_H__ + +#include <xen/types.h> +#include <xen/kernel.h> +#include <xen/macros.h> + +#define MIN_FDT_ALIGN 8 +#define MAX_FDT_SIZE SZ_2M2M blob limit is Arm64 specific. What will be the limit on RISCV? Shouldn't it be moved to some arch specific file?
Agree, good point.
I should drop that definition here and make it arch specific. I have to update my patch series where I am introducing BOOTFDT_MAX_SIZE ( or something similar ) in riscv/config.h.
Thanks.
~ Oleksii
PATCH v2 6/8 xen/riscv: introduce generic Xen page table handling
In reply to Oleksii KurochkoAt least, between Arm and RISC-V most of the code related to Xen page table handling are common.
This GENERIC_PT code is based on Arm's arm/mmu/pt.c except some minor changes such as introduction of the following functions:
* get_root_page()
* xen_pt_check_contig()
* set_pte_table_bit()
* sanity_arch_specific_pte_checks()
* get_contig_bit()
* set_pte_permissions()
* flush_xen_tlb_range_va()
It was done because not every functions has the generic pte_flags and it could be a different positions of the PTE bits in a PTE.
---
Changes in V2:
- newly introduced patch
--- xen/common/Kconfig | 5 + xen/common/Makefile | 1 + xen/common/mmu/pt.c | 441 +++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/mm.h | 24 +++ 4 files changed, 471 insertions(+) create mode 100644 xen/common/mmu/pt.c
xen/common/Kconfig +5 -0
@@ -47,6 +47,11 @@ config ARCH_MAP_DOMAIN_PAGE config GENERIC_BUG_FRAME bool +config GENERIC_PT + bool + help + Introduces common function to work with page table when MMU is enabled. + config HAS_ALTERNATIVE bool
xen/common/Makefile +1 -0
@@ -2,6 +2,7 @@ obj-$(CONFIG_ARGO) += argo.o obj-y += bitmap.o obj-bin-$(CONFIG_SELF_TESTS) += bitops.init.o obj-$(CONFIG_GENERIC_BUG_FRAME) += bug.o +obj-$(CONFIG_GENERIC_PT) += mmu/pt.o obj-$(CONFIG_HYPFS_CONFIG) += config_data.o obj-$(CONFIG_CORE_PARKING) += core_parking.o obj-y += cpu.o
xen/common/mmu/pt.c new file +441 -0
441 lines not on this page · raw message
xen/include/xen/mm.h +24 -0
@@ -648,4 +648,28 @@ static inline void put_page_alloc_ref(struct page_info *page) } } +#ifdef CONFIG_GENERIC_PT + +/* is needed because of pte_t. */ +#include <asm/page.h> + +const mfn_t get_root_page (void ); + +unsigned int xen_pt_check_contig (unsigned long vfn,mfn_t mfn, +unsigned int level,unsigned long left, +unsigned int flags); + +void set_pte_table_bit (pte_t *pte,unsigned int tbl_bit_val); + +bool sanity_arch_specific_pte_checks (pte_t entry); + +unsigned int get_contig_bit (pte_t entry); + +void set_pte_permissions (pte_t *pte,unsigned int flags); + +void flush_xen_tlb_range_va (vaddr_t va, +unsigned long size); + +#endif /* CONFIG_GENERIC_PT */ +#endif /* __XEN_MM_H__ */
Signature · 1 line
2.45.2
Re: [PATCH v2 6/8] xen/riscv: introduce generic Xen page table handling
Hi,
Quoted 14 lines · Oleksii Kurochko
At least, between Arm and RISC-V most of the code related to Xen page table handling are common.
This
GENERIC_PTcode is based on Arm'sarm/mmu/pt.cexcept some minor changes such as introduction of the following functions:
*get_root_page()
*xen_pt_check_contig()
*set_pte_table_bit()
*sanity_arch_specific_pte_checks()
*get_contig_bit()
*set_pte_permissions()
*flush_xen_tlb_range_va()
It was done because not every functions has the genericpte_flagsand it could be a different positions of the PTE bits in a PTE.
While I am always in favor of trying to avoid code duplication, I am not sure the page-tables are one that should be.
For instance, you don't have the concept of contiguous page in RISC-V (I see you introduce dummy flags, but IMHO this is a bit of a hack). All the code was also written in a way to avoid temporary conflict mappings. This is to avoid using Break-Before-Make. But on newer hardware this could be relaxed.
I am interested to know what the others thinks.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 6/8] xen/riscv: introduce generic Xen page table handling
Quoted 20 lines · Julien Grall
Hi,
Quoted 14 lines · Oleksii Kurochko
At least, between Arm and RISC-V most of the code related to Xen page table handling are common.
This
GENERIC_PTcode is based on Arm'sarm/mmu/pt.cexcept some minor changes such as introduction of the following functions:
*get_root_page()
*xen_pt_check_contig()
*set_pte_table_bit()
*sanity_arch_specific_pte_checks()
*get_contig_bit()
*set_pte_permissions()
*flush_xen_tlb_range_va()
It was done because not every functions has the genericpte_flagsand it could be a different positions of the PTE bits in a PTE.While I am always in favor of trying to avoid code duplication, I am not sure the page-tables are one that should be.
Quoted 7 lines
For instance, you don't have the concept of contiguous page in RISC-V (I see you introduce dummy flags, but IMHO this is a bit of a hack). All the code was also written in a way to avoid temporary conflict mappings. This is to avoid using Break-Before-Make. But on newer hardware this could be relaxed.
I am interested to know what the others thinks.
I share the concern; I was rather surprised to see the title, but - not having had the time to look at the patch yet - was kind of guessing (hoping) it wasn't really what the title said. Page table handling quite likely wants to remain arch-specific.
Jan
Re: [PATCH v2 6/8] xen/riscv: introduce generic Xen page table handling
In reply to Julien GrallHi Julien,
Quoted 20 lines · Julien Grall
Hi,
Quoted 4 lines · Oleksii Kurochko
At least, between Arm and RISC-V most of the code related to Xen page
table handling are common.Quoted 13 lines
This
GENERIC_PTcode is based on Arm'sarm/mmu/pt.cexcept some minor
changes such as introduction of the following functions:
*get_root_page()
*xen_pt_check_contig()
*set_pte_table_bit()
*sanity_arch_specific_pte_checks()
*get_contig_bit()
*set_pte_permissions()
*flush_xen_tlb_range_va()
It was done because not every functions has the genericpte_flagsand
it could be a different positions of the PTE bits in a PTE.
Quoted 3 lines
While I am always in favor of trying to avoid code duplication, I am not
sure the page-tables are one that should be.
Probably it wasn't the best one abstraction provided. But I think that there are still some function which could be generic:
- xen_{un}map_table()
- map_pages_to_xen
- probably some page table walking?
But I am okay, if not to abstract that, I just wanted to here an opinion if it is a sense to work in this direction or not.
I will then move everything to RISC-V specific folder and clean up some places related to Arm.
~ Oleksii
Quoted 13 lines
For instance, you don't have the concept of contiguous page in RISC-V (I
see you introduce dummy flags, but IMHO this is a bit of a hack). All the code was also written in a way to avoid temporary conflict mappings.
This is to avoid using Break-Before-Make. But on newer hardware this could be relaxed.I am interested to know what the others thinks.
Cheers,
PATCH v2 7/8 xen/riscv: select CONFIG_GENREIC_PT
In reply to Oleksii KurochkoEnable GENERIC_PT functionalities for RISC-V and also introduce some RISC-V specific functions necessary to make the GENERIC_PT code work and compilable.
---
Changes in V2:
- newly introduced patch
--- xen/arch/riscv/Kconfig | 1 + xen/arch/riscv/include/asm/mm.h | 9 ++++ xen/arch/riscv/include/asm/page-bits.h | 45 ++++++++++++++++ xen/arch/riscv/include/asm/page.h | 73 +++++++++++++++++++++++++- xen/arch/riscv/mm.c | 63 +++++++++++++++++++--- 5 files changed, 184 insertions(+), 7 deletions(-)
xen/arch/riscv/Kconfig +1 -0
@@ -2,6 +2,7 @@ config RISCV def_bool y select FUNCTION_ALIGNMENT_16B select GENERIC_BUG_FRAME + select GENERIC_PT select HAS_DEVICE_TREE select HAS_PMAP
xen/arch/riscv/include/asm/mm.h +9 -0
@@ -42,6 +42,8 @@ static inline void *maddr_to_virt(paddr_t ma)#define virt_to_mfn (va) __virt_to_mfn(va)#define mfn_to_virt (mfn) __mfn_to_virt(mfn) +#define pte_get_mfn (pte) maddr_to_mfn(pte_to_paddr(pte)) +struct page_info {/* Each frame can be threaded onto a doubly-linked list. */
@@ -238,6 +240,13 @@ static inline bool arch_mfns_in_directmap(unsigned long mfn, unsigned long nr)#define PFN_ORDER (pg) ((pg)->v.free.order) +/* +* Generic code that works with page tables expects the page table +* levels to be numbered in the order L0 -> L1 -> ...; +* RISC-V uses the opposite enumeration: Lx -> L1 -> L0 +*/ +#define convert_level (level) (HYP_PT_ROOT_LEVEL - level) +extern unsigned char cpu0_boot_stack[];void setup_initial_pagetables (void );
xen/arch/riscv/include/asm/page-bits.h +45 -0
51 lines not on this page · raw message
xen/arch/riscv/include/asm/page.h +72 -1
97 lines not on this page · raw message
xen/arch/riscv/mm.c +57 -6
70 lines not on this page · raw message
Signature · 1 line
2.45.2
PATCH v6 2/8 xen/common: Move Arm's bootfdt.c to common
In reply to Oleksii KurochkoFrom: Shawn Anastasio <[email protected]>
Move Arm's bootfdt.c to xen/common so that it can be used by other device tree architectures like PPC and RISCV.
---
Changes in V6:
- update the version of the patch to v6, to show that it is based on the work done by Shawn in the patch v4.
---
Changes in v5:
- add guard #ifdef CONFIG_STATIC_SHM around inclusion of <asm/static-shmem.h> in common/device-tree/bootfdt.c.
- add stub for process_shm_node() in case CONFIG_STATIC_SHM isn't enabled.
- add guard around #ifdef CONFIG_STATIC_SHM aroud early_print_info_shmem() in early_print_info().
---
Changes in v4:
- move function prototypes to patch 2's xen/include/bootfdt.h
- clean up #includes
--- xen/arch/arm/Makefile | 1 - xen/arch/arm/bootfdt.c | 622 ------------------------------ xen/arch/arm/include/asm/setup.h | 13 - xen/common/device-tree/Makefile | 1 + xen/common/device-tree/bootfdt.c | 635 +++++++++++++++++++++++++++++++ xen/include/xen/bootfdt.h | 14 + 6 files changed, 650 insertions(+), 636 deletions(-) delete mode 100644 xen/arch/arm/bootfdt.c create mode 100644 xen/common/device-tree/bootfdt.c
xen/arch/arm/Makefile +0 -1
@@ -10,7 +10,6 @@ obj-$(CONFIG_TEE) += tee/ obj-$(CONFIG_HAS_VPCI) += vpci.o obj-$(CONFIG_HAS_ALTERNATIVE) += alternative.o -obj-y += bootfdt.init.o obj-y += cpuerrata.o obj-y += cpufeature.o obj-y += decode.o
xen/arch/arm/bootfdt.c deleted +0 -622
622 lines not on this page · raw message
xen/arch/arm/include/asm/setup.h +0 -13
@@ -39,19 +39,6 @@ void fw_unreserved_regions(paddr_t s, paddr_t e,void (*cb)(paddr_t ps,paddr_t pe), unsigned int first); -bool check_reserved_regions_overlap (paddr_t region_start,paddr_t region_size); - -struct bootmodule *add_boot_module (bootmodule_kind kind, -paddr_t start,paddr_t size,bool domU); -struct bootmodule *boot_module_find_by_kind (bootmodule_kind kind); -struct bootmodule *boot_module_find_by_addr_and_kind (bootmodule_kind kind, -paddr_t start); -void add_boot_cmdline (const char *name,const char *cmdline, -bootmodule_kind kind,paddr_t start,bool domU); -struct bootcmdline *boot_cmdline_find_by_kind (bootmodule_kind kind); -struct bootcmdline *boot_cmdline_find_by_name (const char *name); -const char *boot_module_kind_as_string (bootmodule_kind kind); -void init_pdx (void );void setup_mm (void );
xen/common/device-tree/Makefile +1 -0
@@ -1 +1,2 @@ +obj-y += bootfdt.init.o obj-y += bootinfo.init.o
xen/common/device-tree/bootfdt.c new file +635 -0
635 lines not on this page · raw message
xen/include/xen/bootfdt.h +14 -0
@@ -158,6 +158,20 @@ struct bootinfo {extern struct bootinfo bootinfo; +bool check_reserved_regions_overlap (paddr_t region_start, +paddr_t region_size); + +struct bootmodule *add_boot_module (bootmodule_kind kind, +paddr_t start,paddr_t size,bool domU); +struct bootmodule *boot_module_find_by_kind (bootmodule_kind kind); +struct bootmodule *boot_module_find_by_addr_and_kind (bootmodule_kind kind, +paddr_t start); +void add_boot_cmdline (const char *name,const char *cmdline, +bootmodule_kind kind,paddr_t start,bool domU); +struct bootcmdline *boot_cmdline_find_by_kind (bootmodule_kind kind); +struct bootcmdline *boot_cmdline_find_by_name (const char *name); +const char *boot_module_kind_as_string (bootmodule_kind kind); +void populate_boot_allocator (void );size_t boot_fdt_info (const void *fdt,paddr_t paddr);
Signature · 1 line
2.45.2
PATCH v2 8/8 xen/riscv: introduce early_fdt_map()
In reply to Oleksii KurochkoIntroduce function which allows to map FDT to Xen.
Also, initialization of device_tree_flattened happens using early_fdt_map.
---
Changes in V2:
- rework early_fdt_map to use map_pages_to_xen()
- move call early_fdt_map() to C code after MMU is enabled.
--- xen/arch/riscv/include/asm/mm.h | 2 ++ xen/arch/riscv/mm.c | 55 +++++++++++++++++++++++++++++++++ xen/arch/riscv/setup.c | 9 ++++++ 3 files changed, 66 insertions(+)
xen/arch/riscv/include/asm/mm.h +2 -0
@@ -266,4 +266,6 @@ static inline unsigned int arch_get_dma_bitsize(void)void setup_fixmap_mappings (void ); +void *early_fdt_map (paddr_t fdt_paddr); +#endif /* _ASM_RISCV_MM_H */
xen/arch/riscv/mm.c +55 -0
71 lines not on this page · raw message
xen/arch/riscv/setup.c +9 -0
@@ -2,6 +2,7 @@#include <xen/bug.h> #include <xen/compile.h> +#include <xen/device_tree.h> #include <xen/init.h> #include <xen/mm.h>
@@ -48,6 +49,14 @@ void __init noreturn start_xen(unsigned long bootcpu_id,setup_fixmap_mappings (); + device_tree_flattened =early_fdt_map (dtb_addr); +if ( device_tree_flattened ) +panic ("Invalid device tree blob at physical address %#lx.\n" +"The DTB must be 8-byte aligned and must not exceed %lld " +"bytes in size.\n\n" +"Please check your bootloader.\n" , + dtb_addr,BOOT_FDT_VIRT_SIZE ); +printk ("All set up\n" );for ( ;; )
Signature · 1 line
2.45.2
Re: [PATCH v2 8/8] xen/riscv: introduce early_fdt_map()
xen/arch/riscv/include/asm/mm.h static inline unsigned int arch_get_dma_bitsize(void) · line 269
Quoted 7 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/mm.h +1
-0@@ -266,4 +266,6 @@ static inline unsigned int arch_get_dma_bitsize(void)void setup_fixmap_mappings (void ); +void *early_fdt_map (paddr_t fdt_paddr);
Please can you take care to address comments on earlier versions before submitting a new one?
Quoted 17 lines
xen/arch/riscv/include/asm/mm.h +13
-0@@ -435,3 +438,55 @@ inline pte_t mfn_to_xen_entry(mfn_t mfn, unsigned int attr)return mfn_to_pte (mfn); } + +void *__init early_fdt_map (paddr_t fdt_paddr) +{ +/* We are using 2MB superpage for mapping the FDT */ +paddr_t base_paddr = fdt_paddr &XEN_PT_LEVEL_MAP_MASK (1 ); +paddr_t offset; +void *fdt_virt; +uint32_t size; +int rc; + +/* +* Check whether the physical FDT address is set and meets the minimum +* alignment requirement. Since we are relying on MIN_FDT_ALIGN to be at
xen/arch/riscv/include/asm/mm.h inline pte_t mfn_to_xen_entry(mfn_t mfn, unsigned int attr) · line 463
Quoted 10 lines
xen/arch/riscv/include/asm/mm.h +10
-0+* least 8 bytes so that we always access the magic and size fields +* of the FDT header after mapping the first chunk, double check if +* that is indeed the case. +*/ +BUILD_BUG_ON (MIN_FDT_ALIGN <8 ); +if ( !fdt_paddr || fdt_paddr %MIN_FDT_ALIGN ) +return NULL ; + +/* The FDT is mapped using 2MB superpage */ +BUILD_BUG_ON (BOOT_FDT_VIRT_START %SZ_2M );
May I suggest that you use MB(2) instead of SZ_2M (not just here)? I think I had voiced opposition to the introduction of xen/sizes.h about 10 years back, yet sadly it still landed in the tree. I for one think that our KB(), MB(), and GB() constructs are superior, and (I hope) free of Misra issues (unlike SZ_2G).
Quoted 15 lines
xen/arch/riscv/include/asm/mm.h +15
-0+ rc =map_pages_to_xen (BOOT_FDT_VIRT_START ,maddr_to_mfn (base_paddr), +SZ_2M >>PAGE_SHIFT , +PAGE_HYPERVISOR_RO | _PAGE_BLOCK); +if ( rc ) +panic ("Unable to map the device-tree.\n" ); + + offset = fdt_paddr %XEN_PT_LEVEL_SIZE (1 ); + fdt_virt = (void *)BOOT_FDT_VIRT_START + offset; + +if (fdt_magic (fdt_virt) !=FDT_MAGIC ) +return NULL ; + + size =fdt_totalsize (fdt_virt); +if ( size >BOOT_FDT_VIRT_SIZE ) +return NULL ;
xen/arch/riscv/include/asm/mm.h inline pte_t mfn_to_xen_entry(mfn_t mfn, unsigned int attr) · line 488
Quoted 10 lines
xen/arch/riscv/include/asm/mm.h +10
-0+ +if ( (offset + size) >SZ_2M ) + { + rc =map_pages_to_xen (BOOT_FDT_VIRT_START +SZ_2M , +maddr_to_mfn (base_paddr +SZ_2M ), +SZ_2M >>PAGE_SHIFT , +PAGE_HYPERVISOR_RO | _PAGE_BLOCK); +if ( rc ) +panic ("Unable to map the device-tree\n" ); + }
Why this two part mapping? And why are you mapping perhaps much more than "size"?
xen/arch/riscv/include/asm/mm.h void __init noreturn start_xen(unsigned long bootcpu_id, · line 53
Quoted 6 lines
xen/arch/riscv/include/asm/mm.h +2
-0@@ -48,6 +49,14 @@ void __init noreturn start_xen(unsigned long bootcpu_id,setup_fixmap_mappings (); + device_tree_flattened =early_fdt_map (dtb_addr); +if ( device_tree_flattened )
Is this condition perhaps inverted?
Jan
Quoted 9 lines
xen/arch/riscv/include/asm/mm.h +6
-0+panic ("Invalid device tree blob at physical address %#lx.\n" +"The DTB must be 8-byte aligned and must not exceed %lld " +"bytes in size.\n\n" +"Please check your bootloader.\n" , + dtb_addr,BOOT_FDT_VIRT_SIZE ); +printk ("All set up\n" );for ( ;; )
Re: [PATCH v2 8/8] xen/riscv: introduce early_fdt_map()
Quoted 13 lines · Jan Beulich
Quoted 8 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/mm.h +0
-0@@ -266,4 +266,6 @@ static inline unsigned intarch_get_dma_bitsize (void)
voidsetup_fixmap_mappings(void);
+void*early_fdt_map(paddr_t fdt_paddr);Please can you take care to address comments on earlier versions before
submitting a new one?
Sorry, missed that Nit comment where you suggested to switch space/block and *.
Quoted 65 lines
Quoted 25 lines
xen/arch/riscv/include/asm/mm.h +0
-0@@ -435,3 +438,55 @@ inline pte_t mfn_to_xen_entry(mfn_t mfn, unsigned int attr)
returnmfn_to_pte(mfn);
}xen/arch/riscv/include/asm/mm.h +12
-0+ +void *__init early_fdt_map (paddr_t fdt_paddr) +{ + /* We are using 2MB superpage for mapping the FDT */ + paddr_t base_paddr = fdt_paddr & XEN_PT_LEVEL_MAP_MASK(1); + paddr_t offset; + void *fdt_virt; + uint32_t size; + int rc; + + /* +* Check whether the physical FDT address is set and meets the minimum
+ * alignment requirement. Since we are relying onMIN_FDT_ALIGNto be at
+ * least 8 bytes so that we always access the magic and size fields
+ * of the FDT header after mapping the first chunk, double check ifQuoted 8 lines
+ * that is indeed the case.
+ */
+BUILD_BUG_ON(MIN_FDT_ALIGN < 8);
+ if ( !fdt_paddr ||fdt_paddr%MIN_FDT_ALIGN) + return NULL;
+
+ /* The FDT is mapped using 2MB superpage */ +BUILD_BUG_ON(BOOT_FDT_VIRT_START % SZ_2M);May I suggest that you use MB(2) instead of
SZ_2M(not just here)? I think
I had voiced opposition to the introduction ofxen/sizes.habout 10 years
back, yet sadly it still landed in the tree. I for one think that ourKB(),MB(), andGB()constructs are superior, and (I hope) free of Misra issues
(unlikeSZ_2G).Quoted 21 lines
+ rc = map_pages_to_xen(BOOT_FDT_VIRT_START,
maddr_to_mfn(base_paddr),
+SZ_2M>>PAGE_SHIFT,
+PAGE_HYPERVISOR_RO|_PAGE_BLOCK); + if ( rc )
+panic("Unable to map the device-tree.\n");xen/arch/riscv/include/asm/mm.h +15
-0+ + offset = fdt_paddr % XEN_PT_LEVEL_SIZE(1); + fdt_virt = (void *)BOOT_FDT_VIRT_START + offset; + + if ( fdt_magic(fdt_virt) != FDT_MAGIC ) + return NULL; + + size = fdt_totalsize(fdt_virt); + if ( size > BOOT_FDT_VIRT_SIZE ) + return NULL; + + if ( (offset + size) > SZ_2M ) + { + rc = map_pages_to_xen(BOOT_FDT_VIRT_START + SZ_2M, + maddr_to_mfn(base_paddr + SZ_2M),
Quoted 8 lines
Quoted 5 lines
+
SZ_2M>>PAGE_SHIFT,
+PAGE_HYPERVISOR_RO|_PAGE_BLOCK); + if ( rc )
+panic("Unable to map the device-tree\n"); + }Why this two part mapping? And why are you mapping perhaps much more than "size"?
I wasn't able to find if RISC-V has a requirement for alignment of FDT address so I decided to follow Arm where FDT is required to be placed on a 8-byte boundary, so FDT can cross a 2MB boundary, so the second 2MB page should be mapped if the FDT is crossing the 2MB boundary.
Quoted 10 lines
Quoted 8 lines
xen/arch/riscv/include/asm/mm.h +0
-0@@ -48,6 +49,14 @@ void __init noreturn start_xen(unsigned long bootcpu_id,
setup_fixmap_mappings();
+device_tree_flattened=early_fdt_map(dtb_addr); + if (device_tree_flattened)Is this condition perhaps inverted?
Yes, you are right. It should be inverted.
Thanks.
~ Oleksii
Quoted 13 lines
Quoted 12 lines
+ panic("Invalid device tree blob at physical address %#lx.\n"
+ "The DTB must be 8-byte aligned and must not exceed %lld "
+ "bytes in size.\n\n"
+ "Please check your bootloader.\n",
+dtb_addr,BOOT_FDT_VIRT_SIZE);
+
printk("All set up\n");
for ( ;; )
Re: [PATCH v2 8/8] xen/riscv: introduce early_fdt_map()
Quoted 31 lines · Oleksii
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Oleksii Kurochko
+ rc = map_pages_to_xen(BOOT_FDT_VIRT_START,
maddr_to_mfn(base_paddr),
+SZ_2M>>PAGE_SHIFT,
+PAGE_HYPERVISOR_RO|_PAGE_BLOCK); + if ( rc )
+panic("Unable to map the device-tree.\n");xen/arch/riscv/mm.c +15
-0+ + offset = fdt_paddr % XEN_PT_LEVEL_SIZE(1); + fdt_virt = (void *)BOOT_FDT_VIRT_START + offset; + + if ( fdt_magic(fdt_virt) != FDT_MAGIC ) + return NULL; + + size = fdt_totalsize(fdt_virt); + if ( size > BOOT_FDT_VIRT_SIZE ) + return NULL; + + if ( (offset + size) > SZ_2M ) + { + rc = map_pages_to_xen(BOOT_FDT_VIRT_START + SZ_2M, + maddr_to_mfn(base_paddr + SZ_2M),Quoted 8 lines
Quoted 5 lines
+
SZ_2M>>PAGE_SHIFT,
+PAGE_HYPERVISOR_RO|_PAGE_BLOCK); + if ( rc )
+panic("Unable to map the device-tree\n"); + }Why this two part mapping? And why are you mapping perhaps much more than "size"?
Quoted 4 lines
I wasn't able to find if RISC-V has a requirement for alignment of FDT address so I decided to follow Arm where FDT is required to be placed on a 8-byte boundary, so FDT can cross a 2MB boundary, so the second 2MB page should be mapped if the FDT is crossing the 2MB boundary.
This explains why you may need to map more than 2Mb (which wasn't the question), but it doesn't explain why you need to do it in two steps.
Jan
Re: [PATCH v2 8/8] xen/riscv: introduce early_fdt_map()
Quoted 32 lines · Jan Beulich
Quoted 31 lines · Oleksii
Quoted 30 lines · Jan Beulich
Quoted 16 lines · Oleksii Kurochko
+ rc = map_pages_to_xen(BOOT_FDT_VIRT_START,
maddr_to_mfn(base_paddr),
+SZ_2M>>PAGE_SHIFT,
+PAGE_HYPERVISOR_RO|_PAGE_BLOCK); + if ( rc )
+panic("Unable to map the device-tree.\n");xen/arch/riscv/mm.c +10
-0+ + offset = fdt_paddr % XEN_PT_LEVEL_SIZE(1); + fdt_virt = (void *)BOOT_FDT_VIRT_START + offset; + + if ( fdt_magic(fdt_virt) != FDT_MAGIC ) + return NULL; + + size = fdt_totalsize(fdt_virt); + if ( size > BOOT_FDT_VIRT_SIZE ) + return NULL;xen/arch/riscv/mm.c inline pte_t mfn_to_xen_entry(mfn_t mfn, unsigned int attr) · line 489
Quoted 10 lines
xen/arch/riscv/mm.c +10
-0+ + if ( (offset + size) > SZ_2M ) + { + rc = map_pages_to_xen(BOOT_FDT_VIRT_START + SZ_2M, + maddr_to_mfn(base_paddr + SZ_2M), + SZ_2M >> PAGE_SHIFT, + PAGE_HYPERVISOR_RO | _PAGE_BLOCK); + if ( rc ) + panic("Unable to map the device-tree\n"); + }Why this two part mapping? And why are you mapping perhaps much more than "size"?
Quoted 7 lines
Quoted 4 lines
I wasn't able to find if RISC-V has a requirement for alignment of FDT address so I decided to follow Arm where FDT is required to be placed on a 8-byte boundary, so FDT can cross a 2MB boundary, so the second 2MB page should be mapped if the FDT is crossing the 2MB boundary.
This explains why you may need to map more than 2Mb (which wasn't the question), but it doesn't explain why you need to do it in two steps.
Oh, wait - you know the full size only after having mapped the initial part. I'm sorry, I didn't spot that early enough.
Jan