All of lore.kernel.org
 help / color / mirror / Atom feed
From: Edward AD <eadavis@sina.com>
To: oliver.sang@intel.com
Cc: akpm@linux-foundation.org, eadavis@sina.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org, lkp@intel.com,
	ltp@lists.linux.it, oe-lkp@lists.linux.dev,
	syzbot+b591856e0f0139f83023@syzkaller.appspotmail.com,
	syzkaller-bugs@googlegroups.com
Subject: [PATCH] mm: extpand queue_pages_range() to find and lock the vma range
Date: Thu, 14 Sep 2023 13:53:13 +0800	[thread overview]
Message-ID: <20230914055313.151192-1-eadavis@sina.com> (raw)
In-Reply-To: <202309121302.8864096c-oliver.sang@intel.com>

Using for_each_vma_range to find vmas, and not only inside locking, but also 
outside locking to ensure that vma_start_write are performed.

Reported-and-tested-by: syzbot+b591856e0f0139f83023@syzkaller.appspotmail.com
Signed-off-by: Edward AD <eadavis@sina.com>
---
 mm/pagewalk.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/mm/pagewalk.c b/mm/pagewalk.c
index b7d7e4fcfad7..b31d59a27f57 100644
--- a/mm/pagewalk.c
+++ b/mm/pagewalk.c
@@ -479,6 +479,7 @@ int walk_page_range(struct mm_struct *mm, unsigned long start,
 		.mm		= mm,
 		.private	= private,
 	};
+	struct vma_iterator vmi;
 
 	if (start >= end)
 		return -EINVAL;
