From patchwork Sat May 23 16:14:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11566841 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 40B04138A for ; Sat, 23 May 2020 16:15:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2957920885 for ; Sat, 23 May 2020 16:15:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="g+cyEwqu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728137AbgEWQPX (ORCPT ); Sat, 23 May 2020 12:15:23 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:47355 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728025AbgEWQPW (ORCPT ); Sat, 23 May 2020 12:15:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590250521; 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=ytf9W2kex3b56H4BEKOUukloGENtrEZz4KuH9AmMNpQ=; b=g+cyEwquQ4ytNWuON3C3BagDVPR1LyAEYlnBJBg5tR8fo9+8F69pmhuu6BiaH4Im7RIW6c mXgpwhfYeWkaJRLzK4QVuoqPiSeMC6w49sQBszRTYtWI2LNAH3SlXi/tdHMSYoy9YPSZlB uop49GSr00Kuwl3njyfgPsdBZJbfp9E= 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-85-3rESmGjfPumnQqjegbACfQ-1; Sat, 23 May 2020 12:15:17 -0400 X-MC-Unique: 3rESmGjfPumnQqjegbACfQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8EBCF107ACCA; Sat, 23 May 2020 16:15:15 +0000 (UTC) Received: from starship.f32vm (unknown [10.35.206.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DD6B600E5; Sat, 23 May 2020 16:15:01 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , "H. Peter Anvin" , Tao Xu , Sean Christopherson , Jim Mattson , linux-kernel@vger.kernel.org, Joerg Roedel , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), Wanpeng Li , Ingo Molnar , Thomas Gleixner , Borislav Petkov , Vitaly Kuznetsov , Jingqi Liu , Maxim Levitsky Subject: [PATCH 1/2] kvm/x86/vmx: enable X86_FEATURE_WAITPKG in KVM capabilities Date: Sat, 23 May 2020 19:14:54 +0300 Message-Id: <20200523161455.3940-2-mlevitsk@redhat.com> In-Reply-To: <20200523161455.3940-1-mlevitsk@redhat.com> References: <20200523161455.3940-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 secondary execution controls as specified by VMX capability MSR, rather that we actually enable it for a guest. Fixes: e69e72faa3a0 KVM: x86: Add support for user wait instructions Suggested-by: Paolo Bonzini Signed-off-by: Maxim Levitsky Reviewed-by: Sean Christopherson --- 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 Sat May 23 16:14:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 11566843 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 B97EA15E4 for ; Sat, 23 May 2020 16:15:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9802C20872 for ; Sat, 23 May 2020 16:15:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hRh/Cn5n" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728141AbgEWQPb (ORCPT ); Sat, 23 May 2020 12:15:31 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:59981 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387867AbgEWQPb (ORCPT ); Sat, 23 May 2020 12:15:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590250530; 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=HFg02eb4YubKQIu550jTk5UUZALiVej3kr4L4u3iifQ=; b=hRh/Cn5nZVa4qrPZ8NTS7gKrk4lgtdo4R2EmxsRvC4MNZbClYFqXfYztsScxSIEjPN1Jvl Pq/sV0YYtXJYXY1A+7tXXAp3mzRCEV2Bz4RSgHTJbpsm8PtHQBW9g/LX1Zq0+M0W4qsUtA DgKWJuTJ/ij9+eas/9aeAFYJtojqDHc= 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-19-0ITODA4gNVadJer3b5CRCw-1; Sat, 23 May 2020 12:15:28 -0400 X-MC-Unique: 0ITODA4gNVadJer3b5CRCw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 810B18005AA; Sat, 23 May 2020 16:15:26 +0000 (UTC) Received: from starship.f32vm (unknown [10.35.206.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01ACC600E5; Sat, 23 May 2020 16:15:15 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , "H. Peter Anvin" , Tao Xu , Sean Christopherson , Jim Mattson , linux-kernel@vger.kernel.org, Joerg Roedel , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), Wanpeng Li , Ingo Molnar , Thomas Gleixner , Borislav Petkov , Vitaly Kuznetsov , Jingqi Liu , Maxim Levitsky Subject: [PATCH 2/2] kvm/x86: don't expose MSR_IA32_UMWAIT_CONTROL unconditionally Date: Sat, 23 May 2020 19:14:55 +0300 Message-Id: <20200523161455.3940-3-mlevitsk@redhat.com> In-Reply-To: <20200523161455.3940-1-mlevitsk@redhat.com> References: <20200523161455.3940-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 nested guest, if the L1 hypervisor is set to ignore unknown msrs, because the only other safety check that the kernel does is that it attempts to read the msr and rejects it if it gets an exception. Fixes: 6e3ba4abce KVM: vmx: Emulate MSR IA32_UMWAIT_CONTROL Signed-off-by: Maxim Levitsky Reviewed-by: Sean Christopherson --- 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; }