Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2614693rwn; Fri, 16 Sep 2022 13:12:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5SE5b9fX5H/ogRexc6GukSTjmkDVSW993x0aKHs3J1a7TycfT3psmp3LHjEoAhJR51zkGk X-Received: by 2002:a17:906:da86:b0:740:7120:c6e6 with SMTP id xh6-20020a170906da8600b007407120c6e6mr4727584ejb.44.1663359138450; Fri, 16 Sep 2022 13:12:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663359138; cv=none; d=google.com; s=arc-20160816; b=YJbOAc7YnyZnvZl+XLtisHySSABNMZoXLzLFLuaQxPPG+bYEPXwTuFbsLLVKLuthWk jBr7ed6OTpOU7NBkulI65YxjSESqGhh0Cfei5G78Cb6jpcRrY9ELfpzyPpIK2GLqyQp9 c4/1Np2GVPLOX5cMN3UH4Jo1xHkSfFUe2UBuuah5L39thqDUgxPqmlg+GimzkYtHs+sV wJP3ikS/h4bH2bUjLqBAK4PeczwgvHKAy9meRfQkZkwQ0a985bPE2/oRDaAn64t3wRj6 ZW8u6RNgHrhJ76dLt56ZFN3Lmeryxe050r21kCRvsD2nJ2oOi0VJL7Bshml90+SQn9A1 Zl0g== 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=7koUmLdWd3oEgwetevFBcgnuG0GVKxojKR8I+sUBlm8=; b=1DP4a6K23Ps9twr4BEhp7cnnFG1I8wN4RN3zb+5GaDEA3iRLYgWezJlXTCBPDtZgo9 9Vzl1XVphjZu1tMLkhaAmwtMAGPriaNDnG23bfjq3uImwmCwMVwJ2t2xHYQA8Zgg7WPs bkl9zuYhbTuDgoyT24wei4MwXn8Bsx2A9PmIQ+zbX86MW2tptZK8uU8DWCKlzQ7EiJFR R9DCjUrPN72K3WJmzsc3PbB+iAdR8tlXNkQIO42BlpEQVzp0EygJs+e4ra3JJROHc7Ro JvEcgQVbczmPK/FvrcFIvRNs0Fo2PMa7m4LBb65aC4LkGSsTkbxfmlsUqQh8nSTdUuj4 kICw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=bP5yedyA; 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 l11-20020a056402254b00b004525187513esi3261395edb.574.2022.09.16.13.11.23; Fri, 16 Sep 2022 13:12:18 -0700 (PDT) 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=bP5yedyA; 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 S230185AbiIPTdl (ORCPT + 99 others); Fri, 16 Sep 2022 15:33:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229509AbiIPTdj (ORCPT ); Fri, 16 Sep 2022 15:33:39 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1D76B0B18 for ; Fri, 16 Sep 2022 12:33:37 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id q15-20020a17090a304f00b002002ac83485so597403pjl.0 for ; Fri, 16 Sep 2022 12:33:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=7koUmLdWd3oEgwetevFBcgnuG0GVKxojKR8I+sUBlm8=; b=bP5yedyAXi7WDrG/FFmAEiTMdMkkudI5cP9ED/DF56Kof4boDDYNcpCpYMPnXkKrg4 ujqkBFTI9wqTn+/w2Rr0zYuMlMXL8hzgwdb88DnxyrIhCqy19p+XzNMMiRLYfdcRuKUX nu5PhJo7e/Ne+i9ncLJasmEcEfNLfuN8y1evlNvmdlZHAfxoR1aPqocR10BLUEgcaowu LNKLG/2NjDH+zWjFMdVi20i/KXRM57VYWS1o1Jo3pPmgdYyuLHDVJojta2xIZHMxb3G/ U5j63Ur+XVi2+F2jcCa87/m0B+icKHxHTr0fkbsQA6n9p02cKITP0BA4O50QxHcZG7iw y+zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=7koUmLdWd3oEgwetevFBcgnuG0GVKxojKR8I+sUBlm8=; b=hTMb5rqje08O61D2d7gevJ2A3EbGcsuuBqpXvry4qpD8+Mys3bS8ITSlzeg7+8Tlpe DhcvmiLpIC7RHlnkZdLVXzZSjBkz6e/KOIxkb8qZ1zZYAiMPfYUp/G2tEnH+XZngLl8Y 7Xj+uuPUbNVr1EFmzcdG1MHdemBcwt0xOotJ20juTHQY4jfBPKSkRB3bDxODhWpfuR7V R1iTd7jFOmRnOfv1Ya3t9Z6Aokf7Wt9CYVvJF9lNdCVJh4GVYeLgIakpI63yD68e9NEh LlgGgal7qcgDxCwAwr6ix6cMdK/4zB8j8SJSd10a6a7XLTp1iMvCaPSiXJAcRsBlsp68 HVmQ== X-Gm-Message-State: ACrzQf0zEHjqLe5Mh6f8s7GdS7mqi0KJzvlMjqjHWWLex+YtEyrTeDdw wdkt3YCTJT/4ayQRgmSVYd7XlA== X-Received: by 2002:a17:90b:3809:b0:202:b482:b7d6 with SMTP id mq9-20020a17090b380900b00202b482b7d6mr17580055pjb.209.1663356817295; Fri, 16 Sep 2022 12:33:37 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id 129-20020a620487000000b0053e984a887csm15130733pfe.96.2022.09.16.12.33.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 12:33:36 -0700 (PDT) Date: Fri, 16 Sep 2022 19:33:33 +0000 From: Sean Christopherson To: David Matlack Cc: Hou Wenlong , kvm list , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , X86 ML , "H. Peter Anvin" , LKML Subject: Re: [PATCH v2 6/6] KVM: x86/mmu: Use 1 as the size of gfn range for tlb flushing in FNAME(invlpg)() Message-ID: References: <8baa40dad8496abb2adb1096e0cf50dcc5f66802.1661331396.git.houwenlong.hwl@antgroup.com> <20220913125833.GC113257@k08j02272.eu95sqa> 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, 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 Tue, Sep 13, 2022, David Matlack wrote: > On Tue, Sep 13, 2022 at 5:58 AM Hou Wenlong wrote: > > > > On Thu, Sep 08, 2022 at 01:40:16AM +0800, David Matlack wrote: > > > On Wed, Aug 24, 2022 at 05:29:23PM +0800, Hou Wenlong wrote: > > > > Only SP with PG_LEVLE_4K level could be unsync, so the size of gfn range > > > > must be 1. > > > > > > > > Signed-off-by: Hou Wenlong > > > > --- > > > > arch/x86/kvm/mmu/paging_tmpl.h | 3 ++- > > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h > > > > index 04149c704d5b..486a3163b1e4 100644 > > > > --- a/arch/x86/kvm/mmu/paging_tmpl.h > > > > +++ b/arch/x86/kvm/mmu/paging_tmpl.h > > > > @@ -937,7 +937,8 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva, hpa_t root_hpa) > > > > > > > > mmu_page_zap_pte(vcpu->kvm, sp, sptep, NULL); > > > > if (is_shadow_present_pte(old_spte)) > > > > - kvm_flush_remote_tlbs_sptep(vcpu->kvm, sptep); > > > > + kvm_flush_remote_tlbs_gfn(vcpu->kvm, > > > > + kvm_mmu_page_get_gfn(sp, sptep - sp->spt), 1); > > > > > > The third argument to kvm_flush_remote_tlbs_gfn() is the level, not the > > > number of pages. But that aside, I don't understand why this patch is > > > necessary. kvm_flush_remote_tlbs_sptep() should already do the right > > > thing. > > > > > Since only SP with PG_LEVEL_4K level could be unsync, so the level must > > be PG_LEVEL_4K, then sp->role.level access could be dropped. However, > > I'm not sure whether it is useful. I can drop it if it is useless. > > Ah, I see. I would be surprised if avoiding the read of sp->role.level > has any noticeable impact on VM performance so I vote to drop this patch. Agreed, the cost of the sp->role.level lookup is negligible in this case, and IMO using kvm_flush_remote_tlbs_sptep() is more intuitive. If kvm_flush_remote_tlbs_sptep() didn't exist and this was open coding the use of kvm_flush_remote_tlbs_with_address() + KVM_PAGES_PER_HPAGE(), then I would be in favor of hardcoding '1', because at that point the use of KVM_PAGES_PER_HPAGE() is misleading in its own way.