History

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.

Sean Christopherson committed 3 years ago

Commit 193bbfa1 parent cec29ee1 file · +1 −10Browse files

Unified · Split

virt/kvm/kvm_main.c+1−10
@@ -544,7 +544,6 @@ static inline struct kvm *mmu_notifier_to_kvm(struct mmu_notifier *mn) · 543 unmodified lines
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 { · 5 unmodified lines
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, · 100 unmodified lines
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, · 13 unmodified lines
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 · 12 unmodified lines
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, · 100 unmodified lines
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, · 71 unmodified lines
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 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t