From patchwork Thu Jan 14 20:54:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 12020903 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A838BC433E6 for ; Thu, 14 Jan 2021 20:56:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C03B23A79 for ; Thu, 14 Jan 2021 20:56:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729235AbhANU4e (ORCPT ); Thu, 14 Jan 2021 15:56:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58551 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727152AbhANU4d (ORCPT ); Thu, 14 Jan 2021 15:56:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610657707; 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=Sjyxhinw36uvHQq417p5mpNAZODTNW/mmcrP3tZ/skE=; b=WZr/O74j5Dsw1IamrVLKi+7cnLkeXwRrbeuYuu06UWcUJ/BvO4c6pidjZJLAGmBm4c9nOk z/X3XEzEvNtnRazBMxclA4aLpNpppVBVU7adtSX2xsGp3sgOz1zQRzw3wQPcM4EsQsYvh7 UoB0iJtwaefNXd5OpE6omKMw4tRDLnM= 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-51-zCpK3h7iOsy7slLYsyEwHA-1; Thu, 14 Jan 2021 15:55:03 -0500 X-MC-Unique: zCpK3h7iOsy7slLYsyEwHA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 76082107ACF9; Thu, 14 Jan 2021 20:55:00 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA5E25C1C5; Thu, 14 Jan 2021 20:54:55 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Thomas Gleixner , x86@kernel.org, Borislav Petkov , Paolo Bonzini , Ingo Molnar , Vitaly Kuznetsov , Joerg Roedel , Wanpeng Li , "H. Peter Anvin" , Sean Christopherson , linux-kernel@vger.kernel.org, Jim Mattson , Maxim Levitsky Subject: [PATCH v2 1/3] KVM: nVMX: Always call sync_vmcs02_to_vmcs12_rare on migration Date: Thu, 14 Jan 2021 22:54:47 +0200 Message-Id: <20210114205449.8715-2-mlevitsk@redhat.com> In-Reply-To: <20210114205449.8715-1-mlevitsk@redhat.com> References: <20210114205449.8715-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Even when we are outside the nested guest, some vmcs02 fields are not in sync vs vmcs12. However during the migration, the vmcs12 has to be up to date to be able to load it later after the migration. To fix that, call that function. Fixes: 7952d769c29ca ("KVM: nVMX: Sync rarely accessed guest fields only when needed") Signed-off-by: Maxim Levitsky Reviewed-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 0fbb46990dfce..776688f9d1017 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -6077,11 +6077,14 @@ static int vmx_get_nested_state(struct kvm_vcpu *vcpu, if (is_guest_mode(vcpu)) { sync_vmcs02_to_vmcs12(vcpu, vmcs12); sync_vmcs02_to_vmcs12_rare(vcpu, vmcs12); - } else if (!vmx->nested.need_vmcs12_to_shadow_sync) { - if (vmx->nested.hv_evmcs) - copy_enlightened_to_vmcs12(vmx); - else if (enable_shadow_vmcs) - copy_shadow_to_vmcs12(vmx); + } else { + copy_vmcs02_to_vmcs12_rare(vcpu, get_vmcs12(vcpu)); + if (!vmx->nested.need_vmcs12_to_shadow_sync) { + if (vmx->nested.hv_evmcs) + copy_enlightened_to_vmcs12(vmx); + else if (enable_shadow_vmcs) + copy_shadow_to_vmcs12(vmx); + } } BUILD_BUG_ON(sizeof(user_vmx_nested_state->vmcs12) < VMCS12_SIZE); From patchwork Thu Jan 14 20:54:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 12020905 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAC9CC43381 for ; Thu, 14 Jan 2021 20:56:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 96A2023A9F for ; Thu, 14 Jan 2021 20:56:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729245AbhANU4l (ORCPT ); Thu, 14 Jan 2021 15:56:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22291 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726695AbhANU4l (ORCPT ); Thu, 14 Jan 2021 15:56:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610657714; 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=xXsMcye107TRTUOx9sAA63kyUX0vbBZCLWLrhOEo8GI=; b=WL6B5VPBku1r3GWcgbDwJmQ+tyyhOL1o8m7bXhjXDlByggs7TF/gp+12ISrvzMM6BDWK20 bpUsEFkNxmFeyZQpV1DmG/jN5ko/yx94xMzbXlNtKBGA2O6F4DWCnmN0xZ5lYSUCtFBWEP H2Ef7DUJ5WOzuJpPv3IpHiEvk+MHDvk= 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-58-Dzb7FMrbMWi4MozDekzYBA-1; Thu, 14 Jan 2021 15:55:10 -0500 X-MC-Unique: Dzb7FMrbMWi4MozDekzYBA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 247C4806663; Thu, 14 Jan 2021 20:55:07 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB6A15C1C5; Thu, 14 Jan 2021 20:55:00 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Thomas Gleixner , x86@kernel.org, Borislav Petkov , Paolo Bonzini , Ingo Molnar , Vitaly Kuznetsov , Joerg Roedel , Wanpeng Li , "H. Peter Anvin" , Sean Christopherson , linux-kernel@vger.kernel.org, Jim Mattson , Maxim Levitsky Subject: [PATCH v2 2/3] KVM: nVMX: add kvm_nested_vmlaunch_resume tracepoint Date: Thu, 14 Jan 2021 22:54:48 +0200 Message-Id: <20210114205449.8715-3-mlevitsk@redhat.com> In-Reply-To: <20210114205449.8715-1-mlevitsk@redhat.com> References: <20210114205449.8715-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is very helpful for debugging nested VMX issues. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/trace.h | 30 ++++++++++++++++++++++++++++++ arch/x86/kvm/vmx/nested.c | 6 ++++++ arch/x86/kvm/x86.c | 1 + 3 files changed, 37 insertions(+) diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h index 2de30c20bc264..663d1b1d8bf64 100644 --- a/arch/x86/kvm/trace.h +++ b/arch/x86/kvm/trace.h @@ -554,6 +554,36 @@ TRACE_EVENT(kvm_nested_vmrun, __entry->npt ? "on" : "off") ); + +/* + * Tracepoint for nested VMLAUNCH/VMRESUME + */ +TRACE_EVENT(kvm_nested_vmlaunch_resume, + TP_PROTO(__u64 rip, __u64 vmcs, __u64 nested_rip, + __u32 entry_intr_info), + TP_ARGS(rip, vmcs, nested_rip, entry_intr_info), + + TP_STRUCT__entry( + __field( __u64, rip ) + __field( __u64, vmcs ) + __field( __u64, nested_rip ) + __field( __u32, entry_intr_info ) + ), + + TP_fast_assign( + __entry->rip = rip; + __entry->vmcs = vmcs; + __entry->nested_rip = nested_rip; + __entry->entry_intr_info = entry_intr_info; + ), + + TP_printk("rip: 0x%016llx vmcs: 0x%016llx nrip: 0x%016llx " + "entry_intr_info: 0x%08x", + __entry->rip, __entry->vmcs, __entry->nested_rip, + __entry->entry_intr_info) +); + + TRACE_EVENT(kvm_nested_intercepts, TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u32 intercept1, __u32 intercept2, __u32 intercept3), diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 776688f9d1017..cd51b66480d52 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3327,6 +3327,12 @@ enum nvmx_vmentry_status nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu, !(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_BNDCFGS)) vmx->nested.vmcs01_guest_bndcfgs = vmcs_read64(GUEST_BNDCFGS); + trace_kvm_nested_vmlaunch_resume(kvm_rip_read(vcpu), + vmx->nested.current_vmptr, + vmcs12->guest_rip, + vmcs12->vm_entry_intr_info_field); + + /* * Overwrite vmcs01.GUEST_CR3 with L1's CR3 if EPT is disabled *and* * nested early checks are disabled. In the event of a "late" VM-Fail, diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index a480804ae27a3..7c6e94e32100e 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11562,6 +11562,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_inj_virq); EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_page_fault); EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_msr); EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_cr); +EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_nested_vmlaunch_resume); EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_nested_vmrun); EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_nested_vmexit); EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_nested_vmexit_inject); From patchwork Thu Jan 14 20:54:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 12020907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 749DDC433E0 for ; Thu, 14 Jan 2021 20:57:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 28F2A23A79 for ; Thu, 14 Jan 2021 20:57:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729388AbhANU4o (ORCPT ); Thu, 14 Jan 2021 15:56:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40862 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729262AbhANU4m (ORCPT ); Thu, 14 Jan 2021 15:56:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610657716; 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=zLHJA1TpNmni7zCQ/Lgvyb1GSyvjz6b0bgrDebQHL0w=; b=a2YR93xfHHPmIN4d/Mq2WE017OSpfqv/UZXpN+2YA836bS3ylblYFPSeGx53XlmRuBlz57 j5MLA7vhLLWejiFyC+yyfjzbaE+QHLgBWPjREzyjIfdc50L0hiXJR+tiondwzpkref2Pb5 5rjIkeyoGxTQv2LxPW5IKTupWMu5+BI= 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-310-EISxNTwcPnWDvzfUTYdWnw-1; Thu, 14 Jan 2021 15:55:15 -0500 X-MC-Unique: EISxNTwcPnWDvzfUTYdWnw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7A55E100F341; Thu, 14 Jan 2021 20:55:13 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A35B5C1C5; Thu, 14 Jan 2021 20:55:07 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Thomas Gleixner , x86@kernel.org, Borislav Petkov , Paolo Bonzini , Ingo Molnar , Vitaly Kuznetsov , Joerg Roedel , Wanpeng Li , "H. Peter Anvin" , Sean Christopherson , linux-kernel@vger.kernel.org, Jim Mattson , Maxim Levitsky Subject: [PATCH v2 3/3] KVM: VMX: read idt_vectoring_info a bit earlier Date: Thu, 14 Jan 2021 22:54:49 +0200 Message-Id: <20210114205449.8715-4-mlevitsk@redhat.com> In-Reply-To: <20210114205449.8715-1-mlevitsk@redhat.com> References: <20210114205449.8715-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This allows it to be printed correctly by the trace print that follows. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/vmx/vmx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 2af05d3b05909..9b6e7dbf5e2bd 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6771,6 +6771,8 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu) } vmx->exit_reason = vmcs_read32(VM_EXIT_REASON); + vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD); + if (unlikely((u16)vmx->exit_reason == EXIT_REASON_MCE_DURING_VMENTRY)) kvm_machine_check(); @@ -6780,7 +6782,6 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu) return EXIT_FASTPATH_NONE; vmx->loaded_vmcs->launched = 1; - vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD); vmx_recover_nmi_blocking(vmx); vmx_complete_interrupts(vmx);