Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp320831pxb; Wed, 3 Nov 2021 04:55:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1M8wO90lGDcsP4ZmeXg6Ve8EzxsFls1FfXBMZxejyyLa+hKKbBScLoqTJtGMZd5By5CeF X-Received: by 2002:a50:99c6:: with SMTP id n6mr57778036edb.171.1635940549658; Wed, 03 Nov 2021 04:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635940549; cv=none; d=google.com; s=arc-20160816; b=Rjo2jc3WSDVYXdsZUgoHAcZ6LFAdn/q5B020anc8elbTSViiyUkqsiUFcHhKhfeZ+F BaV3c1kll/nLHClFFyXnITZX1hIfs41MHBRoop6XNohkuw2dAinDhHXwbimhpzt7o214 KfM0aheJ4RWPuCsinfP6CCzfv/vvPcHH/ls7qaHJbsKZEYPHkL5JYCaY2+M2ImGbmgCl kahsxwT2NSjfP+i7+p4/UPcCmCZjtpvS7h8d5myzPDvSqpFDJaTmjZGbxC00gjl/yN/8 Oq+XJIuaP7xsADy4TxzfoSLjLGovAZRcxbslOdklAL+4K4pVjQr1Ne+pji6mZCr2DLI+ Cu/w== 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=PBCDUPBeDW8iF31Qz39WZCL9VVYXxbHCI/wd2pMkgyE=; b=Yrc0FT2i8Nwc4BKM0GtjV2V7v/4NecY7cuRbIxds43+lVe93QlMsodug2s3BGn630o vves6lyQWeqjJ4LyyVUCzng8iXiv1W6YBRFipqEnShCFagSs1DD7NdQnBNtcnhC8Klqv DGdVA2eFQbG3zpG1hpJUKwqqayTqeQjgQ+pAzgRxTMVR6YuKsjGUulMVa9QfYQHrbsvs jLxLiSsRTg3V4br5jpz6S0rKbLv+kojtPXpPay+8Y+7pyPYit/R7NrtgSnW3ad7nBgs9 vNfr1AwB/M+ZDbXBvrALRASFsaen/VNJIvLdOG8PHlq++C7e0u6RnWL3/036VrnYEZvj MyTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Uow0O9jE; 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 hr13si4296466ejc.695.2021.11.03.04.55.26; Wed, 03 Nov 2021 04:55:49 -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=Uow0O9jE; 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 S231975AbhKCL4N (ORCPT + 99 others); Wed, 3 Nov 2021 07:56:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:51818 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231922AbhKCL4L (ORCPT ); Wed, 3 Nov 2021 07:56:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635940414; 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=PBCDUPBeDW8iF31Qz39WZCL9VVYXxbHCI/wd2pMkgyE=; b=Uow0O9jEZQemT0/34GZN9BLshtkdjNjJEEBaxm0jJQMf0sT8mhHa0dyixuwwBKva8+16nM yWPadSfO0dLFcUn4yrIjky+YDo/ZPIDcwNNZKzc+wvE4Z4XEnEP2gSJjWnL68dVGlEFvHf HNaMGtNLCf5g5IM4Lq2heLn/lWbdHPA= 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-115-3JNURkOsOGm74vDTJZGJ4g-1; Wed, 03 Nov 2021 07:53:30 -0400 X-MC-Unique: 3JNURkOsOGm74vDTJZGJ4g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 567461006AA2; Wed, 3 Nov 2021 11:53:28 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 19E4D196E5; Wed, 3 Nov 2021 11:53:26 +0000 (UTC) From: Emanuele Giuseppe Esposito To: kvm@vger.kernel.org Cc: Paolo Bonzini , Maxim Levitsky , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Emanuele Giuseppe Esposito Subject: [PATCH v4 1/7] KVM: nSVM: move nested_vmcb_check_cr3_cr4 logic in nested_vmcb_valid_sregs Date: Wed, 3 Nov 2021 07:52:24 -0400 Message-Id: <20211103115230.720154-2-eesposit@redhat.com> In-Reply-To: <20211103115230.720154-1-eesposit@redhat.com> References: <20211103115230.720154-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Inline nested_vmcb_check_cr3_cr4 as it is not called by anyone else. Doing so simplifies next patches. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 510b833cbd39..9470933c77cd 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -260,27 +260,6 @@ static bool nested_vmcb_check_controls(struct kvm_vcpu *vcpu, return true; } -static bool nested_vmcb_check_cr3_cr4(struct kvm_vcpu *vcpu, - struct vmcb_save_area *save) -{ - /* - * These checks are also performed by KVM_SET_SREGS, - * except that EFER.LMA is not checked by SVM against - * CR0.PG && EFER.LME. - */ - if ((save->efer & EFER_LME) && (save->cr0 & X86_CR0_PG)) { - if (CC(!(save->cr4 & X86_CR4_PAE)) || - CC(!(save->cr0 & X86_CR0_PE)) || - CC(kvm_vcpu_is_illegal_gpa(vcpu, save->cr3))) - return false; - } - - if (CC(!kvm_is_valid_cr4(vcpu, save->cr4))) - return false; - - return true; -} - /* Common checks that apply to both L1 and L2 state. */ static bool nested_vmcb_valid_sregs(struct kvm_vcpu *vcpu, struct vmcb_save_area *save) @@ -302,7 +281,19 @@ static bool nested_vmcb_valid_sregs(struct kvm_vcpu *vcpu, if (CC(!kvm_dr6_valid(save->dr6)) || CC(!kvm_dr7_valid(save->dr7))) return false; - if (!nested_vmcb_check_cr3_cr4(vcpu, save)) + /* + * These checks are also performed by KVM_SET_SREGS, + * except that EFER.LMA is not checked by SVM against + * CR0.PG && EFER.LME. + */ + if ((save->efer & EFER_LME) && (save->cr0 & X86_CR0_PG)) { + if (CC(!(save->cr4 & X86_CR4_PAE)) || + CC(!(save->cr0 & X86_CR0_PE)) || + CC(kvm_vcpu_is_illegal_gpa(vcpu, save->cr3))) + return false; + } + + if (CC(!kvm_is_valid_cr4(vcpu, save->cr4))) return false; if (CC(!kvm_valid_efer(vcpu, save->efer))) -- 2.27.0