From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6ED9E3AA4E0; Wed, 5 Aug 2026 07:32:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785915153; cv=none; b=sFgJyxJexdqmnGuOlfF5JP427Dfw2LMPeZfKGyW+kfhfVBFhPSJPobzDX+5VZgWfvIJbxraoHfwN9gOlRkTDzTzrD+JkMwvKCO/bKnH9anbyCKzL+LBraPK2kTllF4XD1lInqDzmAl+b/EQfi0Ry0DPPevgE2A4fTV5r7EfPrxM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785915153; c=relaxed/simple; bh=e/edK18iGwrGI3is8JT2xxd4IFU/3bP5IVZj0CBsU7E=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=ccIi+A99nFWAbTJyJ1wBgP2d5gNAa7gsGw4G84K+wSZBYPQ/nABMYAtPyA006912jYSdigtPS3SNKq0jYhR8XSEV0/GjDpvmdfDsEJQmAFdx1o7o0OqkHsQcmN6gJLaX51pffqqgpGgXS4Be8pzL7x36kCusbGM2mpE1CwGZW5w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AJJaA9T5; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AJJaA9T5" 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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.