Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp760188rdg; Thu, 10 Aug 2023 20:45:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGH56B8iVeolMjHenCYtYfV4cLntzKaeWU5QA+WBXRqdMkmTy4TbUAV+lu8BF3a6nrFQKVy X-Received: by 2002:a17:907:2e0d:b0:982:79fa:4532 with SMTP id ig13-20020a1709072e0d00b0098279fa4532mr625314ejc.53.1691725514137; Thu, 10 Aug 2023 20:45:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691725514; cv=none; d=google.com; s=arc-20160816; b=vmkak0MtgqBBSRejmvttKiBVmxnhFFCNdXtBZUowTjGRaODeicWz1IvUBV7xIobUPV QsUfedjPFNrvBO3Kosc+3VfUFh03CFputc2+kuHeeHpWMjCpKiPx2lPkQrLjwa30O7gQ iwsrhcGx3GLtxKtyEWoCi4hakUoD5fpzgzrSTWFGzQYYnWmBWjdi+w8m6b14J0/SPfx/ Jc0eJFag9WsQSXn/nupMrr7F+MDzbtyCAOkw+H5ck1TrzKt5nTwz3R7iuO11ghquV6nF ZHlH+ZrZw9o/7CRC+AE+5xiimuxMkvMh63OGNieJs7RhBZR9PgRAN+b4YkGI3Xc7qj3c g9FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=+8Fzopu9BiGSPjrEUNgR9DMg7UpRaexYmg1fQM6xS1Q=; fh=W+GvHaBtCOT/un8p40EbpT798FhOd1y6QWSiqqHdwDE=; b=fr0QVGlp3q8N4KFzsiQdwonxdKU3M9UXQ7avm51nuRQCsWerehrdT9Fq3pz5g8mktp qDlAo+QLZC4IZA/1HEdY7z/ATp6Z3ukg+M9s7UHePrDl+wuhErQEnCq4LgIJzXQkP0qr XsjpAHf3GMcbsl7nzvpQblsO4M47KFdZMt2VkdZy6cPyzj8Gxh4zWodwapRiDc7i+SUY sp/e3hdwvqhWCB02uvy8CCyimqL/XC/4exWiRV0tMAJX72mxBIxlkq5PzI3T5rNSAOkz i6uM4k3jmId5XjiHWk5I1UuYjVCXAEDgg/vQiMeyWjXUKi5qMzXTvClu6S5yA2hs6G55 aUuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="IMq/M1/A"; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cf11-20020a170906b2cb00b0099279b2cdddsi2729776ejb.833.2023.08.10.20.44.49; Thu, 10 Aug 2023 20:45:14 -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=@redhat.com header.s=mimecast20190719 header.b="IMq/M1/A"; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231954AbjHKDOw (ORCPT + 99 others); Thu, 10 Aug 2023 23:14:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229732AbjHKDOu (ORCPT ); Thu, 10 Aug 2023 23:14:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CED42D66 for ; Thu, 10 Aug 2023 20:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691723641; 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=+8Fzopu9BiGSPjrEUNgR9DMg7UpRaexYmg1fQM6xS1Q=; b=IMq/M1/A2+x2XnCbXbxP0azfpoH3yxEdVikgenKNgO1rb70HGcOQlBGIIdvuSsO1pX52Dd OlVD8App50eJkeHNE57AO+t79wzErl+L79kQpVZq4QUi+Tsy8P/TYrL1v2/NgDQaomX9v3 FjNGkcesD9QHMMFBCqiBx+VVqrR/N04= Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-57-GgZfAHWYMOWT0csWMfB8cw-1; Thu, 10 Aug 2023 23:13:55 -0400 X-MC-Unique: GgZfAHWYMOWT0csWMfB8cw-1 Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-686f376f2b8so393849b3a.0 for ; Thu, 10 Aug 2023 20:13:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691723635; x=1692328435; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+8Fzopu9BiGSPjrEUNgR9DMg7UpRaexYmg1fQM6xS1Q=; b=REE/rcRaMz1RU8zy7x8ua5IOdVB+4ABioLjCflDq8voCJqz2oFe/QDTnR+dVGkypjg WUhq/wqF5UiUC29SSRv6ERScAa0gsw4A1czlvpkit+dReaURE96Kl/u70x11moLmfhD4 YeYDCpTIoqzO/1Fh9346RA19bRn4WOwWB3dq/0Nw0TqcI9Q7JJeJAZcvg0jnJb05yqD5 aRt1Nwqu7Oo3WWrGy++RTaSX4jC2vZRbEpeFSrUO3prjp8dsaP+N3dpLR85gy4bWfYxK r1SK2c0tkmDHP/MCm6Za/3OdElRqUW1qPpEGVfbAtigf8NldAxoecbypQKAcheZiyTQM MWyA== X-Gm-Message-State: AOJu0YzYH1YTnJO7lqzMQ0Dus+9XBjQdwPznTTLzgOB50Xie6O0LCC56 1Cm0OyNkMBZPbcJuOYv2DxnmDNTssg3IRdn3Zi2ka7AP/lsLgZzp50qn6HNDlZnPwenHsOHpc/i 4NzRojIMB1oobD+RG/Cl/lBp3 X-Received: by 2002:a05:6a00:4789:b0:687:874c:7ce0 with SMTP id dh9-20020a056a00478900b00687874c7ce0mr669599pfb.1.1691723634859; Thu, 10 Aug 2023 20:13:54 -0700 (PDT) X-Received: by 2002:a05:6a00:4789:b0:687:874c:7ce0 with SMTP id dh9-20020a056a00478900b00687874c7ce0mr669587pfb.1.1691723634514; Thu, 10 Aug 2023 20:13:54 -0700 (PDT) Received: from [10.72.112.92] ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id x8-20020aa79188000000b0064d57ecaa1dsm2227869pfa.28.2023.08.10.20.13.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Aug 2023 20:13:54 -0700 (PDT) Message-ID: <5ca5e4ed-82f0-369b-db61-7fcd1c148f1c@redhat.com> Date: Fri, 11 Aug 2023 11:13:46 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v8 14/14] KVM: arm64: Use TLBI range-based intructions for unmap Content-Language: en-US To: Raghavendra Rao Ananta , Oliver Upton , Marc Zyngier , James Morse , Suzuki K Poulose Cc: Paolo Bonzini , Sean Christopherson , Huacai Chen , Zenghui Yu , Anup Patel , Atish Patra , Jing Zhang , Reiji Watanabe , Colton Lewis , David Matlack , Fuad Tabba , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org References: <20230808231330.3855936-1-rananta@google.com> <20230808231330.3855936-15-rananta@google.com> From: Shaoqin Huang In-Reply-To: <20230808231330.3855936-15-rananta@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE 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 On 8/9/23 07:13, 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 on some systems. > > 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 deferred TLB invalidation on the system supporting FWB, > as the optimization is entirely pointless when the unmap walker > needs to perform CMOs. > > 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 Reviewed-by: Shaoqin Huang > --- > arch/arm64/kvm/hyp/pgtable.c | 40 +++++++++++++++++++++++++++++------- > 1 file changed, 33 insertions(+), 7 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index 5ef098af17362..eaaae76481fa9 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -831,16 +831,36 @@ 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) > { > /* > - * Clear the existing PTE, and perform break-before-make with > - * TLB maintenance if it was valid. > + * If FEAT_TLBIRANGE is implemented, defer the individual > + * TLB invalidations until the entire walk is finished, and > + * then use the range-based TLBI instructions to do the > + * invalidations. Condition deferred TLB invalidation on the > + * system supporting FWB as the optimization is entirely > + * pointless when the unmap walker needs to perform CMOs. > + */ > + 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 if it was > + * valid. Depending on the system support, defer the TLB maintenance > + * for the same until the entire unmap walk is completed. > */ > 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); > @@ -1098,7 +1118,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), > @@ -1112,13 +1132,19 @@ 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_tlb_flush_vmid_range(pgt->mmu, addr, size); > + > + return ret; > } > > struct stage2_attr_data { -- Shaoqin