Introduce enablemenant of dom0less
PATCH v4 6/25 xen/riscv: Implement construct_domain()
In reply to Oleksii KurochkoImplement construct_domain() function for RISC-V, which performs initial setup for the domain's first vCPU, loads the kernel, initrd, and device tree, and sets up guest CPU registers for boot.
It also creates additional vCPUs up to max_vcpus and assigns the device tree address and boot cpuid in registers.
---
Changes in v4:
- Drop the blank before v%u in the printk() failure message so the output matches that of %pv.
- Restore Acked-by that was lost in v3.
---
Changes in v3:
- s/%d/%u for printing vCPU index in the failure message.
- Drop dprintk() for successful vCPU creation.
---
Changes in v2:
- Rework construct_domain() to print that vCPU1...n are created using %pv.
- Use true instead of 1 for initialization of v->is_initialised.
- Drop unnessary BUG_ON() in construct_domain().
- Add TODO comment above *_load() functions.
---
--- xen/arch/riscv/Makefile | 1 + xen/arch/riscv/domain-build.c | 50 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 xen/arch/riscv/domain-build.c
xen/arch/riscv/Makefile +1 -0
@@ -1,6 +1,7 @@ obj-y += aplic.o obj-y += cpufeature.o obj-y += domain.o +obj-y += domain-build.init.o obj-$(CONFIG_DOM0LESS_BOOT) += dom0less-build.init.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-y += entry.o
xen/arch/riscv/domain-build.c new file +50 -0
50 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v4 3/25 xen: arm: update p2m_set_allocation() prototype
In reply to Oleksii Kurochkop2m_set_allocation() uses a bool *preempted out-argument that overloads two meanings. When non-NULL, the value written back (true) duplicates information already carried by the -ERESTART return code — pure redundancy, which the caller-side ASSERT(preempted == (rc == -ERESTART)) only documents. Separately, a NULL pointer is an implicit calling convention meaning "preemption is not permitted in this context".
Replace the pointer with a plain bool can_preempt that explicitly controls whether the preemption check runs, making the NULL-to-suppress convention type-safe and self-documenting, and rely on the -ERESTART return code alone to report that preemption occurred.
Since p2m_set_allocation() is called by the common dom0less build code, move its declaration from the ARM-specific asm/p2m.h to xen/p2m-common.h.
---
Changes in v4:
- Reword commit message: a NULL pointer was a calling convention meaning "preemption not permitted", not pure redundancy.
- Annotate the explicit can_preempt arguments at the call sites with /* can_preempt */ comments for readability.
- Move the function's doc comment to the prototype in xen/p2m-common.h (dropping the duplicate above the Arm and RISC-V definitions) and clarify that -ERESTART is only returned when can_preempt is true.
- Add __must_check to the prototype, since the return code is now the only preemption-status indicator.
---
Changes in v3:
- Nothing changed. Only rebase.
---
Changes in v2:
- new patch
---
--- xen/arch/arm/include/asm/p2m.h | 1 - xen/arch/arm/mmu/p2m.c | 24 ++++++------------------ xen/arch/riscv/include/asm/paging.h | 2 +- xen/arch/riscv/p2m.c | 9 ++------- xen/arch/riscv/paging.c | 7 ++----- xen/common/device-tree/dom0less-build.c | 2 +- xen/include/xen/p2m-common.h | 8 ++++++++ 7 files changed, 20 insertions(+), 33 deletions(-)
xen/arch/arm/include/asm/p2m.h +0 -1
@@ -238,7 +238,6 @@ void p2m_restore_state(struct vcpu *n);/* Print debugging/statistial info about a domain's p2m */ void p2m_dump_info (struct domain *d); -int p2m_set_allocation (struct domain *d,unsigned long pages,bool *preempted);int p2m_teardown_allocation (struct domain *d);static inline void p2m_write_lock (struct p2m_domain *p2m)
xen/arch/arm/mmu/p2m.c +6 -18
@@ -65,12 +65,7 @@ int arch_get_paging_mempool_size(struct domain *d, uint64_t *size)return 0 ; } -/* -* Set the pool of pages to the required number of pages. -* Returns 0 for success, non-zero for failure. -* Call with d->arch.paging.lock held. -*/ -int p2m_set_allocation (struct domain *d,unsigned long pages,bool *preempted) +int p2m_set_allocation (struct domain *d,unsigned long pages,bool can_preempt) {struct page_info *pg;
@@ -112,11 +107,8 @@ int p2m_set_allocation(struct domain *d, unsigned long pages, bool *preempted)break ;/* Check to see if we need to yield and try again */ -if ( preempted &&general_preempt_check () ) - { - *preempted = true; +if ( can_preempt &&general_preempt_check () )return -ERESTART ; - } }return 0 ;
@@ -125,7 +117,6 @@ int p2m_set_allocation(struct domain *d, unsigned long pages, bool *preempted)int arch_set_paging_mempool_size (struct domain *d,uint64_t size) {unsigned long pages = size >>PAGE_SHIFT ; -bool preempted = false;int rc; if ( (size & ~PAGE_MASK) || /* Non page-sized request? */
@@ -133,27 +124,24 @@ int arch_set_paging_mempool_size(struct domain *d, uint64_t size)return -EINVAL ;spin_lock (&d->arch.paging.lock); - rc =p2m_set_allocation (d, pages, &preempted); + rc =p2m_set_allocation (d, pages,/* can_preempt */ true);spin_unlock (&d->arch.paging.lock); -ASSERT (preempted == (rc == -ERESTART )); -return rc; }int p2m_teardown_allocation (struct domain *d) {int ret =0 ; -bool preempted = false;spin_lock (&d->arch.paging.lock);if ( d->arch.paging.p2m_total_pages !=0 ) { - ret =p2m_set_allocation (d,0 , &preempted); -if ( preempted ) + ret =p2m_set_allocation (d,0 ,/* can_preempt */ true); +if ( ret == -ERESTART ) {spin_unlock (&d->arch.paging.lock); -return -ERESTART ; +return ret; }ASSERT (d->arch.paging.p2m_total_pages ==0 ); }
xen/arch/riscv/include/asm/paging.h +1 -1
@@ -9,7 +9,7 @@ struct page_info;int paging_domain_init (struct domain *d);int paging_freelist_adjust (struct domain *d,unsigned long pages, -bool *preempted); +bool can_preempt);int paging_ret_to_domheap (struct domain *d,unsigned int nr_pages);int paging_refill_from_domheap (struct domain *d,unsigned int nr_pages);
xen/arch/riscv/p2m.c +2 -7
@@ -428,17 +428,12 @@ int p2m_init(struct domain *d, const struct xen_domctl_createdomain *config)return 0 ; } -/* -* Set the pool of pages to the required number of pages. -* Returns 0 for success, non-zero for failure. -* Call with d->arch.paging.lock held. -*/ -int p2m_set_allocation (struct domain *d,unsigned long pages,bool *preempted) +int p2m_set_allocation (struct domain *d,unsigned long pages,bool can_preempt) {struct p2m_domain *p2m =p2m_get_hostp2m (d);int rc; -if ( (rc =paging_freelist_adjust (d, pages, preempted)) ) +if ( (rc =paging_freelist_adjust (d, pages, can_preempt)) )return rc;/*
xen/arch/riscv/paging.c +2 -5
@@ -47,7 +47,7 @@ static int _paging_add_to_freelist(struct domain *d) }int paging_freelist_adjust (struct domain *d,unsigned long pages, -bool *preempted) +bool can_preempt) {ASSERT (spin_is_locked (&d->arch.paging.lock));
@@ -66,11 +66,8 @@ int paging_freelist_adjust(struct domain *d, unsigned long pages,return rc;/* Check to see if we need to yield and try again */ -if ( preempted &&general_preempt_check () ) - { - *preempted = true; +if ( can_preempt &&general_preempt_check () )return -ERESTART ; - } }return 0 ;
xen/common/device-tree/dom0less-build.c +1 -1
@@ -747,7 +747,7 @@ static int __init domain_p2m_set_allocation(struct domain *d, uint64_t mem,domain_p2m_pages (mem, d->max_vcpus);spin_lock (&d->arch.paging.lock); - rc =p2m_set_allocation (d, p2m_pages,NULL ); + rc =p2m_set_allocation (d, p2m_pages,/* can_preempt */ false);spin_unlock (&d->arch.paging.lock);return rc;
xen/include/xen/p2m-common.h +8 -0
@@ -43,5 +43,13 @@ int __must_check check_get_page_from_gfn(struct domain *d, gfn_t gfn, bool readonly, p2m_type_t *p2mt_p, struct page_info **page_p); +/* +* Set the pool of pages to the required number of pages. +* Returns 0 for success, -ERESTART if preempted (only when can_preempt is +* true), or a negative error code on failure. +* Call with d->arch.paging.lock held. +*/ +int __must_check p2m_set_allocation (struct domain *d,unsigned long pages, +bool can_preempt);#endif /* _XEN_P2M_COMMON_H */
Signature · 1 line
2.54.0
PATCH v4 7/25 xen/riscv: implement prerequisites for domain_create()
In reply to Oleksii Kurochkoarch_domain_create() and arch_sanitise_domain_config() are prerequisites for domain_create().
arch_sanitise_domain_config() currently returns 0, as there is no specific work required at this stage.
arch_domain_create() performs basic initialization, such as setting up the P2M and initializing of next unused phandle.
---
Changes in v4:
- Add Acked-by: Jan Beulich <[email protected]>.
---
Changes in v3:
- Move arch_domain_destroy() from stubs.c to domain.c next to arch_domain_create().
- Drop d->is_dying = DOMDYING_dead from arch_domain_create()'s fail label as domain_create() already does it.
- Replace BUG_ON("unimplemented") with printk() in arch_domain_destroy().
---
Changes in v2:
- update the commit message.
- Drop vcpu_switch_to_aarch64_mode() from riscv/stubs. It shouldn't be under
riscv/ at all.
- Drop next_phandle as it is now in common code.
---
--- xen/arch/riscv/domain.c | 29 +++++++++++++++++++++++++++++ xen/arch/riscv/stubs.c | 17 ----------------- 2 files changed, 29 insertions(+), 17 deletions(-)
xen/arch/riscv/domain.c +29 -0
@@ -289,6 +289,35 @@ void sync_vcpu_execstate(struct vcpu *v)/* Nothing to do -- no lazy switching */ } +int arch_sanitise_domain_config (struct xen_domctl_createdomain *config) +{ +return 0 ; +} + +void arch_domain_destroy (struct domain *d) +{ +printk (XENLOG_WARNING "%s: unimplemented\n" , __func__); +} + +int arch_domain_create (struct domain *d, +struct xen_domctl_createdomain *config, +unsigned int flags) +{ +int rc =0 ; + +if (is_idle_domain (d) ) +return 0 ; + +if ( (rc =p2m_init (d, config)) !=0 ) + goto fail; + +return rc; + + fail: +arch_domain_destroy (d); +return rc; +} +static void __init __maybe_unused build_assertions (void ) {/*
xen/arch/riscv/stubs.c +0 -17
@@ -101,28 +101,11 @@ void dump_pageframe_info(struct domain *d)BUG_ON ("unimplemented" ); } -int arch_sanitise_domain_config (struct xen_domctl_createdomain *config) -{ -BUG_ON ("unimplemented" ); -} - -int arch_domain_create (struct domain *d, -struct xen_domctl_createdomain *config, -unsigned int flags) -{ -BUG_ON ("unimplemented" ); -} -int arch_domain_teardown (struct domain *d) {BUG_ON ("unimplemented" ); } -void arch_domain_destroy (struct domain *d) -{ -BUG_ON ("unimplemented" ); -} -void arch_domain_shutdown (struct domain *d) {BUG_ON ("unimplemented" );
Signature · 1 line
2.54.0
PATCH v4 12/25 xen/riscv: introduce init interrupt controller operations
In reply to Oleksii KurochkoIntroduce intc_hw_init_ops structure to avoid risky mix of init function and non-init function.
---
Changes in v4:
- Use __initconstrel instead of __initconst for aplic_init_ops as both initialized fields incur a relocation.
- Add Acked-by: ... .
---
Changes in v3:
- Use __initconst instead of __initdata for const intc_hw_init_ops.
- Embed const struct intc_hw_operations *ops into intc_hw_init_ops so register_intc_ops() takes a single pointer argument.
---
Changes in v2:
- New patch.
---
--- xen/arch/riscv/aplic.c | 8 ++++++-- xen/arch/riscv/include/asm/intc.h | 10 +++++++--- xen/arch/riscv/intc.c | 11 ++++++++--- 3 files changed, 21 insertions(+), 8 deletions(-)
xen/arch/riscv/aplic.c +6 -2
@@ -306,12 +306,16 @@ static const hw_irq_controller aplic_xen_irq_type = {static const struct intc_hw_operations aplic_ops = { .info = &aplic_info, - .init = aplic_init, .host_irq_type = &aplic_xen_irq_type, .handle_interrupt = aplic_handle_interrupt, .set_irq_type = aplic_set_irq_type, }; +static const struct intc_hw_init_ops __initconstrel aplic_init_ops = { + .ops = &aplic_ops, + .init = aplic_init, +}; + static int cf_check aplic_irq_xlate(const uint32_t *intspec, unsigned int intsize, unsigned int *out_hwirq,
@@ -347,7 +351,7 @@ static int __init aplic_preinit(struct dt_device_node *node, const void *dat) dt_irq_xlate = aplic_irq_xlate; -register_intc_ops (&aplic_ops); +register_intc_ops (&aplic_init_ops);/* Enable supervisor external interrupt */ csr_set (CSR_SIE ,BIT (IRQ_S_EXT ,UL ));
xen/arch/riscv/include/asm/intc.h +7 -3
@@ -28,8 +28,6 @@ struct intc_info {struct intc_hw_operations {/* Hold intc hw information */ const struct intc_info *info; -/* Initialize the intc and the boot CPU */ -int (*init)(void );/* hw_irq_controller to enable/disable/eoi host irq */ const struct hw_interrupt_type *host_irq_type;
@@ -43,9 +41,15 @@ struct intc_hw_operations {void (*handle_interrupt)(struct cpu_user_regs *regs); }; +struct intc_hw_init_ops { +const struct intc_hw_operations *ops; +/* Initialize the intc and the boot CPU */ +int (*init)(void ); +}; +void intc_preinit (void ); -void register_intc_ops (const struct intc_hw_operations *ops); +void register_intc_ops (const struct intc_hw_init_ops *init_ops);void intc_init (void );
xen/arch/riscv/intc.c +8 -3
@@ -12,9 +12,12 @@static const struct intc_hw_operations *__ro_after_init intc_hw_ops; -void __init register_intc_ops (const struct intc_hw_operations *ops) +static const struct intc_hw_init_ops *__initdata intc_hw_init_ops; + +void __init register_intc_ops (const struct intc_hw_init_ops *init_ops) { - intc_hw_ops = ops; + intc_hw_ops = init_ops->ops; + intc_hw_init_ops = init_ops; }void __init intc_preinit (void )
@@ -27,7 +30,9 @@ void __init intc_preinit(void)void __init intc_init (void ) { -if ( intc_hw_ops->init () ) +ASSERT (intc_hw_init_ops && intc_hw_init_ops->init); + +if ( intc_hw_init_ops->init () )panic ("Failed to initialize the interrupt controller drivers\n" ); }
Signature · 1 line
2.54.0
PATCH v4 14/25 xen/riscv: introduce aia_init() and aia_usable()
In reply to Oleksii Kurochkoaia_init() is going to contain all the logic related to AIA initialization.
At the moment, it only checks whether the SSAIA extension is available, and if so, sets is_aia_usable (which indicates more than just the availability of the extension) to true; it also signifies that the necessary components (to be introduced in follow-up patches) have been initialized.
---
Changes in v4:
- Add Acked-by: Jan Beulich <[email protected]>
---
Changes in v3:
- s/is_aia_usable/_aia_usable to drop the is_ prefix while avoiding conflict with the aia_usable() function name.
---
Changes in v2:
- s/is_aia_available/is_aia_usable.
- Drop return value for aia_init().
- s/aia_available()/aia_usable().
---
--- xen/arch/riscv/Makefile | 1 + xen/arch/riscv/aia.c | 23 +++++++++++++++++++++++ xen/arch/riscv/include/asm/aia.h | 10 ++++++++++ xen/arch/riscv/intc.c | 3 +++ 4 files changed, 37 insertions(+) create mode 100644 xen/arch/riscv/aia.c create mode 100644 xen/arch/riscv/include/asm/aia.h
xen/arch/riscv/Makefile +1 -0
@@ -1,3 +1,4 @@ +obj-y += aia.o obj-y += aplic.o obj-y += cpufeature.o obj-y += domain.o
xen/arch/riscv/aia.c new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <xen/errno.h> +#include <xen/init.h> +#include <xen/sections.h> +#include <xen/types.h> + +#include <asm/cpufeature.h> + +static bool __ro_after_init _aia_usable; + +bool aia_usable (void ) +{ +return _aia_usable; +} + +void __init aia_init (void ) +{ +if ( !riscv_isa_extension_available (NULL , RISCV_ISA_EXT_ssaia) ) +return ; + + _aia_usable = true; +}
xen/arch/riscv/include/asm/aia.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef ASM__RISCV__AIA_H +#define ASM__RISCV__AIA_H + +bool aia_usable (void ); + +void aia_init (void ); + +#endif /* ASM__RISCV__ACPI_H */
xen/arch/riscv/intc.c +3 -0
@@ -9,6 +9,7 @@#include <xen/lib.h> #include <xen/spinlock.h> +#include <asm/aia.h> #include <asm/intc.h> static const struct intc_hw_operations *__ro_after_init intc_hw_ops;
@@ -33,6 +34,8 @@ void __init intc_init(void) {ASSERT (intc_hw_init_ops && intc_hw_init_ops->init); +aia_init (); +if ( intc_hw_init_ops->init () )panic ("Failed to initialize the interrupt controller drivers\n" ); }
Signature · 1 line
2.54.0
v4 cover Introduce enablemenant of dom0less
This patch series reprensent a bunch of patches necessary to enable common part of Dom0less.
The stuff necessary to start/launch domains will be introduced separately.
CI tests: https://gitlab.com/xen-project/people/olkur/xen/-/pipelines/2632323911
---
Changes in v4:
- Address comments from ML.
---
Changes in v3:
- Drop dependency from other patch series
([1] https://lore.kernel.org/xen-devel/[email protected]/T/#t)
as it was merged.
- Reorder patches:
- move common patches to the start.
- Move some patches to separate patch series (will be introduced later)
- Address comments from ML.
---
Changes in v2:
- Move patch "[PATCH v1 04/27] xen/riscv: rework G-stage mode handling" to patch series [1]
- Address the comments from ML.
- The following patches were folded into one:
# xen/riscv: implement init_intc_phandle()
# xen/riscv: call do_initcalls() in start_xen()
# xen/riscv: setup system domains
- The following patch were folded into one:
# xen/riscv: add vaplic access check
# xen/riscv: emulate guest writes to virtual APLIC MMIO
# xen/riscv: emulate guest reads from virtual APLIC MMIO
- Add new bug fix, not really necessary to this patch series:
xen/riscv: manage IRQ_DISABLED flag in APLIC irq enable/disable callbacks
---
Oleksii Kurochko (25):
xen/dom0less: turn max_init_domid into a common variable
xen: arm: move declaration of map_device_irqs_to_domain() to common
header
xen: arm: update p2m_set_allocation() prototype xen/Kconfig: introduce HAS_STATIC_MEMORY
xen/riscv: Implement ARCH_PAGING_MEMPOOL
xen/riscv: Implement construct_domain()
xen/riscv: implement prerequisites for domain_create() xen/riscv: introduce guest riscv,isa string
xen/riscv: implement make_cpus_node()
xen/riscv: implement make_timer_node()
xen/riscv: implement make_arch_nodes()
xen/riscv: introduce init interrupt controller operations xen/riscv: implement make_intc_domU_node()
xen/riscv: introduce aia_init() and aia_usable() xen/riscv: introduce per-vCPU IMSIC state
xen/riscv: introduce minimal virtual APLIC (vAPLIC) infrastructure xen/riscv: rename enum intc_version to intc_variant xen/riscv: introduce (de)initialization helpers for vINTC xen/riscv: generate IMSIC DT node for guest domains xen/riscv: create APLIC DT node for guest domains xen/riscv: implement IRQ routing for device passthrough xen/riscv: implement init_intc_phandle()
xen/riscv: initialize RCU, scheduler, and system domains in
start_xen()
xen/riscv: provide init_vuart()
xen/riscv: add initial dom0less infrastructure support
xen/arch/arm/Kconfig | 1 + xen/arch/arm/device.c | 9 +- xen/arch/arm/include/asm/p2m.h | 1 - xen/arch/arm/include/asm/setup.h | 5 - xen/arch/arm/mmu/p2m.c | 24 +-- xen/arch/arm/setup.c | 2 - xen/arch/ppc/include/asm/setup.h | 2 - xen/arch/riscv/Kconfig | 3 + xen/arch/riscv/Makefile | 4 + xen/arch/riscv/aia.c | 23 +++ xen/arch/riscv/aplic.c | 14 +- xen/arch/riscv/cpufeature.c | 88 ++++++++- xen/arch/riscv/device.c | 95 +++++++++ xen/arch/riscv/dom0less-build.c | 40 ++++ xen/arch/riscv/domain-build.c | 192 ++++++++++++++++++ xen/arch/riscv/domain.c | 46 ++++- xen/arch/riscv/imsic.c | 172 ++++++++++++++++ xen/arch/riscv/include/asm/aia.h | 10 + xen/arch/riscv/include/asm/aplic.h | 11 ++ xen/arch/riscv/include/asm/cpufeature.h | 4 + xen/arch/riscv/include/asm/domain.h | 8 + xen/arch/riscv/include/asm/guest-layout.h | 24 +++ xen/arch/riscv/include/asm/imsic.h | 25 +++ xen/arch/riscv/include/asm/intc.h | 48 ++++- xen/arch/riscv/include/asm/irq.h | 5 + xen/arch/riscv/include/asm/paging.h | 2 +- xen/arch/riscv/include/asm/setup.h | 2 - xen/arch/riscv/include/asm/vaplic.h | 34 ++++ xen/arch/riscv/intc.c | 101 +++++++++- xen/arch/riscv/irq.c | 230 ++++++++++++++++++++++ xen/arch/riscv/p2m.c | 33 +++- xen/arch/riscv/paging.c | 7 +- xen/arch/riscv/setup.c | 12 ++ xen/arch/riscv/stubs.c | 17 -- xen/arch/riscv/vaplic.c | 141 +++++++++++++ xen/arch/x86/include/asm/setup.h | 2 - xen/common/Kconfig | 4 + xen/common/device-tree/dom0less-build.c | 2 +- xen/common/domid.c | 5 + xen/drivers/char/console.c | 1 + xen/include/xen/dom0less-build.h | 7 + xen/include/xen/fdt-domain-build.h | 13 ++ xen/include/xen/p2m-common.h | 8 + 43 files changed, 1384 insertions(+), 93 deletions(-) create mode 100644 xen/arch/riscv/aia.c create mode 100644 xen/arch/riscv/device.c create mode 100644 xen/arch/riscv/domain-build.c create mode 100644 xen/arch/riscv/include/asm/aia.h create mode 100644 xen/arch/riscv/include/asm/vaplic.h create mode 100644 xen/arch/riscv/vaplic.c
Signature · 1 line
2.54.0
PATCH v4 11/25 xen/riscv: implement make_arch_nodes()
No RISC-V-specific nodes need to be created at the moment, so make_arch_nodes() is implemented to simply return 0.
It is placed in dom0less-build.c as make_arch_nodes() is only used in the dom0less code path. In the future, it will be extended to create an emulated UART node.
Add Acked-by: Jan Beulich <[email protected]>
---
Change in v4:
- Add lost Acked-by.
---
Changes in v3:
- Add Acked-by: Jan Beulich <[email protected]>.
---
Changes in v2:
- Update the commit message.
---
--- xen/arch/riscv/dom0less-build.c | 8 ++++++++ 1 file changed, 8 insertions(+)
xen/arch/riscv/dom0less-build.c +8 -0
@@ -2,10 +2,18 @@#include <xen/bootfdt.h> #include <xen/device_tree.h> +#include <xen/fdt-kernel.h> #include <xen/init.h> #include <asm/p2m.h> +int __init make_arch_nodes (struct kernel_info *kinfo) +{ +/* No RISC-V specific nodes need to be made, at the moment. */ + +return 0 ; +} +int __init arch_parse_dom0less_node (struct dt_device_node *node,struct boot_domain *bd) {
Signature · 1 line
2.54.0
PATCH v4 18/25 xen/riscv: introduce (de)initialization helpers for vINTC
In reply to Oleksii KurochkoAdd common helpers domain_vintc_init() and domain_vintc_deinit() to allocate and deallocate a virtual interrupt controller (vINTC) structure and initialize basic virtual interrupt controller registers.
domain_vintc_deinit() isn't called at the moment as arch_domain_destroy() is implemented as stub at the moment.
---
Changes in v4:
- Drop the comment from domain_vintc_init() about guests receiving a virtual interrupt controller that mirrors the host hardware as there can (and eventually should) be alternatives.
- Finish renaming intc_version to intc_variant in domain_vintc_(de)init() (enum intc_variant, info->hw_variant, local variable) started in the prev patch.
---
Changes in v3:
- Drop redundant printk() from domain_vintc_deinit()'s default case to avoid duplicate messages when init fails.
- Add a comment to domain_vintc_init() clarifying that guests currently receive a virtual interrupt controller that mirrors the host hardware.
---
Changes in v2:
- Drop __init for domain_vintc_(de)init().
- Update the commit message.
---
--- xen/arch/riscv/domain.c | 3 +++ xen/arch/riscv/include/asm/intc.h | 3 +++ xen/arch/riscv/intc.c | 35 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+)
xen/arch/riscv/domain.c +3 -0
@@ -309,6 +309,9 @@ int arch_domain_create(struct domain *d,if ( (rc =p2m_init (d, config)) !=0 ) goto fail; +if ( (rc =domain_vintc_init (d)) ) + goto fail; +return rc; fail:
xen/arch/riscv/include/asm/intc.h +3 -0
@@ -75,4 +75,7 @@ void intc_route_irq_to_xen(struct irq_desc *desc, unsigned int priority);void intc_handle_external_irqs (struct cpu_user_regs *regs); +int domain_vintc_init (struct domain *d); +void domain_vintc_deinit (struct domain *d); +#endif /* ASM__RISCV__INTERRUPT_CONTOLLER_H */
xen/arch/riscv/intc.c +35 -0
@@ -11,6 +11,7 @@#include <asm/aia.h> #include <asm/intc.h> +#include <asm/vaplic.h> static const struct intc_hw_operations *__ro_after_init intc_hw_ops;
@@ -83,3 +84,37 @@ int __init make_intc_domU_node(struct kernel_info *kinfo)return vintc->init_ops->make_domu_dt_node (kinfo); } + +int domain_vintc_init (struct domain *d) +{ +int ret = -EOPNOTSUPP ; +const enum intc_variant variant = intc_hw_ops->info->hw_variant; + +switch ( variant ) + { +case INTC_APLIC : + ret =domain_vaplic_init (d); +break ; + +default : +printk ("vintc (variant:%d) isn't implemented\n" , variant); +break ; + } + +return ret; +} + +void domain_vintc_deinit (struct domain *d) +{ +const enum intc_variant variant = intc_hw_ops->info->hw_variant; + +switch ( variant ) + { +case INTC_APLIC : +domain_vaplic_deinit (d); +break ; + +default : +break ; + } +}
Signature · 1 line
2.54.0
PATCH v4 19/25 xen/riscv: generate IMSIC DT node for guest domains
In reply to Oleksii KurochkoGuests using the IMSIC interrupt controller require a corresponding Device Tree description.
Add support for generating an IMSIC node when building the guest DT. This allows guests to discover and use the IMSIC interrupt controller.
The value choosen for GUEST_IMSIC_S_BASE is an address which is typically used for IMSIC and QEMU.
DT-building functions are marked __init because domain creation happens at boot time, before the init sections are freed. In a typical deployment libxl creates the interrupt controller node in userspace and hands the complete FDT to Xen, so these functions are only called during early domain construction.
---
Changes in v4:
- Add a comment for guest_num_msis explaining that it is host-dependent and therefore identical for every domain, which is why a single global is used instead of a per-domain value.
- Reduce vimsic_name[] from 128 to 32 bytes, which is enough to hold "/soc/imsic@" plus a 64-bit hex address.
- Add a comment before GUEST_IMSIC_S_BASE noting that the value is the address typically used for IMSIC by QEMU.
- s/__ULL/_UL for defintion of GUEST_IMSIC_S_BASE.
---
Changes in v3:
- s/__ro_after_init/__read_mostly for guest_num_msis.
- Use IMSIC_MAX_ID as default for guest_num_msis instead of imsic_cfg.nr_ids.
- Drop base_addr local variable in guest_imsic_make_reg_property(); use GUEST_IMSIC_S_BASE directly and introduce size to avoid spelling IMSIC_MMIO_PAGE_SZ * d->max_vcpus twice.
- Change irq_ext type from uint32_t * to __be32 * in guest_imsic_set_interrupt_extended_prop().
- Move phandle declaration into the loop body.
- Extend commit message to explain why __init is used for DT-building
functions: libxl creates the interrupt controller node before handing the FDT to Xen, so these functions are only invoked during boot-time domain construction.
- Re-order patch before APLIC DT node creation patch.
- Update commit message.
---
Changes in v2:
- s/imsic_make_reg_property/guest_imsic_make_reg_property.
- s/imsic_set_interrupt_extended_prop/guest_imsic_set_interrupt_extended_prop.
- Use initalizer for regs[] array in imsic_make_reg_property().
- Move buf[] insde the for() loop.
- Correct check of returned phandle.
- Drop local variable len.
- /s/XVFREE/xvfree in imsic_set_interrupt_extended_prop().
- Drop initializer for local variable data.
- s/uint32_t/unsinged int for pos and cpu in imsic_set_interrupt_extended_prop().
- Drop next_phandle as it is now in common code.
- Introduce vcpu_imsic_deinit.
- Refactor vimsic_make_domu_dt_node() to avoid usage of host IMSIC dt node.
---
--- xen/arch/riscv/imsic.c | 137 ++++++++++++++++++++++ xen/arch/riscv/include/asm/guest-layout.h | 6 + 2 files changed, 143 insertions(+)
xen/arch/riscv/imsic.c +137 -0
@@ -13,8 +13,12 @@#include <xen/const.h> #include <xen/cpumask.h> #include <xen/device_tree.h> +#include <xen/domain.h> #include <xen/errno.h> +#include <xen/fdt-domain-build.h> +#include <xen/fdt-kernel.h> #include <xen/init.h> +#include <xen/libfdt/libfdt.h> #include <xen/macros.h> #include <xen/sched.h> #include <xen/smp.h>
@@ -34,6 +38,16 @@ static struct imsic_config imsic_cfg = { .lock = SPIN_LOCK_UNLOCKED, }; +/* +* Number of MSIs available to a guest. Determined by the host interrupt +* controller, so it is identical for every domain -- hence a single global +* rather than a per-domain value. +*/ +static unsigned int __read_mostly guest_num_msis; + +#define GUEST_IMSIC_COMPATIBLE "riscv,imsics" +#define GUEST_IMSIC_NUM_MSIS 255 +#define IMSIC_DISABLE_EIDELIVERY 0#define IMSIC_ENABLE_EIDELIVERY 1#define IMSIC_DISABLE_EITHRESHOLD 1
@@ -285,6 +299,11 @@ static int imsic_parse_node(const struct dt_device_node *node,return -ENOENT ; } +if (dt_property_read_u32 (node,"riscv,num-guest-ids" , &tmp) ) + guest_num_msis = tmp; +else + guest_num_msis =IMSIC_MAX_ID ; +if ( (imsic_cfg.nr_ids <IMSIC_MIN_ID ) || (imsic_cfg.nr_ids >IMSIC_MAX_ID ) ) {
@@ -522,3 +541,121 @@ int __init imsic_init(const struct dt_device_node *node)return rc; } + +static int __init guest_imsic_make_reg_property (struct domain *d,void *fdt) +{ +paddr_t size =IMSIC_MMIO_PAGE_SZ * d->max_vcpus; +__be32 regs[4 ] = { +cpu_to_be32 (GUEST_IMSIC_S_BASE >>32 ), +cpu_to_be32 (GUEST_IMSIC_S_BASE ), +cpu_to_be32 (size >>32 ), +cpu_to_be32 (size), + }; + +return fdt_property (fdt,"reg" , regs,sizeof (regs)); +} + +static int __init guest_imsic_set_interrupt_extended_prop (struct domain *d, +void *fdt) +{ +unsigned int cpu, pos =0 ; +__be32 *irq_ext; +int res; + + irq_ext =xvzalloc_array (__be32, d->max_vcpus *2 ); +if ( !irq_ext ) +return -ENOMEM ; + +for ( cpu =0 ; cpu < d->max_vcpus; cpu++ ) + { +char buf[64 ]; +uint32_t phandle; + +snprintf (buf,sizeof (buf),"/cpus/cpu@%u/interrupt-controller" , cpu); + phandle =fdt_get_phandle (fdt,fdt_path_offset (fdt, buf)); + +if ( !phandle ) + { + res = -ENODEV ; + goto out; + } + + irq_ext[pos++] =cpu_to_be32 (phandle); + irq_ext[pos++] =cpu_to_be32 (IRQ_S_EXT ); + } + + res =fdt_property (fdt,"interrupts-extended" , irq_ext, + d->max_vcpus *2 *sizeof (*irq_ext)); + + out: +xvfree (irq_ext); + +return res; +} + +int __init vimsic_make_domu_dt_node (struct kernel_info *kinfo, +unsigned int *phandle) +{ +int res; +void *fdt = kinfo->fdt; +char vimsic_name[32 ]; +unsigned int vimsic_phandle; +unsigned int num_msis =min (GUEST_IMSIC_NUM_MSIS +0U , guest_num_msis); + + res =snprintf (vimsic_name,sizeof (vimsic_name),"/soc/imsic@%lx" , +GUEST_IMSIC_S_BASE ); +if ( res >=sizeof (vimsic_name) ) + { +dprintk (XENLOG_DEBUG ,"vimsic name is truncated\n" ); +return -ENOBUFS ; + } + + res =fdt_begin_node (fdt, vimsic_name); +if ( res ) +return res; + + res =fdt_property_string (fdt,"compatible" ,GUEST_IMSIC_COMPATIBLE ); +if ( res ) +return res; + + res =guest_imsic_make_reg_property (kinfo->bd.d, fdt); +if ( res ) +return res; + + res =guest_imsic_set_interrupt_extended_prop (kinfo->bd.d, fdt); +if ( res ) +return res; + + res =fdt_property_u32 (fdt,"riscv,num-ids" , num_msis); +if ( res ) +return res; + + res =fdt_property (fdt,"msi-controller" ,NULL ,0 ); +if ( res ) +return res; + + res =fdt_property_u32 (fdt,"#msi-cells" ,0 ); +if ( res ) +return res; + + res =fdt_property (fdt,"interrupt-controller" ,NULL ,0 ); +if ( res ) +return res; + + res =fdt_property_u32 (fdt,"#interrupt-cells" ,0 ); +if ( res ) +return res; + + vimsic_phandle =alloc_phandle (kinfo); +if ( !vimsic_phandle ) +return -EOVERFLOW ; + + res =fdt_property_cell (fdt,"phandle" , vimsic_phandle); +if ( res ) +return res; + +if ( phandle ) + *phandle = vimsic_phandle; + +return fdt_end_node (fdt); +}
xen/arch/riscv/include/asm/guest-layout.h +6 -0
@@ -3,6 +3,12 @@#include <public/xen.h> +/* +* Base address of the guest's supervisor-mode IMSIC. The value is the address +* typically used for IMSIC by QEMU. +*/ +#define GUEST_IMSIC_S_BASE _UL(0x28000000) +#define GUEST_RAM_BANKS 2/*
Signature · 1 line
2.54.0
PATCH v4 2/25 xen: arm: move declaration of map_device_irqs_to_domain() to common header
In reply to Oleksii KurochkoAs map_device_irqs_to_domain() is used unconditionally by common part of dom0less code, move the prototype to a common header.
fdt-domain-build.h is chosen as map_device_irqs_to_domain() could be also called indirectly in Arm's DOM0-related code and DT overlay feature.
---
Changes in v4:
- Reword commit message: use imperative mood ("move the prototype") and mention the DT overlay feature alongside Arm's DOM0-related code.
- Add #include <xen/fdt-domain-build.h> to Arm's device.c so the definition site sees the prototype.
- Drop the duplicated function description above the definition in device.c (it now lives only on the prototype in fdt-domain-build.h).
---
Changes in v3:
- Add tag arm and move this patch earlier before RISC-V-related patches.
---
Changes in v2:
- New patch.
--- xen/arch/arm/device.c | 9 +-------- xen/arch/arm/include/asm/setup.h | 3 --- xen/include/xen/fdt-domain-build.h | 13 +++++++++++++ 3 files changed, 14 insertions(+), 11 deletions(-)
xen/arch/arm/device.c +1 -8
@@ -11,6 +11,7 @@#include <xen/device_tree.h> #include <xen/dt-overlay.h> #include <xen/errno.h> +#include <xen/fdt-domain-build.h> #include <xen/iocap.h> #include <xen/lib.h>
@@ -117,14 +118,6 @@ int __overlay_init map_range_to_domain(const struct dt_device_node *dev,return 0 ; } -/* -* map_device_irqs_to_domain retrieves the interrupts configuration from -* a device tree node and maps those interrupts to the target domain. -* -* Returns: -* < 0 error -* 0 success -*/ int __overlay_init map_device_irqs_to_domain(struct domain *d, struct dt_device_node *dev, bool need_mapping,
xen/arch/arm/include/asm/setup.h +0 -3
@@ -51,9 +51,6 @@ void init_traps(void);int handle_device (struct domain *d,struct dt_device_node *dev,p2m_type_t p2mt,struct rangeset *iomem_ranges,struct rangeset *irq_ranges); -int map_device_irqs_to_domain (struct domain *d,struct dt_device_node *dev, -bool need_mapping,struct rangeset *irq_ranges); -int map_irq_to_domain (struct domain *d,unsigned int irq,bool need_mapping,const char *devname);
xen/include/xen/fdt-domain-build.h +13 -0
@@ -12,6 +12,7 @@struct domain ;struct page_info ; +struct rangeset ;struct membanks ; typedef bool (*alloc_domheap_mem_cb)(struct domain *d, struct page_info *pg,
@@ -79,6 +80,18 @@ static inline void set_domain_type(struct domain *d, const struct kernel_info *k #endif } +/* +* Retrieves the interrupts configuration from a device tree node and maps +* those interrupts to the target domain. +* +* Returns: +* < 0 error +* 0 success +*/ +int map_device_irqs_to_domain (struct domain *d,struct dt_device_node *dev, +bool need_mapping, +struct rangeset *irq_ranges); +#endif /* __XEN_FDT_DOMAIN_BUILD_H__ */ /*
Signature · 1 line
2.54.0
PATCH v4 4/25 xen/Kconfig: introduce HAS_STATIC_MEMORY
In reply to Oleksii KurochkoIntroduce HAS_STATIC_MEMORY so that STATIC_MEMORY can be enabled or disabled on a per-architecture basis. ARM selects the new flag; RISC-V does not, so CONFIG_STATIC_MEMORY is unavailable on RISC-V and randconfig builds no longer require an explicit STATIC_MEMORY=n override to avoid a compilation error.
---
Changes in v4:
- Reword the commit message to explain that HAS_STATIC_MEMORY allows STATIC_MEMORY to be {en,dis}abled per-arch, dropping the reference to guest_physmap_add_pages().
- Split the STATIC_MEMORY dependency into two separate "depends on" lines.
---
Changes in v3:
- New patch.
---
--- xen/arch/arm/Kconfig | 1 + xen/common/Kconfig | 4 ++++ 2 files changed, 5 insertions(+)
xen/arch/arm/Kconfig +1 -0
@@ -22,6 +22,7 @@ config ARM select HAS_GRANT_CACHE_FLUSH if GRANT_TABLE select HAS_SHARED_INFO select HAS_STACK_PROTECTOR + select HAS_STATIC_MEMORY select HAS_UBSAN config ARCH_DEFCONFIG
xen/common/Kconfig +4 -0
@@ -161,6 +161,9 @@ config HAS_SCHED_GRANULARITY config HAS_SHARED_INFO bool +config HAS_STATIC_MEMORY + bool + config HAS_SOFT_RESET bool
@@ -196,6 +199,7 @@ config NUMA config STATIC_MEMORY bool "Static Allocation Support (UNSUPPORTED)" if UNSUPPORTED + depends on HAS_STATIC_MEMORY depends on DOM0LESS_BOOT && HAS_DEVICE_TREE_DISCOVERY help Static Allocation refers to system or sub-system(domains) for
Signature · 1 line
2.54.0
PATCH v4 13/25 xen/riscv: implement make_intc_domU_node()
In reply to Oleksii KurochkoIntroduce a RISC-V specific function to create an interrupt controller Device Tree node for DomU domains during dom0less build.
Add make_intc_domU_node() to the dom0less build path and wire it to a new generic helper, intc_make_domu_dt_node(), which delegates DT node creation to the active interrupt controller implementation via vintc_init_ops.
---
Change in v4:
- Made local variable vintc pointer-to-const.
- Add Acked-by: Jan Beulich <[email protected]>
---
Changes in v3:
- Use const struct vintc_init_ops *init_ops in struct vintc.
- Drop redundant intc_hw_ops check in make_intc_domU_node().
- Drop NULL pointer checks in make_intc_domU_node() as we can't start domU without properly created interrupt contoller node.
---
Changes in v2:
- s/intc_make_domu_dt_node/make_intc_domU_node.
- introduce separate intc_hw_init_ops structure for init operations.
- Return -EOPNOTSUPP instead of -ENOSYS.
- Drop const for kinfo argument as it could be changed by interrupt controller node creation code.
- Refactor make_domu_dt_node().
- Make make_domu_dt_node part of vintc structure as it looks more logical to be there.
---
--- xen/arch/riscv/include/asm/domain.h | 2 ++ xen/arch/riscv/include/asm/intc.h | 12 ++++++++++-- xen/arch/riscv/intc.c | 8 ++++++++ 3 files changed, 20 insertions(+), 2 deletions(-)
xen/arch/riscv/include/asm/domain.h +2 -0
@@ -98,6 +98,8 @@ struct arch_domain {DECLARE_BITMAP (isa,RISCV_ISA_EXT_MAX );char *isa_str; + +struct vintc *vintc; };#include <xen/sched.h>
xen/arch/riscv/include/asm/intc.h +10 -2
@@ -8,14 +8,13 @@ #ifndef ASM__RISCV__INTERRUPT_CONTOLLER_H #define ASM__RISCV__INTERRUPT_CONTOLLER_H -struct dt_device_node; - enum intc_version { INTC_APLIC, }; struct cpu_user_regs; struct irq_desc; +struct kernel_info; struct intc_info { enum intc_version hw_version;
@@ -47,6 +46,15 @@ struct intc_hw_init_ops {int (*init)(void ); }; +struct vintc_init_ops { +/* Create interrupt controller node for domain */ +int (*make_domu_dt_node)(struct kernel_info *kinfo); +}; + +struct vintc { +const struct vintc_init_ops *init_ops; +}; +void intc_preinit (void );void register_intc_ops (const struct intc_hw_init_ops *init_ops);
xen/arch/riscv/intc.c +8 -0
@@ -3,6 +3,7 @@#include <xen/acpi.h> #include <xen/bug.h> #include <xen/device_tree.h> +#include <xen/fdt-kernel.h> #include <xen/init.h> #include <xen/irq.h> #include <xen/lib.h>
@@ -72,3 +73,10 @@ void intc_route_irq_to_xen(struct irq_desc *desc, unsigned int priority)intc_set_irq_type (desc, desc->arch.type);intc_set_irq_priority (desc, priority); } + +int __init make_intc_domU_node (struct kernel_info *kinfo) +{ +const struct vintc *vintc = kinfo->bd.d->arch.vintc; + +return vintc->init_ops->make_domu_dt_node (kinfo); +}
Signature · 1 line
2.54.0
PATCH v4 16/25 xen/riscv: introduce minimal virtual APLIC (vAPLIC) infrastructure
In reply to Oleksii KurochkoAt the current development stage, only domain vINTC init and deinit operations are required, so implement those first.
Initialize vAPLIC's domaincfg to with the interrupt-enable bit set and MSI delivery mode selected as the current solution is exepcted to have always IMSIC, and initialize vintc->ops.
Other operations such as emulate_load(), emulate_store(), and is_access() will be needed once guests are running and MMIO accesses to APLIC MMIO range must be handled. These will be introduced separately later.
Introduce a structure to describe a virtual interrupt controller (vINTC) and a vintc_ops structure, which provides operations to emulate load and store accesses to interrupt controller MMIOs and to check whether a given address falls within the MMIO range of a specific virtual interrupt controller.
The vAPLIC implementation of these operations will be provided later once guests can be run and these operations are actually needed.
Introduce these structures here as they are required for the implementation of domain_vaplic_init() and domain_vaplic_alloc(). Also, introduce vaplic_init() and init vintc_ops->vcpu_init() with it.
---
Changes in v4:
- Change subject of the commit.
- s/APLIC_DOMAINCFG_RO80/APLIC_DOMAINCFG_RO + added a comment above definition.
- Drop unnessary blank lines.
---
Changes in v3:
- Drop ASSERT() before vintc->ops->vcpu_init() in arch_vcpu_create(); a NULL deref already produces a sufficient backtrace.
- Parenthesize macro argument in to_vaplic().
- Drop __init from domain_vaplic_init() and domain_vaplic_deinit() since the caller domain_vintc_init() (follow-up patch) is not __init.
- Remove pointless zero-initializer for rc in vcpu_vaplic_init().
- Fix domain_vaplic_deinit() to null d->arch.vintc before freeing, making the function idempotent.
- Drop intc_irq_nums(), (*nr_irqs)(void) hook from intc_hw_operations, aplic_nr_irqs(), and vintc->nr_irqs field entirely.
- Rename vcpu_vaplic_init() to vaplic_init() and drop vgein_assign() and imsic_set_guest_file_id() calls; those will be introduced/called later, where for sure we will know on which pCPU vCPU as it is required for proper h/w IMSIC interrupt file calculation, to have this initialization in one place.
- Introduce vaplic_deinit().
---
Changes in v2:
- s/vcpu/v for function arguments in struct vintc_ops().
- Update the comment above is_access() and drop const for addr argument.
- Update to_vaplic() to work with 'struct domain *'.
- Drop smsiaddrcfg{h} from vaplic_regs struct as they aren't used for now.
- Drop inclusion of xen/schec.h from intc.c.
- use result of xvzalloc() as initializer in vpalic_alloc().
- Drop goto in domain_vaplic_init().
- s/XVFREE/xvfree.
- s/aplic/vintc.
- Drop __init for vcpu_vaplic_init() as it could be called for secondary CPU bring up.
- Drop vaplic_alloc().
- Drop vintc_ops struct, embed callbacks iniside struct vintc.
- Introduce and init vintc irqs for vAPLIC.
- Introduce intc_irq_nums() to properly initialize number of vAPLIC's irqs.
---
--- xen/arch/riscv/Makefile | 1 + xen/arch/riscv/domain.c | 11 ++--- xen/arch/riscv/include/asm/aplic.h | 3 ++ xen/arch/riscv/include/asm/intc.h | 10 +++++ xen/arch/riscv/include/asm/vaplic.h | 34 ++++++++++++++++ xen/arch/riscv/vaplic.c | 63 +++++++++++++++++++++++++++++ 6 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 xen/arch/riscv/include/asm/vaplic.h create mode 100644 xen/arch/riscv/vaplic.c
xen/arch/riscv/Makefile +1 -0
@@ -25,6 +25,7 @@ obj-y += smpboot.o obj-y += stubs.o obj-y += time.o obj-y += traps.o +obj-y += vaplic.o obj-y += vmid.o obj-y += vm_event.o obj-y += vsbi/
xen/arch/riscv/domain.c +3 -8
@@ -11,6 +11,7 @@#include <asm/bitops.h> #include <asm/cpufeature.h> #include <asm/csr.h> +#include <asm/intc.h> #include <asm/riscv_encoding.h> #include <asm/vtimer.h>
@@ -155,14 +156,8 @@ int arch_vcpu_create(struct vcpu *v)if ( (rc =vcpu_vtimer_init (v)) ) goto fail; -/* -* As interrupt controller (IC) is not yet implemented, -* return an error. -* -* TODO: Drop this once IC is implemented. -*/ - rc = -EOPNOTSUPP ; - goto fail; +if ( (rc = v->domain->arch.vintc->ops->vcpu_init (v)) ) + goto fail;return rc;
xen/arch/riscv/include/asm/aplic.h +3 -0
@@ -15,6 +15,9 @@#include <asm/imsic.h> + +/* domaincfg bits 31:24 are read-only 0x80 */ +#define APLIC_DOMAINCFG_RO (0x80U << 24)#define APLIC_DOMAINCFG_IE BIT(8, U)#define APLIC_DOMAINCFG_DM BIT(2, U)
xen/arch/riscv/include/asm/intc.h +10 -0
@@ -15,6 +15,7 @@ enum intc_version {struct cpu_user_regs ;struct irq_desc ;struct kernel_info ; +struct vcpu ;struct intc_info {enum intc_version hw_version;
@@ -51,8 +52,17 @@ struct vintc_init_ops {int (*make_domu_dt_node)(struct kernel_info *kinfo); }; +struct vintc_ops { +/* Initialize some vINTC-related stuff for a vCPU */ +int (*vcpu_init)(struct vcpu *v); + +/* Deinitialize some vINTC-related stuff for a vCPU */ +void (*vcpu_deinit)(struct vcpu *v); +}; +struct vintc {const struct vintc_init_ops *init_ops; +const struct vintc_ops *ops; };void intc_preinit (void );
xen/arch/riscv/include/asm/vaplic.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: MIT */ +/* +* xen/arch/riscv/vaplic.c +* +* Virtual RISC-V Advanced Platform-Level Interrupt Controller support +* +* Copyright (c) Microchip. +*/ + +#ifndef ASM__RISCV__VAPLIC_H +#define ASM__RISCV__VAPLIC_H + +#include <xen/kernel.h> +#include <xen/types.h> + +#include <asm/intc.h> + +struct domain ; + +#define to_vaplic (d) container_of((d)->arch.vintc, struct vaplic, vintc) + +struct vaplic_regs { +uint32_t domaincfg; +}; + +struct vaplic { +struct vintc vintc; +struct vaplic_regs regs; +}; + +int domain_vaplic_init (struct domain *d); +void domain_vaplic_deinit (struct domain *d); + +#endif /* ASM__RISCV__VAPLIC_H */
xen/arch/riscv/vaplic.c new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v4 5/25 xen/riscv: Implement ARCH_PAGING_MEMPOOL
In reply to Oleksii KurochkoThe p2m_freelist is used to allocate pages for the P2M. To initialize this list, domain_p2m_set_allocation() may be called from construct_domU() in the common Dom0less code, so RISC-V provides an implementation and enables CONFIG_ARCH_PAGING_MEMPOOL unconditionally.
Additionally, implement arch_{set,get}_paging_mempool_size(). They are not directly used yet, but are required to support the XEN_DOMCTL_{get,set}_paging_mempool_size hypercalls.
---
Changes in v4:
- Nothing changed. Only rebase.
---
Changes in v3:
- Drop stray blank space in arch_get_paging_mempool_size().
- Add Acked-by: Jan Beulich <[email protected]>.
---
Changes in v2:
- Turn on CONFIG_ARCH_PAGING_MEMPOOL=y unconditionally and drop all ifdef-s related to this config.
- Optimize check inside arch_set_paging_mempool_size which verify size argument.
- Use pfn_to_paddr() inside arch_get_paging_mempool_size() instead of open coding the stuff.
- Drop ASSERT() from arch_set_paging_mempool_size() as it is impossible to have here preempted = true and rc != -ERESTART.
---
--- xen/arch/riscv/Kconfig | 1 + xen/arch/riscv/p2m.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+)
xen/arch/riscv/Kconfig +1 -0
@@ -1,5 +1,6 @@ config RISCV def_bool y + select ARCH_PAGING_MEMPOOL select DOMAIN_BUILD_HELPERS select FUNCTION_ALIGNMENT_16B select GENERIC_BUG_FRAME
xen/arch/riscv/p2m.c +24 -0
@@ -1600,3 +1600,27 @@ struct page_info *get_page_from_gfn(struct domain *d, unsigned long gfn,return p2m_get_page_from_gfn (p2m_get_hostp2m (d),_gfn (gfn), t); } + +int arch_set_paging_mempool_size (struct domain *d,uint64_t size) +{ +unsigned long pages =PFN_DOWN (size); +int rc; + +/* Non page-sized request or 32-bit overflow? */ +if (pfn_to_paddr (pages) != size ) +return -EINVAL ; + +spin_lock (&d->arch.paging.lock); + rc =p2m_set_allocation (d, pages, true); +spin_unlock (&d->arch.paging.lock); + +return rc; +} + +/* Return the size of the pool, in bytes. */ +int arch_get_paging_mempool_size (struct domain *d,uint64_t *size) +{ + *size =pfn_to_paddr (ACCESS_ONCE (d->arch.paging.total_pages)); + +return 0 ; +}
Signature · 1 line
2.54.0
PATCH v4 17/25 xen/riscv: rename enum intc_version to intc_variant
In reply to Oleksii KurochkoRename the enum to intc_variant and the structure member from hw_version to hw_variant to better reflect that these values select between different controller variants, not versions of the same one.
---
Changes in v4:
- New patch. Prereq for the next patch.
---
--- xen/arch/riscv/aplic.c | 2 +- xen/arch/riscv/include/asm/intc.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
xen/arch/riscv/aplic.c +1 -1
@@ -35,7 +35,7 @@ static struct aplic_priv aplic = { };static struct intc_info __ro_after_init aplic_info = { - .hw_version =INTC_APLIC , + .hw_variant =INTC_APLIC , };static void __init aplic_init_hw_interrupts (void )
xen/arch/riscv/include/asm/intc.h +2 -2
@@ -8,7 +8,7 @@#ifndef ASM__RISCV__INTERRUPT_CONTOLLER_H #define ASM__RISCV__INTERRUPT_CONTOLLER_H -enum intc_version { +enum intc_variant {INTC_APLIC , };
@@ -18,7 +18,7 @@ struct kernel_info;struct vcpu ;struct intc_info { -enum intc_version hw_version; +enum intc_variant hw_variant;const struct dt_device_node *node;/* number of irqs */
Signature · 1 line
2.54.0
PATCH v4 8/25 xen/riscv: introduce guest riscv,isa string
In reply to Oleksii KurochkoIntroduce generation of the riscv,isa string passed to the guest via the Device Tree riscv,isa property.
Introduce the per-domain isa string and guest isa bitmap, populated during domain creation by calling init_guest_isa().
Introduce guest_unsupp to filter out ISA extensions that should not be exposed to guests:
- f/d/q/v: FPU and vector context save/restore are not yet implemented for guests.
- Z*inx are not exposed either: they aren't in riscv_isa_ext[], so they can never be set in riscv_isa and thus never reach a guest, and no current hardware/guest-OS advertises or expects them. Supporting them would be cheaper than F/D/Q (FP values stay in integer registers Xen already context-switches), but is left as future work.
- h: Nested virtualisation is not supported.
- sstc: Xen owns the supervisor timer; guests must use SBI.
- svade: Xen manages hardware A/D bit updates in stage-2 page tables.
- svpbmt: Page-based memory types are not yet wired up in stage-2 code.
Drop __initconst for riscv_isa_ext() as it can be used after init stage by init_guest_isa().
---
Changes in v4:
- Add an explicit overflow guard in build_guest_isa_str(): return -ENOSPC when buf is non-NULL and total >= size, to avoid the size - total underflow being passed to snprintf().
- Expand the commit message to explain why Zfinx/Zdinx/Zqinx are not added to guest_unsupp (not in riscv_isa_ext[], so never set in riscv_isa nor exposed to a guest; left as future work)
---
Changes in v3:
- s/set_bit/__set_bit in init_guest_unsupp() as atomicity isn't needed at init time.
- Drop RISCV_GUEST_ISA_STR_MAX; allocate isa_str dynamically with xvmalloc_array().
- Drop "guest" prefix from d->arch.guest_isa and d->arch.guest_isa_str.
- Introduce build_guest_isa_str() using snprintf(NULL, 0, ...) to determine the needed buffer size; init_guest_isa() calls it once for sizing and once to fill, keeping both in a single function so they can't go out of sync.
- Scope ret inside the loop; initialize total directly from the prefix snprintf().
- Merge "_" separator and extension name into a single snprintf() with "%s%s".
- Replace ASSERT with an explicit error check: if the fill call returns a different length, free isa_str and return -EINVAL.
---
Changes in v2:
- s/guest_unsupp_bmp/guest_unsupp.
- Drop guest_isa_str.
- Provide init_guest_isa() instead of polluting match_isa_ext().
- Drop xlen.
- Add the comment about guest_unsupp.
- Update the way how guest_unsupp is init-ed.
- Drop __initconst for riscv_isa_ext[] as it is used in init_guest_isa() which isn't marked as __init as it could be used after init stage.
---
--- xen/arch/riscv/cpufeature.c | 88 ++++++++++++++++++++++++- xen/arch/riscv/domain.c | 3 + xen/arch/riscv/include/asm/cpufeature.h | 4 ++ xen/arch/riscv/include/asm/domain.h | 4 ++ 4 files changed, 98 insertions(+), 1 deletion(-)
xen/arch/riscv/cpufeature.c +87 -1
@@ -14,7 +14,9 @@#include <xen/errno.h> #include <xen/init.h> #include <xen/lib.h> +#include <xen/sched.h> #include <xen/sections.h> +#include <xen/xvmalloc.h> #include <asm/cpufeature.h> #include <asm/csr.h>
@@ -120,7 +122,7 @@ static int __init dt_get_cpuid_from_node(const struct dt_device_node *cpu,* and strncmp() is used in match_isa_ext() to compare extension names instead * of strncasecmp(). */ -const struct riscv_isa_ext_data __initconst riscv_isa_ext[] = { +const struct riscv_isa_ext_data riscv_isa_ext[] = {RISCV_ISA_EXT_DATA (i),RISCV_ISA_EXT_DATA (m),RISCV_ISA_EXT_DATA (a),
@@ -128,6 +130,7 @@ const struct riscv_isa_ext_data __initconst riscv_isa_ext[] = {RISCV_ISA_EXT_DATA (d),RISCV_ISA_EXT_DATA (q),RISCV_ISA_EXT_DATA (c), +RISCV_ISA_EXT_DATA (v),RISCV_ISA_EXT_DATA (h),RISCV_ISA_EXT_DATA (zicntr), RISCV_ISA_EXT_DATA(zicsr),
@@ -160,6 +163,12 @@ static const struct riscv_isa_ext_data __initconst required_extensions[] = { RISCV_ISA_EXT_DATA(svpbmt), }; +/* +* Everything in riscv_isa_ext[] which shouldn't be exposed to guests should +* appear here. +*/ +static __ro_after_init DECLARE_BITMAP(guest_unsupp, RISCV_ISA_EXT_MAX); +static bool __init is_lowercase_extension_name (const char *str) {/*
@@ -480,6 +489,81 @@ bool riscv_isa_extension_available(const unsigned long *isa_bitmap,return test_bit (id, isa_bitmap); } +static int build_guest_isa_str (char *buf,size_t size, +const unsigned long *isa_bitmap) +{ +int total; + +#if defined(CONFIG_RISCV_32 ) + total =snprintf (buf, size,"rv32" ); +#elif defined(CONFIG_RISCV_64 ) + total =snprintf (buf, size,"rv64" ); +#else +# error "Unsupported RISC-V bitness" +#endif + +if ( total <0 ) +return total; + +if ( buf && ((size_t )total >= size) ) +return -ENOSPC ; + +for (unsigned int i =0 ; i <ARRAY_SIZE (riscv_isa_ext); i++ ) + { +const struct riscv_isa_ext_data *ext = &riscv_isa_ext[i]; +int ret; + +if ( !riscv_isa_extension_available (isa_bitmap, ext->id) ) +continue ; + + ret =snprintf (buf ? buf + total :NULL , + buf ? size - total :0 ,"%s%s" , + ext->id >=RISCV_ISA_EXT_BASE ?"_" :"" , + ext->name); +if ( ret <0 ) +return ret; + total += ret; + } + +return total; +} + +int init_guest_isa (struct domain *d) +{ +int len; + +bitmap_andnot (d->arch.isa, riscv_isa, guest_unsupp, +RISCV_ISA_EXT_MAX ); + + len =build_guest_isa_str (NULL ,0 , d->arch.isa); +if ( len <0 ) +return len; + + d->arch.isa_str =xvmalloc_array (char, len +1 ); +if ( !d->arch.isa_str ) +return -ENOMEM ; + +if (build_guest_isa_str (d->arch.isa_str, len +1 , d->arch.isa) != len ) + { +XVFREE (d->arch.isa_str); +return -EINVAL ; + } + +return 0 ; +} + +static void __init init_guest_unsupp (void ) +{ +__set_bit (RISCV_ISA_EXT_f, guest_unsupp); +__set_bit (RISCV_ISA_EXT_d, guest_unsupp); +__set_bit (RISCV_ISA_EXT_q, guest_unsupp); +__set_bit (RISCV_ISA_EXT_v, guest_unsupp); +__set_bit (RISCV_ISA_EXT_h, guest_unsupp); +__set_bit (RISCV_ISA_EXT_sstc, guest_unsupp); +__set_bit (RISCV_ISA_EXT_svade, guest_unsupp); +__set_bit (RISCV_ISA_EXT_svpbmt, guest_unsupp); +} +void __init riscv_fill_hwcap (void ) {unsigned int i;
@@ -527,4 +611,6 @@ void __init riscv_fill_hwcap(void)if ( !all_extns_available )panic ("Look why the extensions above are needed in " "https://xenbits.xenproject.org/docs/unstable/misc/riscv/booting.txt\n" ); + +init_guest_unsupp (); }
xen/arch/riscv/domain.c +3 -0
@@ -308,6 +308,9 @@ int arch_domain_create(struct domain *d,if (is_idle_domain (d) )return 0 ; +if ( (rc =init_guest_isa (d)) !=0 ) + goto fail; +if ( (rc =p2m_init (d, config)) !=0 ) goto fail;
xen/arch/riscv/include/asm/cpufeature.h +4 -0
@@ -17,6 +17,7 @@*/ #define RISCV_ISA_EXT_BASE 26 +enum riscv_isa_ext_id { RISCV_ISA_EXT_a, RISCV_ISA_EXT_c,
@@ -44,7 +45,10 @@ enum riscv_isa_ext_id { RISCV_ISA_EXT_MAX }; +struct domain ; +void riscv_fill_hwcap (void ); +int init_guest_isa (struct domain *d);bool riscv_isa_extension_available (const unsigned long *isa_bitmap,enum riscv_isa_ext_id id);
xen/arch/riscv/include/asm/domain.h +4 -0
@@ -7,6 +7,7 @@#include <xen/xmalloc.h> #include <public/hvm/params.h> +#include <asm/cpufeature.h> #include <asm/guest-layout.h> #include <asm/p2m.h> #include <asm/vtimer.h>
@@ -94,6 +95,9 @@ struct arch_domain {struct p2m_domain p2m;struct paging_domain paging; + +DECLARE_BITMAP (isa,RISCV_ISA_EXT_MAX ); +char *isa_str; };#include <xen/sched.h>
Signature · 1 line
2.54.0
PATCH v4 10/25 xen/riscv: implement make_timer_node()
In reply to Oleksii KurochkoGenerally, in DT for RISC-V there is a document which describes a timer node (riscv,timer.yaml or sifive,clint.yaml), but the Linux timer driver is declared with TIMER_OF_DECLARE(riscv_timer, "riscv", ...). It matches the CPU node (compatible "riscv"), not the timer node itself. It then calls of_find_compatible_node(NULL, NULL, "riscv,timer") only to read the optional riscv,timer-cannot-wake-cpu property.
Since Xen does not care about that property for now, make_timer_node() is implemented to return 0, as no timer node needs to be created for RISC-V guests.
---
Changes in v3-4:
- Nothing changed. Only rebase.
---
Changes in v2:
- Acked-by: Jan Beulich <[email protected]>
- Update the commit message.
---
--- xen/arch/riscv/domain-build.c | 8 ++++++++ 1 file changed, 8 insertions(+)
xen/arch/riscv/domain-build.c +8 -0
@@ -3,6 +3,7 @@#include <xen/fdt-domain-build.h> #include <xen/fdt-kernel.h> #include <xen/init.h> +#include <xen/fdt-kernel.h> #include <xen/libfdt/libfdt.h> #include <xen/sched.h>
@@ -154,3 +155,10 @@ int __init make_cpus_node(const struct domain *d, struct kernel_info *kinfo)return fdt_end_node (fdt); } + +int __init make_timer_node (const struct kernel_info *kinfo) +{ +/* There is no need for timer node for RISC-V. */ + +return 0 ; +}
Signature · 1 line
2.54.0
PATCH v4 1/25 xen/dom0less: turn max_init_domid into a common variable
In reply to Oleksii KurochkoUntil now every architecture carried its own notion of max_init_domid:
Arm defined a real variable (declared in asm/setup.h, defined in setup.c), while ppc, riscv and x86 each provided a "#define max_init_domid (0)" stub in their asm/setup.h. This duplicated the same declaration across all arches and placed a purely dom0less concept in arch setup headers.
Now that the dom0less build code lives in common (xen/common/ device-tree/dom0less-build.c sets max_init_domid, and the console serial-input switcher reads it), there is no reason for the symbol to be per-arch. Provide a single declaration in <xen/dom0less-build.h>, with the !CONFIG_DOM0LESS_BOOT stub kept there as well, so there is one source of truth and the arch headers no longer need to mention it. Update console.c to include <xen/dom0less-build.h> for the declaration instead of relying on asm/setup.h.
Place the definition in xen/common/domid.c rather than in dom0less- build.c. The latter is built as dom0less-build.init.o, i.e. the whole object is relocated into the .init.* sections and freed after boot, whereas max_init_domid must outlive boot because it is read at runtime by the console serial-input switcher. domid.c is always linked (obj-y) and resides in regular (non-init) sections, so it is a correct home for the variable. It is marked __ro_after_init since it is only updated while creating boot-time domains and read-only afterwards, and guarded by CONFIG_DOM0LESS_BOOT as domid.c itself is unconditional.
---
Regarding last paragraph it is also alternative option just make dom0less-build.init.o no-init.
---
Changes in v4:
- New patch.
--- xen/arch/arm/include/asm/setup.h | 2 -- xen/arch/arm/setup.c | 2 -- xen/arch/ppc/include/asm/setup.h | 2 -- xen/arch/riscv/include/asm/setup.h | 2 -- xen/arch/x86/include/asm/setup.h | 2 -- xen/common/domid.c | 5 +++++ xen/drivers/char/console.c | 1 + xen/include/xen/dom0less-build.h | 7 +++++++ 8 files changed, 13 insertions(+), 10 deletions(-)
xen/arch/arm/include/asm/setup.h +0 -2
@@ -25,8 +25,6 @@ struct map_range_datastruct rangeset *irq_ranges; }; -extern domid_t max_init_domid; -void copy_from_paddr (void *dst,paddr_t paddr,unsigned long len);size_t estimate_efi_size (unsigned int mem_nr_banks);
xen/arch/arm/setup.c +0 -2
@@ -62,8 +62,6 @@ struct cpuinfo_arm __read_mostly system_cpuinfo;bool __read_mostly acpi_disabled;#endif -domid_t __read_mostly max_init_domid; -static __used void noreturninit_done (void ) {/* Must be done past setting system_state. */
xen/arch/ppc/include/asm/setup.h +0 -2
@@ -1,6 +1,4 @@#ifndef __ASM_PPC_SETUP_H__#define __ASM_PPC_SETUP_H__ -#define max_init_domid (0) -#endif /* __ASM_PPC_SETUP_H__ */
xen/arch/riscv/include/asm/setup.h +0 -2
@@ -5,8 +5,6 @@#include <xen/types.h> -#define max_init_domid (0) -void setup_mm (void );void copy_from_paddr (void *dst,paddr_t paddr,unsigned long len);
xen/arch/x86/include/asm/setup.h +0 -2
@@ -68,6 +68,4 @@ extern bool opt_dom0_verbose;extern bool opt_dom0_cpuid_faulting;extern bool opt_dom0_msr_relaxed; -#define max_init_domid (0) -#endif
xen/common/domid.c +5 -0
@@ -9,6 +9,11 @@*/ #include <xen/domain.h> +#include <xen/dom0less-build.h> + +#ifdef CONFIG_DOM0LESS_BOOT +domid_t __ro_after_init max_init_domid; +#endif static DEFINE_SPINLOCK (domid_lock); static DECLARE_BITMAP(domid_bitmap, DOMID_FIRST_RESERVED);
xen/drivers/char/console.c +1 -0
@@ -31,6 +31,7 @@#include <xen/warning.h> #include <xen/pv_console.h> #include <asm/setup.h> +#include <xen/dom0less-build.h> #include <xen/sections.h> #include <xen/consoled.h>
xen/include/xen/dom0less-build.h +7 -0
@@ -5,6 +5,8 @@#include <xen/stdbool.h> +#include <public/xen.h> +struct domain ;#ifdef CONFIG_DOM0LESS_BOOT
@@ -13,6 +15,9 @@ struct boot_domain;struct dt_device_node ;struct kernel_info ; +/* Highest domain ID assigned to a boot-time (dom0less) domain. */ +extern domid_t max_init_domid; +/* * List of possible features for dom0less domUs *
@@ -72,6 +77,8 @@ static inline bool is_dom0less_mode(void) }static inline void set_xs_domain (struct domain *d) {} +#define max_init_domid 0 +#endif /* CONFIG_DOM0LESS_BOOT */ #endif /* __ASM_GENERIC_DOM0LESS_BUILD_H__ */
Signature · 1 line
2.54.0
PATCH v4 9/25 xen/riscv: implement make_cpus_node()
In reply to Oleksii KurochkoImplement make_cpus_node() to create cpus node for a guest domain.
This function is going to be use by common dom0less code during construction domain.
---
Changes in v4:
- Update the comment in make_cpus_node() to match code style.
- Add Acked-by: Jan Beulich <[email protected]>.
---
Changes in v3:
- Add blank line above make_cpus_node() function definition.
- Move 'unsigned int cpu' from function-level declarations into the for loop.
- Drop 'uint32_t reg = cpu_to_fdt32(cpu)'; use fdt_property_cell(fdt, "reg", cpu) instead of fdt_property(fdt, "reg", ®, sizeof(reg)) so byte-order adjustment is handled internally.
- Add matching /* interrupt-controller */ start comment; fix end comment to /* end interrupt-controller */.
- Update d->arch.guest_isa_str to ->isa_str in make_cpus_node() function.
---
Changes in v2:
- s/u32/uint32_t for timebase_frequency local variable.
- Drop +1 from BUILD_BUG_ON().
- return fdt_end_node(fdt); instead of res at the end of the function.
---
--- xen/arch/riscv/domain-build.c | 106 ++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+)
xen/arch/riscv/domain-build.c +106 -0
@@ -3,8 +3,10 @@#include <xen/fdt-domain-build.h> #include <xen/fdt-kernel.h> #include <xen/init.h> +#include <xen/libfdt/libfdt.h> #include <xen/sched.h> +#include <asm/cpufeature.h> #include <asm/current.h> #include <asm/guest_access.h>
@@ -48,3 +50,107 @@ int __init construct_domain(struct domain *d, struct kernel_info *kinfo)return 0 ; } + +int __init make_cpus_node (const struct domain *d,struct kernel_info *kinfo) +{ +int res; +const struct dt_device_node *cpus =dt_find_node_by_path ("/cpus" ); +uint32_t timebase_frequency; +bool frequency_valid; +void *fdt = kinfo->fdt; + +dt_dprintk ("Create cpus node\n" ); + +if ( !cpus ) + { +dprintk (XENLOG_ERR ,"Missing /cpus node in the device tree?\n" ); +return -ENOENT ; + } + + frequency_valid =dt_property_read_u32 (cpus,"timebase-frequency" , + &timebase_frequency); + + res =fdt_begin_node (fdt,"cpus" ); +if ( res ) +return res; + + res =fdt_property_cell (fdt,"#address-cells" ,1 ); +if ( res ) +return res; + + res =fdt_property_cell (fdt,"#size-cells" ,0 ); +if ( res ) +return res; + +if ( frequency_valid ) + res =fdt_property_cell (fdt,"timebase-frequency" , timebase_frequency); + +for (unsigned int cpu =0 ; cpu < d->max_vcpus; cpu++ ) + { +char buf[64 ]; + +snprintf (buf,sizeof (buf),"cpu@%u" , cpu); + res =fdt_begin_node (fdt, buf); +if ( res ) +return res; + + res =fdt_property_cell (fdt,"reg" , cpu); +if ( res ) +return res; + + res =fdt_property_string (fdt,"status" ,"okay" ); +if ( res ) +return res; + + res =fdt_property_string (fdt,"compatible" ,"riscv" ); +if ( res ) +return res; + +BUILD_BUG_ON ((sizeof ("riscv," ) + + sizeof_field(struct gstage_mode_desc, name)) >= sizeof(buf)); +snprintf (buf,sizeof (buf),"riscv,%s" , max_gstage_mode->name); + res =fdt_property_string (fdt,"mmu-type" , buf); +if ( res ) +return res; + + res =fdt_property_string (fdt,"riscv,isa" , d->arch.isa_str); +if ( res ) +return res; + + res =fdt_property_string (fdt,"device_type" ,"cpu" ); +if ( res ) +return res; + +/* Start of interrupt-controller */ + res =fdt_begin_node (fdt,"interrupt-controller" ); +if ( res ) +return res; + + res =fdt_property_string (fdt,"compatible" ,"riscv,cpu-intc" ); +if ( res ) +return res; + + res =fdt_property_cell (fdt,"#interrupt-cells" ,1 ); +if ( res ) +return res; + + res =fdt_property (fdt,"interrupt-controller" ,NULL ,0 ); +if ( res ) +return res; + + res =fdt_property_u32 (fdt,"phandle" ,alloc_phandle (kinfo)); +if ( res ) +return res; + +/* End of interrupt-controller */ + res =fdt_end_node (fdt); +if ( res ) +return res; + + res =fdt_end_node (fdt); +if ( res ) +return res; + } + +return fdt_end_node (fdt); +}
Signature · 1 line
2.54.0
PATCH v4 21/25 xen/riscv: implement IRQ routing for device passthrough
In reply to Oleksii Kurochkodom0less device passthrough requires granting guest domains access to device interrupts. Introduce map_device_irqs_to_domain() to enumerate a DT node's interrupt properties, skipping those not owned by the primary interrupt controller (as at the moment I haven't seen usages of it), and map_irq_to_domain() to grant domain access and configure Xen's interrupt descriptor accordingly. Sharing IRQ between domains is rejected.
Both map_irq_to_domain() and map_device_irqs_to_domain() are marked __overlay_init, mirroring Arm: without CONFIG_OVERLAY_DTB this expands to __init, so the functions are init-only and need no XSM check; with CONFIG_OVERLAY_DTB they become runtime-callable, but the only runtime entry point is dt_overlay_domctl(), which performs the XSM checks at the domctl layer. RISC-V does not wire up DT overlay yet, so today these are strictly __init; if/when overlay support is added, the domctl-level XSM gating must be added together with it, as on Arm.
route_irq_to_guest() and release_irq() manage irq_desc ownership for guest-assigned interrupts. Each assignment carries a small irq_guest structure as irqaction::dev_id, recording the owning domain and virtual IRQ number which is 1:1 mapped to physical IRQ number. A per-domain vIRQ allocation bitmap (used_irqs in struct vintc), managed by vintc_reserve_virq(), prevents the same vIRQ being claimed twice.
Host and guest interrupts may differ in some operations (EOI timing in particular, possibly others): a host IRQ is completed once Xen's handler runs, whereas a passthrough IRQ must defer the physical completion until the guest issues its own EOI, otherwise a still-asserted level line would immediately retrigger and storm. This affects only the .end callback; the rest of hw_interrupt_type is shared, hence the separate host and guest hw_interrupt_type instances.
With APLIC+IMSIC, guest interrupts are delivered directly by hardware through the IMSIC, bypassing do_IRQ(). The _IRQ_GUEST branch in do_IRQ() is therefore left as BUG() until a platform without direct IMSIC delivery is encountered.
---
Changes in v4:
- Update the commit message.
- Mark map_irq_to_domain() and map_device_irqs_to_domain() as __overlay_init (mirroring Arm) and include <xen/dt-overlay.h>.
- Fix grammar in the controller-skip comment ("IRQ" -> "IRQs").
- Drop the redundant 'base' local in guest_imsic_make_reg_property(); use GUEST_IMSIC_S_BASE directly.
- Rename vintc::irq_nums -> nr_virqs and update all users.
- Guard domain_vintc_deinit() against a NULL d->arch.vintc.
- Use smp_rmb() instead of smp_mb() in release_irq()'s wait loop and document how it pairs with the spin_unlock() in do_IRQ().
- In release_guest_irq(), reject live unrouting from a non-dying domain (-EBUSY) and clear _IRQ_GUEST under desc->lock so a concurrent release for the same IRQ bails out instead of double-freeing 'info'.
- Tidy spurious whitespace in release_irq()'s spin_lock/unlock calls.
---
Changes in v3:
- Drop extraneous "to" from "Unable to permit to %pd" message.
- Move res/irq/rirq to loop scope; use nirq as declaration initializer.
- Hoist irq_ranges check before the loop (it is loop-invariant).
- Remove spurious forward declarations (struct dt_device_node, struct rangeset) from intc.h; remove all three from setup.h.
- Use __set_bit() instead of set_bit() in intc_route_irq_to_guest() since desc->lock is always held on every write path for desc->status.
- Use XVFREE() instead of xvfree() in domain_vintc_deinit().
- Rename allocated_irqs -> used_irqs in struct vintc.
- Fix dangling desc->action in release_irq()'s !IRQ_HAS_MULTIPLE_ACTION path by nulling *action_ptr after saving the action pointer.
- Use true (not 1) for free_on_release in route_irq_to_guest().
- Use %pd for domain printing in route_irq_to_guest() error paths.
- Introduce release_guest_irq() to pair with route_irq_to_guest() and plug the irq_guest info leak; call it from domain_vintc_deinit() for each vIRQ recorded in used_irqs.
---
Changes in v2:
- Rework IRQ mapping in more common (similar approach to Arm).
---
--- xen/arch/riscv/Makefile | 1 + xen/arch/riscv/aplic.c | 4 + xen/arch/riscv/device.c | 95 ++++++++++++ xen/arch/riscv/include/asm/intc.h | 9 ++ xen/arch/riscv/include/asm/irq.h | 5 + xen/arch/riscv/intc.c | 44 ++++++ xen/arch/riscv/irq.c | 230 ++++++++++++++++++++++++++++++ xen/arch/riscv/vaplic.c | 2 + 8 files changed, 390 insertions(+) create mode 100644 xen/arch/riscv/device.c
xen/arch/riscv/Makefile +1 -0
@@ -1,6 +1,7 @@ obj-y += aia.o obj-y += aplic.o obj-y += cpufeature.o +obj-y += device.o obj-y += domain.o obj-y += domain-build.init.o obj-$(CONFIG_DOM0LESS_BOOT) += dom0less-build.init.o
xen/arch/riscv/aplic.c +4 -0
@@ -304,9 +304,13 @@ static const hw_irq_controller aplic_xen_irq_type = { .set_affinity = aplic_set_irq_affinity, }; +/* At the moment there is no difference between guest and Xen ops */ +#define aplic_guest_irq_type aplic_xen_irq_type +static const struct intc_hw_operations aplic_ops = { .info = &aplic_info, .host_irq_type = &aplic_xen_irq_type, + .guest_irq_type = &aplic_guest_irq_type, .handle_interrupt = aplic_handle_interrupt, .set_irq_type = aplic_set_irq_type, };
xen/arch/riscv/device.c new file +95 -0
95 lines not on this page · raw message
xen/arch/riscv/include/asm/intc.h +9 -0
@@ -13,6 +13,7 @@ enum intc_variant { };struct cpu_user_regs ; +struct domain ;struct irq_desc ;struct kernel_info ;struct vcpu ;
@@ -32,6 +33,9 @@ struct intc_hw_operations {/* hw_irq_controller to enable/disable/eoi host irq */ const struct hw_interrupt_type *host_irq_type; +/* hw_irq_controller to enable/disable/eoi guest irq */ +const struct hw_interrupt_type *guest_irq_type; +/* Set IRQ type */ void (*set_irq_type)(struct irq_desc *desc,unsigned int type);/* Set IRQ priority */
@@ -61,6 +65,8 @@ struct vintc_ops { };struct vintc { +unsigned int nr_virqs; +unsigned long *used_irqs;const struct vintc_init_ops *init_ops;const struct vintc_ops *ops; };
@@ -72,10 +78,13 @@ void register_intc_ops(const struct intc_hw_init_ops *init_ops);void intc_init (void );void intc_route_irq_to_xen (struct irq_desc *desc,unsigned int priority); +int intc_route_irq_to_guest (struct irq_desc *desc,unsigned int priority);void intc_handle_external_irqs (struct cpu_user_regs *regs);int domain_vintc_init (struct domain *d);void domain_vintc_deinit (struct domain *d); +bool vintc_reserve_virq (const struct domain *d,unsigned int virq); +#endif /* ASM__RISCV__INTERRUPT_CONTOLLER_H */
xen/arch/riscv/include/asm/irq.h +5 -0
@@ -49,6 +49,11 @@ void init_IRQ(void);void do_IRQ (struct cpu_user_regs *regs,unsigned int irq); +int route_irq_to_guest (struct domain *d,unsigned int virq, +unsigned int irq,const char *devname); + +int release_guest_irq (struct domain *d,unsigned int virq); +#endif /* ASM__RISCV__IRQ_H */ /*
xen/arch/riscv/intc.c +44 -0
73 lines not on this page · raw message
xen/arch/riscv/irq.c +230 -0
250 lines not on this page · raw message
xen/arch/riscv/vaplic.c +2 -0
@@ -123,6 +123,8 @@ int domain_vaplic_init(struct domain *d) vaplic->regs.domaincfg =APLIC_DOMAINCFG_IE |APLIC_DOMAINCFG_DM |APLIC_DOMAINCFG_RO ; + d->arch.vintc->nr_virqs =VAPLIC_NUM_SOURCES ; +return 0 ; }
Signature · 1 line
2.54.0
PATCH v4 20/25 xen/riscv: create APLIC DT node for guest domains
In reply to Oleksii KurochkoGuests require a Device Tree description of the interrupt controller topology. Add support for creating an APLIC node when building the guest DT.
Provide stub for imsic_make_dt_node() it will be introduced properly in follow-up patch.
The value chosen for GUEST_APLIC_S_BASE is based on QEMU one.
DT-building functions are marked __init because domain creation happens at boot time, before the init sections are freed. In a typical deployment libxl creates the interrupt controller node in userspace and hands the complete FDT to Xen, so these functions are only called during early domain construction.
---
Changes in v4:
- Drop spurious <xen/fdt-kernel.h> and <xen/libfdt/libfdt.h> includes from aplic.c (mistakenly added, they belong to vaplic.c).
- Reduce vaplic_name[] from 128 to 32 bytes in vaplic_make_domu_dt_node().
- Use __initconstrel (with const) for init_ops instead of __initdata.
- s/__ULL/_UL for defintion of GUEST_APLIC_S_BASE.
---
Changes in v3:
- Fix rebase conflicts becuase of this patch is reordered after IMSIC DT node creation is intoduced.
- Update the commit message.
- Move initialization of domaincfg with APLIC_DOMAINCFG_RO80 from this patch to earlier.
- Change paddr_t aplic_size to unsigned int in vaplic_make_domu_dt_node() and replace the UB (after it started to be uint) aplic_size >> 32 with an explicit 0 in the DT reg property.
- Add BUILD_BUG_ON() to be sure that aplic size isn't bigger then UINT32_MAX.
---
Changes in v2:
- Avoid as max as possible of host properties inheritance. Only number of APLIC's irqs are checked what leads to an introduction of get_aplic_irqs_num().
- Move this patch earlier what leads to an introduction of vimsic_make_domu_dt_node() stub.
- s/vimsic_make_domu_dt_node/imsic_make_domu_dt_node.
- Refactor vimsic_make_domu_dt_node() to avoid re-usage of APLIC host properties.
- Drop next_phandle as it is now in common code.
- Drop const for kinfo argument of vimsic_make_domu_dt_node() is is going to be updated inside vimsic_make_domu_dt_node().
- Use introduced before vintc->num_irqs.
---
--- xen/arch/riscv/include/asm/aplic.h | 8 +++ xen/arch/riscv/include/asm/guest-layout.h | 6 ++ xen/arch/riscv/include/asm/imsic.h | 3 + xen/arch/riscv/vaplic.c | 76 +++++++++++++++++++++++ 4 files changed, 93 insertions(+)
xen/arch/riscv/include/asm/aplic.h +8 -0
@@ -30,6 +30,14 @@#define APLIC_TARGET_HART_IDX_SHIFT 18 +#define APLIC_IDC_SIZE 32 + +#define APLIC_MIN_SIZE 0x4000 +#define APLIC_SIZE_ALIGN (x) ROUNDUP(x, APLIC_MIN_SIZE) + +#define APLIC_SIZE (nr_cpus) (APLIC_MIN_SIZE + \ + APLIC_SIZE_ALIGN(APLIC_IDC_SIZE * (nr_cpus))) +struct aplic_regs {uint32_t domaincfg;/* 0x0000 */ uint32_t sourcecfg[1023 ];/* 0x0004 */
xen/arch/riscv/include/asm/guest-layout.h +6 -0
@@ -3,6 +3,12 @@#include <public/xen.h> +/* +* Base address of the guest's supervisor-mode APLIC. The value is the address +* typically used for APLIC by QEMU. +*/ +#define GUEST_APLIC_S_BASE _UL(0xd000000) +/* * Base address of the guest's supervisor-mode IMSIC. The value is the address * typically used for IMSIC by QEMU.
xen/arch/riscv/include/asm/imsic.h +3 -0
@@ -78,6 +78,7 @@ struct vimsic_state { };struct dt_device_node ; +struct kernel_info ;struct vcpu ;int imsic_init (const struct dt_device_node *node);
@@ -93,4 +94,6 @@ int vcpu_imsic_init(struct vcpu *v);void vcpu_imsic_deinit (struct vcpu *v);unsigned int vcpu_guest_file_id (const struct vcpu *v); +int vimsic_make_domu_dt_node (struct kernel_info *kinfo,unsigned int *phandle); +#endif /* ASM_RISCV_IMSIC_H */
xen/arch/riscv/vaplic.c +76 -0
100 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v4 15/25 xen/riscv: introduce per-vCPU IMSIC state
In reply to Oleksii KurochkoEach vCPU interacting with the IMSIC requires state to track the associated guest interrupt file and its backing context.
Introduce a per-vCPU structure to hold IMSIC-related state, including the guest interrupt file identifier and the CPU providing the backing VS-file. Access to the guest file identifier is protected by a lock.
Initialize this structure during vCPU setup and store it in arch_vcpu. The initial state marks the VS-file as software-backed until it becomes associated with a physical CPU.
Add helper to retrieve the guest interrupt file identifier:
- vcpu_guest_file_id() is going to be used during update of APLIC's target register with the pair of information <guest_file_id, cpu_id> (to have MSI delivery mode work properly) when guest is trying to access vAPLIC's target register.
It will be used in the follow up patches.
---
Changes in v4:
- s/w vs h/w IMSIC VS-file commentary for struct vimsic_state:
- fix the vsfile_pcpu h/w condition:
"vsfile_pcpu >= 0" -> "vsfile_pcpu < NR_CPUS"
(the old wording conflicted with the s/w "== NR_CPUS" case). - reorder both comment blocks to the "s/w ... / h/w ..." form for readability.
- drop IMPOSSIBLE_GUEST_FILE_ID: the s/w IMSIC VS-file is always available
and corresponds to guest_file_id == 0, which xvzalloc() already provides,
so the explicit initializer in vcpu_imsic_init() and the macro itself
are unneeded.
---
Changes in v3:
- Drop const from imsic_set_guest_file_id() and vcpu_imsic_deinit() as
it only works due to vimsic_state being a pointer member.
- Use XVFREE() in vcpu_imsic_deinit() to make it idempotent.
- Fix SW-file typo in struct vimsic_state comments; should be VS-file.
- Drop imsic_set_guest_file_id() here, it will be added later when it
will be nessary to initialise guest file id as the correspondendt code
in this patch series was reworked and there is no need to use this
function in arch_vcpu_create().
- Introduce IMPOSSIBLE_GUEST_FILE_ID and init with it ->guest_file_id.
---
Changes in v2:
- Rename imsic_state to vimsic_state.
- Use 'unsigned int' for vsfile_pcpu.
- Drop initialzation of ->guest_file_id as it will be by default zero.
- Add the comment about ->guest_file_id field.
- Drop __init for vcpu_imsic_init() as it could be used during post-boot
vCPU creation.
- Update the commit message.
- Drop locks around ->guest_file_id() in vcpu_guest_file_id() and imsic_set_guest_file_id().
---
--- xen/arch/riscv/imsic.c | 35 +++++++++++++++++++++++++++++ xen/arch/riscv/include/asm/domain.h | 2 ++ xen/arch/riscv/include/asm/imsic.h | 22 ++++++++++++++++++ 3 files changed, 59 insertions(+)
xen/arch/riscv/imsic.c +35 -0
@@ -16,6 +16,7 @@#include <xen/errno.h> #include <xen/init.h> #include <xen/macros.h> +#include <xen/sched.h> #include <xen/smp.h> #include <xen/spinlock.h> #include <xen/xvmalloc.h>
@@ -56,6 +57,11 @@ do { \csr_clear (CSR_SIREG , v); \ }while (0 ) +unsigned int vcpu_guest_file_id(const struct vcpu *v) +{ +return ACCESS_ONCE (v->arch.vimsic_state->guest_file_id); +} +void __init imsic_ids_local_delivery (bool enable) {if ( enable )
@@ -312,6 +318,35 @@ static int imsic_parse_node(const struct dt_device_node *node,return 0 ; } +int vcpu_imsic_init (struct vcpu *v) +{ +struct vimsic_state *imsic_state; + +/* Allocate IMSIC context */ + imsic_state = xvzalloc(struct vimsic_state); +if ( !imsic_state ) +return -ENOMEM ; + + v->arch.vimsic_state = imsic_state; + +/* Setup IMSIC context */ +rwlock_init (&imsic_state->vsfile_lock); + +/* +* xvzalloc() already cleared the context, so guest_file_id == 0, i.e. the +* always-available s/w IMSIC VS-file. Only vsfile_pcpu needs an explicit +* initializer as its s/w VS-file value is NR_CPUS rather than 0. +*/ + imsic_state->vsfile_pcpu =NR_CPUS ; + +return 0 ; +} + +void vcpu_imsic_deinit (struct vcpu *v) +{ +XVFREE (v->arch.vimsic_state); +} +/* * Initialize the imsic_cfg structure based on the IMSIC DT node. *
xen/arch/riscv/include/asm/domain.h +2 -0
@@ -54,6 +54,8 @@ struct arch_vcpu {struct vtimer vtimer; +struct vimsic_state *vimsic_state; +register_t hcounteren;register_t hedeleg;register_t hideleg;
xen/arch/riscv/include/asm/imsic.h +22 -0
@@ -11,6 +11,7 @@#ifndef ASM_RISCV_IMSIC_H #define ASM_RISCV_IMSIC_H +#include <xen/rwlock.h> #include <xen/spinlock.h> #include <xen/stdbool.h> #include <xen/types.h>
@@ -61,7 +62,24 @@ struct imsic_config {spinlock_t lock; }; +struct vimsic_state { +/* IMSIC VS-file */ +rwlock_t vsfile_lock; +/* +* s/w IMSIC VS-file -> guest_file_id == 0 +* h/w IMSIC VS-file -> guest_file_id > 0 +*/ +unsigned int guest_file_id; +/* +* s/w IMSIC VS-file -> vsfile_pcpu == NR_CPUS +* h/w IMSIC VS-file -> vsfile_pcpu < NR_CPUS +*/ +unsigned int vsfile_pcpu; +}; +struct dt_device_node ; +struct vcpu ; +int imsic_init (const struct dt_device_node *node);const struct imsic_config *imsic_get_config (void );
@@ -71,4 +89,8 @@ void imsic_irq_disable(unsigned int hwirq);void imsic_ids_local_delivery (bool enable); +int vcpu_imsic_init (struct vcpu *v); +void vcpu_imsic_deinit (struct vcpu *v); +unsigned int vcpu_guest_file_id (const struct vcpu *v); +#endif /* ASM_RISCV_IMSIC_H */
Signature · 1 line
2.54.0
PATCH v4 22/25 xen/riscv: implement init_intc_phandle()
In reply to Oleksii KurochkoImplement init_intc_phandle() to read phandle of interrupt controller node and save it in kernel->phandle_intc for the future usage during creation of guest interrupt controller node.
---
Changes in v4:
- Nothing changed. Only rebase.
---
--- xen/arch/riscv/dom0less-build.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
xen/arch/riscv/dom0less-build.c +17 -0
@@ -4,9 +4,26 @@#include <xen/device_tree.h> #include <xen/fdt-kernel.h> #include <xen/init.h> +#include <xen/libfdt/libfdt.h> #include <asm/p2m.h> +int __init init_intc_phandle (struct kernel_info *kinfo,const char *name, +const int node_next,const void *pfdt) +{ +if (dt_node_cmp (name,"intc" ) ==0 ) + { +uint32_t phandle_intc =fdt_get_phandle (pfdt, node_next); + +if ( phandle_intc !=0 ) + kinfo->phandle_intc = phandle_intc; + +return 0 ; + } + +return 1 ; +} +int __init make_arch_nodes (struct kernel_info *kinfo) {/* No RISC-V specific nodes need to be made, at the moment. */
Signature · 1 line
2.54.0
PATCH v4 23/25 xen/riscv: initialize RCU, scheduler, and system domains in start_xen()
In reply to Oleksii KurochkoWire up the missing early-boot initialization steps in start_xen().
The scheduler must be initialized prior to do_initcalls() because cpupool_create_pool() is called during initcalls; without it, BUG_ON(IS_ERR(pool)) is triggered inside cpupool_create_pool().
---
Changes in v4:
- Nothing changed. Only rebase.
---
Changes in v3:
- Add Acked-by: Jan Beulich <[email protected]>.
---
Changes in v2:
- New patch. Several patches were folded into one.
---
--- xen/arch/riscv/setup.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
xen/arch/riscv/setup.c +12 -0
@@ -6,9 +6,12 @@#include <xen/compile.h> #include <xen/console.h> #include <xen/device_tree.h> +#include <xen/domain.h> #include <xen/init.h> #include <xen/irq.h> #include <xen/mm.h> +#include <xen/rcupdate.h> +#include <xen/sched.h> #include <xen/serial.h> #include <xen/shutdown.h> #include <xen/smp.h>
@@ -156,12 +159,21 @@ void __init noreturn start_xen(unsigned long bootcpu_id,timer_init (); +rcu_init (); + +setup_system_domains (); +local_irq_enable ();console_init_postirq ();guest_mm_init (); +scheduler_init (); +set_current (idle_vcpu[0 ]); + +do_initcalls (); +printk ("All set up\n" );machine_halt ();
Signature · 1 line
2.54.0
PATCH v4 24/25 xen/riscv: provide init_vuart()
In reply to Oleksii KurochkoFor debug purpose is enough to have only print messages from guest what is now implemented in vsbi_legacy_ecall_handler().
For full guesst console support it will better to have something similar to [1], thereby there is nothing specific should be done, at least, for now and init_vuart() is provided to make dom0less code buildable.
---
Changes in v3-v4:
- Nothing changed. Only rebase.
---
Changes in v2:
- Add Acked-by: Jan Beulich <[email protected]>.
---
--- xen/arch/riscv/dom0less-build.c | 8 ++++++++ 1 file changed, 8 insertions(+)
xen/arch/riscv/dom0less-build.c +8 -0
@@ -8,6 +8,14 @@#include <asm/p2m.h> +int __init init_vuart (struct domain *d,struct kernel_info *kinfo, +const struct dt_device_node *node) +{ +/* Nothing to do at the moment */ + +return 0 ; +} +int __init init_intc_phandle (struct kernel_info *kinfo,const char *name,const int node_next,const void *pfdt) {
Signature · 1 line
2.54.0
PATCH v4 25/25 xen/riscv: add initial dom0less infrastructure support
In reply to Oleksii KurochkoEnable dom0less support for RISC-V by selecting HAS_DOM0LESS and providing the minimal architecture hooks required by the common dom0less infrastructure.
Add stub implementations for architecture-specific helpers used when building domains from the device tree. These allow the generic dom0less code to build and let a basic DomU be constructed on RISC-V. construct_hwdom() and make_hypervisor_node() are still stubs returning an error: Dom0/hwdom construction isn't supported yet, and the hypervisor node generation (needed by domains with DOM0LESS_ENHANCED_NO_XS set) is not implemented. Both are marked with a TODO and are not reached by the currently supported configurations.
Provide missing helpers and definitions required by the domain construction code, including domain bitness helpers and the p2m_set_allocation() prototype.
Additionally define the guest magic memory region (GUEST_MAGIC_BASE / GUEST_MAGIC_SIZE) in asm/guest-layout.h. The base is arbitrary; the only constraint is that the region must not overlap guest RAM or the emulated device regions. It is placed in the unused gap below GUEST_RAM0_BASE (0x80000000); the constraints are documented next to the #define-s.
---
Changes in v4:
- Reword the description: the stubs do not let dom0less fully "run" since construct_hwdom() and make_hypervisor_node() return an error; spell out these limitations instead.
- Add a TODO comment to construct_hwdom() explaining that Dom0/hwdom construction isn't supported yet.
- Add a TODO comment to make_hypervisor_node() explaining that returning an error breaks building of domains with DOM0LESS_ENHANCED_NO_XS set, and why that is harmless for now.
- Document the constraints on GUEST_MAGIC_BASE/GUEST_MAGIC_SIZE next to the #define-s and drop the QEMU-based justification (QEMU is not involved); the base is simply an arbitrary non-overlapping address.
Changes in v3:
- Add /* Nothing specific to do for now */ comment to arch_handle_passthrough_prop().
- Use _ULL() instead of xen_mk_ullong() for GUEST_MAGIC_BASE and GUEST_MAGIC_SIZE (xen_mk_ullong() is intended for public headers only).
- Fix GUEST_MAGIC_BASE from 0x39000000 to 0x79000000 to avoid the QEMU RISC-V virt machine PCIE_ECAM range.
- Drop CONFIG_STATIC_MEMORY=n from the CI randconfig; now redundant since STATIC_MEMORY depends on HAS_STATIC_MEMORY which RISC-V does not select.
Changes in v2:
- Move declaration of p2m_set_allocation() to p2m-common.h.
- Add __initdata for max_init_domid and drop initalizer for it.
- Add CONFIG_STATIC_MEMORY=n to CI's randconfig to avoid compilation error because of guest_physmap_add_pages() isn't provided.
--- xen/arch/riscv/Kconfig | 2 ++ xen/arch/riscv/dom0less-build.c | 7 ++++++ xen/arch/riscv/domain-build.c | 28 +++++++++++++++++++++++ xen/arch/riscv/include/asm/guest-layout.h | 12 ++++++++++ 4 files changed, 49 insertions(+)
xen/arch/riscv/Kconfig +2 -0
@@ -6,6 +6,8 @@ config RISCV select GENERIC_BUG_FRAME select GENERIC_UART_INIT select HAS_DEVICE_TREE_DISCOVERY + select HAS_DOM0LESS + select HAS_DOMAIN_TYPE select HAS_EX_TABLE select HAS_PMAP select HAS_UBSAN
xen/arch/riscv/dom0less-build.c +7 -0
@@ -102,3 +102,10 @@ int __init arch_parse_dom0less_node(struct dt_device_node *node,return 0 ; } + +int __init arch_handle_passthrough_prop (struct kernel_info *kinfo, +struct dt_device_node *node) +{ +/* Nothing specific to do for now */ +return 0 ; +}
xen/arch/riscv/domain-build.c +28 -0
@@ -156,9 +156,37 @@ int __init make_cpus_node(const struct domain *d, struct kernel_info *kinfo)return fdt_end_node (fdt); } +int __init construct_hwdom (struct kernel_info *kinfo, +const struct dt_device_node *node) +{ +/* +* TODO: Dom0/hwdom construction isn't supported on RISC-V yet, so this +* is a stub returning an error. It must be implemented before a hardware +* domain can be built from the device tree. +*/ + +return -EOPNOTSUPP ; +} +int __init make_timer_node (const struct kernel_info *kinfo) {/* There is no need for timer node for RISC-V. */ return 0 ; } + +int __init make_hypervisor_node (struct domain *d, +const struct kernel_info *kinfo, +int addrcells,int sizecells) +{ +/* +* TODO: Generating the hypervisor node isn't implemented yet. Returning +* an error here breaks building of any domain (DomU included) whose +* dom0less_feature has DOM0LESS_ENHANCED_NO_XS set. This is harmless for +* now because Dom0/hwdom construction isn't supported on RISC-V yet +* either, and no RISC-V DomU sets that flag, so this path is never taken. +* It must be implemented before DOM0LESS_ENHANCED_NO_XS is used. +*/ + +return -EOPNOTSUPP ; +}
xen/arch/riscv/include/asm/guest-layout.h +12 -0
@@ -32,4 +32,16 @@#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE, GUEST_RAM1_BASE }#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE, GUEST_RAM1_SIZE } +/* +* The guest magic region holds Xen-reserved pages mapped into the guest's +* physical address space (shared info, grant table, etc.). The only real +* constraint is that the GUEST_MAGIC_SIZE-byte region must not overlap +* guest RAM (the GUEST_RAMx banks) or the emulated device regions defined +* above; the exact base is otherwise arbitrary. Here it is placed in the +* unused gap below GUEST_RAM0_BASE (0x80000000), but a hole after a RAM +* bank would work equally well. +*/ +#define GUEST_MAGIC_BASE _UL(0x79000000) +#define GUEST_MAGIC_SIZE _UL(0x01000000) +#endif /* ASM_RISCV_GUEST_LAYOUT_H */
Signature · 1 line
2.54.0
Re: [PATCH v4 04/25] xen/Kconfig: introduce HAS_STATIC_MEMORY
In reply to Oleksii KurochkoQuoted 8 lines · Oleksii Kurochko
Introduce
HAS_STATIC_MEMORYso thatSTATIC_MEMORYcan be enabled or disabled on a per-architecture basis. ARM selects the new flag; RISC-V does not, soCONFIG_STATIC_MEMORYis unavailable on RISC-V and randconfig builds no longer require an explicit STATIC_MEMORY=n override to avoid a compilation error.Suggested-by Jan Beulich <[email protected]>Signed-off-by Oleksii Kurochko <[email protected]>
Re: [PATCH v4 11/25] xen/riscv: implement make_arch_nodes()
In reply to Oleksii KurochkoQuoted 9 lines · Oleksii Kurochko
No RISC-V-specific nodes need to be created at the moment, so
make_arch_nodes()is implemented to simply return 0.It is placed in
dom0less-build.casmake_arch_nodes()is only used in the dom0less code path. In the future, it will be extended to create an emulated UART node.Signed-off-by Oleksii Kurochko <[email protected]>Add Acked-by: Jan Beulich <[email protected]>
Please. This again requires the committer to remember to do (however minor) editing.
Jan
Re: [PATCH v4 02/25] xen: arm: move declaration of map_device_irqs_to_domain() to common header
In reply to Oleksii KurochkoQuoted 7 lines · Oleksii Kurochko
As
map_device_irqs_to_domain()is used unconditionally by common part of dom0less code, move the prototype to a common header.
fdt-domain-build.his chosen asmap_device_irqs_to_domain()could be also called indirectly in Arm's DOM0-related code and DT overlay feature.Signed-off-by Oleksii Kurochko <[email protected]>
~Michal
Re: [PATCH v4 03/25] xen: arm: update p2m_set_allocation() prototype
In reply to Oleksii KurochkoQuoted 12 lines · Oleksii Kurochko
p2m_set_allocation()uses a bool *preempted out-argument that overloads two meanings. When non-NULL, the value written back (true) duplicates information already carried by the-ERESTARTreturn code — pure redundancy, which the caller-side ASSERT(preempted == (rc ==-ERESTART)) only documents. Separately, a NULL pointer is an implicit calling convention meaning "preemption is not permitted in this context".Replace the pointer with a plain bool
can_preemptthat explicitly controls whether the preemption check runs, making the NULL-to-suppress convention type-safe and self-documenting, and rely on the-ERESTARTreturn code alone to report that preemption occurred.
Quoted 5 lines
Since
p2m_set_allocation()is called by the common dom0less build code, move its declaration from the ARM-specificasm/p2m.htoxen/p2m-common.h.Reported-by Jan Beulich <[email protected]>Signed-off-by Oleksii Kurochko <[email protected]>
~Michal
Re: [PATCH v4 04/25] xen/Kconfig: introduce HAS_STATIC_MEMORY
In reply to Oleksii KurochkoQuoted 8 lines · Oleksii Kurochko
Introduce
HAS_STATIC_MEMORYso thatSTATIC_MEMORYcan be enabled or disabled on a per-architecture basis. ARM selects the new flag; RISC-V does not, soCONFIG_STATIC_MEMORYis unavailable on RISC-V and randconfig builds no longer require an explicit STATIC_MEMORY=n override to avoid a compilation error.Suggested-by Jan Beulich <[email protected]>Signed-off-by Oleksii Kurochko <[email protected]>
~Michal
Re: [PATCH v4 14/25] xen/riscv: introduce aia_init() and aia_usable()
In reply to Oleksii KurochkoQuoted 6 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/aia.h new file +0
-0
xen/arch/riscv/include/asm/aia.h line 10
Quoted 10 lines
xen/arch/riscv/include/asm/aia.h new file +10
-0@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef ASM__RISCV__AIA_H +#define ASM__RISCV__AIA_H + +bool aia_usable (void ); + +void aia_init (void ); + +#endif /* ASM__RISCV__ACPI_H */
I just noticed that it should be s/ASM__RISCV__ACPI_H/ASM__RISCV__AIA_H.
I would be happy if it could be done during commit. I am also okay to fix that during the next version of this patch series.
~ Oleksii
Re: [PATCH v4 01/25] xen/dom0less: turn max_init_domid into a common variable
In reply to Oleksii KurochkoQuoted 26 lines · Oleksii Kurochko
Until now every architecture carried its own notion of
max_init_domid:
Arm defined a real variable (declared inasm/setup.h, defined insetup.c), while ppc, riscv and x86 each provided a "#definemax_init_domid(0)" stub in theirasm/setup.h. This duplicated the same declaration across all arches and placed a purely dom0less concept in arch setup headers.Now that the dom0less build code lives in common (xen/common/
device-tree/dom0less-build.csetsmax_init_domid, and the console serial-input switcher reads it), there is no reason for the symbol to be per-arch. Provide a single declaration in <xen/dom0less-build.h>, with the !CONFIG_DOM0LESS_BOOT stub kept there as well, so there is one source of truth and the arch headers no longer need to mention it. Updateconsole.cto include <xen/dom0less-build.h> for the declaration instead of relying onasm/setup.h.Place the definition in
xen/common/domid.crather than in dom0less-build.c. The latter is built as dom0less-build.init.o, i.e. the whole object is relocated into the .init.* sections and freed after boot, whereasmax_init_domidmust outlive boot because it is read at runtime by the console serial-input switcher.domid.cis always linked (obj-y) and resides in regular (non-init) sections, so it is a correct home for the variable. It is marked__ro_after_initsince it is only updated while creating boot-time domains and read-only afterwards, and guarded byCONFIG_DOM0LESS_BOOTasdomid.citself is unconditional.
Quoted 1 line
Signed-off-by Oleksii Kurochko <[email protected]>
Quoted 3 lines
---
Regarding last paragraph it is also alternative option just make dom0less-build.init.o no-init.
That would be a pretty bad move imo.
Jan
Re: [PATCH v4 08/25] xen/riscv: introduce guest riscv,isa string
In reply to Oleksii KurochkoQuoted 4 lines · Oleksii Kurochko
Changes in v4:
- Add an explicit overflow guard inbuild_guest_isa_str(): return-ENOSPCwhen buf is non-NULL and total >= size, to avoid the size - total underflow being passed tosnprintf().
How does ...
Quoted 12 lines
xen/arch/riscv/cpufeature.c +8
-0@@ -480,6 +489,81 @@ bool riscv_isa_extension_available(const unsigned long *isa_bitmap,return test_bit (id, isa_bitmap); } +static int build_guest_isa_str (char *buf,size_t size, +const unsigned long *isa_bitmap) +{ +int total; + +#if defined(CONFIG_RISCV_32 ) + total =snprintf (buf, size,"rv32" ); +#elif defined(CONFIG_RISCV_64 )
xen/arch/riscv/cpufeature.c bool riscv_isa_extension_available(const unsigned long *isa_bitmap, · line 509
Quoted 10 lines
xen/arch/riscv/cpufeature.c +10
-0+ total =snprintf (buf, size,"rv64" ); +#else +# error "Unsupported RISC-V bitness" +#endif + +if ( total <0 ) +return total; + +if ( buf && ((size_t )total >= size) ) +return -ENOSPC ;
... this help an underflow ...
xen/arch/riscv/cpufeature.c bool riscv_isa_extension_available(const unsigned long *isa_bitmap, · line 520
Quoted 10 lines
xen/arch/riscv/cpufeature.c +10
-0+for (unsigned int i =0 ; i <ARRAY_SIZE (riscv_isa_ext); i++ ) + { +const struct riscv_isa_ext_data *ext = &riscv_isa_ext[i]; +int ret; + +if ( !riscv_isa_extension_available (isa_bitmap, ext->id) ) +continue ; + + ret = snprintf(buf ? buf + total : NULL, + buf ? size - total : 0, "%s%s",
... on any but the first iteration here?
xen/arch/riscv/cpufeature.c bool riscv_isa_extension_available(const unsigned long *isa_bitmap, · line 565
Quoted 11 lines
xen/arch/riscv/cpufeature.c +11
-0+static void __init init_guest_unsupp (void ) +{ +__set_bit (RISCV_ISA_EXT_f, guest_unsupp); +__set_bit (RISCV_ISA_EXT_d, guest_unsupp); +__set_bit (RISCV_ISA_EXT_q, guest_unsupp); +__set_bit (RISCV_ISA_EXT_v, guest_unsupp); +__set_bit (RISCV_ISA_EXT_h, guest_unsupp); +__set_bit (RISCV_ISA_EXT_sstc, guest_unsupp); +__set_bit (RISCV_ISA_EXT_svade, guest_unsupp); +__set_bit (RISCV_ISA_EXT_svpbmt, guest_unsupp); +}
Wouldn't riscv_isa_ext[] better get a prominent reminder that additions there may need mirroring here (unless guest support is implemented at the same time)? (As before, yet better would of course be to make sure this is consistent right from build time, i.e. without the need to have this separate function. Or minimally have the info right in that array, so that while adding one needs to think how to set that separate field.)
xen/arch/riscv/include/asm/cpufeature.h line 23
Quoted 10 lines
xen/arch/riscv/include/asm/cpufeature.h +1
-0@@ -17,6 +17,7 @@*/ #define RISCV_ISA_EXT_BASE 26 +enum riscv_isa_ext_id { RISCV_ISA_EXT_a, RISCV_ISA_EXT_c,
???
xen/arch/riscv/include/asm/cpufeature.h struct arch_domain { · line 101
Quoted 8 lines
xen/arch/riscv/include/asm/cpufeature.h +3
-0@@ -94,6 +95,9 @@ struct arch_domain {struct p2m_domain p2m;struct paging_domain paging; + +DECLARE_BITMAP (isa,RISCV_ISA_EXT_MAX ); +char *isa_str; };
Why is it again that both the bitmap and its string representation need storing? In the end they provide two different sources of truth, as there's no guarantee that they'll remain in sync.
Jan
Re: [PATCH v4 15/25] xen/riscv: introduce per-vCPU IMSIC state
In reply to Oleksii KurochkoQuoted 4 lines · Oleksii Kurochko
xen/arch/riscv/imsic.c +0
-0@@ -312,6 +318,35 @@ static int imsic_parse_node(const struct dt_device_node *node,return 0 ; }
xen/arch/riscv/imsic.c static int imsic_parse_node(const struct dt_device_node *node, · line 330
Quoted 10 lines
xen/arch/riscv/imsic.c +10
-0+int vcpu_imsic_init (struct vcpu *v) +{ +struct vimsic_state *imsic_state; + +/* Allocate IMSIC context */ + imsic_state = xvzalloc(struct vimsic_state); +if ( !imsic_state ) +return -ENOMEM ; + + v->arch.vimsic_state = imsic_state;
May I suggest that you make the pointer globally visible only after ...
xen/arch/riscv/imsic.c static int imsic_parse_node(const struct dt_device_node *node, · line 340
Quoted 9 lines
xen/arch/riscv/imsic.c +9
-0+/* Setup IMSIC context */ +rwlock_init (&imsic_state->vsfile_lock); + +/* +* xvzalloc() already cleared the context, so guest_file_id == 0, i.e. the +* always-available s/w IMSIC VS-file. Only vsfile_pcpu needs an explicit +* initializer as its s/w VS-file value is NR_CPUS rather than 0. +*/ + imsic_state->vsfile_pcpu =NR_CPUS ;
... having set up fields? Then:
Jan
Re: [PATCH v4 16/25] xen/riscv: introduce minimal virtual APLIC (vAPLIC) infrastructure
In reply to Oleksii KurochkoQuoted 4 lines · Oleksii Kurochko
Changes in v4:
- Change subject of the commit.
- s/APLIC_DOMAINCFG_RO80/APLIC_DOMAINCFG_RO + added a comment above definition.
- Drop unnessary blank lines.
Did you? What about ...
xen/arch/riscv/include/asm/aplic.h line 22
Quoted 11 lines
xen/arch/riscv/include/asm/aplic.h +3
-0@@ -15,6 +15,9 @@#include <asm/imsic.h> + +/* domaincfg bits 31:24 are read-only 0x80 */ +#define APLIC_DOMAINCFG_RO (0x80U << 24)#define APLIC_DOMAINCFG_IE BIT(8, U)#define APLIC_DOMAINCFG_DM BIT(2, U)
... the one you pointlessly add here?
Quoted 16 lines
xen/arch/riscv/include/asm/intc.h +3
-0@@ -15,6 +15,7 @@ enum intc_version {struct cpu_user_regs ;struct irq_desc ;struct kernel_info ; +struct vcpu ;struct intc_info {enum intc_version hw_version;@@ -51,8 +52,17 @@ struct vintc_init_ops {int (*make_domu_dt_node)(struct kernel_info *kinfo); }; +struct vintc_ops { +/* Initialize some vINTC-related stuff for a vCPU */
xen/arch/riscv/include/asm/intc.h struct vintc_init_ops { · line 66
Quoted 10 lines
xen/arch/riscv/include/asm/intc.h +7
-0+int (*vcpu_init)(struct vcpu *v); + +/* Deinitialize some vINTC-related stuff for a vCPU */ +void (*vcpu_deinit)(struct vcpu *v); +}; +struct vintc {const struct vintc_init_ops *init_ops; +const struct vintc_ops *ops; };
I may have asked before: Why two distinct structures, next to each other (and without any comment guiding what is to go where)? Plus you only set
...
Quoted 44 lines
xen/arch/riscv/vaplic.c new file +41
-0@@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: MIT */ +/* +* xen/arch/riscv/vaplic.c +* +* Virtual RISC-V Advanced Platform-Level Interrupt Controller support +* +* Copyright (c) Microchip. +* Copyright (c) Vates +*/ + +#include <xen/errno.h> +#include <xen/sched.h> +#include <xen/xvmalloc.h> + +#include <asm/aia.h> +#include <asm/imsic.h> +#include <asm/intc.h> +#include <asm/vaplic.h> + +#include "aplic-priv.h" + +static int cf_check vaplic_init(struct vcpu *v) +{ +return vcpu_imsic_init (v); +} + +static void cf_check vaplic_deinit(struct vcpu *v) +{ +return vcpu_imsic_deinit (v); +} + +static const struct vintc_ops vintc_ops = { + .vcpu_init = vaplic_init, + .vcpu_deinit = vaplic_deinit, +}; + +int domain_vaplic_init (struct domain *d) +{ + struct vaplic *vaplic = xvzalloc(struct vaplic); + +if ( !vaplic )
xen/arch/riscv/vaplic.c line 51
Quoted 10 lines
xen/arch/riscv/vaplic.c new file +10
-0+return -ENOMEM ; + + d->arch.vintc = &vaplic->vintc; + d->arch.vintc->ops = &vintc_ops; + + vaplic->regs.domaincfg =APLIC_DOMAINCFG_IE |APLIC_DOMAINCFG_DM | +APLIC_DOMAINCFG_RO ; + +return 0 ; +}
... ->ops here, leaving ->init_ops at NULL (prone to a deref that'll crash).
Jan
Re: [PATCH v4 17/25] xen/riscv: rename enum intc_version to intc_variant
In reply to Oleksii KurochkoQuoted 5 lines · Oleksii Kurochko
Rename the enum to
intc_variantand the structure member fromhw_versiontohw_variantto better reflect that these values select between different controller variants, not versions of the same one.Signed-off-by Oleksii Kurochko <[email protected]>
(perhaps also Requested.by: or Suggested-by:)
It looks as if this might be independent of earlier patches, and could go in soon after branching?
Jan
Re: [PATCH v4 18/25] xen/riscv: introduce (de)initialization helpers for vINTC
In reply to Oleksii KurochkoQuoted 8 lines · Oleksii Kurochko
Add common helpers
domain_vintc_init()anddomain_vintc_deinit()to allocate and deallocate a virtual interrupt controller (vINTC) structure and initialize basic virtual interrupt controller registers.
domain_vintc_deinit()isn't called at the moment asarch_domain_destroy()is implemented as stub at the moment.Signed-off-by Oleksii Kurochko <[email protected]>
with one more suggestion:
Quoted 8 lines
xen/arch/riscv/intc.c +4
-0@@ -83,3 +84,37 @@ int __init make_intc_domU_node(struct kernel_info *kinfo)return vintc->init_ops->make_domu_dt_node (kinfo); } + +int domain_vintc_init (struct domain *d) +{ +int ret = -EOPNOTSUPP ;
xen/arch/riscv/intc.c int __init make_intc_domU_node(struct kernel_info *kinfo) · line 100
Quoted 10 lines
xen/arch/riscv/intc.c +10
-0+const enum intc_variant variant = intc_hw_ops->info->hw_variant; + +switch ( variant ) + { +case INTC_APLIC : + ret =domain_vaplic_init (d); +break ; + +default : +printk ("vintc (variant:%d) isn't implemented\n" , variant);
printk_once() maybe?
Jan
Re: [PATCH v4 19/25] xen/riscv: generate IMSIC DT node for guest domains
In reply to Oleksii KurochkoQuoted 18 lines · Oleksii Kurochko
xen/arch/riscv/imsic.c +4
-0@@ -13,8 +13,12 @@#include <xen/const.h> #include <xen/cpumask.h> #include <xen/device_tree.h> +#include <xen/domain.h> #include <xen/errno.h> +#include <xen/fdt-domain-build.h> +#include <xen/fdt-kernel.h> #include <xen/init.h> +#include <xen/libfdt/libfdt.h> #include <xen/macros.h> #include <xen/sched.h> #include <xen/smp.h> @@ -34,6 +38,16 @@ static struct imsic_config imsic_cfg = { .lock = SPIN_LOCK_UNLOCKED, };
xen/arch/riscv/imsic.c static struct imsic_config imsic_cfg = { · line 49
Quoted 10 lines
xen/arch/riscv/imsic.c +9
-0+/* +* Number of MSIs available to a guest. Determined by the host interrupt +* controller, so it is identical for every domain -- hence a single global +* rather than a per-domain value. +*/ +static unsigned int __read_mostly guest_num_msis; + +#define GUEST_IMSIC_COMPATIBLE "riscv,imsics" +#define GUEST_IMSIC_NUM_MSIS 255
Considering its use this isn't named correctly - it's not the number of MSIs guests get to use.
xen/arch/riscv/imsic.c static int imsic_parse_node(const struct dt_device_node *node, · line 305
Quoted 8 lines
xen/arch/riscv/imsic.c +4
-0@@ -285,6 +299,11 @@ static int imsic_parse_node(const struct dt_device_node *node,return -ENOENT ; } +if (dt_property_read_u32 (node,"riscv,num-guest-ids" , &tmp) ) + guest_num_msis = tmp; +else + guest_num_msis =IMSIC_MAX_ID ;
Why is guest_num_msis __read_mostly, not __ro_after_init? Merely because the function here (wrongly) isn't __init?
Quoted 25 lines
xen/arch/riscv/imsic.c +21
-0@@ -522,3 +541,121 @@ int __init imsic_init(const struct dt_device_node *node)return rc; } + +static int __init guest_imsic_make_reg_property (struct domain *d,void *fdt) +{ +paddr_t size =IMSIC_MMIO_PAGE_SZ * d->max_vcpus; +__be32 regs[4 ] = { +cpu_to_be32 (GUEST_IMSIC_S_BASE >>32 ), +cpu_to_be32 (GUEST_IMSIC_S_BASE ), +cpu_to_be32 (size >>32 ), +cpu_to_be32 (size), + }; + +return fdt_property (fdt,"reg" , regs,sizeof (regs)); +} + +static int __init guest_imsic_set_interrupt_extended_prop (struct domain *d, +void *fdt) +{ +unsigned int cpu, pos =0 ; +__be32 *irq_ext; +int res; +
xen/arch/riscv/imsic.c int __init imsic_init(const struct dt_device_node *node) · line 574
Quoted 10 lines
xen/arch/riscv/imsic.c +10
-0+ irq_ext =xvzalloc_array (__be32, d->max_vcpus *2 ); +if ( !irq_ext ) +return -ENOMEM ; + +for ( cpu =0 ; cpu < d->max_vcpus; cpu++ ) + { +char buf[64 ]; +uint32_t phandle; + +snprintf (buf,sizeof (buf),"/cpus/cpu@%u/interrupt-controller" , cpu);
May I, btw, suggest you get into the habit of using ARRAY_SIZE() in favor of sizeof() with snprintf()? That's because sizeof() isn't correct to use if wide strings (and hence swnprintf()) come into play.
xen/arch/riscv/imsic.c int __init imsic_init(const struct dt_device_node *node) · line 603
Quoted 8 lines
xen/arch/riscv/imsic.c +8
-0+int __init vimsic_make_domu_dt_node (struct kernel_info *kinfo, +unsigned int *phandle) +{ +int res; +void *fdt = kinfo->fdt; +char vimsic_name[32 ]; +unsigned int vimsic_phandle; +unsigned int num_msis =min (GUEST_IMSIC_NUM_MSIS +0U , guest_num_msis);
As guest_num_msis (supposedly) doesn't change anymore after it was set, why would this need calculating again for each call here? Can't you apply the upper bound right in imsic_parse_node()?
xen/arch/riscv/include/asm/guest-layout.h line 10
Quoted 11 lines
xen/arch/riscv/include/asm/guest-layout.h +5
-0@@ -3,6 +3,12 @@#include <public/xen.h> +/* +* Base address of the guest's supervisor-mode IMSIC. The value is the address +* typically used for IMSIC by QEMU. +*/ +#define GUEST_IMSIC_S_BASE _UL(0x28000000)
As you mention it explicitly: Is there also a user-mode IMSIC?
Jan
Re: [PATCH v4 20/25] xen/riscv: create APLIC DT node for guest domains
In reply to Oleksii KurochkoQuoted 11 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/imsic.h +1
-0@@ -78,6 +78,7 @@ struct vimsic_state { };struct dt_device_node ; +struct kernel_info ;struct vcpu ;int imsic_init (const struct dt_device_node *node);
xen/arch/riscv/include/asm/imsic.h int vcpu_imsic_init(struct vcpu *v); · line 97
Quoted 4 lines
xen/arch/riscv/include/asm/imsic.h +1
-0@@ -93,4 +94,6 @@ int vcpu_imsic_init(struct vcpu *v);void vcpu_imsic_deinit (struct vcpu *v);unsigned int vcpu_guest_file_id (const struct vcpu *v); +int vimsic_make_domu_dt_node (struct kernel_info *kinfo,unsigned int *phandle);
Doesn't this belong in the earlier patch?
Quoted 12 lines
xen/arch/riscv/vaplic.c +2
-0@@ -9,6 +9,8 @@*/ #include <xen/errno.h> +#include <xen/fdt-kernel.h> +#include <xen/libfdt/libfdt.h> #include <xen/sched.h> #include <xen/xvmalloc.h>
xen/arch/riscv/vaplic.c line 25
Quoted 5 lines
xen/arch/riscv/vaplic.c +2
-0@@ -19,6 +21,11 @@#include "aplic-priv.h" +#define VAPLIC_COMPATIBLE "riscv,aplic" +#define VAPLIC_NUM_SOURCES 96
So for the IMSIC the host value is relevant, but for the APLIC the count is an arbitrary(?) compile time constant? Why?
xen/arch/riscv/vaplic.c static void cf_check vaplic_deinit(struct vcpu *v) · line 42
Quoted 8 lines
xen/arch/riscv/vaplic.c +4
-0@@ -29,6 +36,74 @@ static void cf_check vaplic_deinit(struct vcpu *v)return vcpu_imsic_deinit (v); } +static int __init cf_check vaplic_make_domu_dt_node(struct kernel_info *kinfo) +{ +struct domain *d = kinfo->bd.d; +int res =0 ;
I'm pretty sure I did point out this (or a very similar) pointless initializer before.
Jan
Re: [PATCH v4 21/25] xen/riscv: implement IRQ routing for device passthrough
In reply to Oleksii KurochkoQuoted 32 lines · Oleksii Kurochko
dom0less device passthrough requires granting guest domains access to device interrupts. Introduce
map_device_irqs_to_domain()to enumerate a DT node's interrupt properties, skipping those not owned by the primary interrupt controller (as at the moment I haven't seen usages of it), andmap_irq_to_domain()to grant domain access and configure Xen's interrupt descriptor accordingly. Sharing IRQ between domains is rejected.Both
map_irq_to_domain()andmap_device_irqs_to_domain()are marked__overlay_init, mirroring Arm: withoutCONFIG_OVERLAY_DTBthis expands to__init, so the functions are init-only and need no XSM check; withCONFIG_OVERLAY_DTBthey become runtime-callable, but the only runtime entry point isdt_overlay_domctl(), which performs the XSM checks at the domctl layer. RISC-V does not wire up DT overlay yet, so today these are strictly__init; if/when overlay support is added, the domctl-level XSM gating must be added together with it, as on Arm.
route_irq_to_guest()andrelease_irq()manageirq_descownership for guest-assigned interrupts. Each assignment carries a smallirq_gueststructure asirqaction::dev_id, recording the owning domain and virtual IRQ number which is 1:1 mapped to physical IRQ number. A per-domain vIRQ allocation bitmap (used_irqsin struct vintc), managed byvintc_reserve_virq(), prevents the same vIRQ being claimed twice.Host and guest interrupts may differ in some operations (EOI timing in particular, possibly others): a host IRQ is completed once Xen's handler runs, whereas a passthrough IRQ must defer the physical completion until the guest issues its own EOI, otherwise a still-asserted level line would immediately retrigger and storm. This affects only the .end callback; the rest of
hw_interrupt_typeis shared, hence the separate host and guesthw_interrupt_typeinstances.
Quoted 4 lines
With APLIC+IMSIC, guest interrupts are delivered directly by hardware through the IMSIC, bypassing
do_IRQ(). The_IRQ_GUESTbranch indo_IRQ()is therefore left asBUG()until a platform without direct IMSIC delivery is encountered.
And this is secure, i.e. one guest (by mishandling things, e.g. simply never claiming / servicing an interrupt) cannot affect another guest?
Quoted 22 lines
xen/arch/riscv/device.c new file +22
-0+int __overlay_init map_device_irqs_to_domain(struct domain *d, +struct dt_device_node *dev, +bool need_mapping, +struct rangeset *irq_ranges) +{ +unsigned int i, nirq =dt_number_of_irq (dev); + +if ( irq_ranges ) +return -EOPNOTSUPP ; + +/* Give permission and map IRQs */ +for ( i =0 ; i < nirq; i++ ) + { +int res, irq; +struct dt_raw_irq rirq; + + res =dt_device_get_raw_irq (dev, i, &rirq); +if ( res ) + { +printk (XENLOG_ERR "Unable to retrieve irq %u for %s\n" , + i,dt_node_full_name (dev)); +return res;
xen/arch/riscv/device.c line 77
Quoted 10 lines
xen/arch/riscv/device.c new file +10
-0+ } + +/* +* Don't map IRQs that have no physical meaning +* ie: IRQs whose controller is not APLIC/IMSIC/PLIC. +*/ +if ( rirq.controller != dt_interrupt_controller ) + { + dt_dprintk("irq %u not connected to primary controller." + "Connected to %s\n", i,
Nit: By splitting a format string like this, you pretty effectively hide that there's a blank missing after the full stop.
Further after an already wrapped function argument there shouldn't follow another one, to maintain visual clarity.
xen/arch/riscv/intc.c int domain_vintc_init(struct domain *d) · line 125
Quoted 8 lines
xen/arch/riscv/intc.c +4
-0@@ -101,12 +119,28 @@ int domain_vintc_init(struct domain *d)break ; } +if ( !ret ) + { + d->arch.vintc->used_irqs = + xvzalloc_array(unsigned long, BITS_TO_LONGS(d->arch.vintc->nr_virqs));
Nit: Overlong line.
Quoted 4 lines
xen/arch/riscv/intc.c +4
-0+if ( !d->arch.vintc->used_irqs ) + ret = -ENOMEM ; + } +
xen/arch/riscv/intc.c int domain_vintc_init(struct domain *d) · line 139
Quoted 10 lines
xen/arch/riscv/intc.c +4
-0return ret; }void domain_vintc_deinit (struct domain *d) {const enum intc_variant variant = intc_hw_ops->info->hw_variant; +unsigned int virq; + +if ( !d->arch.vintc ) +return ;
Seeing this and ...
xen/arch/riscv/intc.c void domain_vintc_deinit(struct domain *d) · line 155
Quoted 12 lines
xen/arch/riscv/intc.c +5
-0+for ( virq =0 ; virq < d->arch.vintc->nr_virqs; virq++ ) +if (test_bit (virq, d->arch.vintc->used_irqs) ) +release_guest_irq (d, virq);switch ( variant ) {@@ -117,4 +151,14 @@ void domain_vintc_deinit(struct domain *d)default :break ; } + +XVFREE (d->arch.vintc->used_irqs);
... this, ...
Review void domain_vintc_deinit(struct domain *d) · line 156
Quoted 1 line
(quoted diff) +1
-0+}
... where is d->arch.vintc being freed? That would logically look to belong into this function.
Quoted 25 lines
xen/arch/riscv/irq.c +9
-0@@ -12,11 +12,20 @@#include <xen/errno.h> #include <xen/init.h> #include <xen/irq.h> +#include <xen/sched.h> #include <xen/spinlock.h> +#include <xen/xvmalloc.h> #include <asm/hardirq.h> #include <asm/intc.h> +/* Describe an IRQ assigned to a guest */ +struct irq_guest +{ +struct domain *d; +unsigned int virq; +}; +static irq_desc_t irq_desc[NR_IRQS ];static bool irq_validate_new_type (unsigned int curr,unsigned int new)@@ -192,6 +201,15 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq)if ( desc->handler->ack )
xen/arch/riscv/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq) · line 211
Quoted 10 lines
xen/arch/riscv/irq.c +8
-0desc->handler->ack (desc); +if ( desc->status &IRQ_GUEST ) +/* +* As at the moment APLIC + IMSIC is used for guest interrupts will +* be directly passed to guest. But if/when IMSIC won't be available +* all interrupts will go through Xenand here an irq injection +* will be necessary to do. +*/ +panic ("unimplemented" );
The first comment sentence doesn't parse for me. In the 2nd there's a blank missing between "Xen" and "and".
Quoted 8 lines
xen/arch/riscv/irq.c +4
-0@@ -221,3 +239,215 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq)spin_unlock (&desc->lock);irq_exit (); } + +static inline struct irq_guest *irq_get_guest_info (struct irq_desc *desc) +{ +ASSERT (spin_is_locked (&desc->lock));
xen/arch/riscv/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq) · line 255
Quoted 10 lines
xen/arch/riscv/irq.c +10
-0+ASSERT (test_bit (_IRQ_GUEST, &desc->status)); +ASSERT (desc->action !=NULL ); + +return desc->action->dev_id; +} + +static inline struct domain *irq_get_domain (struct irq_desc *desc) +{ +return irq_get_guest_info (desc)->d; +}
Does this really need a separate helper? (You effectively open-code it anyway in release_guest_irq().)
For both functions: "inline" generally wants limiting to header files.
Quoted 17 lines
xen/arch/riscv/irq.c +17
-0+int release_guest_irq (struct domain *d,unsigned int virq) +{ +struct irq_desc *desc =irq_to_desc (virq); +struct irq_guest *info; +unsigned long flags; + +spin_lock_irqsave (&desc->lock, flags); + +if ( !test_bit (_IRQ_GUEST, &desc->status) ) + goto unlock_err; + + info =irq_get_guest_info (desc); +if ( d != info->d ) + goto unlock_err; + +/* +* Live IRQ unrouting from a running domain is not supported: the tear-down
xen/arch/riscv/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq) · line 341
Quoted 10 lines
xen/arch/riscv/irq.c +10
-0+* drops desc->lock across release_irq()/xvfree() and relies on no +* concurrent route_irq_to_guest() being issued for this domain. Only permit +* it for a dying domain, where assignment is frozen and no new routes can +* appear. +*/ +if ( !d->is_dying ) + { +spin_unlock_irqrestore (&desc->lock, flags); +return -EBUSY ; + }
Yet route_irq_to_guest() looks to happily act on dying guests. IOW assignment doesn't look to be frozen, despite the comment saying so.
xen/arch/riscv/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq) · line 348
Quoted 6 lines
xen/arch/riscv/irq.c +6
-0+/* +* Clear _IRQ_GUEST while still holding the lock so that a concurrent +* release_guest_irq() for the same IRQ observes it and bails out, rather +* than capturing the same 'info' and double-freeing it below. +*/ +clear_bit (_IRQ_GUEST, &desc->status);
You use __set_bit() / __clear_bit() elsewhere - why not here?
xen/arch/riscv/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq) · line 353
Quoted 4 lines
xen/arch/riscv/irq.c +4
-0+spin_unlock_irqrestore (&desc->lock, flags); + +release_irq (desc->irq, info); +xvfree (info);
If, in release_irq(), action isn't freed, it's ->dev_id field will now have a dangling pointer. (I think I did point this out before.)
Jan
Re: [PATCH v4 25/25] xen/riscv: add initial dom0less infrastructure support
In reply to Oleksii KurochkoQuoted 17 lines · Oleksii Kurochko
Enable dom0less support for RISC-V by selecting
HAS_DOM0LESSand providing the minimal architecture hooks required by the common dom0less infrastructure.Add stub implementations for architecture-specific helpers used when building domains from the device tree. These allow the generic dom0less code to build and let a basic DomU be constructed on RISC-V.
construct_hwdom()andmake_hypervisor_node()are still stubs returning an error: Dom0/hwdom construction isn't supported yet, and the hypervisor node generation (needed by domains withDOM0LESS_ENHANCED_NO_XSset) is not implemented. Both are marked with a TODO and are not reached by the currently supported configurations.Provide missing helpers and definitions required by the domain construction code, including domain bitness helpers and the
p2m_set_allocation()prototype.
Quoted 8 lines
Additionally define the guest magic memory region (
GUEST_MAGIC_BASE/GUEST_MAGIC_SIZE) inasm/guest-layout.h. The base is arbitrary; the only constraint is that the region must not overlap guest RAM or the emulated device regions. It is placed in the unused gap belowGUEST_RAM0_BASE(0x80000000); the constraints are documented next to the #define-s.Signed-off-by Oleksii Kurochko <[email protected]>
Nevertheless, ...
Quoted 7 lines
xen/arch/riscv/include/asm/guest-layout.h +1
-0@@ -32,4 +32,16 @@#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE, GUEST_RAM1_BASE }#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE, GUEST_RAM1_SIZE } +/*
xen/arch/riscv/include/asm/guest-layout.h line 45
Quoted 10 lines
xen/arch/riscv/include/asm/guest-layout.h +10
-0+* The guest magic region holds Xen-reserved pages mapped into the guest's +* physical address space (shared info, grant table, etc.). The only real +* constraint is that the GUEST_MAGIC_SIZE-byte region must not overlap +* guest RAM (the GUEST_RAMx banks) or the emulated device regions defined +* above; the exact base is otherwise arbitrary. Here it is placed in the +* unused gap below GUEST_RAM0_BASE (0x80000000), but a hole after a RAM +* bank would work equally well. +*/ +#define GUEST_MAGIC_BASE _UL(0x79000000) +#define GUEST_MAGIC_SIZE _UL(0x01000000)
... while 16Mb may seem a lot, it feels pretty little for 64-bit guests. Even in just Sv39 mode they have ample VA space to map a bigger region. (As iirc indicated before, a static upper bound looks questionable to me anyway.)
Jan
Re: [PATCH v4 08/25] xen/riscv: introduce guest riscv,isa string
In reply to Jan BeulichQuoted 33 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
Changes in v4:
- Add an explicit overflow guard inbuild_guest_isa_str(): return-ENOSPCwhen buf is non-NULL and total >= size, to avoid the size - total underflow being passed tosnprintf().How does ...
Quoted 12 lines
xen/arch/riscv/cpufeature.c +8
-0@@ -480,6 +489,81 @@ bool riscv_isa_extension_available(const unsigned long *isa_bitmap,return test_bit (id, isa_bitmap); } +static int build_guest_isa_str (char *buf,size_t size, +const unsigned long *isa_bitmap) +{ +int total; + +#if defined(CONFIG_RISCV_32 ) + total =snprintf (buf, size,"rv32" ); +#elif defined(CONFIG_RISCV_64 )xen/arch/riscv/cpufeature.c bool riscv_isa_extension_available(const unsigned long *isa_bitmap, · line 509
Quoted 10 lines
xen/arch/riscv/cpufeature.c +10
-0+ total =snprintf (buf, size,"rv64" ); +#else +# error "Unsupported RISC-V bitness" +#endif + +if ( total <0 ) +return total; + +if ( buf && ((size_t )total >= size) ) +return -ENOSPC ;... this help an underflow ...
Quoted 12 lines
xen/arch/riscv/cpufeature.c bool riscv_isa_extension_available(const unsigned long *isa_bitmap, · line 520
Quoted 10 lines
xen/arch/riscv/cpufeature.c +10
-0+for (unsigned int i =0 ; i <ARRAY_SIZE (riscv_isa_ext); i++ ) + { +const struct riscv_isa_ext_data *ext = &riscv_isa_ext[i]; +int ret; + +if ( !riscv_isa_extension_available (isa_bitmap, ext->id) ) +continue ; + + ret = snprintf(buf ? buf + total : NULL, + buf ? size - total : 0, "%s%s",... on any but the first iteration here?
Agree, overflow still could happen. I will update that part to:
char *p = buf;size_t left = size;
...
ret = snprintf(p, left, ...);
if ( ret < 0 )
return ret;
total += ret;
if ( buf )
{
if ( (size_t)ret >= left )
return -ENOSPC;
p += ret;
left -= ret;
}Then size - total never compute, so unsigned underflow simply cannot occur.
Quoted 11 lines
Quoted 11 lines
xen/arch/riscv/cpufeature.c +10
-0+static void __init init_guest_unsupp (void ) +{ +__set_bit (RISCV_ISA_EXT_f, guest_unsupp); +__set_bit (RISCV_ISA_EXT_d, guest_unsupp); +__set_bit (RISCV_ISA_EXT_q, guest_unsupp); +__set_bit (RISCV_ISA_EXT_v, guest_unsupp); +__set_bit (RISCV_ISA_EXT_h, guest_unsupp); +__set_bit (RISCV_ISA_EXT_sstc, guest_unsupp); +__set_bit (RISCV_ISA_EXT_svade, guest_unsupp); +__set_bit (RISCV_ISA_EXT_svpbmt, guest_unsupp);
Quoted 8 lines
Review bool riscv_isa_extension_available(const unsigned long *isa_bitmap, · line 530
Quoted 1 line
(quoted diff) +1
-0+}Wouldn't riscv_isa_ext[] better get a prominent reminder that additions there may need mirroring here (unless guest support is implemented at the same time)? (As before, yet better would of course be to make sure this is consistent right from build time, i.e. without the need to have this separate function. Or minimally have the info right in that array, so that while adding one needs to think how to set that separate field.)
How about making the field mandatory at the call site instead, so it can't be silently forgotten:
#define RISCV_ISA_EXT_DATA(ext_name, guest_supp) \
{ \
.id = RISCV_ISA_EXT_ ## ext_name, \
.name = #ext_name, \
.guest_supported = guest_supp, \}
Every entry in riscv_isa_ext[] would then need an explicit true/false argument, e.g. RISCV_ISA_EXT_DATA(f, false). That forces whoever adds a new extension to make the decision right there, rather than relying on a separate init_guest_unsupp() to be remembered. We'd drop guest_unsupp and init_guest_unsupp(), and build d->arch.isa directly from the array in init_guest_isa().
Maybe it would be better to introduce separate structure which will embed .guest_supported + struct riscv_isa_ext_data.
Quoted 7 lines
Quoted 7 lines
xen/arch/riscv/include/asm/cpufeature.h +0
-0@@ -17,6 +17,7 @@*/ #define RISCV_ISA_EXT_BASE 26
Quoted 6 lines
xen/arch/riscv/include/asm/cpufeature.h line 23
Quoted 4 lines
xen/arch/riscv/include/asm/cpufeature.h +1
-0+enum riscv_isa_ext_id { RISCV_ISA_EXT_a, RISCV_ISA_EXT_c,???
I will drop unnecessary empty line.
Quoted 4 lines
Quoted 4 lines
xen/arch/riscv/include/asm/cpufeature.h +0
-0@@ -94,6 +95,9 @@ struct arch_domain {struct p2m_domain p2m;
Quoted 9 lines
xen/arch/riscv/include/asm/cpufeature.h struct arch_domain { · line 101
Quoted 5 lines
xen/arch/riscv/include/asm/cpufeature.h +3
-0struct paging_domain paging; + +DECLARE_BITMAP (isa,RISCV_ISA_EXT_MAX ); +char *isa_str; };Why is it again that both the bitmap and its string representation need storing? In the end they provide two different sources of truth, as there's no guarantee that they'll remain in sync.
isa_str is needed to guest device tree to tell which extensions are supported.
isa bitmap is needed to check in runtime if extension is available and it will be faster then search in a string. It could be a cases when code is generic enough and some things shouldn't be touched when some extension is available or not.
Considering the way how they are built they should be always in sync.
Thanks.
~ Oleksii
Re: [PATCH v4 08/25] xen/riscv: introduce guest riscv,isa string
Quoted 31 lines · Oleksii Kurochko
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Oleksii Kurochko
xen/arch/riscv/cpufeature.c +10
-0+static void __init init_guest_unsupp (void ) +{ +__set_bit (RISCV_ISA_EXT_f, guest_unsupp); +__set_bit (RISCV_ISA_EXT_d, guest_unsupp); +__set_bit (RISCV_ISA_EXT_q, guest_unsupp); +__set_bit (RISCV_ISA_EXT_v, guest_unsupp); +__set_bit (RISCV_ISA_EXT_h, guest_unsupp); +__set_bit (RISCV_ISA_EXT_sstc, guest_unsupp); +__set_bit (RISCV_ISA_EXT_svade, guest_unsupp); +__set_bit (RISCV_ISA_EXT_svpbmt, guest_unsupp);Quoted 8 lines
Quoted 1 line
+}
Wouldn't riscv_isa_ext[] better get a prominent reminder that additions there may need mirroring here (unless guest support is implemented at the same time)? (As before, yet better would of course be to make sure this is consistent right from build time, i.e. without the need to have this separate function. Or minimally have the info right in that array, so that while adding one needs to think how to set that separate field.)
How about making the field mandatory at the call site instead, so it can't be silently forgotten:
#define
RISCV_ISA_EXT_DATA(ext_name, guest_supp)\{ \ .id = RISCV_ISA_EXT_ ## ext_name, \ .name = #ext_name, \ .guest_supported = guest_supp, \ }
Quoted 6 lines
Every entry in riscv_isa_ext[] would then need an explicit true/false argument, e.g.
RISCV_ISA_EXT_DATA(f, false). That forces whoever adds a new extension to make the decision right there, rather than relying on a separateinit_guest_unsupp()to be remembered. We'd dropguest_unsuppandinit_guest_unsupp(), and buildd->arch.isadirectly from the array ininit_guest_isa().
This is what I meant with "Or minimally ...".
Quoted 13 lines
Quoted 12 lines
xen/arch/riscv/include/asm/domain.h struct arch_domain { · line 101
Quoted 8 lines
xen/arch/riscv/include/asm/domain.h +3
-0@@ -94,6 +95,9 @@ struct arch_domain {struct p2m_domain p2m;struct paging_domain paging; + +DECLARE_BITMAP (isa,RISCV_ISA_EXT_MAX ); +char *isa_str; };Why is it again that both the bitmap and its string representation need storing? In the end they provide two different sources of truth, as there's no guarantee that they'll remain in sync.
Quoted 2 lines
isa_stris needed to guest device tree to tell which extensions are supported.
Sure, but does that need storing over the lifetime of the domain? Can't that string be allocated, built, used, and then freed while DT is being built? Would that string be used at all for toolstack-created domains?
Jan
Re: [PATCH v4 08/25] xen/riscv: introduce guest riscv,isa string
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 11 lines
xen/arch/riscv/include/asm/domain.h struct arch_domain { · line 101
Quoted 8 lines
xen/arch/riscv/include/asm/domain.h +3
-0@@ -94,6 +95,9 @@ struct arch_domain {struct p2m_domain p2m;struct paging_domain paging; + +DECLARE_BITMAP (isa,RISCV_ISA_EXT_MAX ); +char *isa_str; };Why is it again that both the bitmap and its string representation need storing? In the end they provide two different sources of truth, as there's no guarantee that they'll remain in sync.
Quoted 3 lines
Quoted 2 lines
isa_stris needed to guest device tree to tell which extensions are supported.Sure, but does that need storing over the lifetime of the domain?
Considering my answer to you last question here ... then there is no such need.
Can't
Quoted 2 lines
that string be allocated, built, used, and then freed while DT is being built?
Agree, it could be done in this way.
Would that string be used at all for toolstack-created domains?
... No, it won't. This string will be created by toolstack. So it could really be dropped from arch_domain.
Thasnk.
~ Oleksii
Re: [PATCH v4 16/25] xen/riscv: introduce minimal virtual APLIC (vAPLIC) infrastructure
In reply to Jan BeulichQuoted 14 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
Changes in v4:
- Change subject of the commit.
- s/APLIC_DOMAINCFG_RO80/APLIC_DOMAINCFG_RO + added a comment above definition.
- Drop unnessary blank lines.Did you? What about ...
Quoted 6 lines
xen/arch/riscv/include/asm/aplic.h +0
-0@@ -15,6 +15,9 @@#include <asm/imsic.h>
Quoted 8 lines
xen/arch/riscv/include/asm/aplic.h line 22
Quoted 5 lines
xen/arch/riscv/include/asm/aplic.h +3
-0+ +/* domaincfg bits 31:24 are read-only 0x80 */ +#define APLIC_DOMAINCFG_RO (0x80U << 24)#define APLIC_DOMAINCFG_IE BIT(8, U)#define APLIC_DOMAINCFG_DM BIT(2, U)... the one you pointlessly add here?
I think it is newly introduced... Anyway, I will drop it.
Quoted 14 lines
Quoted 14 lines
xen/arch/riscv/include/asm/intc.h +1
-0@@ -15,6 +15,7 @@ enum intc_version {struct cpu_user_regs ;struct irq_desc ;struct kernel_info ; +struct vcpu ;struct intc_info {enum intc_version hw_version;@@ -51,8 +52,17 @@ struct vintc_init_ops {int (*make_domu_dt_node)(struct kernel_info *kinfo); };
Quoted 15 lines
xen/arch/riscv/include/asm/intc.h struct vintc_init_ops { · line 66
Quoted 12 lines
xen/arch/riscv/include/asm/intc.h +9
-0+struct vintc_ops { +/* Initialize some vINTC-related stuff for a vCPU */ +int (*vcpu_init)(struct vcpu *v); + +/* Deinitialize some vINTC-related stuff for a vCPU */ +void (*vcpu_deinit)(struct vcpu *v); +}; +struct vintc {const struct vintc_init_ops *init_ops; +const struct vintc_ops *ops; };I may have asked before: Why two distinct structures, next to each other (and without any comment guiding what is to go where)?
I will add the comments:
/* Used during domain build only; dropped afterwards. */
const struct vintc_init_ops *init_ops;
/* Runtime callbacks used for the lifetime of the guest. */
const struct vintc_ops *ops;Quoted 51 lines
Plus you only set
...Quoted 48 lines
xen/arch/riscv/vaplic.c new file +45
-0@@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: MIT */ +/* +* xen/arch/riscv/vaplic.c +* +* Virtual RISC-V Advanced Platform-Level Interrupt Controller support +* +* Copyright (c) Microchip. +* Copyright (c) Vates +*/ + +#include <xen/errno.h> +#include <xen/sched.h> +#include <xen/xvmalloc.h> + +#include <asm/aia.h> +#include <asm/imsic.h> +#include <asm/intc.h> +#include <asm/vaplic.h> + +#include "aplic-priv.h" + +static int cf_check vaplic_init(struct vcpu *v) +{ +return vcpu_imsic_init (v); +} + +static void cf_check vaplic_deinit(struct vcpu *v) +{ +return vcpu_imsic_deinit (v); +} + +static const struct vintc_ops vintc_ops = { + .vcpu_init = vaplic_init, + .vcpu_deinit = vaplic_deinit, +}; + +int domain_vaplic_init (struct domain *d) +{ + struct vaplic *vaplic = xvzalloc(struct vaplic); + +if ( !vaplic ) +return -ENOMEM ; + + d->arch.vintc = &vaplic->vintc; + d->arch.vintc->ops = &vintc_ops;
Quoted 8 lines
xen/arch/riscv/vaplic.c line 51
Quoted 6 lines
xen/arch/riscv/vaplic.c new file +6
-0+ + vaplic->regs.domaincfg =APLIC_DOMAINCFG_IE |APLIC_DOMAINCFG_DM | +APLIC_DOMAINCFG_RO ; + +return 0 ; +}... ->ops here, leaving ->init_ops at NULL (prone to a deref that'll crash).
It is init-ed in [PATCH v4 20/25] xen/riscv: create APLIC DT node for guest domains and nothing between this patches could use ->ops. I will update the commit message to point that.
Thanks.
~ Oleksii
Re: [PATCH v4 17/25] xen/riscv: rename enum intc_version to intc_variant
In reply to Jan BeulichQuoted 8 lines · Jan Beulich
Quoted 5 lines · Oleksii Kurochko
Rename the enum to
intc_variantand the structure member fromhw_versiontohw_variantto better reflect that these values select between different controller variants, not versions of the same one.Signed-off-by Oleksii Kurochko <[email protected]>Acked-by Jan Beulich <[email protected]>
Thanks.
Quoted 1 line
(perhaps also Requested.by: or Suggested-by:)
Sure, I will add one of the tag.
Quoted 3 lines
It looks as if this might be independent of earlier patches, and could go in soon after branching?
Yes, it is fully independent. If at the momemnt of posting of v5 it won't be committed I will just move this patch to the start of patch series.
~ Oleksii
Re: [PATCH v4 18/25] xen/riscv: introduce (de)initialization helpers for vINTC
In reply to Jan BeulichQuoted 11 lines · Jan Beulich
Quoted 8 lines · Oleksii Kurochko
Add common helpers
domain_vintc_init()anddomain_vintc_deinit()to allocate and deallocate a virtual interrupt controller (vINTC) structure and initialize basic virtual interrupt controller registers.
domain_vintc_deinit()isn't called at the moment asarch_domain_destroy()is implemented as stub at the moment.Signed-off-by Oleksii Kurochko <[email protected]>Acked-by Jan Beulich <[email protected]>
Thanks.
Quoted 14 lines
with one more suggestion:
Quoted 12 lines
xen/arch/riscv/intc.c +8
-0@@ -83,3 +84,37 @@ int __init make_intc_domU_node(struct kernel_info *kinfo)return vintc->init_ops->make_domu_dt_node (kinfo); } + +int domain_vintc_init (struct domain *d) +{ +int ret = -EOPNOTSUPP ; +const enum intc_variant variant = intc_hw_ops->info->hw_variant; + +switch ( variant ) + {
Quoted 8 lines
xen/arch/riscv/intc.c int __init make_intc_domU_node(struct kernel_info *kinfo) · line 100
Quoted 6 lines
xen/arch/riscv/intc.c +6
-0+case INTC_APLIC : + ret =domain_vaplic_init (d); +break ; + +default : +printk ("vintc (variant:%d) isn't implemented\n" , variant);
printk_once()maybe?
It makes sense. I will apply your suggestions.
~ Oleksii
Re: [PATCH v4 19/25] xen/riscv: generate IMSIC DT node for guest domains
In reply to Jan BeulichQuoted 20 lines · Jan Beulich
Quoted 19 lines · Oleksii Kurochko
xen/arch/riscv/imsic.c +4
-0@@ -13,8 +13,12 @@#include <xen/const.h> #include <xen/cpumask.h> #include <xen/device_tree.h> +#include <xen/domain.h> #include <xen/errno.h> +#include <xen/fdt-domain-build.h> +#include <xen/fdt-kernel.h> #include <xen/init.h> +#include <xen/libfdt/libfdt.h> #include <xen/macros.h> #include <xen/sched.h> #include <xen/smp.h> @@ -34,6 +38,16 @@ static struct imsic_config imsic_cfg = { .lock = SPIN_LOCK_UNLOCKED, };
Quoted 12 lines
xen/arch/riscv/imsic.c static struct imsic_config imsic_cfg = { · line 49
Quoted 9 lines
xen/arch/riscv/imsic.c +9
-0+/* +* Number of MSIs available to a guest. Determined by the host interrupt +* controller, so it is identical for every domain -- hence a single global +* rather than a per-domain value. +*/ +static unsigned int __read_mostly guest_num_msis; + +#define GUEST_IMSIC_COMPATIBLE "riscv,imsics" +#define GUEST_IMSIC_NUM_MSIS 255Considering its use this isn't named correctly - it's not the number of MSIs guests get to use.
I will rename to GUEST_IMSIC_NUM_IDS then it will be fully aligned with dts property name.
Then it makes sense to rename guest_num_msis to guest_num_ids.
Quoted 5 lines
Quoted 5 lines
xen/arch/riscv/imsic.c +0
-0@@ -285,6 +299,11 @@ static int imsic_parse_node(const struct dt_device_node *node,return -ENOENT ; }
Quoted 7 lines
xen/arch/riscv/imsic.c static int imsic_parse_node(const struct dt_device_node *node, · line 305
Quoted 4 lines
xen/arch/riscv/imsic.c +4
-0+if (dt_property_read_u32 (node,"riscv,num-guest-ids" , &tmp) ) + guest_num_msis = tmp; +else + guest_num_msis =IMSIC_MAX_ID ;Why is
guest_num_msis__read_mostly, not__ro_after_init? Merely because the function here (wrongly) isn't__init?
Yes, because of the function isn't __init what I can agree is wrong. I will change that and s/__read_mostly/__ro_after_init for guest_num_msis.
Quoted 32 lines
Quoted 32 lines
xen/arch/riscv/imsic.c +27
-0@@ -522,3 +541,121 @@ int __init imsic_init(const struct dt_device_node *node)return rc; } + +static int __init guest_imsic_make_reg_property (struct domain *d,void *fdt) +{ +paddr_t size =IMSIC_MMIO_PAGE_SZ * d->max_vcpus; +__be32 regs[4 ] = { +cpu_to_be32 (GUEST_IMSIC_S_BASE >>32 ), +cpu_to_be32 (GUEST_IMSIC_S_BASE ), +cpu_to_be32 (size >>32 ), +cpu_to_be32 (size), + }; + +return fdt_property (fdt,"reg" , regs,sizeof (regs)); +} + +static int __init guest_imsic_set_interrupt_extended_prop (struct domain *d, +void *fdt) +{ +unsigned int cpu, pos =0 ; +__be32 *irq_ext; +int res; + + irq_ext =xvzalloc_array (__be32, d->max_vcpus *2 ); +if ( !irq_ext ) +return -ENOMEM ; + +for ( cpu =0 ; cpu < d->max_vcpus; cpu++ ) + {
Quoted 8 lines
xen/arch/riscv/imsic.c int __init imsic_init(const struct dt_device_node *node) · line 574
Quoted 4 lines
xen/arch/riscv/imsic.c +4
-0+char buf[64 ]; +uint32_t phandle; + +snprintf (buf,sizeof (buf),"/cpus/cpu@%u/interrupt-controller" , cpu);May I, btw, suggest you get into the habit of using
ARRAY_SIZE()in favor ofsizeof()withsnprintf()? That's becausesizeof()isn't correct to use if wide strings (and henceswnprintf()) come into play.
Oh, right with wchar_t buf[64] sizeof(buf) won't return 64...
I will apply your suggestion and use ARRAY_SIZE() here instead.
Quoted 13 lines
xen/arch/riscv/imsic.c int __init imsic_init(const struct dt_device_node *node) · line 603
Quoted 9 lines
xen/arch/riscv/imsic.c +8
-0+int __init vimsic_make_domu_dt_node (struct kernel_info *kinfo, +unsigned int *phandle) +{ +int res; +void *fdt = kinfo->fdt; +char vimsic_name[32 ]; +unsigned int vimsic_phandle; +unsigned int num_msis =min (GUEST_IMSIC_NUM_MSIS +0U , guest_num_msis);As
guest_num_msis(supposedly) doesn't change anymore after it was set, why would this need calculating again for each call here? Can't you apply the upper bound right inimsic_parse_node()?
Agree, I will add the following to imsic_parse_node() after guest_num_msis is init-ed:
guest_num_msis = min(GUEST_IMSIC_NUM_MSIS + 0U, guest_num_msis);
Quoted 7 lines
Quoted 7 lines
xen/arch/riscv/include/asm/guest-layout.h +0
-0@@ -3,6 +3,12 @@#include <public/xen.h>
Quoted 7 lines
xen/arch/riscv/include/asm/guest-layout.h line 10
Quoted 5 lines
xen/arch/riscv/include/asm/guest-layout.h +5
-0+/* +* Base address of the guest's supervisor-mode IMSIC. The value is the address +* typically used for IMSIC by QEMU. +*/ +#define GUEST_IMSIC_S_BASE _UL(0x28000000)As you mention it explicitly: Is there also a user-mode IMSIC?
I am not aware of such.
I mention it explicitly as machine mode IMSIC exists and it is a separate DT node for that.
Out of scope: there is a reserved bit in MISA register for user-level interrupts but I don't see that AIA uses that bit.
Thanks.
~ Oleksii
Re: [PATCH v4 20/25] xen/riscv: create APLIC DT node for guest domains
In reply to Jan BeulichQuoted 10 lines · Jan Beulich
Quoted 9 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/imsic.h +1
-0@@ -78,6 +78,7 @@ struct vimsic_state { };struct dt_device_node ; +struct kernel_info ;struct vcpu ;
Quoted 8 lines
xen/arch/riscv/include/asm/imsic.h int vcpu_imsic_init(struct vcpu *v); · line 97
Quoted 6 lines
xen/arch/riscv/include/asm/imsic.h +1
-0int imsic_init (const struct dt_device_node *node);@@ -93,4 +94,6 @@ int vcpu_imsic_init(struct vcpu *v);void vcpu_imsic_deinit (struct vcpu *v);unsigned int vcpu_guest_file_id (const struct vcpu *v); +int vimsic_make_domu_dt_node (struct kernel_info *kinfo,unsigned int *phandle);Doesn't this belong in the earlier patch?
Yes, it should be in the earlier patch. I will move this decl. to prev patch.
Quoted 14 lines
Quoted 14 lines
xen/arch/riscv/vaplic.c +2
-0@@ -9,6 +9,8 @@*/ #include <xen/errno.h> +#include <xen/fdt-kernel.h> +#include <xen/libfdt/libfdt.h> #include <xen/sched.h> #include <xen/xvmalloc.h> @@ -19,6 +21,11 @@
Quoted 7 lines
xen/arch/riscv/vaplic.c line 25
Quoted 4 lines
xen/arch/riscv/vaplic.c +2
-0#include "aplic-priv.h" +#define VAPLIC_COMPATIBLE "riscv,aplic" +#define VAPLIC_NUM_SOURCES 96So for the IMSIC the host value is relevant, but for the APLIC the count is an arbitrary(?) compile time constant? Why?
If you are referring to the number of IMSIC interrupt identities, the IMSIC node has separate properties for the host and guest:
```yaml
riscv,num-ids:
$ref: /schemas/types.yaml#/definitions/uint32
minimum: 63
maximum: 2047
description:
Number of interrupt identities supported by the IMSIC interrupt file.
riscv,num-guest-ids:
$ref: /schemas/types.yaml#/definitions/uint32
minimum: 63
maximum: 2047
description:
Number of interrupt identities supported by the IMSIC guest
interrupt file. If not specified, it is assumed to be the same as the value of the `riscv,num-ids` property.
```Therefore, if riscv,num-guest-ids is not explicitly specified, the predefined value GUEST_IMSIC_NUM_IDS is used.
No equivalent property exists for APLIC, which is why the value is explicitly hardcoded here. To some extent, the chosen number is arbitrary, but I used the same value that QEMU uses when creating the APLIC node.
It probably makes sense to limit this value in a similar way to IMSIC, at least for now, since the case where the number of VAPLIC sources exceeds the number of host APLIC sources is not supported (assuming that configuration is even valid). In other words, we could use:
min(VAPLIC_NUM_SOURCES, host_num_sources)
Would that make sense?
Quoted 5 lines
Quoted 5 lines
xen/arch/riscv/vaplic.c +0
-0@@ -29,6 +36,74 @@ static void cf_check vaplic_deinit(struct vcpu *v)return vcpu_imsic_deinit (v); }
Quoted 8 lines
xen/arch/riscv/vaplic.c static void cf_check vaplic_deinit(struct vcpu *v) · line 42
Quoted 4 lines
xen/arch/riscv/vaplic.c +4
-0+static int __init cf_check vaplic_make_domu_dt_node(struct kernel_info *kinfo) +{ +struct domain *d = kinfo->bd.d; +int res =0 ;I'm pretty sure I did point out this (or a very similar) pointless initializer before.
I will drop initializer.
Thanks.
~ Oleksii
Re: [PATCH v4 19/25] xen/riscv: generate IMSIC DT node for guest domains
In reply to Oleksii KurochkoQuoted 34 lines · Oleksii Kurochko
Quoted 20 lines · Jan Beulich
Quoted 19 lines · Oleksii Kurochko
xen/arch/riscv/imsic.c +4
-0@@ -13,8 +13,12 @@#include <xen/const.h> #include <xen/cpumask.h> #include <xen/device_tree.h> +#include <xen/domain.h> #include <xen/errno.h> +#include <xen/fdt-domain-build.h> +#include <xen/fdt-kernel.h> #include <xen/init.h> +#include <xen/libfdt/libfdt.h> #include <xen/macros.h> #include <xen/sched.h> #include <xen/smp.h> @@ -34,6 +38,16 @@ static struct imsic_config imsic_cfg = { .lock = SPIN_LOCK_UNLOCKED, };Quoted 12 lines
xen/arch/riscv/imsic.c static struct imsic_config imsic_cfg = { · line 49
Quoted 9 lines
xen/arch/riscv/imsic.c +9
-0+/* +* Number of MSIs available to a guest. Determined by the host interrupt +* controller, so it is identical for every domain -- hence a single global +* rather than a per-domain value. +*/ +static unsigned int __read_mostly guest_num_msis; + +#define GUEST_IMSIC_COMPATIBLE "riscv,imsics" +#define GUEST_IMSIC_NUM_MSIS 255Considering its use this isn't named correctly - it's not the number of MSIs guests get to use.
Quoted 4 lines
I will rename to
GUEST_IMSIC_NUM_IDSthen it will be fully aligned with dts property name.Then it makes sense to rename
guest_num_msistoguest_num_ids.
That's not going to help address my remark. I specifically referred to ...
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/riscv/imsic.c +4
-0+int __init vimsic_make_domu_dt_node (struct kernel_info *kinfo, +unsigned int *phandle) +{ +int res;Quoted 8 lines
xen/arch/riscv/imsic.c int __init imsic_init(const struct dt_device_node *node) · line 603
Quoted 4 lines
xen/arch/riscv/imsic.c +4
-0+void *fdt = kinfo->fdt; +char vimsic_name[32 ]; +unsigned int vimsic_phandle; +unsigned int num_msis =min (GUEST_IMSIC_NUM_MSIS +0U , guest_num_msis);As
guest_num_msis(supposedly) doesn't change anymore after it was set, why would this need calculating again for each call here? Can't you apply the upper bound right inimsic_parse_node()?
Quoted 4 lines
Agree, I will add the following to
imsic_parse_node()afterguest_num_msisis init-ed:
guest_num_msis=min(GUEST_IMSIC_NUM_MSIS + 0U, guest_num_msis);
... the sole use of the constant (here). The number of MSIs (or IDs or whatever else) isn't GUEST_IMSIC_NUM_MSIS; that's merely an upper bound (which in turn is there for an unknown to me reason).
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
xen/arch/riscv/include/asm/guest-layout.h +0
-0@@ -3,6 +3,12 @@#include <public/xen.h> Quoted 7 lines
xen/arch/riscv/include/asm/guest-layout.h line 10
Quoted 5 lines
xen/arch/riscv/include/asm/guest-layout.h +5
-0+/* +* Base address of the guest's supervisor-mode IMSIC. The value is the address +* typically used for IMSIC by QEMU. +*/ +#define GUEST_IMSIC_S_BASE _UL(0x28000000)As you mention it explicitly: Is there also a user-mode IMSIC?
Quoted 4 lines
I am not aware of such.
I mention it explicitly as machine mode IMSIC exists and it is a separate DT node for that.
Ah, okay. Then maybe keep the comment as is. It's not quite clear to me whether, from an abstract perspective, "machine mode" could make sense for guests. If it can't, "supervisor-mode" would be redundant with "guest's".
Jan
Re: [PATCH v4 20/25] xen/riscv: create APLIC DT node for guest domains
In reply to Oleksii KurochkoQuoted 51 lines · Oleksii Kurochko
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
xen/arch/riscv/vaplic.c +2
-0@@ -9,6 +9,8 @@*/ #include <xen/errno.h> +#include <xen/fdt-kernel.h> +#include <xen/libfdt/libfdt.h> #include <xen/sched.h> #include <xen/xvmalloc.h> @@ -19,6 +21,11 @@Quoted 7 lines
xen/arch/riscv/vaplic.c line 25
Quoted 4 lines
xen/arch/riscv/vaplic.c +2
-0#include "aplic-priv.h" +#define VAPLIC_COMPATIBLE "riscv,aplic" +#define VAPLIC_NUM_SOURCES 96So for the IMSIC the host value is relevant, but for the APLIC the count is an arbitrary(?) compile time constant? Why?
If you are referring to the number of IMSIC interrupt identities, the IMSIC node has separate properties for the host and guest:
```yaml riscv,num-ids: $ref: /schemas/types.yaml#/definitions/uint32 minimum: 63 maximum: 2047 description: Number of interrupt identities supported by the IMSIC interrupt file. riscv,num-guest-ids: $ref: /schemas/types.yaml#/definitions/uint32 minimum: 63 maximum: 2047 description: Number of interrupt identities supported by the IMSIC guest interrupt file. If not specified, it is assumed to be the same as the value of the `riscv,num-ids` property. ```Therefore, if
riscv,num-guest-idsis not explicitly specified, the predefined valueGUEST_IMSIC_NUM_IDSis used.No equivalent property exists for APLIC, which is why the value is explicitly hardcoded here. To some extent, the chosen number is arbitrary, but I used the same value that QEMU uses when creating the APLIC node.
Quoted 7 lines
It probably makes sense to limit this value in a similar way to IMSIC, at least for now, since the case where the number of VAPLIC sources exceeds the number of host APLIC sources is not supported (assuming that configuration is even valid). In other words, we could use:
min(VAPLIC_NUM_SOURCES, host_num_sources)Would that make sense?
Perhaps, yes. Just with the constant again named appropriately for its purpose (see comments on an earlier patch).
Jan
Re: [PATCH v4 19/25] xen/riscv: generate IMSIC DT node for guest domains
In reply to Jan BeulichQuoted 50 lines · Jan Beulich
Quoted 32 lines · Oleksii Kurochko
Quoted 20 lines · Jan Beulich
Quoted 19 lines · Oleksii Kurochko
xen/arch/riscv/imsic.c +4
-0@@ -13,8 +13,12 @@#include <xen/const.h> #include <xen/cpumask.h> #include <xen/device_tree.h> +#include <xen/domain.h> #include <xen/errno.h> +#include <xen/fdt-domain-build.h> +#include <xen/fdt-kernel.h> #include <xen/init.h> +#include <xen/libfdt/libfdt.h> #include <xen/macros.h> #include <xen/sched.h> #include <xen/smp.h> @@ -34,6 +38,16 @@ static struct imsic_config imsic_cfg = { .lock = SPIN_LOCK_UNLOCKED, };Quoted 11 lines
xen/arch/riscv/imsic.c static struct imsic_config imsic_cfg = { · line 49
Quoted 9 lines
xen/arch/riscv/imsic.c +9
-0+/* +* Number of MSIs available to a guest. Determined by the host interrupt +* controller, so it is identical for every domain -- hence a single global +* rather than a per-domain value. +*/ +static unsigned int __read_mostly guest_num_msis; + +#define GUEST_IMSIC_COMPATIBLE "riscv,imsics" +#define GUEST_IMSIC_NUM_MSIS 255Considering its use this isn't named correctly - it's not the number of MSIs guests get to use.
Quoted 4 lines
I will rename to
GUEST_IMSIC_NUM_IDSthen it will be fully aligned with dts property name.Then it makes sense to rename
guest_num_msistoguest_num_ids.That's not going to help address my remark. I specifically referred to ...
Quoted 11 lines
Quoted 11 lines
xen/arch/riscv/imsic.c int __init imsic_init(const struct dt_device_node *node) · line 603
Quoted 8 lines
xen/arch/riscv/imsic.c +8
-0+int __init vimsic_make_domu_dt_node (struct kernel_info *kinfo, +unsigned int *phandle) +{ +int res; +void *fdt = kinfo->fdt; +char vimsic_name[32 ]; +unsigned int vimsic_phandle; +unsigned int num_msis =min (GUEST_IMSIC_NUM_MSIS +0U , guest_num_msis);As
guest_num_msis(supposedly) doesn't change anymore after it was set, why would this need calculating again for each call here? Can't you apply the upper bound right inimsic_parse_node()?
Quoted 7 lines
Quoted 4 lines
Agree, I will add the following to
imsic_parse_node()afterguest_num_msisis init-ed:
guest_num_msis=min(GUEST_IMSIC_NUM_MSIS + 0U, guest_num_msis);... the sole use of the constant (here). The number of MSIs (or IDs or whatever else) isn't
GUEST_IMSIC_NUM_MSIS; that's merely an upper bound (which in turn is there for an unknown to me reason).
Then GUEST_IMSIC_MAX_IDS (or *_MSIS) would be better.
~ Oleksii
Re: [PATCH v4 21/25] xen/riscv: implement IRQ routing for device passthrough
In reply to Jan BeulichQuoted 33 lines · Jan Beulich
Quoted 32 lines · Oleksii Kurochko
dom0less device passthrough requires granting guest domains access to device interrupts. Introduce
map_device_irqs_to_domain()to enumerate a DT node's interrupt properties, skipping those not owned by the primary interrupt controller (as at the moment I haven't seen usages of it), andmap_irq_to_domain()to grant domain access and configure Xen's interrupt descriptor accordingly. Sharing IRQ between domains is rejected.Both
map_irq_to_domain()andmap_device_irqs_to_domain()are marked__overlay_init, mirroring Arm: withoutCONFIG_OVERLAY_DTBthis expands to__init, so the functions are init-only and need no XSM check; withCONFIG_OVERLAY_DTBthey become runtime-callable, but the only runtime entry point isdt_overlay_domctl(), which performs the XSM checks at the domctl layer. RISC-V does not wire up DT overlay yet, so today these are strictly__init; if/when overlay support is added, the domctl-level XSM gating must be added together with it, as on Arm.
route_irq_to_guest()andrelease_irq()manageirq_descownership for guest-assigned interrupts. Each assignment carries a smallirq_gueststructure asirqaction::dev_id, recording the owning domain and virtual IRQ number which is 1:1 mapped to physical IRQ number. A per-domain vIRQ allocation bitmap (used_irqsin struct vintc), managed byvintc_reserve_virq(), prevents the same vIRQ being claimed twice.Host and guest interrupts may differ in some operations (EOI timing in particular, possibly others): a host IRQ is completed once Xen's handler runs, whereas a passthrough IRQ must defer the physical completion until the guest issues its own EOI, otherwise a still-asserted level line would immediately retrigger and storm. This affects only the .end callback; the rest of
hw_interrupt_typeis shared, hence the separate host and guesthw_interrupt_typeinstances.
Quoted 7 lines
Quoted 4 lines
With APLIC+IMSIC, guest interrupts are delivered directly by hardware through the IMSIC, bypassing
do_IRQ(). The_IRQ_GUESTbranch indo_IRQ()is therefore left asBUG()until a platform without direct IMSIC delivery is encountered.And this is secure, i.e. one guest (by mishandling things, e.g. simply never claiming / servicing an interrupt) cannot affect another guest?
It will be just affect this specific interrupt which isn't claimed/serviced.
Quoted 37 lines
Quoted 23 lines
xen/arch/riscv/device.c new file +22
-0+int __overlay_init map_device_irqs_to_domain(struct domain *d, +struct dt_device_node *dev, +bool need_mapping, +struct rangeset *irq_ranges) +{ +unsigned int i, nirq =dt_number_of_irq (dev); + +if ( irq_ranges ) +return -EOPNOTSUPP ; + +/* Give permission and map IRQs */ +for ( i =0 ; i < nirq; i++ ) + { +int res, irq; +struct dt_raw_irq rirq; + + res =dt_device_get_raw_irq (dev, i, &rirq); +if ( res ) + { +printk (XENLOG_ERR "Unable to retrieve irq %u for %s\n" , + i,dt_node_full_name (dev)); +return res;xen/arch/riscv/device.c line 77
Quoted 10 lines
xen/arch/riscv/device.c new file +10
-0+ } + +/* +* Don't map IRQs that have no physical meaning +* ie: IRQs whose controller is not APLIC/IMSIC/PLIC. +*/ +if ( rirq.controller != dt_interrupt_controller ) + { + dt_dprintk("irq %u not connected to primary controller." + "Connected to %s\n", i,Nit: By splitting a format string like this, you pretty effectively hide that there's a blank missing after the full stop.
Quoted 2 lines
Further after an already wrapped function argument there shouldn't follow another one, to maintain visual clarity.
I would be okay to have a format string a little bit long. I would change that line to (if you are okay with that):
...("irq %u not connected to primary controller. Connected to %s\n",
i, dt_node_full_name(rirq.controller));
Quoted 5 lines
Quoted 5 lines
(quoted diff) +0
-0@@ -101,12 +119,28 @@ int domain_vintc_init(struct domain *d) break; }
Quoted 7 lines
xen/arch/riscv/intc.c int domain_vintc_init(struct domain *d) · line 125
Quoted 4 lines
xen/arch/riscv/intc.c +4
-0+if ( !ret ) + { + d->arch.vintc->used_irqs = + xvzalloc_array(unsigned long, BITS_TO_LONGS(d->arch.vintc->nr_virqs));Nit: Overlong line.
I will reformat that in the following way:
d->arch.vintc->used_irqs =
xvzalloc_array(unsigned long,
BITS_TO_LONGS(d->arch.vintc->nr_virqs));Quoted 32 lines
Quoted 4 lines
xen/arch/riscv/intc.c +4
-0+if ( !d->arch.vintc->used_irqs ) + ret = -ENOMEM ; + } +xen/arch/riscv/intc.c int domain_vintc_init(struct domain *d) · line 139
Quoted 10 lines
xen/arch/riscv/intc.c +4
-0return ret; }void domain_vintc_deinit (struct domain *d) {const enum intc_variant variant = intc_hw_ops->info->hw_variant; +unsigned int virq; + +if ( !d->arch.vintc ) +return ;Seeing this and ...
xen/arch/riscv/intc.c void domain_vintc_deinit(struct domain *d) · line 155
Quoted 12 lines
xen/arch/riscv/intc.c +5
-0+for ( virq =0 ; virq < d->arch.vintc->nr_virqs; virq++ ) +if (test_bit (virq, d->arch.vintc->used_irqs) ) +release_guest_irq (d, virq);switch ( variant ) {@@ -117,4 +151,14 @@ void domain_vintc_deinit(struct domain *d)default :break ; } + +XVFREE (d->arch.vintc->used_irqs);... this, ...
Quoted 4 lines
Review void domain_vintc_deinit(struct domain *d) · line 156
Quoted 1 line
(quoted diff) +1
-0+}... where is
d->arch.vintcbeing freed? That would logically look to belong into this function.
Right, it is an issue: d->arch.vintc is being NULLed inside domain_vaplic_deinit(), which are called from domain_vintc_deinit(), so XVFREE(d->arch.vintc->used_irqs) must be moved to just after the for() loop (before the switch).
As for d->arch.vintc itself, it should only be NULLed and not freed, since it is a pointer to &vaplic->vintc which is embedded in the vaplic struct and not separately allocated.
Quoted 28 lines
Quoted 28 lines
xen/arch/riscv/irq.c +9
-0@@ -12,11 +12,20 @@#include <xen/errno.h> #include <xen/init.h> #include <xen/irq.h> +#include <xen/sched.h> #include <xen/spinlock.h> +#include <xen/xvmalloc.h> #include <asm/hardirq.h> #include <asm/intc.h> +/* Describe an IRQ assigned to a guest */ +struct irq_guest +{ +struct domain *d; +unsigned int virq; +}; +static irq_desc_t irq_desc[NR_IRQS ];static bool irq_validate_new_type (unsigned int curr,unsigned int new)@@ -192,6 +201,15 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq)if ( desc->handler->ack ) desc->handler->ack (desc);
Quoted 11 lines
xen/arch/riscv/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq) · line 211
Quoted 8 lines
xen/arch/riscv/irq.c +8
-0+if ( desc->status &IRQ_GUEST ) +/* +* As at the moment APLIC + IMSIC is used for guest interrupts will +* be directly passed to guest. But if/when IMSIC won't be available +* all interrupts will go through Xenand here an irq injection +* will be necessary to do. +*/ +panic ("unimplemented" );The first comment sentence doesn't parse for me. In the 2nd there's a blank missing between "Xen" and "and".
I will rephrase it for clarity:
/*
* With APLIC + IMSIC, guest interrupts bypass Xen and are delivered
* directly to the guest. Without IMSIC, interrupts would be trapped
* by Xen and would need injecting into the guest here. */
It looks more clearer to me.
Quoted 14 lines
Quoted 14 lines
xen/arch/riscv/irq.c +9
-0@@ -221,3 +239,215 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq)spin_unlock (&desc->lock);irq_exit (); } + +static inline struct irq_guest *irq_get_guest_info (struct irq_desc *desc) +{ +ASSERT (spin_is_locked (&desc->lock)); +ASSERT (test_bit (_IRQ_GUEST, &desc->status)); +ASSERT (desc->action !=NULL ); + +return desc->action->dev_id; +}
Quoted 8 lines
xen/arch/riscv/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq) · line 255
Quoted 5 lines
xen/arch/riscv/irq.c +5
-0+ +static inline struct domain *irq_get_domain (struct irq_desc *desc) +{ +return irq_get_guest_info (desc)->d; +}Does this really need a separate helper? (You effectively open-code it anyway in
release_guest_irq().)
Considering that I used irq_get_domain() once at all (even in downstream) I will drop that.
Quoted 2 lines
For both functions: "inline" generally wants limiting to header files.
Regarding inline I think that I don't understand, it isn't in the header file as irq_get_guest_info() is used only in this file.
Do I understand you correctly and it is needed just to drop "inline" for irq_get_guest_info()?
Quoted 23 lines
Quoted 23 lines
xen/arch/riscv/irq.c +22
-0+int release_guest_irq (struct domain *d,unsigned int virq) +{ +struct irq_desc *desc =irq_to_desc (virq); +struct irq_guest *info; +unsigned long flags; + +spin_lock_irqsave (&desc->lock, flags); + +if ( !test_bit (_IRQ_GUEST, &desc->status) ) + goto unlock_err; + + info =irq_get_guest_info (desc); +if ( d != info->d ) + goto unlock_err; + +/* +* Live IRQ unrouting from a running domain is not supported: the tear-down +* drops desc->lock across release_irq()/xvfree() and relies on no +* concurrent route_irq_to_guest() being issued for this domain. Only permit +* it for a dying domain, where assignment is frozen and no new routes can +* appear. +*/
Quoted 8 lines
xen/arch/riscv/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq) · line 341
Quoted 5 lines
xen/arch/riscv/irq.c +5
-0+if ( !d->is_dying ) + { +spin_unlock_irqrestore (&desc->lock, flags); +return -EBUSY ; + }Yet
route_irq_to_guest()looks to happily act on dying guests. IOW assignment doesn't look to be frozen, despite the comment saying so.
Right, it is needed to add:
if ( d->is_dying )
return -EINVAL;at the top of route_irq_to_guest().
Quoted 9 lines
xen/arch/riscv/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq) · line 348
Quoted 7 lines
xen/arch/riscv/irq.c +6
-0+/* +* Clear _IRQ_GUEST while still holding the lock so that a concurrent +* release_guest_irq() for the same IRQ observes it and bails out, rather +* than capturing the same 'info' and double-freeing it below. +*/ +clear_bit (_IRQ_GUEST, &desc->status);You use
__set_bit()/__clear_bit()elsewhere - why not here?
As it is under spinlock it could __clear_bit here.
Quoted 8 lines
xen/arch/riscv/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq) · line 353
Quoted 5 lines
xen/arch/riscv/irq.c +4
-0+spin_unlock_irqrestore (&desc->lock, flags); + +release_irq (desc->irq, info); +xvfree (info);If, in
release_irq(), action isn't freed, it's ->dev_id field will now have a dangling pointer. (I think I did point this out before.)
It should freed in release_irq() as route_irq_to_guest() always set action->free_on_release = true;
Thanks.
~ Oleksii
Re: [PATCH v4 25/25] xen/riscv: add initial dom0less infrastructure support
In reply to Jan BeulichQuoted 25 lines · Jan Beulich
Quoted 24 lines · Oleksii Kurochko
Enable dom0less support for RISC-V by selecting
HAS_DOM0LESSand providing the minimal architecture hooks required by the common dom0less infrastructure.Add stub implementations for architecture-specific helpers used when building domains from the device tree. These allow the generic dom0less code to build and let a basic DomU be constructed on RISC-V.
construct_hwdom()andmake_hypervisor_node()are still stubs returning an error: Dom0/hwdom construction isn't supported yet, and the hypervisor node generation (needed by domains withDOM0LESS_ENHANCED_NO_XSset) is not implemented. Both are marked with a TODO and are not reached by the currently supported configurations.Provide missing helpers and definitions required by the domain construction code, including domain bitness helpers and the
p2m_set_allocation()prototype.Additionally define the guest magic memory region (
GUEST_MAGIC_BASE/GUEST_MAGIC_SIZE) inasm/guest-layout.h. The base is arbitrary; the only constraint is that the region must not overlap guest RAM or the emulated device regions. It is placed in the unused gap belowGUEST_RAM0_BASE(0x80000000); the constraints are documented next to the #define-s.
Quoted 3 lines
Quoted 1 line
Signed-off-by Oleksii Kurochko <[email protected]>Acked-by Jan Beulich <[email protected]>
Thanks.
Quoted 9 lines
Nevertheless, ...
Quoted 6 lines
xen/arch/riscv/include/asm/guest-layout.h +0
-0@@ -32,4 +32,16 @@#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE, GUEST_RAM1_BASE }#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE, GUEST_RAM1_SIZE }
Quoted 16 lines
xen/arch/riscv/include/asm/guest-layout.h line 45
Quoted 11 lines
xen/arch/riscv/include/asm/guest-layout.h +11
-0+/* +* The guest magic region holds Xen-reserved pages mapped into the guest's +* physical address space (shared info, grant table, etc.). The only real +* constraint is that the GUEST_MAGIC_SIZE-byte region must not overlap +* guest RAM (the GUEST_RAMx banks) or the emulated device regions defined +* above; the exact base is otherwise arbitrary. Here it is placed in the +* unused gap below GUEST_RAM0_BASE (0x80000000), but a hole after a RAM +* bank would work equally well. +*/ +#define GUEST_MAGIC_BASE _UL(0x79000000) +#define GUEST_MAGIC_SIZE _UL(0x01000000)... while 16Mb may seem a lot, it feels pretty little for 64-bit guests. Even in just Sv39 mode they have ample VA space to map a bigger region. (As iirc indicated before, a static upper bound looks questionable to me anyway.)
I think the comment should be updated as for grants will be separate region.
For all others, it looks like 16MB is more then enough. For example, Arm has only 4 used pages (CONSOLE=0, XENSTORE=1, MEMACCESS=2, VUART=3).
So will you be okay with reworking of the comment to:
/*
* The guest magic region holds the Xen-reserved pages mapped into the
* guest's physical address space. The only real constraint on
* GUEST_MAGIC_BASE/SIZE is that the region must not overlap guest RAM
* (the GUEST_RAMx banks) or the emulated device regions defined above;
* the exact base is otherwise arbitrary. Here it is placed in the
unused gap
* below GUEST_RAM0_BASE (0x80000000), but a hole after a RAM bank
would work
* equally well.
*/
And add to the commit message that:
``` A separate region for grant tables will be introduced at the same time as the introduction of the grant table for RISC-V. ```
~ Oleksii
Re: [PATCH v4 21/25] xen/riscv: implement IRQ routing for device passthrough
In reply to Oleksii KurochkoQuoted 24 lines · Oleksii Kurochko
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
xen/arch/riscv/irq.c +9
-0@@ -221,3 +239,215 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq)spin_unlock (&desc->lock);irq_exit (); } + +static inline struct irq_guest *irq_get_guest_info (struct irq_desc *desc) +{ +ASSERT (spin_is_locked (&desc->lock)); +ASSERT (test_bit (_IRQ_GUEST, &desc->status)); +ASSERT (desc->action !=NULL ); + +return desc->action->dev_id; +}Quoted 8 lines
xen/arch/riscv/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq) · line 255
Quoted 5 lines
xen/arch/riscv/irq.c +5
-0+ +static inline struct domain *irq_get_domain (struct irq_desc *desc) +{ +return irq_get_guest_info (desc)->d; +}Does this really need a separate helper? (You effectively open-code it anyway in
release_guest_irq().)
Quoted 2 lines
Considering that I used
irq_get_domain()once at all (even in downstream) I will drop that.
Good.
Quoted 4 lines
Quoted 1 line
For both functions: "inline" generally wants limiting to header files.
Regarding inline I think that I don't understand, it isn't in the header file as
irq_get_guest_info()is used only in this file.
Right. I didn't as it to move to a header file.
Quoted 2 lines
Do I understand you correctly and it is needed just to drop "inline" for
irq_get_guest_info()?
Yes. It can be simply static here, and the compiler can figure out whether to inline it.
Quoted 10 lines
Quoted 7 lines
xen/arch/riscv/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq) · line 353
Quoted 4 lines
xen/arch/riscv/irq.c +4
-0+spin_unlock_irqrestore (&desc->lock, flags); + +release_irq (desc->irq, info); +xvfree (info);If, in
release_irq(), action isn't freed, it's ->dev_id field will now have a dangling pointer. (I think I did point this out before.)It should freed in
release_irq()asroute_irq_to_guest()always setaction->free_on_release= true;
Well, "free_on_release" must exits for a purpose. I.e. there must be, now or soon, cases where it's set to false. Else simply drop the field.
Jan
Re: [PATCH v4 25/25] xen/riscv: add initial dom0less infrastructure support
In reply to Oleksii KurochkoQuoted 25 lines · Oleksii Kurochko
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/guest-layout.h +0
-0@@ -32,4 +32,16 @@#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE, GUEST_RAM1_BASE }#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE, GUEST_RAM1_SIZE }Quoted 16 lines
xen/arch/riscv/include/asm/guest-layout.h line 45
Quoted 11 lines
xen/arch/riscv/include/asm/guest-layout.h +11
-0+/* +* The guest magic region holds Xen-reserved pages mapped into the guest's +* physical address space (shared info, grant table, etc.). The only real +* constraint is that the GUEST_MAGIC_SIZE-byte region must not overlap +* guest RAM (the GUEST_RAMx banks) or the emulated device regions defined +* above; the exact base is otherwise arbitrary. Here it is placed in the +* unused gap below GUEST_RAM0_BASE (0x80000000), but a hole after a RAM +* bank would work equally well. +*/ +#define GUEST_MAGIC_BASE _UL(0x79000000) +#define GUEST_MAGIC_SIZE _UL(0x01000000)... while 16Mb may seem a lot, it feels pretty little for 64-bit guests. Even in just Sv39 mode they have ample VA space to map a bigger region. (As iirc indicated before, a static upper bound looks questionable to me anyway.)
Quoted 4 lines
I think the comment should be updated as for grants will be separate region.
For all others, it looks like 16MB is more then enough. For example, Arm has only 4 used pages (CONSOLE=0, XENSTORE=1, MEMACCESS=2, VUART=3).
Then the question goes the other way around: Why 16Mb? Won't e.g. 2Mb suffice?
Quoted 13 lines
So will you be okay with reworking of the comment to:
/*
* The guest magic region holds the Xen-reserved pages mapped into the
* guest's physical address space. The only real constraint on
* GUEST_MAGIC_BASE/SIZE is that the region must not overlap guest RAM
* (theGUEST_RAMxbanks) or the emulated device regions defined above;
* the exact base is otherwise arbitrary. Here it is placed in the
unused gap
* belowGUEST_RAM0_BASE(0x80000000), but a hole after a RAM bank
would work
* equally well.
*/
Quoted 5 lines
And add to the commit message that:
``` A separate region for grant tables will be introduced at the same time as the introduction of the grant table for RISC-V. ```
That's quite a bit better, yes.
Jan
Re: [PATCH v4 21/25] xen/riscv: implement IRQ routing for device passthrough
In reply to Jan BeulichQuoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
xen/arch/riscv/irq.c +4
-0+spin_unlock_irqrestore (&desc->lock, flags); + +release_irq (desc->irq, info); +xvfree (info);
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
If, in
release_irq(), action isn't freed, it's ->dev_id field will now have a dangling pointer. (I think I did point this out before.)It should freed in
release_irq()asroute_irq_to_guest()always setaction->free_on_release= true;Well, "
free_on_release" must exits for a purpose. I.e. there must be, now or soon, cases where it's set to false. Else simply drop the field.
I can't simply remove this field because it is part of the common struct irqaction and is used by other arc-s. (I assume that it is not what you fully meant...)
IIUC, this field is used to determine whether an irqaction is heap-allocated (and therefore should be freed) or statically allocated (and therefore should not be freed).
At the moment, all IRQ actions are heap-allocated (on RISC-V), so free_on_release should always be set to true. In particular, the code snippet you asked about releases a guest interrupt, and guest interrupt actions are always heap-allocated. As a result, when release_guest_irq() calls release_irq(), the associated irqaction will be freed.
So, from what I can see, the current behavior is correct and I think it should be left as it is. Do you have any concerns about this?
~ Oleksii
Re: [PATCH v4 25/25] xen/riscv: add initial dom0less infrastructure support
In reply to Jan BeulichQuoted 26 lines · Jan Beulich
Quoted 25 lines · Oleksii Kurochko
Quoted 23 lines · Jan Beulich
Quoted 7 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/guest-layout.h +1
-0@@ -32,4 +32,16 @@#define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE, GUEST_RAM1_BASE }#define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE, GUEST_RAM1_SIZE } +/* xen/arch/riscv/include/asm/guest-layout.h line 45
Quoted 10 lines
xen/arch/riscv/include/asm/guest-layout.h +10
-0+* The guest magic region holds Xen-reserved pages mapped into the guest's +* physical address space (shared info, grant table, etc.). The only real +* constraint is that the GUEST_MAGIC_SIZE-byte region must not overlap +* guest RAM (the GUEST_RAMx banks) or the emulated device regions defined +* above; the exact base is otherwise arbitrary. Here it is placed in the +* unused gap below GUEST_RAM0_BASE (0x80000000), but a hole after a RAM +* bank would work equally well. +*/ +#define GUEST_MAGIC_BASE _UL(0x79000000) +#define GUEST_MAGIC_SIZE _UL(0x01000000)... while 16Mb may seem a lot, it feels pretty little for 64-bit guests. Even in just Sv39 mode they have ample VA space to map a bigger region. (As iirc indicated before, a static upper bound looks questionable to me anyway.)
Quoted 7 lines
Quoted 4 lines
I think the comment should be updated as for grants will be separate region.
For all others, it looks like 16MB is more then enough. For example, Arm has only 4 used pages (CONSOLE=0, XENSTORE=1, MEMACCESS=2, VUART=3).
Then the question goes the other way around: Why 16Mb? Won't e.g. 2Mb suffice?
I don't see any technical reason to have 16 Mb on Arm, IMO it could be shrunk to what you suggested (I will do that for RISC-V).
~ Oleksii
Quoted 23 lines
Quoted 14 lines
So will you be okay with reworking of the comment to:
/*
* The guest magic region holds the Xen-reserved pages mapped into the
* guest's physical address space. The only real constraint on
* GUEST_MAGIC_BASE/SIZE is that the region must not overlap guest RAM
* (theGUEST_RAMxbanks) or the emulated device regions defined above;
* the exact base is otherwise arbitrary. Here it is placed in the
unused gap
* belowGUEST_RAM0_BASE(0x80000000), but a hole after a RAM bank
would work
* equally well.
*/Quoted 5 lines
And add to the commit message that:
``` A separate region for grant tables will be introduced at the same time as the introduction of the grant table for RISC-V. ```That's quite a bit better, yes.
Jan
Re: [PATCH v4 21/25] xen/riscv: implement IRQ routing for device passthrough
In reply to Oleksii KurochkoQuoted 18 lines · Oleksii Kurochko
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
xen/arch/riscv/irq.c +4
-0+spin_unlock_irqrestore (&desc->lock, flags); + +release_irq (desc->irq, info); +xvfree (info);Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
If, in
release_irq(), action isn't freed, it's ->dev_id field will now have a dangling pointer. (I think I did point this out before.)It should freed in
release_irq()asroute_irq_to_guest()always setaction->free_on_release= true;Well, "
free_on_release" must exits for a purpose. I.e. there must be, now or soon, cases where it's set to false. Else simply drop the field.
Quoted 7 lines
I can't simply remove this field because it is part of the common
struct irqactionand is used by other arc-s. (I assume that it is not what you fully meant...)IIUC, this field is used to determine whether an irqaction is heap-allocated (and therefore should be freed) or statically allocated (and therefore should not be freed).
Yes. However, all uses of the field are in arch-specific code. So in principle it could be #ifdef-ed out for RISC-V. There may be a better option, though:
Quoted 8 lines
At the moment, all IRQ actions are heap-allocated (on RISC-V), so
free_on_releaseshould always be set to true. In particular, the code snippet you asked about releases a guest interrupt, and guest interrupt actions are always heap-allocated. As a result, whenrelease_guest_irq()callsrelease_irq(), the associated irqaction will be freed.So, from what I can see, the current behavior is correct and I think it should be left as it is. Do you have any concerns about this?
If you only ever have the field set to true, use ASSERT() in place of if().
Jan
Re: [PATCH v4 21/25] xen/riscv: implement IRQ routing for device passthrough
Quoted 37 lines · Jan Beulich
Quoted 18 lines · Oleksii Kurochko
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
xen/arch/riscv/irq.c +4
-0+spin_unlock_irqrestore (&desc->lock, flags); + +release_irq (desc->irq, info); +xvfree (info);Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
If, in
release_irq(), action isn't freed, it's ->dev_id field will now have a dangling pointer. (I think I did point this out before.)It should freed in
release_irq()asroute_irq_to_guest()always setaction->free_on_release= true;Well, "
free_on_release" must exits for a purpose. I.e. there must be, now or soon, cases where it's set to false. Else simply drop the field.Quoted 7 lines
I can't simply remove this field because it is part of the common
struct irqactionand is used by other arc-s. (I assume that it is not what you fully meant...)IIUC, this field is used to determine whether an irqaction is heap-allocated (and therefore should be freed) or statically allocated (and therefore should not be freed).
Yes. However, all uses of the field are in arch-specific code. So in principle it could be #ifdef-ed out for RISC-V. There may be a better option, though:
Quoted 6 lines
At the moment, all IRQ actions are heap-allocated (on RISC-V), so
free_on_releaseshould always be set to true. In particular, the code snippet you asked about releases a guest interrupt, and guest interrupt actions are always heap-allocated. As a result, whenrelease_guest_irq()callsrelease_irq(), the associated irqaction will be freed.
Quoted 6 lines
Quoted 2 lines
So, from what I can see, the current behavior is correct and I think it should be left as it is. Do you have any concerns about this?
If you only ever have the field set to true, use
ASSERT()in place ofif().
It looks like that if we want an ASSERT(), it should be in release_guest_irq(). However, that would require duplicating part of release_irq() to locate the corresponding irqaction and verify free_on_release. Since guest IRQs are created through route_irq_to_guest(), which always sets action->free_on_release = true, we are already safe.
I don't see much benefit in replacing the if statement with an ASSERT() in release_irq(). The current implementation is generic and would also work for Xen-owned, statically allocated interrupts (even though there are none today). If we replace the if with an ASSERT() now, anyone introducing a Xen-owned, statically allocated interrupt in the future would simply have to revert the change and restore the if statement, bringing us back to the current implementation.
Since the existing code doesn't break any logic and already handles both the current use case and potential future extensions (statically allocated irqs), it seems reasonable to keep it as it is.
~ Oleksii
Re: [PATCH v4 21/25] xen/riscv: implement IRQ routing for device passthrough
Quoted 10 lines · Oleksii Kurochko
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Oleksii Kurochko
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ spin_unlock_irqrestore(&desc->lock, flags); + + release_irq(desc->irq, info); + xvfree(info);If, in
release_irq(), action isn't freed, it's ->dev_id field will now have a dangling pointer. (I think I did point this out before.)
We'll be back to this if ...
Quoted 38 lines
Quoted 24 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
It should freed in
release_irq()asroute_irq_to_guest()always setaction->free_on_release= true;Well, "
free_on_release" must exits for a purpose. I.e. there must be, now or soon, cases where it's set to false. Else simply drop the field.Quoted 7 lines
I can't simply remove this field because it is part of the common
struct irqactionand is used by other arc-s. (I assume that it is not what you fully meant...)IIUC, this field is used to determine whether an irqaction is heap-allocated (and therefore should be freed) or statically allocated (and therefore should not be freed).
Yes. However, all uses of the field are in arch-specific code. So in principle it could be #ifdef-ed out for RISC-V. There may be a better option, though:
Quoted 6 lines
At the moment, all IRQ actions are heap-allocated (on RISC-V), so
free_on_releaseshould always be set to true. In particular, the code snippet you asked about releases a guest interrupt, and guest interrupt actions are always heap-allocated. As a result, whenrelease_guest_irq()callsrelease_irq(), the associated irqaction will be freed.Quoted 6 lines
Quoted 2 lines
So, from what I can see, the current behavior is correct and I think it should be left as it is. Do you have any concerns about this?
If you only ever have the field set to true, use
ASSERT()in place ofif().It looks like that if we want an
ASSERT(), it should be inrelease_guest_irq(). However, that would require duplicating part ofrelease_irq()to locate the correspondingirqactionand verifyfree_on_release. Since guest IRQs are created throughroute_irq_to_guest(), which always setsaction->free_on_release = true, we are already safe.
Quoted 7 lines
I don't see much benefit in replacing the
ifstatement with anASSERT()inrelease_irq(). The current implementation is generic and would also work for Xen-owned, statically allocated interrupts (even though there are none today). If we replace theifwith anASSERT()now, anyone introducing a Xen-owned, statically allocated interrupt in the future would simply have to revert the change and restore theifstatement, bringing us back to the current implementation.
... such a change was made. Imo you have two choices: Deal with the issue properly right away, keeping the if(). Or assume "free_on_release" is only ever true, and add an assertion to this effect (indicating that code needs auditing if that assumption is broken).
Jan
Re: [PATCH v4 21/25] xen/riscv: implement IRQ routing for device passthrough
Quoted 60 lines · Jan Beulich
Quoted 10 lines · Oleksii Kurochko
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Oleksii Kurochko
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ spin_unlock_irqrestore(&desc->lock, flags); + + release_irq(desc->irq, info); + xvfree(info);If, in
release_irq(), action isn't freed, it's ->dev_id field will now have a dangling pointer. (I think I did point this out before.)We'll be back to this if ...
Quoted 38 lines
Quoted 24 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
It should freed in
release_irq()asroute_irq_to_guest()always setaction->free_on_release= true;Well, "
free_on_release" must exits for a purpose. I.e. there must be, now or soon, cases where it's set to false. Else simply drop the field.Quoted 7 lines
I can't simply remove this field because it is part of the common
struct irqactionand is used by other arc-s. (I assume that it is not what you fully meant...)IIUC, this field is used to determine whether an irqaction is heap-allocated (and therefore should be freed) or statically allocated (and therefore should not be freed).
Yes. However, all uses of the field are in arch-specific code. So in principle it could be #ifdef-ed out for RISC-V. There may be a better option, though:
Quoted 6 lines
At the moment, all IRQ actions are heap-allocated (on RISC-V), so
free_on_releaseshould always be set to true. In particular, the code snippet you asked about releases a guest interrupt, and guest interrupt actions are always heap-allocated. As a result, whenrelease_guest_irq()callsrelease_irq(), the associated irqaction will be freed.Quoted 6 lines
Quoted 2 lines
So, from what I can see, the current behavior is correct and I think it should be left as it is. Do you have any concerns about this?
If you only ever have the field set to true, use
ASSERT()in place ofif().It looks like that if we want an
ASSERT(), it should be inrelease_guest_irq(). However, that would require duplicating part ofrelease_irq()to locate the correspondingirqactionand verifyfree_on_release. Since guest IRQs are created throughroute_irq_to_guest(), which always setsaction->free_on_release = true, we are already safe.Quoted 7 lines
I don't see much benefit in replacing the
ifstatement with anASSERT()inrelease_irq(). The current implementation is generic and would also work for Xen-owned, statically allocated interrupts (even though there are none today). If we replace theifwith anASSERT()now, anyone introducing a Xen-owned, statically allocated interrupt in the future would simply have to revert the change and restore theifstatement, bringing us back to the current implementation.
Quoted 2 lines
... such a change was made. Imo you have two choices: Deal with the issue properly right away, keeping the
if().
So then my fix will look like as embed struct irqaction as the first member of struct irq_guest and allocate them as one block. Then xvfree(action) inside release_irq() (gated by the still-meaningful if (action->free_on_release)) frees the whole thing - no separate xvfree(info) needed anywhere, so the dangling pointer can't happen regardless of what free_on_release is:
$ git diff
xen/arch/riscv/irq.c +20 -11
@@ -19,9 +19,18 @@#include <asm/hardirq.h> #include <asm/intc.h> -/* Describe an IRQ assigned to a guest */ +/* +* Describe an IRQ assigned to a guest. +* +* The irqaction is embedded here (rather than allocated separately with +* its dev_id pointing at a standalone struct irq_guest) so that freeing +* the action in release_irq() also frees this whole structure in one go. +* That avoids the alternative of release_irq()'s caller having to free +* dev_id itself (something like in Arm release_guest_irq()). +*/ struct irq_guest { +struct irqaction action;struct domain *d;unsigned int virq; };
@@ -345,7 +354,6 @@ int release_guest_irq(struct domain *d, unsigned int virq)spin_unlock_irqrestore (&desc->lock, flags);release_irq (desc->irq, info); -xvfree (info);return 0 ;
@@ -369,20 +377,23 @@ int route_irq_to_guest(struct domain *d, unsigned int virq, desc =irq_to_desc (irq); - action = xvmalloc(struct irqaction); -if ( !action ) -return -ENOMEM ; +/* +* release_irq() frees this action via xvfree(), relying on action +* being the first member of struct irq_guest so that &info->action +* coincides with info itself. Guard the layout so a future field +* reorder can't silently turn that into a free() of a mid-allocation +* pointer. +*/ +BUILD_BUG_ON (offsetof(struct irq_guest , action) !=0 ); info = xvmalloc(struct irq_guest);if ( !info ) - { -xvfree (action);return -ENOMEM ; - } info->d = d; info->virq = virq; + action = &info->action; action->dev_id = info; action->name = devname; action->free_on_release = true;
@@ -436,15 +447,13 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,if ( retval ) {release_irq (desc->irq, info); - goto free_info; +return retval; }return 0 ; out:spin_unlock_irqrestore (&desc->lock, flags); -xvfree (action); - free_info:xvfree (info);return retval;
Also, with such approach release_guest_irq() could be dropped at all, at least for now.
Does this approach look good?
Or assume "free_on_release" is only
Quoted 2 lines
ever true, and add an assertion to this effect (indicating that code needs auditing if that assumption is broken).
I think I'm okay with using ASSERT() instead of the changes suggested above.
What I don't understand is why you think it would be better to put the ASSERT() in release_irq() instead of keeping the if():
```
...
if ( action->free_on_release )
xvfree(action);
}
```As I understand it, the dangling pointer problem would only occur if someone started statically allocating guest interrupts, right? At least for now, all guest interrupts are heap-allocated by route_irq_to_guest().
So my understanding is that we want to ensure that nobody starts statically allocating guest interrupts in the future. If that's the case, wouldn't it make more sense to add the ASSERT() to release_guest_irq(), somewhere before xvfree(info); rather than to release_irq()?
~ Oleksii