Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/gup_benchmark: use proper FOLL_WRITE flags instead of hard-coding "1"

Fix the gup benchmark flags to use the symbolic FOLL_WRITE, instead of a
hard-coded "1" value.

Also, clean up the filtering of gup flags a little, by just doing it
once before issuing any of the get_user_pages*() calls. This makes it
harder to overlook, instead of having little "gup_flags & 1" phrases in
the function calls.

Link: http://lkml.kernel.org/r/20200107224558.2362728-22-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Björn Töpel <bjorn.topel@intel.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: Jan Kara <jack@suse.cz>
Cc: Jason Gunthorpe <jgg@mellanox.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Cc: Leon Romanovsky <leonro@mellanox.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

John Hubbard and committed by
Linus Torvalds
bdffe23e aa4b87fe

+11 -4
+6 -3
mm/gup_benchmark.c
··· 49 49 nr = (next - addr) / PAGE_SIZE; 50 50 } 51 51 52 + /* Filter out most gup flags: only allow a tiny subset here: */ 53 + gup->flags &= FOLL_WRITE; 54 + 52 55 switch (cmd) { 53 56 case GUP_FAST_BENCHMARK: 54 - nr = get_user_pages_fast(addr, nr, gup->flags & 1, 57 + nr = get_user_pages_fast(addr, nr, gup->flags, 55 58 pages + i); 56 59 break; 57 60 case GUP_LONGTERM_BENCHMARK: 58 61 nr = get_user_pages(addr, nr, 59 - (gup->flags & 1) | FOLL_LONGTERM, 62 + gup->flags | FOLL_LONGTERM, 60 63 pages + i, NULL); 61 64 break; 62 65 case GUP_BENCHMARK: 63 - nr = get_user_pages(addr, nr, gup->flags & 1, pages + i, 66 + nr = get_user_pages(addr, nr, gup->flags, pages + i, 64 67 NULL); 65 68 break; 66 69 default:
+5 -1
tools/testing/selftests/vm/gup_benchmark.c
··· 18 18 #define GUP_LONGTERM_BENCHMARK _IOWR('g', 2, struct gup_benchmark) 19 19 #define GUP_BENCHMARK _IOWR('g', 3, struct gup_benchmark) 20 20 21 + /* Just the flags we need, copied from mm.h: */ 22 + #define FOLL_WRITE 0x01 /* check pte is writable */ 23 + 21 24 struct gup_benchmark { 22 25 __u64 get_delta_usec; 23 26 __u64 put_delta_usec; ··· 88 85 } 89 86 90 87 gup.nr_pages_per_call = nr_pages; 91 - gup.flags = write; 88 + if (write) 89 + gup.flags |= FOLL_WRITE; 92 90 93 91 fd = open("/sys/kernel/debug/gup_benchmark", O_RDWR); 94 92 if (fd == -1)