x86: make CPU virtualisation support configurable
v6 cover x86: make CPU virtualisation support configurable
These are final 3 patches of the series for making VMX/SVM support in Xen configurable:
https://lore.kernel.org/xen-devel/[email protected]/
Minor changes comparing to v5, changelogs are provided per-patch.
-Sergiy
Sergiy Kibrik (1):
x86/vmx: guard access to cpu_has_vmx_* in common code
Xenia Ragiadakou (2):
ioreq: do not build arch_vcpu_ioreq_completion() for non-VMX
configurations
x86/hvm: make AMD-V and Intel VT-x support configurable
xen/Kconfig | 6 ++ xen/arch/arm/ioreq.c | 6 -- xen/arch/x86/Kconfig | 19 +++++- xen/arch/x86/hvm/ioreq.c | 2 + xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 90 ++++++++++++++++--------- xen/include/xen/ioreq.h | 10 +++ 6 files changed, 95 insertions(+), 38 deletions(-)
Signature · 1 line
2.25.1
PATCH v6 1/3 x86/vmx: guard access to cpu_has_vmx_* in common code
There're several places in common code, outside of arch/x86/hvm/vmx, where cpu_has_vmx_* get accessed without checking whether VMX supported first. These macros rely on global variables defined in vmx code, so when VMX support is disabled accesses to these variables turn into build failures.
To overcome these failures, build-time check is done before accessing global variables, so that DCE would remove these variables.
---
changes in v6:
- guard all of cpu_has_vmx_* macros
changes in v5:
- change kconfig option name VMX -> INTEL_VMX
- do not change .c files, only modify macros in vmcs.h
changes in v4:
- use IS_ENABLED(CONFIG_VMX) instead of using_vmx
--- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 90 ++++++++++++++++--------- 1 file changed, 60 insertions(+), 30 deletions(-)
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +60 -30
@@ -298,69 +298,99 @@ extern u64 vmx_ept_vpid_cap;#define VMX_TSC_MULTIPLIER_MAX 0xffffffffffffffffULL#define cpu_has_wbinvd_exiting \ - (vmx_secondary_exec_control & SECONDARY_EXEC_WBINVD_EXITING) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_WBINVD_EXITING)#define cpu_has_vmx_virtualize_apic_accesses \ - (vmx_secondary_exec_control & SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES)#define cpu_has_vmx_tpr_shadow \ - (vmx_cpu_based_exec_control & CPU_BASED_TPR_SHADOW) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_cpu_based_exec_control & CPU_BASED_TPR_SHADOW)#define cpu_has_vmx_vnmi \ - (vmx_pin_based_exec_control & PIN_BASED_VIRTUAL_NMIS) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_pin_based_exec_control & PIN_BASED_VIRTUAL_NMIS)#define cpu_has_vmx_msr_bitmap \ - (vmx_cpu_based_exec_control & CPU_BASED_ACTIVATE_MSR_BITMAP) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_cpu_based_exec_control & CPU_BASED_ACTIVATE_MSR_BITMAP)#define cpu_has_vmx_secondary_exec_control \ - (vmx_cpu_based_exec_control & CPU_BASED_ACTIVATE_SECONDARY_CONTROLS) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_cpu_based_exec_control & CPU_BASED_ACTIVATE_SECONDARY_CONTROLS)#define cpu_has_vmx_tertiary_exec_control \ - (vmx_cpu_based_exec_control & CPU_BASED_ACTIVATE_TERTIARY_CONTROLS) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_cpu_based_exec_control & CPU_BASED_ACTIVATE_TERTIARY_CONTROLS)#define cpu_has_vmx_ept \ - (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_EPT) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_EPT)#define cpu_has_vmx_dt_exiting \ - (vmx_secondary_exec_control & SECONDARY_EXEC_DESCRIPTOR_TABLE_EXITING) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_DESCRIPTOR_TABLE_EXITING)#define cpu_has_vmx_rdtscp \ - (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_RDTSCP) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_RDTSCP)#define cpu_has_vmx_vpid \ - (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_VPID) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_VPID)#define cpu_has_monitor_trap_flag \ - (vmx_cpu_based_exec_control & CPU_BASED_MONITOR_TRAP_FLAG) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_cpu_based_exec_control & CPU_BASED_MONITOR_TRAP_FLAG)#define cpu_has_vmx_pat \ - (vmx_vmentry_control & VM_ENTRY_LOAD_GUEST_PAT) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_vmentry_control & VM_ENTRY_LOAD_GUEST_PAT)#define cpu_has_vmx_efer \ - (vmx_vmentry_control & VM_ENTRY_LOAD_GUEST_EFER) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_vmentry_control & VM_ENTRY_LOAD_GUEST_EFER)#define cpu_has_vmx_unrestricted_guest \ - (vmx_secondary_exec_control & SECONDARY_EXEC_UNRESTRICTED_GUEST) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_UNRESTRICTED_GUEST)#define vmx_unrestricted_guest (v) \ ((v)->arch.hvm.vmx.secondary_exec_control & \ SECONDARY_EXEC_UNRESTRICTED_GUEST)#define cpu_has_vmx_ple \ - (vmx_secondary_exec_control & SECONDARY_EXEC_PAUSE_LOOP_EXITING) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_PAUSE_LOOP_EXITING)#define cpu_has_vmx_invpcid \ - (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_INVPCID) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_INVPCID)#define cpu_has_vmx_apic_reg_virt \ - (vmx_secondary_exec_control & SECONDARY_EXEC_APIC_REGISTER_VIRT) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_APIC_REGISTER_VIRT)#define cpu_has_vmx_virtual_intr_delivery \ - (vmx_secondary_exec_control & SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY)#define cpu_has_vmx_virtualize_x2apic_mode \ - (vmx_secondary_exec_control & SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE)#define cpu_has_vmx_posted_intr_processing \ - (vmx_pin_based_exec_control & PIN_BASED_POSTED_INTERRUPT) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_pin_based_exec_control & PIN_BASED_POSTED_INTERRUPT)#define cpu_has_vmx_vmcs_shadowing \ - (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_VMCS_SHADOWING) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_VMCS_SHADOWING)#define cpu_has_vmx_vmfunc \ - (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_VM_FUNCTIONS) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_VM_FUNCTIONS)#define cpu_has_vmx_virt_exceptions \ - (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS)#define cpu_has_vmx_pml \ - (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_PML) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_PML)#define cpu_has_vmx_mpx \ - ((vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) && \ + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + (vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) && \ (vmx_vmentry_control & VM_ENTRY_LOAD_BNDCFGS))#define cpu_has_vmx_xsaves \ - (vmx_secondary_exec_control & SECONDARY_EXEC_XSAVES) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_XSAVES)#define cpu_has_vmx_tsc_scaling \ - (vmx_secondary_exec_control & SECONDARY_EXEC_TSC_SCALING) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_TSC_SCALING)#define cpu_has_vmx_bus_lock_detection \ - (vmx_secondary_exec_control & SECONDARY_EXEC_BUS_LOCK_DETECTION) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_BUS_LOCK_DETECTION)#define cpu_has_vmx_notify_vm_exiting \ - (vmx_secondary_exec_control & SECONDARY_EXEC_NOTIFY_VM_EXITING) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_NOTIFY_VM_EXITING)#define VMCS_RID_TYPE_MASK 0x80000000U
Signature · 1 line
2.25.1
PATCH v6 2/3 ioreq: do not build arch_vcpu_ioreq_completion() for non-VMX configurations
In reply to Sergiy KibrikFrom: Xenia Ragiadakou <[email protected]>
VIO_realmode_completion is specific to vmx realmode and thus the function arch_vcpu_ioreq_completion() has actual handling work only in VMX-enabled build, as for the rest x86 and ARM build configurations it is basically a stub.
Here a separate configuration option ARCH_IOREQ_COMPLETION introduced that tells whether the platform we're building for requires any specific ioreq completion handling. As of now only VMX has such requirement, so the option is selected by INTEL_VMX, for other configurations a generic default stub is provided (it is ARM's version of arch_vcpu_ioreq_completion() moved to common header).
---
changes in v6:
- rename option ARCH_IOREQ_COMPLETION -> ARCH_VCPU_IOREQ_COMPLETION
- put a comment with brief option's description
changes in v5:
- introduce ARCH_IOREQ_COMPLETION option & put arch_vcpu_ioreq_completion() under it
- description changed
changes in v4:
- move whole arch_vcpu_ioreq_completion() under CONFIG_VMX and remove ARM's variant of this handler, as Julien suggested
--- xen/Kconfig | 6 ++++++ xen/arch/arm/ioreq.c | 6 ------ xen/arch/x86/Kconfig | 1 + xen/arch/x86/hvm/ioreq.c | 2 ++ xen/include/xen/ioreq.h | 10 ++++++++++ 5 files changed, 19 insertions(+), 6 deletions(-)
xen/Kconfig +6 -0
@@ -95,4 +95,10 @@ config LTO config ARCH_SUPPORTS_INT128 bool +# +# For platforms that require specific handling of ioreq completion events +# +config ARCH_VCPU_IOREQ_COMPLETION + bool + source "Kconfig.debug"
xen/arch/arm/ioreq.c +0 -6
@@ -135,12 +135,6 @@ bool arch_ioreq_complete_mmio(void)return false; } -bool arch_vcpu_ioreq_completion (enum vio_completion completion) -{ -ASSERT_UNREACHABLE (); -return true; -} -/* * The "legacy" mechanism of mapping magic pages for the IOREQ servers * is x86 specific, so the following hooks don't need to be implemented on Arm:
xen/arch/x86/Kconfig +1 -0
@@ -127,6 +127,7 @@ config AMD_SVM config INTEL_VMX def_bool HVM + select ARCH_VCPU_IOREQ_COMPLETION config XEN_SHSTK bool "Supervisor Shadow Stacks"
xen/arch/x86/hvm/ioreq.c +2 -0
@@ -29,6 +29,7 @@ bool arch_ioreq_complete_mmio(void)return handle_mmio (); } +#ifdef CONFIG_VCPU_ARCH_IOREQ_COMPLETION bool arch_vcpu_ioreq_completion (enum vio_completion completion) { switch ( completion )
@@ -51,6 +52,7 @@ bool arch_vcpu_ioreq_completion(enum vio_completion completion) return true; } +#endif static gfn_t hvm_alloc_legacy_ioreq_gfn (struct ioreq_server *s) {
xen/include/xen/ioreq.h +10 -0
@@ -111,7 +111,17 @@ void ioreq_domain_init(struct domain *d);int ioreq_server_dm_op (struct xen_dm_op *op,struct domain *d,bool *const_op);bool arch_ioreq_complete_mmio (void ); + +#ifdef CONFIG_VCPU_ARCH_IOREQ_COMPLETION bool arch_vcpu_ioreq_completion (enum vio_completion completion); +#else +static inline bool arch_vcpu_ioreq_completion (enum vio_completion completion) +{ +ASSERT_UNREACHABLE (); +return true; +} +#endif +int arch_ioreq_server_map_pages (struct ioreq_server *s);void arch_ioreq_server_unmap_pages (struct ioreq_server *s);void arch_ioreq_server_enable (struct ioreq_server *s);
Signature · 1 line
2.25.1
PATCH v6 3/3 x86/hvm: make AMD-V and Intel VT-x support configurable
In reply to Sergiy KibrikFrom: Xenia Ragiadakou <[email protected]>
Provide the user with configuration control over the cpu virtualization support in Xen by making AMD_SVM and INTEL_VMX options user selectable.
To preserve the current default behavior, both options depend on HVM and default to value of HVM.
To prevent users from unknowingly disabling virtualization support, make the controls user selectable only if EXPERT is enabled.
No functional change intended.
---
changes in v6:
- "default y" instead of "default HVM"
changes in v5:
- change kconfig option name SVM/VMX -> AMD_SVM/INTEL_VMX changes in v3:
- only tags added
--- xen/arch/x86/Kconfig | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
xen/arch/x86/Kconfig +16 -2
@@ -123,11 +123,25 @@ config HVM If unsure, say Y. config AMD_SVM - def_bool HVM + bool "AMD-V" if EXPERT + depends on HVM + default y + help + Enables virtual machine extensions on platforms that implement the + AMD Virtualization Technology (AMD-V). + If your system includes a processor with AMD-V support, say Y. + If in doubt, say Y. config INTEL_VMX - def_bool HVM + bool "Intel VT-x" if EXPERT + depends on HVM + default y select ARCH_VCPU_IOREQ_COMPLETION + help + Enables virtual machine extensions on platforms that implement the + Intel Virtualization Technology (Intel VT-x). + If your system includes a processor with Intel VT-x support, say Y. + If in doubt, say Y. config XEN_SHSTK bool "Supervisor Shadow Stacks"
Signature · 1 line
2.25.1
Re: [XEN PATCH v6 1/3] x86/vmx: guard access to cpu_has_vmx_* in common code
In reply to Sergiy KibrikQuoted 10 lines · Sergiy Kibrik
There're several places in common code, outside of
arch/x86/hvm/vmx, where cpu_has_vmx_* get accessed without checking whether VMX supported first. These macros rely on global variables defined in vmx code, so when VMX support is disabled accesses to these variables turn into build failures.To overcome these failures, build-time check is done before accessing global variables, so that DCE would remove these variables.
Signed-off-by Sergiy Kibrik <[email protected]>Acked-by Paul Durrant <[email protected]>
I can accept this is being kind of complete, so
Howver, ...
Quoted 3 lines
---
changes in v6:
- guard all of cpu_has_vmx_* macros
... this clearly isn't the case. For one ...
xen/arch/x86/include/asm/hvm/vmx/vmcs.h extern u64 vmx_ept_vpid_cap; · line 302
Quoted 9 lines
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +2
-1@@ -298,69 +298,99 @@ extern u64 vmx_ept_vpid_cap;#define VMX_TSC_MULTIPLIER_MAX 0xffffffffffffffffULL#define cpu_has_wbinvd_exiting \ - (vmx_secondary_exec_control & SECONDARY_EXEC_WBINVD_EXITING) + (IS_ENABLED(CONFIG_INTEL_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_WBINVD_EXITING)
... a few lines up from here there is cpu_has_vmx_virt_spec_ctrl. And there are quite a few more in vmx.h (don't ask me why things are split like this). Yet on the grounds that at least this one block of code now is consistent, I think we can leave further adjustments to possible later commits.
Jan
Re: [XEN PATCH v6 2/3] ioreq: do not build arch_vcpu_ioreq_completion() for non-VMX configurations
In reply to Sergiy KibrikQuoted 7 lines · Sergiy Kibrik
From: Xenia Ragiadakou <[email protected]>
VIO_realmode_completionis specific to vmx realmode and thus the functionarch_vcpu_ioreq_completion()has actual handling work only in VMX-enabled build, as for the rest x86 and ARM build configurations it is basically a stub.Here a separate configuration option
ARCH_IOREQ_COMPLETIONintroduced that tells
Nit: The rename of the option wants to be reflected here, too.
xen/Kconfig config LTO · line 102
Quoted 11 lines
xen/Kconfig +5
-0@@ -95,4 +95,10 @@ config LTO config ARCH_SUPPORTS_INT128 bool +# +# For platforms that require specific handling of ioreq completion events +# +config ARCH_VCPU_IOREQ_COMPLETION + bool
If already you add a comment here, then it similarly wants to disambiguate things by saying "per-vCPU ioreq completion events" or something along these lines.
Quoted 5 lines
xen/include/xen/ioreq.h +0
-0@@ -111,7 +111,17 @@ void ioreq_domain_init(struct domain *d);int ioreq_server_dm_op (struct xen_dm_op *op,struct domain *d,bool *const_op);
xen/include/xen/ioreq.h void ioreq_domain_init(struct domain *d); · line 122
Quoted 10 lines
xen/include/xen/ioreq.h +8
-0bool arch_ioreq_complete_mmio (void ); + +#ifdef CONFIG_VCPU_ARCH_IOREQ_COMPLETION bool arch_vcpu_ioreq_completion (enum vio_completion completion); +#else +static inline bool arch_vcpu_ioreq_completion (enum vio_completion completion) +{ +ASSERT_UNREACHABLE (); +return true; +}
My prior comment here remains: Despite pre-existing behavior being to return "true" here, I question that to be in line with coding-best-practices.pandoc. Imo the generalization of the stub is a good opportunity to adjust that. But yes, it could also be done in a separate change. If you really don't want to do so right here, then
with the two cosmetic adjustments (which likely could also be done while committing).
Jan
Re: [XEN PATCH v6 2/3] ioreq: do not build arch_vcpu_ioreq_completion() for non-VMX configurations
13.08.24 10:31, Jan Beulich:
Quoted 20 lines
Quoted 5 lines
xen/include/xen/ioreq.h +0
-0@@ -111,7 +111,17 @@ void ioreq_domain_init(struct domain *d);int ioreq_server_dm_op (struct xen_dm_op *op,struct domain *d,bool *const_op);xen/include/xen/ioreq.h void ioreq_domain_init(struct domain *d); · line 122
Quoted 10 lines
xen/include/xen/ioreq.h +8
-0bool arch_ioreq_complete_mmio (void ); + +#ifdef CONFIG_VCPU_ARCH_IOREQ_COMPLETION bool arch_vcpu_ioreq_completion (enum vio_completion completion); +#else +static inline bool arch_vcpu_ioreq_completion (enum vio_completion completion) +{ +ASSERT_UNREACHABLE (); +return true; +}My prior comment here remains: Despite pre-existing behavior being to return "true" here, I question that to be in line with coding-best-practices.pandoc. Imo the generalization of the stub is a good opportunity to adjust that. But yes, it could also be done in a separate change. If you really don't want to do so right here, then
Quoted 3 lines
Acked-by Jan Beulich<[email protected]>with the two cosmetic adjustments (which likely could also be done while committing).
I'm inclined to do a separate patch, that changes return value of arch_vcpu_ioreq_completion() depending on completion being handled on not. Such change has little to do with this patch series, and also probably should have its own separate discussion.
-Sergiy