[PATCH 1/3] mm: only assert mmap locks if CONFIG_DEBUG_VM or lockdep is set
From: Lorenzo Stoakes (ARM)
Date: Tue Nov 10 2026 - 12:09:08 EST
For a long while we have asserted the mmap lock being held regardless of
whether or not the kernel is a debug build or not.
In general, given that these have been added as programmatic asserts that
nobody did something stupid, production kernels are simply wasting their
time checking for this.
It also means there is a two tier system - where some programmatic
asserts (e.g. VM_WARN_ON_ONCE()-checked conditions) are only checked for if
CONFIG_DEBUG_VM is enabled, whereas others are checked unconditionally.
If we genuinely want to unconditionally check for the mmap lock being held
at runtime, then that should be made clear in the code doing it.
Regardless, if CONFIG_LOCKDEP is enabled, ensure that the lockdep
assertions are performed.
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
---
include/linux/mmap_lock.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h
index 9c3a9c6525c1..9367430ee53c 100644
--- a/include/linux/mmap_lock.h
+++ b/include/linux/mmap_lock.h
@@ -75,12 +75,14 @@ static inline void __mmap_lock_trace_released(struct mm_struct *mm, bool write)
static inline void mmap_assert_locked(const struct mm_struct *mm)
{
- rwsem_assert_held(&mm->mmap_lock);
+ if (IS_ENABLED(CONFIG_DEBUG_VM) || IS_ENABLED(CONFIG_LOCKDEP))
+ rwsem_assert_held(&mm->mmap_lock);
}
static inline void mmap_assert_write_locked(const struct mm_struct *mm)
{
- rwsem_assert_held_write(&mm->mmap_lock);
+ if (IS_ENABLED(CONFIG_DEBUG_VM) || IS_ENABLED(CONFIG_LOCKDEP))
+ rwsem_assert_held_write(&mm->mmap_lock);
}
#ifdef CONFIG_LOCKDEP
--
2.56.0