Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2370001rwb; Thu, 27 Jul 2023 06:21:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlHPsbvnAUFzsab/FVO0NuXcFWv3kCnOSVQO1R2r2u/XLAmrsYJsMfAnwW/CoOFdOXkNJVDs X-Received: by 2002:a17:907:75d5:b0:99a:7ff1:9b5a with SMTP id jl21-20020a17090775d500b0099a7ff19b5amr1995029ejc.4.1690464099134; Thu, 27 Jul 2023 06:21:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690464099; cv=none; d=google.com; s=arc-20160816; b=nyglDT1CCMSqAEzdxbcunk1mbZU/8U3eJ/pYFmeVbapk79xMdoGKMdAGhs7toJAFTR wHWuRGEwzYN5Rxd1cbqZFewpCA9AXB2eENWmV3ZzB9jv4hzIo97gk0EPZJEUtZRiNQX2 3ZykHBaEjsk71pg2MJTsmrHIcKSRnvz88ua9mb3GUiVcXgoHqssOrlc4cMz94FxEBjwC L6PIpT/9L6ZPlu5Lm28pPAOE89tC2lpNckCFGdS7YG6k1PmyiL7FnpHBxy2eH6aARIRn sGvBRrd96fy1R/YR+QGMArSmzfT2DvOFb4211l/9aEcJ57mjBiqQPd3kAomj+23C5g1U R9YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=YpzJG990E1uuq7nZcDfMR3yMQ0ShRVZ0+jCgNgzXgKU=; fh=WyypX3RQYrUB8CslwpBzrfKl9A8f4OUAzy4EkEy6y78=; b=0B6Bzi7vxvBJv00J7k9Pz/oiwvTRHGIF9k8jG/xK3sj1q+V10/ZImQ3PTrdvWYiDGJ t2tNsRC+vOkpGHTA6oRdGawvZ5Hxi/Jw9e0meRGfbfBVrQpSxIn4nShS2Edr4yMWRNfd zS+oXwx7fP1viJSiqyMEQMgzVd9mabyUdyFATQ66JNOA/k/6Vr2At3jnRuMwN3NkkFYZ 0CSVC4sMwzXv43kIJWpSx8ZUKJT4FcNx5l6bEH8f7retgEZmDwnwDv94R5JnctfJaDOp jLXj8JnUISjlxPs5E6SuFJTt8/RfzXJcKAnXfJAxTrN6uE4JrQssXIPcRZlTmyDoWdQI uDWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FYECEGQ5; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jo13-20020a170906f6cd00b00991c8af7ba5si1016542ejb.473.2023.07.27.06.21.13; Thu, 27 Jul 2023 06:21:39 -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=@kernel.org header.s=k20201202 header.b=FYECEGQ5; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232270AbjG0NM2 (ORCPT + 99 others); Thu, 27 Jul 2023 09:12:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbjG0NMV (ORCPT ); Thu, 27 Jul 2023 09:12:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 830011715; Thu, 27 Jul 2023 06:12:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2087C61E71; Thu, 27 Jul 2023 13:12:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75D31C433C8; Thu, 27 Jul 2023 13:12:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690463539; bh=9dsD6qht9F/b5jq523+Sku0tJDHSRASAuDdE3hK28X8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=FYECEGQ5Fy7k8XN9uei3Ju2nUDmE/L0NnLipfyqsyZp0k0r9HpmtRnuPeGjH1CkdR Ss4AtRlEpUv4wNES6j9km4m+th3oQGt0nejciOeOhHBRUpADqErk8n6a4MNa2wdAwF vySWhTE9z3UIA0CRdNXQQ2to0/GoGRCXCYA0vmcipvKXFDXWds3GCedCykFFylQ3wQ z6uGkXRlNwgApJUWUe0wIw3rYuOhlzPKxvTI802CNJkqB++IigCuhCP0kbfoHZpSzN rENDcPTa/y9xYBw2ctxR7P2DeMq/O1y3uYVouqLIfpPH+tRU9XOr7ASAJh/GfCzVFW a5x6QZKhfqNnw== Received: from [104.132.45.102] (helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qP0mu-00HMdJ-Ub; Thu, 27 Jul 2023 14:12:17 +0100 Date: Thu, 27 Jul 2023 14:12:16 +0100 Message-ID: <87jzulqz0v.wl-maz@kernel.org> From: Marc Zyngier To: Raghavendra Rao Ananta 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 Subject: Re: [PATCH v7 12/12] KVM: arm64: Use TLBI range-based intructions for unmap In-Reply-To: <20230722022251.3446223-13-rananta@google.com> References: <20230722022251.3446223-1-rananta@google.com> <20230722022251.3446223-13-rananta@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 104.132.45.102 X-SA-Exim-Rcpt-To: rananta@google.com, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, pbonzini@redhat.com, seanjc@google.com, chenhuacai@kernel.org, yuzenghui@huawei.com, anup@brainfault.org, atishp@atishpatra.org, jingzhangos@google.com, reijiw@google.com, coltonlewis@google.com, dmatlack@google.com, 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 X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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/pgtable.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 = __stage2_unmap_defer_tlb_flush(unmap_data->pgt); > + > + /* > + * Since __stage2_unmap_defer_tlb_flush() is based on alternative > + * 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 != 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 be done with it. Am I missing something obvious? M. -- Without deviation from the norm, progress is not possible.