@@ -488,8 +489,9 @@ int walk_page_range(struct mm_struct *mm, unsigned long start,
 
 	process_mm_walk_lock(walk.mm, ops->walk_lock);
 
-	vma = find_vma(walk.mm, start);
-	do {
+	vma_iter_init(&vmi, walk.mm, start);
+	for_each_vma_range(vmi, vma, end) {
+		process_vma_walk_lock(vma, ops->walk_lock);
 		if (!vma) { /* after the last vma */
 			walk.vma = NULL;
 			next = end;
@@ -501,10 +503,8 @@ int walk_page_range(struct mm_struct *mm, unsigned long start,
 			if (ops->pte_hole)
 				err = ops->pte_hole(start, next, -1, &walk);
 		} else { /* inside vma */
-			process_vma_walk_lock(vma, ops->walk_lock);
 			walk.vma = vma;
 			next = min(end, vma->vm_end);
-			vma = find_vma(mm, vma->vm_end);
 
 			err = walk_page_test(start, next, &walk);
 			if (err > 0) {
@@ -522,7 +522,7 @@ int walk_page_range(struct mm_struct *mm, unsigned long start,
 		}
 		if (err)
 			break;
-	} while (start = next, start < end);
+	};
 	return err;
 }
 
-- 
2.25.1


WARNING: multiple messages have this Message-ID (diff)
From: Edward AD <eadavis@sina.com>
To: oliver.sang@intel.com
Cc: syzbot+b591856e0f0139f83023@syzkaller.appspotmail.com,
	lkp@intel.com, syzkaller-bugs@googlegroups.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	oe-lkp@lists.linux.dev, akpm@linux-foundation.org,
	ltp@lists.linux.it, eadavis@sina.com
Subject: [LTP] [PATCH] mm: extpand queue_pages_range() to find and lock the vma range
Date: Thu, 14 Sep 2023 13:53:13 +0800	[thread overview]
Message-ID: <20230914055313.151192-1-eadavis@sina.com> (raw)
In-Reply-To: <202309121302.8864096c-oliver.sang@intel.com>

Using for_each_vma_range to find vmas, and not only inside locking, but also 
outside locking to ensure that vma_start_write are performed.

Reported-and-tested-by: syzbot+b591856e0f0139f83023@syzkaller.appspotmail.com
Signed-off-by: Edward AD <eadavis@sina.com>
---
 mm/pagewalk.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/mm/pagewalk.c b/mm/pagewalk.c
index b7d7e4fcfad7..b31d59a27f57 100644
--- a/mm/pagewalk.c
+++ b/mm/pagewalk.c
@@ -479,6 +479,7 @@ int walk_page_range(struct mm_struct *mm, unsigned long start,
 		.mm		= mm,
 		.private	= private,
 	};
+	struct vma_iterator vmi;
 
 	if (start >= end)
 		return -EINVAL;
@@ -488,8 +489,9 @@ int walk_page_range(struct mm_struct *mm, unsigned long start,
 
 	process_mm_walk_lock(walk.mm, ops->walk_lock);
 
-	vma = find_vma(walk.mm, start);
-	do {
+	vma_iter_init(&vmi, walk.mm, start);
+	for_each_vma_range(vmi, vma, end) {
+		process_vma_walk_lock(vma, ops->walk_lock);
 		if (!vma) { /* after the last vma */
 			walk.vma = NULL;
 			next = end;
@@ -501,10 +503,8 @@ int walk_page_range(struct mm_struct *mm, unsigned long start,
 			if (ops->pte_hole)
 				err = ops->pte_hole(start, next, -1, &walk);
 		} else { /* inside vma */
-			process_vma_walk_lock(vma, ops->walk_lock);
 			walk.vma = vma;
 			next = min(end, vma->vm_end);
-			vma = find_vma(mm, vma->vm_end);
 
 			err = walk_page_test(start, next, &walk);
 			if (err > 0) {
@@ -522,7 +522,7 @@ int walk_page_range(struct mm_struct *mm, unsigned long start,
 		}
 		if (err)
 			break;
-	} while (start = next, start < end);
+	};
 	return err;
 }
 
-- 
2.25.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2023-09-14  5:58 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-06  1:03 [syzbot] [mm?] kernel BUG in vma_replace_policy syzbot
2023-09-06  6:19 ` [PATCH] mm: as the same logic with queue_pages_range Edward AD
2023-09-06 12:06   ` Matthew Wilcox
2023-09-12  5:20   ` kernel test robot
2023-09-12  5:20     ` [LTP] " kernel test robot
2023-09-13  9:10     ` Cyril Hrubis
2023-09-13  9:10       ` Cyril Hrubis
2023-09-14  5:53     ` Edward AD [this message]
2023-09-14  5:53       ` [LTP] [PATCH] mm: extpand queue_pages_range() to find and lock the vma range Edward AD
2023-09-08 18:04 ` [syzbot] [mm?] kernel BUG in vma_replace_policy syzbot
2023-09-08 18:04   ` syzbot
2023-09-08 18:04   ` syzbot
2023-09-12  5:30 ` Matthew Wilcox
2023-09-12  6:09   ` syzbot
2023-09-12 14:55   ` Matthew Wilcox
2023-09-12 15:03     ` Suren Baghdasaryan
2023-09-12 16:00       ` Suren Baghdasaryan
2023-09-13 16:05         ` Suren Baghdasaryan
2023-09-13 16:46           ` Suren Baghdasaryan
2023-09-14 18:20             ` Suren Baghdasaryan
2023-09-14 19:09               ` Matthew Wilcox
2023-09-14 20:00                 ` Suren Baghdasaryan
2023-09-14 20:53                   ` Suren Baghdasaryan
2023-09-14 21:24                     ` Matthew Wilcox
2023-09-14 22:21                       ` Suren Baghdasaryan
2023-09-15  4:26                         ` Hugh Dickins
2023-09-15 16:09                           ` Suren Baghdasaryan
2023-09-15 18:05                             ` Suren Baghdasaryan
2023-09-16  2:43                               ` Hugh Dickins
2023-09-18 21:20                                 ` Suren Baghdasaryan
2023-09-15 18:26                           ` Matthew Wilcox
2023-09-16  2:54                             ` Hugh Dickins
2023-09-16  1:35                           ` Yang Shi
2023-09-16  3:57                             ` Hugh Dickins
2023-09-18 22:34                               ` Yang Shi
2023-09-19  0:34                                 ` Hugh Dickins

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=20230914055313.151192-1-eadavis@sina.com \
    --to=eadavis@sina.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lkp@intel.com \
    --cc=ltp@lists.linux.it \
    --cc=oe-lkp@lists.linux.dev \
    --cc=oliver.sang@intel.com \
    --cc=syzbot+b591856e0f0139f83023@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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 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.