x86/cpu: Clean up handling of VMX features
Subsystems (9)
v4 cover x86/cpu: Clean up handling of VMX features
Clean up a handful of interrelated warts in the kernel's handling of VMX:
- Enable VMX in IA32_FEATURE_CONTROL during boot instead of on-demand during KVM load to avoid future contention over IA32_FEATURE_CONTROL.
- Rework VMX feature reporting so that it is accurate and up-to-date, now and in the future.
- Consolidate code across CPUs that support VMX.
This series stems from two separate but related issues. The first issue, pointed out by Boris in the SGX enabling series[1], is that the kernel currently doesn't ensure the IA32_FEATURE_CONTROL MSR is configured during boot. The second issue is that the kernel's reporting of VMX features is stale, potentially inaccurate, and difficult to maintain.
v4:
- Rebase to tip/master, 8a1b070333f4 ("Merge branch 'WIP.x86/mm'")
- Rename everything feature control related to IA32_FEAT_CTL. [Boris]
- Minor coding style tweaks [Boris and Jarkko].
- Print VMX feature flags in "vmx flags" to avoid polluting "flags", but keep printing the current synthetic VMX in "flags" so as not to break the ABI. [Boris]
- Don't bother printing an error message in the extremely unlikely event VMX is supported but IA32_FEAT_CTL doesn't exist. [Boris]
- Beef up a few changelogs and comments. [Boris]
- Add a comment in the LMCE code for the new WARN. [Jarkko]
- Check CONFIG_KVM_INTEL instead of CONFIG_KVM when deciding whether or not to enable VMX.
- Add a patch to introduce X86_FEATURE_MSR_IA32_FEAT_CTL.
- Dropped Jim's Reviewed-by from a few KVM patches due to the above addition.
v3:
- Rebase to tip/master, ceceaf1f12ba ("Merge branch 'WIP.x86/cleanups'").
- Rename the feature control MSR bit defines [Boris].
- Rewrite the error message displayed when reading feature control MSR faults on a VMX capable CPU to explicitly state that it's likely a hardware or hypervisor issue [Boris].
- Collect a Reviewed-by for the LMCE change [Boris].
- Enable VMX in feature control (if it's unlocked) if and only if KVM is enabled [Paolo].
- Remove a big pile of redudant MSR defines from the KVM selftests that was discovered when renaming the feature control defines.
- Fix a changelog typoe [Boris].
v2:
- Rebase to latest tip/x86/cpu (1edae1ae6258, "x86/Kconfig: Enforce...)
- Collect Jim's reviews.
- Fix a typo in setting of EPT capabilities [TonyWWang-oc].
- Remove defines for reserved VMX feature flags [Paolo].
- Print the VMX features under "flags" and maintain all existing names to be backward compatible with the ABI [Paolo].
- Create aggregate APIC features to report FLEXPRIORITY and APICV, so that the full feature *and* their associated individual features are printed, e.g. to aid in recognizing why an APIC feature isn't being used.
- Fix a few copy paste errors in changelogs.
v1 cover letter:
== IA32_FEATURE_CONTROL ==
Lack of IA32_FEATURE_CONTROL configuration during boot isn't a functional issue in the current kernel as the majority of platforms set and lock IA32_FEATURE_CONTROL in firmware. And when the MSR is left unlocked, KVM is the only subsystem that writes IA32_FEATURE_CONTROL. That will change if/when SGX support is enabled, as SGX will also want to fully enable itself when IA32_FEATURE_CONTROL is unlocked.
== VMX Feature Reporting ==
VMX features are not enumerated via CPUID, but instead are enumerated through VMX MSRs. As a result, new VMX features are not automatically reported via /proc/cpuinfo.
An attempt was made long ago to report interesting and/or meaningful VMX features by synthesizing select features into a Linux-defined cpufeatures word. Synthetic feature flags worked for the initial purpose, but the existence of the synthetic flags was forgotten almost immediately, e.g. only one new flag (EPT A/D) has been added in the the decade since the synthetic VMX features were introduced, while VMX and KVM have gained support for many new features.
Placing the synthetic flags in x86_capability also allows them to be queried via cpu_has() and company, which is misleading as the flags exist purely for reporting via /proc/cpuinfo. KVM, the only in-kernel user of VMX, ignores the flags.
Last but not least, VMX features are reported in /proc/cpuinfo even when VMX is unusable due to lack of enabling in IA32_FEATURE_CONTROL.
== Caveats ==
All of the testing of non-standard flows was done in a VM, as I don't have a system that leaves IA32_FEATURE_CONTROL unlocked, or locks it with VMX disabled.
The Centaur and Zhaoxin changes are somewhat speculative, as I haven't confirmed they actually support IA32_FEATURE_CONTROL, or that they want to gain "official" KVM support. I assume they unofficially support KVM given that both CPUs went through the effort of enumerating VMX features. That in turn would require them to support IA32_FEATURE_CONTROL since KVM will fault and refuse to load if the MSR doesn't exist.
[1] https://lkml.kernel.org/r/[email protected]
Sean Christopherson (19):
x86/msr-index: Clean up bit defines for IA32_FEATURE_CONTROL MSR
selftests: kvm: Replace manual MSR defs with common msr-index.h tools arch x86: Sync msr-index.h from kernel sources x86/intel: Initialize IA32_FEAT_CTL MSR at boot
x86/mce: WARN once if IA32_FEAT_CTL MSR is left unlocked x86/centaur: Use common IA32_FEAT_CTL MSR initialization x86/zhaoxin: Use common IA32_FEAT_CTL MSR initialization x86/cpu: Clear VMX feature flag if VMX is not fully enabled x86/vmx: Introduce VMX_FEATURES_*
x86/cpu: Detect VMX features on Intel, Centaur and Zhaoxin CPUs x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_* x86/cpu: Set synthetic VMX cpufeatures during init_ia32_feat_ctl() x86/cpufeatures: Add flag to track whether MSR IA32_FEAT_CTL is
configured
KVM: VMX: Drop initialization of IA32_FEAT_CTL MSR
KVM: VMX: Use VMX feature flag to query BIOS enabling
KVM: VMX: Check for full VMX support when verifying CPU compatibility
KVM: VMX: Use VMX_FEATURE_* flags to define VMCS control bits perf/x86: Provide stubs of KVM helpers for non-Intel CPUs
KVM: VMX: Allow KVM_INTEL when building for Centaur and/or Zhaoxin
CPUs
MAINTAINERS | 2 +- arch/x86/Kconfig.cpu | 8 + arch/x86/boot/mkcpustr.c | 1 + arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/msr-index.h | 14 +- arch/x86/include/asm/perf_event.h | 22 +- arch/x86/include/asm/processor.h | 4 + arch/x86/include/asm/vmx.h | 105 +-- arch/x86/include/asm/vmxfeatures.h | 86 +++ arch/x86/kernel/cpu/Makefile | 6 +- arch/x86/kernel/cpu/centaur.c | 35 +- arch/x86/kernel/cpu/common.c | 3 + arch/x86/kernel/cpu/cpu.h | 4 + arch/x86/kernel/cpu/feat_ctl.c | 140 ++++ arch/x86/kernel/cpu/intel.c | 49 +- arch/x86/kernel/cpu/mce/intel.c | 15 +- arch/x86/kernel/cpu/mkcapflags.sh | 15 +- arch/x86/kernel/cpu/proc.c | 15 + arch/x86/kernel/cpu/zhaoxin.c | 35 +- arch/x86/kvm/Kconfig | 10 +- arch/x86/kvm/vmx/nested.c | 4 +- arch/x86/kvm/vmx/vmx.c | 67 +- arch/x86/kvm/vmx/vmx.h | 2 +- arch/x86/kvm/x86.c | 2 +- tools/arch/x86/include/asm/msr-index.h | 30 +- tools/power/x86/turbostat/turbostat.c | 4 +- tools/testing/selftests/kvm/Makefile | 4 +- .../selftests/kvm/include/x86_64/processor.h | 726 +----------------- tools/testing/selftests/kvm/lib/x86_64/vmx.c | 8 +- 29 files changed, 431 insertions(+), 986 deletions(-) create mode 100644 arch/x86/include/asm/vmxfeatures.h create mode 100644 arch/x86/kernel/cpu/feat_ctl.c
Signature · 1 line
2.24.0
PATCH v4 1/19 x86/msr-index: Clean up bit defines for IA32_FEATURE_CONTROL MSR
As pointed out by Boris, the defines for bits in IA32_FEATURE_CONTROL are quite a mouthful, especially the VMX bits which must differentiate between enabling VMX inside and outside SMX (TXT) operation. Rename the MSR and its bit defines to abbreviate FEATURE_CONTROL as FEAT_CTL to make them a little friendlier on the eyes.
Arguably the MSR itself should keep the full IA32_FEATURE_CONTROL name to match Intel's SDM, but a future patch will add a dedicated Kconfig, file and functions for the MSR. Using the full name for those assets is rather unwieldy, so bite the bullet and use IA32_FEAT_CTL so that its nomenclature is consistent throughout the kernel.
Opportunistically fix a few other annoyances with the defines:
- Relocate the bit defines so that they immediately follow the MSR define, e.g. aren't mistaken as belonging to MISC_FEATURE_CONTROL.
- Add whitespace around the block of feature control defines to make it clear they're all related.
- Use BIT() instead of manually encoding the bit shift.
- Use "VMX" instead of "VMXON" to match the SDM.
- Append "_ENABLED" to the LMCE (Local Machine Check Exception) bit to be consistent with the kernel's verbiage used for all other feature control bits. Note, the SDM refers to the LMCE bit as LMCE_ON, likely to differentiate it from IA32_MCG_EXT_CTL.LMCE_EN. Ignore the (literal) one-off usage of _ON, the SDM is simply "wrong".
--- arch/x86/include/asm/msr-index.h | 14 +++++----- arch/x86/kernel/cpu/mce/intel.c | 10 +++---- arch/x86/kvm/vmx/nested.c | 4 +-- arch/x86/kvm/vmx/vmx.c | 46 ++++++++++++++++---------------- arch/x86/kvm/vmx/vmx.h | 2 +- arch/x86/kvm/x86.c | 2 +- 6 files changed, 40 insertions(+), 38 deletions(-)
arch/x86/include/asm/msr-index.h +8 -6
@@ -558,7 +558,14 @@#define MSR_IA32_EBL_CR_POWERON 0x0000002a#define MSR_EBC_FREQUENCY_ID 0x0000002c#define MSR_SMI_COUNT 0x00000034 -#define MSR_IA32_FEATURE_CONTROL 0x0000003a + +/* Referred to as IA32_FEATURE_CONTROL in Intel's SDM. */ +#define MSR_IA32_FEAT_CTL 0x0000003a +#define FEAT_CTL_LOCKED BIT(0) +#define FEAT_CTL_VMX_ENABLED_INSIDE_SMX BIT(1) +#define FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX BIT(2) +#define FEAT_CTL_LMCE_ENABLED BIT(20) +#define MSR_IA32_TSC_ADJUST 0x0000003b#define MSR_IA32_BNDCFGS 0x00000d90
@@ -566,11 +573,6 @@#define MSR_IA32_XSS 0x00000da0 -#define FEATURE_CONTROL_LOCKED (1<<0) -#define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX (1<<1) -#define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX (1<<2) -#define FEATURE_CONTROL_LMCE (1<<20) -#define MSR_IA32_APICBASE 0x0000001b#define MSR_IA32_APICBASE_BSP (1<<8)#define MSR_IA32_APICBASE_ENABLE (1<<11)
arch/x86/kernel/cpu/mce/intel.c +5 -5
@@ -115,12 +115,12 @@ static bool lmce_supported(void)/* * BIOS should indicate support for LMCE by setting bit 20 in -* IA32_FEATURE_CONTROL without which touching MCG_EXT_CTL will -* generate a #GP fault. +* IA32_FEAT_CTL without which touching MCG_EXT_CTL will generate a #GP +* fault. */ -rdmsrl (MSR_IA32_FEATURE_CONTROL , tmp); -if ((tmp & (FEATURE_CONTROL_LOCKED |FEATURE_CONTROL_LMCE )) == - (FEATURE_CONTROL_LOCKED |FEATURE_CONTROL_LMCE )) +rdmsrl (MSR_IA32_FEAT_CTL , tmp); +if ((tmp & (FEAT_CTL_LOCKED |FEAT_CTL_LMCE_ENABLED )) == + (FEAT_CTL_LOCKED |FEAT_CTL_LMCE_ENABLED ))return true;return false;
arch/x86/kvm/vmx/nested.c +2 -2
@@ -4588,8 +4588,8 @@ static int handle_vmon(struct kvm_vcpu *vcpu)gpa_t vmptr;uint32_t revision;struct vcpu_vmx *vmx =to_vmx (vcpu); -const u64 VMXON_NEEDED_FEATURES =FEATURE_CONTROL_LOCKED - |FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX ; +const u64 VMXON_NEEDED_FEATURES =FEAT_CTL_LOCKED + |FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX ;/* * The Intel VMX Instruction Reference lists a bunch of bits that are
arch/x86/kvm/vmx/vmx.c +23 -23
116 lines not on this page · raw message
arch/x86/kvm/vmx/vmx.h +1 -1
@@ -283,7 +283,7 @@ struct vcpu_vmx {/* * Only bits masked by msr_ia32_feature_control_valid_bits can be set in -* msr_ia32_feature_control. FEATURE_CONTROL_LOCKED is always included +* msr_ia32_feature_control. FEAT_CTL_LOCKED is always included * in msr_ia32_feature_control_valid_bits. */ u64 msr_ia32_feature_control;
arch/x86/kvm/x86.c +1 -1
@@ -1142,7 +1142,7 @@ static const u32 msrs_to_save_all[] = {MSR_CSTAR ,MSR_KERNEL_GS_BASE ,MSR_SYSCALL_MASK ,MSR_LSTAR , #endifMSR_IA32_TSC ,MSR_IA32_CR_PAT ,MSR_VM_HSAVE_PA , -MSR_IA32_FEATURE_CONTROL ,MSR_IA32_BNDCFGS ,MSR_TSC_AUX , +MSR_IA32_FEAT_CTL ,MSR_IA32_BNDCFGS ,MSR_TSC_AUX ,MSR_IA32_SPEC_CTRL ,MSR_IA32_RTIT_CTL ,MSR_IA32_RTIT_STATUS ,MSR_IA32_RTIT_CR3_MATCH , MSR_IA32_RTIT_OUTPUT_BASE, MSR_IA32_RTIT_OUTPUT_MASK,
Signature · 1 line
2.24.0
PATCH v4 3/19 tools arch x86: Sync msr-index.h from kernel sources
In reply to Sean ChristophersonSync msr-index.h to pull in recent renames of the IA32_FEATURE_CONTROL MSR definitions. Update KVM's VMX selftest and turbostat accordingly. Keep the full name in turbostat's output to avoid breaking someone's workflow, e.g. if a script is looking for the full name.
While using the renamed defines is by no means necessary, do the sync now to avoid leaving a landmine that will get stepped on the next time msr-index.h needs to be refreshed for some other reason.
No functional change intended.
--- tools/arch/x86/include/asm/msr-index.h | 30 ++++++++++++++++---- tools/power/x86/turbostat/turbostat.c | 4 +-- tools/testing/selftests/kvm/lib/x86_64/vmx.c | 8 +++--- 3 files changed, 30 insertions(+), 12 deletions(-)
tools/arch/x86/include/asm/msr-index.h +24 -6
@@ -93,6 +93,18 @@* Microarchitectural Data * Sampling (MDS) vulnerabilities. */ +#define ARCH_CAP_PSCHANGE_MC_NO BIT(6)/* +* The processor is not susceptible to a +* machine check error due to modifying the +* code page size along with either the +* physical address or cache type +* without TLB invalidation. +*/ +#define ARCH_CAP_TSX_CTRL_MSR BIT(7)/* MSR for TSX control is available. */ +#define ARCH_CAP_TAA_NO BIT(8)/* +* Not susceptible to +* TSX Async Abort (TAA) vulnerabilities. +*/ #define MSR_IA32_FLUSH_CMD 0x0000010b#define L1D_FLUSH BIT(0)/*
@@ -103,6 +115,10 @@#define MSR_IA32_BBL_CR_CTL 0x00000119#define MSR_IA32_BBL_CR_CTL3 0x0000011e +#define MSR_IA32_TSX_CTRL 0x00000122 +#define TSX_CTRL_RTM_DISABLE BIT(0)/* Disable RTM feature */ +#define TSX_CTRL_CPUID_CLEAR BIT(1)/* Disable TSX enumeration */ +#define MSR_IA32_SYSENTER_CS 0x00000174#define MSR_IA32_SYSENTER_ESP 0x00000175#define MSR_IA32_SYSENTER_EIP 0x00000176
@@ -540,7 +556,14 @@#define MSR_IA32_EBL_CR_POWERON 0x0000002a#define MSR_EBC_FREQUENCY_ID 0x0000002c#define MSR_SMI_COUNT 0x00000034 -#define MSR_IA32_FEATURE_CONTROL 0x0000003a + +/* Referred to as IA32_FEATURE_CONTROL in Intel's SDM. */ +#define MSR_IA32_FEAT_CTL 0x0000003a +#define FEAT_CTL_LOCKED BIT(0) +#define FEAT_CTL_VMX_ENABLED_INSIDE_SMX BIT(1) +#define FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX BIT(2) +#define FEAT_CTL_LMCE_ENABLED BIT(20) +#define MSR_IA32_TSC_ADJUST 0x0000003b#define MSR_IA32_BNDCFGS 0x00000d90
@@ -548,11 +571,6 @@#define MSR_IA32_XSS 0x00000da0 -#define FEATURE_CONTROL_LOCKED (1<<0) -#define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX (1<<1) -#define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX (1<<2) -#define FEATURE_CONTROL_LMCE (1<<20) -#define MSR_IA32_APICBASE 0x0000001b#define MSR_IA32_APICBASE_BSP (1<<8)#define MSR_IA32_APICBASE_ENABLE (1<<11)
tools/power/x86/turbostat/turbostat.c +2 -2
@@ -4499,10 +4499,10 @@ void decode_feature_control_msr(void) {unsigned long long msr; -if (!get_msr (base_cpu,MSR_IA32_FEATURE_CONTROL , &msr)) +if (!get_msr (base_cpu,MSR_IA32_FEAT_CTL , &msr))fprintf (outf,"cpu%d: MSR_IA32_FEATURE_CONTROL: 0x%08llx (%sLocked %s)\n" , base_cpu, msr, - msr &FEATURE_CONTROL_LOCKED ?"" :"UN-" , + msr &FEAT_CTL_LOCKED ?"" :"UN-" , msr & (1 <<18 ) ?"SGX" :"" ); }
tools/testing/selftests/kvm/lib/x86_64/vmx.c +4 -4
@@ -157,11 +157,11 @@ bool prepare_for_vmx_operation(struct vmx_pages *vmx)* Bit 2: Enables VMXON outside of SMX operation. If clear, VMXON * outside of SMX causes a #GP. */ - required =FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX ; - required |=FEATURE_CONTROL_LOCKED ; - feature_control =rdmsr (MSR_IA32_FEATURE_CONTROL ); + required =FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX ; + required |=FEAT_CTL_LOCKED ; + feature_control =rdmsr (MSR_IA32_FEAT_CTL );if ((feature_control & required) != required) -wrmsr (MSR_IA32_FEATURE_CONTROL , feature_control | required); +wrmsr (MSR_IA32_FEAT_CTL , feature_control | required);/* Enter VMX root operation. */ *(uint32_t *)(vmx->vmxon) =vmcs_revision ();
Signature · 1 line
2.24.0
PATCH v4 5/19 x86/mce: WARN once if IA32_FEAT_CTL MSR is left unlocked
In reply to Sean ChristophersonWARN if the IA32_FEAT_CTL MSR is somehow left unlocked now that CPU initialization unconditionally locks the MSR.
--- arch/x86/kernel/cpu/mce/intel.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/mce/intel.c +6 -5
@@ -116,14 +116,15 @@ static bool lmce_supported(void)/* * BIOS should indicate support for LMCE by setting bit 20 in * IA32_FEAT_CTL without which touching MCG_EXT_CTL will generate a #GP -* fault. +* fault. The MSR must also be locked for LMCE_ENABLED to take effect. +* WARN if the MSR isn't locked as init_ia32_feat_ctl() unconditionally +* locks the MSR in the event that it wasn't already locked by BIOS. */ rdmsrl (MSR_IA32_FEAT_CTL , tmp); -if ((tmp & (FEAT_CTL_LOCKED |FEAT_CTL_LMCE_ENABLED )) == - (FEAT_CTL_LOCKED |FEAT_CTL_LMCE_ENABLED )) -return true; +if (WARN_ON_ONCE (!(tmp &FEAT_CTL_LOCKED ))) +return false; -return false; +return tmp &FEAT_CTL_LMCE_ENABLED ; }bool mce_intel_cmci_poll (void )
Signature · 1 line
2.24.0
PATCH v4 9/19 x86/vmx: Introduce VMX_FEATURES_*
In reply to Sean ChristophersonAdd a VMX specific variant of X86_FEATURE_* flags, which will eventually supplant the synthetic VMX flags defined in cpufeatures word 8. Use the Intel-defined layouts for the major VMX execution controls so that their word entries can be directly populated from their respective MSRs, and so that the VMX_FEATURE_* flags can be used to define the existing bit definitions in asm/vmx.h, i.e. force developers to define a VMX_FEATURE flag when adding support for a new hardware feature.
The majority of Intel's (and compatible CPU's) VMX capabilities are enumerated via MSRs and not CPUID, i.e. querying /proc/cpuinfo doesn't naturally provide any insight into the virtualization capabilities of VMX enabled CPUs. Commit e38e05a85828d ("x86: extended "flags" to show virtualization HW feature in /proc/cpuinfo") attempted to address the issue by synthesizing select VMX features into a Linux-defined word in cpufeatures.
Lack of reporting of VMX capabilities via /proc/cpuinfo is problematic because there is no sane way for a user to query the capabilities of their platform, e.g. when trying to find a platform to test a feature or debug an issue that has a hardware dependency. Lack of reporting is especially problematic when the user isn't familiar with VMX, e.g. the format of the MSRs is non-standard, existence of some MSRs is reported by bits in other MSRs, several "features" from KVM's point of view are enumerated as 3+ distinct features by hardware, etc...
The synthetic cpufeatures approach has several flaws:
- The set of synthesized VMX flags has become extremely stale with respect to the full set of VMX features, e.g. only one new flag (EPT A/D) has been added in the the decade since the introduction of the synthetic VMX features. Failure to keep the VMX flags up to date is likely due to the lack of a mechanism that forces developers to consider whether or not a new feature is worth reporting.
- The synthetic flags may incorrectly be misinterpreted as affecting kernel behavior, i.e. KVM, the kernel's sole consumer of VMX, completely ignores the synthetic flags.
- New CPU vendors that support VMX have duplicated the hideous code that propagates VMX features from MSRs to cpufeatures. Bringing the synthetic VMX flags up to date would exacerbate the copy+paste trainwreck.
Define separate VMX_FEATURE flags to set the stage for enumerating VMX capabilities outside of the cpu_has() framework, and for adding functional usage of VMX_FEATURE_* to help ensure the features reported via /proc/cpuinfo is up to date with respect to kernel recognition of VMX capabilities.
--- MAINTAINERS | 2 +- arch/x86/include/asm/processor.h | 1 + arch/x86/include/asm/vmxfeatures.h | 81 ++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 arch/x86/include/asm/vmxfeatures.h
MAINTAINERS +1 -1
@@ -9107,7 +9107,7 @@ F: arch/x86/include/uapi/asm/svm.h F: arch/x86/include/asm/kvm* F: arch/x86/include/asm/pvclock-abi.h F: arch/x86/include/asm/svm.h -F: arch/x86/include/asm/vmx.h +F: arch/x86/include/asm/vmx*.h F: arch/x86/kernel/kvm.c F: arch/x86/kernel/kvmclock.c
arch/x86/include/asm/processor.h +1 -0
@@ -25,6 +25,7 @@ struct vm86;#include <asm/special_insns.h> #include <asm/fpu/types.h> #include <asm/unwind_hints.h> +#include <asm/vmxfeatures.h> #include <linux/personality.h> #include <linux/cache.h>
arch/x86/include/asm/vmxfeatures.h new file +81 -0
81 lines not on this page · raw message
Signature · 1 line
2.24.0
PATCH v4 11/19 x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
In reply to Sean ChristophersonAdd support for generating VMX feature names in capflags.c and use the resulting x86_vmx_flags to print the VMX flags in /proc/cpuinfo. Don't print VMX flags if no bits are set in word 0, which holds Pin Controls. Pin Control's INTR and NMI exiting are fundamental pillars of VMX, if they are not supported then the CPU is broken, it does not actually support VMX, or the kernel wasn't built with support for the target CPU.
Print the features in a dedicated "vmx flags" line to avoid polluting the common "flags" and to avoid having to prefix all flags with "vmx_", which results in horrendously long names.
Keep synthetic VMX flags in cpufeatures to preserve /proc/cpuinfo's ABI for those flags. This means that "flags" and "vmx flags" will have duplicate entries for tpr_shadow (virtual_tpr), vnmi (virtual_nmis), ept, flexpriority, vpid and ept_ad, but caps the pollution of "flags" at those six VMX features. The vendor specific code that populates the synthetic flags will be consolidated in a future patch to futher minimize the lasting damage.
--- arch/x86/boot/mkcpustr.c | 1 + arch/x86/kernel/cpu/Makefile | 5 +++-- arch/x86/kernel/cpu/mkcapflags.sh | 15 +++++++++++---- arch/x86/kernel/cpu/proc.c | 15 +++++++++++++++ 4 files changed, 30 insertions(+), 6 deletions(-)
arch/x86/boot/mkcpustr.c +1 -0
@@ -15,6 +15,7 @@#include "../include/asm/required-features.h" #include "../include/asm/disabled-features.h" #include "../include/asm/cpufeatures.h" +#include "../include/asm/vmxfeatures.h" #include "../kernel/cpu/capflags.c" int main (void )
arch/x86/kernel/cpu/Makefile +3 -2
@@ -57,11 +57,12 @@ obj-$(CONFIG_ACRN_GUEST) += acrn.o ifdef CONFIG_X86_FEATURE_NAMES quiet_cmd_mkcapflags = MKCAP $@ - cmd_mkcapflags = $(CONFIG_SHELL) $(srctree)/$(src)/mkcapflags.sh $< $@ + cmd_mkcapflags = $(CONFIG_SHELL) $(srctree)/$(src)/mkcapflags.sh $@ $^ cpufeature = $(src)/../../include/asm/cpufeatures.h +vmxfeature = $(src)/../../include/asm/vmxfeatures.h -$(obj)/capflags.c: $(cpufeature) $(src)/mkcapflags.sh FORCE +$(obj)/capflags.c: $(cpufeature) $(vmxfeature) $(src)/mkcapflags.sh FORCE $(call if_changed,mkcapflags) endif targets += capflags.c
arch/x86/kernel/cpu/mkcapflags.sh +11 -4
@@ -6,8 +6,7 @@ set -e -IN=$1 -OUT=$2 +OUT=$1 dump_array() {
@@ -15,6 +14,7 @@ dump_array() SIZE=$2 PFX=$3 POSTFIX=$4 + IN=$5 PFX_SZ=$(echo $PFX | wc -c) TABS="$(printf '\t\t\t\t\t')"
@@ -57,11 +57,18 @@ trap 'rm "$OUT"' EXIT echo "#endif" echo "" - dump_array "x86_cap_flags" "NCAPINTS*32" "X86_FEATURE_" "" + dump_array "x86_cap_flags" "NCAPINTS*32" "X86_FEATURE_" "" $2 echo "" - dump_array "x86_bug_flags" "NBUGINTS*32" "X86_BUG_" "NCAPINTS*32" + dump_array "x86_bug_flags" "NBUGINTS*32" "X86_BUG_" "NCAPINTS*32" $2 + echo "" + echo "#ifdef CONFIG_X86_VMX_FEATURE_NAMES" + echo "#ifndef _ASM_X86_VMXFEATURES_H" + echo "#include <asm/vmxfeatures.h>" + echo "#endif" + dump_array "x86_vmx_flags" "NVMXINTS*32" "VMX_FEATURE_" "" $3 + echo "#endif /* CONFIG_X86_VMX_FEATURE_NAMES */" ) > $OUT trap - EXIT
arch/x86/kernel/cpu/proc.c +15 -0
@@ -7,6 +7,10 @@#include "cpu.h" +#ifdef CONFIG_X86_VMX_FEATURE_NAMES +extern const char *const x86_vmx_flags[NVMXINTS *32 ]; +#endif +/* * Get CPU information for use by the procfs. */
@@ -102,6 +106,17 @@ static int show_cpuinfo(struct seq_file *m, void *v)if (cpu_has (c, i) && x86_cap_flags[i] !=NULL )seq_printf (m," %s" , x86_cap_flags[i]); +#ifdef CONFIG_X86_VMX_FEATURE_NAMES +if (cpu_has (c,X86_FEATURE_VMX ) && c->vmx_capability[0 ]) { +seq_puts (m,"\nvmx flags\t:" ); +for (i =0 ; i <32 *NVMXINTS ; i++) { +if (test_bit (i, (unsigned long *)c->vmx_capability) && + x86_vmx_flags[i] !=NULL ) +seq_printf (m," %s" , x86_vmx_flags[i]); + } + } +#endif +seq_puts (m,"\nbugs\t\t:" );for (i =0 ; i <32 *NBUGINTS ; i++) {unsigned int bug_bit =32 *NCAPINTS + i;
Signature · 1 line
2.24.0
PATCH v4 12/19 x86/cpu: Set synthetic VMX cpufeatures during init_ia32_feat_ctl()
In reply to Sean ChristophersonSet the synthetic VMX cpufeatures, which need to be kept to preserve /proc/cpuinfo's ABI, in the common IA32_FEAT_CTL initialization code. Remove the vendor code that manually sets the synthetic flags.
--- arch/x86/kernel/cpu/centaur.c | 35 ------------------------ arch/x86/kernel/cpu/feat_ctl.c | 14 ++++++++++ arch/x86/kernel/cpu/intel.c | 49 ---------------------------------- arch/x86/kernel/cpu/zhaoxin.c | 35 ------------------------ 4 files changed, 14 insertions(+), 119 deletions(-)
arch/x86/kernel/cpu/centaur.c +0 -35
@@ -18,13 +18,6 @@#define RNG_ENABLED (1 << 3)#define RNG_ENABLE (1 << 6)/* MSR_VIA_RNG */ -#define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000 -#define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000 -#define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000 -#define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001 -#define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002 -#define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020 -static void init_c3 (struct cpuinfo_x86 *c) {u32 lo, hi;
@@ -119,31 +112,6 @@ static void early_init_centaur(struct cpuinfo_x86 *c) } } -static void centaur_detect_vmx_virtcap (struct cpuinfo_x86 *c) -{ -u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2; - -rdmsr (MSR_IA32_VMX_PROCBASED_CTLS , vmx_msr_low, vmx_msr_high); - msr_ctl = vmx_msr_high | vmx_msr_low; - -if (msr_ctl &X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW ) -set_cpu_cap (c,X86_FEATURE_TPR_SHADOW ); -if (msr_ctl &X86_VMX_FEATURE_PROC_CTLS_VNMI ) -set_cpu_cap (c,X86_FEATURE_VNMI ); -if (msr_ctl &X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS ) { -rdmsr (MSR_IA32_VMX_PROCBASED_CTLS2 , - vmx_msr_low, vmx_msr_high); - msr_ctl2 = vmx_msr_high | vmx_msr_low; -if ((msr_ctl2 &X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC ) && - (msr_ctl &X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW )) -set_cpu_cap (c,X86_FEATURE_FLEXPRIORITY ); -if (msr_ctl2 &X86_VMX_FEATURE_PROC_CTLS2_EPT ) -set_cpu_cap (c,X86_FEATURE_EPT ); -if (msr_ctl2 &X86_VMX_FEATURE_PROC_CTLS2_VPID ) -set_cpu_cap (c,X86_FEATURE_VPID ); - } -} -static void init_centaur (struct cpuinfo_x86 *c) {#ifdef CONFIG_X86_32
@@ -251,9 +219,6 @@ static void init_centaur(struct cpuinfo_x86 *c)#endif init_ia32_feat_ctl (c); - -if (cpu_has (c,X86_FEATURE_VMX )) -centaur_detect_vmx_virtcap (c); }#ifdef CONFIG_X86_32
arch/x86/kernel/cpu/feat_ctl.c +14 -0
@@ -68,6 +68,20 @@ static void init_vmx_capabilities(struct cpuinfo_x86 *c) (c->vmx_capability[SECONDARY_PROC_CTLS ] &F (VIRT_INTR_DELIVERY )) && (c->vmx_capability[MISC_FEATURES] & F(POSTED_INTR))) c->vmx_capability[MISC_FEATURES] |= F(APICV); + +/* Set the synthetic cpufeatures to preserve /proc/cpuinfo's ABI. */ +if (c->vmx_capability[PRIMARY_PROC_CTLS ] &F (VIRTUAL_TPR )) +set_cpu_cap (c,X86_FEATURE_TPR_SHADOW ); +if (c->vmx_capability[MISC_FEATURES ] &F (FLEXPRIORITY )) +set_cpu_cap (c,X86_FEATURE_FLEXPRIORITY ); +if (c->vmx_capability[MISC_FEATURES ] &F (VIRTUAL_NMIS )) +set_cpu_cap (c,X86_FEATURE_VNMI ); +if (c->vmx_capability[SECONDARY_PROC_CTLS ] &F (EPT )) +set_cpu_cap (c,X86_FEATURE_EPT ); +if (c->vmx_capability[MISC_FEATURES ] &F (EPT_AD )) +set_cpu_cap (c,X86_FEATURE_EPT_AD ); +if (c->vmx_capability[MISC_FEATURES ] &F (VPID )) + set_cpu_cap(c, X86_FEATURE_VPID); }#endif /* CONFIG_X86_VMX_FEATURE_NAMES */
arch/x86/kernel/cpu/intel.c +0 -49
61 lines not on this page · raw message
arch/x86/kernel/cpu/zhaoxin.c +0 -35
@@ -16,13 +16,6 @@#define RNG_ENABLED (1 << 3)#define RNG_ENABLE (1 << 8)/* MSR_ZHAOXIN_RNG */ -#define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000 -#define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000 -#define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000 -#define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001 -#define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002 -#define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020 -static void init_zhaoxin_cap (struct cpuinfo_x86 *c) {u32 lo, hi;
@@ -89,31 +82,6 @@ static void early_init_zhaoxin(struct cpuinfo_x86 *c) } -static void zhaoxin_detect_vmx_virtcap (struct cpuinfo_x86 *c) -{ -u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2; - -rdmsr (MSR_IA32_VMX_PROCBASED_CTLS , vmx_msr_low, vmx_msr_high); - msr_ctl = vmx_msr_high | vmx_msr_low; - -if (msr_ctl &X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW ) -set_cpu_cap (c,X86_FEATURE_TPR_SHADOW ); -if (msr_ctl &X86_VMX_FEATURE_PROC_CTLS_VNMI ) -set_cpu_cap (c,X86_FEATURE_VNMI ); -if (msr_ctl &X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS ) { -rdmsr (MSR_IA32_VMX_PROCBASED_CTLS2 , - vmx_msr_low, vmx_msr_high); - msr_ctl2 = vmx_msr_high | vmx_msr_low; -if ((msr_ctl2 &X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC ) && - (msr_ctl &X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW )) -set_cpu_cap (c,X86_FEATURE_FLEXPRIORITY ); -if (msr_ctl2 &X86_VMX_FEATURE_PROC_CTLS2_EPT ) -set_cpu_cap (c,X86_FEATURE_EPT ); -if (msr_ctl2 &X86_VMX_FEATURE_PROC_CTLS2_VPID ) -set_cpu_cap (c,X86_FEATURE_VPID ); - } -} -static void init_zhaoxin (struct cpuinfo_x86 *c) {early_init_zhaoxin (c);
@@ -142,9 +110,6 @@ static void init_zhaoxin(struct cpuinfo_x86 *c)#endif init_ia32_feat_ctl (c); - -if (cpu_has (c,X86_FEATURE_VMX )) -zhaoxin_detect_vmx_virtcap (c); }#ifdef CONFIG_X86_32
Signature · 1 line
2.24.0
PATCH v4 6/19 x86/centaur: Use common IA32_FEAT_CTL MSR initialization
In reply to Sean ChristophersonUse the recently added IA32_FEAT_CTL MSR initialization sequence to opportunstically enable VMX support when running on a Centaur CPU.
--- arch/x86/Kconfig.cpu | 2 +- arch/x86/kernel/cpu/centaur.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
arch/x86/Kconfig.cpu +1 -1
@@ -389,7 +389,7 @@ config X86_DEBUGCTLMSR config IA32_FEAT_CTL def_bool y - depends on CPU_SUP_INTEL + depends on CPU_SUP_INTEL || CPU_SUP_CENTAUR menuconfig PROCESSOR_SELECT bool "Supported processor vendors" if EXPERT
arch/x86/kernel/cpu/centaur.c +2 -0
@@ -250,6 +250,8 @@ static void init_centaur(struct cpuinfo_x86 *c)set_cpu_cap (c,X86_FEATURE_LFENCE_RDTSC );#endif +init_ia32_feat_ctl (c); +if (cpu_has (c,X86_FEATURE_VMX ))centaur_detect_vmx_virtcap (c); }
Signature · 1 line
2.24.0
PATCH v4 17/19 KVM: VMX: Use VMX_FEATURE_* flags to define VMCS control bits
In reply to Sean ChristophersonDefine the VMCS execution control flags (consumed by KVM) using their associated VMX_FEATURE_* to provide a strong hint that new VMX features are expected to be added to VMX_FEATURE and considered for reporting via /proc/cpuinfo.
No functional change intended.
--- arch/x86/include/asm/vmx.h | 105 +++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 50 deletions(-)
arch/x86/include/asm/vmx.h +55 -50
@@ -15,67 +15,70 @@#include <linux/bitops.h> #include <linux/types.h> #include <uapi/asm/vmx.h> +#include <asm/vmxfeatures.h> + +#define VMCS_CONTROL_BIT (x) BIT(VMX_FEATURE_##x & 0x1f)/* * Definitions of Primary Processor-Based VM-Execution Controls. */ -#define CPU_BASED_VIRTUAL_INTR_PENDING 0x00000004 -#define CPU_BASED_USE_TSC_OFFSETING 0x00000008 -#define CPU_BASED_HLT_EXITING 0x00000080 -#define CPU_BASED_INVLPG_EXITING 0x00000200 -#define CPU_BASED_MWAIT_EXITING 0x00000400 -#define CPU_BASED_RDPMC_EXITING 0x00000800 -#define CPU_BASED_RDTSC_EXITING 0x00001000 -#define CPU_BASED_CR3_LOAD_EXITING 0x00008000 -#define CPU_BASED_CR3_STORE_EXITING 0x00010000 -#define CPU_BASED_CR8_LOAD_EXITING 0x00080000 -#define CPU_BASED_CR8_STORE_EXITING 0x00100000 -#define CPU_BASED_TPR_SHADOW 0x00200000 -#define CPU_BASED_VIRTUAL_NMI_PENDING 0x00400000 -#define CPU_BASED_MOV_DR_EXITING 0x00800000 -#define CPU_BASED_UNCOND_IO_EXITING 0x01000000 -#define CPU_BASED_USE_IO_BITMAPS 0x02000000 -#define CPU_BASED_MONITOR_TRAP_FLAG 0x08000000 -#define CPU_BASED_USE_MSR_BITMAPS 0x10000000 -#define CPU_BASED_MONITOR_EXITING 0x20000000 -#define CPU_BASED_PAUSE_EXITING 0x40000000 -#define CPU_BASED_ACTIVATE_SECONDARY_CONTROLS 0x80000000 +#define CPU_BASED_VIRTUAL_INTR_PENDING VMCS_CONTROL_BIT(VIRTUAL_INTR_PENDING) +#define CPU_BASED_USE_TSC_OFFSETING VMCS_CONTROL_BIT(TSC_OFFSETTING) +#define CPU_BASED_HLT_EXITING VMCS_CONTROL_BIT(HLT_EXITING) +#define CPU_BASED_INVLPG_EXITING VMCS_CONTROL_BIT(INVLPG_EXITING) +#define CPU_BASED_MWAIT_EXITING VMCS_CONTROL_BIT(MWAIT_EXITING) +#define CPU_BASED_RDPMC_EXITING VMCS_CONTROL_BIT(RDPMC_EXITING) +#define CPU_BASED_RDTSC_EXITING VMCS_CONTROL_BIT(RDTSC_EXITING) +#define CPU_BASED_CR3_LOAD_EXITING VMCS_CONTROL_BIT(CR3_LOAD_EXITING) +#define CPU_BASED_CR3_STORE_EXITING VMCS_CONTROL_BIT(CR3_STORE_EXITING) +#define CPU_BASED_CR8_LOAD_EXITING VMCS_CONTROL_BIT(CR8_LOAD_EXITING) +#define CPU_BASED_CR8_STORE_EXITING VMCS_CONTROL_BIT(CR8_STORE_EXITING) +#define CPU_BASED_TPR_SHADOW VMCS_CONTROL_BIT(VIRTUAL_TPR) +#define CPU_BASED_VIRTUAL_NMI_PENDING VMCS_CONTROL_BIT(VIRTUAL_NMI_PENDING) +#define CPU_BASED_MOV_DR_EXITING VMCS_CONTROL_BIT(MOV_DR_EXITING) +#define CPU_BASED_UNCOND_IO_EXITING VMCS_CONTROL_BIT(UNCOND_IO_EXITING) +#define CPU_BASED_USE_IO_BITMAPS VMCS_CONTROL_BIT(USE_IO_BITMAPS) +#define CPU_BASED_MONITOR_TRAP_FLAG VMCS_CONTROL_BIT(MONITOR_TRAP_FLAG) +#define CPU_BASED_USE_MSR_BITMAPS VMCS_CONTROL_BIT(USE_MSR_BITMAPS) +#define CPU_BASED_MONITOR_EXITING VMCS_CONTROL_BIT(MONITOR_EXITING) +#define CPU_BASED_PAUSE_EXITING VMCS_CONTROL_BIT(PAUSE_EXITING) +#define CPU_BASED_ACTIVATE_SECONDARY_CONTROLS VMCS_CONTROL_BIT(SEC_CONTROLS)#define CPU_BASED_ALWAYSON_WITHOUT_TRUE_MSR 0x0401e172/* * Definitions of Secondary Processor-Based VM-Execution Controls. */ -#define SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES 0x00000001 -#define SECONDARY_EXEC_ENABLE_EPT 0x00000002 -#define SECONDARY_EXEC_DESC 0x00000004 -#define SECONDARY_EXEC_RDTSCP 0x00000008 -#define SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE 0x00000010 -#define SECONDARY_EXEC_ENABLE_VPID 0x00000020 -#define SECONDARY_EXEC_WBINVD_EXITING 0x00000040 -#define SECONDARY_EXEC_UNRESTRICTED_GUEST 0x00000080 -#define SECONDARY_EXEC_APIC_REGISTER_VIRT 0x00000100 -#define SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY 0x00000200 -#define SECONDARY_EXEC_PAUSE_LOOP_EXITING 0x00000400 -#define SECONDARY_EXEC_RDRAND_EXITING 0x00000800 -#define SECONDARY_EXEC_ENABLE_INVPCID 0x00001000 -#define SECONDARY_EXEC_ENABLE_VMFUNC 0x00002000 -#define SECONDARY_EXEC_SHADOW_VMCS 0x00004000 -#define SECONDARY_EXEC_ENCLS_EXITING 0x00008000 -#define SECONDARY_EXEC_RDSEED_EXITING 0x00010000 -#define SECONDARY_EXEC_ENABLE_PML 0x00020000 -#define SECONDARY_EXEC_PT_CONCEAL_VMX 0x00080000 -#define SECONDARY_EXEC_XSAVES 0x00100000 -#define SECONDARY_EXEC_PT_USE_GPA 0x01000000 -#define SECONDARY_EXEC_MODE_BASED_EPT_EXEC 0x00400000 -#define SECONDARY_EXEC_TSC_SCALING 0x02000000 +#define SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES VMCS_CONTROL_BIT(VIRT_APIC_ACCESSES) +#define SECONDARY_EXEC_ENABLE_EPT VMCS_CONTROL_BIT(EPT) +#define SECONDARY_EXEC_DESC VMCS_CONTROL_BIT(DESC_EXITING) +#define SECONDARY_EXEC_RDTSCP VMCS_CONTROL_BIT(RDTSCP) +#define SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE VMCS_CONTROL_BIT(VIRTUAL_X2APIC) +#define SECONDARY_EXEC_ENABLE_VPID VMCS_CONTROL_BIT(VPID) +#define SECONDARY_EXEC_WBINVD_EXITING VMCS_CONTROL_BIT(WBINVD_EXITING) +#define SECONDARY_EXEC_UNRESTRICTED_GUEST VMCS_CONTROL_BIT(UNRESTRICTED_GUEST) +#define SECONDARY_EXEC_APIC_REGISTER_VIRT VMCS_CONTROL_BIT(APIC_REGISTER_VIRT) +#define SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY VMCS_CONTROL_BIT(VIRT_INTR_DELIVERY) +#define SECONDARY_EXEC_PAUSE_LOOP_EXITING VMCS_CONTROL_BIT(PAUSE_LOOP_EXITING) +#define SECONDARY_EXEC_RDRAND_EXITING VMCS_CONTROL_BIT(RDRAND_EXITING) +#define SECONDARY_EXEC_ENABLE_INVPCID VMCS_CONTROL_BIT(INVPCID) +#define SECONDARY_EXEC_ENABLE_VMFUNC VMCS_CONTROL_BIT(VMFUNC) +#define SECONDARY_EXEC_SHADOW_VMCS VMCS_CONTROL_BIT(SHADOW_VMCS) +#define SECONDARY_EXEC_ENCLS_EXITING VMCS_CONTROL_BIT(ENCLS_EXITING) +#define SECONDARY_EXEC_RDSEED_EXITING VMCS_CONTROL_BIT(RDSEED_EXITING) +#define SECONDARY_EXEC_ENABLE_PML VMCS_CONTROL_BIT(PAGE_MOD_LOGGING) +#define SECONDARY_EXEC_PT_CONCEAL_VMX VMCS_CONTROL_BIT(PT_CONCEAL_VMX) +#define SECONDARY_EXEC_XSAVES VMCS_CONTROL_BIT(XSAVES) +#define SECONDARY_EXEC_MODE_BASED_EPT_EXEC VMCS_CONTROL_BIT(MODE_BASED_EPT_EXEC) +#define SECONDARY_EXEC_PT_USE_GPA VMCS_CONTROL_BIT(PT_USE_GPA) +#define SECONDARY_EXEC_TSC_SCALING VMCS_CONTROL_BIT(TSC_SCALING)#define SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE 0x04000000 -#define PIN_BASED_EXT_INTR_MASK 0x00000001 -#define PIN_BASED_NMI_EXITING 0x00000008 -#define PIN_BASED_VIRTUAL_NMIS 0x00000020 -#define PIN_BASED_VMX_PREEMPTION_TIMER 0x00000040 -#define PIN_BASED_POSTED_INTR 0x00000080 +#define PIN_BASED_EXT_INTR_MASK VMCS_CONTROL_BIT(INTR_EXITING) +#define PIN_BASED_NMI_EXITING VMCS_CONTROL_BIT(NMI_EXITING) +#define PIN_BASED_VIRTUAL_NMIS VMCS_CONTROL_BIT(VIRTUAL_NMIS) +#define PIN_BASED_VMX_PREEMPTION_TIMER VMCS_CONTROL_BIT(PREEMPTION_TIMER) +#define PIN_BASED_POSTED_INTR VMCS_CONTROL_BIT(POSTED_INTR)#define PIN_BASED_ALWAYSON_WITHOUT_TRUE_MSR 0x00000016
@@ -114,7 +117,9 @@#define VMX_MISC_MSR_LIST_MULTIPLIER 512/* VMFUNC functions */ -#define VMX_VMFUNC_EPTP_SWITCHING 0x00000001 +#define VMFUNC_CONTROL_BIT (x) BIT((VMX_FEATURE_##x & 0x1f) - 28) + +#define VMX_VMFUNC_EPTP_SWITCHING VMFUNC_CONTROL_BIT(EPTP_SWITCHING)#define VMFUNC_EPTP_ENTRIES 512static inline u32 vmx_basic_vmcs_revision_id (u64 vmx_basic)
Signature · 1 line
2.24.0
PATCH v4 18/19 perf/x86: Provide stubs of KVM helpers for non-Intel CPUs
In reply to Sean ChristophersonProvide stubs for perf_guest_get_msrs() and intel_pt_handle_vmx() when building without support for Intel CPUs, i.e. CPU_SUP_INTEL=n. Lack of stubs is not currently a problem as the only user, KVM_INTEL, takes a dependency on CPU_SUP_INTEL=y. Provide the stubs for all CPUs so that KVM_INTEL can be built for any CPU with compatible hardware support, e.g. Centuar and Zhaoxin CPUs.
Note, the existing stub for perf_guest_get_msrs() is essentially dead code as KVM selects CONFIG_PERF_EVENTS, i.e. the only user guarantees the full implementation is built.
--- arch/x86/include/asm/perf_event.h | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
arch/x86/include/asm/perf_event.h +15 -7
@@ -322,17 +322,10 @@ struct perf_guest_switch_msr { u64 host, guest; }; -extern struct perf_guest_switch_msr *perf_guest_get_msrs (int *nr);extern void perf_get_x86_pmu_capability (struct x86_pmu_capability *cap);extern void perf_check_microcode (void );extern int x86_perf_rdpmc_index (struct perf_event *event);#else -static inline struct perf_guest_switch_msr *perf_guest_get_msrs (int *nr) -{ - *nr =0 ; -return NULL ; -} -static inline void perf_get_x86_pmu_capability (struct x86_pmu_capability *cap) {memset (cap,0 ,sizeof (*cap));
@@ -342,8 +335,23 @@ static inline void perf_events_lapic_init(void) { }static inline void perf_check_microcode (void ) { }#endif +#if defined(CONFIG_PERF_EVENTS ) && defined(CONFIG_CPU_SUP_INTEL ) +extern struct perf_guest_switch_msr *perf_guest_get_msrs (int *nr); +#else +static inline struct perf_guest_switch_msr *perf_guest_get_msrs (int *nr) +{ + *nr =0 ; +return NULL ; +} +#endif +#ifdef CONFIG_CPU_SUP_INTEL extern void intel_pt_handle_vmx (int on); +#else +static inline void intel_pt_handle_vmx (int on) +{ + +}#endif #if defined(CONFIG_PERF_EVENTS ) && defined(CONFIG_CPU_SUP_AMD )
Signature · 1 line
2.24.0
PATCH v4 19/19 KVM: VMX: Allow KVM_INTEL when building for Centaur and/or Zhaoxin CPUs
In reply to Sean ChristophersonChange the dependency for KVM_INTEL, i.e. KVM w/ VMX, from Intel CPUs to any CPU that supports the IA32_FEAT_CTL MSR and thus VMX functionality. This effectively allows building KVM_INTEL for Centaur and Zhaoxin CPUs.
--- arch/x86/kvm/Kconfig | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
arch/x86/kvm/Kconfig +4 -6
@@ -60,13 +60,11 @@ config KVM If unsure, say N. config KVM_INTEL - tristate "KVM for Intel processors support" - depends on KVM - # for perf_guest_get_msrs(): - depends on CPU_SUP_INTEL + tristate "KVM for Intel (and compatible) processors support" + depends on KVM && IA32_FEAT_CTL ---help--- - Provides support for KVM on Intel processors equipped with the VT - extensions. + Provides support for KVM on processors equipped with Intel's VT + extensions, a.k.a. Virtual Machine Extensions (VMX). To compile this as a module, choose M here: the module will be called kvm-intel.
Signature · 1 line
2.24.0
PATCH v4 14/19 KVM: VMX: Drop initialization of IA32_FEAT_CTL MSR
In reply to Sean ChristophersonRemove KVM's code to initialize IA32_FEAT_CTL MSR when KVM is loaded now that the MSR is initialized during boot on all CPUs that support VMX, i.e. on all CPUs that can possibly load kvm_intel.
Note, don't WARN if IA32_FEAT_CTL is unlocked, even though the MSR is unconditionally locked by init_ia32_feat_ctl(). KVM isn't tied directly to a CPU vendor detection, whereas init_ia32_feat_ctl() is invoked if and only if the CPU vendor is recognized and known to support VMX. As a result, vmx_disabled_by_bios() may be reached without going through init_ia32_feat_ctl() and thus without locking IA32_FEAT_CTL. This quirk will be eliminated in a future patch.
--- arch/x86/kvm/vmx/vmx.c | 48 +++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 29 deletions(-)
arch/x86/kvm/vmx/vmx.c +19 -29
@@ -2207,24 +2207,26 @@ static __init int vmx_disabled_by_bios(void)u64 msr;rdmsrl (MSR_IA32_FEAT_CTL , msr); -if (msr &FEAT_CTL_LOCKED ) { -/* launched w/ TXT and VMX disabled */ -if (!(msr &FEAT_CTL_VMX_ENABLED_INSIDE_SMX ) - &&tboot_enabled ()) -return 1 ; -/* launched w/o TXT and VMX only enabled w/ TXT */ -if (!(msr &FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX ) - && (msr &FEAT_CTL_VMX_ENABLED_INSIDE_SMX ) - && !tboot_enabled ()) { -printk (KERN_WARNING "kvm: disable TXT in the BIOS or " -"activate TXT before enabling KVM\n" ); -return 1 ; - } -/* launched w/o TXT and VMX disabled */ -if (!(msr &FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX ) - && !tboot_enabled ()) -return 1 ; + +if (unlikely (!(msr &FEAT_CTL_LOCKED ))) +return 1 ; + +/* launched w/ TXT and VMX disabled */ +if (!(msr &FEAT_CTL_VMX_ENABLED_INSIDE_SMX ) && +tboot_enabled ()) +return 1 ; +/* launched w/o TXT and VMX only enabled w/ TXT */ +if (!(msr &FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX ) && + (msr &FEAT_CTL_VMX_ENABLED_INSIDE_SMX ) && + !tboot_enabled ()) { +pr_warn ("kvm: disable TXT in the BIOS or " +"activate TXT before enabling KVM\n" ); +return 1 ; } +/* launched w/o TXT and VMX disabled */ +if (!(msr &FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX ) && + !tboot_enabled ()) +return 1 ;return 0 ; }
@@ -2241,7 +2243,6 @@ static int hardware_enable(void) {int cpu =raw_smp_processor_id ();u64 phys_addr =__pa (per_cpu (vmxarea, cpu)); -u64 old, test_bits;if (cr4_read_shadow () &X86_CR4_VMXE )return -EBUSY ;
@@ -2269,17 +2270,6 @@ static int hardware_enable(void)*/ crash_enable_local_vmclear (cpu); -rdmsrl (MSR_IA32_FEAT_CTL , old); - - test_bits =FEAT_CTL_LOCKED ; - test_bits |=FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX ; -if (tboot_enabled ()) - test_bits |=FEAT_CTL_VMX_ENABLED_INSIDE_SMX ; - -if ((old & test_bits) != test_bits) { -/* enable and lock */ -wrmsrl (MSR_IA32_FEAT_CTL , old | test_bits); - }kvm_cpu_vmxon (phys_addr);if (enable_ept)ept_sync_global ();
Signature · 1 line
2.24.0
PATCH v4 16/19 KVM: VMX: Check for full VMX support when verifying CPU compatibility
In reply to Sean ChristophersonExplicitly check the current CPU's IA32_FEAT_CTL and VMX feature flags when verifying compatibility across physical CPUs. This effectively adds a check on IA32_FEAT_CTL to ensure that VMX is fully enabled on all CPUs.
--- arch/x86/kvm/vmx/vmx.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/x86/kvm/vmx/vmx.c +6 -0
@@ -6846,6 +6846,12 @@ static int __init vmx_check_processor_compat(void)struct vmcs_config vmcs_conf;struct vmx_capability vmx_cap; +if (!this_cpu_has (X86_FEATURE_MSR_IA32_FEAT_CTL ) || + !this_cpu_has (X86_FEATURE_VMX )) { +pr_err ("kvm: VMX is disabled on CPU %d\n" ,smp_processor_id ()); +return -EIO ; + } +if (setup_vmcs_config (&vmcs_conf, &vmx_cap) <0 )return -EIO ;if (nested)
Signature · 1 line
2.24.0
PATCH v4 15/19 KVM: VMX: Use VMX feature flag to query BIOS enabling
In reply to Sean ChristophersonReplace KVM's manual checks on IA32_FEAT_CTL with a query on the boot CPU's MSR_IA32_FEAT_CTL and VMX feature flags. The MSR_IA32_FEAT_CTL indicates that IA32_FEAT_CTL has been configured and that dependent features are accurately reflected in cpufeatures, e.g. the VMX flag is now cleared during boot if VMX isn't fully enabled via IA32_FEAT_CTL, including the case where the MSR isn't supported.
--- arch/x86/kvm/vmx/vmx.c | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-)
arch/x86/kvm/vmx/vmx.c +2 -25
@@ -2204,31 +2204,8 @@ static __init int cpu_has_kvm_support(void)static __init int vmx_disabled_by_bios (void ) { -u64 msr; - -rdmsrl (MSR_IA32_FEAT_CTL , msr); - -if (unlikely (!(msr &FEAT_CTL_LOCKED ))) -return 1 ; - -/* launched w/ TXT and VMX disabled */ -if (!(msr &FEAT_CTL_VMX_ENABLED_INSIDE_SMX ) && -tboot_enabled ()) -return 1 ; -/* launched w/o TXT and VMX only enabled w/ TXT */ -if (!(msr &FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX ) && - (msr &FEAT_CTL_VMX_ENABLED_INSIDE_SMX ) && - !tboot_enabled ()) { -pr_warn ("kvm: disable TXT in the BIOS or " -"activate TXT before enabling KVM\n" ); -return 1 ; - } -/* launched w/o TXT and VMX disabled */ -if (!(msr &FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX ) && - !tboot_enabled ()) -return 1 ; - -return 0 ; +return !boot_cpu_has (X86_FEATURE_MSR_IA32_FEAT_CTL ) || + !boot_cpu_has (X86_FEATURE_VMX ); }static void kvm_cpu_vmxon (u64 addr)
Signature · 1 line
2.24.0
PATCH v4 13/19 x86/cpufeatures: Add flag to track whether MSR IA32_FEAT_CTL is configured
In reply to Sean ChristophersonAdd a new feature flag, X86_FEATURE_MSR_IA32_FEAT_CTL, to track whether IA32_FEAT_CTL has been initialized. This will allow KVM, and any future subsystems that depend on IA32_FEAT_CTL, to rely purely on cpufeatures to query platform support, e.g. allows a future patch to remove KVM's manual IA32_FEAT_CTL MSR checks.
Various features (on platforms that support IA32_FEAT_CTL) are dependent on IA32_FEAT_CTL being configured and locked, e.g. VMX and LMCE. The MSR is always configured during boot, but only if the CPU vendor is recognized by the kernel. Because CPUID doesn't incorporate the current IA32_FEAT_CTL value in its reporting of relevant features, it's possible for a feature to be reported as supported in cpufeatures but not truly enabled, e.g. if the CPU supports VMX but the kernel doesn't recognize the CPU.
As a result, without the flag, KVM would see VMX as supported even if IA32_FEAT_CTL hasn't been initialized, and so would need to manually read the MSR and check the various enabling bits to avoid taking an unexpected #GP on VMXON.
---
I tried darn hard to avoid this patch, but couldn't come up with a less crappy alternative. Arguably, letting KVM #GP in the above scenario is acceptable because it means the user is doing something silly. But, KVM currently handles this scenario gracefully, and I think we'll have the same conundrum for SGX. Requiring KVM and SGX to check the MSR sort of defeats the purpose of this series.
Another option I thought of was to call init_ia32_feat_ctl() from common code, but that would mean taking a #GP on the RDMSR on AMD and company, which seems far worse than adding a synthetic feature flag.
The last option I tried was to clear the VMX flag in default_init(), but then we'd have to do the same for SGX and any other new features that get dumped into IA32_FEAT_CTL, which again seems worse than adding a synthetic flag.
arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/feat_ctl.c | 2 ++ 2 files changed, 3 insertions(+)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -220,6 +220,7 @@#define X86_FEATURE_ZEN ( 7*32+28)/* "" CPU is AMD family 0x17 (Zen) */ #define X86_FEATURE_L1TF_PTEINV ( 7*32+29)/* "" L1TF workaround PTE inversion */ #define X86_FEATURE_IBRS_ENHANCED ( 7*32+30)/* Enhanced IBRS */ +#define X86_FEATURE_MSR_IA32_FEAT_CTL ( 7*32+31)/* "" MSR IA32_FEAT_CTL configured */ /* Virtualization flags: Linux defined, word 8 */ #define X86_FEATURE_TPR_SHADOW ( 8*32+ 0)/* Intel TPR Shadow */
arch/x86/kernel/cpu/feat_ctl.c +2 -0
@@ -122,6 +122,8 @@ void init_ia32_feat_ctl(struct cpuinfo_x86 *c)wrmsrl (MSR_IA32_FEAT_CTL , msr); update_caps: +set_cpu_cap (c,X86_FEATURE_MSR_IA32_FEAT_CTL ); +if (!cpu_has (c,X86_FEATURE_VMX ))return ;
Signature · 1 line
2.24.0
PATCH v4 10/19 x86/cpu: Detect VMX features on Intel, Centaur and Zhaoxin CPUs
In reply to Sean ChristophersonAdd an entry in struct cpuinfo_x86 to track VMX capabilities and fill the capabilities during IA32_FEAT_CTL MSR initialization.
Make the VMX capabilities dependent on IA32_FEAT_CTL and X86_FEATURE_NAMES so as to avoid unnecessary overhead on CPUs that can't possibly support VMX, or when /proc/cpuinfo is not available.
--- arch/x86/Kconfig.cpu | 4 ++ arch/x86/include/asm/processor.h | 3 ++ arch/x86/include/asm/vmxfeatures.h | 5 +++ arch/x86/kernel/cpu/common.c | 3 ++ arch/x86/kernel/cpu/feat_ctl.c | 70 ++++++++++++++++++++++++++++++ 5 files changed, 85 insertions(+)
arch/x86/Kconfig.cpu +4 -0
@@ -391,6 +391,10 @@ config IA32_FEAT_CTL def_bool y depends on CPU_SUP_INTEL || CPU_SUP_CENTAUR || CPU_SUP_ZHAOXIN +config X86_VMX_FEATURE_NAMES + def_bool y + depends on IA32_FEAT_CTL && X86_FEATURE_NAMES + menuconfig PROCESSOR_SELECT bool "Supported processor vendors" if EXPERT ---help---
arch/x86/include/asm/processor.h +3 -0
@@ -85,6 +85,9 @@ struct cpuinfo_x86 {#ifdef CONFIG_X86_64 /* Number of 4K pages in DTLB/ITLB combined(in pages): */ int x86_tlbsize; +#endif +#ifdef CONFIG_X86_VMX_FEATURE_NAMES +__u32 vmx_capability[NVMXINTS ];#endif __u8 x86_virt_bits;__u8 x86_phys_bits;
arch/x86/include/asm/vmxfeatures.h +5 -0
@@ -2,6 +2,11 @@#ifndef _ASM_X86_VMXFEATURES_H#define _ASM_X86_VMXFEATURES_H +/* +* Defines VMX CPU feature bits +*/ +#define NVMXINTS 3/* N 32-bit words worth of info */ +/* * Note: If the comment begins with a quoted string, that string is used * in /proc/cpuinfo instead of the macro name. If the string is "",
arch/x86/kernel/cpu/common.c +3 -0
@@ -1449,6 +1449,9 @@ static void identify_cpu(struct cpuinfo_x86 *c)#endif c->x86_cache_alignment = c->x86_clflush_size;memset (&c->x86_capability,0 ,sizeof (c->x86_capability)); +#ifdef CONFIG_X86_VMX_FEATURE_NAMES +memset (&c->vmx_capability,0 ,sizeof (c->vmx_capability)); +#endif generic_identify (c);
arch/x86/kernel/cpu/feat_ctl.c +70 -0
81 lines not on this page · raw message
Signature · 1 line
2.24.0
PATCH v4 4/19 x86/intel: Initialize IA32_FEAT_CTL MSR at boot
In reply to Sean ChristophersonOpportunistically initialize IA32_FEAT_CTL to enable VMX when the MSR is left unlocked by BIOS. Configuring feature control at boot time paves the way for similar enabling of other features, e.g. Software Guard Extensions (SGX).
Temporarily leave equivalent KVM code in place in order to avoid introducing a regression on Centaur and Zhaoxin CPUs, e.g. removing KVM's code would leave the MSR unlocked on those CPUs and would break existing functionality if people are loading kvm_intel on Centaur and/or Zhaoxin. Defer enablement of the boot-time configuration on Centaur and Zhaoxin to future patches to aid bisection.
Note, Local Machine Check Exceptions (LMCE) are also supported by the kernel and enabled via feature control, but the kernel currently uses LMCE if and and only if the feature is explicitly enabled by BIOS. Keep the current behavior to avoid introducing bugs, future patches can opt in to opportunistic enabling if it's deemed desirable to do so.
Always lock IA32_FEAT_CTL if it exists, even if the CPU doesn't support VMX, so that other existing and future kernel code that queries the MSR can assume it's locked.
Start from a clean slate when constructing the value to write to IA32_FEAT_CTL, i.e. ignore whatever value BIOS left in the MSR so as not to enable random features or fault on the WRMSR.
--- arch/x86/Kconfig.cpu | 4 ++++ arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/cpu.h | 4 ++++ arch/x86/kernel/cpu/feat_ctl.c | 37 ++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/intel.c | 2 ++ 5 files changed, 48 insertions(+) create mode 100644 arch/x86/kernel/cpu/feat_ctl.c
arch/x86/Kconfig.cpu +4 -0
@@ -387,6 +387,10 @@ config X86_DEBUGCTLMSR def_bool y depends on !(MK6 || MWINCHIPC6 || MWINCHIP3D || MCYRIXIII || M586MMX || M586TSC || M586 || M486SX || M486) && !UML +config IA32_FEAT_CTL + def_bool y + depends on CPU_SUP_INTEL + menuconfig PROCESSOR_SELECT bool "Supported processor vendors" if EXPERT ---help---
arch/x86/kernel/cpu/Makefile +1 -0
@@ -32,6 +32,7 @@ obj-y += umwait.o obj-$(CONFIG_PROC_FS) += proc.o obj-$(CONFIG_X86_FEATURE_NAMES) += capflags.o powerflags.o +obj-$(CONFIG_IA32_FEAT_CTL) += feat_ctl.o ifdef CONFIG_CPU_SUP_INTEL obj-y += intel.o intel_pconfig.o tsx.o obj-$(CONFIG_PM) += intel_epb.o
arch/x86/kernel/cpu/cpu.h +4 -0
@@ -80,4 +80,8 @@ extern void x86_spec_ctrl_setup_ap(void);extern u64 x86_read_arch_cap_msr (void ); +#ifdef CONFIG_IA32_FEAT_CTL +void init_ia32_feat_ctl (struct cpuinfo_x86 *c); +#endif +#endif /* ARCH_X86_CPU_H */
arch/x86/kernel/cpu/feat_ctl.c new file +37 -0
@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/tboot.h> + +#include <asm/cpufeature.h> +#include <asm/msr-index.h> +#include <asm/processor.h> + +void init_ia32_feat_ctl (struct cpuinfo_x86 *c) +{ +u64 msr; + +if (rdmsrl_safe (MSR_IA32_FEAT_CTL , &msr)) +return ; + +if (msr &FEAT_CTL_LOCKED ) +return ; + +/* +* Ignore whatever value BIOS left in the MSR to avoid enabling random +* features or faulting on the WRMSR. +*/ + msr =FEAT_CTL_LOCKED ; + +/* +* Enable VMX if and only if the kernel may do VMXON at some point, +* i.e. KVM is enabled, to avoid unnecessarily adding an attack vector +* for the kernel, e.g. using VMX to hide malicious code. +*/ +if (cpu_has (c,X86_FEATURE_VMX ) &&IS_ENABLED (CONFIG_KVM_INTEL )) { + msr |=FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX ; + +if (tboot_enabled ()) + msr |=FEAT_CTL_VMX_ENABLED_INSIDE_SMX ; + } + +wrmsrl (MSR_IA32_FEAT_CTL , msr); +}
arch/x86/kernel/cpu/intel.c +2 -0
@@ -755,6 +755,8 @@ static void init_intel(struct cpuinfo_x86 *c)/* Work around errata */ srat_detect_node (c); +init_ia32_feat_ctl (c); +if (cpu_has (c,X86_FEATURE_VMX ))detect_vmx_virtcap (c);
Signature · 1 line
2.24.0
PATCH v4 8/19 x86/cpu: Clear VMX feature flag if VMX is not fully enabled
In reply to Sean ChristophersonNow that IA32_FEAT_CTL is always configured and locked for CPUs that are known to support VMX[*], clear the VMX capability flag if the MSR is unsupported or BIOS disabled VMX, i.e. locked IA32_FEAT_CTL and didn't set the appropriate VMX enable bit.
[*] Because init_ia32_feat_ctl() is called from vendors ->c_init(), it's
still possible for IA32_FEAT_CTL to be left unlocked when VMX is supported by the CPU. This is not fatal, and will be addressed in a future patch.
--- arch/x86/kernel/cpu/feat_ctl.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/feat_ctl.c +20 -3
@@ -5,15 +5,21 @@#include <asm/msr-index.h> #include <asm/processor.h> +#undef pr_fmt +#define pr_fmt (fmt) "x86/cpu: " fmt +void init_ia32_feat_ctl (struct cpuinfo_x86 *c) { +bool tboot =tboot_enabled ();u64 msr; -if (rdmsrl_safe (MSR_IA32_FEAT_CTL , &msr)) +if (rdmsrl_safe (MSR_IA32_FEAT_CTL , &msr)) { +clear_cpu_cap (c,X86_FEATURE_VMX );return ; + }if (msr &FEAT_CTL_LOCKED ) -return ; + goto update_caps;/* * Ignore whatever value BIOS left in the MSR to avoid enabling random
@@ -29,9 +35,20 @@ void init_ia32_feat_ctl(struct cpuinfo_x86 *c)if (cpu_has (c,X86_FEATURE_VMX ) &&IS_ENABLED (CONFIG_KVM_INTEL )) { msr |=FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX ; -if (tboot_enabled ()) +if (tboot) msr |=FEAT_CTL_VMX_ENABLED_INSIDE_SMX ; }wrmsrl (MSR_IA32_FEAT_CTL , msr); + +update_caps: +if (!cpu_has (c,X86_FEATURE_VMX )) +return ; + +if ( (tboot && !(msr &FEAT_CTL_VMX_ENABLED_INSIDE_SMX )) || + (!tboot && !(msr &FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX ))) { +pr_err_once ("VMX (%s TXT) disabled by BIOS\n" , + tboot ?"inside" :"outside" ); +clear_cpu_cap (c,X86_FEATURE_VMX ); + } }
Signature · 1 line
2.24.0
PATCH v4 7/19 x86/zhaoxin: Use common IA32_FEAT_CTL MSR initialization
In reply to Sean ChristophersonUse the recently added IA32_FEAT_CTL MSR initialization sequence to opportunstically enable VMX support when running on a Zhaoxin CPU.
--- arch/x86/Kconfig.cpu | 2 +- arch/x86/kernel/cpu/zhaoxin.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
arch/x86/Kconfig.cpu +1 -1
@@ -389,7 +389,7 @@ config X86_DEBUGCTLMSR config IA32_FEAT_CTL def_bool y - depends on CPU_SUP_INTEL || CPU_SUP_CENTAUR + depends on CPU_SUP_INTEL || CPU_SUP_CENTAUR || CPU_SUP_ZHAOXIN menuconfig PROCESSOR_SELECT bool "Supported processor vendors" if EXPERT
arch/x86/kernel/cpu/zhaoxin.c +2 -0
@@ -141,6 +141,8 @@ static void init_zhaoxin(struct cpuinfo_x86 *c)set_cpu_cap (c,X86_FEATURE_LFENCE_RDTSC );#endif +init_ia32_feat_ctl (c); +if (cpu_has (c,X86_FEATURE_VMX ))zhaoxin_detect_vmx_virtcap (c); }
Signature · 1 line
2.24.0
PATCH v4 2/19 selftests: kvm: Replace manual MSR defs with common msr-index.h
In reply to Sean ChristophersonThe kernel's version of msr-index.h was pulled wholesale into tools by commit 444e2ff34df8 ("tools arch x86: Grab a copy of the file containing the MSR numbers"), use the common msr-index.h instead of manually redefining everything in a KVM-only header.
Note, a few MSR related definitions remain in processor.h because they are not covered by msr-index.h, including the awesomely named APIC_BASE_MSR, which refers to starting index of the x2APIC MSRs, not the actual MSR_IA32_APICBASE, which *is* defined by msr-index.h.
--- tools/testing/selftests/kvm/Makefile | 4 +- .../selftests/kvm/include/x86_64/processor.h | 726 +----------------- 2 files changed, 6 insertions(+), 724 deletions(-)
tools/testing/selftests/kvm/Makefile +3 -1
@@ -45,9 +45,11 @@ LIBKVM += $(LIBKVM_$(UNAME_M)) INSTALL_HDR_PATH = $(top_srcdir)/usr LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/ LINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include +LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/x86/include CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ - -I$(LINUX_HDR_PATH) -Iinclude -I$(<D) -Iinclude/$(UNAME_M) -I.. + -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ + -I$(<D) -Iinclude/$(UNAME_M) -I.. no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \ $(CC) -Werror -no-pie -x c - -o "$$TMP", -no-pie)
tools/testing/selftests/kvm/include/x86_64/processor.h +3 -723
744 lines not on this page · raw message
Signature · 1 line
2.24.0
kbuild test robot
build botRe: [PATCH v4 01/19] x86/msr-index: Clean up bit defines for IA32_FEATURE_CONTROL MSR
In reply to Sean ChristophersonI love your patch! Yet something to improve:
Hi Sean,
I love your patch! Yet something to improve:
[auto build test ERROR on tip/auto-latest]
[also build test ERROR on next-20191128]
[cannot apply to tip/x86/core kvm/linux-next v5.4]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Sean-Christopherson/x86-cpu-Clean-up-handling-of-VMX-features/20191128-094556 base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git e445033e58108a9891abfbc0dea90b066a75e4a9 config: i386-randconfig-a002-20191128 (attached as .config) compiler: gcc-6 (Debian 6.3.0-18+deb9u1) 6.3.0 20170516 reproduce: # save the attached .config to linux build tree make ARCH=i386
If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
In file included from arch/x86/include/asm/processor.h:22:0,
from arch/x86/include/asm/cpufeature.h:5,
from arch/x86/include/asm/thread_info.h:53,
from include/linux/thread_info.h:38,
from arch/x86/include/asm/preempt.h:7,
from include/linux/preempt.h:78,
from include/linux/percpu.h:6,
from include/linux/cpuidle.h:14,
from drivers//idle/intel_idle.c:45:
drivers//idle/intel_idle.c: In function 'sklh_idle_state_table_update':
>> drivers//idle/intel_idle.c:1287:10: error: 'MSR_IA32_FEATURE_CONTROL' undeclared (first use in this function)
rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
^
arch/x86/include/asm/msr.h:279:28: note: in definition of macro 'rdmsrl'
((val) = native_read_msr((msr)))
^~~
drivers//idle/intel_idle.c:1287:10: note: each undeclared identifier is reported only once for each function it appears in
rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
^
arch/x86/include/asm/msr.h:279:28: note: in definition of macro 'rdmsrl'
((val) = native_read_msr((msr)))
^~~vim +/MSR_IA32_FEATURE_CONTROL +1287 drivers//idle/intel_idle.c
5dcef694860100 Len Brown 2016-04-06 1189
5dcef694860100 Len Brown 2016-04-06 1190 /*
5dcef694860100 Len Brown 2016-04-06 1191 * Translate IRTL (Interrupt Response Time Limit) MSR to usec
5dcef694860100 Len Brown 2016-04-06 1192 */
5dcef694860100 Len Brown 2016-04-06 1193
5dcef694860100 Len Brown 2016-04-06 1194 static unsigned int irtl_ns_units[] = {
5dcef694860100 Len Brown 2016-04-06 1195 1, 32, 1024, 32768, 1048576, 33554432, 0, 0 };
5dcef694860100 Len Brown 2016-04-06 1196
5dcef694860100 Len Brown 2016-04-06 1197 static unsigned long long irtl_2_usec(unsigned long long irtl)
5dcef694860100 Len Brown 2016-04-06 1198 {
5dcef694860100 Len Brown 2016-04-06 1199 unsigned long long ns;
5dcef694860100 Len Brown 2016-04-06 1200
3451ab3ebf92b1 Jan Beulich 2016-06-27 1201 if (!irtl)
3451ab3ebf92b1 Jan Beulich 2016-06-27 1202 return 0;
3451ab3ebf92b1 Jan Beulich 2016-06-27 1203
bef450962597ff Jan Beulich 2016-06-27 1204 ns = irtl_ns_units[(irtl >> 10) & 0x7];
5dcef694860100 Len Brown 2016-04-06 1205
5dcef694860100 Len Brown 2016-04-06 1206 return div64_u64((irtl & 0x3FF) * ns, 1000);
5dcef694860100 Len Brown 2016-04-06 1207 }
5dcef694860100 Len Brown 2016-04-06 1208 /*
5dcef694860100 Len Brown 2016-04-06 1209 * bxt_idle_state_table_update(void)
5dcef694860100 Len Brown 2016-04-06 1210 *
5dcef694860100 Len Brown 2016-04-06 1211 * On BXT, we trust the IRTL to show the definitive maximum latency
5dcef694860100 Len Brown 2016-04-06 1212 * We use the same value for target_residency.
5dcef694860100 Len Brown 2016-04-06 1213 */
5dcef694860100 Len Brown 2016-04-06 1214 static void bxt_idle_state_table_update(void)
5dcef694860100 Len Brown 2016-04-06 1215 {
5dcef694860100 Len Brown 2016-04-06 1216 unsigned long long msr;
3451ab3ebf92b1 Jan Beulich 2016-06-27 1217 unsigned int usec;
5dcef694860100 Len Brown 2016-04-06 1218
5dcef694860100 Len Brown 2016-04-06 1219 rdmsrl(MSR_PKGC6_IRTL, msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1220 usec = irtl_2_usec(msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1221 if (usec) {
5dcef694860100 Len Brown 2016-04-06 1222 bxt_cstates[2].exit_latency = usec;
5dcef694860100 Len Brown 2016-04-06 1223 bxt_cstates[2].target_residency = usec;
5dcef694860100 Len Brown 2016-04-06 1224 }
5dcef694860100 Len Brown 2016-04-06 1225
5dcef694860100 Len Brown 2016-04-06 1226 rdmsrl(MSR_PKGC7_IRTL, msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1227 usec = irtl_2_usec(msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1228 if (usec) {
5dcef694860100 Len Brown 2016-04-06 1229 bxt_cstates[3].exit_latency = usec;
5dcef694860100 Len Brown 2016-04-06 1230 bxt_cstates[3].target_residency = usec;
5dcef694860100 Len Brown 2016-04-06 1231 }
5dcef694860100 Len Brown 2016-04-06 1232
5dcef694860100 Len Brown 2016-04-06 1233 rdmsrl(MSR_PKGC8_IRTL, msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1234 usec = irtl_2_usec(msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1235 if (usec) {
5dcef694860100 Len Brown 2016-04-06 1236 bxt_cstates[4].exit_latency = usec;
5dcef694860100 Len Brown 2016-04-06 1237 bxt_cstates[4].target_residency = usec;
5dcef694860100 Len Brown 2016-04-06 1238 }
5dcef694860100 Len Brown 2016-04-06 1239
5dcef694860100 Len Brown 2016-04-06 1240 rdmsrl(MSR_PKGC9_IRTL, msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1241 usec = irtl_2_usec(msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1242 if (usec) {
5dcef694860100 Len Brown 2016-04-06 1243 bxt_cstates[5].exit_latency = usec;
5dcef694860100 Len Brown 2016-04-06 1244 bxt_cstates[5].target_residency = usec;
5dcef694860100 Len Brown 2016-04-06 1245 }
5dcef694860100 Len Brown 2016-04-06 1246
5dcef694860100 Len Brown 2016-04-06 1247 rdmsrl(MSR_PKGC10_IRTL, msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1248 usec = irtl_2_usec(msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1249 if (usec) {
5dcef694860100 Len Brown 2016-04-06 1250 bxt_cstates[6].exit_latency = usec;
5dcef694860100 Len Brown 2016-04-06 1251 bxt_cstates[6].target_residency = usec;
5dcef694860100 Len Brown 2016-04-06 1252 }
5dcef694860100 Len Brown 2016-04-06 1253
5dcef694860100 Len Brown 2016-04-06 1254 }
d70e28f57e14a4 Len Brown 2016-03-13 1255 /*
d70e28f57e14a4 Len Brown 2016-03-13 1256 * sklh_idle_state_table_update(void)
d70e28f57e14a4 Len Brown 2016-03-13 1257 *
d70e28f57e14a4 Len Brown 2016-03-13 1258 * On SKL-H (model 0x5e) disable C8 and C9 if:
d70e28f57e14a4 Len Brown 2016-03-13 1259 * C10 is enabled and SGX disabled
d70e28f57e14a4 Len Brown 2016-03-13 1260 */
d70e28f57e14a4 Len Brown 2016-03-13 1261 static void sklh_idle_state_table_update(void)
d70e28f57e14a4 Len Brown 2016-03-13 1262 {
d70e28f57e14a4 Len Brown 2016-03-13 1263 unsigned long long msr;
d70e28f57e14a4 Len Brown 2016-03-13 1264 unsigned int eax, ebx, ecx, edx;
d70e28f57e14a4 Len Brown 2016-03-13 1265
d70e28f57e14a4 Len Brown 2016-03-13 1266
d70e28f57e14a4 Len Brown 2016-03-13 1267 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
d70e28f57e14a4 Len Brown 2016-03-13 1268 if (max_cstate <= 7)
d70e28f57e14a4 Len Brown 2016-03-13 1269 return;
d70e28f57e14a4 Len Brown 2016-03-13 1270
d70e28f57e14a4 Len Brown 2016-03-13 1271 /* if PC10 not present in CPUID.MWAIT.EDX */
d70e28f57e14a4 Len Brown 2016-03-13 1272 if ((mwait_substates & (0xF << 28)) == 0)
d70e28f57e14a4 Len Brown 2016-03-13 1273 return;
d70e28f57e14a4 Len Brown 2016-03-13 1274
6cfb2374f83bc7 Len Brown 2017-01-07 1275 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr);
d70e28f57e14a4 Len Brown 2016-03-13 1276
d70e28f57e14a4 Len Brown 2016-03-13 1277 /* PC10 is not enabled in PKG C-state limit */
d70e28f57e14a4 Len Brown 2016-03-13 1278 if ((msr & 0xF) != 8)
d70e28f57e14a4 Len Brown 2016-03-13 1279 return;
d70e28f57e14a4 Len Brown 2016-03-13 1280
d70e28f57e14a4 Len Brown 2016-03-13 1281 ecx = 0;
d70e28f57e14a4 Len Brown 2016-03-13 1282 cpuid(7, &eax, &ebx, &ecx, &edx);
d70e28f57e14a4 Len Brown 2016-03-13 1283
d70e28f57e14a4 Len Brown 2016-03-13 1284 /* if SGX is present */
d70e28f57e14a4 Len Brown 2016-03-13 1285 if (ebx & (1 << 2)) {
d70e28f57e14a4 Len Brown 2016-03-13 1286
d70e28f57e14a4 Len Brown 2016-03-13 @1287 rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
d70e28f57e14a4 Len Brown 2016-03-13 1288
d70e28f57e14a4 Len Brown 2016-03-13 1289 /* if SGX is enabled */
d70e28f57e14a4 Len Brown 2016-03-13 1290 if (msr & (1 << 18))
0138d8f0755b5b Len Brown 2014-04-04 1291 return;
0138d8f0755b5b Len Brown 2014-04-04 1292 }
0138d8f0755b5b Len Brown 2014-04-04 1293
d70e28f57e14a4 Len Brown 2016-03-13 1294 skl_cstates[5].disabled = 1; /* C8-SKL */
d70e28f57e14a4 Len Brown 2016-03-13 1295 skl_cstates[6].disabled = 1; /* C9-SKL */
d70e28f57e14a4 Len Brown 2016-03-13 1296 }
d70e28f57e14a4 Len Brown 2016-03-13 1297 /*
d70e28f57e14a4 Len Brown 2016-03-13 1298 * intel_idle_state_table_update()
d70e28f57e14a4 Len Brown 2016-03-13 1299 *
d70e28f57e14a4 Len Brown 2016-03-13 1300 * Update the default state_table for this CPU-id
d70e28f57e14a4 Len Brown 2016-03-13 1301 */
d70e28f57e14a4 Len Brown 2016-03-13 1302 :::::: The code@line 1287 was first introduced by commit
:::::: d70e28f57e14a481977436695b0c9ba165472431 intel_idle: prevent SKL-H boot failure when C8+C9+C10 enabled
:::::: TO: Len Brown <[email protected]>
:::::: CC: Len Brown <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation
kbuild test robot
build botRe: [PATCH v4 01/19] x86/msr-index: Clean up bit defines for IA32_FEATURE_CONTROL MSR
In reply to Sean ChristophersonI love your patch! Yet something to improve:
Hi Sean,
I love your patch! Yet something to improve:
[auto build test ERROR on tip/auto-latest]
[also build test ERROR on next-20191129]
[cannot apply to tip/x86/core kvm/linux-next v5.4]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Sean-Christopherson/x86-cpu-Clean-up-handling-of-VMX-features/20191128-094556 base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git e445033e58108a9891abfbc0dea90b066a75e4a9 config: x86_64-randconfig-s0-20191128 (attached as .config) compiler: gcc-7 (Debian 7.4.0-14) 7.4.0 reproduce: # save the attached .config to linux build tree make ARCH=x86_64
If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
In file included from arch/x86/include/asm/processor.h:22:0,
from arch/x86/include/asm/cpufeature.h:5,
from arch/x86/include/asm/thread_info.h:53,
from include/linux/thread_info.h:38,
from arch/x86/include/asm/preempt.h:7,
from include/linux/preempt.h:78,
from include/linux/percpu.h:6,
from include/linux/cpuidle.h:14,
from drivers/idle/intel_idle.c:45:
drivers/idle/intel_idle.c: In function 'sklh_idle_state_table_update':
>> drivers/idle/intel_idle.c:1287:10: error: 'MSR_IA32_FEATURE_CONTROL' undeclared (first use in this function); did you mean 'MSR_MISC_FEATURE_CONTROL'?
rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
^
arch/x86/include/asm/msr.h:279:28: note: in definition of macro 'rdmsrl'
((val) = native_read_msr((msr)))
^~~
drivers/idle/intel_idle.c:1287:10: note: each undeclared identifier is reported only once for each function it appears in
rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
^
arch/x86/include/asm/msr.h:279:28: note: in definition of macro 'rdmsrl'
((val) = native_read_msr((msr)))
^~~vim +1287 drivers/idle/intel_idle.c
5dcef694860100 Len Brown 2016-04-06 1189
5dcef694860100 Len Brown 2016-04-06 1190 /*
5dcef694860100 Len Brown 2016-04-06 1191 * Translate IRTL (Interrupt Response Time Limit) MSR to usec
5dcef694860100 Len Brown 2016-04-06 1192 */
5dcef694860100 Len Brown 2016-04-06 1193
5dcef694860100 Len Brown 2016-04-06 1194 static unsigned int irtl_ns_units[] = {
5dcef694860100 Len Brown 2016-04-06 1195 1, 32, 1024, 32768, 1048576, 33554432, 0, 0 };
5dcef694860100 Len Brown 2016-04-06 1196
5dcef694860100 Len Brown 2016-04-06 1197 static unsigned long long irtl_2_usec(unsigned long long irtl)
5dcef694860100 Len Brown 2016-04-06 1198 {
5dcef694860100 Len Brown 2016-04-06 1199 unsigned long long ns;
5dcef694860100 Len Brown 2016-04-06 1200
3451ab3ebf92b1 Jan Beulich 2016-06-27 1201 if (!irtl)
3451ab3ebf92b1 Jan Beulich 2016-06-27 1202 return 0;
3451ab3ebf92b1 Jan Beulich 2016-06-27 1203
bef450962597ff Jan Beulich 2016-06-27 1204 ns = irtl_ns_units[(irtl >> 10) & 0x7];
5dcef694860100 Len Brown 2016-04-06 1205
5dcef694860100 Len Brown 2016-04-06 1206 return div64_u64((irtl & 0x3FF) * ns, 1000);
5dcef694860100 Len Brown 2016-04-06 1207 }
5dcef694860100 Len Brown 2016-04-06 1208 /*
5dcef694860100 Len Brown 2016-04-06 1209 * bxt_idle_state_table_update(void)
5dcef694860100 Len Brown 2016-04-06 1210 *
5dcef694860100 Len Brown 2016-04-06 1211 * On BXT, we trust the IRTL to show the definitive maximum latency
5dcef694860100 Len Brown 2016-04-06 1212 * We use the same value for target_residency.
5dcef694860100 Len Brown 2016-04-06 1213 */
5dcef694860100 Len Brown 2016-04-06 1214 static void bxt_idle_state_table_update(void)
5dcef694860100 Len Brown 2016-04-06 1215 {
5dcef694860100 Len Brown 2016-04-06 1216 unsigned long long msr;
3451ab3ebf92b1 Jan Beulich 2016-06-27 1217 unsigned int usec;
5dcef694860100 Len Brown 2016-04-06 1218
5dcef694860100 Len Brown 2016-04-06 1219 rdmsrl(MSR_PKGC6_IRTL, msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1220 usec = irtl_2_usec(msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1221 if (usec) {
5dcef694860100 Len Brown 2016-04-06 1222 bxt_cstates[2].exit_latency = usec;
5dcef694860100 Len Brown 2016-04-06 1223 bxt_cstates[2].target_residency = usec;
5dcef694860100 Len Brown 2016-04-06 1224 }
5dcef694860100 Len Brown 2016-04-06 1225
5dcef694860100 Len Brown 2016-04-06 1226 rdmsrl(MSR_PKGC7_IRTL, msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1227 usec = irtl_2_usec(msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1228 if (usec) {
5dcef694860100 Len Brown 2016-04-06 1229 bxt_cstates[3].exit_latency = usec;
5dcef694860100 Len Brown 2016-04-06 1230 bxt_cstates[3].target_residency = usec;
5dcef694860100 Len Brown 2016-04-06 1231 }
5dcef694860100 Len Brown 2016-04-06 1232
5dcef694860100 Len Brown 2016-04-06 1233 rdmsrl(MSR_PKGC8_IRTL, msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1234 usec = irtl_2_usec(msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1235 if (usec) {
5dcef694860100 Len Brown 2016-04-06 1236 bxt_cstates[4].exit_latency = usec;
5dcef694860100 Len Brown 2016-04-06 1237 bxt_cstates[4].target_residency = usec;
5dcef694860100 Len Brown 2016-04-06 1238 }
5dcef694860100 Len Brown 2016-04-06 1239
5dcef694860100 Len Brown 2016-04-06 1240 rdmsrl(MSR_PKGC9_IRTL, msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1241 usec = irtl_2_usec(msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1242 if (usec) {
5dcef694860100 Len Brown 2016-04-06 1243 bxt_cstates[5].exit_latency = usec;
5dcef694860100 Len Brown 2016-04-06 1244 bxt_cstates[5].target_residency = usec;
5dcef694860100 Len Brown 2016-04-06 1245 }
5dcef694860100 Len Brown 2016-04-06 1246
5dcef694860100 Len Brown 2016-04-06 1247 rdmsrl(MSR_PKGC10_IRTL, msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1248 usec = irtl_2_usec(msr);
3451ab3ebf92b1 Jan Beulich 2016-06-27 1249 if (usec) {
5dcef694860100 Len Brown 2016-04-06 1250 bxt_cstates[6].exit_latency = usec;
5dcef694860100 Len Brown 2016-04-06 1251 bxt_cstates[6].target_residency = usec;
5dcef694860100 Len Brown 2016-04-06 1252 }
5dcef694860100 Len Brown 2016-04-06 1253
5dcef694860100 Len Brown 2016-04-06 1254 }
d70e28f57e14a4 Len Brown 2016-03-13 1255 /*
d70e28f57e14a4 Len Brown 2016-03-13 1256 * sklh_idle_state_table_update(void)
d70e28f57e14a4 Len Brown 2016-03-13 1257 *
d70e28f57e14a4 Len Brown 2016-03-13 1258 * On SKL-H (model 0x5e) disable C8 and C9 if:
d70e28f57e14a4 Len Brown 2016-03-13 1259 * C10 is enabled and SGX disabled
d70e28f57e14a4 Len Brown 2016-03-13 1260 */
d70e28f57e14a4 Len Brown 2016-03-13 1261 static void sklh_idle_state_table_update(void)
d70e28f57e14a4 Len Brown 2016-03-13 1262 {
d70e28f57e14a4 Len Brown 2016-03-13 1263 unsigned long long msr;
d70e28f57e14a4 Len Brown 2016-03-13 1264 unsigned int eax, ebx, ecx, edx;
d70e28f57e14a4 Len Brown 2016-03-13 1265
d70e28f57e14a4 Len Brown 2016-03-13 1266
d70e28f57e14a4 Len Brown 2016-03-13 1267 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
d70e28f57e14a4 Len Brown 2016-03-13 1268 if (max_cstate <= 7)
d70e28f57e14a4 Len Brown 2016-03-13 1269 return;
d70e28f57e14a4 Len Brown 2016-03-13 1270
d70e28f57e14a4 Len Brown 2016-03-13 1271 /* if PC10 not present in CPUID.MWAIT.EDX */
d70e28f57e14a4 Len Brown 2016-03-13 1272 if ((mwait_substates & (0xF << 28)) == 0)
d70e28f57e14a4 Len Brown 2016-03-13 1273 return;
d70e28f57e14a4 Len Brown 2016-03-13 1274
6cfb2374f83bc7 Len Brown 2017-01-07 1275 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr);
d70e28f57e14a4 Len Brown 2016-03-13 1276
d70e28f57e14a4 Len Brown 2016-03-13 1277 /* PC10 is not enabled in PKG C-state limit */
d70e28f57e14a4 Len Brown 2016-03-13 1278 if ((msr & 0xF) != 8)
d70e28f57e14a4 Len Brown 2016-03-13 1279 return;
d70e28f57e14a4 Len Brown 2016-03-13 1280
d70e28f57e14a4 Len Brown 2016-03-13 1281 ecx = 0;
d70e28f57e14a4 Len Brown 2016-03-13 1282 cpuid(7, &eax, &ebx, &ecx, &edx);
d70e28f57e14a4 Len Brown 2016-03-13 1283
d70e28f57e14a4 Len Brown 2016-03-13 1284 /* if SGX is present */
d70e28f57e14a4 Len Brown 2016-03-13 1285 if (ebx & (1 << 2)) {
d70e28f57e14a4 Len Brown 2016-03-13 1286
d70e28f57e14a4 Len Brown 2016-03-13 @1287 rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
d70e28f57e14a4 Len Brown 2016-03-13 1288
d70e28f57e14a4 Len Brown 2016-03-13 1289 /* if SGX is enabled */
d70e28f57e14a4 Len Brown 2016-03-13 1290 if (msr & (1 << 18))
0138d8f0755b5b Len Brown 2014-04-04 1291 return;
0138d8f0755b5b Len Brown 2014-04-04 1292 }
0138d8f0755b5b Len Brown 2014-04-04 1293
d70e28f57e14a4 Len Brown 2016-03-13 1294 skl_cstates[5].disabled = 1; /* C8-SKL */
d70e28f57e14a4 Len Brown 2016-03-13 1295 skl_cstates[6].disabled = 1; /* C9-SKL */
d70e28f57e14a4 Len Brown 2016-03-13 1296 }
d70e28f57e14a4 Len Brown 2016-03-13 1297 /*
d70e28f57e14a4 Len Brown 2016-03-13 1298 * intel_idle_state_table_update()
d70e28f57e14a4 Len Brown 2016-03-13 1299 *
d70e28f57e14a4 Len Brown 2016-03-13 1300 * Update the default state_table for this CPU-id
d70e28f57e14a4 Len Brown 2016-03-13 1301 */
d70e28f57e14a4 Len Brown 2016-03-13 1302 :::::: The code@line 1287 was first introduced by commit
:::::: d70e28f57e14a481977436695b0c9ba165472431 intel_idle: prevent SKL-H boot failure when C8+C9+C10 enabled
:::::: TO: Len Brown <[email protected]>
:::::: CC: Len Brown <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation
Re: [PATCH v4 01/19] x86/msr-index: Clean up bit defines for IA32_FEATURE_CONTROL MSR
Quoted 33 lines · kbuild test robot
Hi Sean,
I love your patch! Yet something to improve:
[auto build test ERROR on tip/auto-latest]
[also build test ERROR on next-20191129]
[cannot apply to tip/x86/core kvm/linux-next v5.4]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]url: https://github.com/0day-ci/linux/commits/Sean-Christopherson/x86-cpu-Clean-up-handling-of-VMX-features/20191128-094556 base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git e445033e58108a9891abfbc0dea90b066a75e4a9 config: x86_64-randconfig-s0-20191128 (attached as .config) compiler: gcc-7 (Debian 7.4.0-14) 7.4.0 reproduce: # save the attached .config to linux build tree make ARCH=x86_64If you fix the issue, kindly add following tag
Reported-by kbuild test robot <[email protected]>All errors (new ones prefixed by >>):
In file included from
arch/x86/include/asm/processor.h:22:0,from arch/x86/include/asm/cpufeature.h:5, from arch/x86/include/asm/thread_info.h:53, from include/linux/thread_info.h:38, from arch/x86/include/asm/preempt.h:7, from include/linux/preempt.h:78, from include/linux/percpu.h:6, from include/linux/cpuidle.h:14, from drivers/idle/intel_idle.c:45:
Quoted 4 lines
drivers/idle/intel_idle.c: In function 'sklh_idle_state_table_update':Quoted 1 line
Quoted 1 line
drivers/idle/intel_idle.c:1287:10: error: 'MSR_IA32_FEATURE_CONTROL' undeclared (first use in this function); did you mean 'MSR_MISC_FEATURE_CONTROL'?rdmsrl(MSR_IA32_FEATURE_CONTROL, msr); ^
Argh, flat out missed this when doing search and replace.
Quoted 11 lines
arch/x86/include/asm/msr.h:279:28: note: in definition of macro 'rdmsrl' ((val) = native_read_msr((msr))) ^~~ drivers/idle/intel_idle.c:1287:10: note: each undeclared identifier is reported only once for each function it appears in rdmsrl(MSR_IA32_FEATURE_CONTROL, msr); ^ arch/x86/include/asm/msr.h:279:28: note: in definition of macro 'rdmsrl' ((val) = native_read_msr((msr))) ^~~vim +1287
drivers/idle/intel_idle.c
Borislav Petkov
maintainerRe: [PATCH v4 01/19] x86/msr-index: Clean up bit defines for IA32_FEATURE_CONTROL MSR
Quoted 1 line · Sean Christopherson
Argh, flat out missed this when doing search and replace.
There are more. What always works reliably for me is git grep:
$ git grep MSR_IA32_FEATURE_CONTROL drivers/idle/intel_idle.c:1287: rdmsrl(MSR_IA32_FEATURE_CONTROL, msr); tools/arch/x86/include/asm/msr-index.h:561:#define MSR_IA32_FEATURE_CONTROL 0x0000003a tools/power/x86/turbostat/turbostat.c:4502: if (!get_msr(base_cpu, MSR_IA32_FEATURE_CONTROL, &msr)) tools/power/x86/turbostat/turbostat.c:4503: fprintf(outf, "cpu%d: MSR_IA32_FEATURE_CONTROL: 0x%08llx (%sLocked %s)\n", tools/testing/selftests/kvm/include/x86_64/processor.h:771:#define MSR_IA32_FEATURE_CONTROL 0x0000003a tools/testing/selftests/kvm/lib/x86_64/vmx.c:162: feature_control = rdmsr(MSR_IA32_FEATURE_CONTROL); tools/testing/selftests/kvm/lib/x86_64/vmx.c:164: wrmsr(MSR_IA32_FEATURE_CONTROL, feature_control | required);
those additional ones won't break the build but it is perhaps worth unifying them all since we're at it, anyway.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteBorislav Petkov
maintainerRe: [PATCH v4 10/19] x86/cpu: Detect VMX features on Intel, Centaur and Zhaoxin CPUs
In reply to Sean ChristophersonQuoted 9 lines · Sean Christopherson
arch/x86/kernel/cpu/feat_ctl.c +1
-0@@ -4,6 +4,72 @@#include <asm/cpufeature.h> #include <asm/msr-index.h> #include <asm/processor.h> +#include <asm/vmx.h>
arch/x86/kernel/cpu/feat_ctl.c line 17
Quoted 10 lines
arch/x86/kernel/cpu/feat_ctl.c +10
-0+ +#ifdef CONFIG_X86_VMX_FEATURE_NAMES +enum vmx_feature_leafs { +MISC_FEATURES =0 , +PRIMARY_PROC_CTLS , +SECONDARY_PROC_CTLS , +NR_VMX_FEATURE_WORDS , +}; + +#define F (x) BIT(VMX_FEATURE_##x & 0x1f)
Eww, this F-thing has been always bugging me, especially if it means something a little different each time:
arch/x86/crypto/blowfish-x86_64-asm_64.S:59:#define F() \
arch/x86/kernel/cpu/feat_ctl.c:17:#define F(x) BIT(VMX_FEATURE_##x & 0x1f) arch/x86/kvm/cpuid.c:65:#define F(x) bit(X86_FEATURE_##x) arch/x86/kvm/emulate.c:4393:#define F(_f, _e) { .flags = (_f) | Fastop, .u.fastop = (_e) } arch/x86/kvm/svm.c:5927:#define F(x) bit(X86_FEATURE_##x)
I guess you can call yours VMX_F() or so, just so that it's name is something different.
Quoted 16 lines
arch/x86/kernel/cpu/feat_ctl.c +16
-0+static void init_vmx_capabilities (struct cpuinfo_x86 *c) +{ +u32 supported, funcs, ept, vpid, ign; + +BUILD_BUG_ON (NVMXINTS !=NR_VMX_FEATURE_WORDS ); + +/* +* The high bits contain the allowed-1 settings, i.e. features that can +* be turned on. The low bits contain the allowed-0 settings, i.e. +* features that can be turned off. Ignore the allowed-0 settings, +* if a feature can be turned on then it's supported. +*/ +rdmsr (MSR_IA32_VMX_PROCBASED_CTLS , ign, supported); + c->vmx_capability[PRIMARY_PROC_CTLS ] = supported; + +rdmsr_safe (MSR_IA32_VMX_PROCBASED_CTLS2 , &ign, &supported);
arch/x86/kernel/cpu/feat_ctl.c line 44
Quoted 10 lines
arch/x86/kernel/cpu/feat_ctl.c +10
-0+ c->vmx_capability[SECONDARY_PROC_CTLS ] = supported; + +rdmsr (MSR_IA32_VMX_PINBASED_CTLS , ign, supported); +rdmsr_safe (MSR_IA32_VMX_VMFUNC , &ign, &funcs); + +/* +* Except for EPT+VPID, which enumerates support for both in a single +* MSR, low for EPT, high for VPID. +*/ +rdmsr_safe (MSR_IA32_VMX_EPT_VPID_CAP , &ept, &vpid);
Right, so this is a garden variety of rdmsr() and rdmsr_safe() and the safe variant's retval needs to be checked, strictly speaking. It probably doesn't matter here since you'll get 0s if it fails, which means feature not supported, so all good.
But I guess you can still use rdmsr_safe() everywhere just so it doesn't cause head scratching in the future, when one looks at that code.
arch/x86/kernel/cpu/feat_ctl.c void init_ia32_feat_ctl(struct cpuinfo_x86 *c) · line 122
Quoted 12 lines
arch/x86/kernel/cpu/feat_ctl.c +5
-0+#endif /* CONFIG_X86_VMX_FEATURE_NAMES */ #undef pr_fmt#define pr_fmt (fmt) "x86/cpu: " fmt@@ -50,5 +116,9 @@ void init_ia32_feat_ctl(struct cpuinfo_x86 *c)pr_err_once ("VMX (%s TXT) disabled by BIOS\n" , tboot ?"inside" :"outside" );clear_cpu_cap (c,X86_FEATURE_VMX ); + }else { +#ifdef CONFIG_X86_VMX_FEATURE_NAMES +init_vmx_capabilities (c); +#endif
Can't say that I'm happy about all that ifdeffery but I guess we need to perpetuate this since X86_FEATURE_NAMES is there for embedded. In practice, probably no one disables it...
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteBorislav Petkov
maintainerRe: [PATCH v4 11/19] x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
In reply to Sean ChristophersonQuoted 11 lines · Sean Christopherson
Add support for generating VMX feature names in
capflags.cand use the resultingx86_vmx_flagsto print the VMX flags in/proc/cpuinfo. Don't print VMX flags if no bits are set in word 0, which holds Pin Controls. Pin Control's INTR and NMI exiting are fundamental pillars of VMX, if they are not supported then the CPU is broken, it does not actually support VMX, or the kernel wasn't built with support for the target CPU.Print the features in a dedicated "vmx flags" line to avoid polluting the common "flags" and to avoid having to prefix all flags with "
vmx_", which results in horrendously long names.
Quoted 6 lines
Keep synthetic VMX flags in cpufeatures to preserve /proc/cpuinfo's ABI for those flags. This means that "flags" and "vmx flags" will have duplicate entries for
tpr_shadow(virtual_tpr), vnmi (virtual_nmis), ept, flexpriority, vpid andept_ad, but caps the pollution of "flags" at those six VMX features. The vendor specific code that populates the synthetic flags will be consolidated in a future patch to futher
^
further
arch/x86/kernel/cpu/proc.c static int show_cpuinfo(struct seq_file *m, void *v) · line 118
Quoted 10 lines
arch/x86/kernel/cpu/proc.c +10
-0+#ifdef CONFIG_X86_VMX_FEATURE_NAMES +if (cpu_has (c,X86_FEATURE_VMX ) && c->vmx_capability[0 ]) { +seq_puts (m,"\nvmx flags\t:" ); +for (i =0 ; i <32 *NVMXINTS ; i++) { +if (test_bit (i, (unsigned long *)c->vmx_capability) && + x86_vmx_flags[i] !=NULL ) +seq_printf (m," %s" , x86_vmx_flags[i]); + } + } +#endif
Oh well, some could be shorter:
vmx flags : virtual_nmis preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offsetting virtual_tpr mtf virt_apic_accesses ept vpid unrestricted_guest ple shadow_vmcs pml mode_based_ept_exec
virtual_nmis -> vnmispreemption_timer -> preempt_tmr
flexpriority -> flexpriotsc_offsetting -> tsc_ofsvirtual_tpr -> vtprvirt_apic_accesses -> vapicunrestricted_guest -> unres_guest
and so on. Those are just my examples - I betcha the SDM is more creative here with abbreviations. But you guys are going to grep for them. If it were me, I'd save on typing. :-)
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteBorislav Petkov
maintainerQuoted 9 lines · Sean Christopherson
Clean up a handful of interrelated warts in the kernel's handling of VMX:
- Enable VMX in
IA32_FEATURE_CONTROLduring boot instead of on-demand during KVM load to avoid future contention overIA32_FEATURE_CONTROL.- Rework VMX feature reporting so that it is accurate and up-to-date, now and in the future.
- Consolidate code across CPUs that support VMX.
Ok, this is shaping up slowly to be upstream-ready, AFAICT.
How are we merging the next revision, after the minor things have been taken care of? Through tip?
Paolo?
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquettePaolo Bonzini
maintainerRe: [PATCH v4 11/19] x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
In reply to Borislav PetkovQuoted 4 lines · Borislav Petkov
vmx flags :
virtual_nmispreemption_timerinvvpidept_x_onlyept_adept_1gbflexprioritytsc_offsettingvirtual_tprmtfvirt_apic_accessesept vpidunrestricted_guestpleshadow_vmcspmlmode_based_ept_exec
virtual_nmis-> vnmis
Even vnmi
Quoted 1 line
preemption_timer->preempt_tmr
I would prefer the full one here.
Quoted 1 line
flexpriority -> flexprio
Full name?
Quoted 1 line
tsc_offsetting->tsc_ofs
tsc_offset?
Quoted 1 line
virtual_tpr-> vtpr
Do we need this? It's usually included together with flexpriority.
Quoted 1 line
virt_apic_accesses-> vapic
apicv
Quoted 1 line
unrestricted_guest->unres_guest
Full? Or just unrestricted
In general I would stick to the same names as kvm_intel module parameters (sans "enable_" if applicable) and not even bother publishing the others. Some features are either not used by KVM or available on all VMX processors.
Paolo
Quoted 3 lines
and so on. Those are just my examples - I betcha the SDM is more creative here with abbreviations. But you guys are going to grep for them. If it were me, I'd save on typing. :-)
Re: [PATCH v4 11/19] x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
Quoted 24 lines · Paolo Bonzini
Quoted 4 lines · Borislav Petkov
vmx flags :
virtual_nmispreemption_timerinvvpidept_x_onlyept_adept_1gbflexprioritytsc_offsettingvirtual_tprmtfvirt_apic_accessesept vpidunrestricted_guestpleshadow_vmcspmlmode_based_ept_exec
virtual_nmis-> vnmisEven vnmi
Quoted 1 line
preemption_timer->preempt_tmrI would prefer the full one here.
Quoted 1 line
flexpriority -> flexprio
Full name?
Quoted 1 line
tsc_offsetting->tsc_ofs
tsc_offset?
Quoted 7 lines
Quoted 1 line
virtual_tpr-> vtprDo we need this? It's usually included together with flexpriority.
Quoted 1 line
virt_apic_accesses-> vapicapicv
Frankly, I dislike APICv terminology. I prefer to enumerate the various VMX features which are collectively called APICv by KVM.
APICv currently represents in KVM terminology the combination of APIC-register virtualization, virtual-interrupt-delivery and posted-interrupts (See cpu_has_vmx_apicv()).
In fact, the coupling of “enable_apicv” module parameter have made me multiple times to need to disable entire APICv features when there for example was only a bug in posted-interrupts.
Even you got confused as virtualize-apic-access is not part of KVM’s APICv terminology but rather it’s enablement depend on flexpriority_enabled (See cpu_need_virtualize_apic_accesses()). i.e. It can be used for faster intercept handling of accesses to guest xAPIC MMIO page.
Quoted 4 lines
Quoted 2 lines
unrestricted_guest->unres_guestFull? Or just unrestricted
I prefer unrestricted_guest.
Quoted 12 lines
In general I would stick to the same names as
kvm_intelmodule parameters (sans "enable_" if applicable) and not even bother publishing the others. Some features are either not used by KVM or available on all VMX processors.Paolo
Quoted 3 lines
and so on. Those are just my examples - I betcha the SDM is more creative here with abbreviations. But you guys are going to grep for them. If it were me, I'd save on typing. :-)
Paolo Bonzini
maintainerRe: [PATCH v4 11/19] x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
Quoted 12 lines · Liran Alon
Quoted 2 lines
Quoted 1 line
virt_apic_accesses-> vapicapicv
Frankly, I dislike APICv terminology. I prefer to enumerate the various VMX features which are collectively called APICv by KVM. APICv currently represents in KVM terminology the combination of APIC-register virtualization, virtual-interrupt-delivery and posted-interrupts (See
cpu_has_vmx_apicv()).In fact, the coupling of “enable_apicv” module parameter have made me multiple times to need to disable entire APICv features when there for example was only a bug in posted-interrupts.
Quoted 5 lines
Even you got confused as virtualize-apic-access is not part of KVM’s APICv terminology but rather it’s enablement depend on
flexpriority_enabled(Seecpu_need_virtualize_apic_accesses()). i.e. It can be used for faster intercept handling of accesses to guest xAPIC MMIO page.
Right, I got confused with APIC-register virtualization. Virtualize APIC accesses is another one I wouldn't bother putting in /proc/cpuinfo, since it's usually present together with flexpriority.
Paolo
Re: [PATCH v4 11/19] x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
Quoted 19 lines · Paolo Bonzini
Quoted 12 lines · Liran Alon
Quoted 2 lines
Quoted 1 line
virt_apic_accesses-> vapicapicv
Frankly, I dislike APICv terminology. I prefer to enumerate the various VMX features which are collectively called APICv by KVM. APICv currently represents in KVM terminology the combination of APIC-register virtualization, virtual-interrupt-delivery and posted-interrupts (See
cpu_has_vmx_apicv()).In fact, the coupling of “enable_apicv” module parameter have made me multiple times to need to disable entire APICv features when there for example was only a bug in posted-interrupts.
Quoted 5 lines
Even you got confused as virtualize-apic-access is not part of KVM’s APICv terminology but rather it’s enablement depend on
flexpriority_enabled(Seecpu_need_virtualize_apic_accesses()). i.e. It can be used for faster intercept handling of accesses to guest xAPIC MMIO page.
Quoted 3 lines
Right, I got confused with APIC-register virtualization. Virtualize APIC accesses is another one I wouldn't bother putting in
/proc/cpuinfo, since it's usually present together with flexpriority.
Key word being "usually". My intent in printing out partially redundant flags was to help users debug/understand why the combined feature isn't supported. E.g. userspace can already easily (relatively speaking) query flexpriority support via /sys/module/kvm_intel/parameters/flexpriority. But if that comes back "N", the user has no way to determine exactly why flexpriority is disabled.
Paolo Bonzini
maintainerRe: [PATCH v4 11/19] x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
Quoted 6 lines · Sean Christopherson
Key word being "usually". My intent in printing out partially redundant flags was to help users debug/understand why the combined feature isn't supported. E.g. userspace can already easily (relatively speaking) query flexpriority support via
/sys/module/kvm_intel/parameters/flexpriority. But if that comes back "N", the user has no way to determine exactly why flexpriority is disabled.
There are tools such as vmxcap. It is part of QEMU, but I wouldn't mind moving it into the kernel tree.
Paolo
Re: [PATCH v4 01/19] x86/msr-index: Clean up bit defines for IA32_FEATURE_CONTROL MSR
In reply to Borislav PetkovQuoted 14 lines · Borislav Petkov
Quoted 1 line · Sean Christopherson
Argh, flat out missed this when doing search and replace.
There are more. What always works reliably for me is git grep:
$ git grep MSR_IA32_FEATURE_CONTROL drivers/idle/intel_idle.c:1287: rdmsrl(MSR_IA32_FEATURE_CONTROL, msr); tools/arch/x86/include/asm/msr-index.h:561:#define MSR_IA32_FEATURE_CONTROL 0x0000003a tools/power/x86/turbostat/turbostat.c:4502: if (!get_msr(base_cpu, MSR_IA32_FEATURE_CONTROL, &msr)) tools/power/x86/turbostat/turbostat.c:4503: fprintf(outf, "cpu%d: MSR_IA32_FEATURE_CONTROL: 0x%08llx (%sLocked %s)\n", tools/testing/selftests/kvm/include/x86_64/processor.h:771:#define MSR_IA32_FEATURE_CONTROL 0x0000003a tools/testing/selftests/kvm/lib/x86_64/vmx.c:162: feature_control = rdmsr(MSR_IA32_FEATURE_CONTROL); tools/testing/selftests/kvm/lib/x86_64/vmx.c:164: wrmsr(MSR_IA32_FEATURE_CONTROL, feature_control | required);
Quoted 2 lines
those additional ones won't break the build but it is perhaps worth unifying them all since we're at it, anyway.
I caught all the tools updates and addressed them in patch 03/19, "tools arch x86: Sync msr-index.h from kernel sources". Do you want those changes folded into the rename itself?
Re: [PATCH v4 11/19] x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
In reply to Sean ChristophersonQuoted 28 lines · Sean Christopherson
Quoted 19 lines · Paolo Bonzini
Quoted 12 lines · Liran Alon
Quoted 2 lines
Quoted 1 line
virt_apic_accesses-> vapicapicv
Frankly, I dislike APICv terminology. I prefer to enumerate the various VMX features which are collectively called APICv by KVM. APICv currently represents in KVM terminology the combination of APIC-register virtualization, virtual-interrupt-delivery and posted-interrupts (See
cpu_has_vmx_apicv()).In fact, the coupling of “enable_apicv” module parameter have made me multiple times to need to disable entire APICv features when there for example was only a bug in posted-interrupts.
Quoted 5 lines
Even you got confused as virtualize-apic-access is not part of KVM’s APICv terminology but rather it’s enablement depend on
flexpriority_enabled(Seecpu_need_virtualize_apic_accesses()). i.e. It can be used for faster intercept handling of accesses to guest xAPIC MMIO page.Quoted 3 lines
Right, I got confused with APIC-register virtualization. Virtualize APIC accesses is another one I wouldn't bother putting in
/proc/cpuinfo, since it's usually present together with flexpriority.
Quoted 6 lines
Key word being "usually". My intent in printing out partially redundant flags was to help users debug/understand why the combined feature isn't supported. E.g. userspace can already easily (relatively speaking) query flexpriority support via
/sys/module/kvm_intel/parameters/flexpriority. But if that comes back "N", the user has no way to determine exactly why flexpriority is disabled.
+1 on that.
/proc/cpuinfo should just dump supported VMX features that kernel is aware of as exposed from CPU. Without further processing.
Re: [PATCH v4 10/19] x86/cpu: Detect VMX features on Intel, Centaur and Zhaoxin CPUs
In reply to Borislav PetkovQuoted 33 lines · Borislav Petkov
Quoted 16 lines · Sean Christopherson
arch/x86/kernel/cpu/feat_ctl.c +16
-0+static void init_vmx_capabilities (struct cpuinfo_x86 *c) +{ +u32 supported, funcs, ept, vpid, ign; + +BUILD_BUG_ON (NVMXINTS !=NR_VMX_FEATURE_WORDS ); + +/* +* The high bits contain the allowed-1 settings, i.e. features that can +* be turned on. The low bits contain the allowed-0 settings, i.e. +* features that can be turned off. Ignore the allowed-0 settings, +* if a feature can be turned on then it's supported. +*/ +rdmsr (MSR_IA32_VMX_PROCBASED_CTLS , ign, supported); + c->vmx_capability[PRIMARY_PROC_CTLS ] = supported; + +rdmsr_safe (MSR_IA32_VMX_PROCBASED_CTLS2 , &ign, &supported);arch/x86/kernel/cpu/feat_ctl.c line 44
Quoted 10 lines
arch/x86/kernel/cpu/feat_ctl.c +10
-0+ c->vmx_capability[SECONDARY_PROC_CTLS ] = supported; + +rdmsr (MSR_IA32_VMX_PINBASED_CTLS , ign, supported); +rdmsr_safe (MSR_IA32_VMX_VMFUNC , &ign, &funcs); + +/* +* Except for EPT+VPID, which enumerates support for both in a single +* MSR, low for EPT, high for VPID. +*/ +rdmsr_safe (MSR_IA32_VMX_EPT_VPID_CAP , &ept, &vpid);Right, so this is a garden variety of
rdmsr()andrdmsr_safe()and the safe variant's retval needs to be checked, strictly speaking. It probably doesn't matter here since you'll get 0s if it fails, which means feature not supported, so all good.
Quoted 2 lines
But I guess you can still use
rdmsr_safe()everywhere just so it doesn't cause head scratching in the future, when one looks at that code.
The reasoning behind using vanilla rdmsr() on PROC and PIN controls is that those MSRs should exist on any CPU that supports VMX, i.e. we want the WARN.
The alternative would be to use rdmsr_safe() for everything and then explicitly disable VMX if a fault on PROC or PIN occurs, but that circles us back to the handling a fault on rdmsr(MSR_IA32_FEAT_CTL), i.e. is it really worth gracefully handling a fault that should never occur?
Quoted 17 lines
arch/x86/kernel/cpu/feat_ctl.c void init_ia32_feat_ctl(struct cpuinfo_x86 *c) · line 122
Quoted 13 lines
arch/x86/kernel/cpu/feat_ctl.c +5
-0+#endif /* CONFIG_X86_VMX_FEATURE_NAMES */ #undef pr_fmt#define pr_fmt (fmt) "x86/cpu: " fmt@@ -50,5 +116,9 @@ void init_ia32_feat_ctl(struct cpuinfo_x86 *c)pr_err_once ("VMX (%s TXT) disabled by BIOS\n" , tboot ?"inside" :"outside" );clear_cpu_cap (c,X86_FEATURE_VMX ); + }else { +#ifdef CONFIG_X86_VMX_FEATURE_NAMES +init_vmx_capabilities (c); +#endif Can't say that I'm happy about all that ifdeffery but I guess we need to perpetuate this since
X86_FEATURE_NAMESis there for embedded. In practice, probably no one disables it...
Ya, systemd wasn't happy when I tried booting without X86_FEATURE_NAMES.
Re: [PATCH v4 11/19] x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
In reply to Paolo BonziniQuoted 12 lines · Paolo Bonzini
Quoted 6 lines · Sean Christopherson
Key word being "usually". My intent in printing out partially redundant flags was to help users debug/understand why the combined feature isn't supported. E.g. userspace can already easily (relatively speaking) query flexpriority support via
/sys/module/kvm_intel/parameters/flexpriority. But if that comes back "N", the user has no way to determine exactly why flexpriority is disabled.
Quoted 5 lines
There are tools such as vmxcap. It is part of QEMU, but I wouldn't mind moving it into the kernel tree.
Paolo
True. But it relies on /dev/msr0 (exposed from msr kernel module) to be able to read any host arbitrary MSR. It’s much more elegant to just report CPU VMX features in a /proc/cpuinfo pseudo-file and don’t require strong privileges. Why should CPU VMX features be treated differently than standard CPUID deduced features?
CPU SVM features are also present in /proc/cpuinfo today (Because they are deduced from CPUID leafs). So it should be similar.
-Liran
Re: [PATCH v4 11/19] x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
Quoted 1 line · Liran Alon
Why should CPU VMX features be treated differently than standard CPUID deduced features?
Do we have the right Intel people on the recipient list to answer this question? Presumably, Intel felt that this information should be available in supervisor mode only.
Sean?
Re: [PATCH v4 11/19] x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
Quoted 13 lines · Jim Mattson
Quoted 1 line · Liran Alon
Why should CPU VMX features be treated differently than standard CPUID deduced features?
Do we have the right Intel people on the recipient list to answer this question? Presumably, Intel felt that this information should be available in supervisor mode only.
Sean?
Good question. Probably because it just makes sense that Ring3 will never need to use this info as all VMX instructions are privileged. i.e. Can only be executed in Ring0.
De-facto in KVM we have discovered this assumption to be problematic BTW, as KVM created an interface to query VMX MSRs values to properly define the requested vCPU model. :P (See kvm_get_msr_feature())
Borislav Petkov
maintainerRe: [PATCH v4 01/19] x86/msr-index: Clean up bit defines for IA32_FEATURE_CONTROL MSR
In reply to Sean ChristophersonQuoted 3 lines · Sean Christopherson
I caught all the tools updates and addressed them in patch 03/19, "tools arch x86: Sync
msr-index.hfrom kernel sources". Do you want those changes folded into the rename itself?
Nah, it's ok as it is.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquettePaolo Bonzini
maintainerRe: [PATCH v4 11/19] x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
In reply to Sean ChristophersonQuoted 6 lines · Sean Christopherson
Using v<feature> across the board makes sense to keep things consistent, i.e. vnmi, vtpr, vapic, etc...
Anyone have thoughts on how to shorten "APIC-register virtualization" without colliding with vapic or apicv? I currently have
apic_reg_virt, which is a bit wordy.apic_regvisn't awful, but I don't love it.
Perhaps vapic_access and vapic_register?
Quoted 3 lines
The other control that will be awkard is "Virtual Interrupt Delivery".
vint_delivery?
We can just use vid I think. And posted_intr.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
unrestricted_guest->unres_guestFull? Or just unrestricted
I prefer
unrestricted_guest, a bare unrestricted just makes me wonder
"unrestricted what?". But I can live with "unrestricted" if that's the
consensus.
I do prefer unrestricted_guest actually.
Quoted 18 lines
Quoted 4 lines
In general I would stick to the same names as
kvm_intelmodule parameters (sans "enable_" if applicable) and not even bother publishing the others. Some features are either not used by KVM or available on all VMX processors.IMO there's value in printing features that are not 1:1 with module params.
I also think it makes sense to print features of interest even if KVM doesn't (yet) support the feature, e.g. to allow a user/developer to check if they can use/test a KVM build with support for a new feature without having to build and install the new kernel.
Quoted 5 lines
Paolo
Quoted 3 lines
and so on. Those are just my examples - I betcha the SDM is more creative here with abbreviations. But you guys are going to grep for them. If it were me, I'd save on typing. :-)
Borislav Petkov
maintainerRe: [PATCH v4 10/19] x86/cpu: Detect VMX features on Intel, Centaur and Zhaoxin CPUs
In reply to Sean ChristophersonQuoted 7 lines · Sean Christopherson
The reasoning behind using vanilla
rdmsr()on PROC and PIN controls is that those MSRs should exist on any CPU that supports VMX, i.e. we want the WARN.The alternative would be to use
rdmsr_safe()for everything and then explicitly disable VMX if a fault on PROC or PIN occurs, but that circles us back to the handling a fault onrdmsr(MSR_IA32_FEAT_CTL), i.e. is it really worth gracefully handling a fault that should never occur?
No but pls put a comment above it explaining why we're doing rdmsr() only with those two MSRs.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v4 11/19] x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
In reply to Paolo BonziniQuoted 3 lines · Paolo Bonzini
Quoted 2 lines · Borislav Petkov
vmx flags :
virtual_nmispreemption_timerinvvpidept_x_onlyept_adept_1gbflexprioritytsc_offsettingvirtual_tprmtfvirt_apic_accessesept vpidunrestricted_guestpleshadow_vmcspmlmode_based_ept_exec
Tying into the consistency comment below, any objection to always prefixing "ept" for relevant controls instead of following the SDM? Specifically, that would yield ept_mode_based_exec and ept_spp
Quoted 9 lines
Quoted 2 lines
virtual_nmis-> vnmisEven vnmi
Quoted 1 line
preemption_timer->preempt_tmrI would prefer the full one here.
Quoted 7 lines
Quoted 1 line
flexpriority -> flexprio
Full name?
Quoted 1 line
tsc_offsetting->tsc_ofs
tsc_offset?
I'll go with tsc_offset.
Quoted 5 lines
Quoted 1 line
virtual_tpr-> vtprDo we need this? It's usually included together with flexpriority.
Quoted 1 line
virt_apic_accesses-> vapic
Using v<feature> across the board makes sense to keep things consistent, i.e. vnmi, vtpr, vapic, etc...
Anyone have thoughts on how to shorten "APIC-register virtualization" without colliding with vapic or apicv? I currently have apic_reg_virt, which is a bit wordy. apic_regv isn't awful, but I don't love it.
The other control that will be awkard is "Virtual Interrupt Delivery". vint_delivery?
Quoted 3 lines
Quoted 1 line
unrestricted_guest->unres_guestFull? Or just unrestricted
I prefer unrestricted_guest, a bare unrestricted just makes me wonder
"unrestricted what?". But I can live with "unrestricted" if that's the
consensus.
Quoted 4 lines
In general I would stick to the same names as
kvm_intelmodule parameters (sans "enable_" if applicable) and not even bother publishing the others. Some features are either not used by KVM or available on all VMX processors.
IMO there's value in printing features that are not 1:1 with module params.
I also think it makes sense to print features of interest even if KVM doesn't (yet) support the feature, e.g. to allow a user/developer to check if they can use/test a KVM build with support for a new feature without having to build and install the new kernel.
Quoted 5 lines
Paolo
Quoted 3 lines
and so on. Those are just my examples - I betcha the SDM is more creative here with abbreviations. But you guys are going to grep for them. If it were me, I'd save on typing. :-)
Borislav Petkov
maintainerRe: [PATCH v4 11/19] x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
In reply to Liran AlonQuoted 4 lines · Liran Alon
Why should CPU VMX features be treated differently than standard CPUID deduced features? CPU SVM features are also present in
/proc/cpuinfotoday (Because they are deduced from CPUID leafs). So it should be similar.
Well, VMX features are not CPUID bits apparently because <reasons>. And Intel hw folk will give you a bunch, I bet. So Sean needs to do all this dancing to get them to be more usable to other kernel code.
SVM feature bits are proper CPUID bits and this is what the cpufeatures glue does - mirro CPUID bits, mainly.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v4 11/19] x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
In reply to Liran AlonQuoted 8 lines · Liran Alon
Quoted 8 lines · Jim Mattson
Quoted 1 line · Liran Alon
Why should CPU VMX features be treated differently than standard CPUID deduced features?
Quoted 8 lines
Quoted 5 lines
Do we have the right Intel people on the recipient list to answer this question? Presumably, Intel felt that this information should be available in supervisor mode only.
Sean?
Good question. Probably because it just makes sense that Ring3 will never need to use this info as all VMX instructions are privileged. i.e. Can only be executed in Ring0.
I highly doubt ring0 vs. ring3 was a motivating factor. I suspect the MSR interface is primarily driven by VMX's allowed-0 vs. allowed-1 behavior, which would be awkward to encode in CPUID. Reporting via MSR also likely provided more flexibility for updating/fixing CPU behavior, e.g. patching the RDMSR hook is likely far easier than patching CPUID.
Even if the architects intended the information to be supervisor-only, that's just their opinion, no?
Quoted 3 lines
De-facto in KVM we have discovered this assumption to be problematic BTW, as KVM created an interface to query VMX MSRs values to properly define the requested vCPU model. :P (See
kvm_get_msr_feature())
Quoted 9 lines · Borislav Petkov
Quoted 8 lines · Sean Christopherson
Clean up a handful of interrelated warts in the kernel's handling of VMX:
- Enable VMX in
IA32_FEATURE_CONTROLduring boot instead of on-demand during KVM load to avoid future contention overIA32_FEATURE_CONTROL.- Rework VMX feature reporting so that it is accurate and up-to-date, now and in the future.
Quoted 8 lines
Quoted 1 line
- Consolidate code across CPUs that support VMX.
Ok, this is shaping up slowly to be upstream-ready, AFAICT.
How are we merging the next revision, after the minor things have been taken care of? Through tip?
Paolo?
Tip would be my preference, we'll need to rebase the SGX series on this and tip would probably be slightly more convenient for that.
Re: [PATCH v4 11/19] x86/cpu: Print VMX flags in /proc/cpuinfo using VMX_FEATURES_*
In reply to Paolo BonziniQuoted 9 lines · Paolo Bonzini
Quoted 6 lines · Sean Christopherson
Using v<feature> across the board makes sense to keep things consistent, i.e. vnmi, vtpr, vapic, etc...
Anyone have thoughts on how to shorten "APIC-register virtualization" without colliding with vapic or apicv? I currently have
apic_reg_virt, which is a bit wordy.apic_regvisn't awful, but I don't love it.Perhaps
vapic_accessandvapic_register?
I ended up going with vapic and vapic_reg, figured everyone looking at this knows what "reg" is short for, and I like the progression shown by vapic -> vapic_reg.