From patchwork Wed May 27 14:04:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11573073 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4253A90 for ; Wed, 27 May 2020 14:04:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B24D20EDD for ; Wed, 27 May 2020 14:04:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TlyRv+7f" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730363AbgE0OEl (ORCPT ); Wed, 27 May 2020 10:04:41 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:58036 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730258AbgE0OEk (ORCPT ); Wed, 27 May 2020 10:04:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590588280; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LoMxv8kbrQ7HIAUcS1Qgahod+d8JOwkdyw5s7rWVktc=; b=TlyRv+7fD16zpHxZezzCBJowxVL0lQuNe2jKaQE7Uk+fLt5NE1T2FAb1ofcuXZ5FT77IbI 2cvNBO4LKpCYz3GyRrejUciRCwsYYK0ZkWUBIKczf5QlVAADSyqOhGkto4rDAytiPZdyn/ V03kJM2nnwCX8PPmRS3iT5I0k+7lNZk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-76-G9Dv8E5LO6mDJTCtZeQgzQ-1; Wed, 27 May 2020 10:04:38 -0400 X-MC-Unique: G9Dv8E5LO6mDJTCtZeQgzQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E203519057A1; Wed, 27 May 2020 14:04:36 +0000 (UTC) Received: from starship.f32vm (unknown [10.35.206.172]) by smtp.corp.redhat.com (Postfix) with ESMTP id D21471C946; Wed, 27 May 2020 14:04:32 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ingo Molnar , Borislav Petkov , Sean Christopherson , Jingqi Liu , Tao Xu , Paolo Bonzini , Thomas Gleixner , Vitaly Kuznetsov , "H. Peter Anvin" , Joerg Roedel , Wanpeng Li , Jim Mattson , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), Maxim Levitsky , Krish Sadhukhan Subject: [PATCH v3 1/2] KVM: VMX: enable X86_FEATURE_WAITPKG in KVM capabilities Date: Wed, 27 May 2020 17:04:24 +0300 Message-Id: <20200527140425.3484-2-mlevitsk@redhat.com> In-Reply-To: <20200527140425.3484-1-mlevitsk@redhat.com> References: <20200527140425.3484-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Even though we might not allow the guest to use WAITPKG's new instructions, we should tell KVM that the feature is supported by the host CPU. Note that vmx_waitpkg_supported checks that WAITPKG _can_ be set in the secondary execution controls as specified by VMX capability MSR, rather that indicate that we actually enable it for a guest. Fixes: e69e72faa3a07 (KVM: x86: Add support for user wait instructions) Suggested-by: Paolo Bonzini Signed-off-by: Maxim Levitsky Reviewed-by: Sean Christopherson Reviewed-by: Krish Sadhukhan --- arch/x86/kvm/vmx/vmx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 55712dd86bafa..fca493d4517c5 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7298,6 +7298,9 @@ static __init void vmx_set_cpu_caps(void) /* CPUID 0x80000001 */ if (!cpu_has_vmx_rdtscp()) kvm_cpu_cap_clear(X86_FEATURE_RDTSCP); + + if (vmx_waitpkg_supported()) + kvm_cpu_cap_check_and_set(X86_FEATURE_WAITPKG); } static void vmx_request_immediate_exit(struct kvm_vcpu *vcpu) From patchwork Wed May 27 14:04:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11573077 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3830190 for ; Wed, 27 May 2020 14:04:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20D8120C56 for ; Wed, 27 May 2020 14:04:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LgQ/OqB5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730380AbgE0OEt (ORCPT ); Wed, 27 May 2020 10:04:49 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:20766 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730378AbgE0OEt (ORCPT ); Wed, 27 May 2020 10:04:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590588287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vlVIr30v//g+9i0b5CXbC5CgscrkJJKNK4GDkeNGLN8=; b=LgQ/OqB5AP8qz5t6Tzr4V4Nr0xTTlm5j4kShL6HDmy2ujxtaMZ0XZeyiGUYcX/0arOy2oZ ptCt2q7R2mFo2XbH/pNXoIPCgKS+z52z60nqphdhg1JLy4TvAmZvBScy8DftSqwhN9fNL4 F5V+jJFjtuHOcQ7mGOUN6rfVWoSpYuA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-E90PUzbCNjmMj-KVuivPGQ-1; Wed, 27 May 2020 10:04:46 -0400 X-MC-Unique: E90PUzbCNjmMj-KVuivPGQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 58431474; Wed, 27 May 2020 14:04:44 +0000 (UTC) Received: from starship.f32vm (unknown [10.35.206.172]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F2571A8EA; Wed, 27 May 2020 14:04:37 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ingo Molnar , Borislav Petkov , Sean Christopherson , Jingqi Liu , Tao Xu , Paolo Bonzini , Thomas Gleixner , Vitaly Kuznetsov , "H. Peter Anvin" , Joerg Roedel , Wanpeng Li , Jim Mattson , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), Maxim Levitsky , Krish Sadhukhan Subject: [PATCH v3 2/2] KVM: x86: don't expose MSR_IA32_UMWAIT_CONTROL unconditionally Date: Wed, 27 May 2020 17:04:25 +0300 Message-Id: <20200527140425.3484-3-mlevitsk@redhat.com> In-Reply-To: <20200527140425.3484-1-mlevitsk@redhat.com> References: <20200527140425.3484-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This MSR is only available when the host supports WAITPKG feature. This breaks a L2 guest, if the L0 is set to ignore the unknown MSRs, because the only other safety check that the L1 kernel does is an attempt to read the MSR, and it succeeds since L0 ignores that read. This makes L1 kernel to inform its qemu that MSR_IA32_UMWAIT_CONTROL is a supported MSR but later on when qemu attempts to set it in the host state this fails since it is not supported. Fixes: 6e3ba4abcea56 (KVM: vmx: Emulate MSR IA32_UMWAIT_CONTROL) Signed-off-by: Maxim Levitsky Reviewed-by: Sean Christopherson Reviewed-by: Krish Sadhukhan --- arch/x86/kvm/x86.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b226fb8abe41b..4752293312947 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5316,6 +5316,10 @@ static void kvm_init_msr_list(void) min(INTEL_PMC_MAX_GENERIC, x86_pmu.num_counters_gp)) continue; break; + case MSR_IA32_UMWAIT_CONTROL: + if (!kvm_cpu_cap_has(X86_FEATURE_WAITPKG)) + continue; + break; default: break; }