On Tue, Jun 17, 2025 at 9:24 PM James Houghton <jthoughton@xxxxxxxxxx> wrote: > > Only a few changes are needed to support KVM userfault exits on x86: > > 1. Adjust kvm_mmu_hugepage_adjust() to force pages to be mapped at 4K > while KVM_MEM_USERFAULT is enabled. > 2. Return -EFAULT when kvm_do_userfault() when it reports that the page > is userfault. (Upon failure to read from the bitmap, > kvm_do_userfault() will return true without setting up a memory fault > exit, so we'll return a bare -EFAULT). > > For hugepage recovery, the behavior when disabling KVM_MEM_USERFAULT > should match the behavior when disabling KVM_MEM_LOG_DIRTY_PAGES; make > changes to kvm_mmu_slot_apply_flags() to recover hugepages when > KVM_MEM_USERFAULT is disabled. > > Signed-off-by: James Houghton <jthoughton@xxxxxxxxxx> > Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx> This patch fails to remove the WARN in recover_huge_pages_range(). The diff below will be applied to the next version of this patch, whenever it comes. This WARN can be hit by enabling KVM_MEM_LOG_DIRTY_PAGES and KVM_MEM_USERFAULT, then disabling KVM_MEM_USERFAULT. I've been having offline discussions with Sean about this series; I'm waiting for him to rework the KVM_GENERIC_PAGE_FAULT bits. I'll dedicate some more time to the QEMU side of things too. Thanks. diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 7f3d7229b2c1f..2d83ddb233a9a 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1779,7 +1779,7 @@ static void recover_huge_pages_range(struct kvm *kvm, u64 huge_spte; int r; - if (WARN_ON_ONCE(kvm_slot_dirty_track_enabled(slot))) + if (kvm_slot_dirty_track_enabled(slot)) return; rcu_read_lock();