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 2F348C74A5B for ; Thu, 30 Mar 2023 00:18:35 +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=r51kTIq2lkGEwQHpn0o7TzNiEjJEwAHF7i6kJEn3hf4=; b=zqpmJ4826+jdin HBESKSoXmNqUOqvT7q6YT6zJfa+22ty/ep+MyiCLAtUwtX6NClGD0H+fR1j6ANdcGBMR+ZVwXdelL qGLoCWMzLAEtoaAefG5JSLUCwdLFD2KFAh93sRrMVtKpToR2yeyiK7nJe3+lR6R63+zjOvE8bWctB j/uCs1nb4CkJaIe3XbO1RIbqSi8QUkrBjt0SXXZ6OZ+08Q3soJ4DuThG/SsHNdAmMJo1f0/8Pi/rC C2f6oZjo90Rq+ifC4ku/u4nI4EMJ8pZT6KPyEdCZcxGiNlBbvhHqcqCIu+5kPOnxFLKbloCmZpqDv Pl1gxPHzg7+6eL4/2FUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phfzA-0028r8-0S; Thu, 30 Mar 2023 00:17:48 +0000 Received: from out-22.mta1.migadu.com ([2001:41d0:203:375::16]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1phfz6-0028pm-1z for linux-arm-kernel@lists.infradead.org; Thu, 30 Mar 2023 00:17:46 +0000 Date: Thu, 30 Mar 2023 00:17:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1680135457; 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=dZ7CgR7LTAUcUKEiGOSUlgNQXWvEplmklKUnppCogvc=; b=hRX9HcY4lHKvklyIm9h5vMkVivWZXvGwyJDd5XCTzM29yNzKcO7TXlGwIu+7wmffVDeVof XgLEjtUm074mMAdnfFC0AGMUVl2/hrS6DpBuI9GVy6scElft++20vrOGXsNmvbt2Zh3bAr 8VYBc2aq4fHO3hc8+86ULT8PRGPctfE= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Raghavendra Rao Ananta Cc: Oliver Upton , Marc Zyngier , Ricardo Koller , Reiji Watanabe , James Morse , Alexandru Elisei , Suzuki K Poulose , Will Deacon , Paolo Bonzini , Catalin Marinas , Jing Zhang , Colton Lewis , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH v2 6/7] KVM: arm64: Break the table entries using TLBI range instructions Message-ID: References: <20230206172340.2639971-1-rananta@google.com> <20230206172340.2639971-7-rananta@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230206172340.2639971-7-rananta@google.com> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230329_171745_037598_DCA2F223 X-CRM114-Status: GOOD ( 24.14 ) 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 nit: s/break/invalidate/g There is a rather important degree of nuance there. 'Break' as it relates to break-before-make implies that the PTE is made invalid and visible to hardware _before_ a subsequent invalidation. There will be systems that relax this requirement and also support TLBIRANGE. On Mon, Feb 06, 2023 at 05:23:39PM +0000, Raghavendra Rao Ananta wrote: Some nitpicking on the changelog: > Currently, when breaking up the stage-2 table entries, KVM 'breaking up stage-2 table entries' is rather ambiguous. Instead describe the operation taking place on the page tables (i.e. hugepage collapse). > would flush the entire VM's context using 'vmalls12e1is' > TLBI operation. One of the problematic situation is collapsing > table entries into a hugepage, specifically if the VM is > faulting on many hugepages (say after dirty-logging). This > creates a performance penality for the guest whose pages have typo: penalty > already been faulted earlier as they would have to refill their > TLBs again. > > Hence, if the system supports it, use __kvm_tlb_flush_range_vmid_ipa() > to flush only the range of pages governed by the table entry, > while leaving other TLB entries alone. An upcoming patch also > takes advantage of this when breaking up table entries during > the unmap operation. Language regarding an upcoming patch isn't necessary, as this one stands on its own (implements and uses a range-based invalidation helper). > Signed-off-by: Raghavendra Rao Ananta > --- > arch/arm64/kvm/hyp/pgtable.c | 23 ++++++++++++++++++++--- > 1 file changed, 20 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index b11cf2c618a6c..0858d1fa85d6b 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -686,6 +686,20 @@ static bool stage2_try_set_pte(const struct kvm_pgtable_visit_ctx *ctx, kvm_pte_ > return cmpxchg(ctx->ptep, ctx->old, new) == ctx->old; > } > > +static void kvm_pgtable_stage2_flush_range(struct kvm_s2_mmu *mmu, u64 start, u64 end, > + u32 level, u32 tlb_level) > +{ > + if (system_supports_tlb_range()) You also check this in __kvm_tlb_flush_range(), ideally this should be done exactly once per call. > + kvm_call_hyp(__kvm_tlb_flush_range_vmid_ipa, mmu, start, end, level, tlb_level); > + else > + /* > + * Invalidate the whole stage-2, as we may have numerous leaf > + * entries below us which would otherwise need invalidating > + * individually. > + */ > + kvm_call_hyp(__kvm_tlb_flush_vmid, mmu); > +} > + > /** > * stage2_try_break_pte() - Invalidates a pte according to the > * 'break-before-make' requirements of the > @@ -721,10 +735,13 @@ static bool stage2_try_break_pte(const struct kvm_pgtable_visit_ctx *ctx, > * Perform the appropriate TLB invalidation based on the evicted pte > * value (if any). > */ > - if (kvm_pte_table(ctx->old, ctx->level)) > - kvm_call_hyp(__kvm_tlb_flush_vmid, mmu); > - else if (kvm_pte_valid(ctx->old)) > + if (kvm_pte_table(ctx->old, ctx->level)) { > + u64 end = ctx->addr + kvm_granule_size(ctx->level); > + > + kvm_pgtable_stage2_flush_range(mmu, ctx->addr, end, ctx->level, 0); > + } else if (kvm_pte_valid(ctx->old)) { > kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, mmu, ctx->addr, ctx->level); > + } > > if (stage2_pte_is_counted(ctx->old)) > mm_ops->put_page(ctx->ptep); > -- > 2.39.1.519.gcb327c4b5f-goog > > -- Thanks, Oliver _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel