lkml.org 
[lkml]   [2020]   [May]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v5.5 09/10] mmap locking API: add mmap_assert_locked() and mmap_assert_write_locked()
From
Date
On 4/24/20 3:38 AM, Michel Lespinasse wrote:
> Add new APIs to assert that mmap_sem is held.
>
> Using this instead of rwsem_is_locked and lockdep_assert_held[_write]
> makes the assertions more tolerant of future changes to the lock type.
>
> Signed-off-by: Michel Lespinasse <walken@google.com>
> ---
> arch/x86/events/core.c | 2 +-
> fs/userfaultfd.c | 6 +++---
> include/linux/mmap_lock.h | 14 ++++++++++++++
> mm/gup.c | 2 +-
> mm/hmm.c | 2 +-
> mm/memory.c | 2 +-
> mm/mmu_notifier.c | 6 +++---
> mm/pagewalk.c | 6 +++---
> mm/util.c | 2 +-
> 9 files changed, 28 insertions(+), 14 deletions(-)
>

...

> @@ -73,4 +75,16 @@ static inline void mmap_read_unlock_non_owner(struct mm_struct *mm)
> up_read_non_owner(&mm->mmap_sem);
> }
>
> +static inline void mmap_assert_locked(struct mm_struct *mm)
> +{
> + VM_BUG_ON_MM(!lockdep_is_held_type(&mm->mmap_sem, -1), mm);
> + VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm);
> +}
> +
> +static inline void mmap_assert_write_locked(struct mm_struct *mm)
> +{
> + VM_BUG_ON_MM(!lockdep_is_held_type(&mm->mmap_sem, 0), mm);
> + VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm);
> +}

I would remove VM_BUG_ON_MM() from the lockdep part. If kernel has lockdep
enabled, it's already in heavy debugging mode enough so let's just use it and
not depend on DEBUG_VM. Many sites you convert don't require DEBUG_VM for the
lockdep checks.

With that you can also use the standard lockdep_assert_held() and
lockdep_assert_held_write() wrappers.

If user has both lockdep and DEBUG_VM enabled, should we run both variants?
Perhaps lockdep is enough as it's more comprehensive? Your initial v5 version
was doing that.

\
 
 \ /
  Last update: 2020-05-18 13:02    [W:0.771 / U:0.628 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site