Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3398455pxv; Mon, 28 Jun 2021 03:47:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoyWLn2b0D9g2dHqF32TWjOlSL1+saNQ737Ry3E1EeRiqFM2kPyM/bBQ/5rxqKVGb6E9fF X-Received: by 2002:a05:6402:5248:: with SMTP id t8mr32402398edd.110.1624877271404; Mon, 28 Jun 2021 03:47:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624877271; cv=none; d=google.com; s=arc-20160816; b=nDm1AIHM1j0dtekYWenGZuGStFAnDhRj/NoMgDUtIFP70tv4DGV0LM3KfL9Bd4jbZ8 AYMsUFH3gYNpOSvU6+652FkBW6wMaGjfFlwmlm+GqyzW6l8F+/s2BjbxXsSVwBKJeZeA NemDMr+Gs9L7LEtB/B1H/ccbqOq0qc+3BHX7hK2zLqO5ZLlGTTN/CrvbfND73EO23/Ys vQ0Avg/GRjYIs7UKAml+HJoDl3yWMYZLdQ20rtTSvwJNeVAR5zL8v7DY5xg6gbmIaBJj K44yEpl3IsBvhZBWKtk2i8bQ8VKibDa16BekAZoJXb487B4K0ZjWQmHSkflhgc5nVXix JazA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rBfRa821p85I312i32ddAVzacLWsbIFKIiXFAUfQdyc=; b=XTsGiyFpP8hJ/QxZF9c3LziU82AES2oIV5TRrZG0QLOth4GVC4uXv5EoxcMnu7P10t bHX6loKjyeT/MUmYCYbyic9GPA9b8x7Yhv2xL2ck6q3/U4lbK+jWd6cnpc851O83mcoY 5f6cLk0/pi7J0TESyEqcDkABvSsQWDLnri7so0kwrQfG2pO1gOmHRBKz1Ff3W1akn2vp X4HBs7OVmduxCjocwUTq4tykeJUQZBJOwdpZRQbZmEF/fEmKig/BykWvAi8zM9FQQgjj tmyJyeu1YCiXa1obzPPj3WQYQyW0xd/1CR9UY6UHJh3KEqI3njfuIqtC+299qk76ac/O UCsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dpieVVRM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s18si15311228eji.59.2021.06.28.03.47.28; Mon, 28 Jun 2021 03:47:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dpieVVRM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232903AbhF1Krk (ORCPT + 99 others); Mon, 28 Jun 2021 06:47:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56626 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232798AbhF1KrW (ORCPT ); Mon, 28 Jun 2021 06:47:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624877096; 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=rBfRa821p85I312i32ddAVzacLWsbIFKIiXFAUfQdyc=; b=dpieVVRMxLGp6GUaYpiT6qSk0xRhZeKWAavQT57DhCUgfaWRiVB0aevU8whBl/oZYV+/Db nnrQeJf7qonVzvNj8zYBMNeZnWDrAl0F7wXbx9IhMV9EJvOJc2wz1nNzhbIqt878iK999U HyhgIbaSwWAsaokirgWvvFfCfs1Pp/o= 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-226-jczH1GhQMFaTHQTv1jc36A-1; Mon, 28 Jun 2021 06:44:55 -0400 X-MC-Unique: jczH1GhQMFaTHQTv1jc36A-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 8B4BE804300; Mon, 28 Jun 2021 10:44:54 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id C30B85C1CF; Mon, 28 Jun 2021 10:44:51 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , Maxim Levitsky , Cathy Avery , Emanuele Giuseppe Esposito , Tom Lendacky , Michael Roth , linux-kernel@vger.kernel.org Subject: [PATCH 5/6] KVM: nSVM: Restore nested control upon leaving SMM Date: Mon, 28 Jun 2021 12:44:24 +0200 Message-Id: <20210628104425.391276-6-vkuznets@redhat.com> In-Reply-To: <20210628104425.391276-1-vkuznets@redhat.com> References: <20210628104425.391276-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case nested state was saved/resored while in SMM, nested_load_control_from_vmcb12() which sets svm->nested.ctl was never called and the first nested_vmcb_check_controls() (either from nested_svm_vmrun() or from svm_set_nested_state() if save/restore cycle is repeated) is doomed to fail. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/svm/nested.c | 4 ++-- arch/x86/kvm/svm/svm.c | 7 ++++++- arch/x86/kvm/svm/svm.h | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index a1dec2c40181..6549e40155fa 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -304,8 +304,8 @@ static bool nested_vmcb_valid_sregs(struct kvm_vcpu *vcpu, return true; } -static void nested_load_control_from_vmcb12(struct vcpu_svm *svm, - struct vmcb_control_area *control) +void nested_load_control_from_vmcb12(struct vcpu_svm *svm, + struct vmcb_control_area *control) { copy_vmcb_control_area(&svm->nested.ctl, control); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index fbf1b352a9bb..525b07873927 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4344,6 +4344,7 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const char *smstate) u64 saved_efer = GET_SMSTATE(u64, smstate, 0x7ed0); u64 guest = GET_SMSTATE(u64, smstate, 0x7ed8); u64 vmcb12_gpa = GET_SMSTATE(u64, smstate, 0x7ee0); + struct vmcb *vmcb12; if (guest) { if (!guest_cpuid_has(vcpu, X86_FEATURE_SVM)) @@ -4359,7 +4360,11 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const char *smstate) if (svm_allocate_nested(svm)) return 1; - ret = enter_svm_guest_mode(vcpu, vmcb12_gpa, map.hva); + vmcb12 = map.hva; + + nested_load_control_from_vmcb12(svm, &vmcb12->control); + + ret = enter_svm_guest_mode(vcpu, vmcb12_gpa, vmcb12); kvm_vcpu_unmap(vcpu, &map, true); /* diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index ff2dac2b23b6..13f2d465ca36 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -481,6 +481,8 @@ int nested_svm_check_permissions(struct kvm_vcpu *vcpu); int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr, bool has_error_code, u32 error_code); int nested_svm_exit_special(struct vcpu_svm *svm); +void nested_load_control_from_vmcb12(struct vcpu_svm *svm, + struct vmcb_control_area *control); void nested_sync_control_from_vmcb02(struct vcpu_svm *svm); void nested_vmcb02_compute_g_pat(struct vcpu_svm *svm); void svm_switch_vmcb(struct vcpu_svm *svm, struct kvm_vmcb_info *target_vmcb); -- 2.31.1