diff mbox series

[3/3] pagewalk: use lockdep_assert_held for locking validation

Message ID 20190808154240.9384-4-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [1/3] mm: split out a new pagewalk.h header from mm.h | expand

Commit Message

Christoph Hellwig Aug. 8, 2019, 3:42 p.m. UTC
Use lockdep to check for held locks instead of using home grown
asserts.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 mm/pagewalk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Matthew Wilcox Aug. 8, 2019, 6:18 p.m. UTC | #1
On Thu, Aug 08, 2019 at 06:42:40PM +0300, Christoph Hellwig wrote:
> Use lockdep to check for held locks instead of using home grown
> asserts.
> 
> @@ -319,7 +319,7 @@ int walk_page_range(struct mm_struct *mm, unsigned long start,
>  	if (!walk.mm)
>  		return -EINVAL;
>  
> -	VM_BUG_ON_MM(!rwsem_is_locked(&walk.mm->mmap_sem), walk.mm);
> +	lockdep_assert_held(&walk.mm->mmap_sem);

It occurs to me that this is exactly the pattern that lockdep_pin_lock()
was designed for.  I'm pretty sure things will go badly if any callee
unlocks then relocks the lock.
diff mbox series

Patch

diff --git a/mm/pagewalk.c b/mm/pagewalk.c
index 28510fc0dde1..9ec1885ceed7 100644
--- a/mm/pagewalk.c
+++ b/mm/pagewalk.c
@@ -319,7 +319,7 @@  int walk_page_range(struct mm_struct *mm, unsigned long start,
 	if (!walk.mm)
 		return -EINVAL;
 
-	VM_BUG_ON_MM(!rwsem_is_locked(&walk.mm->mmap_sem), walk.mm);
+	lockdep_assert_held(&walk.mm->mmap_sem);
 
 	vma = find_vma(walk.mm, start);
 	do {
@@ -369,7 +369,7 @@  int walk_page_vma(struct vm_area_struct *vma, const struct mm_walk_ops *ops,
 	if (!walk.mm)
 		return -EINVAL;
 
-	VM_BUG_ON(!rwsem_is_locked(&vma->vm_mm->mmap_sem));
+	lockdep_assert_held(&walk.mm->mmap_sem);
 
 	err = walk_page_test(vma->vm_start, vma->vm_end, &walk);
 	if (err > 0)