Re: [PATCH v3] KVM: x86/mmu: Retry fault before acquiring mmu_lock if mapping is changing

From: Friedrich Weber
Date: Tue Feb 06 2024 - 08:52:53 EST


On 03/02/2024 01:35, Sean Christopherson wrote:
> Retry page faults without acquiring mmu_lock if the resolved gfn is covered
> by an active invalidation. Contending for mmu_lock is especially
> problematic on preemptible kernels as the mmu_notifier invalidation task
> will yield mmu_lock (see rwlock_needbreak()), delay the in-progress
> invalidation, and ultimately increase the latency of resolving the page
> fault. And in the worst case scenario, yielding will be accompanied by a
> remote TLB flush, e.g. if the invalidation covers a large range of memory
> and vCPUs are accessing addresses that were already zapped.
[...]

Can confirm this patch fixes temporary guest hangs in combination with
KSM and NUMA balancing I'm seeing [1], which is likely to be the same
issue as described in [2]:

* On this patch's base-commit 60eedcfc from
git.kernel.org/pub/scm/virt/kvm/kvm.git, I can reproduce the hangs (see
[1] for reproducer)
* With this patch applied on top, I cannot reproduce the hangs anymore.

Thanks!

[1]
https://lore.kernel.org/kvm/832697b9-3652-422d-a019-8c0574a188ac@xxxxxxxxxxx/
[2] https://bugzilla.kernel.org/show_bug.cgi?id=218259