Re: [RFC/PATCH] No get_user/put_user while holding mmap_sem in do_pages_stat?

Christoph Lameter
2008-12-09T14:29:55Z

I guess the simplest solution would be to move the taking of mmap_sem into
the loop. Mean taking mmap_sem for every page that we determine the status of.

Signed-off-by: Christoph Lameter <clameter@sgi.com>

Index: linux-2.6/mm/migrate.c
===================================================================
--- linux-2.6.orig/mm/migrate.c 2008-12-09 08:07:08.796603952 -0600
+++ linux-2.6/mm/migrate.c 2008-12-09 08:08:36.400116263 -0600
@@ -994,8 +994,6 @@
unsigned long i;
int err;

- down_read(&mm->mmap_sem);
-
for (i = 0; i < nr_pages; i++) {
const void __user *p;
unsigned long addr;
@@ -1007,12 +1005,17 @@
goto out;
addr = (unsigned long) p;

+ down_read(&mm->mmap_sem);
+
vma = find_vma(mm, addr);
- if (!vma)
+ if (!vma) {
+ up_read(&mm->mmap_sem);
goto set_status;
-
+ }
page = follow_page(vma, addr, 0);

+ up_read(&mm->mmap_sem);
+
err = PTR_ERR(page);
if (IS_ERR(page))
goto set_status;
@@ -1029,7 +1032,6 @@
err = 0;

out:
- up_read(&mm->mmap_sem);
return err;
}