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 F2CB710AB830 for ; Fri, 27 Mar 2026 14:49:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2rnMwgQO4R/3vr4dsXn1qdBtSH9uq6/lEmthcxDJm2Y=; b=XIdZ81edkcYJfCJAevnOcQKXia myIBXPJ4hDXLV6t0GEWj9H5UEosrST3/Qm3nRXuBDR6RmzmciG0pJ7UzWN4a+bJaX9AbqDZWz7BRv UYCNEHdTKwIC7lConA0iyZFnTD6zxGa0VfECiT0wBv7drYBhiaK6wlkvwRi7uzkLWU48Pn+ziRIIy vp7FHDajfXq1sta406vSUa1aP7LLBQxtsxqfS0eDSxsoSwbON8XuPKUcabjUjPpbckaIRBh/MIyVB VYr+KhKdqmrP5kEsYT9fVnB2pFSj+d8ocn91fxoYAnlEXsRTzpSL7uTCW9wz82hvlKATPi80De7bz 4w3rpFYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1w68Uu-00000007dbQ-2hXB; Fri, 27 Mar 2026 14:49:16 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w68Ut-00000007dbI-3YbQ for linux-arm-kernel@lists.infradead.org; Fri, 27 Mar 2026 14:49:15 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id DC970600AC; Fri, 27 Mar 2026 14:49:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BFC4C19423; Fri, 27 Mar 2026 14:49:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774622954; bh=bGI/cAugrNnig4KQOyBbkhQzweiFkpeRdiDXpd6DHe8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=C/jm2dmRjOh6fraMMQ4iojohVQmL/HM+bEnLFDCyIdSen6wG4z7QHm+U8z32tHi4k uC/DCDo9SJ6w0SJO0jjwSVJxpnbSX9Liw3QWjyMkKXpVpBDd4Ny9ZlTxs47xQP3F8F CiIGMA2I7wRfeh0QlMQPliOsWuKqjqFM8HYtwKyh6mQkr6gEROCPSvESPs5D3AslTZ CiiIMHUvftAXSSkLFt07sHBOHnto1QFryRr8+XIfoVUjGwlfwz6JsjjU9HMEUjHGGA 6WWmn81OJQetqULZ0KPFgXf6IU+KXaYgY8Ub6CN81OrfKf8gkjYR4BUL8zA7G+AIst nOKf8YcPuc0ZA== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w68Uq-00000006OdQ-0zc8; Fri, 27 Mar 2026 14:49:12 +0000 Date: Fri, 27 Mar 2026 14:49:11 +0000 Message-ID: <86ecl549aw.wl-maz@kernel.org> From: Marc Zyngier To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: Joey Gouly , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Fuad Tabba , Will Deacon , Quentin Perret Subject: Re: [PATCH v2 21/30] KVM: arm64: Kill topup_memcache from kvm_s2_fault In-Reply-To: <20260327113618.4051534-22-maz@kernel.org> References: <20260327113618.4051534-1-maz@kernel.org> <20260327113618.4051534-22-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, oupton@kernel.org, yuzenghui@huawei.com, tabba@google.com, will@kernel.org, qperret@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, 27 Mar 2026 11:36:09 +0000, Marc Zyngier wrote: > > The topup_memcache field can be easily replaced by the equivalent > conditions, and the resulting code is not much worse. > > Tested-by: Fuad Tabba > Reviewed-by: Fuad Tabba > Reviewed-by: Suzuki K Poulose > Signed-off-by: Marc Zyngier > --- > arch/arm64/kvm/mmu.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index e8bda71e862b2..5b05caecdbd92 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -1712,7 +1712,6 @@ static short kvm_s2_resolve_vma_size(const struct kvm_s2_fault_desc *s2fd, > > struct kvm_s2_fault { > bool writable; > - bool topup_memcache; > bool mte_allowed; > bool is_vma_cacheable; > bool s2_force_noncacheable; > @@ -1983,9 +1982,8 @@ static int user_mem_abort(const struct kvm_s2_fault_desc *s2fd) > .logging_active = logging_active, > .force_pte = logging_active, > .prot = KVM_PGTABLE_PROT_R, > - .topup_memcache = !perm_fault || (logging_active && kvm_is_write_fault(s2fd->vcpu)), > }; > - void *memcache; > + void *memcache = NULL; > int ret; > > /* > @@ -1994,9 +1992,11 @@ static int user_mem_abort(const struct kvm_s2_fault_desc *s2fd) > * only exception to this is when dirty logging is enabled at runtime > * and a write fault needs to collapse a block entry into a table. > */ > - ret = prepare_mmu_memcache(s2fd->vcpu, fault.topup_memcache, &memcache); > - if (ret) > - return ret; > + if (!perm_fault || (logging_active && kvm_is_write_fault(s2fd->vcpu))) { > + ret = prepare_mmu_memcache(s2fd->vcpu, true, &memcache); > + if (ret) > + return ret; > + } > > /* > * Let's check if we will get back a huge page backed by hugetlbfs, or Sashiko has spotted [1] an interesting corner case here, which is that the original code always initialises memcache to its correct value, while we now only do it in a limited number of cases. I'm proposing to restore the original behaviour by folding the following change into this patch, splitting the retrieval of the memcache pointer from the top-up and avoiding the ugly pointer indirection: diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 1fe7182be45ac..03e1f389339c7 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1513,25 +1513,22 @@ static bool kvm_vma_is_cacheable(struct vm_area_struct *vma) } } -static int prepare_mmu_memcache(struct kvm_vcpu *vcpu, bool topup_memcache, - void **memcache) +static void *get_mmu_memcache(struct kvm_vcpu *vcpu) { - int min_pages; - if (!is_protected_kvm_enabled()) - *memcache = &vcpu->arch.mmu_page_cache; + return &vcpu->arch.mmu_page_cache; else - *memcache = &vcpu->arch.pkvm_memcache; - - if (!topup_memcache) - return 0; + return &vcpu->arch.pkvm_memcache; +} - min_pages = kvm_mmu_cache_min_pages(vcpu->arch.hw_mmu); +static int topup_mmu_memcache(struct kvm_vcpu *vcpu, void *memcache) +{ + int min_pages = kvm_mmu_cache_min_pages(vcpu->arch.hw_mmu); if (!is_protected_kvm_enabled()) - return kvm_mmu_topup_memory_cache(*memcache, min_pages); + return kvm_mmu_topup_memory_cache(memcache, min_pages); - return topup_hyp_memcache(*memcache, min_pages); + return topup_hyp_memcache(memcache, min_pages); } /* @@ -1589,7 +1586,8 @@ static int gmem_abort(const struct kvm_s2_fault_desc *s2fd) gfn_t gfn; int ret; - ret = prepare_mmu_memcache(s2fd->vcpu, true, &memcache); + memcache = get_mmu_memcache(s2fd->vcpu); + ret = topup_mmu_memcache(s2fd->vcpu, memcache); if (ret) return ret; @@ -1993,7 +1991,7 @@ static int user_mem_abort(const struct kvm_s2_fault_desc *s2fd) bool perm_fault = kvm_vcpu_trap_is_permission_fault(s2fd->vcpu); struct kvm_s2_fault_vma_info s2vi = {}; enum kvm_pgtable_prot prot; - void *memcache = NULL; + void *memcache; int ret; /* @@ -2002,9 +2000,10 @@ static int user_mem_abort(const struct kvm_s2_fault_desc *s2fd) * only exception to this is when dirty logging is enabled at runtime * and a write fault needs to collapse a block entry into a table. */ + memcache = get_mmu_memcache(s2fd->vcpu); if (!perm_fault || (memslot_is_logging(s2fd->memslot) && kvm_is_write_fault(s2fd->vcpu))) { - ret = prepare_mmu_memcache(s2fd->vcpu, true, &memcache); + ret = topup_mmu_memcache(s2fd->vcpu, memcache); if (ret) return ret; } The bot has also pointed out a couple of cases where memcache and permission faults interact badly. I'll look into them separately, as they predate this rework. Thanks, M. [1] https://sashiko.dev/#/patchset/20260327113618.4051534-1-maz%40kernel.org?patch=12134 -- Without deviation from the norm, progress is not possible.