Message ID | 20200201185218.24473-1-sean.j.christopherson@intel.com (mailing list archive) |
---|---|
Headers | show |
Series | KVM: x86: Introduce KVM cpu caps | expand |
On 25/02/20 16:18, Vitaly Kuznetsov wrote: > Would it be better or worse if we eliminate set_supported_cpuid() hook > completely by doing an ugly hack like (completely untested): Yes, it makes sense. Paolo
On Tue, Feb 25, 2020 at 04:25:34PM +0100, Paolo Bonzini wrote: > On 25/02/20 16:18, Vitaly Kuznetsov wrote: > > Would it be better or worse if we eliminate set_supported_cpuid() hook > > completely by doing an ugly hack like (completely untested): > > Yes, it makes sense. Works for me, I'll tack it on. I think my past self kept it because I was planning on using vmx_set_supported_cpuid() for SGX, which adds multiple sub-leafs, but I'm pretty sure I can squeeze them into kvm_cpu_caps with a few extra shenanigans.
On 28/02/20 02:37, Sean Christopherson wrote: >>> Would it be better or worse if we eliminate set_supported_cpuid() hook >>> completely by doing an ugly hack like (completely untested): >> Yes, it makes sense. > Works for me, I'll tack it on. I think my past self kept it because I was > planning on using vmx_set_supported_cpuid() for SGX, which adds multiple > sub-leafs, but I'm pretty sure I can squeeze them into kvm_cpu_caps with > a few extra shenanigans. > We can add it back for full CPUID leaves; it may even make sense to move PT processing there (but not in this series). Paolo
On Tue, Feb 25, 2020 at 04:18:38PM +0100, Vitaly Kuznetsov wrote: > Sean Christopherson <sean.j.christopherson@intel.com> writes: > > > > > 7. Profit! > > Would it be better or worse if we eliminate set_supported_cpuid() hook > completely by doing an ugly hack like (completely untested): > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index a2a091d328c6..5ad291d48e1b 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -1145,8 +1145,6 @@ struct kvm_x86_ops { > > void (*set_tdp_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3); > > - void (*set_supported_cpuid)(struct kvm_cpuid_entry2 *entry); > - > bool (*has_wbinvd_exit)(void); > > u64 (*read_l1_tsc_offset)(struct kvm_vcpu *vcpu); > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c > index e8beb1e542a8..88431fc02797 100644 > --- a/arch/x86/kvm/cpuid.c > +++ b/arch/x86/kvm/cpuid.c > @@ -749,6 +749,16 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) > cpuid_entry_override(entry, CPUID_8000_0008_EBX); > break; > } > + case 0x8000000A: > + if (boot_cpu_has(X86_FEATURE_SVM)) { > + entry->eax = 1; /* SVM revision 1 */ > + entry->ebx = 8; /* Lets support 8 ASIDs in case we add proper > + ASID emulation to nested SVM */ > + entry->ecx = 0; /* Reserved */ > + entry->edx = 0; /* Per default do not support any > + additional features */ Lucky thing that you suggested this change, patch ("KVM: SVM: Convert feature updates from CPUID to KVM cpu caps") was buggy in that clearing entry->edx here would wipe out all X86_FEATURE_NRIPS and X86_FEATURE_NPT. Only noticed it when moving this code.
Sean Christopherson <sean.j.christopherson@intel.com> writes: > On Tue, Feb 25, 2020 at 04:18:38PM +0100, Vitaly Kuznetsov wrote: >> Sean Christopherson <sean.j.christopherson@intel.com> writes: >> >> > >> > 7. Profit! >> >> Would it be better or worse if we eliminate set_supported_cpuid() hook >> completely by doing an ugly hack like (completely untested): >> >> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h >> index a2a091d328c6..5ad291d48e1b 100644 >> --- a/arch/x86/include/asm/kvm_host.h >> +++ b/arch/x86/include/asm/kvm_host.h >> @@ -1145,8 +1145,6 @@ struct kvm_x86_ops { >> >> void (*set_tdp_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3); >> >> - void (*set_supported_cpuid)(struct kvm_cpuid_entry2 *entry); >> - >> bool (*has_wbinvd_exit)(void); >> >> u64 (*read_l1_tsc_offset)(struct kvm_vcpu *vcpu); >> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c >> index e8beb1e542a8..88431fc02797 100644 >> --- a/arch/x86/kvm/cpuid.c >> +++ b/arch/x86/kvm/cpuid.c >> @@ -749,6 +749,16 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) >> cpuid_entry_override(entry, CPUID_8000_0008_EBX); >> break; >> } >> + case 0x8000000A: >> + if (boot_cpu_has(X86_FEATURE_SVM)) { >> + entry->eax = 1; /* SVM revision 1 */ >> + entry->ebx = 8; /* Lets support 8 ASIDs in case we add proper >> + ASID emulation to nested SVM */ >> + entry->ecx = 0; /* Reserved */ >> + entry->edx = 0; /* Per default do not support any >> + additional features */ > > Lucky thing that you suggested this change, patch ("KVM: SVM: Convert > feature updates from CPUID to KVM cpu caps") was buggy in that clearing > entry->edx here would wipe out all X86_FEATURE_NRIPS and X86_FEATURE_NPT. > Only noticed it when moving this code. > I plan to give your v2 a spin on AMD Epyc, just in case)