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 3DD8EC54E58 for ; Tue, 26 Mar 2024 08:34:46 +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=w/WJLm3pHfggwoVQ1PkdXNw752WyOSqEa/IdtMw/m88=; b=eO2UBj0bVV0xs2 KbowJCtAer8RbBdCXkWNp79AJyNY3jl1OiILhEMCvVhX0EbqboOyM5Kr185hUene6gb0uZT+6goXy /el/lh1Ep/8mrOZJzO/Yfok6RczSeq4rNKOW2taZtEGaeVaE8uKvtyBFqIQ0oTOIsqvAZeC4s2y4/ KhDnWv6zOyGQmgJCgNnOa7q3kADEvYMkXFoSb/tCCyvgnAvNnR5RHFWacCMDE5h4Q5HuRmt4SWEMk 7AJSZNM1wOXG6PxLVwC3B7yJPvB6E+mT3ScyvKoErjFHBmGD8b5EBn40Yqtu//x/guPcQOLQUNrrd 6cniI3DueK4hGVf33ciA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rp2GN-00000003d66-273o; Tue, 26 Mar 2024 08:34:31 +0000 Received: from out-172.mta1.migadu.com ([95.215.58.172]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rp2GJ-00000003d3T-3po2 for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2024 08:34:29 +0000 Date: Tue, 26 Mar 2024 01:34:17 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711442062; 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=a5Qd+NuqhOMxkePHM7IZmqHPBd6oxS5Xxd9L3bfHHfY=; b=USXG375Vv8L3dUSSTZ8DW/Q1PMHqssfPfdtzbygRL9hSHys72/eP0YL+TFLqhz6A43lvcq uAqURNDGbwpwmo5LZtDqCKF6Nv3cWJhCoMDGjHe/s64oMXxkR6tcuKROQ67IwGS9wzv8aF lrAQlYLR4QIScvxWKjozlZrBVC/QTxc= 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: <20240325185158.8565-2-will@kernel.org> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240326_013428_489094_95C77EEA X-CRM114-Status: GOOD ( 17.47 ) 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 Hey Will, On Mon, Mar 25, 2024 at 06:51:56PM +0000, Will Deacon wrote: > Commit 7657ea920c54 ("KVM: arm64: Use TLBI range-based instructions for > unmap") introduced deferred TLB invalidation for the stage-2 page-table > so that range-based invalidation can be used for the accumulated > addresses. This works fine if the structure of the page-tables remains > unchanged, but if entire tables are zapped and subsequently freed then > we transiently leave the hardware page-table walker with a reference > to freed memory thanks to the translation walk caches. Yikes! Well spotted. This is rather unfortunate because the unmap path has been found to be a massive pain w/o aggregating invalidations. But sacrificing correctness in the name of performance... No thanks :) > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index 3fae5830f8d2..de0b667ba296 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -896,9 +896,11 @@ static void stage2_unmap_put_pte(const struct kvm_pgtable_visit_ctx *ctx, > if (kvm_pte_valid(ctx->old)) { > kvm_clear_pte(ctx->ptep); > > - if (!stage2_unmap_defer_tlb_flush(pgt)) > + if (!stage2_unmap_defer_tlb_flush(pgt) || > + kvm_pte_table(ctx->old, ctx->level)) { > kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, mmu, > ctx->addr, ctx->level); > + } I'm not sure this is correct, though. My understanding of TTL is that we're telling hardware where the *leaf* entry we're invalidating is found, however here we know that the addressed PTE is a table entry. So maybe in the case of a table PTE this invalidation should TLBI_TTL_UNKNOWN. > } > > 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. -- Thanks, Oliver _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel