[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PULL 31/53] KVM: x86: believe what KVM says about WAITPKG
From: |
Maxim Levitsky |
Subject: |
Re: [PULL 31/53] KVM: x86: believe what KVM says about WAITPKG |
Date: |
Tue, 07 Jul 2020 14:42:11 +0300 |
User-agent: |
Evolution 3.34.4 (3.34.4-1.fc31) |
On Mon, 2020-07-06 at 12:41 -0400, Paolo Bonzini wrote:
> Currently, QEMU is overriding KVM_GET_SUPPORTED_CPUID's answer for
> the WAITPKG bit depending on the "-overcommit cpu-pm" setting. This is a
> bad idea because it does not even check if the host supports it, but it
> can be done in x86_cpu_realizefn just like we do for the MONITOR bit.
>
> This patch moves it there, while making it conditional on host
> support for the related UMWAIT MSR.
>
> Cc: qemu-stable@nongnu.org
> Reported-by: Maxim Levitsky <mlevitsk@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> target/i386/cpu.c | 3 +++
> target/i386/kvm.c | 11 +++++------
> target/i386/kvm_i386.h | 1 +
> 3 files changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index c44cc510e1..dc9ba06f1f 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -6536,6 +6536,9 @@ static void x86_cpu_realizefn(DeviceState *dev, Error
> **errp)
> host_cpuid(5, 0, &cpu->mwait.eax, &cpu->mwait.ebx,
> &cpu->mwait.ecx, &cpu->mwait.edx);
> env->features[FEAT_1_ECX] |= CPUID_EXT_MONITOR;
> + if (kvm_enabled() && kvm_has_waitpkg()) {
> + env->features[FEAT_7_0_ECX] |= CPUID_7_0_ECX_WAITPKG;
> + }
> }
> if (kvm_enabled() && cpu->ucode_rev == 0) {
> cpu->ucode_rev = kvm_arch_get_supported_msr_feature(kvm_state,
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index 2b6b7443d2..b8455c89ed 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -411,12 +411,6 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s,
> uint32_t function,
> if (host_tsx_blacklisted()) {
> ret &= ~(CPUID_7_0_EBX_RTM | CPUID_7_0_EBX_HLE);
> }
> - } else if (function == 7 && index == 0 && reg == R_ECX) {
> - if (enable_cpu_pm) {
> - ret |= CPUID_7_0_ECX_WAITPKG;
> - } else {
> - ret &= ~CPUID_7_0_ECX_WAITPKG;
> - }
> } else if (function == 7 && index == 0 && reg == R_EDX) {
> /*
> * Linux v4.17-v4.20 incorrectly return ARCH_CAPABILITIES on SVM
> hosts.
> @@ -4730,3 +4724,8 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)
> {
> abort();
> }
> +
> +bool kvm_has_waitpkg(void)
> +{
> + return has_msr_umwait;
Note that this depends on the fix in the kernel
to report this msr only when UMWAIT is supported.
I personally don't mind that.
If we want to support older kernels that don't,
then we have to run 'cpuid' ourselves and check the result.
Otherwise looks good to me.
Best regards,
Maxim Levitsky
> +}
> diff --git a/target/i386/kvm_i386.h b/target/i386/kvm_i386.h
> index 00bde7acaf..064b8798a2 100644
> --- a/target/i386/kvm_i386.h
> +++ b/target/i386/kvm_i386.h
> @@ -44,6 +44,7 @@ void kvm_put_apicbase(X86CPU *cpu, uint64_t value);
>
> bool kvm_enable_x2apic(void);
> bool kvm_has_x2apic_api(void);
> +bool kvm_has_waitpkg(void);
>
> bool kvm_hv_vpindex_settable(void);
>
- [PULL 21/53] MAINTAINERS: Add an 'overall' entry for accelerators, (continued)
- [PULL 21/53] MAINTAINERS: Add an 'overall' entry for accelerators, Paolo Bonzini, 2020/07/06
- [PULL 22/53] MAINTAINERS: Cover the HAX accelerator stub, Paolo Bonzini, 2020/07/06
- [PULL 23/53] Makefile: Remove dangerous EOL trailing backslash, Paolo Bonzini, 2020/07/06
- [PULL 24/53] Makefile: Write MINIKCONF variables as one entry per line, Paolo Bonzini, 2020/07/06
- [PULL 16/53] i386: hvf: Move Guest LMA reset to macvm_set_cr0(), Paolo Bonzini, 2020/07/06
- [PULL 25/53] accel/Kconfig: Extract accel selectors into their own config, Paolo Bonzini, 2020/07/06
- [PULL 01/53] tcg/svm: use host cr4 during NPT page table walk, Paolo Bonzini, 2020/07/06
- [PULL 19/53] MAINTAINERS: Add Cameron as HVF co-maintainer, Paolo Bonzini, 2020/07/06
- [PULL 11/53] coverity: provide Coverity-friendly MIN_CONST and MAX_CONST, Paolo Bonzini, 2020/07/06
- [PULL 31/53] KVM: x86: believe what KVM says about WAITPKG, Paolo Bonzini, 2020/07/06
- Re: [PULL 31/53] KVM: x86: believe what KVM says about WAITPKG,
Maxim Levitsky <=
- [PULL 13/53] i386: hvf: Move synchronize functions to sysemu, Paolo Bonzini, 2020/07/06
- [PULL 15/53] i386: hvf: Make long mode enter and exit clearer, Paolo Bonzini, 2020/07/06
- [PULL 30/53] target/i386: implement undocumented "smsw r32" behavior, Paolo Bonzini, 2020/07/06
- [PULL 20/53] MAINTAINERS: Fix KVM path expansion glob, Paolo Bonzini, 2020/07/06
- [PULL 32/53] target/i386: sev: provide proper error reporting for query-sev-capabilities, Paolo Bonzini, 2020/07/06
- [PULL 26/53] accel/Kconfig: Add the TCG selector, Paolo Bonzini, 2020/07/06
- [PULL 40/53] pc: fix leak in pc_system_flash_cleanup_unused, Paolo Bonzini, 2020/07/06
- [PULL 29/53] target/i386: remove gen_io_end, Paolo Bonzini, 2020/07/06
- [PULL 33/53] target/i386: sev: fail query-sev-capabilities if QEMU cannot use SEV, Paolo Bonzini, 2020/07/06