Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1165675pxb; Tue, 8 Feb 2022 10:42:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYqMv+wTmsFH9JBZcu+BMaE+S78Jd2WB+MccbN/28zBA69iWV1D8JSgwBSnpcbwGHbmsjL X-Received: by 2002:a17:902:da84:: with SMTP id j4mr4248071plx.108.1644345727836; Tue, 08 Feb 2022 10:42:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644345727; cv=none; d=google.com; s=arc-20160816; b=S5xdIVWn0DN6XYrLMv1+4KApZCQHhCPdYJdLl6p0IpFcjvEAnAVlfWv6CF+3YtZchG ITv/XPrndEI6MFhP6PgRi8A0vAoIUM8xDnmq99aJwSAIPpeUMutPmUzbLai2i7dJD1aC 8bl9aiBtHkRZa+BCjzcG60DySqitVzhdLoNv9hB5bz8/hXfMttHJZwi1kds2WdCfAbfQ EjPIdya1fr8+mwwb7cF+VS4PAJets4dgPLw+pUp74wNAaTzE+XX+x+b7gAZiv82BN3rT KW9rdqU+Z4kO1feyqm/usOI4R0LPqUY8MAGopfD2xmZYoO8pLcdsec600i/wcYisQa3e 1CbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=BhxzVjZr2SNzqHU8dl3WZkOg+9n73v4zh51iEiFYkNg=; b=GqWmT3NbkYgifwqDeizYZ81zdDF7+erJNRlJxgUSFwyqQa1yaRQp/JhW0SIUWsPZfL 0Ov3vgSvqhWvpfba1ShWs6a6OnPZC9thppM+lAmrmGo4T3AhmCKeeu7LbOslx7SAWvVL LN1QIVpvCFxMXbODlxT+QZpZLfzsvA2CI4NBzHsyk65URETUmQ08+X05qVBKmWv13S8J 3C8oKZzRo4eSP+sYvHsr5MgYqHCz/8rqz4gHxHotYwm3WsKWyODF27YSLdg00WusC24u oGwY5wSM9paTC2I7u/FfmEJxJwycbDNutXe5QszzF2Hrh/3d+eYazF+2ouZq3yp4K7I+ U3yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=jx4XAzAU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w22si14148730pfu.333.2022.02.08.10.41.55; Tue, 08 Feb 2022 10:42:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=jx4XAzAU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244099AbiBGWRa (ORCPT + 99 others); Mon, 7 Feb 2022 17:17:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244074AbiBGWRX (ORCPT ); Mon, 7 Feb 2022 17:17:23 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 995A9C061355 for ; Mon, 7 Feb 2022 14:17:22 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id s14so467199pfw.3 for ; Mon, 07 Feb 2022 14:17:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=BhxzVjZr2SNzqHU8dl3WZkOg+9n73v4zh51iEiFYkNg=; b=jx4XAzAUQTqRAztXU98sKZ6bOQXbAIjv4M+D3fDMo4P6/vN0Uag8uadVd5UIRITSeh SRTu4nFI5Yv07DbbXV7RUSj6bsPNRQHWcVdnkkXb5VQ6AkMO5t9uq03nA8iKzIyl5wSd W36GUSH5eXvPWu3HwO4lob7qsG6nNRF/1NE22gj3Q3n3gThgVFIt1Ti81f9TvZWiq+Nh IhD6WCOWwMIp8kLcIoAXhOHts6QqnIgLuZkFygsKNqmpRumaq90YO7A2pbMs87+AF0d6 ONDi4uVJ4lkC9uNgXzRnEyJqIkHy6V9uilRDo4H2J9yqackqX1TRa3VmfGOZPv12ILK3 qaIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=BhxzVjZr2SNzqHU8dl3WZkOg+9n73v4zh51iEiFYkNg=; b=xIlU5UD8/ookJXOEJLLTTnduC5JbFv0RWhEOnn4E1/if1Ipghs5Stor0fbNIPuDIUR KpuNPyzM4QEAbN6yLXgcv2ahMchhuE1uZdfeCeIhxlt5ccoqODZUrL1peBYLfM1zrNhK Kf7sSzqJgK2IwaBxUUdkwBf2kj8xP6WARr4EX9wVZRrkdYEkZPRIfyJFfW1CLnxrToud vi2pOPrGE1nHCzvBoUpu4MZKtfbl2zo08wit2kcQo4UJT9ZA24HFl1tLYH9HY8niqbUB s/4YTLE1mk7BETUqT7NNvuCVPNgeCbQlsqNs8HYoPWXD2WrG/8dMNUvrXqZZLiNNjfoX O/Fw== X-Gm-Message-State: AOAM533CeRYFneGtTh35RQPeskNrScRHnwzz+L8eH0O5/k+eps9Of7gc +zcnAkKFBRPKW9mfVbOp8HtArw== X-Received: by 2002:a63:6983:: with SMTP id e125mr1180405pgc.574.1644272241901; Mon, 07 Feb 2022 14:17:21 -0800 (PST) Received: from google.com (254.80.82.34.bc.googleusercontent.com. [34.82.80.254]) by smtp.gmail.com with ESMTPSA id j4sm13274215pfc.217.2022.02.07.14.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 14:17:21 -0800 (PST) Date: Mon, 7 Feb 2022 22:17:17 +0000 From: David Matlack To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, seanjc@google.com, vkuznets@redhat.com Subject: Re: [PATCH 11/23] KVM: MMU: do not recompute root level from kvm_mmu_role_regs Message-ID: References: <20220204115718.14934-1-pbonzini@redhat.com> <20220204115718.14934-12-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 07, 2022 at 10:10:39PM +0000, David Matlack wrote: > On Fri, Feb 04, 2022 at 06:57:06AM -0500, Paolo Bonzini wrote: > > The root_level can be found in the cpu_role (in fact the field > > is superfluous and could be removed, but one thing at a time). > > Since there is only one usage left of role_regs_to_root_level, > > inline it into kvm_calc_cpu_role. > > > > Signed-off-by: Paolo Bonzini > > --- > > arch/x86/kvm/mmu/mmu.c | 23 ++++++++--------------- > > 1 file changed, 8 insertions(+), 15 deletions(-) > > > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > > index f98444e1d834..74789295f922 100644 > > --- a/arch/x86/kvm/mmu/mmu.c > > +++ b/arch/x86/kvm/mmu/mmu.c > > @@ -253,19 +253,6 @@ static struct kvm_mmu_role_regs vcpu_to_role_regs(struct kvm_vcpu *vcpu) > > return regs; > > } > > > > -static int role_regs_to_root_level(const struct kvm_mmu_role_regs *regs) > > -{ > > - if (!____is_cr0_pg(regs)) > > - return 0; > > - else if (____is_efer_lma(regs)) > > - return ____is_cr4_la57(regs) ? PT64_ROOT_5LEVEL : > > - PT64_ROOT_4LEVEL; > > - else if (____is_cr4_pae(regs)) > > - return PT32E_ROOT_LEVEL; > > - else > > - return PT32_ROOT_LEVEL; > > -} > > - > > static inline bool kvm_available_flush_tlb_with_range(void) > > { > > return kvm_x86_ops.tlb_remote_flush_with_range; > > @@ -4673,7 +4660,13 @@ kvm_calc_cpu_role(struct kvm_vcpu *vcpu, const struct kvm_mmu_role_regs *regs) > > role.base.smep_andnot_wp = ____is_cr4_smep(regs) && !____is_cr0_wp(regs); > > role.base.smap_andnot_wp = ____is_cr4_smap(regs) && !____is_cr0_wp(regs); > > role.base.has_4_byte_gpte = !____is_cr4_pae(regs); > > - role.base.level = role_regs_to_root_level(regs); > > + > > + if (____is_efer_lma(regs)) > > + role.base.level = ____is_cr4_la57(regs) ? PT64_ROOT_5LEVEL : PT64_ROOT_4LEVEL; > > + else if (____is_cr4_pae(regs)) > > + role.base.level = PT32E_ROOT_LEVEL; > > + else > > + role.base.level = PT32_ROOT_LEVEL; > > Did you mean to drop the !CR0.PG case? Oh never mind I see the !CR0.PG case is handled above. Reviewed-by: David Matlack > > > > > role.ext.cr0_pg = 1; > > role.ext.cr4_pae = ____is_cr4_pae(regs); > > @@ -4766,7 +4759,7 @@ static void init_kvm_tdp_mmu(struct kvm_vcpu *vcpu, > > context->get_guest_pgd = get_cr3; > > context->get_pdptr = kvm_pdptr_read; > > context->inject_page_fault = kvm_inject_page_fault; > > - context->root_level = role_regs_to_root_level(regs); > > + context->root_level = cpu_role.base.level; > > > > if (!is_cr0_pg(context)) > > context->gva_to_gpa = nonpaging_gva_to_gpa; > > -- > > 2.31.1 > > > >