diff mbox series

[SRU,O,1/3] UBUNTU: SAUCE: Revert "mm: use rwsem assertion macros for mmap_lock"

Message ID 20241210152352.877132-2-jacob.martin@canonical.com
State New
Headers show
Series Fix vfio_pci soft lockup on VM start while using PCIe passthrough | expand

Commit Message

Jacob Martin Dec. 10, 2024, 3:23 p.m. UTC
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(-)
diff mbox series

Patch

diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h
index de9dc20b01ba..8d38dcb6d044 100644
--- a/include/linux/mmap_lock.h
+++ b/include/linux/mmap_lock.h
@@ -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