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 91D09C6FD1F for ; Tue, 26 Mar 2024 14:32:07 +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=OG5nAYe9W5KBO3WLZHl1KWPL4dseG23qiEcIWf3OEN4=; b=qKAQ3ZRrDxpvUJ SoAdCyQyrEwf5v4FFeLYgezl4VC+nVRbuVtec2KN4Rgx6hYNhJTZy8hf2r5074ITv3xc0ikIi/kGO HEHg7gwrM4LwajfG6AwAnqqZ0PfMMIuH8NUUUz+uGiGTtJbFcWUgAF2h0C/QZp0a1mtEpw2LRcDrI k8eKNC7tSbhBBW+QSSfaEVHBrLfUIbb7t8b6qUduHBkslih8VeHpoLBC1BzCjImWn1bZv4dQ+5LyF if/67tIrYpEiwCnozfmejvHLF9REl4jBpCUrptvdnaRHlj+HHWM9fFhfinv2r13ekVI4HMN1QAtMp 9bbwf3xEGF+G1FXZh3Iw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rp7qA-00000004vFb-19nW; Tue, 26 Mar 2024 14:31:50 +0000 Received: from out-178.mta1.migadu.com ([95.215.58.178]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rp7q6-00000004vEm-0c1K for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2024 14:31:48 +0000 Date: Tue, 26 Mar 2024 07:31:27 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711463500; 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: in-reply-to:in-reply-to:references:references; bh=G7iS7lQs00EYF2SDJRYWc2FNwHrQZRrb8S4189WW3Ng=; b=nHdp8HhwkY8EXBBwMVosXje3TaAumgW1CQ8Q6MYLL8VPd+TWTljKc+cnv/66RekIX8jG5T 2QLiQ9Y0VXh29z+j0OCJ0Jpk3T6njuZP6b8NbaqUT/Sv2Biv2e3e9hmK3pBekdbPVjoBer oWeUu4rp0W7Ooa4vfg8atnsM1imA+gA= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Will Deacon 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: References: <20240325185158.8565-1-will@kernel.org> <20240325185158.8565-2-will@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240326_073146_844032_93C46D79 X-CRM114-Status: GOOD ( 17.12 ) 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 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); return 0; } _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel