Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp1671121rwi; Thu, 3 Nov 2022 07:52:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4fwCUHdup55biw42GXgFYTA4L6PqxQc9khynwCU4RtGsqDdIJ8+TO5etacNydkICgBgaO8 X-Received: by 2002:a17:907:8a0a:b0:78d:b87d:e68a with SMTP id sc10-20020a1709078a0a00b0078db87de68amr28440722ejc.301.1667487175656; Thu, 03 Nov 2022 07:52:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667487175; cv=none; d=google.com; s=arc-20160816; b=XPb+LXriwREXhkk5XtdaRKcxCxVBolaz1HDDv8GvMu/a518d3G75uPBx+YJUGDZ4Ab Wrhkw1d5rybiv1L8W+J2z/sNF66N33AbKuzr2UGzIohiIQJ16Kq5wGAhPr4eI4zz3cPC 4T+/HxQHLaoxZllQNz/dpO4AVB4zZDbx2ajW77qEvKLgoz5ao/MS+pAB1WgGmo5/MdMd 19y+JHVnrlAI2jCOIAdQXKaDf/1nSzDX8EgwZuIru7DQzwcGgE3eY3ej/9MFuwLAM1Z5 x2YJGepuTr5E28ao958soyG6zTHHQVn7+0DPOOKE3xCQoHiCF2kC2ZGuGiEW6WqeVo7P 7P4A== 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=94fXNJlMtb+F/0JTvy69iWSeE6FRHdWRb8tmVfQpuZA=; b=cxh0mmOGGxXFXJn1I+73wQy2VXJaZyD7OFjwvzBMU1QAmx4x1NC8LpGtJAPFXvIS/6 NalqEoMFZ+VVvMo4QFsGJpKxEfMfKVBVfjrZOug54RCKbJkEBY8PLRk6wIUjWfnapqTh 3/7/A7oR3wKJ8T1ENZJujprmE3I80CtVn1vDiq5w8HlSW+EVDaX0+YoL8HNE6q+FIvzf zQcazzk2oGQwHs6IAR+MYrH/VR872nMZ0dbZvWPdrY1O57auIGZ2nl8KIM9ZxZ3FcJVN 1V03lxRjKTs7uH+NYzG0lRrbt7tzS38Oa8bIw8BPAfg760RdDMxbvjTPjUnF7bd0u0++ SJAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FgjUKtQd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020a1709065d0e00b0078e11a20640si655317ejt.2.2022.11.03.07.52.32; Thu, 03 Nov 2022 07:52:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FgjUKtQd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231382AbiKCOPY (ORCPT + 97 others); Thu, 3 Nov 2022 10:15:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231302AbiKCOPN (ORCPT ); Thu, 3 Nov 2022 10:15:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F9E31276F for ; Thu, 3 Nov 2022 07:14:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667484853; 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=94fXNJlMtb+F/0JTvy69iWSeE6FRHdWRb8tmVfQpuZA=; b=FgjUKtQdeNrPUsUCCCzL7gjHiHnF24qaHzPhX9H+cEJUFXsp7fca7G+SWmisE9OXnm8n6Y /aANB23FeeUusfCGI9fUn4K3AmD1PqTRTLa5US3c0igmXzv0IpNXCPElnF2JLcVq0/nM5O NhrqbawPSldtM8f24BBnAvjXphbni5k= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-213-EnmTDWMaOJ2pOzA6ZiKQVg-1; Thu, 03 Nov 2022 10:14:09 -0400 X-MC-Unique: EnmTDWMaOJ2pOzA6ZiKQVg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ECC8085A583; Thu, 3 Nov 2022 14:14:07 +0000 (UTC) Received: from amdlaptop.tlv.redhat.com (dhcp-4-238.tlv.redhat.com [10.35.4.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4900D40C6EC3; Thu, 3 Nov 2022 14:14:04 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , Thomas Gleixner , linux-kernel@vger.kernel.org, Chenyi Qiang , Yang Zhong , x86@kernel.org, Shuah Khan , Dave Hansen , "H. Peter Anvin" , Maxim Levitsky , Colton Lewis , Borislav Petkov , Peter Xu , Sean Christopherson , Jim Mattson , linux-kselftest@vger.kernel.org, Ingo Molnar , Wei Wang , David Matlack , stable@vger.kernel.org Subject: [PATCH v2 3/9] KVM: x86: add kvm_leave_nested Date: Thu, 3 Nov 2022 16:13:45 +0200 Message-Id: <20221103141351.50662-4-mlevitsk@redhat.com> In-Reply-To: <20221103141351.50662-1-mlevitsk@redhat.com> References: <20221103141351.50662-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org add kvm_leave_nested which wraps a call to nested_ops->leave_nested into a function. Cc: stable@vger.kernel.org Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 3 --- arch/x86/kvm/vmx/nested.c | 3 --- arch/x86/kvm/x86.c | 8 +++++++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index b74da40c1fc40c..bcc4f6620f8aec 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -1147,9 +1147,6 @@ void svm_free_nested(struct vcpu_svm *svm) svm->nested.initialized = false; } -/* - * Forcibly leave nested mode in order to be able to reset the VCPU later on. - */ void svm_leave_nested(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 61a2e551640a08..1ebe141a0a015f 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -6441,9 +6441,6 @@ static int vmx_get_nested_state(struct kvm_vcpu *vcpu, return kvm_state.size; } -/* - * Forcibly leave nested mode in order to be able to reset the VCPU later on. - */ void vmx_leave_nested(struct kvm_vcpu *vcpu) { if (is_guest_mode(vcpu)) { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index cd9eb13e2ed7fc..316ab1d5317f92 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -627,6 +627,12 @@ static void kvm_queue_exception_vmexit(struct kvm_vcpu *vcpu, unsigned int vecto ex->payload = payload; } +/* Forcibly leave the nested mode in cases like a vCPU reset */ +static void kvm_leave_nested(struct kvm_vcpu *vcpu) +{ + kvm_x86_ops.nested_ops->leave_nested(vcpu); +} + static void kvm_multiple_exception(struct kvm_vcpu *vcpu, unsigned nr, bool has_error, u32 error_code, bool has_payload, unsigned long payload, bool reinject) @@ -5193,7 +5199,7 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu, if (events->flags & KVM_VCPUEVENT_VALID_SMM) { #ifdef CONFIG_KVM_SMM if (!!(vcpu->arch.hflags & HF_SMM_MASK) != events->smi.smm) { - kvm_x86_ops.nested_ops->leave_nested(vcpu); + kvm_leave_nested(vcpu); kvm_smm_changed(vcpu, events->smi.smm); } -- 2.34.3