Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1783404rwd; Thu, 18 May 2023 17:54:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6T+WcjBoUFdrEDaL0tpeyRvCYLCcM9beEBZTwTALcvDgRGd5Tsa9Ms6k3du7IIjAp2G1JB X-Received: by 2002:a17:90a:6b84:b0:250:8f09:75f2 with SMTP id w4-20020a17090a6b8400b002508f0975f2mr389168pjj.22.1684457698835; Thu, 18 May 2023 17:54:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684457698; cv=none; d=google.com; s=arc-20160816; b=kHKLx3QpgII9mQskQwISSofyVO7P53uvSSXPO22WTQdAq0tDkoVmbuxutXA+gyuYaG BAGPKLIZixqTMyhlUlNXGV5iY4GZ/xsTj2RB1Leo5iFKRs2h3esz0Q1BG5mPBAoBy38Z /74cysiEXfGMUgyr0oVpD/PHtSoyRXQYZVZl3jvZEQMKE6bnCnBaocoWleE7u8uE1JCO Qm8yHdaUtifKtXF5T6th/zk0pLOoDpkeKosoxT50v7HvphHl21GkdMM7VJrejBqRS6rQ o9Jv/ZPCulZYOJYlKIHCxZ1GJYtOCFzExa25qROW0XAkbtcl7fBZ3KluL0U11IhcVTqL SBGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=rGsmPoc/T4Ss3kfVhJrmlF6LuTv5aUCcul/iCKRGGfw=; b=J6diiElQd7RayV24qtMJodTpX7T/aQbF5UWuHT7udqUxu9u9RB2kepkm2g7KaHL6rc /53oj171i8iVoC2RpjLcl4AfmlGVJudImYRX322WOI8RrzUEWz3kNk/8wZXjO6wmbZ35 jSPg8G+GvVqgu9QyIgNoKX0DqzkH6cG7s+WqjF86pr/kJQ2ZIpfmNpk8oarHN97CizbL 79WibE5tMeXCCVuzGXGG+GoMoBo9BcJvYuOgsKFKY/ZlZdshv9fumdWFcn4moIAl3Kv2 qIjJj6K9p64iUo875UDgNTTtCFe70rQ760ZpT74qHk+DBJnI7/uLKcNaBWeJInJaae6e UqAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=xW05sinA; 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 s63-20020a632c42000000b0051909d663d8si2736211pgs.656.2023.05.18.17.54.46; Thu, 18 May 2023 17:54:58 -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=20221208 header.b=xW05sinA; 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 S230272AbjESAw4 (ORCPT + 99 others); Thu, 18 May 2023 20:52:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229616AbjESAwp (ORCPT ); Thu, 18 May 2023 20:52:45 -0400 Received: from mail-io1-xd49.google.com (mail-io1-xd49.google.com [IPv6:2607:f8b0:4864:20::d49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCC2610E0 for ; Thu, 18 May 2023 17:52:42 -0700 (PDT) Received: by mail-io1-xd49.google.com with SMTP id ca18e2360f4ac-7603d830533so26392339f.1 for ; Thu, 18 May 2023 17:52:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684457562; x=1687049562; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rGsmPoc/T4Ss3kfVhJrmlF6LuTv5aUCcul/iCKRGGfw=; b=xW05sinAfw8C44WTP/9vyg4AsrI69Imj2ZmwYQLJZF8kEHkqon5WhJrYk6DNXK7Gw6 ORpvYUQiCd6GWx/VkoJW+RFSdfhvlRh0N9mjXQWCD6GhGofxw22goCURFVI2zQtlWjI3 q40Px7tzzEXTuwbuR/ZiN0k40rk4wWlizlUEyM3BENmLsLioAlGtY649VgAWbXD8mNoT jqpj50br7Y7C26Wwzs7ZYrY5XUZtlZuQUEmP94MjpBLWtfJKC0Hj0gvsmYFqFZ6EU0/5 BTWcttwAOtqDV1LAtO7UFkbUjq6YDBOiaJ3QlnQPpYOq6lbHz3ZzDuYKfXJ/7nDGH2YH /vSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684457562; x=1687049562; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rGsmPoc/T4Ss3kfVhJrmlF6LuTv5aUCcul/iCKRGGfw=; b=Y/Q7J2IALdv+psCmbfYIWN2HUcLtVdqpXXkGmZbQn/hipR/dtubto6roAQtxunqf8R +LGZaOfiQfhiNlDNGzGif1CBHvMDW6kVuD6VkBocZsLQb3YLzQRsgNHTLrRIOdiM5IaC t/fc+bc8U5Y7vQVX/FD/6o3tFwFC0EB2Rr0dzL0wIT1AviOrSyJ8xtfzsVsEOOkmYnVs tldaN/NnqfD4EVsjW3sUWv8NbhdvpjM5EKOgLqkYsbSxv3tKisiNAY80niaT2ALDvTPs Jv6rx5ZcFUFgQP6Ki6quHmarlh/NPltxqzzADyUOUtrF+PisUuHoFmNwcnBvoBNg00PC VCNg== X-Gm-Message-State: AC+VfDzEkUtdyZ0nRPyv2NhJYgVp8PSsojKtGsAnnYNV+lpXgWcc7X1m brWWRMRhdkhpmL2BdIzN7jcsr5+GB546 X-Received: from rananta-linux.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:22b5]) (user=rananta job=sendgmr) by 2002:a05:6602:2ac4:b0:763:b184:fe92 with SMTP id m4-20020a0566022ac400b00763b184fe92mr5060981iov.0.1684457562041; Thu, 18 May 2023 17:52:42 -0700 (PDT) Date: Fri, 19 May 2023 00:52:31 +0000 In-Reply-To: <20230519005231.3027912-1-rananta@google.com> Mime-Version: 1.0 References: <20230519005231.3027912-1-rananta@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Message-ID: <20230519005231.3027912-7-rananta@google.com> Subject: [PATCH v4 6/6] KVM: arm64: Use TLBI range-based intructions for unmap From: Raghavendra Rao Ananta To: Oliver Upton , Marc Zyngier , James Morse , Suzuki K Poulose Cc: Ricardo Koller , Paolo Bonzini , Jing Zhang , Colton Lewis , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 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. Rename stage2_put_pte() to stage2_unmap_put_pte() as the function now serves the stage-2 unmap walker specifically, rather than acting generic. Signed-off-by: Raghavendra Rao Ananta --- arch/arm64/kvm/hyp/pgtable.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index b8f0dbd12f773..5832ee3418fb0 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -771,16 +771,34 @@ static void stage2_make_pte(const struct kvm_pgtable_visit_ctx *ctx, kvm_pte_t n smp_store_release(ctx->ptep, new); } -static void stage2_put_pte(const struct kvm_pgtable_visit_ctx *ctx, struct kvm_s2_mmu *mmu, - struct kvm_pgtable_mm_ops *mm_ops) +static bool stage2_unmap_defer_tlb_flush(struct kvm_pgtable *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. + */ + return system_supports_tlb_range() && stage2_has_fwb(pgt); +} + +static void stage2_unmap_put_pte(const struct kvm_pgtable_visit_ctx *ctx, + struct kvm_s2_mmu *mmu, + struct kvm_pgtable_mm_ops *mm_ops) +{ + struct kvm_pgtable *pgt = ctx->arg; + /* * Clear the existing PTE, and perform break-before-make with * TLB maintenance if it was valid. */ if (kvm_pte_valid(ctx->old)) { kvm_clear_pte(ctx->ptep); - kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, mmu, ctx->addr, ctx->level); + + if (!stage2_unmap_defer_tlb_flush(pgt)) + kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, mmu, + ctx->addr, ctx->level); } mm_ops->put_page(ctx->ptep); @@ -1015,7 +1033,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); + stage2_unmap_put_pte(ctx, mmu, mm_ops); if (need_flush && mm_ops->dcache_clean_inval_poc) mm_ops->dcache_clean_inval_poc(kvm_pte_follow(ctx->old, mm_ops), @@ -1029,13 +1047,20 @@ 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 kvm_pgtable_walker walker = { .cb = stage2_unmap_walker, .arg = pgt, .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 (stage2_unmap_defer_tlb_flush(pgt)) + /* 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.1.698.g37aff9b760-goog