From mboxrd@z Thu Jan 1 00:00:00 1970 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=-11.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 14C0CC4727D for ; Tue, 29 Sep 2020 05:15:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CCE21206A4 for ; Tue, 29 Sep 2020 05:15:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725791AbgI2FP2 (ORCPT ); Tue, 29 Sep 2020 01:15:28 -0400 Received: from mga03.intel.com ([134.134.136.65]:10267 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725355AbgI2FP2 (ORCPT ); Tue, 29 Sep 2020 01:15:28 -0400 IronPort-SDR: Bm+EbaawbJDQ+rlpgwhgqSYR6TxIklYrLVzifWew0xHFwX1AZ6CFEw9jZYEI9EaHlAME2uK3Rf nd40msS0PbiQ== X-IronPort-AV: E=McAfee;i="6000,8403,9758"; a="162180219" X-IronPort-AV: E=Sophos;i="5.77,317,1596524400"; d="scan'208";a="162180219" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2020 22:15:27 -0700 IronPort-SDR: DTZmPi9P93L/egJWF9MbJKYfFpDPN2yT9BwsCdgxHKC1nCm2v7aLggLB4d/6P6AzP0ylnW/f9k T1oPt0BuLQ4A== X-IronPort-AV: E=Sophos;i="5.77,317,1596524400"; d="scan'208";a="457124988" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.160]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2020 22:15:27 -0700 Date: Mon, 28 Sep 2020 22:15:26 -0700 From: Sean Christopherson To: Maxim Levitsky Cc: kvm@vger.kernel.org, "H. Peter Anvin" , Ingo Molnar , Borislav Petkov , Vitaly Kuznetsov , Joerg Roedel , Paolo Bonzini , Wanpeng Li , Thomas Gleixner , linux-kernel@vger.kernel.org, Jim Mattson , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" Subject: Re: [PATCH v6 4/4] KVM: nSVM: implement on demand allocation of the nested state Message-ID: <20200929051526.GD353@linux.intel.com> References: <20200922211025.175547-1-mlevitsk@redhat.com> <20200922211025.175547-5-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200922211025.175547-5-mlevitsk@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Wed, Sep 23, 2020 at 12:10:25AM +0300, Maxim Levitsky wrote: > This way we don't waste memory on VMs which don't use nesting > virtualization even when the host enabled it for them. > > Signed-off-by: Maxim Levitsky > --- > arch/x86/kvm/svm/nested.c | 42 ++++++++++++++++++++++++++++++ > arch/x86/kvm/svm/svm.c | 55 ++++++++++++++++++++++----------------- > arch/x86/kvm/svm/svm.h | 6 +++++ > 3 files changed, 79 insertions(+), 24 deletions(-) > > diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c > index 09417f5197410..dd13856818a03 100644 > --- a/arch/x86/kvm/svm/nested.c > +++ b/arch/x86/kvm/svm/nested.c > @@ -467,6 +467,9 @@ int nested_svm_vmrun(struct vcpu_svm *svm) > > vmcb12 = map.hva; > > + if (WARN_ON(!svm->nested.initialized)) Probably should use WARN_ON_ONCE, if this is somehow it, userspace could easily spam the kernel. Side topic, do we actually need 'initialized'? Wouldn't checking for a valid nested.msrpm or nested.hsave suffice? > + return 1; > + > if (!nested_vmcb_checks(svm, vmcb12)) { > vmcb12->control.exit_code = SVM_EXIT_ERR; > vmcb12->control.exit_code_hi = 0; > @@ -684,6 +687,45 @@ int nested_svm_vmexit(struct vcpu_svm *svm) > return 0; > }