RISCV: enable DOMAIN_BUILD_HELPERS
cover RISCV: enable DOMAIN_BUILD_HELPERS
Introduce necessary things to enable DOMAIN_BUILD_HELPERS config for RISC-V.
Generally it is indepenent patch series from [1] and [2] but depends on which patches will go first it could be some merge conflicts.
At the moment, patch series is rebased on top of [2]:
staging -> [1] -> [2] -> current patch series.
[1] https://lore.kernel.org/xen-devel/[email protected]/T/#t
[2] https://lore.kernel.org/xen-devel/[email protected]/T/#t
Oleksii Kurochko (6):
xen/riscv: implement get_page_from_gfn()
xen/riscv: implement copy_to_guest_phys()
xen/riscv: add zImage kernel loading support
xen: move declaration of fw_unreserved_regions() to common header
xen: move domain_use_host_layout() to common header xen/riscv: enable DOMAIN_BUILD_HELPERS
xen/arch/arm/include/asm/domain.h | 14 -- xen/arch/arm/include/asm/setup.h | 3 - xen/arch/riscv/Kconfig | 1 + xen/arch/riscv/Makefile | 2 + xen/arch/riscv/guestcopy.c | 112 ++++++++++++++++ xen/arch/riscv/include/asm/config.h | 13 ++ xen/arch/riscv/include/asm/guest_access.h | 7 + xen/arch/riscv/include/asm/p2m.h | 11 +- xen/arch/riscv/kernel.c | 156 ++++++++++++++++++++++ xen/arch/riscv/p2m.c | 34 +++++ xen/include/public/arch-riscv.h | 8 ++ xen/include/xen/bootinfo.h | 4 + xen/include/xen/domain.h | 16 +++ 13 files changed, 358 insertions(+), 23 deletions(-) create mode 100644 xen/arch/riscv/guestcopy.c create mode 100644 xen/arch/riscv/kernel.c
Signature · 1 line
2.52.0
PATCH 2/6 xen/riscv: implement copy_to_guest_phys()
Introduce copy_to_guest_phys() for RISC-V, based on the Arm implementation.
Add a generic copy_guest() helper for copying to and from guest physical (and potentially virtual addresses in the future), and implement translate_get_page() to translate a guest physical address into a struct page_info via the domain p2m.
Compared to the Arm code:
- Drop COPY_flush_dcache(), as no such use cases exist on RISC-V.
- Do not implement the linear mapping case, which is currently unused.
- Use PAGE_OFFSET() to initialize the local offset variable in copy_guest().
--- xen/arch/riscv/Makefile | 1 + xen/arch/riscv/guestcopy.c | 112 ++++++++++++++++++++++ xen/arch/riscv/include/asm/guest_access.h | 7 ++ 3 files changed, 120 insertions(+) create mode 100644 xen/arch/riscv/guestcopy.c
xen/arch/riscv/Makefile +1 -0
@@ -3,6 +3,7 @@ obj-y += cpufeature.o obj-y += domain.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-y += entry.o +obj-y += guestcopy.o obj-y += imsic.o obj-y += intc.o obj-y += irq.o
xen/arch/riscv/guestcopy.c new file +112 -0
112 lines not on this page · raw message
xen/arch/riscv/include/asm/guest_access.h +7 -0
@@ -2,6 +2,10 @@#ifndef ASM__RISCV__GUEST_ACCESS_H #define ASM__RISCV__GUEST_ACCESS_H +#include <xen/types.h> + +struct domain ; +unsigned long raw_copy_to_guest (void *to,const void *from,unsigned len);unsigned long raw_copy_from_guest (void *to,const void *from,unsigned len);unsigned long raw_clear_guest (void *to,unsigned int len);
@@ -18,6 +22,9 @@ unsigned long raw_clear_guest(void *to, unsigned int len);#define guest_handle_okay (hnd, nr) (1)#define guest_handle_subrange_okay (hnd, first, last) (1) +unsigned long copy_to_guest_phys (struct domain *d,paddr_t gpa,void *buf, +unsigned int len); +#endif /* ASM__RISCV__GUEST_ACCESS_H */ /* * Local variables:
Signature · 1 line
2.52.0
PATCH 1/6 xen/riscv: implement get_page_from_gfn()
In reply to Oleksii KurochkoProvide a RISC-V implementation of get_page_from_gfn(), matching the semantics used by other architectures.
For translated guests, this is implemented as a wrapper around p2m_get_page_from_gfn(). For DOMID_XEN, which is not auto-translated, provide a 1:1 RAM/MMIO mapping and perform the required validation and reference counting.
The function is implemented out-of-line rather than as a static inline, to avoid header ordering issues where struct domain is incomplete when asm/p2m.h is included, leading to build failures:
In file included from ./arch/riscv/include/asm/domain.h:10,
from ./include/xen/domain.h:16,
from ./include/xen/sched.h:11,
from ./include/xen/event.h:12,
from common/cpu.c:3:
./arch/riscv/include/asm/p2m.h: In function 'get_page_from_gfn':
./arch/riscv/include/asm/p2m.h:50:33: error: invalid use of undefined type 'struct domain'
50 | #define p2m_get_hostp2m(d) (&(d)->arch.p2m)
| ^~
./arch/riscv/include/asm/p2m.h:180:38: note: in expansion of macro 'p2m_get_hostp2m'
180 | return p2m_get_page_from_gfn(p2m_get_hostp2m(d), _gfn(gfn), t);
| ^~~~~~~~~~~~~~~ make[2]: *** [Rules.mk:253: common/cpu.o] Error 1 make[1]: *** [build.mk:72: common] Error 2
make: *** [Makefile:623: xen] Error 2
---
Does it make sense to make this function almost fully generic?
It looks like most of the logic here is architecture-independent and identical across architectures, except for the following points:
1. ```
if ( likely(d != dom_xen) )
```
This could be made generic by introducing paging_mode_translate() for ARM
and defining it as `(d != dom_xen)` there.
2. ```
if ( t )
*t = likely(d != dom_io) ? p2m_ram_rw : p2m_mmio_direct_io;
``` Here, only p2m_mmio_direct_io appears to be architecture-specific. This could be abstracted via a helper such as dom_io_p2m_type() and used here instead.
---
--- xen/arch/riscv/include/asm/p2m.h | 8 ++------ xen/arch/riscv/p2m.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-)
xen/arch/riscv/include/asm/p2m.h +2 -6
@@ -171,12 +171,8 @@ typedef unsigned int p2m_query_t;#define P2M_ALLOC (1u<<0)/* Populate PoD and paged-out entries */ #define P2M_UNSHARE (1u<<1)/* Break CoW sharing */ -static inline struct page_info *get_page_from_gfn ( -struct domain *d,unsigned long gfn,p2m_type_t *t,p2m_query_t q) -{ -BUG_ON ("unimplemented" ); -return NULL ; -} +struct page_info *get_page_from_gfn (struct domain *d,unsigned long gfn, +p2m_type_t *t,p2m_query_t q);static inline void memory_type_changed (struct domain *d) {
xen/arch/riscv/p2m.c +28 -0
@@ -1557,3 +1557,31 @@ void p2m_handle_vmenter(void)flush_tlb_guest_local (); } } + +struct page_info *get_page_from_gfn (struct domain *d,unsigned long gfn, +p2m_type_t *t,p2m_query_t q) +{ +struct page_info *page; + +/* +* Special case for DOMID_XEN as it is the only domain so far that is +* not auto-translated. +*/ +if (likely (d != dom_xen) ) +return p2m_get_page_from_gfn (p2m_get_hostp2m (d),_gfn (gfn), t); + +/* Non-translated guests see 1-1 RAM / MMIO mappings everywhere */ + +if ( t ) + *t = p2m_invalid; + + page =mfn_to_page (_mfn (gfn)); + +if ( !mfn_valid (_mfn (gfn)) || !get_page (page, d) ) +return NULL ; + +if ( t ) + *t =likely (d != dom_io) ? p2m_ram_rw : p2m_mmio_direct_io; + +return page; +}
Signature · 1 line
2.52.0
PATCH 3/6 xen/riscv: add zImage kernel loading support
In reply to Oleksii KurochkoIntroduce support for loading a Linux zImage kernel on RISC-V.
Note that if panic() is used instead of returning an error as common code doesn't expect to have return code and it is something that should be done separately.
This prepares the RISC-V port for booting Linux guests using the common domain build infrastructure.
The code is based on Xen Arm code.
--- xen/arch/riscv/Makefile | 1 + xen/arch/riscv/include/asm/config.h | 13 +++ xen/arch/riscv/kernel.c | 156 ++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 xen/arch/riscv/kernel.c
xen/arch/riscv/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-y += guestcopy.o obj-y += imsic.o obj-y += intc.o obj-y += irq.o +obj-y += kernel.o obj-y += mm.o obj-y += p2m.o obj-y += paging.o
xen/arch/riscv/include/asm/config.h +13 -0
@@ -152,6 +152,19 @@extern unsigned long phys_offset;/* = load_start - XEN_VIRT_START */ #endif +/* +* KERNEL_LOAD_ADDR_ALIGNMENT is defined based on paragraph of +* "Kernel location" of boot.rst: +* https://docs.kernel.org/arch/riscv/boot.html#kernel-location +*/ +#if defined(CONFIG_RISCV_32 ) +#define KERNEL_LOAD_ADDR_ALIGNMENT MB(4) +#elif defined(CONFIG_RISCV_64 ) +#define KERNEL_LOAD_ADDR_ALIGNMENT MB(2) +#else +#error "Define KERNEL_LOAD_ADDR_ALIGNMENT" +#endif +#endif /* ASM__RISCV__CONFIG_H */ /* * Local variables:
xen/arch/riscv/kernel.c new file +156 -0
156 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH 5/6 xen: move domain_use_host_layout() to common header
In reply to Oleksii Kurochkodomain_use_host_layout() is generic enough to be moved to the common header xen/domain.h.
Wrap domain_use_host_layout() with "#ifndef domain_use_host_layout" to allow architectures to override it if needed.
No functional change.
--- xen/arch/arm/include/asm/domain.h | 14 -------------- xen/include/xen/domain.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 14 deletions(-)
xen/arch/arm/include/asm/domain.h +0 -14
@@ -29,20 +29,6 @@ enum domain_type {#define is_64bit_domain (d) (0)#endif -/* -* Is the domain using the host memory layout? -* -* Direct-mapped domain will always have the RAM mapped with GFN == MFN. -* To avoid any trouble finding space, it is easier to force using the -* host memory layout. -* -* The hardware domain will use the host layout regardless of -* direct-mapped because some OS may rely on a specific address ranges -* for the devices. -*/ -#define domain_use_host_layout (d) (is_domain_direct_mapped(d) || \ - is_hardware_domain(d)) -struct vtimer {struct vcpu *v;int irq;
xen/include/xen/domain.h +16 -0
@@ -62,6 +62,22 @@ void domid_free(domid_t domid);#define is_domain_direct_mapped (d) ((d)->cdf & CDF_directmap)#define is_domain_using_staticmem (d) ((d)->cdf & CDF_staticmem) +/* +* Is the domain using the host memory layout? +* +* Direct-mapped domain will always have the RAM mapped with GFN == MFN. +* To avoid any trouble finding space, it is easier to force using the +* host memory layout. +* +* The hardware domain will use the host layout regardless of +* direct-mapped because some OS may rely on a specific address ranges +* for the devices. +*/ +#ifndef domain_use_host_layout +# define domain_use_host_layout (d) (is_domain_direct_mapped(d) || \ + is_hardware_domain(d)) +#endif +/* * Arch-specifics. */
Signature · 1 line
2.52.0
PATCH 6/6 xen/riscv: enable DOMAIN_BUILD_HELPERS
In reply to Oleksii KurochkoTo enable DOMAIN_BUILD_HELPERS for RISC-V the following is introduced:
- Add a global p2m_ipa_bits variable, initialized to PADDR_BITS, to represent the maximum supported IPA size as find_unallocated_memory() requires it.
- Define default guest RAM layout parameters in the public RISC-V header as it is required by allocate_memory().
--- xen/arch/riscv/Kconfig | 1 + xen/arch/riscv/include/asm/p2m.h | 3 +++ xen/arch/riscv/p2m.c | 6 ++++++ xen/include/public/arch-riscv.h | 8 ++++++++ 4 files changed, 18 insertions(+)
xen/arch/riscv/Kconfig +1 -0
@@ -1,5 +1,6 @@ config RISCV def_bool y + select DOMAIN_BUILD_HELPERS select FUNCTION_ALIGNMENT_16B select GENERIC_BUG_FRAME select GENERIC_UART_INIT
xen/arch/riscv/include/asm/p2m.h +3 -0
@@ -44,6 +44,9 @@#define P2M_LEVEL_MASK (p2m, lvl) \ (P2M_TABLE_OFFSET(p2m, lvl) << P2M_GFN_LEVEL_SHIFT(lvl)) +/* Holds the bit size of IPAs in p2m tables */ +extern unsigned int p2m_ipa_bits; +#define paddr_bits PADDR_BITS/* Get host p2m table */
xen/arch/riscv/p2m.c +6 -0
@@ -51,6 +51,12 @@ static struct gstage_mode_desc __ro_after_init max_gstage_mode = { .name = "Bare", }; +/* +* Set to the maximum configured support for IPA bits, so the number of IPA bits can be +* restricted by external entity (e.g. IOMMU). +*/ +unsigned int __read_mostly p2m_ipa_bits =PADDR_BITS ; +static void p2m_free_page (struct p2m_domain *p2m,struct page_info *pg); static inline void p2m_free_metadata_page(struct p2m_domain *p2m,
xen/include/public/arch-riscv.h +8 -0
@@ -50,6 +50,14 @@ typedef uint64_t xen_ulong_t;#if defined(__XEN__) || defined(__XEN_TOOLS__) +#define GUEST_RAM_BANKS 1 + +#define GUEST_RAM0_BASE xen_mk_ullong(0x80000000)/* 2GB of low RAM @ 2GB */ +#define GUEST_RAM0_SIZE xen_mk_ullong(0x80000000) + +#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE } +#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE } +struct vcpu_guest_context { };typedef struct vcpu_guest_context vcpu_guest_context_t ;
Signature · 1 line
2.52.0
PATCH 4/6 xen: move declaration of fw_unreserved_regions() to common header
In reply to Oleksii KurochkoSince the implementation of fw_unreserved_regions() is in common code, move its declaration to xen/bootinfo.h.
--- xen/arch/arm/include/asm/setup.h | 3 --- xen/include/xen/bootinfo.h | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-)
xen/arch/arm/include/asm/setup.h +0 -3
@@ -43,9 +43,6 @@ int acpi_make_efi_nodes(void *fdt, struct membank tbl_add[]);void create_dom0 (void );void discard_initial_modules (void ); -void fw_unreserved_regions (paddr_t s,paddr_t e, -void (*cb)(paddr_t ps,paddr_t pe), -unsigned int first);void init_pdx (void );void setup_mm (void );
xen/include/xen/bootinfo.h +4 -0
@@ -210,4 +210,8 @@ static inline struct membanks *membanks_xzalloc(unsigned int nr, return banks; } +void fw_unreserved_regions (paddr_t s,paddr_t e, +void (*cb)(paddr_t ps,paddr_t pe), +unsigned int first); +#endif /* XEN_BOOTINFO_H */
Signature · 1 line
2.52.0
Re: [PATCH v1 6/6] xen/riscv: enable DOMAIN_BUILD_HELPERS
In reply to Oleksii Kurochkoxen/arch/riscv/include/asm/p2m.h line 48
Quoted 8 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/p2m.h +2
-0@@ -44,6 +44,9 @@#define P2M_LEVEL_MASK (p2m, lvl) \ (P2M_TABLE_OFFSET(p2m, lvl) << P2M_GFN_LEVEL_SHIFT(lvl)) +/* Holds the bit size of IPAs in p2m tables */ +extern unsigned int p2m_ipa_bits;
Hmm, I can spot a declaration and ...
xen/arch/riscv/p2m.c static struct gstage_mode_desc __ro_after_init max_gstage_mode = { · line 58
Quoted 11 lines
xen/arch/riscv/p2m.c +5
-0@@ -51,6 +51,12 @@ static struct gstage_mode_desc __ro_after_init max_gstage_mode = { .name = "Bare", }; +/* +* Set to the maximum configured support for IPA bits, so the number of IPA bits can be +* restricted by external entity (e.g. IOMMU). +*/ +unsigned int __read_mostly p2m_ipa_bits =PADDR_BITS ;
... a definition, but neither a use nor a place where the variable would be set. Hmm, yes, I see common/device-tree/domain-build.c uses it. Then the following questions arise:
- What does "ipa" stand for? Is this a term sensible in RISC-V context at all? Judging from the comment at the decl, isn't it PPN width (plus PAGE_SHIFT) that it describes?
- With there not being anyone writing to the variable, why is it not const (or even a #define), or at the very least __ro_after_init?
And no, "Arm has it like this" doesn't count as an answer. Considering all the review comments you've got so far you should know by now that you shouldn't copy things blindly.
xen/include/public/arch-riscv.h typedef uint64_t xen_ulong_t; · line 59
Quoted 13 lines
xen/include/public/arch-riscv.h +7
-0@@ -50,6 +50,14 @@ typedef uint64_t xen_ulong_t;#if defined(__XEN__) || defined(__XEN_TOOLS__) +#define GUEST_RAM_BANKS 1 + +#define GUEST_RAM0_BASE xen_mk_ullong(0x80000000)/* 2GB of low RAM @ 2GB */ +#define GUEST_RAM0_SIZE xen_mk_ullong(0x80000000) + +#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE } +#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE }
Hmm, does RISC-V really want to go with compile-time constants here? And if so, why would guests be limited to just 2 Gb? That may more efficiently be RV32 guests then, with perhaps just an RV32 hypervisor.
Jan
Re: [PATCH v1 6/6] xen/riscv: enable DOMAIN_BUILD_HELPERS
Quoted 17 lines · Jan Beulich
xen/arch/riscv/include/asm/p2m.h line 48
Quoted 8 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/p2m.h +2
-0@@ -44,6 +44,9 @@#define P2M_LEVEL_MASK (p2m, lvl) \ (P2M_TABLE_OFFSET(p2m, lvl) << P2M_GFN_LEVEL_SHIFT(lvl)) +/* Holds the bit size of IPAs in p2m tables */ +extern unsigned int p2m_ipa_bits;Hmm, I can spot a declaration and ...
Quoted 6 lines
xen/arch/riscv/p2m.c +0
-0@@ -51,6 +51,12 @@ static struct gstage_mode_desc __ro_after_init max_gstage_mode = { .name = "Bare", };
Quoted 10 lines
xen/arch/riscv/p2m.c static struct gstage_mode_desc __ro_after_init max_gstage_mode = { · line 58
Quoted 5 lines
xen/arch/riscv/p2m.c +5
-0+/* +* Set to the maximum configured support for IPA bits, so the number of IPA bits can be +* restricted by external entity (e.g. IOMMU). +*/ +unsigned int __read_mostly p2m_ipa_bits =PADDR_BITS ;... a definition, but neither a use nor a place where the variable would be set. Hmm, yes, I see
common/device-tree/domain-build.cuses it. Then the following questions arise:
- What does "ipa" stand for? Is this a term sensible in RISC-V context at all?
IPA stands for GPA. (maybe it would better to rename the in common code to gpa too). It was used as common code uses p2m_ipa_bits.
Yes, I miss to set p2m_ipa_bits properly in p2m_init() where G-stage MMU mode is set.
Quoted 2 lines
Judging from the comment at the decl, isn't it PPN width (plus
PAGE_SHIFT) that it describes?
It is PPN width + PAGE_SHIFT what is equal to PADDR_BITS (44bit PPN + 12 bit PAGE_SHIFT).
Quoted 5 lines
- With there not being anyone writing to the variable, why is it not const (or even a #define), or at the very least
__ro_after_init?
And no, "Arm has it like this" doesn't count as an answer. Considering all the review comments you've got so far you should know by now that you shouldn't copy things blindly.
It was added because of the usage in common/device-tree/domain-build.c.
It was done in the same way as it is also possible that an IOMMU shares the P2M page tables with the CPU's G-stage(stage-2) translation, so GPA size must not exceed what the IOMMU can handle (or G-stage address limitation if it is smaller then IOMMU's).
(a) It could be that MMU uses Sv57, IOMMU uses Sv39, so in this case if IOMMU and MMU shares G-stae page tables it is necessary to respect guest address limitation.
But considering that according to RISC-V IOMMU spec ... :
The IOMMU must support all the virtual memory extensions that are supported by any of the harts in the system.
... (a) isn't real issue as we could always program IOMMU to use the same as MMU mode and then p2m_ipa_bits __ro_after_init should work well. It can't be const as I mentioned above I missed to initialize it properly in p2m_init() code. (It is also a case for RISC-V that IOMMU could use x4 mode, so MMU uses Sv57 and IOMMU uses Sv57x4.)
Quoted 6 lines
Quoted 6 lines
xen/include/public/arch-riscv.h +0
-0@@ -50,6 +50,14 @@ typedef uint64_t xen_ulong_t;#if defined(__XEN__) || defined(__XEN_TOOLS__)
Quoted 8 lines
xen/include/public/arch-riscv.h typedef uint64_t xen_ulong_t; · line 59
Quoted 7 lines
xen/include/public/arch-riscv.h +7
-0+#define GUEST_RAM_BANKS 1 + +#define GUEST_RAM0_BASE xen_mk_ullong(0x80000000)/* 2GB of low RAM @ 2GB */ +#define GUEST_RAM0_SIZE xen_mk_ullong(0x80000000) + +#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE } +#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE }Hmm, does RISC-V really want to go with compile-time constants here?
It is needed for allocate_memory() for guest domains, so it is expected to be compile-time constant with the current code of common dom0less approach.
It represents the start of RAM address for DomU and the maximum RAM size (the actual size will be calculated based on what is mentioned in DomU node in dts) and then will be used to generate memory node for DomU (GUEST_RAM0_BASE as RAM start address and min(GUEST_RAM0_SIZE, dts->domU->memory->size) as a RAM size).
Quoted 2 lines
And
if so, why would guests be limited to just 2 Gb?
It is enough for guest domain I am using in dom0less mode.
Quoted 2 lines
That may more efficiently
be RV32 guests then, with perhaps just an RV32 hypervisor.
I didn't get this point. Could you please explain differently what do you mean?
~ Oleksii
Re: [PATCH v1 6/6] xen/riscv: enable DOMAIN_BUILD_HELPERS
Quoted 39 lines · Oleksii Kurochko
Quoted 17 lines · Jan Beulich
xen/arch/riscv/include/asm/p2m.h line 48
Quoted 8 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/p2m.h +2
-0@@ -44,6 +44,9 @@#define P2M_LEVEL_MASK (p2m, lvl) \ (P2M_TABLE_OFFSET(p2m, lvl) << P2M_GFN_LEVEL_SHIFT(lvl)) +/* Holds the bit size of IPAs in p2m tables */ +extern unsigned int p2m_ipa_bits;Hmm, I can spot a declaration and ...
Quoted 6 lines
xen/arch/riscv/p2m.c +0
-0@@ -51,6 +51,12 @@ static struct gstage_mode_desc __ro_after_init max_gstage_mode = { .name = "Bare", };Quoted 10 lines
xen/arch/riscv/p2m.c static struct gstage_mode_desc __ro_after_init max_gstage_mode = { · line 58
Quoted 5 lines
xen/arch/riscv/p2m.c +5
-0+/* +* Set to the maximum configured support for IPA bits, so the number of IPA bits can be +* restricted by external entity (e.g. IOMMU). +*/ +unsigned int __read_mostly p2m_ipa_bits =PADDR_BITS ;... a definition, but neither a use nor a place where the variable would be set. Hmm, yes, I see
common/device-tree/domain-build.cuses it. Then the following questions arise:
- What does "ipa" stand for? Is this a term sensible in RISC-V context at all?IPA stands for GPA. (maybe it would better to rename the in common code to gpa too). It was used as common code uses
p2m_ipa_bits.Yes, I miss to set
p2m_ipa_bitsproperly inp2m_init()where G-stage MMU mode is set.Quoted 2 lines
Judging from the comment at the decl, isn't it PPN width (plus
PAGE_SHIFT) that it describes?It is PPN width +
PAGE_SHIFTwhat is equal toPADDR_BITS(44bit PPN + 12 bitPAGE_SHIFT).
Quoted 7 lines
Quoted 5 lines
- With there not being anyone writing to the variable, why is it not const (or even a #define), or at the very least
__ro_after_init?
And no, "Arm has it like this" doesn't count as an answer. Considering all the review comments you've got so far you should know by now that you shouldn't copy things blindly.It was added because of the usage in
common/device-tree/domain-build.c.
Well, I understand that, but this isn't the way to do. And you've been through such before. Anything you want to share between arch-es that isn't shared yet, will want some suitable abstraction done. Like giving variables names which are appropriate independent of the arch.
Quoted 25 lines
Quoted 6 lines
Quoted 6 lines
xen/include/public/arch-riscv.h +0
-0@@ -50,6 +50,14 @@ typedef uint64_t xen_ulong_t;#if defined(__XEN__) || defined(__XEN_TOOLS__)Quoted 8 lines
xen/include/public/arch-riscv.h typedef uint64_t xen_ulong_t; · line 59
Quoted 7 lines
xen/include/public/arch-riscv.h +7
-0+#define GUEST_RAM_BANKS 1 + +#define GUEST_RAM0_BASE xen_mk_ullong(0x80000000)/* 2GB of low RAM @ 2GB */ +#define GUEST_RAM0_SIZE xen_mk_ullong(0x80000000) + +#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE } +#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE }Hmm, does RISC-V really want to go with compile-time constants here?
It is needed for
allocate_memory()for guest domains, so it is expected to be compile-time constant with the current code of common dom0less approach.It represents the start of RAM address for DomU and the maximum RAM size (the actual size will be calculated based on what is mentioned in DomU node in dts) and then will be used to generate memory node for DomU (
GUEST_RAM0_BASEas RAM start address andmin(GUEST_RAM0_SIZE, dts->domU->memory->size)as a RAM size).
Quoted 4 lines
Quoted 2 lines
And
if so, why would guests be limited to just 2 Gb?It is enough for guest domain I am using in dom0less mode.
And what others may want to use RISC-V for once it actually becomes usable isn't relevant? As you start adding things to the public headers, you will need to understand that you can't change easily what once was put there. Everything there is part of the ABI, and the ABI needs to remain stable (within certain limits).
Quoted 5 lines
Quoted 2 lines
That may more efficiently
be RV32 guests then, with perhaps just an RV32 hypervisor.I didn't get this point. Could you please explain differently what do you mean?
If all you want are 2Gb guests, why would such guests be 64-bit? And with (iirc) RV32 permitting more than 4Gb (via PPN being 22 bits wide), perhaps even a 32-bit hypervisor would suffice?
Jan
Re: [PATCH v1 1/6] xen/riscv: implement get_page_from_gfn()
In reply to Oleksii KurochkoQuoted 23 lines · Oleksii Kurochko
Provide a RISC-V implementation of
get_page_from_gfn(), matching the semantics used by other architectures.For translated guests, this is implemented as a wrapper around
p2m_get_page_from_gfn(). ForDOMID_XEN, which is not auto-translated, provide a 1:1 RAM/MMIO mapping and perform the required validation and reference counting.The function is implemented out-of-line rather than as a static inline, to avoid header ordering issues where struct domain is incomplete when
asm/p2m.his included, leading to build failures:
In file included from./arch/riscv/include/asm/domain.h:10,from ./include/xen/domain.h:16, from ./include/xen/sched.h:11, from ./include/xen/event.h:12, from common/cpu.c:3: ./arch/riscv/include/asm/p2m.h: In function 'get_page_from_gfn': ./arch/riscv/include/asm/p2m.h:50:33: error: invalid use of undefined type 'struct domain' 50 | #define p2m_get_hostp2m(d) (&(d)->arch.p2m) | ^~ ./arch/riscv/include/asm/p2m.h:180:38: note: in expansion of macro 'p2m_get_hostp2m' 180 | return p2m_get_page_from_gfn(p2m_get_hostp2m(d), _gfn(gfn), t); | ^~~~~~~~~~~~~~~
Quoted 3 lines
make[2]: *** [Rules.mk:253:
common/cpu.o] Error 1 make[1]: *** [build.mk:72: common] Error 2
make: *** [Makefile:623: xen] Error 2
Surely this can be addressed, when x86 and Arm have the function as inline?
Quoted 19 lines
Signed-off-by Oleksii Kurochko <[email protected]>---
Does it make sense to make this function almost fully generic?It looks like most of the logic here is architecture-independent and identical across architectures, except for the following points:
1. ```
if (likely(d != dom_xen))``` This could be made generic by introducing paging_mode_translate() for ARM and defining it as `(d != dom_xen)` there. 2. ``` if ( t ) *t = likely(d != dom_io) ? p2m_ram_rw : p2m_mmio_direct_io; ```
Quoted 3 lines
Here, only
p2m_mmio_direct_ioappears to be architecture-specific. This could be abstracted via a helper such asdom_io_p2m_type()and used here instead.
With P2M stuff I'd be careful. Abstracting the two aspects above may make future arch-specific changes there more difficult.
Quoted 6 lines
xen/arch/riscv/p2m.c +0
-0@@ -1557,3 +1557,31 @@ void p2m_handle_vmenter(void)flush_tlb_guest_local (); } }
xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1569
Quoted 10 lines
xen/arch/riscv/p2m.c +10
-0+ +struct page_info *get_page_from_gfn (struct domain *d,unsigned long gfn, +p2m_type_t *t,p2m_query_t q) +{ +struct page_info *page; + +/* +* Special case for DOMID_XEN as it is the only domain so far that is +* not auto-translated. +*/
Once again something taken verbatim from Arm. Yes, dom_xen can in fact appear here, but it's not a real domain, has no memory truly assigned to it, has no GFN space, and hence calling it translated (or not) is simply wrong (at best:
misleading). IOW ...
xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1573
Quoted 4 lines
xen/arch/riscv/p2m.c +4
-0+if (likely (d != dom_xen) ) +return p2m_get_page_from_gfn (p2m_get_hostp2m (d),_gfn (gfn), t); + +/* Non-translated guests see 1-1 RAM / MMIO mappings everywhere */
... this comment would also want re-wording.
xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1584
Quoted 10 lines
xen/arch/riscv/p2m.c +10
-0+if ( t ) + *t = p2m_invalid; + + page =mfn_to_page (_mfn (gfn)); + +if ( !mfn_valid (_mfn (gfn)) || !get_page (page, d) ) +return NULL ; + +if ( t ) + *t =likely (d != dom_io) ? p2m_ram_rw : p2m_mmio_direct_io;
If only dom_xen can make it here, why the check for dom_io?
Jan
Re: [PATCH v1 1/6] xen/riscv: implement get_page_from_gfn()
Quoted 66 lines · Jan Beulich
Quoted 23 lines · Oleksii Kurochko
Provide a RISC-V implementation of
get_page_from_gfn(), matching the semantics used by other architectures.For translated guests, this is implemented as a wrapper around
p2m_get_page_from_gfn(). ForDOMID_XEN, which is not auto-translated, provide a 1:1 RAM/MMIO mapping and perform the required validation and reference counting.The function is implemented out-of-line rather than as a static inline, to avoid header ordering issues where struct domain is incomplete when
asm/p2m.his included, leading to build failures:
In file included from./arch/riscv/include/asm/domain.h:10,from ./include/xen/domain.h:16, from ./include/xen/sched.h:11, from ./include/xen/event.h:12, from common/cpu.c:3: ./arch/riscv/include/asm/p2m.h: In function 'get_page_from_gfn': ./arch/riscv/include/asm/p2m.h:50:33: error: invalid use of undefined type 'struct domain' 50 | #define p2m_get_hostp2m(d) (&(d)->arch.p2m) | ^~ ./arch/riscv/include/asm/p2m.h:180:38: note: in expansion of macro 'p2m_get_hostp2m' 180 | return p2m_get_page_from_gfn(p2m_get_hostp2m(d), _gfn(gfn), t); | ^~~~~~~~~~~~~~~Quoted 3 lines
make[2]: *** [Rules.mk:253:
common/cpu.o] Error 1 make[1]: *** [build.mk:72: common] Error 2
make: *** [Makefile:623: xen] Error 2Surely this can be addressed, when x86 and Arm have the function as inline?
Quoted 19 lines
Signed-off-by Oleksii Kurochko <[email protected]>---
Does it make sense to make this function almost fully generic?It looks like most of the logic here is architecture-independent and identical across architectures, except for the following points:
1. ```
if (likely(d != dom_xen))``` This could be made generic by introducing paging_mode_translate() for ARM and defining it as `(d != dom_xen)` there. 2. ``` if ( t ) *t = likely(d != dom_io) ? p2m_ram_rw : p2m_mmio_direct_io; ```Quoted 3 lines
Here, only
p2m_mmio_direct_ioappears to be architecture-specific. This could be abstracted via a helper such asdom_io_p2m_type()and used here instead.With P2M stuff I'd be careful. Abstracting the two aspects above may make future arch-specific changes there more difficult.
Quoted 10 lines
xen/arch/riscv/p2m.c +4
-0@@ -1557,3 +1557,31 @@ void p2m_handle_vmenter(void)flush_tlb_guest_local (); } } + +struct page_info *get_page_from_gfn (struct domain *d,unsigned long gfn, +p2m_type_t *t,p2m_query_t q) +{
Quoted 8 lines
xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1569
Quoted 6 lines
xen/arch/riscv/p2m.c +6
-0+struct page_info *page; + +/* +* Special case for DOMID_XEN as it is the only domain so far that is +* not auto-translated. +*/ Once again something taken verbatim from Arm.
Actually it's a mix, up to ...
Quoted 7 lines
Yes,
dom_xencan in fact appear
here, but it's not a real domain, has no memory truly assigned to it, has no GFN space, and hence calling it translated (or not) is simply wrong (at best:
misleading). IOW ...Quoted 2 lines
xen/arch/riscv/p2m.c +2
-0+if (likely (d != dom_xen) ) +return p2m_get_page_from_gfn (p2m_get_hostp2m (d),_gfn (gfn), t);
... here it's Arm code, but what follows is x86 code. Why did you create such a mix?
Jan
Quoted 18 lines
xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1573
Quoted 1 line
xen/arch/riscv/p2m.c +1
-0+/* Non-translated guests see 1-1 RAM / MMIO mappings everywhere */ ... this comment would also want re-wording.
xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1584
Quoted 10 lines
xen/arch/riscv/p2m.c +10
-0+if ( t ) + *t = p2m_invalid; + + page =mfn_to_page (_mfn (gfn)); + +if ( !mfn_valid (_mfn (gfn)) || !get_page (page, d) ) +return NULL ; + +if ( t ) + *t =likely (d != dom_io) ? p2m_ram_rw : p2m_mmio_direct_io;If only
dom_xencan make it here, why the check fordom_io?Jan
Re: [PATCH v1 2/6] xen/riscv: implement copy_to_guest_phys()
In reply to Oleksii KurochkoQuoted 5 lines · Oleksii Kurochko
xen/arch/riscv/guestcopy.c new file +2
-0@@ -0,0 +1,112 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +
xen/arch/riscv/guestcopy.c line 12
Quoted 10 lines
xen/arch/riscv/guestcopy.c new file +10
-0+#include <xen/domain_page.h> +#include <xen/page-size.h> +#include <xen/sched.h> +#include <xen/string.h> + +#include <asm/guest_access.h> + +#define COPY_from_guest (0U << 0) +#define COPY_to_guest (1U << 0) +#define COPY_ipa (0U << 1)
Like already asked elsewhere - is "ipa" a term commonly in use on RISC-V? To me it's Arm terminology, which you don't want to copy as is.
Also, don't you prefer to use BIT() everywhere else?
Quoted 9 lines
xen/arch/riscv/guestcopy.c new file +9
-0+#define COPY_linear (1U << 1) + +typedef union +{ + struct + { + struct vcpu *v; + } gva; +
xen/arch/riscv/guestcopy.c line 31
Quoted 10 lines
xen/arch/riscv/guestcopy.c new file +10
-0+struct + { +struct domain *d; + } gpa; +} copy_info_t; + +#define GVA_INFO (vcpu) ((copy_info_t) { .gva = { vcpu } }) +#define GPA_INFO (domain) ((copy_info_t) { .gpa = { domain } }) + +static struct page_info *translate_get_page(copy_info_t info, uint64_t addr,
The caller has to pass in a domain here. I therefore recommend against use of copy_info_t for this function. Or wait, this is misleading, as the consuming part ...
xen/arch/riscv/guestcopy.c line 38
Quoted 7 lines
xen/arch/riscv/guestcopy.c new file +7
-0+ bool linear, bool write) +{ +p2m_type_t p2mt; +struct page_info *page; + +if ( linear ) +BUG_ON ("unimplemeted\n" );
... of "linear" is missing here.
In any event, this one please shorter as:
BUG_ON(linear);
xen/arch/riscv/guestcopy.c line 52
Quoted 13 lines
xen/arch/riscv/guestcopy.c new file +13
-0+ page =get_page_from_gfn (info.gpa.d,paddr_to_pfn (addr), &p2mt,P2M_ALLOC ); + +if ( !page ) +return NULL ; + +if ( !p2m_is_ram (p2mt) ) + { +put_page (page); +return NULL ; + } + +return page; +}
The "write" function parameter also is unused, but there's no BUG_ON() for that one? Imo the p2m_is_ram() check isn't thorough enough (on the Arm original): p2m_ram_ro shouldn't be allowed when "write" is true. As soon as you gain p2m_ram_ro on RISC-V, things will need updating here as well. Perhaps best to leave a note.
xen/arch/riscv/guestcopy.c line 55
Quoted 2 lines
xen/arch/riscv/guestcopy.c new file +2
-0+static unsigned long copy_guest (void *buf,uint64_t addr,unsigned int len, +copy_info_t info,unsigned int flags)
Why an "unsigned long" return value when ...
Quoted 6 lines
xen/arch/riscv/guestcopy.c new file +6
-0+{ +unsigned int offset =PAGE_OFFSET (addr); + +BUILD_BUG_ON ((sizeof (addr)) <sizeof (vaddr_t)); +BUILD_BUG_ON ((sizeof (addr)) <sizeof (paddr_t)); +
xen/arch/riscv/guestcopy.c line 71
Quoted 10 lines
xen/arch/riscv/guestcopy.c new file +10
-0+while ( len ) + { +void *p; +unsigned int size =min (len, (unsigned int )PAGE_SIZE - offset); +struct page_info *page; + + page =translate_get_page (info, addr, flags & COPY_linear, + flags & COPY_to_guest); +if ( page ==NULL ) +return len;
... only an "unsigned int" (or 0 further down) is returned? Same question for copy_to_guest_phys() below then.
Quoted 26 lines
xen/arch/riscv/guestcopy.c new file +26
-0+ p =__map_domain_page (page); + p += offset; +if ( flags & COPY_to_guest ) + { +/* +* buf will be NULL when the caller request to zero the +* guest memory. +*/ +if ( buf ) +memcpy (p, buf, size); +else +memset (p,0 , size); + } +else +memcpy (buf, p, size); + +unmap_domain_page (p - offset); +put_page (page); + len -= size; + buf += size; + addr += size; + +/* +* After the first iteration, guest virtual address is correctly +* aligned to PAGE_SIZE. +*/
xen/arch/riscv/guestcopy.c line 108
Quoted 10 lines
xen/arch/riscv/guestcopy.c new file +10
-0+ offset =0 ; + } + +return 0 ; +} + +unsigned long copy_to_guest_phys (struct domain *d, +paddr_t gpa, +void *buf, +unsigned int len)
May I suggest to make good use of line length, just like how copy_guest() does?
Jan
Re: [PATCH v1 3/6] xen/riscv: add zImage kernel loading support
In reply to Oleksii KurochkoQuoted 1 line · Oleksii Kurochko
Introduce support for loading a Linux zImage kernel on RISC-V.
Before I look here in any detail - where would a zImage come from? I can't spot any support for it in Linux'es arch/riscv/Makefile (whereas arch/arm/Makefile has such).
Quoted 3 lines
Note that if
panic()is used instead of returning an error as common code doesn't expect to have return code and it is something that should be done separately.
Is the "if" in this sentence a leftover from some editing of earlier different text? I can't make sense of it. Also, which "common code" do you mean? kernel_zimage_probe()'s sole caller does respect the return value (handing it on).
Quoted 2 lines
This prepares the RISC-V port for booting Linux guests using the common domain build infrastructure.
Again, what's "common" here? Not something x86 uses, afaict.
Jan
Re: [PATCH v1 5/6] xen: move domain_use_host_layout() to common header
In reply to Oleksii KurochkoQuoted 2 lines · Oleksii Kurochko
domain_use_host_layout()is generic enough to be moved to the common headerxen/domain.h.
Maybe, but then something DT-specific, not xen/domain.h. Specifically, ...
Quoted 10 lines
xen/include/xen/domain.h +4
-0@@ -62,6 +62,22 @@ void domid_free(domid_t domid);#define is_domain_direct_mapped (d) ((d)->cdf & CDF_directmap)#define is_domain_using_staticmem (d) ((d)->cdf & CDF_staticmem) +/* +* Is the domain using the host memory layout? +* +* Direct-mapped domain will always have the RAM mapped with GFN == MFN.
xen/include/xen/domain.h void domid_free(domid_t domid); · line 78
Quoted 10 lines
xen/include/xen/domain.h +10
-0+* To avoid any trouble finding space, it is easier to force using the +* host memory layout. +* +* The hardware domain will use the host layout regardless of +* direct-mapped because some OS may rely on a specific address ranges +* for the devices. +*/ +#ifndef domain_use_host_layout +# define domain_use_host_layout (d) (is_domain_direct_mapped(d) || \ + is_hardware_domain(d))
... is_domain_direct_mapped() isn't something that I'd like to see further proliferate in common (non-DT) code.
Jan
Re: [PATCH v1 5/6] xen: move domain_use_host_layout() to common header
Quoted 21 lines · Jan Beulich
Quoted 2 lines · Oleksii Kurochko
domain_use_host_layout()is generic enough to be moved to the common headerxen/domain.h.Maybe, but then something DT-specific, not
xen/domain.h. Specifically, ...Quoted 15 lines
xen/include/xen/domain.h +9
-0@@ -62,6 +62,22 @@ void domid_free(domid_t domid);#define is_domain_direct_mapped (d) ((d)->cdf & CDF_directmap)#define is_domain_using_staticmem (d) ((d)->cdf & CDF_staticmem) +/* +* Is the domain using the host memory layout? +* +* Direct-mapped domain will always have the RAM mapped with GFN == MFN. +* To avoid any trouble finding space, it is easier to force using the +* host memory layout. +* +* The hardware domain will use the host layout regardless of +* direct-mapped because some OS may rely on a specific address ranges
Quoted 8 lines
xen/include/xen/domain.h void domid_free(domid_t domid); · line 78
Quoted 5 lines
xen/include/xen/domain.h +5
-0+* for the devices. +*/ +#ifndef domain_use_host_layout +# define domain_use_host_layout (d) (is_domain_direct_mapped(d) || \ + is_hardware_domain(d))...
is_domain_direct_mapped()isn't something that I'd like to see further proliferate in common (non-DT) code.
Hi Jan, we have a requirement for 1:1 mapped Dom0 (I should say hardware domain) on x86 as well. In fact, we already have a working prototype, although it is not suitable for upstream yet.
In addition to the PSP use case that we discussed a few months ago, where the PSP is not behind an IOMMU and therefore exchanged addresses must be 1:1 mapped, we also have a new use case. We are running the full Xen-based automotive stack on an Azure instance where SVM (vmentry and vmexit) is available, but an IOMMU is not present. All virtual machines are configured as PVH.
Re: [PATCH v1 5/6] xen: move domain_use_host_layout() to common header
Quoted 35 lines · Stefano Stabellini
Quoted 21 lines · Jan Beulich
Quoted 2 lines · Oleksii Kurochko
domain_use_host_layout()is generic enough to be moved to the common headerxen/domain.h.Maybe, but then something DT-specific, not
xen/domain.h. Specifically, ...Quoted 15 lines
xen/include/xen/domain.h +9
-0@@ -62,6 +62,22 @@ void domid_free(domid_t domid);#define is_domain_direct_mapped (d) ((d)->cdf & CDF_directmap)#define is_domain_using_staticmem (d) ((d)->cdf & CDF_staticmem) +/* +* Is the domain using the host memory layout? +* +* Direct-mapped domain will always have the RAM mapped with GFN == MFN. +* To avoid any trouble finding space, it is easier to force using the +* host memory layout. +* +* The hardware domain will use the host layout regardless of +* direct-mapped because some OS may rely on a specific address ranges Quoted 8 lines
xen/include/xen/domain.h void domid_free(domid_t domid); · line 78
Quoted 5 lines
xen/include/xen/domain.h +5
-0+* for the devices. +*/ +#ifndef domain_use_host_layout +# define domain_use_host_layout (d) (is_domain_direct_mapped(d) || \ + is_hardware_domain(d))...
is_domain_direct_mapped()isn't something that I'd like to see further proliferate in common (non-DT) code.Hi Jan, we have a requirement for 1:1 mapped Dom0 (I should say hardware domain) on x86 as well. In fact, we already have a working prototype, although it is not suitable for upstream yet.
Quoted 6 lines
In addition to the PSP use case that we discussed a few months ago, where the PSP is not behind an IOMMU and therefore exchanged addresses must be 1:1 mapped, we also have a new use case. We are running the full Xen-based automotive stack on an Azure instance where SVM (vmentry and vmexit) is available, but an IOMMU is not present. All virtual machines are configured as PVH.
Hmm. Then adjustments need making, for commentary and macro to be correct on x86. First and foremost none of what is there is true for PV.
Jan
Re: [PATCH v1 1/6] xen/riscv: implement get_page_from_gfn()
In reply to Jan BeulichQuoted 27 lines · Jan Beulich
Quoted 11 lines · Oleksii Kurochko
Provide a RISC-V implementation of
get_page_from_gfn(), matching the semantics used by other architectures.For translated guests, this is implemented as a wrapper around
p2m_get_page_from_gfn(). ForDOMID_XEN, which is not auto-translated, provide a 1:1 RAM/MMIO mapping and perform the required validation and reference counting.The function is implemented out-of-line rather than as a static inline, to avoid header ordering issues where struct domain is incomplete when
asm/p2m.his included, leading to build failures:Quoted 15 lines
In file included from ./arch/riscv/include/asm/domain.h:10, from ./include/xen/domain.h:16, from ./include/xen/sched.h:11, from ./include/xen/event.h:12, from common/cpu.c:3: ./arch/riscv/include/asm/p2m.h: In function 'get_page_from_gfn': ./arch/riscv/include/asm/p2m.h:50:33: error: invalid use of undefined type 'struct domain' 50 | #define p2m_get_hostp2m(d) (&(d)->arch.p2m) | ^~ ./arch/riscv/include/asm/p2m.h:180:38: note: in expansion of macro 'p2m_get_hostp2m' 180 | return p2m_get_page_from_gfn(p2m_get_hostp2m(d), _gfn(gfn), t); | ^~~~~~~~~~~~~~~ make[2]: *** [Rules.mk:253: common/cpu.o] Error 1 make[1]: *** [build.mk:72: common] Error 2 make: *** [Makefile:623: xen] Error 2
Quoted 1 line
Surely this can be addressed, when x86 and Arm have the function as inline?
Yes, it should be possible. The reason for now that is working for x86 and Arm is that:
1. Arm only pass pointer to struct domain to p2m_get_page_from_gfn() so it is enough just to have forward declaration for struct domain.
2. x86 uses pointer to p2m_domain in arch_domain so there is no need to include asm/p2m.h in asm/domain.h and so forward declaration will be enough. And so there is no dependency between xen/sched.h and asm/p2m.h through asm/domain.h which leads to the issue mentioned in the commit message.
RISC-V could in principle follow the x86 pattern (avoid including asm/p2m.h), but the current out-of-line approach is also acceptable, it is simpler and more robust against future header reordering problems.
Quoted 46 lines
Quoted 14 lines
Signed-off-by Oleksii Kurochko<[email protected]>---
Does it make sense to make this function almost fully generic?It looks like most of the logic here is architecture-independent and identical across architectures, except for the following points:
1. ```
if ( likely(d != dom_xen) ) ``` This could be made generic by introducing paging_mode_translate() for ARM and defining it as `(d != dom_xen)` there.Quoted 8 lines
2. ```
if ( t )
*t =likely(d != dom_io)?p2m_ram_rw:p2m_mmio_direct_io;
```Here, only
p2m_mmio_direct_ioappears to be architecture-specific. This could be abstracted via a helper such asdom_io_p2m_type()and used here instead.With P2M stuff I'd be careful. Abstracting the two aspects above may make future arch-specific changes there more difficult.
Quoted 6 lines
xen/arch/riscv/p2m.c +0
-0@@ -1557,3 +1557,31 @@ void p2m_handle_vmenter(void)flush_tlb_guest_local (); } }xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1569
Quoted 10 lines
xen/arch/riscv/p2m.c +10
-0+ +struct page_info *get_page_from_gfn (struct domain *d,unsigned long gfn, +p2m_type_t *t,p2m_query_t q) +{ +struct page_info *page; + +/* +* Special case for DOMID_XEN as it is the only domain so far that is +* not auto-translated. +*/ Once again something taken verbatim from Arm. Yes,
dom_xencan in fact appear here, but it's not a real domain, has no memory truly assigned to it, has no GFN space, and hence calling it translated (or not) is simply wrong (at best:
misleading). IOW ...
Quoted 5 lines
xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1573
Quoted 4 lines
xen/arch/riscv/p2m.c +4
-0+if (likely (d != dom_xen) ) +return p2m_get_page_from_gfn (p2m_get_hostp2m (d),_gfn (gfn), t); + +/* Non-translated guests see 1-1 RAM / MMIO mappings everywhere */ ... this comment would also want re-wording.
As you mentioned in the another reply to this patch, I messed up x86 and Arm implementation in a bad way, so here should be DOMID_XEN used instead of "Non-translated".
Based on your reply it seems like the first comment should be also rephrased as you mentioned that DOMID_XEN can't be called also "not auto-translated". I think it would be better to write the following:
/*
* Special case for DOMID_XEN as it is the only domain so far that has
* no GFN space.
*/
Quoted 12 lines
xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1584
Quoted 11 lines
xen/arch/riscv/p2m.c +10
-0+if ( t ) + *t = p2m_invalid; + + page =mfn_to_page (_mfn (gfn)); + +if ( !mfn_valid (_mfn (gfn)) || !get_page (page, d) ) +return NULL ; + +if ( t ) + *t =likely (d != dom_io) ? p2m_ram_rw : p2m_mmio_direct_io;If only
dom_xencan make it here, why the check fordom_io?
Incorrectly copied from x86. It should be just:
*t = p2m_ram_rw
here as in RISC-V for MMIO pages owner isn't set to dom_io (and the same is true for Arm I think).
Thanks.
~ Oleksii
Re: [PATCH v1 1/6] xen/riscv: implement get_page_from_gfn()
Quoted 33 lines · Oleksii Kurochko
Quoted 22 lines · Jan Beulich
Quoted 6 lines · Oleksii Kurochko
xen/arch/riscv/p2m.c +0
-0@@ -1557,3 +1557,31 @@ void p2m_handle_vmenter(void)flush_tlb_guest_local (); } }xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1569
Quoted 10 lines
xen/arch/riscv/p2m.c +10
-0+ +struct page_info *get_page_from_gfn (struct domain *d,unsigned long gfn, +p2m_type_t *t,p2m_query_t q) +{ +struct page_info *page; + +/* +* Special case for DOMID_XEN as it is the only domain so far that is +* not auto-translated. +*/ Once again something taken verbatim from Arm. Yes,
dom_xencan in fact appear here, but it's not a real domain, has no memory truly assigned to it, has no GFN space, and hence calling it translated (or not) is simply wrong (at best:
misleading). IOW ...Quoted 5 lines
xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1573
Quoted 4 lines
xen/arch/riscv/p2m.c +4
-0+if (likely (d != dom_xen) ) +return p2m_get_page_from_gfn (p2m_get_hostp2m (d),_gfn (gfn), t); + +/* Non-translated guests see 1-1 RAM / MMIO mappings everywhere */ ... this comment would also want re-wording.
As you mentioned in the another reply to this patch, I messed up x86 and Arm implementation in a bad way, so here should be
DOMID_XENused instead of "Non-translated".
Quoted 7 lines
Based on your reply it seems like the first comment should be also rephrased as you mentioned that
DOMID_XENcan't be called also "not auto-translated". I think it would be better to write the following:
/*
* Special case forDOMID_XENas it is the only domain so far that has
* no GFN space.
*/
Simply say that dom_xen isn't a "normal" domain?
Quoted 12 lines
Quoted 11 lines
xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1584
Quoted 10 lines
xen/arch/riscv/p2m.c +10
-0+if ( t ) + *t = p2m_invalid; + + page =mfn_to_page (_mfn (gfn)); + +if ( !mfn_valid (_mfn (gfn)) || !get_page (page, d) ) +return NULL ; + +if ( t ) + *t =likely (d != dom_io) ? p2m_ram_rw : p2m_mmio_direct_io;If only
dom_xencan make it here, why the check fordom_io?
Quoted 4 lines
Incorrectly copied from x86. It should be just:
*t =p2m_ram_rw
here as in RISC-V for MMIO pages owner isn't set todom_io(and the same is true for Arm I think).
May I suggest that right away you use the construct that I suggested Arm to switch to (you were Cc-ed on that patch, I think)? Despite the absence of p2m_ram_ro on RISC-V, that'll be usable, and it will allow keeping the code untouched when p2m_ram_ro is introduced (sooner or later you will need it, I expect).
Jan
Re: [PATCH v1 1/6] xen/riscv: implement get_page_from_gfn()
Quoted 57 lines · Jan Beulich
Quoted 32 lines · Oleksii Kurochko
Quoted 22 lines · Jan Beulich
Quoted 6 lines · Oleksii Kurochko
xen/arch/riscv/p2m.c +0
-0@@ -1557,3 +1557,31 @@ void p2m_handle_vmenter(void)flush_tlb_guest_local (); } }xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1569
Quoted 10 lines
xen/arch/riscv/p2m.c +10
-0+ +struct page_info *get_page_from_gfn (struct domain *d,unsigned long gfn, +p2m_type_t *t,p2m_query_t q) +{ +struct page_info *page; + +/* +* Special case for DOMID_XEN as it is the only domain so far that is +* not auto-translated. +*/ Once again something taken verbatim from Arm. Yes,
dom_xencan in fact appear here, but it's not a real domain, has no memory truly assigned to it, has no GFN space, and hence calling it translated (or not) is simply wrong (at best:
misleading). IOW ...Quoted 5 lines
xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1573
Quoted 4 lines
xen/arch/riscv/p2m.c +4
-0+if (likely (d != dom_xen) ) +return p2m_get_page_from_gfn (p2m_get_hostp2m (d),_gfn (gfn), t); + +/* Non-translated guests see 1-1 RAM / MMIO mappings everywhere */ ... this comment would also want re-wording.
As you mentioned in the another reply to this patch, I messed up x86 and Arm implementation in a bad way, so here should be
DOMID_XENused instead of "Non-translated".Quoted 7 lines
Based on your reply it seems like the first comment should be also rephrased as you mentioned that
DOMID_XENcan't be called also "not auto-translated". I think it would be better to write the following:
/*
* Special case forDOMID_XENas it is the only domain so far that has
* no GFN space.
*/Simply say that
dom_xenisn't a "normal" domain?Quoted 11 lines
Quoted 11 lines
xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1584
Quoted 10 lines
xen/arch/riscv/p2m.c +10
-0+if ( t ) + *t = p2m_invalid; + + page =mfn_to_page (_mfn (gfn)); + +if ( !mfn_valid (_mfn (gfn)) || !get_page (page, d) ) +return NULL ; + +if ( t ) + *t =likely (d != dom_io) ? p2m_ram_rw : p2m_mmio_direct_io;If only
dom_xencan make it here, why the check fordom_io?Quoted 4 lines
Incorrectly copied from x86. It should be just:
*t = p2m_ram_rwhere as in RISC-V for MMIO pages owner isn't set to
dom_io(and the same is true for Arm I think).
Quoted 5 lines
May I suggest that right away you use the construct that I suggested Arm to switch to (you were Cc-ed on that patch, I think)? Despite the absence of
p2m_ram_roon RISC-V, that'll be usable, and it will allow keeping the code untouched whenp2m_ram_rois introduced (sooner or later you will need it, I expect).
Sure, but doesn't that patch is connected to another function (translate_get_page()) and just fixing the handling of what get_page_from_gfn() in *t?
For get_page_from_gfn() to not miss the case when new type is introduced it make sense to do the following:
if ( page->u.inuse.type_info & PGT_writable_page )
*t = p2m_ram_rw;
else
BUG_ON("unimplemented");~ Oleksii
Re: [PATCH v1 2/6] xen/riscv: implement copy_to_guest_phys()
In reply to Jan BeulichQuoted 10 lines · Jan Beulich
Quoted 9 lines · Oleksii Kurochko
xen/arch/riscv/guestcopy.c new file +6
-0@@ -0,0 +1,112 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/domain_page.h> +#include <xen/page-size.h> +#include <xen/sched.h> +#include <xen/string.h>
Quoted 8 lines
xen/arch/riscv/guestcopy.c line 12
Quoted 6 lines
xen/arch/riscv/guestcopy.c new file +6
-0+ +#include <asm/guest_access.h> + +#define COPY_from_guest (0U << 0) +#define COPY_to_guest (1U << 0) +#define COPY_ipa (0U << 1)Like already asked elsewhere - is "ipa" a term commonly in use on RISC-V? To me it's Arm terminology, which you don't want to copy as is.
As we discussed in another patch thread, IPA isn't really used for RISC-V and I will rename it to GPA.
Quoted 2 lines
Also, don't you prefer to use
BIT()everywhere else?
Yes, BIT() would be better for consistency.
Quoted 24 lines
Quoted 10 lines
xen/arch/riscv/guestcopy.c new file +9
-0+#define COPY_linear (1U << 1) + +typedef union +{ + struct + { + struct vcpu *v; + } gva; +xen/arch/riscv/guestcopy.c line 31
Quoted 10 lines
xen/arch/riscv/guestcopy.c new file +10
-0+struct + { +struct domain *d; + } gpa; +} copy_info_t; + +#define GVA_INFO (vcpu) ((copy_info_t) { .gva = { vcpu } }) +#define GPA_INFO (domain) ((copy_info_t) { .gpa = { domain } }) + +static struct page_info *translate_get_page(copy_info_t info, uint64_t addr,The caller has to pass in a domain here. I therefore recommend against use of
copy_info_tfor this function. Or wait, this is misleading, as the consuming part ...
Quoted 8 lines
xen/arch/riscv/guestcopy.c line 38
Quoted 7 lines
xen/arch/riscv/guestcopy.c new file +7
-0+ bool linear, bool write) +{ +p2m_type_t p2mt; +struct page_info *page; + +if ( linear ) +BUG_ON ("unimplemeted\n" );... of "linear" is missing here.
Yes, for this once cases it will be used vcpu as an argument passed by "copy_info_t info". I will add the comment above suggested below BUG_ON(linear).
Btw, I think it makes sense to change linear to GVA to be more close to RISC-V spec?
Quoted 15 lines
In any event, this one please shorter as:
BUG_ON(linear);Quoted 10 lines
xen/arch/riscv/guestcopy.c new file +10
-0+ page =get_page_from_gfn (info.gpa.d,paddr_to_pfn (addr), &p2mt,P2M_ALLOC ); + +if ( !page ) +return NULL ; + +if ( !p2m_is_ram (p2mt) ) + { +put_page (page); +return NULL ; + }
Quoted 8 lines
xen/arch/riscv/guestcopy.c line 52
Quoted 3 lines
xen/arch/riscv/guestcopy.c new file +3
-0+ +return page; +}The "write" function parameter also is unused, but there's no
BUG_ON()for that one? Imo thep2m_is_ram()check isn't thorough enough (on the Arm original):p2m_ram_roshouldn't be allowed when "write" is true. As soon as you gainp2m_ram_roon RISC-V, things will need updating here as well. Perhaps best to leave a note.
I will apply your changes from suggested for Arm patch (Arm: tighten translate_get_page()) so write will be used and also no extra updates will be needed here.
Quoted 15 lines
xen/arch/riscv/guestcopy.c line 55
Quoted 3 lines
xen/arch/riscv/guestcopy.c new file +2
-0+static unsigned long copy_guest (void *buf,uint64_t addr,unsigned int len, +copy_info_t info,unsigned int flags)Why an "unsigned long" return value when ...
Quoted 10 lines
xen/arch/riscv/guestcopy.c new file +10
-0+{ +unsigned int offset =PAGE_OFFSET (addr); + +BUILD_BUG_ON ((sizeof (addr)) <sizeof (vaddr_t)); +BUILD_BUG_ON ((sizeof (addr)) <sizeof (paddr_t)); + +while ( len ) + { +void *p; +unsigned int size =min (len, (unsigned int )PAGE_SIZE - offset);
Quoted 8 lines
xen/arch/riscv/guestcopy.c line 71
Quoted 6 lines
xen/arch/riscv/guestcopy.c new file +6
-0+struct page_info *page; + + page =translate_get_page (info, addr, flags & COPY_linear, + flags & COPY_to_guest); +if ( page ==NULL ) +return len;... only an "unsigned int" (or 0 further down) is returned? Same question for
copy_to_guest_phys()below then.
Agree, unsigned int should be enough.
Quoted 31 lines
Quoted 31 lines
xen/arch/riscv/guestcopy.c new file +30
-0+ p =__map_domain_page (page); + p += offset; +if ( flags & COPY_to_guest ) + { +/* +* buf will be NULL when the caller request to zero the +* guest memory. +*/ +if ( buf ) +memcpy (p, buf, size); +else +memset (p,0 , size); + } +else +memcpy (buf, p, size); + +unmap_domain_page (p - offset); +put_page (page); + len -= size; + buf += size; + addr += size; + +/* +* After the first iteration, guest virtual address is correctly +* aligned to PAGE_SIZE. +*/ + offset =0 ; + } + +return 0 ;
Quoted 8 lines
xen/arch/riscv/guestcopy.c line 108
Quoted 6 lines
xen/arch/riscv/guestcopy.c new file +6
-0+} + +unsigned long copy_to_guest_phys (struct domain *d, +paddr_t gpa, +void *buf, +unsigned int len)May I suggest to make good use of line length, just like how
copy_guest()does?
Sure, I will do that.
Thanks.
~ Oleksii
Re: [PATCH v1 1/6] xen/riscv: implement get_page_from_gfn()
In reply to Oleksii KurochkoQuoted 59 lines · Oleksii Kurochko
Quoted 57 lines · Jan Beulich
Quoted 32 lines · Oleksii Kurochko
Quoted 22 lines · Jan Beulich
Quoted 6 lines · Oleksii Kurochko
xen/arch/riscv/p2m.c +0
-0@@ -1557,3 +1557,31 @@ void p2m_handle_vmenter(void)flush_tlb_guest_local (); } }xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1569
Quoted 10 lines
xen/arch/riscv/p2m.c +10
-0+ +struct page_info *get_page_from_gfn (struct domain *d,unsigned long gfn, +p2m_type_t *t,p2m_query_t q) +{ +struct page_info *page; + +/* +* Special case for DOMID_XEN as it is the only domain so far that is +* not auto-translated. +*/ Once again something taken verbatim from Arm. Yes,
dom_xencan in fact appear here, but it's not a real domain, has no memory truly assigned to it, has no GFN space, and hence calling it translated (or not) is simply wrong (at best:
misleading). IOW ...Quoted 5 lines
xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1573
Quoted 4 lines
xen/arch/riscv/p2m.c +4
-0+if (likely (d != dom_xen) ) +return p2m_get_page_from_gfn (p2m_get_hostp2m (d),_gfn (gfn), t); + +/* Non-translated guests see 1-1 RAM / MMIO mappings everywhere */ ... this comment would also want re-wording.
As you mentioned in the another reply to this patch, I messed up x86 and Arm implementation in a bad way, so here should be
DOMID_XENused instead of "Non-translated".Quoted 7 lines
Based on your reply it seems like the first comment should be also rephrased as you mentioned that
DOMID_XENcan't be called also "not auto-translated". I think it would be better to write the following:
/*
* Special case forDOMID_XENas it is the only domain so far that has
* no GFN space.
*/Simply say that
dom_xenisn't a "normal" domain?Quoted 15 lines
Quoted 11 lines
xen/arch/riscv/p2m.c void p2m_handle_vmenter(void) · line 1584
Quoted 10 lines
xen/arch/riscv/p2m.c +10
-0+if ( t ) + *t = p2m_invalid; + + page =mfn_to_page (_mfn (gfn)); + +if ( !mfn_valid (_mfn (gfn)) || !get_page (page, d) ) +return NULL ; + +if ( t ) + *t =likely (d != dom_io) ? p2m_ram_rw : p2m_mmio_direct_io;If only
dom_xencan make it here, why the check fordom_io?Incorrectly copied from x86. It should be just:
*t = p2m_ram_rwhere as in RISC-V for MMIO pages owner isn't set to
dom_io(and the same is true for Arm I think).
Quoted 8 lines
Quoted 5 lines
May I suggest that right away you use the construct that I suggested Arm to switch to (you were Cc-ed on that patch, I think)? Despite the absence of
p2m_ram_roon RISC-V, that'll be usable, and it will allow keeping the code untouched whenp2m_ram_rois introduced (sooner or later you will need it, I expect).Sure, but doesn't that patch is connected to another function (
translate_get_page()) and just fixing the handling of whatget_page_from_gfn()in *t?
Oh, sorry, I should have made explicit that the request was for patch 2. Here indeed ...
Quoted 6 lines
For
get_page_from_gfn()to not miss the case when new type is introduced it make sense to do the following:if ( page->u.inuse.type_info & PGT_writable_page ) *t = p2m_ram_rw; else BUG_ON("unimplemented");
... this may be the best you can do right now (unless you want to introduce p2m_ram_ro).
Jan
Re: [PATCH v1 2/6] xen/riscv: implement copy_to_guest_phys()
In reply to Oleksii KurochkoQuoted 59 lines · Oleksii Kurochko
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Oleksii Kurochko
xen/arch/riscv/guestcopy.c new file +6
-0@@ -0,0 +1,112 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/domain_page.h> +#include <xen/page-size.h> +#include <xen/sched.h> +#include <xen/string.h> Quoted 8 lines
xen/arch/riscv/guestcopy.c line 12
Quoted 6 lines
xen/arch/riscv/guestcopy.c new file +6
-0+ +#include <asm/guest_access.h> + +#define COPY_from_guest (0U << 0) +#define COPY_to_guest (1U << 0) +#define COPY_ipa (0U << 1)Like already asked elsewhere - is "ipa" a term commonly in use on RISC-V? To me it's Arm terminology, which you don't want to copy as is.
As we discussed in another patch thread, IPA isn't really used for RISC-V and I will rename it to GPA.
Quoted 1 line
Also, don't you prefer to use
BIT()everywhere else?Yes,
BIT()would be better for consistency.Quoted 23 lines
Quoted 9 lines
xen/arch/riscv/guestcopy.c new file +9
-0+#define COPY_linear (1U << 1) + +typedef union +{ + struct + { + struct vcpu *v; + } gva; +xen/arch/riscv/guestcopy.c line 31
Quoted 10 lines
xen/arch/riscv/guestcopy.c new file +10
-0+struct + { +struct domain *d; + } gpa; +} copy_info_t; + +#define GVA_INFO (vcpu) ((copy_info_t) { .gva = { vcpu } }) +#define GPA_INFO (domain) ((copy_info_t) { .gpa = { domain } }) + +static struct page_info *translate_get_page(copy_info_t info, uint64_t addr,The caller has to pass in a domain here. I therefore recommend against use of
copy_info_tfor this function. Or wait, this is misleading, as the consuming part ...Quoted 8 lines
xen/arch/riscv/guestcopy.c line 38
Quoted 7 lines
xen/arch/riscv/guestcopy.c new file +7
-0+ bool linear, bool write) +{ +p2m_type_t p2mt; +struct page_info *page; + +if ( linear ) +BUG_ON ("unimplemeted\n" );... of "linear" is missing here.
Quoted 4 lines
Yes, for this once cases it will be used vcpu as an argument passed by "
copy_info_tinfo". I will add the comment above suggested belowBUG_ON(linear).Btw, I think it makes sense to change linear to GVA to be more close to RISC-V spec?
And to better match the rename to GPA that you talk about above.
Jan
Re: [PATCH v1 3/6] xen/riscv: add zImage kernel loading support
In reply to Jan BeulichQuoted 5 lines · Jan Beulich
Quoted 1 line · Oleksii Kurochko
Introduce support for loading a Linux zImage kernel on RISC-V.
Before I look here in any detail - where would a zImage come from? I can't spot any support for it in Linux'es
arch/riscv/Makefile(whereasarch/arm/Makefilehas such).
Good point.
It is something that should be renamed as not Arm64 (Arm32 really has such target), not RISC-V doesn't really work with zImage. They are using Image plus Image.gz as compressed image.
Maybe it would be better to rename kernel_zimage_probe() to something more generic kernel_image_probe().
Quoted 8 lines
Quoted 4 lines
Note that if
panic()is used instead of returning an error as common code doesn't expect to have return code and it is something that should be done separately.Is the "if" in this sentence a leftover from some editing of earlier different text? I can't make sense of it. Also, which "common code" do you mean? kernel_zimage_probe()'s sole caller does respect the return value (handing it on).
It is about kernel_zimage_load() which is used to set:
struct kernel_info->load = kernel_zimage_load
in kernel_zimage64_probe().
and which is called (and is in common code) from:
void __init kernel_load(struct kernel_info *info)
{
ASSERT(info && info->load);
info->load(info);}
Quoted 4 lines
Quoted 3 lines
This prepares the RISC-V port for booting Linux guests using the common domain build infrastructure.
Again, what's "common" here? Not something x86 uses, afaict.
By "common" here I meant dom0less's common code which may use functions from this file.
I will update that part to use more specific instead of "common".
~ Oleksii
Re: [PATCH v1 3/6] xen/riscv: add zImage kernel loading support
Quoted 7 lines · Oleksii Kurochko
Quoted 5 lines · Jan Beulich
Quoted 1 line · Oleksii Kurochko
Introduce support for loading a Linux zImage kernel on RISC-V.
Before I look here in any detail - where would a zImage come from? I can't spot any support for it in Linux'es
arch/riscv/Makefile(whereasarch/arm/Makefilehas such).
Quoted 8 lines
Good point.
It is something that should be renamed as not Arm64 (Arm32 really has such target), not RISC-V doesn't really work with zImage. They are using Image plus Image.gz as compressed image.
Maybe it would be better to rename
kernel_zimage_probe()to something more generickernel_image_probe().
Well, it's two things. In the description you explicitly say zImage. That's simply misleading. Renaming the function (if indeed it copes with more than just zImage) would likely be a good thing too, but needs sorting with its maintainers.
Jan
Re: [PATCH v1 3/6] xen/riscv: add zImage kernel loading support
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Oleksii Kurochko
Quoted 5 lines · Jan Beulich
Quoted 1 line · Oleksii Kurochko
Introduce support for loading a Linux zImage kernel on RISC-V.
Before I look here in any detail - where would a zImage come from? I can't spot any support for it in Linux'es
arch/riscv/Makefile(whereasarch/arm/Makefilehas such).Good point.
Quoted 8 lines
Quoted 6 lines
It is something that should be renamed as not Arm64 (Arm32 really has such target), not RISC-V doesn't really work with zImage. They are using Image plus Image.gz as compressed image.
Maybe it would be better to rename
kernel_zimage_probe()to something more generickernel_image_probe().Well, it's two things. In the description you explicitly say zImage. That's simply misleading.
Agree, it should be just Image, I'll update that part of commit description in the next version.
Quoted 3 lines
Renaming the function (if indeed it copes with more than
just zImage) would likely be a good thing too, but needs sorting with its maintainers.
I will suggest that then in a separate patch.
~ Oleksii
Re: [PATCH v1 6/6] xen/riscv: enable DOMAIN_BUILD_HELPERS
In reply to Jan BeulichQuoted 27 lines · Jan Beulich
Quoted 26 lines · Oleksii Kurochko
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Oleksii Kurochko
xen/include/public/arch-riscv.h +0
-0@@ -50,6 +50,14 @@ typedef uint64_t xen_ulong_t;#if defined(__XEN__) || defined(__XEN_TOOLS__)Quoted 8 lines
xen/include/public/arch-riscv.h typedef uint64_t xen_ulong_t; · line 59
Quoted 7 lines
xen/include/public/arch-riscv.h +7
-0+#define GUEST_RAM_BANKS 1 + +#define GUEST_RAM0_BASE xen_mk_ullong(0x80000000)/* 2GB of low RAM @ 2GB */ +#define GUEST_RAM0_SIZE xen_mk_ullong(0x80000000) + +#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE } +#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE }Hmm, does RISC-V really want to go with compile-time constants here?
It is needed for
allocate_memory()for guest domains, so it is expected to be compile-time constant with the current code of common dom0less approach.It represents the start of RAM address for DomU and the maximum RAM size (the actual size will be calculated based on what is mentioned in DomU node in dts) and then will be used to generate memory node for DomU (
GUEST_RAM0_BASEas RAM start address andmin(GUEST_RAM0_SIZE, dts->domU->memory->size)as a RAM size).
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
And
if so, why would guests be limited to just 2 Gb?It is enough for guest domain I am using in dom0less mode.
And what others may want to use RISC-V for once it actually becomes usable isn't relevant? As you start adding things to the public headers, you will need to understand that you can't change easily what once was put there. Everything there is part of the ABI, and the ABI needs to remain stable (within certain limits).
Considering this ...
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
That may more efficiently
be RV32 guests then, with perhaps just an RV32 hypervisor.I didn't get this point. Could you please explain differently what do you mean?
If all you want are 2Gb guests, why would such guests be 64-bit? And with (iirc) RV32 permitting more than 4Gb (via PPN being 22 bits wide), perhaps even a 32-bit hypervisor would suffice?
... now I can agree that Xen should permit bigger amount of RAM. At least, (2^34-1) should be allowed for RV32 and so for RV64 so it could be used like a base for both of them. As RV64 allows (2^56 - 1) it makes sense to add another bank to cover range from 2^34 to (2^56 -1) for RV64 (and ifdef this second bank for RV64).
Would it be better?
~ Oleksii
Re: [PATCH v1 6/6] xen/riscv: enable DOMAIN_BUILD_HELPERS
Quoted 48 lines · Oleksii Kurochko
Quoted 27 lines · Jan Beulich
Quoted 26 lines · Oleksii Kurochko
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Oleksii Kurochko
xen/include/public/arch-riscv.h +0
-0@@ -50,6 +50,14 @@ typedef uint64_t xen_ulong_t;#if defined(__XEN__) || defined(__XEN_TOOLS__)Quoted 8 lines
xen/include/public/arch-riscv.h typedef uint64_t xen_ulong_t; · line 59
Quoted 7 lines
xen/include/public/arch-riscv.h +7
-0+#define GUEST_RAM_BANKS 1 + +#define GUEST_RAM0_BASE xen_mk_ullong(0x80000000)/* 2GB of low RAM @ 2GB */ +#define GUEST_RAM0_SIZE xen_mk_ullong(0x80000000) + +#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE } +#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE }Hmm, does RISC-V really want to go with compile-time constants here?
It is needed for
allocate_memory()for guest domains, so it is expected to be compile-time constant with the current code of common dom0less approach.It represents the start of RAM address for DomU and the maximum RAM size (the actual size will be calculated based on what is mentioned in DomU node in dts) and then will be used to generate memory node for DomU (
GUEST_RAM0_BASEas RAM start address andmin(GUEST_RAM0_SIZE, dts->domU->memory->size)as a RAM size).Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
And
if so, why would guests be limited to just 2 Gb?It is enough for guest domain I am using in dom0less mode.
And what others may want to use RISC-V for once it actually becomes usable isn't relevant? As you start adding things to the public headers, you will need to understand that you can't change easily what once was put there. Everything there is part of the ABI, and the ABI needs to remain stable (within certain limits).
Considering this ...
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
That may more efficiently
be RV32 guests then, with perhaps just an RV32 hypervisor.I didn't get this point. Could you please explain differently what do you mean?
If all you want are 2Gb guests, why would such guests be 64-bit? And with (iirc) RV32 permitting more than 4Gb (via PPN being 22 bits wide), perhaps even a 32-bit hypervisor would suffice?
Quoted 7 lines
... now I can agree that Xen should permit bigger amount of RAM. At least, (2^34-1) should be allowed for RV32 and so for RV64 so it could be used like a base for both of them. As RV64 allows (2^56 - 1) it makes sense to add another bank to cover range from 2^34 to (2^56 -1) for RV64 (and ifdef this second bank for RV64).
Would it be better?
Having a 2nd bank right away for RV64 would seem better to me, yes. Whether that means going all the way up to 2^56 I don't know.
In whether a public header can be changed, it also matters whether these #define-s actually are meant to be exposed to guests (vs. merely the tool stack). Longer-term, however, this is going to change (as we intend to move to a fully stable ABI).
Jan
Re: [PATCH v1 5/6] xen: move domain_use_host_layout() to common header
In reply to Jan BeulichQuoted 33 lines · Jan Beulich
Quoted 32 lines · Stefano Stabellini
Quoted 11 lines · Jan Beulich
Quoted 2 lines · Oleksii Kurochko
domain_use_host_layout()is generic enough to be moved to the common headerxen/domain.h.Maybe, but then something DT-specific, not
xen/domain.h. Specifically, ...Quoted 6 lines
xen/include/xen/domain.h +0
-0@@ -62,6 +62,22 @@ void domid_free(domid_t domid);#define is_domain_direct_mapped (d) ((d)->cdf & CDF_directmap)#define is_domain_using_staticmem (d) ((d)->cdf & CDF_staticmem)Quoted 16 lines
Quoted 4 lines
xen/include/xen/domain.h +4
-0+/* +* Is the domain using the host memory layout? +* +* Direct-mapped domain will always have the RAM mapped with GFN == MFN. xen/include/xen/domain.h void domid_free(domid_t domid); · line 78
Quoted 10 lines
xen/include/xen/domain.h +10
-0+* To avoid any trouble finding space, it is easier to force using the +* host memory layout. +* +* The hardware domain will use the host layout regardless of +* direct-mapped because some OS may rely on a specific address ranges +* for the devices. +*/ +#ifndef domain_use_host_layout +# define domain_use_host_layout (d) (is_domain_direct_mapped(d) || \ + is_hardware_domain(d))...
is_domain_direct_mapped()isn't something that I'd like to see further proliferate in common (non-DT) code.Hi Jan, we have a requirement for 1:1 mapped Dom0 (I should say hardware domain) on x86 as well. In fact, we already have a working prototype, although it is not suitable for upstream yet.
Quoted 8 lines
Quoted 6 lines
In addition to the PSP use case that we discussed a few months ago, where the PSP is not behind an IOMMU and therefore exchanged addresses must be 1:1 mapped, we also have a new use case. We are running the full Xen-based automotive stack on an Azure instance where SVM (vmentry and vmexit) is available, but an IOMMU is not present. All virtual machines are configured as PVH.
Hmm. Then adjustments need making, for commentary and macro to be correct on x86. First and foremost none of what is there is true for PV.
As is_domain_direct_mapped() returns always false for x86, so domain_use_host_layout macro will return incorrect value for non-hardware domains (dom0?). And as PV domains are not auto_translated domains so are always direct-mapped, so technically is_domain_direct_mapped() (or domain_use_host_layout()) should return true in such case.
(I assume it is also true for every domain except HVM according to the comment /* HVM guests are translated. PV guests are not. */ in xc_dom_translated and the comment above definition of XENFEAT_direct_mapped: /* ...not auto_translated domains (x86 only) are always direct-mapped*/).
Is my understanding correct?
Then isn't that a problem of how is_domain_direct_mapped() is defined
for x86? Shouldn't it be defined like:
#define is_domain_direct_mapped(d) (!paging_mode_translate(d) || ((d)->cdf & CDF_directmap))
Would it be better to move "!paging_mode_translate(d) || " to the definition of domain_use_host_layout()?
Could you please explain what is wrong with the comment? Probably, except:
* To avoid any trouble finding space, it is easier to force using the
* host memory layout.
everything else should be true for x86.
~ Oleksii
Re: [PATCH v1 5/6] xen: move domain_use_host_layout() to common header
Quoted 41 lines · Oleksii Kurochko
Quoted 39 lines · Jan Beulich
Quoted 38 lines · Stefano Stabellini
Quoted 11 lines · Jan Beulich
Quoted 2 lines · Oleksii Kurochko
domain_use_host_layout()is generic enough to be moved to the common headerxen/domain.h.Maybe, but then something DT-specific, not
xen/domain.h. Specifically, ...Quoted 6 lines
xen/include/xen/domain.h +0
-0@@ -62,6 +62,22 @@ void domid_free(domid_t domid);#define is_domain_direct_mapped (d) ((d)->cdf & CDF_directmap)#define is_domain_using_staticmem (d) ((d)->cdf & CDF_staticmem)Quoted 16 lines
Quoted 4 lines
xen/include/xen/domain.h +4
-0+/* +* Is the domain using the host memory layout? +* +* Direct-mapped domain will always have the RAM mapped with GFN == MFN. xen/include/xen/domain.h void domid_free(domid_t domid); · line 78
Quoted 10 lines
xen/include/xen/domain.h +10
-0+* To avoid any trouble finding space, it is easier to force using the +* host memory layout. +* +* The hardware domain will use the host layout regardless of +* direct-mapped because some OS may rely on a specific address ranges +* for the devices. +*/ +#ifndef domain_use_host_layout +# define domain_use_host_layout (d) (is_domain_direct_mapped(d) || \ + is_hardware_domain(d))...
is_domain_direct_mapped()isn't something that I'd like to see further proliferate in common (non-DT) code.Hi Jan, we have a requirement for 1:1 mapped Dom0 (I should say hardware domain) on x86 as well. In fact, we already have a working prototype, although it is not suitable for upstream yet.
In addition to the PSP use case that we discussed a few months ago, where the PSP is not behind an IOMMU and therefore exchanged addresses must be 1:1 mapped, we also have a new use case. We are running the full Xen-based automotive stack on an Azure instance where SVM (vmentry and vmexit) is available, but an IOMMU is not present. All virtual machines are configured as PVH.
Quoted 8 lines
Quoted 2 lines
Hmm. Then adjustments need making, for commentary and macro to be correct on x86. First and foremost none of what is there is true for PV.
As
is_domain_direct_mapped()returns always false for x86, sodomain_use_host_layoutmacro will return incorrect value for non-hardware domains (dom0?). And as PV domains are notauto_translateddomains so are always direct-mapped, so technicallyis_domain_direct_mapped()(ordomain_use_host_layout()) should return true in such case.
Hmm? PV domains aren't direct-mapped. Direct-map was introduced by Arm for some special purpose (absence of IOMMU iirc).
Quoted 11 lines
(I assume it is also true for every domain except HVM according to the comment /* HVM guests are translated. PV guests are not. */ in
xc_dom_translatedand the comment above definition ofXENFEAT_direct_mapped: /* ...notauto_translateddomains (x86 only) are always direct-mapped*/).Is my understanding correct?
Then isn't that a problem of how
is_domain_direct_mapped()is defined
for x86? Shouldn't it be defined like:
#defineis_domain_direct_mapped(d)(!paging_mode_translate(d) || ((d)->cdf &CDF_directmap))
Quoted 7 lines
Would it be better to move "!paging_mode_translate(d) || " to the definition of
domain_use_host_layout()?Could you please explain what is wrong with the comment? Probably, except:
* To avoid any trouble finding space, it is easier to force using the
* host memory layout.
everything else should be true for x86.
"The hardware domain will use ..." isn't true for PV Dom0.
Jan
Re: [PATCH v1 5/6] xen: move domain_use_host_layout() to common header
Quoted 43 lines · Jan Beulich
Quoted 42 lines · Oleksii Kurochko
Quoted 41 lines · Jan Beulich
Quoted 32 lines · Stefano Stabellini
Quoted 11 lines · Jan Beulich
Quoted 2 lines · Oleksii Kurochko
domain_use_host_layout()is generic enough to be moved to the common headerxen/domain.h.Maybe, but then something DT-specific, not
xen/domain.h. Specifically, ...Quoted 6 lines
xen/include/xen/domain.h +0
-0@@ -62,6 +62,22 @@ void domid_free(domid_t domid);#define is_domain_direct_mapped (d) ((d)->cdf & CDF_directmap)#define is_domain_using_staticmem (d) ((d)->cdf & CDF_staticmem)Quoted 16 lines
Quoted 4 lines
xen/include/xen/domain.h +4
-0+/* +* Is the domain using the host memory layout? +* +* Direct-mapped domain will always have the RAM mapped with GFN == MFN. xen/include/xen/domain.h void domid_free(domid_t domid); · line 78
Quoted 10 lines
xen/include/xen/domain.h +10
-0+* To avoid any trouble finding space, it is easier to force using the +* host memory layout. +* +* The hardware domain will use the host layout regardless of +* direct-mapped because some OS may rely on a specific address ranges +* for the devices. +*/ +#ifndef domain_use_host_layout +# define domain_use_host_layout (d) (is_domain_direct_mapped(d) || \ + is_hardware_domain(d))...
is_domain_direct_mapped()isn't something that I'd like to see further proliferate in common (non-DT) code.Hi Jan, we have a requirement for 1:1 mapped Dom0 (I should say hardware domain) on x86 as well. In fact, we already have a working prototype, although it is not suitable for upstream yet.
Quoted 6 lines
In addition to the PSP use case that we discussed a few months ago, where the PSP is not behind an IOMMU and therefore exchanged addresses must be 1:1 mapped, we also have a new use case. We are running the full Xen-based automotive stack on an Azure instance where SVM (vmentry and vmexit) is available, but an IOMMU is not present. All virtual machines are configured as PVH.
Hmm. Then adjustments need making, for commentary and macro to be correct on x86. First and foremost none of what is there is true for PV.
Quoted 7 lines
Quoted 5 lines
As
is_domain_direct_mapped()returns always false for x86, sodomain_use_host_layoutmacro will return incorrect value for non-hardware domains (dom0?). And as PV domains are notauto_translateddomains so are always direct-mapped, so technicallyis_domain_direct_mapped()(ordomain_use_host_layout()) should return true in such case.Hmm? PV domains aren't direct-mapped. Direct-map was introduced by Arm for some special purpose (absence of IOMMU iirc).
I made such conclusion because of the comments in the code mentioned below:
- https://elixir.bootlin.com/xen/v4.21.0/source/tools/libs/guest/xg_dom_x86.c#L1880
- https://elixir.bootlin.com/xen/v4.21.0/source/xen/include/public/features.h#L107
Also, in the comment where it is introduced (d66bf122c0a "xen: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped") is mentioned that:
XENFEAT_direct_mapped is always set for not auto-translated guests.
Quoted 12 lines
Quoted 12 lines
(I assume it is also true for every domain except HVM according to the comment /* HVM guests are translated. PV guests are not. */ in
xc_dom_translatedand the comment above definition ofXENFEAT_direct_mapped: /* ...notauto_translateddomains (x86 only) are always direct-mapped*/).Is my understanding correct?
Then isn't that a problem of how
is_domain_direct_mapped()is defined
for x86? Shouldn't it be defined like:
#defineis_domain_direct_mapped(d)(!paging_mode_translate(d) || ((d)->cdf &CDF_directmap))
Quoted 8 lines
Quoted 7 lines
Would it be better to move "!paging_mode_translate(d) || " to the definition of
domain_use_host_layout()?Could you please explain what is wrong with the comment? Probably, except:
* To avoid any trouble finding space, it is easier to force using the
* host memory layout.
everything else should be true for x86."The hardware domain will use ..." isn't true for PV Dom0.
And then just pure is_hardware_domain(d) inside macros isn't correct too, right? So it should be (... || (!is_pv_domain(d) && is_hardware_domain(d)))
~ Oleksii
Re: [PATCH v1 5/6] xen: move domain_use_host_layout() to common header
Quoted 52 lines · Oleksii Kurochko
Quoted 43 lines · Jan Beulich
Quoted 42 lines · Oleksii Kurochko
Quoted 41 lines · Jan Beulich
Quoted 32 lines · Stefano Stabellini
Quoted 11 lines · Jan Beulich
Quoted 2 lines · Oleksii Kurochko
domain_use_host_layout()is generic enough to be moved to the common headerxen/domain.h.Maybe, but then something DT-specific, not
xen/domain.h. Specifically, ...Quoted 6 lines
xen/include/xen/domain.h +0
-0@@ -62,6 +62,22 @@ void domid_free(domid_t domid);#define is_domain_direct_mapped (d) ((d)->cdf & CDF_directmap)#define is_domain_using_staticmem (d) ((d)->cdf & CDF_staticmem)Quoted 16 lines
Quoted 4 lines
xen/include/xen/domain.h +4
-0+/* +* Is the domain using the host memory layout? +* +* Direct-mapped domain will always have the RAM mapped with GFN == MFN. xen/include/xen/domain.h void domid_free(domid_t domid); · line 78
Quoted 10 lines
xen/include/xen/domain.h +10
-0+* To avoid any trouble finding space, it is easier to force using the +* host memory layout. +* +* The hardware domain will use the host layout regardless of +* direct-mapped because some OS may rely on a specific address ranges +* for the devices. +*/ +#ifndef domain_use_host_layout +# define domain_use_host_layout (d) (is_domain_direct_mapped(d) || \ + is_hardware_domain(d))...
is_domain_direct_mapped()isn't something that I'd like to see further proliferate in common (non-DT) code.Hi Jan, we have a requirement for 1:1 mapped Dom0 (I should say hardware domain) on x86 as well. In fact, we already have a working prototype, although it is not suitable for upstream yet.
Quoted 6 lines
In addition to the PSP use case that we discussed a few months ago, where the PSP is not behind an IOMMU and therefore exchanged addresses must be 1:1 mapped, we also have a new use case. We are running the full Xen-based automotive stack on an Azure instance where SVM (vmentry and vmexit) is available, but an IOMMU is not present. All virtual machines are configured as PVH.
Hmm. Then adjustments need making, for commentary and macro to be correct on x86. First and foremost none of what is there is true for PV.
Quoted 7 lines
Quoted 5 lines
As
is_domain_direct_mapped()returns always false for x86, sodomain_use_host_layoutmacro will return incorrect value for non-hardware domains (dom0?). And as PV domains are notauto_translateddomains so are always direct-mapped, so technicallyis_domain_direct_mapped()(ordomain_use_host_layout()) should return true in such case.Hmm? PV domains aren't direct-mapped. Direct-map was introduced by Arm for some special purpose (absence of IOMMU iirc).
Quoted 7 lines
I made such conclusion because of the comments in the code mentioned below:
- https://elixir.bootlin.com/xen/v4.21.0/source/tools/libs/guest/xg_dom_x86.c#L1880
- https://elixir.bootlin.com/xen/v4.21.0/source/xen/include/public/features.h#L107Also, in the comment where it is introduced (
d66bf122c0a"xen: introduceXENFEAT_direct_mappedandXENFEAT_not_direct_mapped") is mentioned that:
XENFEAT_direct_mappedis always set for not auto-translated guests.
Hmm, this you're right with, and XENVER_get_features handling indeed has
if ( !paging_mode_translate(d) || is_domain_direct_mapped(d) )
fi.submap |= (1U << XENFEAT_direct_mapped);Which now I have a vague recollection of not having been happy with back at the time. Based solely on the GFN == MFN statement this may be correct, but "GFN" is a questionable term for PV in the first place. See how e.g. common/memory.c resorts to using GPFN and GMFN, in line with commentary in public/memory.h.
What the above demonstrates quite well though is that there's no direct relationship between XENFEAT_direct_mapped and is_domain_direct_mapped().
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
(I assume it is also true for every domain except HVM according to the comment /* HVM guests are translated. PV guests are not. */ in
xc_dom_translatedand the comment above definition ofXENFEAT_direct_mapped: /* ...notauto_translateddomains (x86 only) are always direct-mapped*/).Is my understanding correct?
Then isn't that a problem of how
is_domain_direct_mapped()is defined
for x86? Shouldn't it be defined like:
#defineis_domain_direct_mapped(d)(!paging_mode_translate(d) || ((d)->cdf &CDF_directmap))Would it be better to move "!paging_mode_translate(d) || " to the definition of
domain_use_host_layout()?
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Could you please explain what is wrong with the comment? Probably, except:
* To avoid any trouble finding space, it is easier to force using the
* host memory layout.
everything else should be true for x86."The hardware domain will use ..." isn't true for PV Dom0.
And then just pure
is_hardware_domain(d)inside macros isn't correct too, right? So it should be (... || (!is_pv_domain(d) &&is_hardware_domain(d)))
Stefano, please can you guide Oleksii to put there something which is both correct and will cover your intended use case as well?
Jan
Re: [PATCH v1 5/6] xen: move domain_use_host_layout() to common header
Quoted 66 lines · Jan Beulich
Quoted 52 lines · Oleksii Kurochko
Quoted 43 lines · Jan Beulich
Quoted 42 lines · Oleksii Kurochko
Quoted 41 lines · Jan Beulich
Quoted 32 lines · Stefano Stabellini
Quoted 11 lines · Jan Beulich
Quoted 2 lines · Oleksii Kurochko
domain_use_host_layout()is generic enough to be moved to the common headerxen/domain.h.Maybe, but then something DT-specific, not
xen/domain.h. Specifically, ...Quoted 6 lines
xen/include/xen/domain.h +0
-0@@ -62,6 +62,22 @@ void domid_free(domid_t domid);#define is_domain_direct_mapped (d) ((d)->cdf & CDF_directmap)#define is_domain_using_staticmem (d) ((d)->cdf & CDF_staticmem)Quoted 16 lines
Quoted 4 lines
xen/include/xen/domain.h +4
-0+/* +* Is the domain using the host memory layout? +* +* Direct-mapped domain will always have the RAM mapped with GFN == MFN. xen/include/xen/domain.h void domid_free(domid_t domid); · line 78
Quoted 10 lines
xen/include/xen/domain.h +10
-0+* To avoid any trouble finding space, it is easier to force using the +* host memory layout. +* +* The hardware domain will use the host layout regardless of +* direct-mapped because some OS may rely on a specific address ranges +* for the devices. +*/ +#ifndef domain_use_host_layout +# define domain_use_host_layout (d) (is_domain_direct_mapped(d) || \ + is_hardware_domain(d))...
is_domain_direct_mapped()isn't something that I'd like to see further proliferate in common (non-DT) code.Hi Jan, we have a requirement for 1:1 mapped Dom0 (I should say hardware domain) on x86 as well. In fact, we already have a working prototype, although it is not suitable for upstream yet.
Quoted 6 lines
In addition to the PSP use case that we discussed a few months ago, where the PSP is not behind an IOMMU and therefore exchanged addresses must be 1:1 mapped, we also have a new use case. We are running the full Xen-based automotive stack on an Azure instance where SVM (vmentry and vmexit) is available, but an IOMMU is not present. All virtual machines are configured as PVH.
Hmm. Then adjustments need making, for commentary and macro to be correct on x86. First and foremost none of what is there is true for PV.
Quoted 7 lines
Quoted 5 lines
As
is_domain_direct_mapped()returns always false for x86, sodomain_use_host_layoutmacro will return incorrect value for non-hardware domains (dom0?). And as PV domains are notauto_translateddomains so are always direct-mapped, so technicallyis_domain_direct_mapped()(ordomain_use_host_layout()) should return true in such case.Hmm? PV domains aren't direct-mapped. Direct-map was introduced by Arm for some special purpose (absence of IOMMU iirc).
Quoted 7 lines
I made such conclusion because of the comments in the code mentioned below:
- https://elixir.bootlin.com/xen/v4.21.0/source/tools/libs/guest/xg_dom_x86.c#L1880
- https://elixir.bootlin.com/xen/v4.21.0/source/xen/include/public/features.h#L107Also, in the comment where it is introduced (
d66bf122c0a"xen: introduceXENFEAT_direct_mappedandXENFEAT_not_direct_mapped") is mentioned that:
XENFEAT_direct_mappedis always set for not auto-translated guests.Hmm, this you're right with, and
XENVER_get_featureshandling indeed hasif ( !paging_mode_translate(d) || is_domain_direct_mapped(d) ) fi.submap |= (1U << XENFEAT_direct_mapped);
Quoted 8 lines
Which now I have a vague recollection of not having been happy with back at the time. Based solely on the GFN == MFN statement this may be correct, but "GFN" is a questionable term for PV in the first place. See how e.g.
common/memory.cresorts to using GPFN and GMFN, in line with commentary inpublic/memory.h.What the above demonstrates quite well though is that there's no direct relationship between
XENFEAT_direct_mappedandis_domain_direct_mapped().
Let's start from the easy case: domain_use_host_layout.
domain_use_host_layout is meant to indicate whether the domain memory map (e.g. the address of the interrupt controller, the start of RAM, etc.) matches the host memory map or not.
It is implemented as:
#define domain_use_host_layout(d) (is_domain_direct_mapped(d) || \
is_hardware_domain(d))
Because on ARM there are two cases:
1) hardware domain is always using the host layout
2) non-hardware domain only use the host layout when directly mapped (more on the later)
I think this can be generalized and made arch-neutral with the caveat that it should return False for PV guests as Jan mentioned. After all the virtual interrupt controller in a PV domain doesn't start at the same guest physical address of the real interrupt controller. The comment can be improved, but let's get to it after we talk about is_domain_direct_mapped.
is_domain_direct_mapped is meant to indicate that a domain's memory is allocated 1:1 such that GFN == MFN. is_domain_direct_mapped is easily applicable as-is to PVH and HVM guests where there are two stages of translation.
What about PV guests? One could take the stance that given that there are no real GFN space, then GFN is always the same as MFN. But this is more philosophical than practical.
Practically, is_domain_direct_mapped() triggers a different code path in xen/common/memory.c:populate_physmap for contiguous 1:1 memory allocations which is probably undesirable for PV guests.
Practically, there is a related flag exposed to Linux XENFEAT_direct_mapped. For HVM/PVH guests makes sense to be one and the same as is_domain_direct_mapped(). This flag is used by Linux to know whether it can use swiotlb-xen or not. Specifically, swiotlb-xen is only usable when XENFEAT_direct_mapped is enabled for ARM guests and the principle could apply to HVM/PVH guests too. What about PV guests? They also make use of swiotlb-xen and XENFEAT_direct_mapped is set to True for PV guests today.
In conclusion, is_domain_direct_mapped() was born for autotranslated guests and is meant to trigger large contigous memory allocations is Xen and permit the usage of swiotlb-xen in Linux. For PV guests, while we want swiotlb-xen and the XENFEAT_direct_mapped flag is already set to True, we don't want to change the memory allocation scheme.
So I think is_domain_direct_mapped() should be always False on x86:
- PV guests should be always False
- PVH/HVM guests could be True but it is currently unimplemented (AMD is working on an implementation)
For compatibility and functionality, XENFEAT_direct_mapped should be left as is.
The implementation of domain_use_host_layout() can be moved to common code with a change:
/*
* Is the auto-translated domain using the host memory layout? *
* domain_use_host_layout() is always False for PV guests.
*
* Direct-mapped domains (autotranslated domains with memory allocated
* contiguously and mapped 1:1 so that GFN == MFN) are always using the
* host memory layout to avoid address clashes.
*
* The hardware domain will use the host layout (regardless of
* direct-mapped) because some OS may rely on a specific address ranges
* for the devices. PV Dom0, like any other PV guests, has
* domain_use_host_layout() returning False.
*/
#define domain_use_host_layout(d) (is_domain_direct_mapped(d) ||
(paging_mode_translate(d) &&
is_hardware_domain(d)))Re: [PATCH v1 5/6] xen: move domain_use_host_layout() to common header
Quoted 156 lines · Stefano Stabellini
Quoted 66 lines · Jan Beulich
Quoted 52 lines · Oleksii Kurochko
Quoted 43 lines · Jan Beulich
Quoted 42 lines · Oleksii Kurochko
Quoted 41 lines · Jan Beulich
Quoted 32 lines · Stefano Stabellini
Quoted 11 lines · Jan Beulich
Quoted 2 lines · Oleksii Kurochko
domain_use_host_layout()is generic enough to be moved to the common headerxen/domain.h.Maybe, but then something DT-specific, not
xen/domain.h. Specifically, ...Quoted 6 lines
xen/include/xen/domain.h +0
-0@@ -62,6 +62,22 @@ void domid_free(domid_t domid);#define is_domain_direct_mapped (d) ((d)->cdf & CDF_directmap)#define is_domain_using_staticmem (d) ((d)->cdf & CDF_staticmem)Quoted 16 lines
Quoted 4 lines
xen/include/xen/domain.h +4
-0+/* +* Is the domain using the host memory layout? +* +* Direct-mapped domain will always have the RAM mapped with GFN == MFN. xen/include/xen/domain.h void domid_free(domid_t domid); · line 78
Quoted 10 lines
xen/include/xen/domain.h +10
-0+* To avoid any trouble finding space, it is easier to force using the +* host memory layout. +* +* The hardware domain will use the host layout regardless of +* direct-mapped because some OS may rely on a specific address ranges +* for the devices. +*/ +#ifndef domain_use_host_layout +# define domain_use_host_layout (d) (is_domain_direct_mapped(d) || \ + is_hardware_domain(d))...
is_domain_direct_mapped()isn't something that I'd like to see further proliferate in common (non-DT) code.Hi Jan, we have a requirement for 1:1 mapped Dom0 (I should say hardware domain) on x86 as well. In fact, we already have a working prototype, although it is not suitable for upstream yet.
Quoted 6 lines
In addition to the PSP use case that we discussed a few months ago, where the PSP is not behind an IOMMU and therefore exchanged addresses must be 1:1 mapped, we also have a new use case. We are running the full Xen-based automotive stack on an Azure instance where SVM (vmentry and vmexit) is available, but an IOMMU is not present. All virtual machines are configured as PVH.
Hmm. Then adjustments need making, for commentary and macro to be correct on x86. First and foremost none of what is there is true for PV.
Quoted 7 lines
Quoted 5 lines
As
is_domain_direct_mapped()returns always false for x86, sodomain_use_host_layoutmacro will return incorrect value for non-hardware domains (dom0?). And as PV domains are notauto_translateddomains so are always direct-mapped, so technicallyis_domain_direct_mapped()(ordomain_use_host_layout()) should return true in such case.Hmm? PV domains aren't direct-mapped. Direct-map was introduced by Arm for some special purpose (absence of IOMMU iirc).
Quoted 7 lines
I made such conclusion because of the comments in the code mentioned below:
- https://elixir.bootlin.com/xen/v4.21.0/source/tools/libs/guest/xg_dom_x86.c#L1880
- https://elixir.bootlin.com/xen/v4.21.0/source/xen/include/public/features.h#L107Also, in the comment where it is introduced (
d66bf122c0a"xen: introduceXENFEAT_direct_mappedandXENFEAT_not_direct_mapped") is mentioned that:
XENFEAT_direct_mappedis always set for not auto-translated guests.Hmm, this you're right with, and
XENVER_get_featureshandling indeed hasif ( !paging_mode_translate(d) || is_domain_direct_mapped(d) ) fi.submap |= (1U << XENFEAT_direct_mapped);Quoted 8 lines
Which now I have a vague recollection of not having been happy with back at the time. Based solely on the GFN == MFN statement this may be correct, but "GFN" is a questionable term for PV in the first place. See how e.g.
common/memory.cresorts to using GPFN and GMFN, in line with commentary inpublic/memory.h.What the above demonstrates quite well though is that there's no direct relationship between
XENFEAT_direct_mappedandis_domain_direct_mapped().Let's start from the easy case:
domain_use_host_layout.
domain_use_host_layoutis meant to indicate whether the domain memory map (e.g. the address of the interrupt controller, the start of RAM, etc.) matches the host memory map or not.It is implemented as:
#define
domain_use_host_layout(d)(is_domain_direct_mapped(d)|| \
is_hardware_domain(d))Because on ARM there are two cases:
1) hardware domain is always using the host layout
2) non-hardware domain only use the host layout when directly mapped (more on the later)I think this can be generalized and made arch-neutral with the caveat that it should return False for PV guests as Jan mentioned. After all the virtual interrupt controller in a PV domain doesn't start at the same guest physical address of the real interrupt controller. The comment can be improved, but let's get to it after we talk about
is_domain_direct_mapped.
is_domain_direct_mappedis meant to indicate that a domain's memory is allocated 1:1 such that GFN == MFN.is_domain_direct_mappedis easily applicable as-is to PVH and HVM guests where there are two stages of translation.What about PV guests? One could take the stance that given that there are no real GFN space, then GFN is always the same as MFN. But this is more philosophical than practical.
Practically,
is_domain_direct_mapped()triggers a different code path in xen/common/memory.c:populate_physmap for contiguous 1:1 memory allocations which is probably undesirable for PV guests.Practically, there is a related flag exposed to Linux
XENFEAT_direct_mapped. For HVM/PVH guests makes sense to be one and the same asis_domain_direct_mapped(). This flag is used by Linux to know whether it can use swiotlb-xen or not. Specifically, swiotlb-xen is only usable whenXENFEAT_direct_mappedis enabled for ARM guests and the principle could apply to HVM/PVH guests too. What about PV guests? They also make use of swiotlb-xen andXENFEAT_direct_mappedis set to True for PV guests today.In conclusion,
is_domain_direct_mapped()was born for autotranslated guests and is meant to trigger large contigous memory allocations is Xen and permit the usage of swiotlb-xen in Linux. For PV guests, while we want swiotlb-xen and theXENFEAT_direct_mappedflag is already set to True, we don't want to change the memory allocation scheme.So I think
is_domain_direct_mapped()should be always False on x86:
- PV guests should be always False
- PVH/HVM guests could be True but it is currently unimplemented (AMD is working on an implementation)For compatibility and functionality,
XENFEAT_direct_mappedshould be left as is.The implementation of
domain_use_host_layout()can be moved to common code with a change:/*
* Is the auto-translated domain using the host memory layout? *
*domain_use_host_layout()is always False for PV guests.
*
* Direct-mapped domains (autotranslated domains with memory allocated
* contiguously and mapped 1:1 so that GFN == MFN) are always using the
* host memory layout to avoid address clashes.
*
* The hardware domain will use the host layout (regardless of
* direct-mapped) because some OS may rely on a specific address ranges
* for the devices. PV Dom0, like any other PV guests, has
*domain_use_host_layout()returning False.
*/
Quoted 3 lines
#define domain_use_host_layout(d) (is_domain_direct_mapped(d) ||
(paging_mode_translate(d) &&
is_hardware_domain(d)))I'll add one thing. While I think it is clear that XENFEAT_direct_mapped should remain as is and that is_domain_direct_mapped() should be always False for PV guests, given that domain_use_host_layout is not currently used on x86 it is debatable how it should be implemented.
For PVH/HVM, domain_use_host_layout() can easily be aligned with ARM.
For PV DomUs, it will return false and there is no issue.
For PV Dom0, I would argue it should return False because the concept of "host memory layout" is about the address of virtual platform devices (interrupt controller, UART, etc.) in the guest physical address space. PV guests don't have virtual devices mapped at specific guest physical addresses, they use hypercalls. But I can see it could be argued either way, when you take into consideration EFI/ACPI tables. For now, domain_use_host_layout() is unused on x86, so it doesn't make a difference.
Re: [PATCH v1 6/6] xen/riscv: enable DOMAIN_BUILD_HELPERS
In reply to Jan BeulichQuoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
xen/include/public/arch-riscv.h +5
-0+#define GUEST_RAM0_BASE xen_mk_ullong(0x80000000)/* 2GB of low RAM @ 2GB */ +#define GUEST_RAM0_SIZE xen_mk_ullong(0x80000000) + +#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE } +#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE }
(cut)
Quoted 3 lines
If all you want are 2Gb guests, why would such guests be 64-bit? And with (iirc) RV32 permitting more than 4Gb (via PPN being 22 bits wide), perhaps even a 32-bit hypervisor would suffice?
Btw, shouldn't we look at VPN width?
My understanding is that we should take GUEST_RAM0_BASE as sgfn address and then map it to mfn's page (allocated by alloc_domheap_pages())? And then repeat this process until we won't map GUEST_RAM0_SIZE.
In this case for RV32 VPN (which is GFN in the current context) is 32-bit wide as RV32 supports only Sv32, what is 2^32 - 1, what is almost 4gb.
~ Oleksii
Re: [PATCH v1 6/6] xen/riscv: enable DOMAIN_BUILD_HELPERS
Quoted 14 lines · Oleksii Kurochko
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
xen/include/public/arch-riscv.h +5
-0+#define GUEST_RAM0_BASE xen_mk_ullong(0x80000000)/* 2GB of low RAM @ 2GB */ +#define GUEST_RAM0_SIZE xen_mk_ullong(0x80000000) + +#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE } +#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE }(cut)
Quoted 3 lines
If all you want are 2Gb guests, why would such guests be 64-bit? And with (iirc) RV32 permitting more than 4Gb (via PPN being 22 bits wide), perhaps even a 32-bit hypervisor would suffice?
Quoted 8 lines
Btw, shouldn't we look at VPN width?
My understanding is that we should take
GUEST_RAM0_BASEas sgfn address and then map it to mfn's page (allocated byalloc_domheap_pages())? And then repeat this process until we won't mapGUEST_RAM0_SIZE.In this case for RV32 VPN (which is GFN in the current context) is 32-bit wide as RV32 supports only Sv32, what is 2^32 - 1, what is almost 4gb.
??? (IOW - I fear I'm confused enough by the question that I don't know how to respond.)
Jan
Re: [PATCH v1 6/6] xen/riscv: enable DOMAIN_BUILD_HELPERS
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
xen/include/public/arch-riscv.h +5
-0+#define GUEST_RAM0_BASE xen_mk_ullong(0x80000000)/* 2GB of low RAM @ 2GB */ +#define GUEST_RAM0_SIZE xen_mk_ullong(0x80000000) + +#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE } +#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE }(cut)
Quoted 3 lines
If all you want are 2Gb guests, why would such guests be 64-bit? And with (iirc) RV32 permitting more than 4Gb (via PPN being 22 bits wide), perhaps even a 32-bit hypervisor would suffice?
Btw, shouldn't we look at VPN width?
Quoted 8 lines
Quoted 6 lines
My understanding is that we should take
GUEST_RAM0_BASEas sgfn address and then map it to mfn's page (allocated byalloc_domheap_pages())? And then repeat this process until we won't mapGUEST_RAM0_SIZE.In this case for RV32 VPN (which is GFN in the current context) is 32-bit wide as RV32 supports only Sv32, what is 2^32 - 1, what is almost 4gb.
??? (IOW - I fear I'm confused enough by the question that I don't know how to respond.)
You mentioned above that:
"... And with (iirc) RV32 permitting more than 4Gb (via PPN being 22 bits wide) ..."
I wanted to clarify why you use PPN here in the context of GUEST_RAM0_BASE definition. (and maybe I just misinterpreted incorrectly your original message) GUEST_RAM0_BASE is the address at which the guest believes RAM starts in its physical address space, i.e. it is a GPA, which is then translated to an MPA.
From the MMU's perspective, the GPA looks like:
VPN[1] | VPN[0] | page_offset (in Sv32x4 mode)
In Sv32x4, the GPA is 34 bits wide (or 22 bits wide in terms of GFNs), and the MPA is also 32 bits wide (or 22 bits wide in terms of PPN).
The distinction is not significant in Sv32x4, since PPN width equals VPN width, but in other modes VPN < PPN (in terms of bit width).
So when we want to run a guest in Sv39x4 mode and want to give the guest the full Sv39x4 address space, setting GUEST_RAM0_SIZE to the maximum possible value for Sv39x4, shouldn't we look at the VPN width rather than the PPN width? In other words, GUEST_RAM0_SIZE should be (2^41 - 1) rather than (2^56 - 1) for Sv39x4.
~ Oleksii
Re: [PATCH v1 6/6] xen/riscv: enable DOMAIN_BUILD_HELPERS
Quoted 32 lines · Oleksii Kurochko
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +5
-0+#define GUEST_RAM0_BASE xen_mk_ullong(0x80000000) /* 2GB of low RAM @ 2GB */ +#define GUEST_RAM0_SIZE xen_mk_ullong(0x80000000) + +#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE } +#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE }(cut)
Quoted 3 lines
If all you want are 2Gb guests, why would such guests be 64-bit? And with (iirc) RV32 permitting more than 4Gb (via PPN being 22 bits wide), perhaps even a 32-bit hypervisor would suffice?
Btw, shouldn't we look at VPN width?
Quoted 8 lines
Quoted 6 lines
My understanding is that we should take
GUEST_RAM0_BASEas sgfn address and then map it to mfn's page (allocated byalloc_domheap_pages())? And then repeat this process until we won't mapGUEST_RAM0_SIZE.In this case for RV32 VPN (which is GFN in the current context) is 32-bit wide as RV32 supports only Sv32, what is 2^32 - 1, what is almost 4gb.
??? (IOW - I fear I'm confused enough by the question that I don't know how to respond.)
You mentioned above that:
"... And with (iirc) RV32 permitting more than 4Gb (via PPN being 22 bits wide) ..."I wanted to clarify why you use PPN here in the context of
GUEST_RAM0_BASEdefinition. (and maybe I just misinterpreted incorrectly your original message)GUEST_RAM0_BASEis the address at which the guest believes RAM starts in its physical address space, i.e. it is a GPA, which is then translated to an MPA.
Quoted 5 lines
From the MMU's perspective, the GPA looks like:
VPN[1] | VPN[0] | page_offset (in Sv32x4 mode)In Sv32x4, the GPA is 34 bits wide (or 22 bits wide in terms of GFNs), and the MPA is also 32 bits wide (or 22 bits wide in terms of PPN).
You mentioning Sv32x4 may point at part of the problem: For the guest physical memory layout (and hence size), paging and hence virtual addresses don't matter at all. What matters is what the guest can put in the page table entries it writes. Addresses there are represented as PPNs, aren't they? Hence my use of that acronym.
Quoted 5 lines
The distinction is not significant in Sv32x4, since PPN width equals VPN width, but in other modes VPN < PPN (in terms of bit width).
So when we want to run a guest in Sv39x4 mode and want to give the guest the full Sv39x4 address space, settingGUEST_RAM0_SIZEto the maximum possible value for Sv39x4, shouldn't we look at the VPN width rather than the PPN width?
No, why? The guest can arrange to map more than 2^39 bytes. Not all at the same time, sure, but by suitable switching page tables (or merely entries) around.
Jan
Quoted 5 lines
In other words,
GUEST_RAM0_SIZEshould be (2^41 - 1) rather than (2^56 - 1) for Sv39x4.~ Oleksii
Re: [PATCH v1 6/6] xen/riscv: enable DOMAIN_BUILD_HELPERS
Quoted 36 lines · Jan Beulich
Quoted 35 lines · Oleksii Kurochko
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +5
-0+#define GUEST_RAM0_BASE xen_mk_ullong(0x80000000) /* 2GB of low RAM @ 2GB */ +#define GUEST_RAM0_SIZE xen_mk_ullong(0x80000000) + +#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE } +#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE }(cut)
Quoted 3 lines
If all you want are 2Gb guests, why would such guests be 64-bit? And with (iirc) RV32 permitting more than 4Gb (via PPN being 22 bits wide), perhaps even a 32-bit hypervisor would suffice?
Btw, shouldn't we look at VPN width?
Quoted 8 lines
Quoted 6 lines
My understanding is that we should take
GUEST_RAM0_BASEas sgfn address and then map it to mfn's page (allocated byalloc_domheap_pages())? And then repeat this process until we won't mapGUEST_RAM0_SIZE.In this case for RV32 VPN (which is GFN in the current context) is 32-bit wide as RV32 supports only Sv32, what is 2^32 - 1, what is almost 4gb.
??? (IOW - I fear I'm confused enough by the question that I don't know how to respond.)
You mentioned above that:
"... And with (iirc) RV32 permitting more than 4Gb (via PPN being 22 bits wide) ..."I wanted to clarify why you use PPN here in the context of
GUEST_RAM0_BASEdefinition. (and maybe I just misinterpreted incorrectly your original message)GUEST_RAM0_BASEis the address at which the guest believes RAM starts in its physical address space, i.e. it is a GPA, which is then translated to an MPA.From the MMU's perspective, the GPA looks like:
VPN[1] | VPN[0] | page_offset (in Sv32x4 mode)
Quoted 8 lines
Quoted 2 lines
In Sv32x4, the GPA is 34 bits wide (or 22 bits wide in terms of GFNs), and the MPA is also 32 bits wide (or 22 bits wide in terms of PPN).
You mentioning Sv32x4 may point at part of the problem: For the guest physical memory layout (and hence size), paging and hence virtual addresses don't matter at all. What matters is what the guest can put in the page table entries it writes. Addresses there are represented as PPNs, aren't they? Hence my use of that acronym.
That's is what I came to after wrote and sent an e-mail. Now you confirmed that.
Quoted 10 lines
Quoted 6 lines
The distinction is not significant in Sv32x4, since PPN width equals VPN width, but in other modes VPN < PPN (in terms of bit width).
So when we want to run a guest in Sv39x4 mode and want to give the guest the full Sv39x4 address space, settingGUEST_RAM0_SIZEto the maximum possible value for Sv39x4, shouldn't we look at the VPN width rather than the PPN width?No, why? The guest can arrange to map more than 2^39 bytes. Not all at the same time, sure, but by suitable switching page tables (or merely entries) around.
Good point. Then the right limit is therefore the PPN width which reflects the actual physical addressing capability.
Thanks a lot.
~ Oleksii