Setup memory management
cover Setup memory management
Finish initializing the memory subsystem by mapping the direct map and frame table.
In the case of RISC-V 64, which has a large virtual address space (the minimum supported MMU mode is Sv39, providing TB of VA space), the direct map and frame table are mapped starting from physical address
0. This simplifies the calculations and thereby improves performance for page_to_mfn(), mfn_to_page(), and maddr_to_virt(), as there is no need to account for {directmap, frametable}_base_pdx.
In addition, initialize the VMAP_DEFAULT region, finalize the boot allocator, and update the system state from early_boot to boot.
Also, after patch 3 ("xen/riscv: introduce setup_mm()") of this patch series, the linkage error mentioned in patch 1 ("xen/riscv: add stub for share_xen_page_with_guest()") began to occur, so patch 1 addresses this issue.
The function maddr_to_virt() is introduced as part of this patch series, as setup_directmap_mappings() uses it indirectly through mfn_to_virt().
Oleksii Kurochko (5):
xen/riscv: add stub for share_xen_page_with_guest() xen/riscv: implement maddr_to_virt()
xen/riscv: introduce setup_mm()
xen/riscv: initialize the VMAP_DEFAULT virtual range xen/riscv: finalize boot allocator and transition to boot state
xen/arch/riscv/include/asm/mm.h | 10 ++- xen/arch/riscv/include/asm/setup.h | 2 + xen/arch/riscv/mm.c | 104 +++++++++++++++++++++++++++-- xen/arch/riscv/pt.c | 6 ++ xen/arch/riscv/setup.c | 14 ++++ xen/arch/riscv/stubs.c | 10 +++ 6 files changed, 138 insertions(+), 8 deletions(-)
Signature · 1 line
2.47.0
PATCH 3/5 xen/riscv: introduce setup_mm()
Introduce the implementation of setup_mm(), which includes:
1. Adding all free regions to the boot allocator, as memory is needed to allocate page tables used for frame table mapping.
2. Calculating RAM size and the RAM end address.
3. Setting up direct map mappings from the PFN of physical address 0 to the PFN of RAM end.
4. Setting up frame table mappings from physical address 0 to ram_end.
5. Setting up total_pages and max_page.
6. Establishing directmap_virt_end, which is not currently used but is intended for future use in virt_to_page() to ensure that virtual addresses do not exceed directmap_virt_end.
In the case of RISC-V 64, which has a large virtual address space (the minimum supported MMU mode is Sv39, providing TB of VA space), the direct map and frame table are mapped starting from physical address
0. This simplifies the calculations and thereby improves performance for page_to_mfn(), mfn_to_page(), and maddr_to_virt(), as there is no need to account for {directmap, frametable}_base_pdx.
--- xen/arch/riscv/include/asm/mm.h | 2 + xen/arch/riscv/include/asm/setup.h | 2 + xen/arch/riscv/mm.c | 93 ++++++++++++++++++++++++++++++ xen/arch/riscv/setup.c | 3 + 4 files changed, 100 insertions(+)
xen/arch/riscv/include/asm/mm.h +2 -0
@@ -12,6 +12,8 @@#include <asm/page-bits.h> +extern vaddr_t directmap_virt_end; +#define pfn_to_paddr (pfn) ((paddr_t)(pfn) << PAGE_SHIFT)#define paddr_to_pfn (pa) ((unsigned long)((pa) >> PAGE_SHIFT))
xen/arch/riscv/include/asm/setup.h +2 -0
@@ -5,6 +5,8 @@#define max_init_domid (0) +void setup_mm (void ); +#endif /* ASM__RISCV__SETUP_H */ /*
xen/arch/riscv/mm.c +93 -0
102 lines not on this page · raw message
xen/arch/riscv/setup.c +3 -0
@@ -12,6 +12,7 @@#include <asm/early_printk.h> #include <asm/sbi.h> +#include <asm/setup.h> #include <asm/smp.h> #include <asm/traps.h>
@@ -59,6 +60,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id,printk ("Command line: %s\n" , cmdline);cmdline_parse (cmdline); +setup_mm (); +printk ("All set up\n" );machine_halt ();
Signature · 1 line
2.47.0
PATCH 1/5 xen/riscv: add stub for share_xen_page_with_guest()
In reply to Oleksii KurochkoTo avoid the following linkage fail the stub for share_xen_page_with_guest()
is introduced:
riscv64-linux-gnu-ld: prelink.o: in function `tasklet_kill':
/build/xen/common/tasklet.c:176: undefined reference to `share_xen_page_with_guest'
riscv64-linux-gnu-ld: ./.xen-syms.0: hidden symbol `share_xen_page_with_guest' isn't defined
riscv64-linux-gnu-ld: final link failed: bad value
$ find . -name \*.o | while read F; do nm $F | grep share_xen_page_with_guest && echo $F; done
U share_xen_page_with_guest
./xen/common/built_in.o
U share_xen_page_with_guest
./xen/common/trace.o
U share_xen_page_with_guest
./xen/prelink.oDespite the linker fingering tasklet.c (very likely a toolchain bug), it's trace.o which has the undefined reference.
Looking at trace.i, there is call of share_xen_page_with_guest() in share_xen_page_with_privileged_guests() from asm/mm.h.
--- xen/arch/riscv/stubs.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
xen/arch/riscv/stubs.c +10 -0
@@ -2,7 +2,9 @@#include <xen/cpumask.h> #include <xen/domain.h> #include <xen/irq.h> +#include <xen/mm.h> #include <xen/nodemask.h> +#include <xen/sched.h> #include <xen/sections.h> #include <xen/time.h> #include <public/domctl.h>
@@ -409,3 +411,11 @@ unsigned long get_upper_mfn_bound(void) {BUG_ON ("unimplemented" ); } + +/* mm.c */ + +void share_xen_page_with_guest (struct page_info *page,struct domain *d, +enum XENSHARE_flags flags) +{ +BUG_ON ("unimplemented" ); +}
Signature · 1 line
2.47.0
PATCH 2/5 xen/riscv: implement maddr_to_virt()
In reply to Oleksii KurochkoImplement the maddr_to_virt() function to convert a machine address to a virtual address. This function is specifically designed to be used only for the DIRECTMAP region, so a check has been added to ensure that the address does not exceed DIRECTMAP_SIZE.
--- xen/arch/riscv/include/asm/mm.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
xen/arch/riscv/include/asm/mm.h +6 -2
@@ -25,8 +25,12 @@static inline void *maddr_to_virt (paddr_t ma) { -BUG_ON ("unimplemented" ); -return NULL ; +/* Offset in the direct map, accounting for pdx compression */ +unsigned long va_offset =maddr_to_directmapoff (ma); + +ASSERT (va_offset <DIRECTMAP_SIZE ); + +return (void *)(DIRECTMAP_VIRT_START + va_offset); }/*
Signature · 1 line
2.47.0
PATCH 4/5 xen/riscv: initialize the VMAP_DEFAULT virtual range
In reply to Oleksii KurochkoCall vm_init() to initialize the VMAP_DEFAULT virtual range.
To support this, introduce the populate_pt_range() and arch_vmap_virt_end() functions, which are used by vm_init()->vm_init_type().
--- xen/arch/riscv/mm.c | 11 +++++------ xen/arch/riscv/pt.c | 6 ++++++ xen/arch/riscv/setup.c | 3 +++ 3 files changed, 14 insertions(+), 6 deletions(-)
xen/arch/riscv/mm.c +5 -6
@@ -352,12 +352,6 @@ void arch_dump_shared_mem_info(void)BUG_ON ("unimplemented" ); } -int populate_pt_range (unsigned long virt,unsigned long nr_mfns) -{ -BUG_ON ("unimplemented" ); -return -1 ; -} -int xenmem_add_to_physmap_one (struct domain *d,unsigned int space,union add_to_physmap_extra extra,unsigned long idx,gfn_t gfn)
@@ -516,3 +510,8 @@ void __init setup_mm(void)#else /* CONFIG_RISCV_32 */ #error setup_mm(), setup_{directmap,frametable}_mapping() should be implemented for RV_32#endif + +void *__init arch_vmap_virt_end (void ) +{ +return (void *)(VMAP_VIRT_START +VMAP_VIRT_SIZE ); +}
xen/arch/riscv/pt.c +6 -0
@@ -1,6 +1,7 @@#include <xen/bug.h> #include <xen/domain_page.h> #include <xen/errno.h> +#include <xen/init.h> #include <xen/lib.h> #include <xen/mm.h> #include <xen/pfn.h>
@@ -419,3 +420,8 @@ int map_pages_to_xen(unsigned long virt,return pt_update (virt, mfn, nr_mfns, flags); } + +int __init populate_pt_range (unsigned long virt,unsigned long nr_mfns) +{ +return pt_update (virt,INVALID_MFN , nr_mfns,PTE_POPULATE ); +}
xen/arch/riscv/setup.c +3 -0
@@ -7,6 +7,7 @@#include <xen/init.h> #include <xen/mm.h> #include <xen/shutdown.h> +#include <xen/vmap.h> #include <public/version.h>
@@ -62,6 +63,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id,setup_mm (); +vm_init (); +printk ("All set up\n" );machine_halt ();
Signature · 1 line
2.47.0
PATCH 5/5 xen/riscv: finalize boot allocator and transition to boot state
In reply to Oleksii KurochkoAdd a call to end_boot_allocator() in start_xen() to finalize the boot memory allocator, moving free pages to the domain sub-allocator.
After initializing the memory subsystem, update system_state from SYS_STATE_early_boot to SYS_STATE_boot, signifying the end of the early boot phase.
--- xen/arch/riscv/setup.c | 8 ++++++++ 1 file changed, 8 insertions(+)
xen/arch/riscv/setup.c +8 -0
@@ -65,6 +65,14 @@ void __init noreturn start_xen(unsigned long bootcpu_id,vm_init (); +end_boot_allocator (); + +/* +* The memory subsystem has been initialized, we can now switch from +* early_boot -> boot. +*/ + system_state = SYS_STATE_boot; +printk ("All set up\n" );machine_halt ();
Signature · 1 line
2.47.0
Re: [PATCH v1 2/5] xen/riscv: implement maddr_to_virt()
In reply to Oleksii KurochkoQuoted 5 lines · Oleksii Kurochko
Implement the
maddr_to_virt()function to convert a machine address to a virtual address. This function is specifically designed to be used only for the DIRECTMAP region, so a check has been added to ensure that the address does not exceedDIRECTMAP_SIZE.
nit: Worth mentioning this comes from the x86 side of things.
Quoted 24 lines
Signed-off-by Oleksii Kurochko <[email protected]>--- xen/arch/riscv/include/asm/mm.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)xen/arch/riscv/include/asm/mm.h +6
-2@@ -25,8 +25,12 @@static inline void *maddr_to_virt (paddr_t ma) { -BUG_ON ("unimplemented" ); -return NULL ; +/* Offset in the direct map, accounting for pdx compression */ +unsigned long va_offset =maddr_to_directmapoff (ma); + +ASSERT (va_offset <DIRECTMAP_SIZE ); + +return (void *)(DIRECTMAP_VIRT_START + va_offset); }/*
Re: [PATCH v1 1/5] xen/riscv: add stub for share_xen_page_with_guest()
In reply to Oleksii KurochkoQuoted 2 lines · Oleksii Kurochko
To avoid the following linkage fail the stub for
share_xen_page_with_guest()is introduced:
What do you intend to express with "is introduced"? Is there a problem now? Would there be a problem with subsequent changes? I'm entirely fine with adding that stub, but the description should make clear why /when exactly it's needed.
Jan
Quoted 50 lines
riscv64-linux-gnu-ld: prelink.o: in function `tasklet_kill':
/build/xen/common/tasklet.c:176: undefined reference to `share_xen_page_with_guest'
riscv64-linux-gnu-ld: ./.xen-syms.0: hidden symbol `share_xen_page_with_guest' isn't defined
riscv64-linux-gnu-ld: final link failed: bad value$ find . -name \*.o | while read F; do nm $F | grep share_xen_page_with_guest && echo $F; done U share_xen_page_with_guest ./xen/common/built_in.o U share_xen_page_with_guest ./xen/common/trace.o U share_xen_page_with_guest ./xen/prelink.oDespite the linker fingering
tasklet.c(very likely a toolchain bug), it's trace.o which has the undefined reference.Looking at trace.i, there is call of
share_xen_page_with_guest()inshare_xen_page_with_privileged_guests()fromasm/mm.h.Signed-off-by Oleksii Kurochko <[email protected]>--- xen/arch/riscv/stubs.c | 10 ++++++++++ 1 file changed, 10 insertions(+)xen/arch/riscv/stubs.c +10
-0@@ -2,7 +2,9 @@#include <xen/cpumask.h> #include <xen/domain.h> #include <xen/irq.h> +#include <xen/mm.h> #include <xen/nodemask.h> +#include <xen/sched.h> #include <xen/sections.h> #include <xen/time.h> #include <public/domctl.h> @@ -409,3 +411,11 @@ unsigned long get_upper_mfn_bound(void) {BUG_ON ("unimplemented" ); } + +/* mm.c */ + +void share_xen_page_with_guest (struct page_info *page,struct domain *d, +enum XENSHARE_flags flags) +{ +BUG_ON ("unimplemented" ); +}
Re: [PATCH v1 2/5] xen/riscv: implement maddr_to_virt()
In reply to Oleksii Kurochkoxen/arch/riscv/include/asm/mm.h line 29
Quoted 10 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/mm.h +2
-2@@ -25,8 +25,12 @@static inline void *maddr_to_virt (paddr_t ma) { -BUG_ON ("unimplemented" ); -return NULL ; +/* Offset in the direct map, accounting for pdx compression */ +unsigned long va_offset =maddr_to_directmapoff (ma);
Why the mentioning of PDX compression? At least right now it's unavailable for RISC-V afaics. Are there plans to change that any time soon?
Jan
Re: [PATCH v1 3/5] xen/riscv: introduce setup_mm()
In reply to Oleksii Kurochkoxen/arch/riscv/mm.c void * __init early_fdt_map(paddr_t fdt_paddr) · line 434
Quoted 12 lines · Oleksii Kurochko
xen/arch/riscv/mm.c +8
-0@@ -423,3 +424,95 @@ void * __init early_fdt_map(paddr_t fdt_paddr)return fdt_virt; } + +#ifndef CONFIG_RISCV_32 +/* Map the region in the directmap area. */ +static void __init setup_directmap_mappings (unsigned long nr_mfns) +{ +if ( nr_mfns >PFN_DOWN (DIRECTMAP_SIZE ) ) +panic ("The directmap cannot cover the physical region %#" PRIpaddr" - %#" PRIpaddr"\n" , +0UL , nr_mfns <<PAGE_SHIFT );
Here and elsewhere can you please use mathematical range expressions (apparently "[%"PRIpaddr", %#"PRIpaddr")" here), to avoid ambiguity?
xen/arch/riscv/mm.c void * __init early_fdt_map(paddr_t fdt_paddr) · line 445
Quoted 10 lines
xen/arch/riscv/mm.c +10
-0+if (map_pages_to_xen ((vaddr_t )mfn_to_virt (0 ), +_mfn (0 ), nr_mfns, +PAGE_HYPERVISOR_RW ) ) +panic ("Unable to setup the directmap mappings.\n" ); +} + +/* Map a frame table to cover physical addresses ps through pe */ +static void __init setup_frametable_mappings (paddr_t ps,paddr_t pe) +{ + unsigned long nr_mfns = mfn_x(mfn_add(maddr_to_mfn(pe), -1)) -
This looks to be accounting for a partial page at the end.
xen/arch/riscv/mm.c void * __init early_fdt_map(paddr_t fdt_paddr) · line 446
Quoted 1 line
xen/arch/riscv/mm.c +1
-0+mfn_x (maddr_to_mfn (ps)) +1 ;
Whereas this doesn't do the same at the start. The sole present caller passes 0, so that's going to be fine for the time being. Yet it's a latent pitfall. I'd recommend to either drop the function parameter, or to deal with it correctly right away.
xen/arch/riscv/mm.c void * __init early_fdt_map(paddr_t fdt_paddr) · line 455
Quoted 9 lines
xen/arch/riscv/mm.c +9
-0+unsigned long frametable_size = nr_mfns *sizeof (struct page_info ); +mfn_t base_mfn; + +if ( frametable_size >FRAMETABLE_SIZE ) +panic ("The frametable cannot cover the physical region %#" PRIpaddr" - %#" PRIpaddr"\n" , + ps, pe); + + frametable_size =ROUNDUP (frametable_size,MB (2 )); + base_mfn =alloc_boot_pages (frametable_size >>PAGE_SHIFT ,2 <<(20 -12 ));
Nit: Missing blanks in binary expressions. Also please don't open-code PFN_DOWN() (and again below).
xen/arch/riscv/mm.c void * __init early_fdt_map(paddr_t fdt_paddr) · line 460
Quoted 4 lines
xen/arch/riscv/mm.c +4
-0+if (map_pages_to_xen (FRAMETABLE_VIRT_START , base_mfn, + frametable_size >>PAGE_SHIFT , +PAGE_HYPERVISOR_RW ) ) +panic ("Unable to setup the frametable mappings.\n" );
Nit (as indicated before): No full stop please at the end of log or panic messages.
xen/arch/riscv/mm.c void * __init early_fdt_map(paddr_t fdt_paddr) · line 467
Quoted 6 lines
xen/arch/riscv/mm.c +6
-0+memset (&frame_table[0 ],0 , nr_mfns *sizeof (struct page_info )); +memset (&frame_table[nr_mfns],-1 , + frametable_size - (nr_mfns *sizeof (struct page_info ))); +} + +vaddr_t directmap_virt_end__read_mostly ;
__ro_after_init? And moved ahead of the identifier, just like ...
xen/arch/riscv/mm.c void * __init early_fdt_map(paddr_t fdt_paddr) · line 479
Quoted 11 lines
xen/arch/riscv/mm.c +11
-0+/* +* Setup memory management +* +* RISC-V 64 has a large virtual address space (the minimum supported +* MMU mode is Sv39, which provides TBs of VA space). +* In the case of RISC-V 64, the directmap and frametable are mapped +* starting from physical address 0 to simplify the page_to_mfn(), +* mfn_to_page(), and maddr_to_virt() calculations, as there is no need +* to account for {directmap, frametable}_base_pdx in this setup. +*/ +void __init setup_mm (void )
... __init is placed e.g. here.
It's also unclear why the variable needs to be non-static.
Quoted 17 lines
xen/arch/riscv/mm.c +17
-0+{ +const struct membanks *banks =bootinfo_get_mem (); +paddr_t ram_end =0 ; +paddr_t ram_size =0 ; +unsigned int i; + +/* +* We need some memory to allocate the page-tables used for the directmap +* mappings. But some regions may contain memory already allocated +* for other uses (e.g. modules, reserved-memory...). +* +* For simplicity, add all the free regions in the boot allocator. +*/ +populate_boot_allocator (); + + total_pages =0 ; +
xen/arch/riscv/mm.c void * __init early_fdt_map(paddr_t fdt_paddr) · line 506
Quoted 10 lines
xen/arch/riscv/mm.c +10
-0+for ( i =0 ; i < banks->nr_banks; i++ ) + { +const struct membank *bank = &banks->bank[i]; +paddr_t bank_end = bank->start + bank->size; + + ram_size = ram_size + bank->size; + ram_end =max (ram_end, bank_end); + } + +setup_directmap_mappings (PFN_DOWN (ram_end));
While you may want to use non-offset-ed mappings, I can't see how you can validly map just a single huge chunk, no matter whether there are holes in there. Such holes could hold MMIO regions, which I'm sure would require more careful mapping (to avoid cacheable accesses, or even speculative ones).
xen/arch/riscv/mm.c void * __init early_fdt_map(paddr_t fdt_paddr) · line 508
Quoted 1 line
xen/arch/riscv/mm.c +1
-0+ total_pages =PFN_DOWN (ram_size);
Imo the rounding down to page granularity needs to be done when ram_size is accumulated, such that partial pages simply won't be counted. Unless of course there's a guarantee that banks can never have partial pages at their start/end.
Jan
Re: [PATCH v1 4/5] xen/riscv: initialize the VMAP_DEFAULT virtual range
In reply to Oleksii KurochkoQuoted 7 lines · Oleksii Kurochko
Call
vm_init()to initialize theVMAP_DEFAULTvirtual range.To support this, introduce the
populate_pt_range()andarch_vmap_virt_end()functions, which are used by vm_init()->vm_init_type().Signed-off-by Oleksii Kurochko <[email protected]>
Re: [PATCH v1 5/5] xen/riscv: finalize boot allocator and transition to boot state
In reply to Oleksii KurochkoQuoted 8 lines · Oleksii Kurochko
Add a call to
end_boot_allocator()instart_xen()to finalize the boot memory allocator, moving free pages to the domain sub-allocator.After initializing the memory subsystem, update
system_statefromSYS_STATE_early_boottoSYS_STATE_boot, signifying the end of the early boot phase.Signed-off-by Oleksii Kurochko <[email protected]>
Re: [PATCH v1 1/5] xen/riscv: add stub for share_xen_page_with_guest()
In reply to Jan BeulichQuoted 5 lines · Jan Beulich
Quoted 3 lines · Oleksii Kurochko
To avoid the following linkage fail the stub for
share_xen_page_with_guest()
is introduced:
Quoted 7 lines
What do you intend to express with "is introduced"? Is there a problem now?
Would there be a problem with subsequent changes? I'm entirely fine with
adding that stub, but the description should make clear why /when exactly
it's needed.
I mentioned that in the cover letter:
```
Also, after patch 3 ("xen/riscv: introduce setup_mm()") of this
patch series,
the linkage error mentioned in patch 1 ("xen/riscv: add stub for
share_xen_page_with_guest()") began to occur, so patch 1 addresses
this issue.
```I thought it would be the better then just mention in the commit message that.
Will it be fine to mention instead:
``` Introduction of setup memory management function will require share_xen_page_with_guest() defined, at least, as a stub otherwise the following linkage error will occur... ```
Perhaps it would be better just to merge these changes with patch 3 and add an explanation in patch 3 commit message.
~ Oleksii
Quoted 56 lines
Quoted 55 lines
riscv64-linux-gnu-ld: prelink.o: in function `tasklet_kill':
/build/xen/common/tasklet.c:176: undefined reference to `share_xen_page_with_guest'
riscv64-linux-gnu-ld: ./.xen-syms.0: hidden symbol `share_xen_page_with_guest' isn't defined
riscv64-linux-gnu-ld: final link failed: bad value$ find . -name \*.o | while read F; do nm $F | grep share_xen_page_with_guest && echo $F; done U share_xen_page_with_guest ./xen/common/built_in.o U share_xen_page_with_guest ./xen/common/trace.o U share_xen_page_with_guest ./xen/prelink.oDespite the linker fingering
tasklet.c(very likely a toolchain bug),
it's trace.o which has the undefined reference.Looking at trace.i, there is call of
share_xen_page_with_guest()inshare_xen_page_with_privileged_guests()fromasm/mm.h.Signed-off-by Oleksii Kurochko <[email protected]>---
xen/arch/riscv/stubs.c | 10 ++++++++++1 file changed, 10 insertions(+)xen/arch/riscv/stubs.c +6
-0@@ -2,7 +2,9 @@ #include <xen/cpumask.h> #include <xen/domain.h> #include <xen/irq.h> +#include <xen/mm.h> #include <xen/nodemask.h> +#include <xen/sched.h> #include <xen/sections.h> #include <xen/time.h> #include <public/domctl.h>@@ -409,3 +411,11 @@ unsigned long get_upper_mfn_bound(void) { BUG_ON("unimplemented"); } + +/* mm.c */ + +void share_xen_page_with_guest(struct page_info *page, structdomain *d,
+ enumXENSHARE_flagsflags)xen/arch/riscv/stubs.c +3
-0+{ + BUG_ON("unimplemented"); +}
Re: [PATCH v1 2/5] xen/riscv: implement maddr_to_virt()
In reply to Jan BeulichQuoted 13 lines · Jan Beulich
Quoted 10 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/mm.h +0
-0@@ -25,8 +25,12 @@
static inline void *maddr_to_virt(paddr_t ma)
{
-BUG_ON("unimplemented");
- return NULL;
+ /* Offset in the direct map, accounting for pdx compression */ + unsigned longva_offset=maddr_to_directmapoff(ma);Why the mentioning of PDX compression?
It was mentioned because if PDX will be enabled maddr_to_directmapoff() will take into account PDX stuff.
Quoted 2 lines
At least right now it's unavailable
for RISC-V afaics. Are there plans to change that any time soon?
At the moment, I don't have such plans, looking at available platform there are no a lot of benefits of having PDX compression now.
Perhaps it would be good to add BUILD_BUG_ON(IS_ENABLED(PDX_COMPRESSION)) for the places which should be updated when CONFIG_PDX will be enabled.
~ Oleksii
Re: [PATCH v1 1/5] xen/riscv: add stub for share_xen_page_with_guest()
In reply to [email protected]Quoted 21 lines · On 18.10.2024 15:10, [email protected] wrote:
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Oleksii Kurochko
To avoid the following linkage fail the stub for
share_xen_page_with_guest()
is introduced:Quoted 7 lines
What do you intend to express with "is introduced"? Is there a problem now?
Would there be a problem with subsequent changes? I'm entirely fine with
adding that stub, but the description should make clear why /when exactly
it's needed.I mentioned that in the cover letter:
``` Also, after patch 3 ("xen/riscv: introduce setup_mm()") of this patch series, the linkage error mentioned in patch 1 ("xen/riscv: add stub for share_xen_page_with_guest()") began to occur, so patch 1 addresses this issue. ```
Quoted 2 lines
I thought it would be the better then just mention in the commit message that.
Mentioning in the cover letter is fine, but each patch needs to also be self-contained.
Quoted 6 lines
Will it be fine to mention instead:
``` Introduction of setup memory management function will require share_xen_page_with_guest() defined, at least, as a stub otherwise the following linkage error will occur... ```
Quoting the linker error is imo of limited use. What such an explanation wants to say is why, all of the sudden, such an error occurs. After all you don't change anything directly related to common/trace.c.
Quoted 2 lines
Perhaps it would be better just to merge these changes with patch 3 and add an explanation in patch 3 commit message.
Perhaps, as you say.
Jan
Re: [PATCH v1 3/5] xen/riscv: introduce setup_mm()
In reply to Jan BeulichQuoted 16 lines · Jan Beulich
Quoted 11 lines · Oleksii Kurochko
+ if ( map_pages_to_xen((vaddr_t)mfn_to_virt(0), +
_mfn(0),nr_mfns,
+PAGE_HYPERVISOR_RW) )
+panic("Unable to setup the directmap mappings.\n");xen/arch/riscv/mm.c +4
-0+} + +/* Map a frame table to cover physical addresses ps through pe */ +static void __init setup_frametable_mappings(paddr_t ps, paddr_tpe)
+{
+ unsigned longnr_mfns=mfn_x(mfn_add(maddr_to_mfn(pe), -1))-This looks to be accounting for a partial page at the end.
Quoted 8 lines
Quoted 1 line
+ mfn_x(maddr_to_mfn(ps)) + 1;
Whereas this doesn't do the same at the start. The sole present caller
passes 0, so that's going to be fine for the time being. Yet it's a latent pitfall. I'd recommend to either drop the function parameter, or
to deal with it correctly right away.
Then it will be better to do in the next way to be sure that everything is properly aligned:
unsigned long nr_mfns = PFN_DOWN(ALIGN_UP(pe) - ALIGN_DOWN(ps));
Quoted 28 lines
xen/arch/riscv/mm.c void * __init early_fdt_map(paddr_t fdt_paddr) · line 467
Quoted 8 lines
+
memset(&frame_table[0], 0, nr_mfns * sizeof(struct page_info));
+ memset(&frame_table[nr_mfns], -1,
+frametable_size- (nr_mfns*sizeof(struct page_info)));xen/arch/riscv/mm.c +3
-0+} + +vaddr_t directmap_virt_end__read_mostly ;
__ro_after_init? And moved ahead of the identifier, just like ...Quoted 6 lines
+/*
+ * Setup memory management
+ *
+ * RISC-V 64 has a large virtual address space (the minimum supported
+ * MMU mode is Sv39, which provides TBs of VA space).Quoted 8 lines
+ * In the case of RISC-V 64, the directmap and frametable are mapped
+ * starting from physical address 0 to simplify thepage_to_mfn(),
+ *mfn_to_page(), andmaddr_to_virt()calculations, as there is no need
+ * to account for {directmap, frametable}_base_pdx in this setup.
+ */
+void__initsetup_mm(void)...
__initis placed e.g. here.
Quoted 1 line
It's also unclear why the variable needs to be non-static.
As it could be use then for some ASSERT(), for example, in virt_to_page() as Arm or x86 do.
Quoted 33 lines
Quoted 21 lines
xen/arch/riscv/mm.c +8
-0+{ + const struct membanks *banks = bootinfo_get_mem(); + paddr_t ram_end = 0; + paddr_t ram_size = 0; + unsigned int i; + + /* +* We need some memory to allocate the page-tables used for the directmap
+ * mappings. But some regions may contain memory already allocated
+ * for other uses (e.g. modules, reserved-memory...). + *
+ * For simplicity, add all the free regions in the boot allocator.
+ */
+populate_boot_allocator();xen/arch/riscv/mm.c +3
-0+ + total_pages = 0; +xen/arch/riscv/mm.c void * __init early_fdt_map(paddr_t fdt_paddr) · line 506
Quoted 10 lines
xen/arch/riscv/mm.c +10
-0+ for ( i = 0; i < banks->nr_banks; i++ ) + { + const struct membank *bank = &banks->bank[i]; + paddr_t bank_end = bank->start + bank->size; + + ram_size = ram_size + bank->size; + ram_end = max(ram_end, bank_end); + } + + setup_directmap_mappings(PFN_DOWN(ram_end));While you may want to use non-offset-ed mappings, I can't see how you
Quoted 8 lines
can
validly map just a single huge chunk, no matter whether there are holes
in there. Such holes could hold MMIO regions, which I'm sure would require
more careful mapping (to avoid cacheable accesses, or even speculative
ones).
My intention was to avoid subraction of directmap_start ( = ram_start ) in maddr_to_virt() to have less operations during maddr to virt calculation:
static inline void *maddr_to_virt(paddr_t ma)
{
/* Offset in the direct map, accounting for pdx compression */
unsigned long va_offset = maddr_to_directmapoff(ma);
ASSERT(va_offset < DIRECTMAP_SIZE);
return (void *)(DIRECTMAP_VIRT_START /* - directmap_start */ + va_offset);
}
But it seems I don't have any chance to avoid that because of mentioned by you reasons... Except probably to have a config which will hard code RAM_START for each platform ( what on other hand will make Xen less flexible in some point ).
Does it make sense to have a config instead of identifying ram_start in runtime?
So I have to rework this part of code to look as:
for ( i = 0; i < banks->nr_banks; i++ )
{
const struct membank *bank = &banks->bank[i];
paddr_t bank_end = bank->start + bank->size;
ram_size = ram_size + bank->size;
ram_start = min(ram_start, bank->start);
ram_end = max(ram_end, bank_end);
setup_directmap_mappings(PFN_DOWN(bank->start),
PFN_DOWN(bank->size));
}Quoted 10 lines
Quoted 2 lines
+
total_pages=PFN_DOWN(ram_size);Imo the rounding down to page granularity needs to be done when
ram_size
is accumulated, such that partial pages simply won't be counted. Unless
of course there's a guarantee that banks can never have partial pages at
their start/end.
Hmm, good point. I thought that start/end is always properly aligned but I can't find in device tree spec that it is guaranteed for memory node, so it will really better rounding down after ram_size is accumulated.
~ Oleksii
Re: [PATCH v1 1/5] xen/riscv: add stub for share_xen_page_with_guest()
In reply to Jan BeulichQuoted 38 lines · Jan Beulich
Quoted 23 lines · On 18.10.2024 15:10, [email protected] wrote:
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Oleksii Kurochko
To avoid the following linkage fail the stub for
share_xen_page_with_guest()
is introduced:Quoted 8 lines
What do you intend to express with "is introduced"? Is there a problem now?
Would there be a problem with subsequent changes? I'm entirely fine
with
adding that stub, but the description should make clear why /when exactly
it's needed.I mentioned that in the cover letter:
``` Also, after patch 3 ("xen/riscv: introduce setup_mm()") of this patch series, the linkage error mentioned in patch 1 ("xen/riscv: add stub for share_xen_page_with_guest()") began to occur, so patch 1 addresses this issue. ```Quoted 2 lines
I thought it would be the better then just mention in the commit message that.
Mentioning in the cover letter is fine, but each patch needs to also be self-contained.
Quoted 7 lines
Will it be fine to mention instead:
``` Introduction of setup memory management function will require share_xen_page_with_guest() defined, at least, as a stub otherwise the following linkage error will occur... ```
Quoted 5 lines
Quoting the linker error is imo of limited use. What such an explanation
wants to say is why, all of the sudden, such an error occurs. After all
you don't change anything directly related tocommon/trace.c.
if maddr_to_virt() is defined as:
static inline void *maddr_to_virt(paddr_t ma)
{
BUG_ON("unimplemented");
return NULL;
// /* Offset in the direct map, accounting for pdx compression */
// unsigned long va_offset = maddr_to_directmapoff(ma);
// ASSERT(va_offset < DIRECTMAP_SIZE);
// return (void *)(DIRECTMAP_VIRT_START + va_offset); }
Then no stub for share_xen_page_with_privileged_guests() is needed but it isn't clear at all why the definition of maddr_to_virt() affects linkage of share_xen_page_with_privileged_guests().
I tried to look what is the difference after preprocessing stage for common/trace.o and the only difference is in how maddr_to_virt() is implemented:
7574a7575,7577
Quoted 1 line
do { if (__builtin_expect(!!("unimplemented"),0)) do { do { ({ _Static_assert(!((30) >> ((31 - 24) + (31 - 24))), "!(" "(30) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH)" ")"); }); ({ _Static_assert(!((2) >= 4), "!(" "(2) >= BUGFRAME_NR" ")"); }); asm
volatile ( ".Lbug%=:""unimp""\n" " .pushsection
.bug_frames.%""""[bf_type], \"a\", %%progbits\n" " .p2align 2\n"
".Lfrm%=:\n" " .long (.Lbug%= - .Lfrm%=) + %""""[bf_line_hi]\n" "
.long (%""""[bf_ptr] - .Lfrm%=) + %""""[bf_line_lo]\n" " .if " "0"
"\n" " .long 0, %""""[bf_msg] - .Lfrm%=\n" " .endif\n" "
.popsection\n" :: [bf_type] "i" (2), [bf_ptr] "i" ("./arch/riscv/include/asm/mm.h"), [bf_msg] "i" (((void*)0)), [bf_line_lo] "i" (((30) & ((1 << (31 - 24)) - 1)) << 24), [bf_line_hi] "i" (((30) >> (31 - 24)) << 24) ); } while ( 0 ); __builtin_unreachable(); } while ( 0 ); } while (0);
Quoted 2 lines
return ((void*)0);
7578d7580
< unsigned long va_offset = (ma);
7580d7581
< do { if ( __builtin_expect(!!(!(va_offset < ((((vaddr_t)(509))
<< ((3 - 1) * (9) + 12)) - (((vaddr_t)(200)) << ((3 - 1) * (9) + 12))))),0) ) do { do { ({ _Static_assert(!((35) >> ((31 - 24) + (31
- 24))), "!(" "(35) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH)" ")"); }); ({ _Static_assert(!((3) >= 4), "!(" "(3) >= BUGFRAME_NR"
")"); }); asm volatile ( ".Lbug%=:""unimp""\n" " .pushsection
.bug_frames.%""""[bf_type], \"a\", %%progbits\n" " .p2align 2\n"
".Lfrm%=:\n" " .long (.Lbug%= - .Lfrm%=) + %""""[bf_line_hi]\n" "
.long (%""""[bf_ptr] - .Lfrm%=) + %""""[bf_line_lo]\n" " .if " "1"
"\n" " .long 0, %""""[bf_msg] - .Lfrm%=\n" " .endif\n" "
.popsection\n" :: [bf_type] "i" (3), [bf_ptr] "i" ("./arch/riscv/include/asm/mm.h"), [bf_msg] "i" ("va_offset < DIRECTMAP_SIZE"), [bf_line_lo] "i" (((35) & ((1 << (31 - 24)) - 1)) << 24), [bf_line_hi] "i" (((35) >> (31 - 24)) << 24) ); } while ( 0 ); __builtin_unreachable(); } while ( 0 ); } while (0); 7582d7582
< return (void *)((((vaddr_t)(200)) << ((3 - 1) * (9) + 12)) +
va_offset);
Could it be that DCE likely happen when maddr_to_virt() is defined as stub and so code which call share_xen_page_with_privileged_guests() is just eliminated? ( but I am not sure that I know fast way to check that , do you have any pointers? )
~ Oleksii
Re: [PATCH v1 2/5] xen/riscv: implement maddr_to_virt()
In reply to [email protected]Quoted 19 lines · oleksii.kurochko
Quoted 13 lines · Jan Beulich
Quoted 10 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/mm.h +0
-0@@ -25,8 +25,12 @@
static inline void *maddr_to_virt(paddr_t ma)
{
-BUG_ON("unimplemented");
- return NULL;
+ /* Offset in the direct map, accounting for pdx compression */ + unsigned longva_offset=maddr_to_directmapoff(ma);Why the mentioning of PDX compression?
It was mentioned because if PDX will be enabled
maddr_to_directmapoff()will take into account PDX stuff.Quoted 2 lines
At least right now it's unavailable
for RISC-V afaics. Are there plans to change that any time soon?
Quoted 8 lines
At the moment, I don't have such plans, looking at available platform there are no a lot of benefits of having PDX compression now.
Perhaps it would be good to add BUILD_BUG_ON(IS_ENABLED(PDX_COMPRESSION)) for the places which should be updated when
CONFIG_PDXwill be enabled.~ Oleksii
I'd just forget about it unless you ever notice you're wasting a lot of entries in the frame table due to empty space in the memory map. Julien measured the effect on Amazon's Live Migration as a 10% improvement in downtime with PDX off.
PDX compression shines when you have separate RAM banks at very, very disparately far addresses (specifics in pdx.h). Unfortunately the flip side of this compression is that you get several memory accesses for each single pdx-(to/from)-mfn conversion. And we do a lot of those. One possible solution would be to alt-patch the values in the code-stream and avoid the perf-hit, but that's not merged. Jan had some patches but that didn't make it to staging, IIRC.
Cheers,
Alejandro
Re: [PATCH v1 2/5] xen/riscv: implement maddr_to_virt()
Quoted 41 lines · Alejandro Vallejo
Quoted 25 lines · oleksii.kurochko
Quoted 14 lines · Jan Beulich
Quoted 11 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/mm.h +0
-0@@ -25,8 +25,12 @@
static inline void *maddr_to_virt(paddr_t ma)
{
-BUG_ON("unimplemented");
- return NULL;
+ /* Offset in the direct map, accounting for pdx compression */
+ unsigned longva_offset=maddr_to_directmapoff(ma);Why the mentioning of PDX compression?
It was mentioned because if PDX will be enabled
maddr_to_directmapoff()
will take into account PDX stuff.Quoted 2 lines
At least right now it's unavailable
for RISC-V afaics. Are there plans to change that any time soon?At the moment, I don't have such plans, looking at available platform
there are no a lot of benefits of having PDX compression now.Quoted 6 lines
Perhaps it would be good to add BUILD_BUG_ON(IS_ENABLED(PDX_COMPRESSION)) for the places which should
be updated whenCONFIG_PDXwill be enabled.~ Oleksii
I'd just forget about it unless you ever notice you're wasting a lot of entries
in the frame table due to empty space in the memory map. Julien measured the
effect on Amazon's Live Migration as a 10% improvement in downtime with PDX
off.
Quoted 12 lines
PDX compression shines when you have separate RAM banks at very, very disparately far addresses (specifics in
pdx.h). Unfortunately the flip side of
this compression is that you get several memory accesses for each single
pdx-(to/from)-mfn conversion. And we do a lot of those. One possible solution
would be to alt-patch the values in the code-stream and avoid the perf-hit, but
that's not merged. Jan had some patches but that didn't make it to staging,
IIRC.
Could you please give me some links in the mailing list with mentioned patches?
~ Oleksii
Re: [PATCH v1 2/5] xen/riscv: implement maddr_to_virt()
Quoted 54 lines · oleksii.kurochko
Quoted 41 lines · Alejandro Vallejo
Quoted 25 lines · oleksii.kurochko
Quoted 14 lines · Jan Beulich
Quoted 11 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/mm.h +0
-0@@ -25,8 +25,12 @@
static inline void *maddr_to_virt(paddr_t ma)
{
-BUG_ON("unimplemented");
- return NULL;
+ /* Offset in the direct map, accounting for pdx compression */
+ unsigned longva_offset=maddr_to_directmapoff(ma);Why the mentioning of PDX compression?
It was mentioned because if PDX will be enabled
maddr_to_directmapoff()
will take into account PDX stuff.Quoted 2 lines
At least right now it's unavailable
for RISC-V afaics. Are there plans to change that any time soon?At the moment, I don't have such plans, looking at available platform
there are no a lot of benefits of having PDX compression now.Quoted 6 lines
Perhaps it would be good to add BUILD_BUG_ON(IS_ENABLED(PDX_COMPRESSION)) for the places which should
be updated whenCONFIG_PDXwill be enabled.~ Oleksii
I'd just forget about it unless you ever notice you're wasting a lot of entries
in the frame table due to empty space in the memory map. Julien measured the
effect on Amazon's Live Migration as a 10% improvement in downtime with PDX
off.Quoted 12 lines
PDX compression shines when you have separate RAM banks at very, very disparately far addresses (specifics in
pdx.h). Unfortunately the flip side of
this compression is that you get several memory accesses for each single
pdx-(to/from)-mfn conversion. And we do a lot of those. One possible solution
would be to alt-patch the values in the code-stream and avoid the perf-hit, but
that's not merged. Jan had some patches but that didn't make it to staging,
IIRC.
Quoted 4 lines
Could you please give me some links in the mailing list with mentioned patches?
~ Oleksii
Sure.
Much of this was discussed in the "Make PDX compression optional" series. This link is v1, but there were 3 in total and a pre-patch documenting pdx.h explaining what the technique actually does to make sure we were all on the same page (pun intended) and the pdx-off case wouldn't break the world.
https://lore.kernel.org/xen-devel/[email protected]/
This was Jan's 2018 take to turn PDX into alternatives. He mentioned it somewhere in those threads, but I can't find that message anymore.
https://lore.kernel.org/xen-devel/[email protected]/
Cheers,
Alejandro
Re: [PATCH v1 1/5] xen/riscv: add stub for share_xen_page_with_guest()
In reply to [email protected]Quoted 102 lines · On 18.10.2024 17:57, [email protected] wrote:
Quoted 38 lines · Jan Beulich
Quoted 23 lines · On 18.10.2024 15:10, [email protected] wrote:
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Oleksii Kurochko
To avoid the following linkage fail the stub for
share_xen_page_with_guest()
is introduced:Quoted 8 lines
What do you intend to express with "is introduced"? Is there a problem now?
Would there be a problem with subsequent changes? I'm entirely fine
with
adding that stub, but the description should make clear why /when exactly
it's needed.I mentioned that in the cover letter:
``` Also, after patch 3 ("xen/riscv: introduce setup_mm()") of this patch series, the linkage error mentioned in patch 1 ("xen/riscv: add stub for share_xen_page_with_guest()") began to occur, so patch 1 addresses this issue. ```Quoted 2 lines
I thought it would be the better then just mention in the commit message that.
Mentioning in the cover letter is fine, but each patch needs to also be self-contained.
Quoted 7 lines
Will it be fine to mention instead:
``` Introduction of setup memory management function will require share_xen_page_with_guest() defined, at least, as a stub otherwise the following linkage error will occur... ```Quoted 5 lines
Quoting the linker error is imo of limited use. What such an explanation
wants to say is why, all of the sudden, such an error occurs. After all
you don't change anything directly related tocommon/trace.c.if
maddr_to_virt()is defined as:
static inline void *maddr_to_virt(paddr_t ma){ BUG_ON("unimplemented"); return NULL; // /* Offset in the direct map, accounting for pdx compression */ // unsigned long va_offset = maddr_to_directmapoff(ma); // ASSERT(va_offset < DIRECTMAP_SIZE); // return (void *)(DIRECTMAP_VIRT_START + va_offset);}
Then no stub forshare_xen_page_with_privileged_guests()is needed but it isn't clear at all why the definition ofmaddr_to_virt()affects linkage ofshare_xen_page_with_privileged_guests().I tried to look what is the difference after preprocessing stage for
common/trace.oand the only difference is in howmaddr_to_virt()is implemented:7574a7575,7577 > do { if (__builtin_expect(!!("unimplemented"),0)) do { do { ({ _Static_assert(!((30) >> ((31 - 24) + (31 - 24))), "!(" "(30) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH)" ")"); }); ({ _Static_assert(!((2) >= 4), "!(" "(2) >= BUGFRAME_NR" ")"); }); asm volatile ( ".Lbug%=:""unimp""\n" " .pushsection .bug_frames.%""""[bf_type], \"a\", %%progbits\n" " .p2align 2\n" ".Lfrm%=:\n" " .long (.Lbug%= - .Lfrm%=) + %""""[bf_line_hi]\n" " .long (%""""[bf_ptr] - .Lfrm%=) + %""""[bf_line_lo]\n" " .if " "0" "\n" " .long 0, %""""[bf_msg] - .Lfrm%=\n" " .endif\n" " .popsection\n" :: [bf_type] "i" (2), [bf_ptr] "i" ("./arch/riscv/include/asm/mm.h"), [bf_msg] "i" (((void*)0)), [bf_line_lo] "i" (((30) & ((1 << (31 - 24)) - 1)) << 24), [bf_line_hi] "i" (((30) >> (31 - 24)) << 24) ); } while ( 0 ); __builtin_unreachable(); } while ( 0 ); } while (0); > return ((void*)0); > 7578d7580 < unsigned long va_offset = (ma); 7580d7581 < do { if ( __builtin_expect(!!(!(va_offset < ((((vaddr_t)(509)) << ((3 - 1) * (9) + 12)) - (((vaddr_t)(200)) << ((3 - 1) * (9) + 12))))),0) ) do { do { ({ _Static_assert(!((35) >> ((31 - 24) + (31 - 24))), "!(" "(35) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH)" ")"); }); ({ _Static_assert(!((3) >= 4), "!(" "(3) >= BUGFRAME_NR" ")"); }); asm volatile ( ".Lbug%=:""unimp""\n" " .pushsection .bug_frames.%""""[bf_type], \"a\", %%progbits\n" " .p2align 2\n" ".Lfrm%=:\n" " .long (.Lbug%= - .Lfrm%=) + %""""[bf_line_hi]\n" " .long (%""""[bf_ptr] - .Lfrm%=) + %""""[bf_line_lo]\n" " .if " "1" "\n" " .long 0, %""""[bf_msg] - .Lfrm%=\n" " .endif\n" " .popsection\n" :: [bf_type] "i" (3), [bf_ptr] "i" ("./arch/riscv/include/asm/mm.h"), [bf_msg] "i" ("va_offset < DIRECTMAP_SIZE"), [bf_line_lo] "i" (((35) & ((1 << (31 - 24)) - 1)) << 24), [bf_line_hi] "i" (((35) >> (31 - 24)) << 24) ); } while ( 0 ); __builtin_unreachable(); } while ( 0 ); } while (0); 7582d7582 < return (void *)((((vaddr_t)(200)) << ((3 - 1) * (9) + 12)) + va_offset);
Quoted 4 lines
Could it be that DCE likely happen when
maddr_to_virt()is defined as stub and so code which callshare_xen_page_with_privileged_guests()is just eliminated? ( but I am not sure that I know fast way to check that , do you have any pointers? )
Yes, I think DCE is the explanation here. And that's what (imo) wants saying in the description.
Jan
Re: [PATCH v1 3/5] xen/riscv: introduce setup_mm()
In reply to [email protected]Quoted 23 lines · On 18.10.2024 16:27, [email protected] wrote:
Quoted 22 lines · Jan Beulich
Quoted 1 line · Oleksii Kurochko
+vaddr_t
directmap_virt_end__read_mostly;
__ro_after_init? And moved ahead of the identifier, just like ...Quoted 6 lines
+/*
+ * Setup memory management
+ *
+ * RISC-V 64 has a large virtual address space (the minimum supported
+ * MMU mode is Sv39, which provides TBs of VA space).Quoted 8 lines
+ * In the case of RISC-V 64, the directmap and frametable are mapped
+ * starting from physical address 0 to simplify thepage_to_mfn(),
+ *mfn_to_page(), andmaddr_to_virt()calculations, as there is no need
+ * to account for {directmap, frametable}_base_pdx in this setup.
+ */
+void__initsetup_mm(void)...
__initis placed e.g. here.
Quoted 3 lines
Quoted 1 line
It's also unclear why the variable needs to be non-static.
As it could be use then for some
ASSERT(), for example, invirt_to_page()as Arm or x86 do.
"Could be" is too little here. Misra dislikes identifiers which could be static, but aren't. If it's not used right now (nor any time soon), it should imo be static until a use appears requiring it to be globally visible.
Quoted 53 lines
Quoted 32 lines
Quoted 20 lines
xen/arch/riscv/mm.c +8
-0+{ + const struct membanks *banks = bootinfo_get_mem(); + paddr_t ram_end = 0; + paddr_t ram_size = 0; + unsigned int i; + + /* +* We need some memory to allocate the page-tables used for the directmap
+ * mappings. But some regions may contain memory already allocated
+ * for other uses (e.g. modules, reserved-memory...). + *
+ * For simplicity, add all the free regions in the boot allocator.
+ */
+populate_boot_allocator();xen/arch/riscv/mm.c +3
-0+ + total_pages = 0; +xen/arch/riscv/mm.c void * __init early_fdt_map(paddr_t fdt_paddr) · line 506
Quoted 10 lines
xen/arch/riscv/mm.c +10
-0+ for ( i = 0; i < banks->nr_banks; i++ ) + { + const struct membank *bank = &banks->bank[i]; + paddr_t bank_end = bank->start + bank->size; + + ram_size = ram_size + bank->size; + ram_end = max(ram_end, bank_end); + } + + setup_directmap_mappings(PFN_DOWN(ram_end));While you may want to use non-offset-ed mappings, I can't see how you
Quoted 8 lines
can
validly map just a single huge chunk, no matter whether there are holes
in there. Such holes could hold MMIO regions, which I'm sure would require
more careful mapping (to avoid cacheable accesses, or even speculative
ones).My intention was to avoid subraction of
directmap_start( =ram_start) inmaddr_to_virt()to have less operations during maddr to virt calculation:static inline void *maddr_to_virt(paddr_t ma) { /* Offset in the direct map, accounting for pdx compression */ unsigned long va_offset = maddr_to_directmapoff(ma); ASSERT(va_offset < DIRECTMAP_SIZE); return (void *)(DIRECTMAP_VIRT_START /* - directmap_start */ + va_offset); }
Quoted 6 lines
But it seems I don't have any chance to avoid that because of mentioned by you reasons... Except probably to have a config which will hard code
RAM_STARTfor each platform ( what on other hand will make Xen less flexible in some point ).
Does it make sense to have a config instead of identifyingram_startin runtime?
I don't think building Xen for just one (kind of) platform is going to be overly useful (except maybe for development purposes, yet the goal ought to be to be flexible, and hence it may be a bad idea even while developing new code).
Jan