KVM: Add a dedicated mmu_notifier flag for reclaiming freed memory
authorSean Christopherson <seanjc@google.com>
Fri, 27 Oct 2023 18:21:52 +0000 (11:21 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 13 Nov 2023 10:31:37 +0000 (05:31 -0500)
commitcec29eef0a815386d520d61c2cbe16d537931639
tree1821e7d4a62f39e239e776021372c8461542d909
parent16f95f3b95caded251a0440051e44a2fbe9e5f55
KVM: Add a dedicated mmu_notifier flag for reclaiming freed memory

Handle AMD SEV's kvm_arch_guest_memory_reclaimed() hook by having
__kvm_handle_hva_range() return whether or not an overlapping memslot
was found, i.e. mmu_lock was acquired.  Using the .on_unlock() hook
works, but kvm_arch_guest_memory_reclaimed() needs to run after dropping
mmu_lock, which makes .on_lock() and .on_unlock() asymmetrical.

Use a small struct to return the tuple of the notifier-specific return,
plus whether or not overlap was found.  Because the iteration helpers are
__always_inlined, practically speaking, the struct will never actually be
returned from a function call (not to mention the size of the struct will
be two bytes in practice).

Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Fuad Tabba <tabba@google.com>
Tested-by: Fuad Tabba <tabba@google.com>
Message-Id: <20231027182217.3615211-11-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
virt/kvm/kvm_main.c