Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Karl Mehltretter <kmehltretter@gmail.com>
Cc: Oliver Upton <oupton@kernel.org>, Fuad Tabba <tabba@google.com>,
	Joey Gouly <joey.gouly@arm.com>,
	Steffen Eiden <seiden@linux.ibm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <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
Subject: Re: [PATCH 1/2] KVM: arm64: nv: Allocate the shadow S2 MMUs individually
Date: Wed, 05 Aug 2026 08:32:29 +0100	[thread overview]
Message-ID: <86ecgdaupe.wl-maz@kernel.org> (raw)
In-Reply-To: <anJcUNlnNmP-mKWH@gmail.com>

On Tue, 04 Aug 2026 22:54:30 +0100,
Karl Mehltretter <kmehltretter@gmail.com> 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.


  reply	other threads:[~2026-08-05  7:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 22:44 [PATCH 1/2] KVM: arm64: nv: Allocate the shadow S2 MMUs individually Karl Mehltretter
2026-08-03 22:44 ` [PATCH 2/2] KVM: arm64: selftests: Add a nested S2 MMU realloc test Karl Mehltretter
2026-08-04 14:44   ` Marc Zyngier
2026-08-04 10:24 ` [PATCH 1/2] KVM: arm64: nv: Allocate the shadow S2 MMUs individually Wei-Lin Chang
2026-08-04 14:31 ` Marc Zyngier
2026-08-04 14:56   ` Marc Zyngier
2026-08-04 21:54     ` Karl Mehltretter
2026-08-05  7:32       ` Marc Zyngier [this message]
2026-08-05 21:39         ` Karl Mehltretter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86ecgdaupe.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=grayhat@foxmail.com \
    --cc=joey.gouly@arm.com \
    --cc=kmehltretter@gmail.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oupton@kernel.org \
    --cc=seiden@linux.ibm.com \
    --cc=stable@vger.kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=tabba@google.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox