* [PATCH] KVM: arm64: Top up the mmu memcache on user fault for NV
@ 2026-11-26 17:28 Lorenzo Stoakes (ARM)
2026-11-27 11:58 ` Leonardo Bras
0 siblings, 1 reply; 2+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-26 17:28 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Fuad Tabba, Joey Gouly, Steffen Eiden,
Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
Mark Rutland, Christoffer Dall, Jintack Lim, Leonardo Bras,
Wei-Lin Chang
Cc: linux-arm-kernel, kvmarm, linux-kernel, Usama Arif, ljs, stable
The S2 user fault path tops up the MMU memcache (used for page table
pre-allocation as the point at which page tables are installed may not
allocate) except when:
* It's a permission fault AND
* dirty page logging is disabled AND
* pKVM is disabled
At which point it is assumed no page table will be allocated.
However nested virtualisation adds another edge case - the mapping size of
a shadow S2 is clamped to that of the guest's own S2. If the guest
hypervisor replaces a block mapping with a table, a permission fault on the
shadow block has to be mapped at PAGE_SIZE, which requires a page table to
collapse the block into.
With the memcache empty, kvm_mmu_memory_cache_alloc() hits its
guest-triggerable WARN_ON(!nobjs) and falls back to a GFP_ATOMIC allocation
under mmu_lock, with a BUG_ON() if that fails.
Therefore, also top up the memcache for permission faults taken on a
shadow S2.
Note that dirty logging had a similar issue, addressed in commit
56fd1fc526e6 ("KVM: arm64: Top up stage-2 memcache for dirty logging
faults").
Fixes: fd276e71d1e7 ("KVM: arm64: nv: Handle shadow stage 2 page faults")
Cc: stable@vger.kernel.org
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
---
arch/arm64/kvm/mmu.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index a0d4981ebb99..e09a8f2c0482 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -2256,16 +2256,18 @@ static int user_mem_abort(const struct kvm_s2_fault_desc *s2fd,
/*
* Permission faults just need to update the existing leaf entry,
- * and so normally don't require allocations from the memcache. The
- * only exception to this is when dirty logging is enabled at runtime
+ * and so normally don't require allocations from the memcache. One
+ * exception to this is when dirty logging is enabled at runtime
* and a fault needs to collapse a block entry into a table.
* Under pKVM a permission fault can also collapse pages into a block,
* which needs a fresh mapping object, and the hypervisor requires the
* min-pages memcache even when the install allocates nothing.
+ * With nested, a shadow stage-2 block may also need to be collapsed
+ * into a table if the guest's own stage-2 mapping has become smaller.
*/
memcache = get_mmu_memcache(s2fd->vcpu);
if (!perm_fault || memslot_is_logging(s2fd->memslot) ||
- is_protected_kvm_enabled()) {
+ is_protected_kvm_enabled() || s2fd->nested) {
ret = topup_mmu_memcache(s2fd->mmu, memcache);
if (ret)
return ret;
---
base-commit: 012e4bc01e339a65dc7c59181b5efb33b171d12c
change-id: 20261126-fix-nv-cache-topup-9ab1fd829014
Cheers,
--
Lorenzo Stoakes (ARM) <ljs@kernel.org>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] KVM: arm64: Top up the mmu memcache on user fault for NV
2026-11-26 17:28 [PATCH] KVM: arm64: Top up the mmu memcache on user fault for NV Lorenzo Stoakes (ARM)
@ 2026-11-27 11:58 ` Leonardo Bras
0 siblings, 0 replies; 2+ messages in thread
From: Leonardo Bras @ 2026-11-27 11:58 UTC (permalink / raw)
To: Lorenzo Stoakes (ARM)
Cc: Leonardo Bras, Marc Zyngier, Oliver Upton, Fuad Tabba, Joey Gouly,
Steffen Eiden, Suzuki K Poulose, Zenghui Yu, Catalin Marinas,
Will Deacon, Mark Rutland, Christoffer Dall, Jintack Lim,
Wei-Lin Chang, linux-arm-kernel, kvmarm, linux-kernel, Usama Arif,
stable
On Thu, Nov 26, 2026 at 05:28:29PM +0000, Lorenzo Stoakes (ARM) wrote:
> The S2 user fault path tops up the MMU memcache (used for page table
> pre-allocation as the point at which page tables are installed may not
> allocate) except when:
>
> * It's a permission fault AND
> * dirty page logging is disabled AND
> * pKVM is disabled
>
> At which point it is assumed no page table will be allocated.
>
> However nested virtualisation adds another edge case - the mapping size of
> a shadow S2 is clamped to that of the guest's own S2. If the guest
> hypervisor replaces a block mapping with a table, a permission fault on the
> shadow block has to be mapped at PAGE_SIZE, which requires a page table to
> collapse the block into.
Can you please expand on how would that happen?
IIUC when a guest hypervisor replaces a block mapping with a table, it
calls a tlbi in the range, and L0 will trap and remove the Shadow S2 entry,
then next access shouldn't be a permission but a translation fault.
What am I missing?
Thanks!
Leo
>
> With the memcache empty, kvm_mmu_memory_cache_alloc() hits its
> guest-triggerable WARN_ON(!nobjs) and falls back to a GFP_ATOMIC allocation
> under mmu_lock, with a BUG_ON() if that fails.
>
> Therefore, also top up the memcache for permission faults taken on a
> shadow S2.
>
> Note that dirty logging had a similar issue, addressed in commit
> 56fd1fc526e6 ("KVM: arm64: Top up stage-2 memcache for dirty logging
> faults").
>
> Fixes: fd276e71d1e7 ("KVM: arm64: nv: Handle shadow stage 2 page faults")
> Cc: stable@vger.kernel.org
> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> ---
> arch/arm64/kvm/mmu.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index a0d4981ebb99..e09a8f2c0482 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c
> @@ -2256,16 +2256,18 @@ static int user_mem_abort(const struct kvm_s2_fault_desc *s2fd,
>
> /*
> * Permission faults just need to update the existing leaf entry,
> - * and so normally don't require allocations from the memcache. The
> - * only exception to this is when dirty logging is enabled at runtime
> + * and so normally don't require allocations from the memcache. One
> + * exception to this is when dirty logging is enabled at runtime
> * and a fault needs to collapse a block entry into a table.
> * Under pKVM a permission fault can also collapse pages into a block,
> * which needs a fresh mapping object, and the hypervisor requires the
> * min-pages memcache even when the install allocates nothing.
> + * With nested, a shadow stage-2 block may also need to be collapsed
> + * into a table if the guest's own stage-2 mapping has become smaller.
> */
> memcache = get_mmu_memcache(s2fd->vcpu);
> if (!perm_fault || memslot_is_logging(s2fd->memslot) ||
> - is_protected_kvm_enabled()) {
> + is_protected_kvm_enabled() || s2fd->nested) {
> ret = topup_mmu_memcache(s2fd->mmu, memcache);
> if (ret)
> return ret;
>
> ---
> base-commit: 012e4bc01e339a65dc7c59181b5efb33b171d12c
> change-id: 20261126-fix-nv-cache-topup-9ab1fd829014
>
> Cheers,
> --
> Lorenzo Stoakes (ARM) <ljs@kernel.org>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-27 11:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 17:28 [PATCH] KVM: arm64: Top up the mmu memcache on user fault for NV Lorenzo Stoakes (ARM)
2026-11-27 11:58 ` Leonardo Bras
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox