Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3530342pxk; Mon, 28 Sep 2020 22:20:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVRDl5hsoth1uVnwk3QqZkaiqrO0fvONbxowJk2DDWlzZJ9pPtUGzZZgbFrEywr663MTqm X-Received: by 2002:a17:906:4bc4:: with SMTP id x4mr2226801ejv.240.1601356817208; Mon, 28 Sep 2020 22:20:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601356817; cv=none; d=google.com; s=arc-20160816; b=IqmPArKFd+/UoWjTpGUQ7XKGwTK13JU8z+EW++5CUD/7Yfz1bF7NF+qhv8zTAsnJsO 3vyO3+dasRM2XCPAL750O1YPprIMGACo9LYdDWpQ4dC7XiMiz533dhS/b3SqEsr9pBLd CXMqadc0wv8r7ivjbj627aFVLa40T0SCI7CFM6Zater4jX5YI0VPb14pY+qIlFGpy07m T5zfboTXk0PgvrtEE1QmQJdXyc6HwFcQ4WtAH0sVGa22TSMfu1CuQ1CFMOWio9r53Rug XJRwZthYWj5QioPQb1UXa50asj9LDFcYYL8gRjbnfLj3jqVOYw4fRmDDTPYsFFOQR2/h 29QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=0S3Im1+OL3uLQ6mZxkMlVjlSwmPX1id3VrcQyG41jMQ=; b=rq+Jj0XpdkCIfilWDV9ap4sVISF9bCCB1tTtDS5gMLP+WiRO01FXUw+/vdA8uJpeTa zydvJBxZORVwZTSQm6ZqWBjo+AZmak81z35WEosNUg7mRcZ/43iRVcbSkACjWAp9CW6c HkS+R4ZVCW2SGmVTKuH8eUj327QKhzoXt3okRiezMCyW5vi8C9joyynQARdSnsYW/f8k 95xnO0462ERJr4DwftPYxH+4fYeZCXdHmyPNWL/xC65fhhhF6U09U/D226/j/tLdrGH+ 4uNq2K3+djoDTXkdbNT9kJPx9t60s5NN4w5t52WtzE48ZpncUulTLCSqf8XpbU9aDYYz tePg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s13si2137979edj.323.2020.09.28.22.19.45; Mon, 28 Sep 2020 22:20:17 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725819AbgI2FP2 (ORCPT + 99 others); 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: linux-kernel@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; > }