From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 344C3CD11DD for ; Tue, 26 Mar 2024 16:10:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XhsCvd0cB+ymiJd0khF6CtHC7dYalTAfV/PTlJ6MBNs=; b=ph0c6wzSvZmtT4 R/wFahZ7LjRVMxxJupwlkNW2R3PdsAkFSphUrzHFEYR72FK8BsWIo+7d9GNZAdHjn7E87LCgpaVHv +VPbl+ioqpfpWugK1fn85y8K+yH16vdzl2Igb81FmUc3PU/ai8YYy4jEX/+Xo+u6FCH+8HQ2kixf9 TrE25yY9sh1MXR6XUdKQh7MRtQjEbP7a0El9VHJCgd+wfQXgo3KnLkYq0xvEQdaHDwxhAMHUivlRP nETnIG5yWUiIR+JdLWAZgX4hYM+n84RV5nOpNCoFK+3LlveeQPm60x/WYjAU1nc5kQwRaeQf8xeyd QLNEWTv7nXnMzpBey8bg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rp9NM-00000005OTo-0jYK; Tue, 26 Mar 2024 16:10:12 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rp9NJ-00000005OT4-2pXW for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2024 16:10:11 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id F39E5CE1F8B; Tue, 26 Mar 2024 16:10:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC1B9C433F1; Tue, 26 Mar 2024 16:10:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711469407; bh=yIc1T3rbGBsJt2JIZmWDELw5PA9dbbkZaW489v6thG0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OteM+pLW+ZRdxUHq1062qBHLsgCzRYgmSyjd2+ncLEcBFMsIaN64bFy0eesTeL10n YNI1zDwjz19qNWG6GGLq9BSepqIhLpfL7XCl2/EmMPUFai2lzDE+H4OhaMm3cj6i/W /etpuauzFSpRXUqBjo4rZQIRuOurAAKW5xzOzmhtbQNYhDVhko3bD2HTe2M0ARmtQD f7bu+jvgBDDHhBuyJoyHQ62JMtmtuUq3uIouWaV79rrIqsbxrMNnoHDezJLbT5Asqe bRCSFuF/oDQ5eiHPvTtU8+Lq/uNs0zxHAo+FJ5hITbGft3sFcYZKkfc2VHJdYKDzX2 BNjjz3UVzYHnA== Date: Tue, 26 Mar 2024 16:10:01 +0000 From: Will Deacon To: Oliver Upton Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Catalin Marinas , Gavin Shan , Marc Zyngier , Mostafa Saleh , Quentin Perret , Raghavendra Rao Ananta , Ryan Roberts , Shaoqin Huang , Suzuki K Poulose , Zenghui Yu Subject: Re: [PATCH 1/3] KVM: arm64: Don't defer TLB invalidation when zapping table entries Message-ID: <20240326161000.GA9723@willie-the-truck> References: <20240325185158.8565-1-will@kernel.org> <20240325185158.8565-2-will@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240326_091010_118481_2702B5CD X-CRM114-Status: GOOD ( 25.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Mar 26, 2024 at 07:31:27AM -0700, Oliver Upton wrote: > On Tue, Mar 26, 2024 at 01:34:17AM -0700, Oliver Upton wrote: > > > } > > > > > > mm_ops->put_page(ctx->ptep); > > > > At least for the 'normal' MMU where we use RCU, this could be changed to > > ->free_unlinked_table() which would defer the freeing of memory til > > after the invalidation completes. But that still hoses pKVM's stage-2 > > MMU freeing in-place. > > How about this (untested) diff? I _think_ it should address the > invalidation issue while leaving the performance optimization in place > for a 'normal' stage-2. > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index 3fae5830f8d2..896fdc0d157d 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -872,14 +872,19 @@ static void stage2_make_pte(const struct kvm_pgtable_visit_ctx *ctx, kvm_pte_t n > 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. > + * It is possible to use FEAT_TLBIRANGE to do TLB invalidations at the > + * end of the walk if certain conditions are met: > + * > + * - The stage-2 is for a 'normal' VM (i.e. managed in the kernel > + * context). RCU provides sufficient guarantees to ensure that all > + * hardware and software references on the stage-2 page tables are > + * relinquished before freeing a table page. > + * > + * - The system supports FEAT_FWB. Otherwise, KVM needs to do CMOs > + * during the page table table walk. > */ > - return system_supports_tlb_range() && stage2_has_fwb(pgt); > + return !is_hyp_code() && system_supports_tlb_range() && > + stage2_has_fwb(pgt); > } > > static void stage2_unmap_put_pte(const struct kvm_pgtable_visit_ctx *ctx, > @@ -1163,7 +1168,7 @@ static int stage2_unmap_walker(const struct kvm_pgtable_visit_ctx *ctx, > kvm_granule_size(ctx->level)); > > if (childp) > - mm_ops->put_page(childp); > + mm_ops->free_unlinked_table(childp, ctx->level); Hmm, but doesn't the deferred TLBI still happen after the RCU critical section? I also think I found another bug, so I'll send a v2 with an extra patch... Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel