@@ -60,14 +60,16 @@ static inline void __mmap_lock_trace_released(struct mm_struct *mm, bool write)
#endif /* CONFIG_TRACING */
-static inline void mmap_assert_locked(const struct mm_struct *mm)
+static inline void mmap_assert_locked(struct mm_struct *mm)
{
- rwsem_assert_held(&mm->mmap_lock);
+ lockdep_assert_held(&mm->mmap_lock);
+ VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_lock), mm);
}
-static inline void mmap_assert_write_locked(const struct mm_struct *mm)
+static inline void mmap_assert_write_locked(struct mm_struct *mm)
{
- rwsem_assert_held_write(&mm->mmap_lock);
+ lockdep_assert_held_write(&mm->mmap_lock);
+ VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_lock), mm);
}
#ifdef CONFIG_PER_VMA_LOCK
BugLink: https://bugs.launchpad.net/bugs/2089306 This reverts commit "mm: use rwsem assertion macros for mmap_lock". The original commit changes "mmap_assert_write_locked()" to be stricter when lockdep is disabled, checking explicitly for a held write lock. This is beneficial for catching errors, but it breaks a locking workaround used by vfio_pci, resulting in an unnecessary WARN_ON message. The erroneous WARN_ON message was resolved in vfio_pci by tracking mapped areas with the significantly slower "vmf_insert_pfn()" and "unmap_mapping_range()" functions. To restore the better performing vfio_pci fault handler, stop the WARN_ON message with this revert, allowing "vfio/pci: Use unmap_mapping_range()" and "vfio/pci: Insert full vma on mmap'd MMIO fault" to also be safely reverted. Signed-off-by: Jacob Martin <jacob.martin@canonical.com> --- include/linux/mmap_lock.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)