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 9D0E0C55182 for ; Wed, 5 Aug 2026 07:32:42 +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=4gwj0kFUhwuS98ircZVc44GpqB+5fy9yUkWQ55U7j40=; b=N1NPgabomm8LOhzlYQDoxo47Jr gdnOB/FJeJ8mHYTMWOoojEI6NTFjCKoJLVHw/pD16ynW7ZB66j4/HOAeBsD+hb85dq7DxeWb4iKDq ESZqfqZEadJMu7yz9fYPT030hjLyPqdMwvkUmRIGj6IdrvwQDjUWwq436yocsGzZhJ7y7GwDSYt2T 5WSAI46hBLBJvkL/R4gUPQF6YhlK26jkF608wUKkvc/35V1w7tRoSabWfM4qGq/gR8IfFXa8iOF3F GCwTBHs9y+pWe6HrTKsFoSVnuFCc9EV4u8QOpULJpQ2exeTaNvRD/VCWTNDFPof7x/qkDFV5BMCyH atsxJZkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wrW79-00000003Psr-3XPd; Wed, 05 Aug 2026 07:32:35 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wrW78-00000003Psl-2zCB for linux-arm-kernel@lists.infradead.org; Wed, 05 Aug 2026 07:32:34 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 65326600B1; Wed, 5 Aug 2026 07:32:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A6D91F000E9; Wed, 5 Aug 2026 07:32:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785915152; bh=4gwj0kFUhwuS98ircZVc44GpqB+5fy9yUkWQ55U7j40=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=AJJaA9T5tFKel4SLkebN3gx+nsuoveBPZ42YEDRckt7z5kruBLv1cdm23oYFWUo5S 2+0Uy2veLD2U0WtemOp5DFT8pOeKwMnYh7BfGDSHPFK6RD0dqCa+j8bfHG0k4sUI15 APjHr9sxzCjMFbJnmXLX+Cy4cajxnSR6QLQXbSZyd8QNc2Wu3QyuGRHuxH+DT2vWUi PDLuTIFKK+UrX5hi4PA44H90RVHvhmJexgou2NK1zNvaE4o0wdp43YQ7Okb3YV5jC1 P2OIor9K3oxs5BK8xht++hYBWLCkk3S9xo6QCLtvmvfiubshhWNZ/+gPb9B0BTkmjr N4JsiYxAy70eA== 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 1wrW73-0000000CUuY-39dd; Wed, 05 Aug 2026 07:32:29 +0000 Date: Wed, 05 Aug 2026 08:32:29 +0100 Message-ID: <86ecgdaupe.wl-maz@kernel.org> From: Marc Zyngier To: Karl Mehltretter Cc: Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org, grayhat@foxmail.com Subject: Re: [PATCH 1/2] KVM: arm64: nv: Allocate the shadow S2 MMUs individually In-Reply-To: References: <20260803224405.41468-1-kmehltretter@gmail.com> <86mrv2arf2.wl-maz@kernel.org> <86jyq6aq8g.wl-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: kmehltretter@gmail.com, oupton@kernel.org, tabba@google.com, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org, grayhat@foxmail.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 Tue, 04 Aug 2026 22:54:30 +0100, Karl Mehltretter wrote: > > On Tue, Aug 04, 2026 at 03:56:47PM +0100, Marc Zyngier wrote: > > > The other thing is that reallocating the pointer array isn't great. It > > > adds complexity, and makes everything more fragile than it should be. > > > > > > See the hack below that seems to work OK. > > > > > Your draft is indeed a bit simpler. > > Should I send a cleaned-up version as v2? Yes, please. > > I would allocate the table on the first call to kvm_vcpu_init_nested() > and not in kvm_init_nested(), so it cannot leak if VM creation > fails. I'd rather keep it on the VM creation path. This is VM-wide data, by definition, and given that its size doesn't depend on the number of vcpus anymore (we allocate the maximum once and for all), it is right where it belongs. See the untested hack below for the freeing on error. > There's another issue in the current code: the ptdump debugfs file > keeps the raw mmu pointer as its private data. I would add that to the > commit message. Why is that a problem? With this approach, the mmu pointers are always expected to be valid, irrespective of the allocation pattern, and we only publish pointers to the dumper when the S2_mmu is actively being used. We're about to rip out the NV ptdump anyway as it has many other problems, but I'd like to understand what you see that I don't. Thanks, M. diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 9e42e92dbc7b1..e883e45382fb2 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -223,10 +223,6 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) mutex_unlock(&kvm->lock); #endif - ret = kvm_init_nested(kvm); - if (ret) - return ret; - ret = kvm_share_hyp(kvm, kvm + 1); if (ret) return ret; @@ -241,6 +237,10 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) if (ret) goto err_free_cpumask; + ret = kvm_init_nested(kvm); + if (ret) + goto err_uninit_mmu; + if (is_protected_kvm_enabled()) { /* * If any failures occur after this is successful, make sure to @@ -269,6 +269,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) err_uninit_mmu: kvm_uninit_stage2_mmu(kvm); + kvfree(kvm->arch.nested_mmus); err_free_cpumask: free_cpumask_var(kvm->arch.supported_cpus); err_unshare_kvm: -- Without deviation from the norm, progress is not possible.