linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Michal Hocko <mhocko@suse.com>, Vlastimil Babka <vbabka@suse.cz>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Yang Shi <yang.shi@linux.alibaba.com>,
	Waiman Long <longman@redhat.com>
Subject: [PATCH] mm: Replace verify_mm_writelocked() by lockdep_assert_held_exclusive()
Date: Thu, 13 Dec 2018 14:38:05 -0500	[thread overview]
Message-ID: <1544729885-30702-1-git-send-email-longman@redhat.com> (raw)

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

             reply	other threads:[~2018-12-13 19:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-13 19:38 Waiman Long [this message]
2018-12-13 19:40 ` Vlastimil Babka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1544729885-30702-1-git-send-email-longman@redhat.com \
    --to=longman@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=vbabka@suse.cz \
    --cc=yang.shi@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox