Skip to content

Commit 193bbfa

Browse files
sean-jcbonzini
authored andcommitted
KVM: Drop .on_unlock() mmu_notifier hook
Drop the .on_unlock() mmu_notifer hook now that it's no longer used for notifying arch code that memory has been reclaimed. Adding .on_unlock() and invoking it *after* dropping mmu_lock was a terrible idea, as doing so resulted in .on_lock() and .on_unlock() having divergent and asymmetric behavior, and set future developers up for failure, i.e. all but asked for bugs where KVM relied on using .on_unlock() to try to run a callback while holding mmu_lock. Opportunistically add a lockdep assertion in kvm_mmu_invalidate_end() to guard against future bugs of this nature. Reported-by: Isaku Yamahata <isaku.yamahata@intel.com> Link: https://lore.kernel.org/all/20230802203119.GB2021422@ls.amr.corp.intel.com 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-12-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent cec29ee commit 193bbfa

1 file changed

Lines changed: 1 addition & 10 deletions

File tree

virt/kvm/kvm_main.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,6 @@ static inline struct kvm *mmu_notifier_to_kvm(struct mmu_notifier *mn)
544544
typedef bool (*gfn_handler_t)(struct kvm *kvm, struct kvm_gfn_range *range);
545545

546546
typedef void (*on_lock_fn_t)(struct kvm *kvm);
547-
typedef void (*on_unlock_fn_t)(struct kvm *kvm);
548547

549548
struct kvm_mmu_notifier_range {
550549
/*
@@ -556,7 +555,6 @@ struct kvm_mmu_notifier_range {
556555
union kvm_mmu_notifier_arg arg;
557556
gfn_handler_t handler;
558557
on_lock_fn_t on_lock;
559-
on_unlock_fn_t on_unlock;
560558
bool flush_on_ret;
561559
bool may_block;
562560
};
@@ -663,11 +661,8 @@ static __always_inline kvm_mn_ret_t __kvm_handle_hva_range(struct kvm *kvm,
663661
if (range->flush_on_ret && r.ret)
664662
kvm_flush_remote_tlbs(kvm);
665663

666-
if (r.found_memslot) {
664+
if (r.found_memslot)
667665
KVM_MMU_UNLOCK(kvm);
668-
if (!IS_KVM_NULL_FN(range->on_unlock))
669-
range->on_unlock(kvm);
670-
}
671666

672667
srcu_read_unlock(&kvm->srcu, idx);
673668

@@ -687,7 +682,6 @@ static __always_inline int kvm_handle_hva_range(struct mmu_notifier *mn,
687682
.arg = arg,
688683
.handler = handler,
689684
.on_lock = (void *)kvm_null_fn,
690-
.on_unlock = (void *)kvm_null_fn,
691685
.flush_on_ret = true,
692686
.may_block = false,
693687
};
@@ -706,7 +700,6 @@ static __always_inline int kvm_handle_hva_range_no_flush(struct mmu_notifier *mn
706700
.end = end,
707701
.handler = handler,
708702
.on_lock = (void *)kvm_null_fn,
709-
.on_unlock = (void *)kvm_null_fn,
710703
.flush_on_ret = false,
711704
.may_block = false,
712705
};
@@ -813,7 +806,6 @@ static int kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn,
813806
.end = range->end,
814807
.handler = kvm_mmu_unmap_gfn_range,
815808
.on_lock = kvm_mmu_invalidate_begin,
816-
.on_unlock = (void *)kvm_null_fn,
817809
.flush_on_ret = true,
818810
.may_block = mmu_notifier_range_blockable(range),
819811
};
@@ -891,7 +883,6 @@ static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn,
891883
.end = range->end,
892884
.handler = (void *)kvm_null_fn,
893885
.on_lock = kvm_mmu_invalidate_end,
894-
.on_unlock = (void *)kvm_null_fn,
895886
.flush_on_ret = false,
896887
.may_block = mmu_notifier_range_blockable(range),
897888
};

0 commit comments

Comments
 (0)