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.
Unified · Split
| @@ -544,7 +544,6 @@ static inline struct kvm *mmu_notifier_to_kvm(struct mmu_notifier *mn) · 543 unmodified lines | ||
| 544 | 544 | typedef bool (*gfn_handler_t)(struct kvm *kvm, struct kvm_gfn_range *range); |
| 545 | 545 | |
| 546 | 546 | typedef void (*on_lock_fn_t)(struct kvm *kvm); |
| 547 | −typedef void (*on_unlock_fn_t)(struct kvm *kvm); | |
| 548 | 547 | |
| 549 | 548 | struct kvm_mmu_notifier_range { |
| 550 | 549 | /* |
| @@ -556,7 +555,6 @@ struct kvm_mmu_notifier_range { · 5 unmodified lines | ||
| 556 | 555 | union kvm_mmu_notifier_arg arg; |
| 557 | 556 | gfn_handler_t handler; |
| 558 | 557 | on_lock_fn_t on_lock; |
| 559 | − on_unlock_fn_t on_unlock; | |
| 560 | 558 | bool flush_on_ret; |
| 561 | 559 | bool may_block; |
| 562 | 560 | }; |
| @@ -663,11 +661,8 @@ static __always_inline kvm_mn_ret_t __kvm_handle_hva_range(struct kvm *kvm, · 100 unmodified lines | ||
| 663 | 661 | if (range->flush_on_ret && r.ret) |
| 664 | 662 | kvm_flush_remote_tlbs(kvm); |
| 665 | 663 | |
| 666 | − if (r.found_memslot) { | |
| 664 | + if (r.found_memslot) | |
| 667 | 665 | KVM_MMU_UNLOCK(kvm); |
| 668 | − if (!IS_KVM_NULL_FN(range->on_unlock)) | |
| 669 | − range->on_unlock(kvm); | |
| 670 | − } | |
| 671 | 666 | |
| 672 | 667 | srcu_read_unlock(&kvm->srcu, idx); |
| 673 | 668 | |
| @@ -687,7 +682,6 @@ static __always_inline int kvm_handle_hva_range(struct mmu_notifier *mn, · 13 unmodified lines | ||
| 687 | 682 | .arg = arg, |
| 688 | 683 | .handler = handler, |
| 689 | 684 | .on_lock = (void *)kvm_null_fn, |
| 690 | − .on_unlock = (void *)kvm_null_fn, | |
| 691 | 685 | .flush_on_ret = true, |
| 692 | 686 | .may_block = false, |
| 693 | 687 | }; |
| @@ -706,7 +700,6 @@ static __always_inline int kvm_handle_hva_range_no_flush(struct mmu_notifier *mn · 12 unmodified lines | ||
| 706 | 700 | .end = end, |
| 707 | 701 | .handler = handler, |
| 708 | 702 | .on_lock = (void *)kvm_null_fn, |
| 709 | − .on_unlock = (void *)kvm_null_fn, | |
| 710 | 703 | .flush_on_ret = false, |
| 711 | 704 | .may_block = false, |
| 712 | 705 | }; |
| @@ -813,7 +806,6 @@ static int kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn, · 100 unmodified lines | ||
| 813 | 806 | .end = range->end, |
| 814 | 807 | .handler = kvm_mmu_unmap_gfn_range, |
| 815 | 808 | .on_lock = kvm_mmu_invalidate_begin, |
| 816 | − .on_unlock = (void *)kvm_null_fn, | |
| 817 | 809 | .flush_on_ret = true, |
| 818 | 810 | .may_block = mmu_notifier_range_blockable(range), |
| 819 | 811 | }; |
| @@ -891,7 +883,6 @@ static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn, · 71 unmodified lines | ||
| 891 | 883 | .end = range->end, |
| 892 | 884 | .handler = (void *)kvm_null_fn, |
| 893 | 885 | .on_lock = kvm_mmu_invalidate_end, |
| 894 | − .on_unlock = (void *)kvm_null_fn, | |
| 895 | 886 | .flush_on_ret = false, |
| 896 | 887 | .may_block = mmu_notifier_range_blockable(range), |
| 897 | 888 | }; |