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 | typedef bool (*gfn_handler_t)(struct kvm *kvm, struct kvm_gfn_range *range); | 544 | typedef bool (*gfn_handler_t)(struct kvm *kvm, struct kvm_gfn_range *range); |
| 545 | 545 | ||
| 546 | typedef void (*on_lock_fn_t)(struct kvm *kvm); | 546 | typedef void (*on_lock_fn_t)(struct kvm *kvm); |
| 547 | typedef void (*on_unlock_fn_t)(struct kvm *kvm); | ||
| 548 | 547 | ||
| 549 | struct kvm_mmu_notifier_range { | 548 | struct kvm_mmu_notifier_range { |
| 550 | /* | 549 | /* |
| @@ -556,7 +555,6 @@ struct kvm_mmu_notifier_range { · 5 unmodified lines | |||
| 556 | union kvm_mmu_notifier_arg arg; | 555 | union kvm_mmu_notifier_arg arg; |
| 557 | gfn_handler_t handler; | 556 | gfn_handler_t handler; |
| 558 | on_lock_fn_t on_lock; | 557 | on_lock_fn_t on_lock; |
| 559 | on_unlock_fn_t on_unlock; | ||
| 560 | bool flush_on_ret; | 558 | bool flush_on_ret; |
| 561 | bool may_block; | 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 | if (range->flush_on_ret && r.ret) | 661 | if (range->flush_on_ret && r.ret) |
| 664 | kvm_flush_remote_tlbs(kvm); | 662 | kvm_flush_remote_tlbs(kvm); |
| 665 | 663 | ||
| 666 | if (r.found_memslot) { | 664 | if (r.found_memslot) |
| 667 | KVM_MMU_UNLOCK(kvm); | 665 | KVM_MMU_UNLOCK(kvm); |
| 668 | if (!IS_KVM_NULL_FN(range->on_unlock)) | ||
| 669 | range->on_unlock(kvm); | ||
| 670 | } | ||
| 671 | 666 | ||
| 672 | srcu_read_unlock(&kvm->srcu, idx); | 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 | .arg = arg, | 682 | .arg = arg, |
| 688 | .handler = handler, | 683 | .handler = handler, |
| 689 | .on_lock = (void *)kvm_null_fn, | 684 | .on_lock = (void *)kvm_null_fn, |
| 690 | .on_unlock = (void *)kvm_null_fn, | ||
| 691 | .flush_on_ret = true, | 685 | .flush_on_ret = true, |
| 692 | .may_block = false, | 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 | .end = end, | 700 | .end = end, |
| 707 | .handler = handler, | 701 | .handler = handler, |
| 708 | .on_lock = (void *)kvm_null_fn, | 702 | .on_lock = (void *)kvm_null_fn, |
| 709 | .on_unlock = (void *)kvm_null_fn, | ||
| 710 | .flush_on_ret = false, | 703 | .flush_on_ret = false, |
| 711 | .may_block = false, | 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 | .end = range->end, | 806 | .end = range->end, |
| 814 | .handler = kvm_mmu_unmap_gfn_range, | 807 | .handler = kvm_mmu_unmap_gfn_range, |
| 815 | .on_lock = kvm_mmu_invalidate_begin, | 808 | .on_lock = kvm_mmu_invalidate_begin, |
| 816 | .on_unlock = (void *)kvm_null_fn, | ||
| 817 | .flush_on_ret = true, | 809 | .flush_on_ret = true, |
| 818 | .may_block = mmu_notifier_range_blockable(range), | 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 | .end = range->end, | 883 | .end = range->end, |
| 892 | .handler = (void *)kvm_null_fn, | 884 | .handler = (void *)kvm_null_fn, |
| 893 | .on_lock = kvm_mmu_invalidate_end, | 885 | .on_lock = kvm_mmu_invalidate_end, |
| 894 | .on_unlock = (void *)kvm_null_fn, | ||
| 895 | .flush_on_ret = false, | 886 | .flush_on_ret = false, |
| 896 | .may_block = mmu_notifier_range_blockable(range), | 887 | .may_block = mmu_notifier_range_blockable(range), |
| 897 | }; | 888 | }; |