Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp10640727rwr; Fri, 12 May 2023 10:44:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7l15XXOpQ6sorFQnf6KS4ox+U6gO+UamZPyUpE6r0rf62Wi1tvxRdxVIvRI5GjhTAdN/Ko X-Received: by 2002:a05:6a00:1346:b0:63b:4313:f8b5 with SMTP id k6-20020a056a00134600b0063b4313f8b5mr32123822pfu.23.1683913456841; Fri, 12 May 2023 10:44:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683913456; cv=none; d=google.com; s=arc-20160816; b=YgGS1+z5UB9z+/0q/CYRa1cnMldpKrhsjtD16yAfxP1bQiJPh1LBF/k4VNb95vBylN lGeFCbWdIzqq6fODZyweSq15Dxeu2UP8UHEJHZKpnu5Khn/zNKAAEqx4C4iDPKU0/qNL WNIpYhRbVny5pUu73MSolGVyk4morp3t/x3scWfcexttdkIVQSmEgAhcN0SHNgEz+6L0 yzvY7RgFBukkkoOPb6xCa74M9V5ahGceMZFoTPaf4ehwqecABBneZQNtuewqNVaClN3C kuEBeYXwgd3S4BXJMrhfICm3gqb6Hk/o832UGszOLmsFO5nDso0E9GU/u4VCp42n7m+p pyQw== 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:dkim-signature:date; bh=sODTyDv5L5PcXKxq0ByU2ty1JyyzAf4TEsGxAx4S/Kk=; b=VRUTThVRtbTk0hkLxGnUPeYHKLJ0Lkpp0H8cKAo+1A4bMjhL9gRYfwn9H0sEF5tI+e 24ddxiP920dGNyJtd6TGvBWVewuX2fQ+ClrSPOlDuU1hwRzBHQODgr9PonB0o+oJoy3C cR8T25ULHnr3F5Tt39KxGhpD4jzyfAjN6or8+qO3uNm9bnTRGO27wMEqs1bY2BuBPkLD QM5bQ3JvMg0CszTlMnCmdXFOQXLJkC5Kj8+bNyJ086V6rnzi/n0OORSErpEnJAr9F2rJ jdBWVNSoCSRDDR0i+tcNGF4FEuC9xFMpSnRqez97TTA5PXLlrI9pstmGPJwmfZ6CRPeb /FBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=wLQHdgkj; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k26-20020aa7999a000000b0064a35829154si3395584pfh.343.2023.05.12.10.44.01; Fri, 12 May 2023 10:44:16 -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=@linux.dev header.s=key1 header.b=wLQHdgkj; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237913AbjELRK4 (ORCPT + 99 others); Fri, 12 May 2023 13:10:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233644AbjELRKz (ORCPT ); Fri, 12 May 2023 13:10:55 -0400 X-Greylist: delayed 484 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 12 May 2023 10:10:51 PDT Received: from out-29.mta0.migadu.com (out-29.mta0.migadu.com [IPv6:2001:41d0:1004:224b::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCEC9728D for ; Fri, 12 May 2023 10:10:51 -0700 (PDT) Date: Fri, 12 May 2023 17:02:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1683910963; 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: in-reply-to:in-reply-to:references:references; bh=sODTyDv5L5PcXKxq0ByU2ty1JyyzAf4TEsGxAx4S/Kk=; b=wLQHdgkjIl3VGsRv1Hh6QjgfeOSxabsRa36OxyVZst7jQZNdxWCojHsM6ILzlp0BgNiTld vq0YTbY3+uPgZ18oxcEsbxXqyjoqNsW8fv7mYQ7sekHxJvZOA7r9DbhV5Nxo35rnAGH77i qZvp+8t6N7mE0AgDSfEQ1E3V/QbxSZ8= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Raghavendra Rao Ananta Cc: Marc Zyngier , James Morse , Suzuki K Poulose , Ricardo Koller , Paolo Bonzini , Jing Zhang , Colton Lewis , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH v3 7/7] KVM: arm64: Use TLBI range-based intructions for unmap Message-ID: References: <20230414172922.812640-1-rananta@google.com> <20230414172922.812640-8-rananta@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230414172922.812640-8-rananta@google.com> X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 Hi Raghavendra, On Fri, Apr 14, 2023 at 05:29:22PM +0000, Raghavendra Rao Ananta wrote: > The current implementation of the stage-2 unmap walker traverses > the given range and, as a part of break-before-make, performs > TLB invalidations with a DSB for every PTE. A multitude of this > combination could cause a performance bottleneck. > > Hence, if the system supports FEAT_TLBIRANGE, defer the TLB > invalidations until the entire walk is finished, and then > use range-based instructions to invalidate the TLBs in one go. > Condition this upon S2FWB in order to avoid walking the page-table > again to perform the CMOs after issuing the TLBI. > > Signed-off-by: Raghavendra Rao Ananta > Suggested-by: Oliver Upton > --- > arch/arm64/kvm/hyp/pgtable.c | 33 +++++++++++++++++++++++++++++---- > 1 file changed, 29 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index 3f136e35feb5e..bcb748e3566c7 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -987,10 +987,16 @@ int kvm_pgtable_stage2_set_owner(struct kvm_pgtable *pgt, u64 addr, u64 size, > return ret; > } > > +struct stage2_unmap_data { > + struct kvm_pgtable *pgt; > + bool skip_pte_tlbis; > +}; > + > static int stage2_unmap_walker(const struct kvm_pgtable_visit_ctx *ctx, > enum kvm_pgtable_walk_flags visit) > { > - struct kvm_pgtable *pgt = ctx->arg; > + struct stage2_unmap_data *unmap_data = ctx->arg; > + struct kvm_pgtable *pgt = unmap_data->pgt; > struct kvm_s2_mmu *mmu = pgt->mmu; > struct kvm_pgtable_mm_ops *mm_ops = ctx->mm_ops; > kvm_pte_t *childp = NULL; > @@ -1018,7 +1024,7 @@ static int stage2_unmap_walker(const struct kvm_pgtable_visit_ctx *ctx, > * block entry and rely on the remaining portions being faulted > * back lazily. > */ > - stage2_put_pte(ctx, mmu, mm_ops, false); > + stage2_put_pte(ctx, mmu, mm_ops, unmap_data->skip_pte_tlbis); > > if (need_flush && mm_ops->dcache_clean_inval_poc) > mm_ops->dcache_clean_inval_poc(kvm_pte_follow(ctx->old, mm_ops), > @@ -1032,13 +1038,32 @@ static int stage2_unmap_walker(const struct kvm_pgtable_visit_ctx *ctx, > > int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size) > { > + int ret; > + struct stage2_unmap_data unmap_data = { > + .pgt = pgt, > + /* > + * If FEAT_TLBIRANGE is implemented, defer the individial PTE > + * TLB invalidations until the entire walk is finished, and > + * then use the range-based TLBI instructions to do the > + * invalidations. Condition this upon S2FWB in order to avoid > + * a page-table walk again to perform the CMOs after TLBI. > + */ > + .skip_pte_tlbis = system_supports_tlb_range() && > + stage2_has_fwb(pgt), Why can't the underlying walker just call these two helpers directly? There are static keys behind these... > + }; > struct kvm_pgtable_walker walker = { > .cb = stage2_unmap_walker, > - .arg = pgt, > + .arg = &unmap_data, > .flags = KVM_PGTABLE_WALK_LEAF | KVM_PGTABLE_WALK_TABLE_POST, > }; > > - return kvm_pgtable_walk(pgt, addr, size, &walker); > + ret = kvm_pgtable_walk(pgt, addr, size, &walker); > + if (unmap_data.skip_pte_tlbis) > + /* Perform the deferred TLB invalidations */ > + kvm_call_hyp(__kvm_tlb_flush_vmid_range, pgt->mmu, > + addr, addr + size); > + > + return ret; > } > > struct stage2_attr_data { > -- > 2.40.0.634.g4ca3ef3211-goog > -- Thanks, Oliver