xen/domain: updates to hardware emulation flags
Subsystems (2)
cover xen/domain: updates to hardware emulation flags
The patch series introduces use of d->arch.emulation_flags for non-x86 platforms (patch 1) and hooks emulation_flags to 'q' keyhandler for debugging. emulation_flags on non-x86 systems will be used in the follow on virtual UARTs clean up series.
Also, series adds helper macros (patch 2) which are used in re-write of emulation_flags_ok() on x86 (patch 3, depends on patch 2).
Originally, the code was part of [1], part of NS16550 emulator v3 series.
[1] https://lore.kernel.org/xen-devel/[email protected]/
[2] Link to CI run: https://gitlab.com/xen-project/people/dmukhin/xen/-/pipelines/1745622772
Denis Mukhin (3):
xen/domain: introduce non-x86 hardware emulation flags x86/domain: add helpers to simplify emulation flags management xen/domain: rewrite emulation_flags_ok()
tools/python/xen/lowlevel/xc/xc.c | 4 +--- xen/arch/arm/include/asm/domain.h | 2 ++ xen/arch/ppc/include/asm/domain.h | 2 ++ xen/arch/riscv/include/asm/domain.h | 2 ++ xen/arch/x86/domain.c | 29 +++++++++++------------------ xen/arch/x86/include/asm/domain.h | 2 +- xen/common/keyhandler.c | 1 + xen/include/public/arch-x86/xen.h | 7 +++++++ 8 files changed, 27 insertions(+), 22 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/3 xen/domain: introduce non-x86 hardware emulation flags
From: Denis Mukhin <[email protected]>
Define per-architecture emulation_flags for configuring in-hypervisor emulators.
Print d->arch.emulation_flags from 'q' keyhandler for better traceability while debugging in-hypervisor hardware emulators.
Simplify the x86's emulation_flags description and make it consistent with newly introduced non-x86 descriptions.
--- xen/arch/arm/include/asm/domain.h | 2 ++ xen/arch/ppc/include/asm/domain.h | 2 ++ xen/arch/riscv/include/asm/domain.h | 2 ++ xen/arch/x86/include/asm/domain.h | 2 +- xen/common/keyhandler.c | 1 + 5 files changed, 8 insertions(+), 1 deletion(-)
xen/arch/arm/include/asm/domain.h +2 -0
@@ -119,6 +119,8 @@ struct arch_domainvoid *tee;#endif +/* Hardware emulation flags. */ +uint32_t emulation_flags; } __cacheline_aligned;struct arch_vcpu
xen/arch/ppc/include/asm/domain.h +2 -0
@@ -21,6 +21,8 @@ struct arch_vcpu {struct arch_domain {struct hvm_domain hvm; +/* Hardware emulation flags. */ +uint32_t emulation_flags; };#include <xen/sched.h>
xen/arch/riscv/include/asm/domain.h +2 -0
@@ -18,6 +18,8 @@ struct arch_vcpu {struct arch_domain {struct hvm_domain hvm; +/* Hardware emulation flags. */ +uint32_t emulation_flags; };#include <xen/sched.h>
xen/arch/x86/include/asm/domain.h +1 -1
@@ -456,7 +456,7 @@ struct arch_domain/* Don't unconditionally inject #GP for unhandled MSRs. */ bool msr_relaxed; -/* Emulated devices enabled bitmap. */ +/* Hardware emulation flags. */ uint32_t emulation_flags; } __cacheline_aligned;
xen/common/keyhandler.c +1 -0
@@ -306,6 +306,7 @@ static void cf_check dump_domains(unsigned char key)if (test_bit (i, &d->watchdog_inuse_map) )printk (" watchdog %d expires in %d seconds\n" , i, (u32)((d->watchdog_timer[i].expires -NOW ()) >>30 )); +printk (" emulation_flags %#x\n" , d->arch.emulation_flags);arch_dump_domain_info (d);
Signature · 1 line
2.34.1
PATCH 2/3 x86/domain: add helpers to simplify emulation flags management
In reply to [email protected]From: Denis Mukhin <[email protected]>
Introduce XEN_X86_EMU_BASELINE and XEN_X86_EMU_OPTIONAL to simplify d->arch.emulation_flags management in the code.
--- tools/python/xen/lowlevel/xc/xc.c | 4 +--- xen/include/public/arch-x86/xen.h | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-)
tools/python/xen/lowlevel/xc/xc.c +1 -3
@@ -159,9 +159,7 @@ static PyObject *pyxc_domain_create(XcObject *self,#if defined (__i386) || defined(__x86_64__)if ( config.flags & XEN_DOMCTL_CDF_hvm ) - config.arch.emulation_flags =XEN_X86_EMU_ALL & - ~(XEN_X86_EMU_VPCI | -XEN_X86_EMU_USE_PIRQ ); + config.arch.emulation_flags =XEN_X86_EMU_BASELINE ;#elif defined (__arm__) || defined(__aarch64__) config.arch.gic_version =XEN_DOMCTL_CONFIG_GIC_NATIVE ;#else
xen/include/public/arch-x86/xen.h +7 -0
@@ -290,6 +290,13 @@ struct xen_arch_domainconfig { XEN_X86_EMU_VGA | XEN_X86_EMU_IOMMU | \ XEN_X86_EMU_PIT | XEN_X86_EMU_USE_PIRQ |\ XEN_X86_EMU_VPCI) + +#define XEN_X86_EMU_OPTIONAL (XEN_X86_EMU_VPCI | \ + XEN_X86_EMU_USE_PIRQ) + +#define XEN_X86_EMU_BASELINE (XEN_X86_EMU_ALL & ~XEN_X86_EMU_OPTIONAL) + +/* Hardware emulation flags. */ uint32_t emulation_flags;/*
Signature · 1 line
2.34.1
Re: [PATCH v1 2/3] x86/domain: add helpers to simplify emulation flags management
Quoted 4 lines · On 01.04.2025 02:52, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Introduce
XEN_X86_EMU_BASELINEandXEN_X86_EMU_OPTIONALto simplifyd->arch.emulation_flagsmanagement in the code.
If the simplification is limited to ...
tools/python/xen/lowlevel/xc/xc.c static PyObject *pyxc_domain_create(XcObject *self, · line 165
Quoted 13 lines
tools/python/xen/lowlevel/xc/xc.c +1
-3@@ -159,9 +159,7 @@ static PyObject *pyxc_domain_create(XcObject *self,#if defined (__i386) || defined(__x86_64__)if ( config.flags & XEN_DOMCTL_CDF_hvm ) - config.arch.emulation_flags =XEN_X86_EMU_ALL & - ~(XEN_X86_EMU_VPCI | -XEN_X86_EMU_USE_PIRQ ); + config.arch.emulation_flags =XEN_X86_EMU_BASELINE ;#elif defined (__arm__) || defined(__aarch64__) config.arch.gic_version =XEN_DOMCTL_CONFIG_GIC_NATIVE ;#else
... just this, I'm not convinced that's worth introducing yet two more items into the namespace.
Quoted 4 lines
xen/include/public/arch-x86/xen.h +0
-0@@ -290,6 +290,13 @@ struct xen_arch_domainconfig { XEN_X86_EMU_VGA | XEN_X86_EMU_IOMMU | \
xen/include/public/arch-x86/xen.h struct xen_arch_domainconfig { · line 300
Quoted 10 lines
xen/include/public/arch-x86/xen.h +7
-0XEN_X86_EMU_PIT | XEN_X86_EMU_USE_PIRQ |\ XEN_X86_EMU_VPCI) + +#define XEN_X86_EMU_OPTIONAL (XEN_X86_EMU_VPCI | \ + XEN_X86_EMU_USE_PIRQ) + +#define XEN_X86_EMU_BASELINE (XEN_X86_EMU_ALL & ~XEN_X86_EMU_OPTIONAL) + +/* Hardware emulation flags. */ uint32_t emulation_flags;
The comment isn't quite accurate here (and hence perhaps also not in the earlier patch): XEN_X86_EMU_USE_PIRQ isn't exactly about emulation of anything hardware-ish.
Jan
Re: [PATCH v1 2/3] x86/domain: add helpers to simplify emulation flags management
Quoted 12 lines · Jan Beulich
Quoted 4 lines · On 01.04.2025 02:52, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Introduce
XEN_X86_EMU_BASELINEandXEN_X86_EMU_OPTIONALto simplifyd->arch.emulation_flagsmanagement in the code.If the simplification is limited to ...
Quoted 4 lines
tools/python/xen/lowlevel/xc/xc.c +0
-0@@ -159,9 +159,7 @@ static PyObject *pyxc_domain_create(XcObject *self,
Quoted 12 lines
tools/python/xen/lowlevel/xc/xc.c static PyObject *pyxc_domain_create(XcObject *self, · line 165
Quoted 9 lines
tools/python/xen/lowlevel/xc/xc.c +1
-3#if defined (__i386) || defined(__x86_64__)if ( config.flags & XEN_DOMCTL_CDF_hvm ) - config.arch.emulation_flags =XEN_X86_EMU_ALL & - ~(XEN_X86_EMU_VPCI | -XEN_X86_EMU_USE_PIRQ ); + config.arch.emulation_flags =XEN_X86_EMU_BASELINE ;#elif defined (__arm__) || defined(__aarch64__) config.arch.gic_version =XEN_DOMCTL_CONFIG_GIC_NATIVE ;#else ... just this, I'm not convinced that's worth introducing yet two more items into the namespace.
Sorry, it took me a while to get back to the series.
The X86_EMU_BASELINE mask is used in two places: in the toolstack (xc.c) and in domain.c, emulation_flags_ok(), so adding a new flag may require updates in two places.
Perhaps it will be better to merge this patch 2 with patch 3 to highlight that?
Quoted 21 lines
Quoted 5 lines
xen/include/public/arch-x86/xen.h +0
-0@@ -290,6 +290,13 @@ struct xen_arch_domainconfig { XEN_X86_EMU_VGA | XEN_X86_EMU_IOMMU | \xen/include/public/arch-x86/xen.h struct xen_arch_domainconfig { · line 300
Quoted 10 lines
xen/include/public/arch-x86/xen.h +7
-0XEN_X86_EMU_PIT | XEN_X86_EMU_USE_PIRQ |\ XEN_X86_EMU_VPCI) + +#define XEN_X86_EMU_OPTIONAL (XEN_X86_EMU_VPCI | \ + XEN_X86_EMU_USE_PIRQ) + +#define XEN_X86_EMU_BASELINE (XEN_X86_EMU_ALL & ~XEN_X86_EMU_OPTIONAL) + +/* Hardware emulation flags. */ uint32_t emulation_flags;The comment isn't quite accurate here (and hence perhaps also not in the earlier patch):
XEN_X86_EMU_USE_PIRQisn't exactly about emulation of anything hardware-ish.Jan
Re: [PATCH v1 2/3] x86/domain: add helpers to simplify emulation flags management
Quoted 26 lines · On 23.04.2025 00:49, [email protected] wrote:
Quoted 12 lines · Jan Beulich
Quoted 4 lines · On 01.04.2025 02:52, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Introduce
XEN_X86_EMU_BASELINEandXEN_X86_EMU_OPTIONALto simplifyd->arch.emulation_flagsmanagement in the code.If the simplification is limited to ...
Quoted 4 lines
tools/python/xen/lowlevel/xc/xc.c +0
-0@@ -159,9 +159,7 @@ static PyObject *pyxc_domain_create(XcObject *self,Quoted 12 lines
tools/python/xen/lowlevel/xc/xc.c static PyObject *pyxc_domain_create(XcObject *self, · line 165
Quoted 9 lines
tools/python/xen/lowlevel/xc/xc.c +1
-3#if defined (__i386) || defined(__x86_64__)if ( config.flags & XEN_DOMCTL_CDF_hvm ) - config.arch.emulation_flags =XEN_X86_EMU_ALL & - ~(XEN_X86_EMU_VPCI | -XEN_X86_EMU_USE_PIRQ ); + config.arch.emulation_flags =XEN_X86_EMU_BASELINE ;#elif defined (__arm__) || defined(__aarch64__) config.arch.gic_version =XEN_DOMCTL_CONFIG_GIC_NATIVE ;#else ... just this, I'm not convinced that's worth introducing yet two more items into the namespace.
Quoted 5 lines
Sorry, it took me a while to get back to the series.
The
X86_EMU_BASELINEmask is used in two places: in the toolstack (xc.c) and indomain.c,emulation_flags_ok(), so adding a new flag may require updates in two places.
Which may be even desirable in this case, so effects can be properly considered at both sites. I wouldn't take it for given that the two will forever need to stay in full sync.
Jan
PATCH 3/3 xen/domain: rewrite emulation_flags_ok()
In reply to [email protected]From: Denis Mukhin <[email protected]>
Rewrite emulation_flags_ok() using XEN_X86_EMU_{OPTIONAL,BASELINE} to simplify future modifications.
---
Came in the context of NS16550 emulator v3 series:
https://lore.kernel.org/xen-devel/[email protected]/
After modifying emulation_flags_ok() with a new NS16550 vUART configuration switch passed from the toolstack for the HVM case, I decided to look into how to improve emulation_flags_ok().
--- xen/arch/x86/domain.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-)
xen/arch/x86/domain.c +11 -18
@@ -750,25 +750,18 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)BUILD_BUG_ON (X86_EMU_ALL !=XEN_X86_EMU_ALL );#endif -if (is_hvm_domain (d) ) - { -if (is_hardware_domain (d) && - emflags != (X86_EMU_VPCI |X86_EMU_LAPIC |X86_EMU_IOAPIC ) ) -return false; -if ( !is_hardware_domain (d) && -/* HVM PIRQ feature is user-selectable. */ - (emflags & ~X86_EMU_USE_PIRQ ) != - (X86_EMU_ALL & ~(X86_EMU_VPCI |X86_EMU_USE_PIRQ )) && - emflags !=X86_EMU_LAPIC ) -return false; - } -else if ( emflags !=0 && emflags !=X86_EMU_PIT ) - { -/* PV or classic PVH. */ -return false; - } +/* PV or classic PVH */ +if ( !is_hvm_domain (d) ) +return emflags ==0 || emflags ==XEN_X86_EMU_PIT ; -return true; +/* HVM */ +if (is_hardware_domain (d) ) +return emflags == (XEN_X86_EMU_LAPIC | +XEN_X86_EMU_IOAPIC | +XEN_X86_EMU_VPCI ); + +return (emflags & ~XEN_X86_EMU_OPTIONAL ) ==XEN_X86_EMU_BASELINE || + emflags ==XEN_X86_EMU_LAPIC ; }void __init arch_init_idle_domain (struct domain *d)
Signature · 1 line
2.34.1
Re: [PATCH v1 3/3] xen/domain: rewrite emulation_flags_ok()
Quoted 10 lines · On 01.04.2025 02:52, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Rewrite
emulation_flags_ok()using XEN_X86_EMU_{OPTIONAL,BASELINE} to simplify future modifications.Signed-off-by Denis Mukhin <[email protected]>---
Came in the context of NS16550 emulator v3 series:
https://lore.kernel.org/xen-devel/[email protected]/
Quoted 6 lines
After modifying
emulation_flags_ok()with a new NS16550 vUART configuration switch passed from the toolstack for the HVM case, I decided to look into how to improveemulation_flags_ok().--- xen/arch/x86/domain.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-)
There is a readability win, yes.
Quoted 16 lines
xen/arch/x86/domain.c +0
-10@@ -750,25 +750,18 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)BUILD_BUG_ON (X86_EMU_ALL !=XEN_X86_EMU_ALL );#endif -if (is_hvm_domain (d) ) - { -if (is_hardware_domain (d) && - emflags != (X86_EMU_VPCI |X86_EMU_LAPIC |X86_EMU_IOAPIC ) ) -return false; -if ( !is_hardware_domain (d) && -/* HVM PIRQ feature is user-selectable. */ - (emflags & ~X86_EMU_USE_PIRQ ) != - (X86_EMU_ALL & ~(X86_EMU_VPCI |X86_EMU_USE_PIRQ )) && - emflags !=X86_EMU_LAPIC )
xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 755
Quoted 10 lines
xen/arch/x86/domain.c +3
-7-return false; - } -else if ( emflags !=0 && emflags !=X86_EMU_PIT ) - { -/* PV or classic PVH. */ -return false; - } +/* PV or classic PVH */ +if ( !is_hvm_domain (d) ) +return emflags ==0 || emflags ==XEN_X86_EMU_PIT ;
What's "classic PVH" here? This got to be PVHv1, which is dead. As you touch / move such a comment, you want to adjust it so it's at least no longer stale.
xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 764
Quoted 9 lines
xen/arch/x86/domain.c +8
-1-return true; +/* HVM */ +if (is_hardware_domain (d) ) +return emflags == (XEN_X86_EMU_LAPIC | +XEN_X86_EMU_IOAPIC | +XEN_X86_EMU_VPCI ); + +return (emflags & ~XEN_X86_EMU_OPTIONAL ) ==XEN_X86_EMU_BASELINE || + emflags ==XEN_X86_EMU_LAPIC ;
There was a comment about X86_EMU_USE_PIRQ being optional, which you've lost together with (only) that (i.e. not at the same time including vPCI) optionality.
Furthermore you move from X86_EMU_* namespace to XEN_X86_EMU_* one without even mentioning that (and the reason to do so) in the description. Aiui the function deliberately uses the internal names, not the public interface ones.
Jan
Re: [PATCH v1 3/3] xen/domain: rewrite emulation_flags_ok()
Quoted 41 lines · Jan Beulich
Quoted 10 lines · On 01.04.2025 02:52, [email protected] wrote:
From: Denis Mukhin <[email protected]>
Rewrite
emulation_flags_ok()using XEN_X86_EMU_{OPTIONAL,BASELINE} to simplify future modifications.Signed-off-by Denis Mukhin <[email protected]>---
Came in the context of NS16550 emulator v3 series:
https://lore.kernel.org/xen-devel/[email protected]/Quoted 6 lines
After modifying
emulation_flags_ok()with a new NS16550 vUART configuration switch passed from the toolstack for the HVM case, I decided to look into how to improveemulation_flags_ok().--- xen/arch/x86/domain.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-)There is a readability win, yes.
Quoted 21 lines
xen/arch/x86/domain.c +0
-15@@ -750,25 +750,18 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)BUILD_BUG_ON (X86_EMU_ALL !=XEN_X86_EMU_ALL );#endif -if (is_hvm_domain (d) ) - { -if (is_hardware_domain (d) && - emflags != (X86_EMU_VPCI |X86_EMU_LAPIC |X86_EMU_IOAPIC ) ) -return false; -if ( !is_hardware_domain (d) && -/* HVM PIRQ feature is user-selectable. */ - (emflags & ~X86_EMU_USE_PIRQ ) != - (X86_EMU_ALL & ~(X86_EMU_VPCI |X86_EMU_USE_PIRQ )) && - emflags !=X86_EMU_LAPIC ) -return false; - } -else if ( emflags !=0 && emflags !=X86_EMU_PIT ) - { -/* PV or classic PVH. */
Quoted 8 lines
xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 755
Quoted 5 lines
xen/arch/x86/domain.c +3
-2-return false; - } +/* PV or classic PVH */ +if ( !is_hvm_domain (d) ) +return emflags ==0 || emflags ==XEN_X86_EMU_PIT ;What's "classic PVH" here? This got to be PVHv1, which is dead. As you touch / move such a comment, you want to adjust it so it's at least no longer stale.
Looks like the comment should say "PV".
Quoted 19 lines
xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 764
Quoted 10 lines
xen/arch/x86/domain.c +8
-1-return true; +/* HVM */ +if (is_hardware_domain (d) ) +return emflags == (XEN_X86_EMU_LAPIC | +XEN_X86_EMU_IOAPIC | +XEN_X86_EMU_VPCI ); + +return (emflags & ~XEN_X86_EMU_OPTIONAL ) ==XEN_X86_EMU_BASELINE || + emflags ==XEN_X86_EMU_LAPIC ;There was a comment about
X86_EMU_USE_PIRQbeing optional, which you've lost together with (only) that (i.e. not at the same time including vPCI) optionality.Furthermore you move from X86_EMU_* namespace to XEN_X86_EMU_* one without even mentioning that (and the reason to do so) in the description. Aiui the function deliberately uses the internal names, not the public interface ones.
Jan