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 6/6] KVM: arm64: nv: Park shadow S2 MMUs emptied by a guest range invalidation
Date: Tue, 24 Nov 2026 13:12:18 -0800 [thread overview]
Message-ID: <20261124211218.2751086-7-nathanc@nvidia.com> (raw)
In-Reply-To: <20261124211218.2751086-1-nathanc@nvidia.com>
If a guest TLBI RIPAS2E1IS or VMALLS12E1IS leaves a grown, unreferenced
MMU empty, park it there rather than leave it valid until a recycle
unmaps the whole IPA space of an already empty MMU.
Signed-off-by: Nathan Chen <nathanc@nvidia.com>
---
arch/arm64/include/asm/kvm_nested.h | 1 +
arch/arm64/kvm/nested.c | 2 +-
arch/arm64/kvm/sys_regs.c | 8 ++++++++
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/kvm_nested.h b/arch/arm64/include/asm/kvm_nested.h
index 952853ab245a..164e42376296 100644
--- a/arch/arm64/include/asm/kvm_nested.h
+++ b/arch/arm64/include/asm/kvm_nested.h
@@ -175,6 +175,7 @@ extern void kvm_nested_unmap_cipa_range(struct kvm *kvm, gpa_t cipa,
size_t unmap_size, bool may_block);
extern void kvm_nested_s2_unmap(struct kvm *kvm, bool may_block);
extern void kvm_nested_s2_shrink(struct kvm *kvm);
+extern bool kvm_nested_s2_park(struct kvm *kvm, struct kvm_s2_mmu *mmu);
extern void kvm_nested_s2_flush(struct kvm *kvm);
unsigned long compute_tlb_inval_range(struct kvm_s2_mmu *mmu, u64 val);
diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
index 9251f3fd4840..e9a2eaef9eda 100644
--- a/arch/arm64/kvm/nested.c
+++ b/arch/arm64/kvm/nested.c
@@ -121,7 +121,7 @@ static bool kvm_s2_mmu_empty(struct kvm_s2_mmu *mmu)
* mmu_lock never see it go away. Parking always leaves S2_MMU_PER_VCPU
* unparked MMUs per vcpu, so the victim search always has a candidate.
*/
-static bool kvm_nested_s2_park(struct kvm *kvm, struct kvm_s2_mmu *mmu)
+bool kvm_nested_s2_park(struct kvm *kvm, struct kvm_s2_mmu *mmu)
{
unsigned int keep = atomic_read(&kvm->online_vcpus) * S2_MMU_PER_VCPU;
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index df81adf96259..99dcd2549b08 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -4123,6 +4123,14 @@ static void s2_mmu_unmap_range(struct kvm_s2_mmu *mmu,
* the TLBI.
*/
kvm_stage2_unmap_range(mmu, info->range.start, info->range.size, true);
+
+ /*
+ * The guest hypervisor may have unmapped everything this MMU held,
+ * e.g. all memory of a nested VM being torn down. If it is grown and
+ * now empty, return it to the budget rather than leave it for a
+ * recycle to unmap again.
+ */
+ kvm_nested_s2_park(kvm_s2_mmu_to_kvm(mmu), mmu);
}
static bool handle_vmalls12e1is(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
--
2.43.0
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 ` [RFC PATCH 3/6] KVM: arm64: Add kvm_arm_vmid_nr_usable() Nathan Chen
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 ` Nathan Chen [this message]
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-7-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