From: Nathan Chen <nathanc@nvidia.com>
To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
linux-kernel@vger.kernel.org
Cc: Mark Rutland <mark.rutland@arm.com>,
Will Deacon <will@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Joey Gouly <joey.gouly@arm.com>,
Fuad Tabba <fuad.tabba@linux.dev>,
Oliver Upton <oupton@kernel.org>, Marc Zyngier <maz@kernel.org>,
Tom Matthias <tmatthias@nvidia.com>,
Shameer Kolothum Thodi <skolothumtho@nvidia.com>,
Jason Gunthorpe <jgg@nvidia.com>,
Julian Miller <julianmiller@nvidia.com>
Subject: [RFC PATCH 3/6] KVM: arm64: Add kvm_arm_vmid_nr_usable()
Date: Tue, 24 Nov 2026 13:12:15 -0800 [thread overview]
Message-ID: <20261124211218.2751086-4-nathanc@nvidia.com> (raw)
In-Reply-To: <20261124211218.2751086-1-nathanc@nvidia.com>
Growing the shadow stage-2 MMU pool of nested VMs needs a host-wide
limit derived from how many VMIDs the allocator can hand out within a
generation, before a rollover.
That is fewer than NUM_USER_VMIDS: VMID #0 is never allocated, and a
rollover can keep one VMID reserved per CPU for the VMID active on it.
Add kvm_arm_vmid_nr_usable() to return that number, so that the limit
is computed next to the allocator that sets it.
Signed-off-by: Nathan Chen <nathanc@nvidia.com>
---
arch/arm64/include/asm/kvm_host.h | 1 +
arch/arm64/kvm/vmid.c | 12 ++++++++++++
2 files changed, 13 insertions(+)
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index c7133999296f..6ae86bc96600 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -1431,6 +1431,7 @@ int __init kvm_arm_vmid_alloc_init(void);
void __init kvm_arm_vmid_alloc_free(void);
void kvm_arm_vmid_update(struct kvm_vmid *kvm_vmid);
void kvm_arm_vmid_clear_active(void);
+unsigned int kvm_arm_vmid_nr_usable(void);
static inline void kvm_arm_pvtime_vcpu_init(struct kvm_vcpu_arch *vcpu_arch)
{
diff --git a/arch/arm64/kvm/vmid.c b/arch/arm64/kvm/vmid.c
index 7fe8ba1a2851..cf044f434531 100644
--- a/arch/arm64/kvm/vmid.c
+++ b/arch/arm64/kvm/vmid.c
@@ -129,6 +129,18 @@ static u64 new_vmid(struct kvm_vmid *kvm_vmid)
return vmid;
}
+/*
+ * Number of VMIDs that can be handed out within a generation: VMID #0
+ * is never allocated, and a rollover can keep one VMID reserved per CPU.
+ */
+unsigned int kvm_arm_vmid_nr_usable(void)
+{
+ if (NUM_USER_VMIDS - 1 <= num_possible_cpus())
+ return 0;
+
+ return NUM_USER_VMIDS - 1 - num_possible_cpus();
+}
+
/* Called from vCPU sched out with preemption disabled */
void kvm_arm_vmid_clear_active(void)
{
--
2.43.0
next prev parent reply other threads:[~2026-11-24 21:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 21:12 [RFC PATCH 0/6] KVM: arm64: nv: Grow the shadow S2 MMU pool on demand Nathan Chen
2026-11-24 21:12 ` [RFC PATCH 1/6] KVM: arm64: nv: Allocate shadow S2 MMUs in blocks Nathan Chen
2026-11-24 21:12 ` [RFC PATCH 2/6] KVM: arm64: nv: Pick the shadow S2 MMU to recycle with a clock Nathan Chen
2026-11-24 21:12 ` Nathan Chen [this message]
2026-11-24 21:12 ` [RFC PATCH 4/6] KVM: arm64: nv: Grow the shadow S2 MMU pool on demand Nathan Chen
2026-11-24 21:12 ` [RFC PATCH 5/6] KVM: arm64: nv: Park grown MMUs on ALLE1 and reactivate them " Nathan Chen
2026-11-24 21:12 ` [RFC PATCH 6/6] KVM: arm64: nv: Park shadow S2 MMUs emptied by a guest range invalidation Nathan Chen
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=20261124211218.2751086-4-nathanc@nvidia.com \
--to=nathanc@nvidia.com \
--cc=catalin.marinas@arm.com \
--cc=fuad.tabba@linux.dev \
--cc=jgg@nvidia.com \
--cc=joey.gouly@arm.com \
--cc=julianmiller@nvidia.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=seiden@linux.ibm.com \
--cc=skolothumtho@nvidia.com \
--cc=suzuki.poulose@arm.com \
--cc=tmatthias@nvidia.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