KVM: x86: Virtualize AMD's "disable CPUID in usermode"
Subsystems (10)
v4 cover KVM: x86: Virtualize AMD's "disable CPUID in usermode"
AMD's "disable CPUID in usermode" feature is analogous to Intel's "CPUID faulting" feature, but it is advertised and activated differently. The AMD feature is advertised via CPUID.80000021H:EAX.CpuidUserDis[bit 17] and activated by setting HWCR.CpuidUserDis[bit 35].
Add virtualization support for the AMD feature.
v3 -> v4:
* Fix typo in commit message for patch 1 [Binbin]
* Fix #GP/CPUID VM-exit precedence in nested VMX [Sashiko]
* Add EXPORT_STATIC_CALL_GPL(kvm_x86_get_cpl)
v1: https://lore.kernel.org/kvm/[email protected]/
v2: https://lore.kernel.org/kvm/[email protected]/
v3: https://lore.kernel.org/kvm/[email protected]/
Jim Mattson (4):
KVM: x86: Prioritize CPUID faulting over CPUID VM-exits in nested VMX
KVM: x86: Remove supports_cpuid_fault() helper
KVM: x86: Virtualize AMD CPUID faulting
KVM: selftests: Update hwcr_msr_test for CPUID faulting bit
Sean Christopherson (1):
KVM: x86: Consolidate CPUID fault handling for emulator and
interception logic
arch/x86/include/asm/kvm_host.h | 1 - arch/x86/include/asm/msr-index.h | 1 + arch/x86/kvm/cpuid.c | 7 ++-- arch/x86/kvm/cpuid.h | 14 ++++--- arch/x86/kvm/emulate.c | 6 +-- arch/x86/kvm/kvm_emulate.h | 1 + arch/x86/kvm/vmx/nested.c | 2 + arch/x86/kvm/x86.c | 39 ++++++++++--------- .../selftests/kvm/include/x86/processor.h | 1 + .../testing/selftests/kvm/x86/hwcr_msr_test.c | 9 ++++- 10 files changed, 46 insertions(+), 35 deletions(-)
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
PATCH v4 1/5 KVM: x86: Consolidate CPUID fault handling for emulator and interception logic
From: Sean Christopherson <[email protected]>
Extract the logic for emulating CPUID faulting (where CPUID #GPs at CPL>0 outside of SMM) into a dedicated helper and use the helper for both the full emulator and the intercepted-CPUID paths.
Opportunistically drop kvm_require_cpl(), as kvm_emulate_cpuid() was the one and only user.
No functional change intended.
[jim: Add EXPORT_STATIC_CALL_GPL(kvm_x86_get_cpl) so that KVM vendor modules can call kvm_is_cpuid_allowed(). Fix typo in commit message.]
--- arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/cpuid.c | 5 +++-- arch/x86/kvm/cpuid.h | 8 ++++++++ arch/x86/kvm/emulate.c | 6 +----- arch/x86/kvm/kvm_emulate.h | 1 + arch/x86/kvm/x86.c | 19 +++++++------------ 6 files changed, 20 insertions(+), 20 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -1
@@ -2321,7 +2321,6 @@ static inline void kvm_inject_emulated_page_fault(struct kvm_vcpu *vcpu,__kvm_inject_emulated_page_fault (vcpu, fault, false); } -bool kvm_require_cpl (struct kvm_vcpu *vcpu,int required_cpl);bool kvm_require_dr (struct kvm_vcpu *vcpu,int dr); static inline int __kvm_irq_line_state(unsigned long *irq_state,
arch/x86/kvm/cpuid.c +3 -2
@@ -2161,9 +2161,10 @@ int kvm_emulate_cpuid(struct kvm_vcpu *vcpu) {u32 eax, ebx, ecx, edx; -if (!is_smm (vcpu) &&cpuid_fault_enabled (vcpu) && - !kvm_require_cpl (vcpu,0 )) +if (!kvm_is_cpuid_allowed (vcpu)) { +kvm_queue_exception_e (vcpu,GP_VECTOR ,0 );return 1 ; + } eax =kvm_rax_read (vcpu); ecx =kvm_rcx_read (vcpu);
arch/x86/kvm/cpuid.h +8 -0
@@ -7,6 +7,8 @@#include <asm/processor.h> #include <uapi/asm/kvm_para.h> +#include "smm.h" +extern u32 kvm_cpu_caps[NR_KVM_CPU_CAPS ]__read_mostly ;extern bool kvm_is_configuring_cpu_caps__read_mostly ;
@@ -192,6 +194,12 @@ static inline bool cpuid_fault_enabled(struct kvm_vcpu *vcpu)MSR_MISC_FEATURES_ENABLES_CPUID_FAULT ; } +static inline bool kvm_is_cpuid_allowed (struct kvm_vcpu *vcpu) +{ +return !cpuid_fault_enabled (vcpu) ||is_smm (vcpu) || + !kvm_x86_call (get_cpl)(vcpu); +} + static __always_inline void kvm_cpu_cap_clear(unsigned int x86_feature) {unsigned int x86_leaf =__feature_leaf (x86_feature);
arch/x86/kvm/emulate.c +1 -5
@@ -3594,12 +3594,8 @@ static int em_sti(struct x86_emulate_ctxt *ctxt)static int em_cpuid (struct x86_emulate_ctxt *ctxt) {u32 eax, ebx, ecx, edx; -u64 msr =0 ; - ctxt->ops->get_msr (ctxt,MSR_MISC_FEATURES_ENABLES , &msr); -if (!ctxt->ops->is_smm (ctxt) && - (msr &MSR_MISC_FEATURES_ENABLES_CPUID_FAULT ) && - ctxt->ops->cpl (ctxt)) +if (!ctxt->ops->is_cpuid_allowed (ctxt))return emulate_gp (ctxt,0 ); eax =reg_read (ctxt,VCPU_REGS_RAX );
arch/x86/kvm/kvm_emulate.h +1 -0
@@ -230,6 +230,7 @@ struct x86_emulate_ops {struct x86_instruction_info *info, enum x86_intercept_stage stage); +bool (*is_cpuid_allowed)(struct x86_emulate_ctxt *ctxt);bool (*get_cpuid)(struct x86_emulate_ctxt *ctxt,u32 *eax,u32 *ebx,u32 *ecx,u32 *edx,bool exact_only);bool (*guest_has_movbe)(struct x86_emulate_ctxt *ctxt);
arch/x86/kvm/x86.c +7 -12
@@ -151,6 +151,7 @@ struct kvm_x86_ops kvm_x86_ops __read_mostly;#include <asm/kvm-x86-ops.h> EXPORT_STATIC_CALL_GPL (kvm_x86_get_cs_db_l_bits);EXPORT_STATIC_CALL_GPL (kvm_x86_cache_reg); +EXPORT_STATIC_CALL_GPL (kvm_x86_get_cpl);static bool __read_mostly ignore_msrs =0 ;module_param (ignore_msrs, bool,0644 );
@@ -1022,18 +1023,6 @@ void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code) }EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_queue_exception_e); -/* -* Checks if cpl <= required_cpl; if true, return true. Otherwise queue -* a #GP and return false. -*/ -bool kvm_require_cpl (struct kvm_vcpu *vcpu,int required_cpl) -{ -if (kvm_x86_call (get_cpl)(vcpu) <= required_cpl) -return true; -kvm_queue_exception_e (vcpu,GP_VECTOR ,0 ); -return false; -} -bool kvm_require_dr (struct kvm_vcpu *vcpu,int dr) {if ((dr !=4 && dr !=5 ) || !kvm_is_cr4_bit_set (vcpu,X86_CR4_DE ))
@@ -8829,6 +8818,11 @@ static int emulator_intercept(struct x86_emulate_ctxt *ctxt, &ctxt->exception); } +static bool emulator_is_cpuid_allowed (struct x86_emulate_ctxt *ctxt) +{ +return kvm_is_cpuid_allowed (emul_to_vcpu (ctxt)); +} +static bool emulator_get_cpuid (struct x86_emulate_ctxt *ctxt,u32 *eax,u32 *ebx,u32 *ecx,u32 *edx,bool exact_only)
@@ -8966,6 +8960,7 @@ static const struct x86_emulate_ops emulate_ops = { .wbinvd = emulator_wbinvd, .fix_hypercall = emulator_fix_hypercall, .intercept = emulator_intercept, + .is_cpuid_allowed = emulator_is_cpuid_allowed, .get_cpuid = emulator_get_cpuid, .guest_has_movbe = emulator_guest_has_movbe, .guest_has_fxsr = emulator_guest_has_fxsr,
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
Peter Zijlstra
maintainerRe: [PATCH v4 1/5] KVM: x86: Consolidate CPUID fault handling for emulator and interception logic
arch/x86/kvm/x86.c struct kvm_x86_ops kvm_x86_ops __read_mostly; · line 154
Quoted 12 lines · Jim Mattson
[jim: Add
EXPORT_STATIC_CALL_GPL(kvm_x86_get_cpl)so that KVM vendor modules can callkvm_is_cpuid_allowed(). Fix typo in commit message.]arch/x86/kvm/x86.c +1
-0@@ -151,6 +151,7 @@ struct kvm_x86_ops kvm_x86_ops __read_mostly;#include <asm/kvm-x86-ops.h> EXPORT_STATIC_CALL_GPL (kvm_x86_get_cs_db_l_bits);EXPORT_STATIC_CALL_GPL (kvm_x86_cache_reg); +EXPORT_STATIC_CALL_GPL (kvm_x86_get_cpl);
Are you aware of the distinction between EXPORT_STATIC_CALL_GPL() and EXPORT_STATIC_CALL_TRAMP_GPL() ?
Specifically, the former allows modules to do static_call_update(), while the latter does not. Whenever possible use the TRAMP thing, this allows modules to *call* the static_call, but not to redirect it.
Re: [PATCH v4 1/5] KVM: x86: Consolidate CPUID fault handling for emulator and interception logic
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Jim Mattson
[jim: Add
EXPORT_STATIC_CALL_GPL(kvm_x86_get_cpl)so that KVM vendor modules can callkvm_is_cpuid_allowed(). Fix typo in commit message.]
Quoted 12 lines
arch/x86/kvm/x86.c struct kvm_x86_ops kvm_x86_ops __read_mostly; · line 154
Quoted 9 lines
arch/x86/kvm/x86.c +1
-0@@ -151,6 +151,7 @@ struct kvm_x86_ops kvm_x86_ops __read_mostly;#include <asm/kvm-x86-ops.h> EXPORT_STATIC_CALL_GPL (kvm_x86_get_cs_db_l_bits);EXPORT_STATIC_CALL_GPL (kvm_x86_cache_reg); +EXPORT_STATIC_CALL_GPL (kvm_x86_get_cpl);Are you aware of the distinction between
EXPORT_STATIC_CALL_GPL()andEXPORT_STATIC_CALL_TRAMP_GPL()?
I am now. :)
Quoted 3 lines
Specifically, the former allows modules to do
static_call_update(), while the latter does not. Whenever possible use the TRAMP thing, this allows modules to *call* thestatic_call, but not to redirect it.
Sean - Can you fix this up when you apply it, or do you want a v5?
Sean Christopherson
maintainerRe: [PATCH v4 1/5] KVM: x86: Consolidate CPUID fault handling for emulator and interception logic
Quoted 20 lines · Jim Mattson
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Jim Mattson
[jim: Add
EXPORT_STATIC_CALL_GPL(kvm_x86_get_cpl)so that KVM vendor modules can callkvm_is_cpuid_allowed(). Fix typo in commit message.]Quoted 12 lines
arch/x86/kvm/x86.c struct kvm_x86_ops kvm_x86_ops __read_mostly; · line 154
Quoted 9 lines
arch/x86/kvm/x86.c +1
-0@@ -151,6 +151,7 @@ struct kvm_x86_ops kvm_x86_ops __read_mostly;#include <asm/kvm-x86-ops.h> EXPORT_STATIC_CALL_GPL (kvm_x86_get_cs_db_l_bits);EXPORT_STATIC_CALL_GPL (kvm_x86_cache_reg); +EXPORT_STATIC_CALL_GPL (kvm_x86_get_cpl);Are you aware of the distinction between
EXPORT_STATIC_CALL_GPL()andEXPORT_STATIC_CALL_TRAMP_GPL()?
Quoted 7 lines
I am now. :)
Quoted 3 lines
Specifically, the former allows modules to do
static_call_update(), while the latter does not. Whenever possible use the TRAMP thing, this allows modules to *call* thestatic_call, but not to redirect it.Sean - Can you fix this up when you apply it, or do you want a v5?
Neither, as detailed in my other response, using EXPORT_STATIC_CALL_TRAMP_GPL() requires switching kvm_x86_call() to static_call_mod(). We can do that, but I want to do it separately.
Sean Christopherson
maintainerRe: [PATCH v4 1/5] KVM: x86: Consolidate CPUID fault handling for emulator and interception logic
In reply to Peter ZijlstraQuoted 5 lines · Peter Zijlstra
Quoted 2 lines · Jim Mattson
[jim: Add
EXPORT_STATIC_CALL_GPL(kvm_x86_get_cpl)so that KVM vendor modules can callkvm_is_cpuid_allowed(). Fix typo in commit message.]
Quoted 12 lines
arch/x86/kvm/x86.c struct kvm_x86_ops kvm_x86_ops __read_mostly; · line 154
Quoted 9 lines
arch/x86/kvm/x86.c +1
-0@@ -151,6 +151,7 @@ struct kvm_x86_ops kvm_x86_ops __read_mostly;#include <asm/kvm-x86-ops.h> EXPORT_STATIC_CALL_GPL (kvm_x86_get_cs_db_l_bits);EXPORT_STATIC_CALL_GPL (kvm_x86_cache_reg); +EXPORT_STATIC_CALL_GPL (kvm_x86_get_cpl);Are you aware of the distinction between
EXPORT_STATIC_CALL_GPL()andEXPORT_STATIC_CALL_TRAMP_GPL()?
No, but it's a moot point at the moment, because EXPORT_STATIC_CALL_TRAMP_GPL() doesn't actually work?
For CONFIG_HAVE_STATIC_CALL_INLINE=y, __static_call() references the key
/*
* __ADDRESSABLE() is used to ensure the key symbol doesn't get stripped from
* the symbol table so that objtool can reference it when it generates the
* .static_call_sites section.
*/
#define __STATIC_CALL_ADDRESSABLE(name) \
__ADDRESSABLE(STATIC_CALL_KEY(name))
#define __static_call(name) \
({ \
__STATIC_CALL_ADDRESSABLE(name); \
__raw_static_call(name); \
})which leads to
ERROR: modpost: "__SCK__kvm_x86_cache_reg" [arch/x86/kvm/kvm-intel.ko] undefined!
ERROR: modpost: "__SCK__kvm_x86_get_cpl" [arch/x86/kvm/kvm-intel.ko] undefined!
ERROR: modpost: "__SCK__kvm_x86_get_cs_db_l_bits" [arch/x86/kvm/kvm-intel.ko] undefined!
ERROR: modpost: "__SCK__kvm_x86_cache_reg" [arch/x86/kvm/kvm-amd.ko] undefined!
ERROR: modpost: "__SCK__kvm_x86_get_cs_db_l_bits" [arch/x86/kvm/kvm-amd.ko] undefined!
Ahh, it requires using static_call_mod.
Argh, and it's actually broken for PPC32, which selects HAVE_STATIC_CALL_INLINE but doesn't provide ARCH_ADD_TRAMP_KEY.
Quoted 3 lines
Specifically, the former allows modules to do
static_call_update(), while the latter does not. Whenever possible use the TRAMP thing, this allows modules to *call* thestatic_call, but not to redirect it.
Hmm, should we kill off EXPORT_STATIC_CALL{,_GPL}() entirely and figure out a way to fold them into EXPORT_TRACEPOINT_SYMBOL{,_GPL}()? Or create macros that are quite cleary only for tracepoints. KVM x86 is the only other user, and all of KVM's usage is unnecessary, KVM just wants to let vendor modules invoke the call.
$ git grep EXPORT_STATIC_CALL_GPL arch/x86/kvm/pmu.c:EXPORT_STATIC_CALL_GPL(kvm_x86_pmu_pmc_is_disabled_in_current_mode); arch/x86/kvm/x86.c:EXPORT_STATIC_CALL_GPL(kvm_x86_get_cs_db_l_bits); arch/x86/kvm/x86.c:EXPORT_STATIC_CALL_GPL(kvm_x86_cache_reg); arch/x86/kvm/x86.c:EXPORT_STATIC_CALL_GPL(kvm_x86_get_cpl); include/linux/static_call.h:#define EXPORT_STATIC_CALL_GPL(name) \ include/linux/static_call.h:#define EXPORT_STATIC_CALL_GPL(name) \ include/linux/static_call.h:#define EXPORT_STATIC_CALL_GPL(name) EXPORT_SYMBOL_GPL(STATIC_CALL_KEY(name)) include/linux/tracepoint.h: EXPORT_STATIC_CALL_GPL(tp_func_##name)
$ git grep -w EXPORT_STATIC_CALL
include/linux/static_call.h: * EXPORT_STATIC_CALL{,_TRAMP}{,_GPL}()
include/linux/static_call.h: * EXPORT_STATIC_CALL() vs EXPORT_STATIC_CALL_TRAMP():
include/linux/static_call.h:#define EXPORT_STATIC_CALL(name) \
include/linux/static_call.h:#define EXPORT_STATIC_CALL(name) \
include/linux/static_call.h:#define EXPORT_STATIC_CALL(name) EXPORT_SYMBOL(STATIC_CALL_KEY(name))
include/linux/tracepoint.h: EXPORT_STATIC_CALL(tp_func_##name)As for KVM, if we're going to hack on the static call exports, this would be a good time to add EXPORT_STATIC_CALL_FOR_KVM{,_INTERNAL}.
The attached patches appear to do what I want, and pass my build tests. If they seem reasonable (I would say "sane", but none of this is sane :-D), I'll write changelogs and post them.
From 9e96186654e41f957e6499a64c5bfcb145a5f9f0 Mon Sep 17 00:00:00 2001
From: Sean Christopherson <[email protected]>
Date: Thu, 28 May 2026 08:09:56 -0700
Subject: [PATCH 1/4] static_call: Add stub for ARCH_ADD_TRAMP_KEY if not
provided by arch
--- include/linux/static_call.h | 4 ++++ 1 file changed, 4 insertions(+)
include/linux/static_call.h +4 -0
@@ -210,6 +210,10 @@ extern long __static_call_return0(void);#define static_call_cond (name) (void)__static_call(name) +#ifndef ARCH_ADD_TRAMP_KEY +#define ARCH_ADD_TRAMP_KEY (name) +#endif +#define EXPORT_STATIC_CALL (name) \ EXPORT_SYMBOL(STATIC_CALL_KEY(name)); \ EXPORT_SYMBOL(STATIC_CALL_TRAMP(name))
base-commit: d1568b1332b6b3b36b222c2868fc102727c12a34
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
From a32b2d999e6c441139534b86b2288376c87d2609 Mon Sep 17 00:00:00 2001
From: Sean Christopherson <[email protected]>
Date: Thu, 28 May 2026 07:01:36 -0700
Subject: [PATCH 2/4] KVM: x86: Don't export static call keys to vendor modules
--- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/pmu.h | 2 +- arch/x86/kvm/x86.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -1
@@ -2062,7 +2062,7 @@ extern bool __read_mostly enable_ipiv;extern bool __read_mostly enable_device_posted_irqs;extern struct kvm_x86_ops kvm_x86_ops; -#define kvm_x86_call (func) static_call(kvm_x86_##func) +#define kvm_x86_call (func) static_call_mod(kvm_x86_##func)#define KVM_X86_OP (func) \ DECLARE_STATIC_CALL(kvm_x86_##func, *(((struct kvm_x86_ops *)0)->func));
arch/x86/kvm/pmu.h +1 -1
@@ -54,7 +54,7 @@ struct kvm_pmu_ops {const u32 MSR_STRIDE ; }; -#define kvm_pmu_call (func) static_call(kvm_x86_pmu_##func) +#define kvm_pmu_call (func) static_call_mod(kvm_x86_pmu_##func)#define KVM_X86_PMU_OP (func) \ DECLARE_STATIC_CALL(kvm_x86_pmu_##func, *(((struct kvm_pmu_ops *)0)->func));
arch/x86/kvm/x86.c +3 -3
@@ -149,9 +149,9 @@ struct kvm_x86_ops kvm_x86_ops __read_mostly;#define KVM_X86_OP_OPTIONAL KVM_X86_OP#define KVM_X86_OP_OPTIONAL_RET0 KVM_X86_OP#include <asm/kvm-x86-ops.h> -EXPORT_STATIC_CALL_GPL (kvm_x86_get_cs_db_l_bits); -EXPORT_STATIC_CALL_GPL (kvm_x86_cache_reg); -EXPORT_STATIC_CALL_GPL (kvm_x86_get_cpl); +EXPORT_STATIC_CALL_TRAMP_GPL (kvm_x86_get_cs_db_l_bits); +EXPORT_STATIC_CALL_TRAMP_GPL (kvm_x86_cache_reg); +EXPORT_STATIC_CALL_TRAMP_GPL (kvm_x86_get_cpl);static bool __read_mostly ignore_msrs =0 ;module_param (ignore_msrs, bool,0644 );
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
From 5f45d849f0034bac3d2f30d2ad2d7490e9c7548e Mon Sep 17 00:00:00 2001
From: Sean Christopherson <[email protected]>
Date: Thu, 28 May 2026 07:03:24 -0700
Subject: [PATCH 3/4] static_call: Restrict exporting of static call *key* to
tracepoints
--- arch/x86/events/amd/brs.c | 2 +- arch/x86/kernel/apic/init.c | 4 +-- arch/x86/kernel/cpu/mshyperv.c | 2 +- arch/x86/kernel/traps.c | 2 +- arch/x86/kvm/x86.c | 6 ++-- arch/x86/xen/enlighten.c | 2 +- include/linux/static_call.h | 59 +++++++++++++--------------------- include/linux/tracepoint.h | 4 +-- kernel/sched/core.c | 8 ++--- 9 files changed, 38 insertions(+), 51 deletions(-)
arch/x86/events/amd/brs.c +1 -1
@@ -424,7 +424,7 @@ void noinstr perf_amd_brs_lopwr_cb(bool lopwr_in) }DEFINE_STATIC_CALL_NULL (perf_lopwr_cb, perf_amd_brs_lopwr_cb); -EXPORT_STATIC_CALL_TRAMP_GPL (perf_lopwr_cb); +EXPORT_STATIC_CALL_GPL (perf_lopwr_cb);void __init amd_brs_lopwr_init (void ) {
arch/x86/kernel/apic/init.c +2 -2
@@ -30,8 +30,8 @@ DEFINE_APIC_CALL(wakeup_secondary_cpu);DEFINE_APIC_CALL (wakeup_secondary_cpu_64);DEFINE_APIC_CALL (write); -EXPORT_STATIC_CALL_TRAMP_GPL (apic_call_send_IPI_mask); -EXPORT_STATIC_CALL_TRAMP_GPL (apic_call_send_IPI_self); +EXPORT_STATIC_CALL_GPL (apic_call_send_IPI_mask); +EXPORT_STATIC_CALL_GPL (apic_call_send_IPI_self);/* The container for function call overrides */ struct apic_override __x86_apic_override__initdata ;
arch/x86/kernel/cpu/mshyperv.c +1 -1
@@ -333,7 +333,7 @@ static void __init x86_setup_ops_for_tsc_pg_clock(void)#ifdef CONFIG_X86_64 DEFINE_STATIC_CALL (hv_hypercall, hv_std_hypercall); -EXPORT_STATIC_CALL_TRAMP_GPL (hv_hypercall); +EXPORT_STATIC_CALL_GPL (hv_hypercall);#define hypercall_update (hc) static_call_update(hv_hypercall, hc)#endif #endif /* CONFIG_HYPERV */
arch/x86/kernel/traps.c +1 -1
@@ -218,7 +218,7 @@ static inline unsigned long pt_regs_val(struct pt_regs *regs, int nr)#ifdef HAVE_ARCH_BUG_FORMAT_ARGS DEFINE_STATIC_CALL (WARN_trap, __WARN_trap); -EXPORT_STATIC_CALL_TRAMP (WARN_trap); +EXPORT_STATIC_CALL (WARN_trap);/* * Create a va_list from an exception context.
arch/x86/kvm/x86.c +3 -3
@@ -149,9 +149,9 @@ struct kvm_x86_ops kvm_x86_ops __read_mostly;#define KVM_X86_OP_OPTIONAL KVM_X86_OP#define KVM_X86_OP_OPTIONAL_RET0 KVM_X86_OP#include <asm/kvm-x86-ops.h> -EXPORT_STATIC_CALL_TRAMP_GPL (kvm_x86_get_cs_db_l_bits); -EXPORT_STATIC_CALL_TRAMP_GPL (kvm_x86_cache_reg); -EXPORT_STATIC_CALL_TRAMP_GPL (kvm_x86_get_cpl); +EXPORT_STATIC_CALL_GPL (kvm_x86_get_cs_db_l_bits); +EXPORT_STATIC_CALL_GPL (kvm_x86_cache_reg); +EXPORT_STATIC_CALL_GPL (kvm_x86_get_cpl);static bool __read_mostly ignore_msrs =0 ;module_param (ignore_msrs, bool,0644 );
arch/x86/xen/enlighten.c +1 -1
@@ -23,7 +23,7 @@#include "xen-ops.h" DEFINE_STATIC_CALL (xen_hypercall, xen_hypercall_hvm); -EXPORT_STATIC_CALL_TRAMP (xen_hypercall); +EXPORT_STATIC_CALL (xen_hypercall);/* * Pointer to the xen_vcpu_info structure or
include/linux/static_call.h +23 -36
90 lines not on this page · raw message
include/linux/tracepoint.h +2 -2
@@ -415,12 +415,12 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p) TRACEPOINT_CHECK(name) \ EXPORT_SYMBOL_GPL(__tracepoint_##name); \ EXPORT_SYMBOL_GPL(__traceiter_##name); \ - EXPORT_STATIC_CALL_GPL(tp_func_##name) + EXPORT_TRACEPOINT_STATIC_CALL_GPL(tp_func_##name)#define EXPORT_TRACEPOINT_SYMBOL (name) \ TRACEPOINT_CHECK(name) \ EXPORT_SYMBOL(__tracepoint_##name); \ EXPORT_SYMBOL(__traceiter_##name); \ - EXPORT_STATIC_CALL(tp_func_##name) + EXPORT_TRACEPOINT_STATIC_CALL(tp_func_##name)#else /* !TRACEPOINTS_ENABLED */
kernel/sched/core.c +4 -4
@@ -7403,7 +7403,7 @@ EXPORT_SYMBOL(preempt_schedule);# define preempt_schedule_dynamic_disabled NULL# endif DEFINE_STATIC_CALL (preempt_schedule, preempt_schedule_dynamic_enabled); -EXPORT_STATIC_CALL_TRAMP (preempt_schedule); +EXPORT_STATIC_CALL (preempt_schedule);# elif defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY)static DEFINE_STATIC_KEY_TRUE (sk_dynamic_preempt_schedule); void __sched notrace dynamic_preempt_schedule(void)
@@ -7476,7 +7476,7 @@ EXPORT_SYMBOL_GPL(preempt_schedule_notrace);# define preempt_schedule_notrace_dynamic_disabled NULL# endif DEFINE_STATIC_CALL (preempt_schedule_notrace, preempt_schedule_notrace_dynamic_enabled); -EXPORT_STATIC_CALL_TRAMP (preempt_schedule_notrace); +EXPORT_STATIC_CALL (preempt_schedule_notrace);# elif defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY)static DEFINE_STATIC_KEY_TRUE (sk_dynamic_preempt_schedule_notrace); void __sched notrace dynamic_preempt_schedule_notrace(void)
@@ -7723,12 +7723,12 @@ EXPORT_SYMBOL(__cond_resched);# define cond_resched_dynamic_enabled __cond_resched# define cond_resched_dynamic_disabled ((void *)&__static_call_return0)DEFINE_STATIC_CALL_RET0 (cond_resched, __cond_resched); -EXPORT_STATIC_CALL_TRAMP (cond_resched); +EXPORT_STATIC_CALL (cond_resched);# define might_resched_dynamic_enabled __cond_resched# define might_resched_dynamic_disabled ((void *)&__static_call_return0)DEFINE_STATIC_CALL_RET0 (might_resched, __cond_resched); -EXPORT_STATIC_CALL_TRAMP (might_resched); +EXPORT_STATIC_CALL (might_resched);# elif defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY )static DEFINE_STATIC_KEY_FALSE (sk_dynamic_cond_resched); int __sched dynamic_cond_resched(void)
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
From f11d22a3d10693796dcf8ae2e2e0cb681a071be6 Mon Sep 17 00:00:00 2001
From: Sean Christopherson <[email protected]>
Date: Thu, 28 May 2026 07:32:41 -0700
Subject: [PATCH 4/4] static_call: Add FOR_MODULES static call exports, use 'em
in KVM
--- arch/x86/kvm/pmu.c | 2 +- arch/x86/kvm/x86.c | 6 +++--- include/linux/kvm_types.h | 8 ++++++++ include/linux/static_call.h | 12 +++++++----- 4 files changed, 19 insertions(+), 9 deletions(-)
arch/x86/kvm/pmu.c +1 -1
@@ -100,7 +100,7 @@ static struct kvm_pmu_ops kvm_pmu_ops __read_mostly;#define KVM_X86_PMU_OP_OPTIONAL KVM_X86_PMU_OP#define KVM_X86_PMU_OP_OPTIONAL_RET0 KVM_X86_PMU_OP#include <asm/kvm-x86-pmu-ops.h> -EXPORT_STATIC_CALL_GPL (kvm_x86_pmu_pmc_is_disabled_in_current_mode); +EXPORT_STATIC_CALL_FOR_KVM_INTERNAL (kvm_x86_pmu_pmc_is_disabled_in_current_mode);void kvm_pmu_ops_update (const struct kvm_pmu_ops *pmu_ops) {
arch/x86/kvm/x86.c +3 -3
@@ -149,9 +149,9 @@ struct kvm_x86_ops kvm_x86_ops __read_mostly;#define KVM_X86_OP_OPTIONAL KVM_X86_OP#define KVM_X86_OP_OPTIONAL_RET0 KVM_X86_OP#include <asm/kvm-x86-ops.h> -EXPORT_STATIC_CALL_GPL (kvm_x86_get_cs_db_l_bits); -EXPORT_STATIC_CALL_GPL (kvm_x86_cache_reg); -EXPORT_STATIC_CALL_GPL (kvm_x86_get_cpl); +EXPORT_STATIC_CALL_FOR_KVM_INTERNAL (kvm_x86_get_cs_db_l_bits); +EXPORT_STATIC_CALL_FOR_KVM_INTERNAL (kvm_x86_cache_reg); +EXPORT_STATIC_CALL_FOR_KVM_INTERNAL (kvm_x86_get_cpl);static bool __read_mostly ignore_msrs =0 ;module_param (ignore_msrs, bool,0644 );
include/linux/kvm_types.h +8 -0
@@ -13,8 +13,14 @@ EXPORT_SYMBOL_FOR_MODULES(symbol, __stringify(KVM_SUB_MODULES))#define EXPORT_SYMBOL_FOR_KVM (symbol) \ EXPORT_SYMBOL_FOR_MODULES(symbol, "kvm," __stringify(KVM_SUB_MODULES)) +#define EXPORT_STATIC_CALL_FOR_KVM_INTERNAL (symbol) \ + EXPORT_STATIC_CALL_FOR_MODULES(symbol, __stringify(KVM_SUB_MODULES)) +#define EXPORT_STATIC_CALL_FOR_KVM (symbol) \ + EXPORT_STATIC_CALL_FOR_MODULES(symbol, "kvm," __stringify(KVM_SUB_MODULES))#else #define EXPORT_SYMBOL_FOR_KVM_INTERNAL (symbol) +#define EXPORT_STATIC_CALL_FOR_KVM_INTERNAL (symbol) +/* * Allow architectures to provide a custom EXPORT_SYMBOL_FOR_KVM, but only * if there are no submodules, e.g. to allow suppressing exports if KVM=m, but
@@ -23,8 +29,10 @@#ifndef EXPORT_SYMBOL_FOR_KVM #if IS_MODULE (CONFIG_KVM )#define EXPORT_SYMBOL_FOR_KVM (symbol) EXPORT_SYMBOL_FOR_MODULES(symbol, "kvm") +#define EXPORT_STATIC_CALL_FOR_KVM (symbol) EXPORT_STATIC_CALL_FOR_MODULES(symbol, "kvm")#else #define EXPORT_SYMBOL_FOR_KVM (symbol) +#define EXPORT_STATIC_CALL_FOR_KVM (symbol)#endif /* IS_MODULE(CONFIG_KVM) */ #endif /* EXPORT_SYMBOL_FOR_KVM */ #endif
include/linux/static_call.h +7 -5
@@ -206,8 +206,8 @@ extern long __static_call_return0(void);#define ARCH_ADD_TRAMP_KEY (name)#endif -#define __EXPORT_STATIC_CALL (name, scope) \ - EXPORT_SYMBOL##scope(STATIC_CALL_TRAMP(name)); \ +#define __EXPORT_STATIC_CALL (name, scope, ...) \ + EXPORT_SYMBOL##scope(STATIC_CALL_TRAMP(name), ##__VA_ARGS__); \ ARCH_ADD_TRAMP_KEY(name)#elif defined(CONFIG_HAVE_STATIC_CALL)
@@ -255,8 +255,8 @@ static inline int static_call_text_reserved(void *start, void *end)extern long __static_call_return0 (void ); -#define __EXPORT_STATIC_CALL (name, scope) \ - EXPORT_SYMBOL##scope(STATIC_CALL_TRAMP(name)) +#define __EXPORT_STATIC_CALL (name, scope, ...) \ + EXPORT_SYMBOL##scope(STATIC_CALL_TRAMP(name), ##__VA_ARGS__)#else /* Generic implementation */
@@ -319,7 +319,7 @@ static inline int static_call_text_reserved(void *start, void *end) return 0; } -#define __EXPORT_STATIC_CALL (name, scope) +#define __EXPORT_STATIC_CALL (name, scope, ...)#endif /* CONFIG_HAVE_STATIC_CALL */
@@ -339,5 +339,7 @@ static inline int static_call_text_reserved(void *start, void *end) __EXPORT_STATIC_CALL(name, ) #define EXPORT_STATIC_CALL_GPL(name) \ __EXPORT_STATIC_CALL(name, _GPL) +#define EXPORT_STATIC_CALL_FOR_MODULES(name, mods) \ + __EXPORT_STATIC_CALL(name, _FOR_MODULES, mods)#endif /* _LINUX_STATIC_CALL_H */
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
PATCH v4 2/5 KVM: x86: Prioritize CPUID faulting over CPUID VM-exits in nested VMX
In reply to Jim MattsonPer the Intel SDM, "Certain exceptions have priority over VM exits. These include invalid-opcode exceptions, faults based on privilege level, and general-protection exceptions that are based on checking I/O permission bits in the task-state segment (TSS)."
Ensure that when L2 executes CPUID at CPL > 0 while L1 has enabled CPUID faulting, KVM intercepts the exit in L0 and queues #GP rather than forwarding the CPUID VM-exit to L1.
Empirical testing confirms that this #GP has higher precedence than a CPUID VM-exit on Granite Rapids (F/M/S 6/0xad/1).
--- arch/x86/kvm/vmx/nested.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/kvm/vmx/nested.c +2 -0
@@ -6552,6 +6552,8 @@ static bool nested_vmx_l0_wants_exit(struct kvm_vcpu *vcpu,nested_evmcs_l2_tlb_flush_enabled (vcpu) &&kvm_hv_is_tlb_flush_hcall (vcpu);#endif +case EXIT_REASON_CPUID : +return !kvm_is_cpuid_allowed (vcpu);default :break ; }
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
PATCH v4 3/5 KVM: x86: Remove supports_cpuid_fault() helper
In reply to Jim MattsonThe function, supports_cpuid_fault(), tests specifically for guest support of Intel's CPUID faulting feature. It does not test for guest support of AMD's CPUID faulting feature.
To avoid confusion, remove the helper.
--- arch/x86/kvm/cpuid.h | 5 ----- arch/x86/kvm/x86.c | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-)
arch/x86/kvm/cpuid.h +0 -5
@@ -183,11 +183,6 @@ static inline int guest_cpuid_stepping(struct kvm_vcpu *vcpu)return x86_stepping (best->eax); } -static inline bool supports_cpuid_fault (struct kvm_vcpu *vcpu) -{ -return vcpu->arch.msr_platform_info &MSR_PLATFORM_INFO_CPUID_FAULT ; -} -static inline bool cpuid_fault_enabled (struct kvm_vcpu *vcpu) { return vcpu->arch.msr_misc_features_enables &
arch/x86/kvm/x86.c +1 -1
@@ -4264,7 +4264,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)case MSR_MISC_FEATURES_ENABLES :if (data & ~MSR_MISC_FEATURES_ENABLES_CPUID_FAULT || (data &MSR_MISC_FEATURES_ENABLES_CPUID_FAULT && - !supports_cpuid_fault (vcpu))) + !(vcpu->arch.msr_platform_info &MSR_PLATFORM_INFO_CPUID_FAULT )))return 1 ; vcpu->arch.msr_misc_features_enables = data;break ;
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
PATCH v4 4/5 KVM: x86: Virtualize AMD CPUID faulting
In reply to Jim MattsonOn AMD CPUs, CPUID faulting support is advertised via CPUID.80000021H:EAX.CpuidUserDis[bit 17] and enabled by setting HWCR.CpuidUserDis[bit 35].
Advertise the feature to userspace regardless of host CPU support. Allow writes to HWCR to set bit 35 when the guest CPUID advertises CpuidUserDis. Update cpuid_fault_enabled() to check HWCR.CpuidUserDis as well as MSR_FEATURE_ENABLES.CPUID_GP_ON_CPL_GT_0.
Unlike VMX, SVM prioritizes the CPUID intercept over the #GP induced by CPUID faulting.[1] This behavior has been confirmed on a Turin CPU (F/M/S 1AH/2/1).
--- arch/x86/include/asm/msr-index.h | 1 + arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/cpuid.h | 5 +++-- arch/x86/kvm/x86.c | 18 ++++++++++++------ 4 files changed, 17 insertions(+), 9 deletions(-)
arch/x86/include/asm/msr-index.h +1 -0
@@ -898,6 +898,7 @@#define MSR_K7_HWCR_IRPERF_EN_BIT 30#define MSR_K7_HWCR_IRPERF_EN BIT_ULL(MSR_K7_HWCR_IRPERF_EN_BIT)#define MSR_K7_HWCR_CPUID_USER_DIS_BIT 35 +#define MSR_K7_HWCR_CPUID_USER_DIS BIT_ULL(MSR_K7_HWCR_CPUID_USER_DIS_BIT)#define MSR_K7_FID_VID_CTL 0xc0010041#define MSR_K7_FID_VID_STATUS 0xc0010042#define MSR_K7_HWCR_CPB_DIS_BIT 25
arch/x86/kvm/cpuid.c +1 -1
@@ -1248,7 +1248,7 @@ void kvm_initialize_cpu_caps(void)F (AUTOIBRS ),EMULATED_F (NO_SMM_CTL_MSR ),/* PrefetchCtlMsr */ -/* GpOnUserCpuid */ +EMULATED_F (GP_ON_USER_CPUID ),/* EPSF */ F (PREFETCHI ), F(AVX512_BMM),
arch/x86/kvm/cpuid.h +3 -2
@@ -185,8 +185,9 @@ static inline int guest_cpuid_stepping(struct kvm_vcpu *vcpu)static inline bool cpuid_fault_enabled (struct kvm_vcpu *vcpu) { -return vcpu->arch.msr_misc_features_enables & -MSR_MISC_FEATURES_ENABLES_CPUID_FAULT ; +return (vcpu->arch.msr_misc_features_enables & +MSR_MISC_FEATURES_ENABLES_CPUID_FAULT ) || + (vcpu->arch.msr_hwcr &MSR_K7_HWCR_CPUID_USER_DIS ); }static inline bool kvm_is_cpuid_allowed (struct kvm_vcpu *vcpu)
arch/x86/kvm/x86.c +12 -6
@@ -4002,22 +4002,28 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)break ;case MSR_EFER :return set_efer (vcpu, msr_info); -case MSR_K7_HWCR : - data &= ~(u64 )0x40 ;/* ignore flush filter disable */ - data &= ~(u64 )0x100 ;/* ignore ignne emulation enable */ - data &= ~(u64 )0x8 ;/* ignore TLB cache disable */ - +case MSR_K7_HWCR : {/* * Allow McStatusWrEn and TscFreqSel. (Linux guests from v3.2 * through at least v6.6 whine if TscFreqSel is clear, * depending on F/M/S. */ -if (data & ~(BIT_ULL (18 ) |BIT_ULL (24 ))) { +u64 valid =BIT_ULL (18 ) |BIT_ULL (24 ); + + data &= ~(u64 )0x40 ;/* ignore flush filter disable */ + data &= ~(u64 )0x100 ;/* ignore ignne emulation enable */ + data &= ~(u64 )0x8 ;/* ignore TLB cache disable */ + +if (guest_cpu_cap_has (vcpu,X86_FEATURE_GP_ON_USER_CPUID )) + valid |=MSR_K7_HWCR_CPUID_USER_DIS ; + +if (data & ~valid) {kvm_pr_unimpl_wrmsr (vcpu, msr, data);return 1 ; } vcpu->arch.msr_hwcr = data;break ; + }case MSR_FAM10H_MMIO_CONF_BASE :if (data !=0 ) {kvm_pr_unimpl_wrmsr (vcpu, msr, data);
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
PATCH v4 5/5 KVM: selftests: Update hwcr_msr_test for CPUID faulting bit
In reply to Jim MattsonAdd BIT_ULL(35) (CpuidUserDis) to the valid mask in hwcr_msr_test, now that KVM accepts writes to this bit when the guest CPUID advertises CpuidUserDis.
--- tools/testing/selftests/kvm/include/x86/processor.h | 1 + tools/testing/selftests/kvm/x86/hwcr_msr_test.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/include/x86/processor.h +1 -0
@@ -226,6 +226,7 @@ struct kvm_x86_cpu_feature {#define X86_FEATURE_SEV KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 1)#define X86_FEATURE_SEV_ES KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 3)#define X86_FEATURE_SEV_SNP KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 4) +#define X86_FEATURE_GP_ON_USER_CPUID KVM_X86_CPU_FEATURE(0x80000021, 0, EAX, 17)#define X86_FEATURE_PERFMON_V2 KVM_X86_CPU_FEATURE(0x80000022, 0, EAX, 0)#define X86_FEATURE_LBR_PMC_FREEZE KVM_X86_CPU_FEATURE(0x80000022, 0, EAX, 2)
tools/testing/selftests/kvm/x86/hwcr_msr_test.c +7 -2
@@ -11,12 +11,17 @@void test_hwcr_bit (struct kvm_vcpu *vcpu,unsigned int bit) {const u64 ignored =BIT_ULL (3 ) |BIT_ULL (6 ) |BIT_ULL (8 ); -const u64 valid =BIT_ULL (18 ) |BIT_ULL (24 ); -const u64 legal = ignored | valid; +u64 valid =BIT_ULL (18 ) |BIT_ULL (24 );u64 val =BIT_ULL (bit);u64 actual; +u64 legal;int r; +if (kvm_cpu_has (X86_FEATURE_GP_ON_USER_CPUID )) + valid |=BIT_ULL (35 ); + + legal = ignored | valid; + r =_vcpu_set_msr (vcpu,MSR_K7_HWCR , val); TEST_ASSERT(val & ~legal ? !r : r == 1, "Expected KVM_SET_MSRS(MSR_K7_HWCR) = 0x%lx to %s",
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
Quoted 8 lines · Jim Mattson
AMD's "disable CPUID in usermode" feature is analogous to Intel's "CPUID faulting" feature, but it is advertised and activated differently. The AMD feature is advertised via CPUID.80000021H:EAX.CpuidUserDis[bit 17] and activated by setting HWCR.CpuidUserDis[bit 35].
Add virtualization support for the AMD feature.
[...]
Applied to kvm-x86 misc, thanks!
[1/5] KVM: x86: Consolidate CPUID fault handling for emulator and interception logic
https://github.com/kvm-x86/linux/commit/cf7d65d1d6f5 [2/5] KVM: x86: Prioritize CPUID faulting over CPUID VM-exits in nested VMX https://github.com/kvm-x86/linux/commit/be7fd7c3e8bc [3/5] KVM: x86: Remove supports_cpuid_fault() helper https://github.com/kvm-x86/linux/commit/d1bc99885a59 [4/5] KVM: x86: Virtualize AMD CPUID faulting https://github.com/kvm-x86/linux/commit/e93a93f11490 [5/5] KVM: selftests: Update hwcr_msr_test for CPUID faulting bit https://github.com/kvm-x86/linux/commit/b16c2aca369d
Quoted 7 lines · Sean Christopherson
Quoted 5 lines · Jim Mattson
AMD's "disable CPUID in usermode" feature is analogous to Intel's "CPUID faulting" feature, but it is advertised and activated differently. The AMD feature is advertised via CPUID.80000021H:EAX.CpuidUserDis[bit 17] and activated by setting HWCR.CpuidUserDis[bit 35].
Quoted 5 lines
Quoted 3 lines
Add virtualization support for the AMD feature.
[...]
Applied to kvm-x86 misc, thanks!
Oops! You haven't sent a pull request for this series yet, have you?
Our internal Sashiko asks:
Quoted 9 lines
In
kvm_set_msr_common(), theMSR_PLATFORM_INFOhandler usescpuid_fault_enabled()to prevent the host from clearingMSR_PLATFORM_INFO_CPUID_FAULTwhile CPUID faulting is enabled:case MSR_PLATFORM_INFO: if (!msr_info->host_initiated || (!(data & MSR_PLATFORM_INFO_CPUID_FAULT) && cpuid_fault_enabled(vcpu))) return 1;If a VMM restores
MSR_K7_HWCRbeforeMSR_PLATFORM_INFOduring live migration, and the guest had enabled AMD CPUID faulting, won't the write toMSR_PLATFORM_INFOfail if it doesn't haveMSR_PLATFORM_INFO_CPUID_FAULTset?
Sadly, I think it's right. Even on AMD systems, MSR_PLATFORM_INFO is enumerated by KVM_GET_MSR_INDEX_LIST. It does come before MSR_K7_HWCR in that list, but userspace is free to restore the virtual MSRs in any order. For any sane AMD-hosted vCPU, MSR_PLATFORM_INFO will be zero.
Quoted 27 lines · Jim Mattson
Quoted 7 lines · Sean Christopherson
Quoted 5 lines · Jim Mattson
AMD's "disable CPUID in usermode" feature is analogous to Intel's "CPUID faulting" feature, but it is advertised and activated differently. The AMD feature is advertised via CPUID.80000021H:EAX.CpuidUserDis[bit 17] and activated by setting HWCR.CpuidUserDis[bit 35].
Quoted 5 lines
Quoted 3 lines
Add virtualization support for the AMD feature.
[...]
Applied to kvm-x86 misc, thanks!
Oops! You haven't sent a pull request for this series yet, have you?
Our internal Sashiko asks:
Quoted 8 lines
In
kvm_set_msr_common(), theMSR_PLATFORM_INFOhandler usescpuid_fault_enabled()to prevent the host from clearingMSR_PLATFORM_INFO_CPUID_FAULTwhile CPUID faulting is enabled:case MSR_PLATFORM_INFO: if (!msr_info->host_initiated || (!(data & MSR_PLATFORM_INFO_CPUID_FAULT) && cpuid_fault_enabled(vcpu))) return 1;
Quoted 6 lines
Quoted 1 line
If a VMM restores
MSR_K7_HWCRbeforeMSR_PLATFORM_INFOduring live migration, and the guest had enabled AMD CPUID faulting, won't the write toMSR_PLATFORM_INFOfail if it doesn't haveMSR_PLATFORM_INFO_CPUID_FAULTset?Sadly, I think it's right. Even on AMD systems,
MSR_PLATFORM_INFOis enumerated byKVM_GET_MSR_INDEX_LIST. It does come beforeMSR_K7_HWCRin that list, but userspace is free to restore the virtual MSRs in any order. For any sane AMD-hosted vCPU,MSR_PLATFORM_INFOwill be zero.
Never mind. This Sashiko observation was on a backport to a branch that doesn't have commit 1ded7a57b805 ("KVM: x86: Remove ordering check b/w MSR_PLATFORM_INFO and MISC_FEATURES_ENABLES"). Everything is fine at tip.