Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp951515pxb; Sun, 12 Sep 2021 03:39:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjM2XPI1/51LWu2FvqB5DkwV7v2QIcDSo2e08hDjcp0gH6w4xH91qdHExtKYsG0mfYGlsG X-Received: by 2002:a05:6402:430f:: with SMTP id m15mr7296117edc.115.1631443171859; Sun, 12 Sep 2021 03:39:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631443171; cv=none; d=google.com; s=arc-20160816; b=m5HPZlFfM+FOM+Cs7GWRTka8DW6d9tlthUe+tfE7z2NzNcUm76tMgC8TcfZcq37wUY PtK+vT6wMYDx2dElaPwfmlqEErlAULAy28alpWEE9nws6unpGR88ow5PJ0mGXeuqA7zG cz/N5vlYE13zZjkmgw57SAobkyTnJgK74cx7BVx2sjKnPuzxrsQ8yRLIA027zg7pcRhR hyhIPP9X/XSbHYBzi0FFJPNK6usMT5Fd7xiL1e7rISBXiDdZ3IchvAzIMivGQ9AwtLmB lmuAx8x/YSlB3tQ7Jt+P0Ovgy7wREfHXXmOD4gmACMjHtI6N221pmGZBK/Wp9QxPXVw3 2+oQ== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=+jtt+oEw1ZNN1QEhzO+iGOuy7I227KftkhvSAbDZ7/c=; b=HYraBak0ct0TqEnAVGFrD/ckYpLovXzWATbujZk84ho7ia0YYqKSBUBNirT2PfrTS3 XFWs9otWLrsUG5/nJQVHSx2otUvFru6jLepoELBUrqCqtDVeIyvHTV2jCRkTHkhvXO15 pUkbl8zVDTGSfpRqBZIDZBjdQ0c72Nc4giQe9c8s84Ch+FhvISzvxe37LIJv+rbE2Qin 8ldY+F1Dbw31MZW4VHsfR9OEbIzURSh4mj0Ad5gFjwb3QLxxJwYoX+guCwj01+BnXpVv tRMClRAmq+OYykRNZ5alwFVvBHLJMchyFG5SUiMVPQyjUd4ZRk3d6aQt7YOLrjmdcXGd BWPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="igpL6NC/"; 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 z2si4442636ejo.651.2021.09.12.03.39.07; Sun, 12 Sep 2021 03:39:31 -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="igpL6NC/"; 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 S235044AbhILKhm (ORCPT + 99 others); Sun, 12 Sep 2021 06:37:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25849 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234945AbhILKhh (ORCPT ); Sun, 12 Sep 2021 06:37:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631442983; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+jtt+oEw1ZNN1QEhzO+iGOuy7I227KftkhvSAbDZ7/c=; b=igpL6NC/oF/dPjTlZcJb8tXgigYbe9h2N8FLMkjoaj3f8kG/TcR1Ecx4felCBPdVtp/fzG hlr1IpWjnwf65RCFPwvL9i36SpDifCx+RymI1RRcRnaC7XfPMXYrtzy49Ef4y3fkVdp0iM Z5lNeP36w+fZzEKhBSBGujepnkKcCEg= 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-291-rwu6vjPmM4CHXSKAtNZ7OQ-1; Sun, 12 Sep 2021 06:36:20 -0400 X-MC-Unique: rwu6vjPmM4CHXSKAtNZ7OQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9F7F836307; Sun, 12 Sep 2021 10:36:18 +0000 (UTC) Received: from starship (unknown [10.35.206.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E9861B480; Sun, 12 Sep 2021 10:36:12 +0000 (UTC) Message-ID: Subject: Re: [RFC PATCH 1/3] KVM: nSVM: move nested_vmcb_check_cr3_cr4 logic in nested_vmcb_valid_sregs From: Maxim Levitsky To: Emanuele Giuseppe Esposito , kvm@vger.kernel.org Cc: Paolo Bonzini , 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 Date: Sun, 12 Sep 2021 13:36:11 +0300 In-Reply-To: <20210903102039.55422-2-eesposit@redhat.com> References: <20210903102039.55422-1-eesposit@redhat.com> <20210903102039.55422-2-eesposit@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2021-09-03 at 12:20 +0200, Emanuele Giuseppe Esposito wrote: > 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 > --- > 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 e5515477c30a..d2fe65e2a7a4 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))) Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky