All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: Replace verify_mm_writelocked() by lockdep_assert_held_exclusive()
@ 2018-12-13 19:38 Waiman Long
  2018-12-13 19:40 ` Vlastimil Babka
  0 siblings, 1 reply; 2+ messages in thread
From: Waiman Long @ 2018-12-13 19:38 UTC (permalink / raw)
  To: Andrew Morton, Michal Hocko, Vlastimil Babka
  Cc: linux-mm, linux-kernel, Yang Shi, Waiman Long

Using down_read_trylock() to check if a task holds a write lock on
a rwsem is not reliable. A task can hold a read lock on a rwsem and
down_read_trylock() can fail if a writer is waiting in the wait queue.
So use lockdep_assert_held_exclusive() instead which can do the right
check when CONFIG_LOCKDEP is on.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 mm/mmap.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 6c04292..62a5593 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2962,16 +2962,6 @@ int vm_munmap(unsigned long start, size_t len)
 	return ret;
 }
 
-static inline void verify_mm_writelocked(struct mm_struct *mm)
-{
-#ifdef CONFIG_DEBUG_VM
-	if (unlikely(down_read_trylock(&mm->mmap_sem))) {
-		WARN_ON(1);
-		up_read(&mm->mmap_sem);
-	}
-#endif
-}
-
 /*
  *  this is really a simplified "do_mmap".  it only handles
  *  anonymous maps.  eventually we may be able to do some
@@ -3002,7 +2992,7 @@ static int do_brk_flags(unsigned long addr, unsigned long len, unsigned long fla
 	 * mm->mmap_sem is required to protect against another thread
 	 * changing the mappings in case we sleep.
 	 */
-	verify_mm_writelocked(mm);
+	lockdep_assert_held_exclusive(&mm->mmap_sem);
 
 	/*
 	 * Clear old maps.  this also does some error checking for us
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mm: Replace verify_mm_writelocked() by lockdep_assert_held_exclusive()
  2018-12-13 19:38 [PATCH] mm: Replace verify_mm_writelocked() by lockdep_assert_held_exclusive() Waiman Long
@ 2018-12-13 19:40 ` Vlastimil Babka
  0 siblings, 0 replies; 2+ messages in thread
From: Vlastimil Babka @ 2018-12-13 19:40 UTC (permalink / raw)
  To: Waiman Long, Andrew Morton, Michal Hocko; +Cc: linux-mm, linux-kernel, Yang Shi

On 12/13/18 8:38 PM, Waiman Long wrote:
> Using down_read_trylock() to check if a task holds a write lock on
> a rwsem is not reliable. A task can hold a read lock on a rwsem and
> down_read_trylock() can fail if a writer is waiting in the wait queue.
>
> So use lockdep_assert_held_exclusive() instead which can do the right
> check when CONFIG_LOCKDEP is on.
> 
> Signed-off-by: Waiman Long <longman@redhat.com>

There's already a patch in mmotm removing this completely:
https://www.ozlabs.org/~akpm/mmots/broken-out/mm-mmap-remove-verify_mm_writelocked.patch

Vlastimil

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-12-13 19:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-13 19:38 [PATCH] mm: Replace verify_mm_writelocked() by lockdep_assert_held_exclusive() Waiman Long
2018-12-13 19:40 ` Vlastimil Babka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.