Merge tag 'linux-watchdog-5.10-rc1' of git://www.linux-watchdog.org/linux-watchdog
[linux-2.6-microblaze.git] / mm / gup_benchmark.c
index be690fa..8b3e5b5 100644 (file)
@@ -6,10 +6,10 @@
 #include <linux/debugfs.h>
 
 #define GUP_FAST_BENCHMARK     _IOWR('g', 1, struct gup_benchmark)
-#define GUP_LONGTERM_BENCHMARK _IOWR('g', 2, struct gup_benchmark)
-#define GUP_BENCHMARK          _IOWR('g', 3, struct gup_benchmark)
-#define PIN_FAST_BENCHMARK     _IOWR('g', 4, struct gup_benchmark)
-#define PIN_BENCHMARK          _IOWR('g', 5, struct gup_benchmark)
+#define GUP_BENCHMARK          _IOWR('g', 2, struct gup_benchmark)
+#define PIN_FAST_BENCHMARK     _IOWR('g', 3, struct gup_benchmark)
+#define PIN_BENCHMARK          _IOWR('g', 4, struct gup_benchmark)
+#define PIN_LONGTERM_BENCHMARK _IOWR('g', 5, struct gup_benchmark)
 
 struct gup_benchmark {
        __u64 get_delta_usec;
@@ -28,7 +28,6 @@ static void put_back_pages(unsigned int cmd, struct page **pages,
 
        switch (cmd) {
        case GUP_FAST_BENCHMARK:
-       case GUP_LONGTERM_BENCHMARK:
        case GUP_BENCHMARK:
                for (i = 0; i < nr_pages; i++)
                        put_page(pages[i]);
@@ -36,6 +35,7 @@ static void put_back_pages(unsigned int cmd, struct page **pages,
 
        case PIN_FAST_BENCHMARK:
        case PIN_BENCHMARK:
+       case PIN_LONGTERM_BENCHMARK:
                unpin_user_pages(pages, nr_pages);
                break;
        }
@@ -50,6 +50,7 @@ static void verify_dma_pinned(unsigned int cmd, struct page **pages,
        switch (cmd) {
        case PIN_FAST_BENCHMARK:
        case PIN_BENCHMARK:
+       case PIN_LONGTERM_BENCHMARK:
                for (i = 0; i < nr_pages; i++) {
                        page = pages[i];
                        if (WARN(!page_maybe_dma_pinned(page),
@@ -71,6 +72,8 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
        int nr;
        struct page **pages;
        int ret = 0;
+       bool needs_mmap_lock =
+               cmd != GUP_FAST_BENCHMARK && cmd != PIN_FAST_BENCHMARK;
 
        if (gup->size > ULONG_MAX)
                return -EINVAL;
@@ -80,6 +83,11 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
        if (!pages)
                return -ENOMEM;
 
+       if (needs_mmap_lock && mmap_read_lock_killable(current->mm)) {
+               ret = -EINTR;
+               goto free_pages;
+       }
+
        i = 0;
        nr = gup->nr_pages_per_call;
        start_time = ktime_get();
@@ -101,11 +109,6 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
                        nr = get_user_pages_fast(addr, nr, gup->flags,
                                                 pages + i);
                        break;
-               case GUP_LONGTERM_BENCHMARK:
-                       nr = get_user_pages(addr, nr,
-                                           gup->flags | FOLL_LONGTERM,
-                                           pages + i, NULL);
-                       break;
                case GUP_BENCHMARK:
                        nr = get_user_pages(addr, nr, gup->flags, pages + i,
                                            NULL);
@@ -118,10 +121,14 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
                        nr = pin_user_pages(addr, nr, gup->flags, pages + i,
                                            NULL);
                        break;
+               case PIN_LONGTERM_BENCHMARK:
+                       nr = pin_user_pages(addr, nr,
+                                           gup->flags | FOLL_LONGTERM,
+                                           pages + i, NULL);
+                       break;
                default:
-                       kvfree(pages);
                        ret = -EINVAL;
-                       goto out;
+                       goto unlock;
                }
 
                if (nr <= 0)
@@ -149,8 +156,11 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
        end_time = ktime_get();
        gup->put_delta_usec = ktime_us_delta(end_time, start_time);
 
+unlock:
+       if (needs_mmap_lock)
+               mmap_read_unlock(current->mm);
+free_pages:
        kvfree(pages);
-out:
        return ret;
 }
 
@@ -162,10 +172,10 @@ static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd,
 
        switch (cmd) {
        case GUP_FAST_BENCHMARK:
-       case GUP_LONGTERM_BENCHMARK:
        case GUP_BENCHMARK:
        case PIN_FAST_BENCHMARK:
        case PIN_BENCHMARK:
+       case PIN_LONGTERM_BENCHMARK:
                break;
        default:
                return -EINVAL;