Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp50004ybm; Tue, 26 May 2020 10:27:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVBOawlGkP/5TmWmhpJvRNChbF9BP4TvYmSPs/RTneR6WqSS1I54CB6Xdds2yF5SLomK7/ X-Received: by 2002:a17:906:11c4:: with SMTP id o4mr2136378eja.163.1590514059896; Tue, 26 May 2020 10:27:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590514059; cv=none; d=google.com; s=arc-20160816; b=0yN1eSskr0ZWPi4YLy39e0FvnAPt8tnzymIkZHcahaOgFUa54lFBfu7NtOeQi+9E8g HN1MMgRJtAiipP8LRz45eWhNZ+UV+V5wZ+xJryIcdSEkRuQWW3IhzSv963Oh3bJNl2d1 BLMnORmFkfkenepx3aCdBngIp8H0v3NLOxadF9/gWfGzytoz+AEkWf4ytTIumLvwwQ6s 0V2vObPBLLJu/G7YpcZEkznHkQphKt8JmkQz9o9XZCxBcj7gv8QtwXPXaTOXPf8PvrBt 8BmzwL/EGWaYjOATS79of/gIPksDwtRC5UFSkSDKBs1kOZbLQ39XUN/0yQNmL3Vjci3T IYqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QATNBAlNqgPgKFpxZu85aWV0J1Km94CChkhQ5CPCspU=; b=v/k7zCBGcqE2SQLM7pG/yPVTaupfKbnGNGVIbMNKh+zTlvi0cbPWhJ8ZKwzYQXB46x 2CHQn89kbJCo3KlpCnh0yJxsWNyJkKtrOXenxZZejuQFBDYTVLXRDwqY9Q9p9f2wE7U9 66T0y0zKXfeeuS18RskbIJQ2fR+bIHUwEBzQ9orMAfPfQ2ZnSUFYeSaOhQ3zQOYfwz5V m10+07edq2mIpMqe/C2zgiP/hRIPxshhBBZyrj9gbJtWGWviTOYntSyb0lXTe1Lomas6 /lJwz/y6qmo/BOGEUw9yxIDHpRcfuH2oiIjBfli99WSz4nTc4cp7360vGOv/uHrcIGNg Tl2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="LNUbGMD/"; 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 dx10si254066ejb.496.2020.05.26.10.27.17; Tue, 26 May 2020 10:27:39 -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="LNUbGMD/"; 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 S2389427AbgEZRYB (ORCPT + 99 others); Tue, 26 May 2020 13:24:01 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:41726 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389328AbgEZRX4 (ORCPT ); Tue, 26 May 2020 13:23:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590513836; 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=QATNBAlNqgPgKFpxZu85aWV0J1Km94CChkhQ5CPCspU=; b=LNUbGMD/AtEDV+HGJ/lF4mzc+odUpjs45Tu469PrlyfBisCGSzEJGWteyqAnGcgN3ZThNM IPjOPf2NGY5sCl7IgZmUf96yT/DNMVZxyTxBfzPOXN0GFYMYB/n9QmE6VCla9zPjnSVj7i 5XKedyBY0XUexKxRoDF0JR4bCm/1MXY= 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-458-nvbmV7NmPUq9YqZKtwWagw-1; Tue, 26 May 2020 13:23:54 -0400 X-MC-Unique: nvbmV7NmPUq9YqZKtwWagw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 23B4E800688; Tue, 26 May 2020 17:23:53 +0000 (UTC) Received: from virtlab511.virt.lab.eng.bos.redhat.com (virtlab511.virt.lab.eng.bos.redhat.com [10.19.152.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 19AF65D9E5; Tue, 26 May 2020 17:23:50 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: vkuznets@redhat.com, mlevitsk@redhat.com, Sean Christopherson , Jim Mattson Subject: [PATCH 24/28] KVM: nSVM: split nested_vmcb_check_controls Date: Tue, 26 May 2020 13:23:04 -0400 Message-Id: <20200526172308.111575-25-pbonzini@redhat.com> In-Reply-To: <20200526172308.111575-1-pbonzini@redhat.com> References: <20200526172308.111575-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The authoritative state does not come from the VMCB once in guest mode, but KVM_SET_NESTED_STATE can still perform checks on L1's provided SVM controls because we get them from userspace. Therefore, split out a function to do them. Signed-off-by: Paolo Bonzini --- arch/x86/kvm/svm/nested.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index f3e70aee18cd..a504963ef532 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -203,26 +203,31 @@ static bool nested_svm_vmrun_msrpm(struct vcpu_svm *svm) return true; } -static bool nested_vmcb_checks(struct vmcb *vmcb) +static bool nested_vmcb_check_controls(struct vmcb_control_area *control) { - if ((vmcb->save.efer & EFER_SVME) == 0) + if ((control->intercept & (1ULL << INTERCEPT_VMRUN)) == 0) return false; - if (((vmcb->save.cr0 & X86_CR0_CD) == 0) && - (vmcb->save.cr0 & X86_CR0_NW)) + if (control->asid == 0) return false; - if ((vmcb->control.intercept & (1ULL << INTERCEPT_VMRUN)) == 0) + if ((control->nested_ctl & SVM_NESTED_CTL_NP_ENABLE) && + !npt_enabled) return false; - if (vmcb->control.asid == 0) + return true; +} + +static bool nested_vmcb_checks(struct vmcb *vmcb) +{ + if ((vmcb->save.efer & EFER_SVME) == 0) return false; - if ((vmcb->control.nested_ctl & SVM_NESTED_CTL_NP_ENABLE) && - !npt_enabled) + if (((vmcb->save.cr0 & X86_CR0_CD) == 0) && + (vmcb->save.cr0 & X86_CR0_NW)) return false; - return true; + return nested_vmcb_check_controls(&vmcb->control); } static void load_nested_vmcb_control(struct vcpu_svm *svm, -- 2.26.2