linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* mm: use mmap_assert_write_locked() instead of open coding it
@ 2022-03-28  8:24 Rolf Eike Beer
  2022-03-29  6:36 ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Rolf Eike Beer @ 2022-03-28  8:24 UTC (permalink / raw)
  To: Andrew Morton, linux-mm, linux-kernel

In case the lock is actually not held at this point this also avoids a
stale lock reference if built with NDEBUG.

Signed-off-by: Rolf Eike Beer <eb@emlix.com>
---
 mm/mmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 3aa839f81e63..d62598dc2fdd 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -3561,7 +3561,7 @@ int mm_take_all_locks(struct mm_struct *mm)
 	struct vm_area_struct *vma;
 	struct anon_vma_chain *avc;
 
-	BUG_ON(mmap_read_trylock(mm));
+	mmap_assert_write_locked(mm);
 
 	mutex_lock(&mm_all_locks_mutex);
 
@@ -3641,7 +3641,7 @@ void mm_drop_all_locks(struct mm_struct *mm)
 	struct vm_area_struct *vma;
 	struct anon_vma_chain *avc;
 
-	BUG_ON(mmap_read_trylock(mm));
+	mmap_assert_write_locked(mm);
 	BUG_ON(!mutex_is_locked(&mm_all_locks_mutex));
 
 	for (vma = mm->mmap; vma; vma = vma->vm_next) {
-- 
2.35.1


-- 
Rolf Eike Beer, emlix GmbH, https://www.emlix.com
Fon +49 551 30664-0, Fax +49 551 30664-11
Gothaer Platz 3, 37083 Göttingen, Germany
Sitz der Gesellschaft: Göttingen, Amtsgericht Göttingen HR B 3160
Geschäftsführung: Heike Jordan, Dr. Uwe Kracke – Ust-IdNr.: DE 205 198 055

emlix - smart embedded open source




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

* Re: mm: use mmap_assert_write_locked() instead of open coding it
  2022-03-28  8:24 mm: use mmap_assert_write_locked() instead of open coding it Rolf Eike Beer
@ 2022-03-29  6:36 ` Christoph Hellwig
  2022-03-29  6:45   ` Rolf Eike Beer
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2022-03-29  6:36 UTC (permalink / raw)
  To: Rolf Eike Beer; +Cc: Andrew Morton, linux-mm, linux-kernel

On Mon, Mar 28, 2022 at 10:24:51AM +0200, Rolf Eike Beer wrote:
> In case the lock is actually not held at this point this also avoids a
> stale lock reference if built with NDEBUG.

The change looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

But I don't think NDEBUG is a thing in the kernel.


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

* Re: mm: use mmap_assert_write_locked() instead of open coding it
  2022-03-29  6:36 ` Christoph Hellwig
@ 2022-03-29  6:45   ` Rolf Eike Beer
  2022-04-01  2:32     ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Rolf Eike Beer @ 2022-03-29  6:45 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Andrew Morton, linux-mm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 907 bytes --]

Am Dienstag, 29. März 2022, 08:36:39 CEST schrieb Christoph Hellwig:
> On Mon, Mar 28, 2022 at 10:24:51AM +0200, Rolf Eike Beer wrote:
> > In case the lock is actually not held at this point this also avoids a
> > stale lock reference if built with NDEBUG.
> 
> The change looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 
> But I don't think NDEBUG is a thing in the kernel.

You are right, it was in tools/include/linux/kernel.h and I didn't spot the 
prefix. Andrew, maybe you could just delete the sentence when you add the 
Reviewed-by?

Eike
-- 
Rolf Eike Beer, emlix GmbH, https://www.emlix.com
Fon +49 551 30664-0, Fax +49 551 30664-11
Gothaer Platz 3, 37083 Göttingen, Germany
Sitz der Gesellschaft: Göttingen, Amtsgericht Göttingen HR B 3160
Geschäftsführung: Heike Jordan, Dr. Uwe Kracke – Ust-IdNr.: DE 205 198 055

emlix - smart embedded open source

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 313 bytes --]

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

* Re: mm: use mmap_assert_write_locked() instead of open coding it
  2022-03-29  6:45   ` Rolf Eike Beer
@ 2022-04-01  2:32     ` Andrew Morton
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2022-04-01  2:32 UTC (permalink / raw)
  To: Rolf Eike Beer; +Cc: Christoph Hellwig, linux-mm, linux-kernel

On Tue, 29 Mar 2022 08:45:37 +0200 Rolf Eike Beer <eb@emlix.com> wrote:

> You are right, it was in tools/include/linux/kernel.h and I didn't spot the 
> prefix. Andrew, maybe you could just delete the sentence when you add the 
> Reviewed-by?

Did that.  I used simply "In case the lock is actually not held at this
point."



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

end of thread, other threads:[~2022-04-01  2:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-28  8:24 mm: use mmap_assert_write_locked() instead of open coding it Rolf Eike Beer
2022-03-29  6:36 ` Christoph Hellwig
2022-03-29  6:45   ` Rolf Eike Beer
2022-04-01  2:32     ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox