Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1410297rwl; Wed, 29 Mar 2023 17:52:35 -0700 (PDT) X-Google-Smtp-Source: AKy350bpOGYnjTKingwcyWLWf4b6iaBd7lRigy3z1v0UI6qIpFS07nitiCscto0xh5/C8PaHX028 X-Received: by 2002:aa7:cac5:0:b0:500:4a5d:af3f with SMTP id l5-20020aa7cac5000000b005004a5daf3fmr22015601edt.34.1680137555082; Wed, 29 Mar 2023 17:52:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680137555; cv=none; d=google.com; s=arc-20160816; b=it/4MTZYZSQAFohaIJaJ/PtafIpIbRal/2TzPECNDJ626Zx+9PZ/UDxDm9JCuHR9cR rHrbPnVPtgesax0/OR2nMArKioEykFR+lQAutAaMPEjCCHHeLK6aEYoi82oRiIYSKx5W rrXW2ODSylrE+YjPQ25OtJWBDdEJjOUuxYmCW8m/L164F6gwr+Zkpyw1VjhcHKVsQLDo /WhHWRCnqGxvF1/IkfazJc8J/QcK7czVQ8YsPkra79d6mQkMTDcEIo+FfR2lQ7oDdgSP 6NPdjwBTbR7Vb+S55RQ0AAJxTogx+Sc2V0KZfHA9p3AaRFD3Kr5LOJN+Rd47EPDyjamY II0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=dZ7CgR7LTAUcUKEiGOSUlgNQXWvEplmklKUnppCogvc=; b=jk9uoD84f9EMm0suUlpZ8lY7lSydsc4qOEDQyxpFtEMCkWWY/QRAdNT00ZhmWt2uie zkrtQzrZBfOIIVTnQtvLoPFuXme+/2cumU/yjwNo1v81y1dShQuXFOnCRq+tf4qsSBOC 63kLlcLd9+t6DWUuFaZ1qWzEIDyAOI/n3xdg+F9BfYmoVKFn/2rdt6XaE8dFqNEu5alN CWhcVHVZ7rswwuayHSIf9MrEZPpzOmr7Zkzac3mNsGFWWLkW8uch2puG2VIy1CHvSmT6 t6LjTzURfHF2qtO+vptifgCihYBUPpnexsntwiNlJLmbN1nex5CeHQ5y0179GIx+wLTE MXcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=hRX9HcY4; 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=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o14-20020aa7c50e000000b004faec05e5c5si26401530edq.138.2023.03.29.17.51.59; Wed, 29 Mar 2023 17:52:35 -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=@linux.dev header.s=key1 header.b=hRX9HcY4; 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=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231342AbjC3ARo (ORCPT + 99 others); Wed, 29 Mar 2023 20:17:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbjC3ARm (ORCPT ); Wed, 29 Mar 2023 20:17:42 -0400 Received: from out-40.mta1.migadu.com (out-40.mta1.migadu.com [95.215.58.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 433F7C0 for ; Wed, 29 Mar 2023 17:17:40 -0700 (PDT) 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230206172340.2639971-7-rananta@google.com> X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 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