Re: [PATCH] KVM: mmu_notifier: make mn_invalidate_lock non-sleeping for non-blocking invalidations

From: Paolo Bonzini

Date: Sat Mar 14 2026 - 03:48:06 EST


On 3/12/26 20:24, shaikh kamaluddin wrote:
Alternatively, if you think this needs to be addressed in
mmu_notifiers(eg. how non_block_start() is applied), I'm happy to
redirect my efforts there-Please advise.

Have you considered a "OOM entered" callback for MMU notifiers? KVM's MMU
notifier can just remove itself for example, in fact there is code in
kvm_destroy_vm() to do that even if invalidations are unbalanced.

Paolo

Thanks for the suggestion! That's a much cleaner approach than what I was considering.

If I understand correctly, the idea would be:
1. Add a new MMU notifier callback (e.g., .oom_entered or .release_on_oom)
2. Have KVM implement it to unregister the notifier when OOM reaper starts
3. Leverage the existing kvm_destroy_vm() logic that already handles unbalanced invalidations

Yes pretty much. Essentially, move the existing logic to the new callback and invoke it from kvm_destroy_vm().

This avoids the whole "convert locks to raw" problem and the complexity of deferring work.

I have questions on Testing part:
------------------------------------
I tried to reproduce the bug scenario using the virtme-ng then running
the stress-ng putting memory pressure on VM, but not able to reproduce
the scenario.
I tried this way ..
vng -v -r ./arch/x86/boot/bzImage
VM is up, then running the stress-ng as below
stress-ng --vm 2 --vm-bytes 95% --timeout 20s & sleep 5 & dmesg | tail -30 | grep "sleeping function"
OOM Killer is triggered, but exact bug not able to reproduce, Please
suggest how to reproduce this bug, even we need to verify after code
changes which you have suggested.

I don't know, sorry. But with this new approach there will always be a call to the new callback from the OOM killer, so it's easier to test.

Thanks,

Paolo