]> git.baikalelectronics.ru Git - kernel.git/commitdiff
goldish_pipe: convert to pin_user_pages() and put_user_page()
authorJohn Hubbard <jhubbard@nvidia.com>
Fri, 31 Jan 2020 06:12:58 +0000 (22:12 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 31 Jan 2020 18:30:37 +0000 (10:30 -0800)
1. Call the new global pin_user_pages_fast(), from
   pin_goldfish_pages().

2. As required by pin_user_pages(), release these pages via
   put_user_page().  In this case, do so via put_user_pages_dirty_lock().

That has the side effect of calling set_page_dirty_lock(), instead of
set_page_dirty().  This is probably more accurate.

As Christoph Hellwig put it, "set_page_dirty() is only safe if we are
dealing with a file backed page where we have reference on the inode it
hangs off." [1]

Another side effect is that the release code is simplified because the
page[] loop is now in gup.c instead of here, so just delete the local
release_user_pages() entirely, and call put_user_pages_dirty_lock()
directly, instead.

[1] https://lore.kernel.org/r/20190723153640.GB720@lst.de

Link: http://lkml.kernel.org/r/20200107224558.2362728-13-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Jan Kara <jack@suse.cz>
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: 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>
drivers/platform/goldfish/goldfish_pipe.c

index ef50c264db715c1b77a3602d0dc2db7cb29ec767..2a5901efecde48ed0a449fdff326534461b368eb 100644 (file)
@@ -274,7 +274,7 @@ static int goldfish_pin_pages(unsigned long first_page,
                *iter_last_page_size = last_page_size;
        }
 
-       ret = get_user_pages_fast(first_page, requested_pages,
+       ret = pin_user_pages_fast(first_page, requested_pages,
                                  !is_write ? FOLL_WRITE : 0,
                                  pages);
        if (ret <= 0)
@@ -285,18 +285,6 @@ static int goldfish_pin_pages(unsigned long first_page,
        return ret;
 }
 
-static void release_user_pages(struct page **pages, int pages_count,
-                              int is_write, s32 consumed_size)
-{
-       int i;
-
-       for (i = 0; i < pages_count; i++) {
-               if (!is_write && consumed_size > 0)
-                       set_page_dirty(pages[i]);
-               put_page(pages[i]);
-       }
-}
-
 /* Populate the call parameters, merging adjacent pages together */
 static void populate_rw_params(struct page **pages,
                               int pages_count,
@@ -372,7 +360,8 @@ static int transfer_max_buffers(struct goldfish_pipe *pipe,
 
        *consumed_size = pipe->command_buffer->rw_params.consumed_size;
 
-       release_user_pages(pipe->pages, pages_count, is_write, *consumed_size);
+       put_user_pages_dirty_lock(pipe->pages, pages_count,
+                                 !is_write && *consumed_size > 0);
 
        mutex_unlock(&pipe->lock);
        return 0;