Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1646561rwo; Wed, 2 Aug 2023 18:50:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlHxzfe+ZkwKbAstmFQKORgxXfflbFhL0PJh+gqlgmaSPCZxZbqJW+pXVqY/fd7MHjKIRxfG X-Received: by 2002:a05:6358:991c:b0:139:a419:d837 with SMTP id w28-20020a056358991c00b00139a419d837mr9514343rwa.1.1691027452823; Wed, 02 Aug 2023 18:50:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027452; cv=none; d=google.com; s=arc-20160816; b=CyEa/rX2g3bkpgfgncsG+KQG/DZkbNSQ9n/fzZmn7YLIbocC7WcNsuZl04v6aaa1Ik kta0L8drqg3uyDhgJVE68aCNkKhb4xxFwce8sNK8qxg6NyfvAKevaU8mJWgqxAhKwB3+ yQNzTBdK3E9tPoQcmiN0Cynb8mV9SvFfPpb2gL25fjHF4USPHXAk3NOyiUaRLHfKn41f +vKE+lt17aQDSNfxbieV93X2qBye/CyHpIPB1jKKxnGJXEAdhZRvOYJLXH3QGtZMzXpZ bibZGhHSGcIWTkqGCINAE19+bxlllB8BzrPAWrfW9YyxN6Yx/AgD7YsU8FCNdamrgvdO o3Kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Vc6C3YLRbpQi2AL32H49CSJKRRKMAivDlEx5K2+EnSw=; fh=KGy1JiwIK++xOzbGvyml6MPSdA92viZosKLm42YoloI=; b=MIqNPIA7Mk0FBSiFi430apExcIEwKT+I2ZkiOoQ5mxiqxNXpWvEn4u5yyA8O3w5RBx 2EedL9ySrP1GiNXCjMnFrklOjLrTs2veXegAXFI5kKFZfpVkp8X6q6utk2p9oDhk9zVw lnnFO7ORh9kXDtxcbq+biDs5glJvf3BAdWxk20Wz0MD55VTeEnN8Hc4GxcZx9+Bo/fTk 0vzkhlbgz2fLyzBYcU8+ei49AU1WAWWU/u3yInRyB4DgMxv2nra1M5CMtkp2kaz873KV CrrJWS59O3glWNXErh1+ZvJPwVhK77w696C8x7wA1V7qgjGDWyXVReyt2e/kvWUdWgAy ZTQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="xf/IJNr/"; 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 b19-20020a6567d3000000b0055acc7f805bsi11850132pgs.334.2023.08.02.18.50.28; Wed, 02 Aug 2023 18:50:52 -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="xf/IJNr/"; 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 S231204AbjHBXeF (ORCPT + 99 others); Wed, 2 Aug 2023 19:34:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230376AbjHBXeD (ORCPT ); Wed, 2 Aug 2023 19:34:03 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF3C52D51 for ; Wed, 2 Aug 2023 16:34:00 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1bbb3195013so36175ad.1 for ; Wed, 02 Aug 2023 16:34:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691019240; x=1691624040; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Vc6C3YLRbpQi2AL32H49CSJKRRKMAivDlEx5K2+EnSw=; b=xf/IJNr/83ysKxnLoIpURXqtW5k4S78Gh5tHb3m0g2cM656O5cPNqbgVhIX2RxNi81 rwN3s+1UASkz3bkOQsKt/jfKJPUdzGRFa2ffYFtxNksgXsGw9O+9OKdHnIY5qvM4LBWh SO1LP5+sgpcVIpZxoTkUG2YUN21gRCZKcROF8+jYm9Oz49kUtlbb/rvbWBZj7GBNX8w0 4wDDyENbZdXj4phELOLafcq19/Iy+WmF5GW/WIxs4naY1ZHw9AH8dTs/Xqsb0FZL+KGI 5+YVJJNiMt5dFlAPlHT/6ZhE+J9D0mljI4Zs6eq8RwKcYhSzORWMDh2dDSPiSsB1zI2l W0ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691019240; x=1691624040; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vc6C3YLRbpQi2AL32H49CSJKRRKMAivDlEx5K2+EnSw=; b=AZa94+TvZzqX+kLOq0vwZzVTw1PB2qHjQi6FPLcxwkgdVbZz2YoQnlbsgKIU+KXmde vFr41QUnZk1J0TAyQL8YjF+tXeNmtEn0Gr3pU7KdmU4rG/JQwxQh0Fu+9dtQq7ZDqfhE 9bNMq/aKUHpXScfynuMm1Xk4be6vMuBcPIs2+ncTAveY3bE25tx0MwG10FRdSRNkAZd5 ckiZsc0L6mvVSt4AiVpBSruYpS7I06IDO3wLp48bLSB9Ko0ocEz0r6rpr5nQsLvmG2EY RzOws+6bt7M2P7bedGlEMc3WCKbjPeJcYykeffWTjpYIDHwfalhMlpebuofkMIyUpDOK qrGQ== X-Gm-Message-State: AOJu0YxC75+d8J1aitUfyYPkyHwTheAmPVH1/NGY46zEzJ8AP/rjzQdE TokDmNkiFiPzgtRw/Z1bvVfz1TcIpytMQAXu9EmLCQ== X-Received: by 2002:a17:903:5ce:b0:1bc:3321:4105 with SMTP id kf14-20020a17090305ce00b001bc33214105mr289379plb.2.1691019240198; Wed, 02 Aug 2023 16:34:00 -0700 (PDT) MIME-Version: 1.0 References: <20230722022251.3446223-1-rananta@google.com> <20230722022251.3446223-13-rananta@google.com> <87jzulqz0v.wl-maz@kernel.org> <86fs5158j7.wl-maz@kernel.org> In-Reply-To: <86fs5158j7.wl-maz@kernel.org> From: Raghavendra Rao Ananta Date: Wed, 2 Aug 2023 16:33:48 -0700 Message-ID: Subject: Re: [PATCH v7 12/12] KVM: arm64: Use TLBI range-based intructions for unmap To: Marc Zyngier Cc: Oliver Upton , James Morse , Suzuki K Poulose , Paolo Bonzini , Sean Christopherson , Huacai Chen , Zenghui Yu , Anup Patel , Atish Patra , Jing Zhang , Reiji Watanabe , Colton Lewis , David Matlack , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 On Wed, Aug 2, 2023 at 4:28=E2=80=AFPM Marc Zyngier wrote: > > On Mon, 31 Jul 2023 19:26:09 +0100, > Raghavendra Rao Ananta wrote: > > > > On Thu, Jul 27, 2023 at 6:12=E2=80=AFAM Marc Zyngier w= rote: > > > > > > On Sat, 22 Jul 2023 03:22:51 +0100, > > > 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 > > > > --- > > > > arch/arm64/kvm/hyp/pgtable.c | 67 +++++++++++++++++++++++++++++++-= ---- > > > > 1 file changed, 58 insertions(+), 9 deletions(-) > > > > > > > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgta= ble.c > > > > index 5ef098af1736..cf88933a2ea0 100644 > > > > --- a/arch/arm64/kvm/hyp/pgtable.c > > > > +++ b/arch/arm64/kvm/hyp/pgtable.c > > > > @@ -831,16 +831,54 @@ 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) > > > > +struct stage2_unmap_data { > > > > + struct kvm_pgtable *pgt; > > > > + bool defer_tlb_flush_init; > > > > +}; > > > > + > > > > +static bool __stage2_unmap_defer_tlb_flush(struct kvm_pgtable *pgt= ) > > > > +{ > > > > + /* > > > > + * 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 bool stage2_unmap_defer_tlb_flush(struct stage2_unmap_data = *unmap_data) > > > > +{ > > > > + bool defer_tlb_flush =3D __stage2_unmap_defer_tlb_flush(unmap= _data->pgt); > > > > + > > > > + /* > > > > + * Since __stage2_unmap_defer_tlb_flush() is based on alterna= tive > > > > + * patching and the TLBIs' operations behavior depend on this= , > > > > + * track if there's any change in the state during the unmap = sequence. > > > > + */ > > > > + WARN_ON(unmap_data->defer_tlb_flush_init !=3D defer_tlb_flush= ); > > > > + return defer_tlb_flush; > > > > > > I really don't understand what you're testing here. The ability to > > > defer TLB invalidation is a function of the system capabilities > > > (range+FWB) and a single flag that is only set on the host for pKVM. > > > > > > How could that change in the middle of the life of the system? if > > > further begs the question about the need for the unmap_data data > > > structure. > > > > > > It looks to me that we could simply pass the pgt pointer around and b= e > > > done with it. Am I missing something obvious? > > > > > From one of the previous comments [1] (used in a different context), > > I'm given to understand that since these feature checks are governed > > by alternative patching, they can potentially change (at runtime?). Is > > that not the case and I have misunderstood the idea in comment [1] > > entirely? Is it solely used for optimization purposes and set only > > once? > > Alternative patching, just like the static branches used to implement > the capability stuff, is a one way street. At the point where KVM is > initialised, these configurations are set in stone, and there is no > going back. > Understood. > > If that's the case, I can get rid of the WARN_ON() and unmap_data. > > yes, please. > Sure, I'll get rid of the WARN_ON and 'struct stage2_unmap_data' in v8. Thanks, Raghavendra > Thanks, > > M. > > -- > Without deviation from the norm, progress is not possible.