Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp30247pxt; Wed, 11 Aug 2021 13:42:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyk/QoeCrO/RyvV32etN9Uq8ILmPUpGE0tNpldSoKZVkGqFFxUwVlR84RHmkPYQuD0MckRn X-Received: by 2002:a17:906:a14b:: with SMTP id bu11mr383561ejb.260.1628714565142; Wed, 11 Aug 2021 13:42:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628714565; cv=none; d=google.com; s=arc-20160816; b=ULx73egJD/tgplzZYSeSEloNAJ4pAQe6kEHb/aj8udo+mKSj18wpAX9zxVfsTu/hdn /55r3bcKDqh40sfSSDCw8JYnz5JE408H/UIIHCT4gxXLDLuScBs20k61O5ls7CMNJ0GJ GhSZxmLiza7/ahZX+FD2pcVVgQLQ3GndQ5Kr5mD8S1Ioax/9NFm4YLm2iJnu7KGzLMAG mU3AtuPTIofvcjH011IIgGMlZYGdBm6XT0XkEjbkZRgA7cWp/6pg1oF08FnZggeqiOck YoTl29y5lxE/4Ch63gM1kIG0qITt+8V+1bdEDYGCc6v6JKj29Ws3X7KDhDWmgTB1J9Mz XdyQ== 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=0ka+IaiRT9uoAXjkqh+ylnD8wbn5wPgLIQgiXRNpQ8s=; b=VRS0616/wAjHzhSq/CxDIIIAH0eXQijyxvZ56DocXLRFezdzHWdOzT87OmQyNaiAJG IfGtubvrYwcs7Qjy01bNkI8SHkBvvtkbolaCqf0JQuOdbuW2f904DApgAaXPxq0aOWPp VL2qMhkFuxKn02CA5S+CcYulgD7es0i5yO7W0E0MTCtCQlnmww/Vi7Whl/15qSs4EX5n 4LOaYuyg8MkR6teIS4EFG0I/JzBT+7pQLO+v3MDrgIwTVYso6/HTzVFNxXKz7R6LCUb+ WwUujjSMo0Ie2GzbKVMXZm5VzlciwRqwbQQY5Ao25OdPBnnhCs3s8UPVdsCgDRiVxj4d bY8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cGZCYhOr; 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 y2si389252edv.102.2021.08.11.13.42.16; Wed, 11 Aug 2021 13:42:45 -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=cGZCYhOr; 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 S231991AbhHKUif (ORCPT + 99 others); Wed, 11 Aug 2021 16:38:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43406 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbhHKUid (ORCPT ); Wed, 11 Aug 2021 16:38:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628714289; 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=0ka+IaiRT9uoAXjkqh+ylnD8wbn5wPgLIQgiXRNpQ8s=; b=cGZCYhOrBB82HHOOoSZ1cP2h5egMPOQt64w+dOjMMnKP1liWPysGqaXPgNHFuDKz5E1YkX eZjFj5ceWSg/IscVCuyd/KFk21UFgd2LKVmCXDBefVRo7QGTEegUTJu2MvkOnEhwiCsyrD bLBqWztz8I6PF/0rVk6TU+W88HWD67M= 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-196-udhTEI-HOB2sH51f10f_Gg-1; Wed, 11 Aug 2021 16:38:05 -0400 X-MC-Unique: udhTEI-HOB2sH51f10f_Gg-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 6071818C89E6; Wed, 11 Aug 2021 20:38:04 +0000 (UTC) Received: from starship (unknown [10.35.206.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76DC56A056; Wed, 11 Aug 2021 20:37:57 +0000 (UTC) Message-ID: <3194331f42f5bcf760564b9714edf3d99d7a7b73.camel@redhat.com> Subject: Re: [PATCH 1/2] 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 , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org Date: Wed, 11 Aug 2021 23:37:56 +0300 In-Reply-To: <20210809145343.97685-2-eesposit@redhat.com> References: <20210809145343.97685-1-eesposit@redhat.com> <20210809145343.97685-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 Mon, 2021-08-09 at 16:53 +0200, Emanuele Giuseppe Esposito wrote: > nested_vmcb_check_cr3_cr4 is not called by anyone else, and removing the > call simplifies next patch Tiny nitpick: I would call this 'inline the nested_vmcb_check_cr3_cr4' instead of move, but please feel free to ignore. Reviewed-by: Maxim Levitsky > > 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 5e13357da21e..0ac2d14add15 100644 > --- a/arch/x86/kvm/svm/nested.c > +++ b/arch/x86/kvm/svm/nested.c > @@ -257,27 +257,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) > @@ -299,7 +278,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)))