From patchwork Tue Jul 30 20:57:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john.hubbard@gmail.com X-Patchwork-Id: 11066805 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 05B96912 for ; Tue, 30 Jul 2019 20:57:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7FC41FF14 for ; Tue, 30 Jul 2019 20:57:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB571284C5; Tue, 30 Jul 2019 20:57:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD5241FF14 for ; Tue, 30 Jul 2019 20:57:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D402B8E0005; Tue, 30 Jul 2019 16:57:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C547C8E0001; Tue, 30 Jul 2019 16:57:11 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7EAB8E0005; Tue, 30 Jul 2019 16:57:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 6F01D8E0001 for ; Tue, 30 Jul 2019 16:57:11 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id t19so41334184pgh.6 for ; Tue, 30 Jul 2019 13:57:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=qVOEtC+FJUT8up8TCOoMm5YvZPMSmdk5e2B42ED2yyM=; b=Dmf3Z2cYl0AmjHJSawUfU1gXY0ZAUs0MKc3Aua+jHvVgexJooaprDgy6WApbbQoIqV 2OHVYR+Iz4czwO4pxjmLVpYLBgy49ms7bck+JZzNlp5f1kSSQ1mBafaALd9lEAv9x1Fc c7NG6uJMywssSlMboas9yv7KSq7dcTWXC904o/gXB/2nNH5b1wTAZQ0oxhXiEgyhr36W dUvwCRrX4FLLm02zuN00WEw+uMnnPwkgvZq42AAzO8zrCCAnc4qMWfKYw2yDgv7q6TxW XNVc4FKY6mzw/F7lRSMLVffynKGP0EXlFLNcQOonfWIqlWzHEw3dqIroEETbYsoXvcRW opGA== X-Gm-Message-State: APjAAAXgQ6wTL5U2ekFRRuG+6tvCtmi8cEUvenYW6NOsrWd8ZieSrWug LTfDkZi5AvxtRcG6e5/lA1VpL8WVOo4HK2Pas9S/bWaVY+fhxo8MECjE5oP8kZovNvboDO8t6/M F9o0mUxBX5yJ39Qdt5PkYSfOSNs4iSudmVcnn8rsXMm4QTZfIw94brLfIq/21um1gEw== X-Received: by 2002:a63:101b:: with SMTP id f27mr106498971pgl.291.1564520230967; Tue, 30 Jul 2019 13:57:10 -0700 (PDT) X-Received: by 2002:a63:101b:: with SMTP id f27mr106498937pgl.291.1564520230057; Tue, 30 Jul 2019 13:57:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564520230; cv=none; d=google.com; s=arc-20160816; b=E34Db8xukKQvahokiaeySuD5zQ8cPYcoJHOK9vE8jKwFTuFMY8sZIOovlueBp6Zp26 z9PuLy4KKynWp6wU+prY4BamE4lmy+2UjlTADZjYZEENjCb4BoqR1frERjblJilshFMB fd+3K9V/XgDuuiVDv9oNabDrLjTlOLnIKzNE+Wy3tgGd3k5IH+2fY9yoY94R11LrOmxc 95sEHwnb8J3tU1NODa47w9fIWOji7DviYUoygBfLpBq3h+H1hP2FzZEQFCBqu8Q00LwU DfVLWkplqvKJ5JT6WDPNJOuTpnbAZ61/rDdvODswztBFvAMaFGJiWOfanV/WQ1JYcwtw i5Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=qVOEtC+FJUT8up8TCOoMm5YvZPMSmdk5e2B42ED2yyM=; b=yMdKWRZ6JFsN0vuUI6Z3M9sJU38U+6sv3s01Z/1hExQuWndu2DsK18f+WhlfQLesVm v9bwhpBYBuVZztnPMaaacvN1VDeh+Drsu8UV0huITQoSVpUuHFnf1kyuyBfGbBXu9pHU 3atNx83GPgOkHVcaCy40qUZo3STQM+SWliAX/I93Mfuv4bnu+j5Lxd7O1sHTpIo4iMZn zuzPc58cFU5tjsTjAPEFQJuXjyALoPxFXvOSc2OdvkuSmAe40h4qwd4qqnR2k566s5rL /xyIa8L1bCs7PWsaE2ORm5bvNgYV7dSS/TZEb1teFanNA0HCg+gdEeVd5kHBWHEZDB5x hq8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vOKoqRCX; spf=pass (google.com: domain of john.hubbard@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.hubbard@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 142sor43130327pge.7.2019.07.30.13.57.09 for (Google Transport Security); Tue, 30 Jul 2019 13:57:10 -0700 (PDT) Received-SPF: pass (google.com: domain of john.hubbard@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vOKoqRCX; spf=pass (google.com: domain of john.hubbard@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.hubbard@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qVOEtC+FJUT8up8TCOoMm5YvZPMSmdk5e2B42ED2yyM=; b=vOKoqRCXkRksLkHF8e/bQJkY0W69YGeddm/Oefo3c+6nmDlnov4NDL6lpLQaes3vmC 6xdHnC73e8FR7AXBX4ah7GYsYuh8zAapmTLDSCYzXg5WkOhQ2VurxI3aboVhdxEFGO+a GBexzCjCwmv1brgG8gHRvtTZ8vnItUCeyW9Phzx0mCebkzCBUG+Qly/sYpPGf+/F3LFI JE6qFuiiMzDFQWTJDjE0oANYY9b7RO4L7D8ngM0UilW8viFLkdz0v4RtODWeMVZQBlsv JXMCPPGLsJvYb1wDTBl0hdSVZwONqWccDrols1BK6xq0kkxkA4braahq0YvlKJOQVLO2 yOFA== X-Google-Smtp-Source: APXvYqxv3i/Zxbh0PKRmchj5zJB09g94vbXYfWpGhGD8lt1BUSO+tmjzN4TsYdbs73nUtD6BRW+KgQ== X-Received: by 2002:a63:a302:: with SMTP id s2mr5085413pge.125.1564520229687; Tue, 30 Jul 2019 13:57:09 -0700 (PDT) Received: from blueforge.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id 137sm80565678pfz.112.2019.07.30.13.57.08 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 30 Jul 2019 13:57:09 -0700 (PDT) From: john.hubbard@gmail.com X-Google-Original-From: jhubbard@nvidia.com To: Andrew Morton Cc: Al Viro , Christian Benvenuti , Christoph Hellwig , Dan Williams , "Darrick J . Wong" , Dave Chinner , Ira Weiny , Jan Kara , Jason Gunthorpe , Jens Axboe , Jerome Glisse , "Kirill A . Shutemov" , Matthew Wilcox , Michal Hocko , Mike Marciniszyn , Mike Rapoport , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, LKML , John Hubbard , Christoph Hellwig Subject: [PATCH v4 1/3] mm/gup: add make_dirty arg to put_user_pages_dirty_lock() Date: Tue, 30 Jul 2019 13:57:03 -0700 Message-Id: <20190730205705.9018-2-jhubbard@nvidia.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190730205705.9018-1-jhubbard@nvidia.com> References: <20190730205705.9018-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: John Hubbard Provide more capable variation of put_user_pages_dirty_lock(), and delete put_user_pages_dirty(). This is based on the following: 1. Lots of call sites become simpler if a bool is passed into put_user_page*(), instead of making the call site choose which put_user_page*() variant to call. 2. Christoph Hellwig's observation that set_page_dirty_lock() is usually correct, and set_page_dirty() is usually a bug, or at least questionable, within a put_user_page*() calling chain. This leads to the following API choices: * put_user_pages_dirty_lock(page, npages, make_dirty) * There is no put_user_pages_dirty(). You have to hand code that, in the rare case that it's required. Cc: Matthew Wilcox Cc: Jan Kara Cc: Christoph Hellwig Cc: Ira Weiny Cc: Jason Gunthorpe Signed-off-by: John Hubbard --- drivers/infiniband/core/umem.c | 5 +- drivers/infiniband/hw/hfi1/user_pages.c | 5 +- drivers/infiniband/hw/qib/qib_user_pages.c | 5 +- drivers/infiniband/hw/usnic/usnic_uiom.c | 5 +- drivers/infiniband/sw/siw/siw_mem.c | 10 +- include/linux/mm.h | 5 +- mm/gup.c | 115 +++++++++------------ 7 files changed, 58 insertions(+), 92 deletions(-) diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c index 08da840ed7ee..965cf9dea71a 100644 --- a/drivers/infiniband/core/umem.c +++ b/drivers/infiniband/core/umem.c @@ -54,10 +54,7 @@ static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int d for_each_sg_page(umem->sg_head.sgl, &sg_iter, umem->sg_nents, 0) { page = sg_page_iter_page(&sg_iter); - if (umem->writable && dirty) - put_user_pages_dirty_lock(&page, 1); - else - put_user_page(page); + put_user_pages_dirty_lock(&page, 1, umem->writable && dirty); } sg_free_table(&umem->sg_head); diff --git a/drivers/infiniband/hw/hfi1/user_pages.c b/drivers/infiniband/hw/hfi1/user_pages.c index b89a9b9aef7a..469acb961fbd 100644 --- a/drivers/infiniband/hw/hfi1/user_pages.c +++ b/drivers/infiniband/hw/hfi1/user_pages.c @@ -118,10 +118,7 @@ int hfi1_acquire_user_pages(struct mm_struct *mm, unsigned long vaddr, size_t np void hfi1_release_user_pages(struct mm_struct *mm, struct page **p, size_t npages, bool dirty) { - if (dirty) - put_user_pages_dirty_lock(p, npages); - else - put_user_pages(p, npages); + put_user_pages_dirty_lock(p, npages, dirty); if (mm) { /* during close after signal, mm can be NULL */ atomic64_sub(npages, &mm->pinned_vm); diff --git a/drivers/infiniband/hw/qib/qib_user_pages.c b/drivers/infiniband/hw/qib/qib_user_pages.c index bfbfbb7e0ff4..6bf764e41891 100644 --- a/drivers/infiniband/hw/qib/qib_user_pages.c +++ b/drivers/infiniband/hw/qib/qib_user_pages.c @@ -40,10 +40,7 @@ static void __qib_release_user_pages(struct page **p, size_t num_pages, int dirty) { - if (dirty) - put_user_pages_dirty_lock(p, num_pages); - else - put_user_pages(p, num_pages); + put_user_pages_dirty_lock(p, num_pages, dirty); } /** diff --git a/drivers/infiniband/hw/usnic/usnic_uiom.c b/drivers/infiniband/hw/usnic/usnic_uiom.c index 0b0237d41613..62e6ffa9ad78 100644 --- a/drivers/infiniband/hw/usnic/usnic_uiom.c +++ b/drivers/infiniband/hw/usnic/usnic_uiom.c @@ -75,10 +75,7 @@ static void usnic_uiom_put_pages(struct list_head *chunk_list, int dirty) for_each_sg(chunk->page_list, sg, chunk->nents, i) { page = sg_page(sg); pa = sg_phys(sg); - if (dirty) - put_user_pages_dirty_lock(&page, 1); - else - put_user_page(page); + put_user_pages_dirty_lock(&page, 1, dirty); usnic_dbg("pa: %pa\n", &pa); } kfree(chunk); diff --git a/drivers/infiniband/sw/siw/siw_mem.c b/drivers/infiniband/sw/siw/siw_mem.c index 67171c82b0c4..ab83a9cec562 100644 --- a/drivers/infiniband/sw/siw/siw_mem.c +++ b/drivers/infiniband/sw/siw/siw_mem.c @@ -63,15 +63,7 @@ struct siw_mem *siw_mem_id2obj(struct siw_device *sdev, int stag_index) static void siw_free_plist(struct siw_page_chunk *chunk, int num_pages, bool dirty) { - struct page **p = chunk->plist; - - while (num_pages--) { - if (!PageDirty(*p) && dirty) - put_user_pages_dirty_lock(p, 1); - else - put_user_page(*p); - p++; - } + put_user_pages_dirty_lock(chunk->plist, num_pages, dirty); } void siw_umem_release(struct siw_umem *umem, bool dirty) diff --git a/include/linux/mm.h b/include/linux/mm.h index 0334ca97c584..9759b6a24420 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1057,8 +1057,9 @@ static inline void put_user_page(struct page *page) put_page(page); } -void put_user_pages_dirty(struct page **pages, unsigned long npages); -void put_user_pages_dirty_lock(struct page **pages, unsigned long npages); +void put_user_pages_dirty_lock(struct page **pages, unsigned long npages, + bool make_dirty); + void put_user_pages(struct page **pages, unsigned long npages); #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP) diff --git a/mm/gup.c b/mm/gup.c index 98f13ab37bac..7fefd7ab02c4 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -29,85 +29,70 @@ struct follow_page_context { unsigned int page_mask; }; -typedef int (*set_dirty_func_t)(struct page *page); - -static void __put_user_pages_dirty(struct page **pages, - unsigned long npages, - set_dirty_func_t sdf) -{ - unsigned long index; - - for (index = 0; index < npages; index++) { - struct page *page = compound_head(pages[index]); - - /* - * Checking PageDirty at this point may race with - * clear_page_dirty_for_io(), but that's OK. Two key cases: - * - * 1) This code sees the page as already dirty, so it skips - * the call to sdf(). That could happen because - * clear_page_dirty_for_io() called page_mkclean(), - * followed by set_page_dirty(). However, now the page is - * going to get written back, which meets the original - * intention of setting it dirty, so all is well: - * clear_page_dirty_for_io() goes on to call - * TestClearPageDirty(), and write the page back. - * - * 2) This code sees the page as clean, so it calls sdf(). - * The page stays dirty, despite being written back, so it - * gets written back again in the next writeback cycle. - * This is harmless. - */ - if (!PageDirty(page)) - sdf(page); - - put_user_page(page); - } -} - /** - * put_user_pages_dirty() - release and dirty an array of gup-pinned pages - * @pages: array of pages to be marked dirty and released. + * put_user_pages_dirty_lock() - release and optionally dirty gup-pinned pages + * @pages: array of pages to be maybe marked dirty, and definitely released. * @npages: number of pages in the @pages array. + * @make_dirty: whether to mark the pages dirty * * "gup-pinned page" refers to a page that has had one of the get_user_pages() * variants called on that page. * * For each page in the @pages array, make that page (or its head page, if a - * compound page) dirty, if it was previously listed as clean. Then, release - * the page using put_user_page(). + * compound page) dirty, if @make_dirty is true, and if the page was previously + * listed as clean. In any case, releases all pages using put_user_page(), + * possibly via put_user_pages(), for the non-dirty case. * * Please see the put_user_page() documentation for details. * - * set_page_dirty(), which does not lock the page, is used here. - * Therefore, it is the caller's responsibility to ensure that this is - * safe. If not, then put_user_pages_dirty_lock() should be called instead. + * set_page_dirty_lock() is used internally. If instead, set_page_dirty() is + * required, then the caller should a) verify that this is really correct, + * because _lock() is usually required, and b) hand code it: + * set_page_dirty_lock(), put_user_page(). * */ -void put_user_pages_dirty(struct page **pages, unsigned long npages) +void put_user_pages_dirty_lock(struct page **pages, unsigned long npages, + bool make_dirty) { - __put_user_pages_dirty(pages, npages, set_page_dirty); -} -EXPORT_SYMBOL(put_user_pages_dirty); + unsigned long index; -/** - * put_user_pages_dirty_lock() - release and dirty an array of gup-pinned pages - * @pages: array of pages to be marked dirty and released. - * @npages: number of pages in the @pages array. - * - * For each page in the @pages array, make that page (or its head page, if a - * compound page) dirty, if it was previously listed as clean. Then, release - * the page using put_user_page(). - * - * Please see the put_user_page() documentation for details. - * - * This is just like put_user_pages_dirty(), except that it invokes - * set_page_dirty_lock(), instead of set_page_dirty(). - * - */ -void put_user_pages_dirty_lock(struct page **pages, unsigned long npages) -{ - __put_user_pages_dirty(pages, npages, set_page_dirty_lock); + /* + * TODO: this can be optimized for huge pages: if a series of pages is + * physically contiguous and part of the same compound page, then a + * single operation to the head page should suffice. + */ + + if (!make_dirty) { + put_user_pages(pages, npages); + return; + } + + for (index = 0; index < npages; index++) { + struct page *page = compound_head(pages[index]); + /* + * Checking PageDirty at this point may race with + * clear_page_dirty_for_io(), but that's OK. Two key + * cases: + * + * 1) This code sees the page as already dirty, so it + * skips the call to set_page_dirty(). That could happen + * because clear_page_dirty_for_io() called + * page_mkclean(), followed by set_page_dirty(). + * However, now the page is going to get written back, + * which meets the original intention of setting it + * dirty, so all is well: clear_page_dirty_for_io() goes + * on to call TestClearPageDirty(), and write the page + * back. + * + * 2) This code sees the page as clean, so it calls + * set_page_dirty(). The page stays dirty, despite being + * written back, so it gets written back again in the + * next writeback cycle. This is harmless. + */ + if (!PageDirty(page)) + set_page_dirty_lock(page); + put_user_page(page); + } } EXPORT_SYMBOL(put_user_pages_dirty_lock); From patchwork Tue Jul 30 20:57:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john.hubbard@gmail.com X-Patchwork-Id: 11066807 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9765013A0 for ; Tue, 30 Jul 2019 20:57:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8933D1FF14 for ; Tue, 30 Jul 2019 20:57:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C8B7284C5; Tue, 30 Jul 2019 20:57:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17EAC1FF14 for ; Tue, 30 Jul 2019 20:57:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CCDF38E0006; Tue, 30 Jul 2019 16:57:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C06BE8E0001; Tue, 30 Jul 2019 16:57:12 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BD0F8E0006; Tue, 30 Jul 2019 16:57:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id 65B8F8E0001 for ; Tue, 30 Jul 2019 16:57:12 -0400 (EDT) Received: by mail-pf1-f200.google.com with SMTP id q14so41641145pff.8 for ; Tue, 30 Jul 2019 13:57:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=SsIRGkPWeq5HvTZzTxF/TGZYHjIKFiRIBMhKcsnvtic=; b=Dyq+ph1J23s2I/sw5y7E/GkVVMbF9RUjpeDbF1CtDTUen2Ibic5hA5kEl18qzfr2n7 GnmQ3H622QfQP8U5G4a7Ahmt9s7bCLSvHiMCt6+iLJtghtEH0xItJM/A62j0hBmuZifN ezwDxcoHWyQJHogvr/sjZ7cFKH6iiRSt4Wv1i02AMmWIqUc/sEVngYLWxGBAcZJOTadJ LXCfJRcMnV38KlfFYSx8nE5QpRc8HEcCzsE3hZbC7sE60TxuMjE1i3D7IumtVTlKWlU0 mKU2C/VZmNRSo/moF/j6iCgz7xgF7/MLDa8y/BuN8UYloZhsPwpmQZ3FQ8a4daGKzNsB iD7A== X-Gm-Message-State: APjAAAXLidN5JSLBZZmL9X5Ow2CgE5F3jBhSRujg4hix3zw/Pnk/TjmA 5WtqOfH/8EM9CLME8aplnjAullIDgZKWnqoRy5RnU5xR2WtFTIXldvTwuSyZhsRmSm76QDNTY4N lLfO/qcP+Emjq9D9o+NfSY5RulcuU5axSH3EiasWL9x3G4TPn362lTco5SOdjiijKAg== X-Received: by 2002:a17:902:a504:: with SMTP id s4mr93922492plq.117.1564520232016; Tue, 30 Jul 2019 13:57:12 -0700 (PDT) X-Received: by 2002:a17:902:a504:: with SMTP id s4mr93922471plq.117.1564520231304; Tue, 30 Jul 2019 13:57:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564520231; cv=none; d=google.com; s=arc-20160816; b=OhFHwt5gPkz/hpZvc0XTkcNBu0mXCl/UAPvfPdM9vhHMHcoDpy1Z7fwRlV64po0Otx jAle340C4vV6OFZGDM/tH+2Kjfb16SDsQN7oIn9wWRdZNuinMeV2QWvy8DSLv+eB8eqN EvsZAhSf5AtTXE2DrqDvhZzPElcnny6FIZff2CFuKy6PwmKnZ/tG8Z130bHyy5HEilyY xhReBU8wlZGiqRD/rbO+IMyS1GP2/bYPgrm9EcjnwjYfb2G6qTS/Df0Kgn0SrhWhCOpF UyLPK+ar43SjzdrrFBrKeDSfx6zZpchgL4qcIkWo8IuNYNDyD4+LueCbWdk198lzp5TP iRSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=SsIRGkPWeq5HvTZzTxF/TGZYHjIKFiRIBMhKcsnvtic=; b=wgqgdlLG4RQEjv3bJUgSNwcJ4kk+Y9xxEa9sZRzb/T4J1AtG9yknh0my3Nrx7aK1YO oo03j96hErM3LiXfiWGwWjnE41f4tAvWbi+fwElIP24PhxXikSJgffnTc+LaxCjnQeF0 jm3l9XgHKdMsD64a5gsIaQ5bv+KKXQUpC2ufsOeOWuru9k2Menc7ecQXt0KWRQoUaD4G P2c8XWucAlN22QVe4Us7OTGfxWMcnz0YHUrRNCr9bxYBh/5FyOefrhbQIhCX3vqkAC3n KlfOtvQZbkkp1J2roIjuGvrTq6tMLrN5+X50gsVs+IBhXIFPUmGLPG1jHsp0Ea25z+3r KHxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=L70HGCBp; spf=pass (google.com: domain of john.hubbard@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.hubbard@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id q10sor78691752pls.59.2019.07.30.13.57.11 for (Google Transport Security); Tue, 30 Jul 2019 13:57:11 -0700 (PDT) Received-SPF: pass (google.com: domain of john.hubbard@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=L70HGCBp; spf=pass (google.com: domain of john.hubbard@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.hubbard@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SsIRGkPWeq5HvTZzTxF/TGZYHjIKFiRIBMhKcsnvtic=; b=L70HGCBpUUMrWcTYYa1tWt0fRX779kjwbp/s6gA95+/zzmpU3IMR+36XPu6QXWYkEz GEPYR7mAV3vyjYSmzzWYu6kjt+nQg1Jg4SangC+yzRJwehG6MkWlg16U5uguv1hf3kWq 9Tqg0UJEIPLTyulc+AA/95D7pCfaH+LelJn5KxT6KTVfpFGLIfvySPSKZsZzkMs9nKuh QWj9L9d1BZ5D59hL8WBrevhlL1w7quzW43CxLhBc+4AyG43JuFNBmQt/xX6gXlBUF1zH xpHnUvhHUuhY3ZdNfG7F8rbdZ5KLVsX0Zf+N41sRw4UH+rRhS++YLT9LEFo089KwaEs6 02wQ== X-Google-Smtp-Source: APXvYqyy6VjZJUb9Skq0KrIp0ivrFjlnCTe9JAlvBAw+0GWE4YicDO+sW1ZwlcZNdADtE6J1EDk0/A== X-Received: by 2002:a17:902:290b:: with SMTP id g11mr114922168plb.26.1564520231026; Tue, 30 Jul 2019 13:57:11 -0700 (PDT) Received: from blueforge.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id 137sm80565678pfz.112.2019.07.30.13.57.09 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 30 Jul 2019 13:57:10 -0700 (PDT) From: john.hubbard@gmail.com X-Google-Original-From: jhubbard@nvidia.com To: Andrew Morton Cc: Al Viro , Christian Benvenuti , Christoph Hellwig , Dan Williams , "Darrick J . Wong" , Dave Chinner , Ira Weiny , Jan Kara , Jason Gunthorpe , Jens Axboe , Jerome Glisse , "Kirill A . Shutemov" , Matthew Wilcox , Michal Hocko , Mike Marciniszyn , Mike Rapoport , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, LKML , John Hubbard , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org Subject: [PATCH v4 2/3] drivers/gpu/drm/via: convert put_page() to put_user_page*() Date: Tue, 30 Jul 2019 13:57:04 -0700 Message-Id: <20190730205705.9018-3-jhubbard@nvidia.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190730205705.9018-1-jhubbard@nvidia.com> References: <20190730205705.9018-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: John Hubbard For pages that were retained via get_user_pages*(), release those pages via the new put_user_page*() routines, instead of via put_page() or release_pages(). This is part a tree-wide conversion, as described in commit fc1d8e7cca2d ("mm: introduce put_user_page*(), placeholder versions"). Also reverse the order of a comparison, in order to placate checkpatch.pl. Cc: David Airlie Cc: Daniel Vetter Cc: dri-devel@lists.freedesktop.org Signed-off-by: John Hubbard --- drivers/gpu/drm/via/via_dmablit.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/via/via_dmablit.c b/drivers/gpu/drm/via/via_dmablit.c index 062067438f1d..b5b5bf0ba65e 100644 --- a/drivers/gpu/drm/via/via_dmablit.c +++ b/drivers/gpu/drm/via/via_dmablit.c @@ -171,7 +171,6 @@ via_map_blit_for_device(struct pci_dev *pdev, static void via_free_sg_info(struct pci_dev *pdev, drm_via_sg_info_t *vsg) { - struct page *page; int i; switch (vsg->state) { @@ -186,13 +185,8 @@ via_free_sg_info(struct pci_dev *pdev, drm_via_sg_info_t *vsg) kfree(vsg->desc_pages); /* fall through */ case dr_via_pages_locked: - for (i = 0; i < vsg->num_pages; ++i) { - if (NULL != (page = vsg->pages[i])) { - if (!PageReserved(page) && (DMA_FROM_DEVICE == vsg->direction)) - SetPageDirty(page); - put_page(page); - } - } + put_user_pages_dirty_lock(vsg->pages, vsg->num_pages, + (vsg->direction == DMA_FROM_DEVICE)); /* fall through */ case dr_via_pages_alloc: vfree(vsg->pages); From patchwork Tue Jul 30 20:57:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: john.hubbard@gmail.com X-Patchwork-Id: 11066809 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 35B0013A0 for ; Tue, 30 Jul 2019 20:57:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 248181FF14 for ; Tue, 30 Jul 2019 20:57:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17F5D284C5; Tue, 30 Jul 2019 20:57:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E5E41FF14 for ; Tue, 30 Jul 2019 20:57:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43D0F8E0007; Tue, 30 Jul 2019 16:57:14 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3C9358E0001; Tue, 30 Jul 2019 16:57:14 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A49B8E0007; Tue, 30 Jul 2019 16:57:14 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id D99BB8E0001 for ; Tue, 30 Jul 2019 16:57:13 -0400 (EDT) Received: by mail-pl1-f198.google.com with SMTP id 71so36045507pld.1 for ; Tue, 30 Jul 2019 13:57:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=zIg1AeRgD/CqkmVywbx+SzJM6fRrXplz7aYhAvptzng=; b=Lb06agBKR5Ogp/ZPHWUJoeNRPBUZ9VGzn6rC1OFSUXSMUVY8R2iBrGMe2HrvnId2xP u7WEC3HtR06MrjqRTSsJfliN98Ng117Vml1mhBagfP7kJVKccIxHcN+fjW2cei4Bipfx I7c3GJomlJmlpSNm8S3zqkMrcj4yW/1BBOdq9sGWR1/PHZBe59KksDLioL+0ESxrFPkF HX4cESemipcBtvUUpcCp9mwNtmSIYEfDQZCEST3JoXSFLMhWgGvWSmSwzgD5VMhhQvut glCwVv+Rh7kY1jKFA4B658wITDW8ZTRsZ9aCf+/YpS/UdBPtMOQQFJ1tG6iVPC3aGj+V II1A== X-Gm-Message-State: APjAAAXTGGQiIy4NZqtgJDF0kdqLoy7kOCrSh7tQ14QPBlA0RB04vdtv J/okeq+GF6NAxOkXueHfBwL2BFZQuWn9DMurWcs8HdhIPgkyb0eI8JDdT3VBpi7lFe+7UWVkFbP JMm3hcOr7hW7ltB2biViTdLaMMCFA+htNsJz0wn6WWEBCTGv70HMC4gQGmX88Uj2oKg== X-Received: by 2002:a17:90a:20a2:: with SMTP id f31mr117573271pjg.90.1564520233529; Tue, 30 Jul 2019 13:57:13 -0700 (PDT) X-Received: by 2002:a17:90a:20a2:: with SMTP id f31mr117573237pjg.90.1564520232700; Tue, 30 Jul 2019 13:57:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564520232; cv=none; d=google.com; s=arc-20160816; b=RHR+TlWKWvP8godTRmsviWzZXh+Y+UvR8oTmPGWW1LDHkA76AajXDHYnK9mJ87PVft j33Q9TlR26vhci99wSU8lQz4YiPNzNaWFCYbO6DYCb98c9qCVJQS1OuVIRXGWWu/tc3D ywrMebkt3yM4D2OVbqi8NBpP3qQ+yQIOnSfhvR6IYAWqqcIzQq3k4SRMktSDpTovmg0m AJhibDeaGpOHLBQQOK96Ob8b2m56LfcdA1Y/he9YbFP56uLwMKDDX8mlZA8+JuhRlESA hymgcK6bSuFlVuDxgGBwDy3YHRDTUmQYtidtK52rv+SO0L0GDdlL/vgZKITLZCaQGSOG XEXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=zIg1AeRgD/CqkmVywbx+SzJM6fRrXplz7aYhAvptzng=; b=aXyuPlSnEVEompm+ovWtrHxevd3ejYryYUtyvzTV7JpIvH99Y4vUa85SDYjryE+Mnm pY35mYOZYoF2nygJRFGFqtxXB17iksnBWQE80YWc0c1CaCzSTwRLw/BviyYOgTkXIWVN RBxQXY0DJuQZ8iXYhrb58b61IS854YqrIDBN1Bxw7RKQZv/dM2sMeAg324sEDUacgYKp lvsWvQlcsocWF2anN597MQJypy5LC7u8VUPyO13y+jGxR0lqeleJD9fi+bh3NijyAtBX iaLIv6aQXHHNM88Wa/IeEjoAdvOIRKCGjGx/jUXzLo/5nEAlvMH+MX3dOIaMO7HdUOec 9OHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="XPofLF/P"; spf=pass (google.com: domain of john.hubbard@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.hubbard@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id k65sor43351453pge.18.2019.07.30.13.57.12 for (Google Transport Security); Tue, 30 Jul 2019 13:57:12 -0700 (PDT) Received-SPF: pass (google.com: domain of john.hubbard@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="XPofLF/P"; spf=pass (google.com: domain of john.hubbard@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.hubbard@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zIg1AeRgD/CqkmVywbx+SzJM6fRrXplz7aYhAvptzng=; b=XPofLF/PHutz4HRxq81cl690l9JazNX7DE9Sz1LHW56Ma+PaWewPn4NCX7vVDtKrug q4GYLQHOLbQNIyzRjkilYec92LYHDHYE3s7umnjLyHZVoR8ACBwShBGZlhCQzJ0e/K9n G7PcNQdBdB1MIJeCd9Jz0A5GyrPYQBkVdaffdydfOlpBLG3dhqUxeiCBrG1LWqTE7Xqy zmL+9yVwrhVt2Kz5wb2SR2RniJWXisEJMoF7R3sZthPZBIVjkuCkP3ahQg4hWjCzfAjS HmJSUf3TZqxLbfGjRtE0Yjx4i11cxdEwGB/Fo/WLx+/qENW7fbOiVLgn4HM3pHlMEDwz K+sw== X-Google-Smtp-Source: APXvYqxsCn2vX6p1aDH+4gab5/zzeAvDw245fAqNqTfAzQelWKMC8Rw1mqVzx4xsB8ePETum3mpINg== X-Received: by 2002:a63:121b:: with SMTP id h27mr95395492pgl.335.1564520232325; Tue, 30 Jul 2019 13:57:12 -0700 (PDT) Received: from blueforge.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id 137sm80565678pfz.112.2019.07.30.13.57.11 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 30 Jul 2019 13:57:11 -0700 (PDT) From: john.hubbard@gmail.com X-Google-Original-From: jhubbard@nvidia.com To: Andrew Morton Cc: Al Viro , Christian Benvenuti , Christoph Hellwig , Dan Williams , "Darrick J . Wong" , Dave Chinner , Ira Weiny , Jan Kara , Jason Gunthorpe , Jens Axboe , Jerome Glisse , "Kirill A . Shutemov" , Matthew Wilcox , Michal Hocko , Mike Marciniszyn , Mike Rapoport , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, LKML , John Hubbard , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , "David S . Miller" , netdev@vger.kernel.org Subject: [PATCH v4 3/3] net/xdp: convert put_page() to put_user_page*() Date: Tue, 30 Jul 2019 13:57:05 -0700 Message-Id: <20190730205705.9018-4-jhubbard@nvidia.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190730205705.9018-1-jhubbard@nvidia.com> References: <20190730205705.9018-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: John Hubbard For pages that were retained via get_user_pages*(), release those pages via the new put_user_page*() routines, instead of via put_page() or release_pages(). This is part a tree-wide conversion, as described in commit fc1d8e7cca2d ("mm: introduce put_user_page*(), placeholder versions"). Cc: Björn Töpel Cc: Magnus Karlsson Cc: David S. Miller Cc: netdev@vger.kernel.org Signed-off-by: John Hubbard Acked-by: Björn Töpel --- net/xdp/xdp_umem.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c index 83de74ca729a..17c4b3d3dc34 100644 --- a/net/xdp/xdp_umem.c +++ b/net/xdp/xdp_umem.c @@ -166,14 +166,7 @@ void xdp_umem_clear_dev(struct xdp_umem *umem) static void xdp_umem_unpin_pages(struct xdp_umem *umem) { - unsigned int i; - - for (i = 0; i < umem->npgs; i++) { - struct page *page = umem->pgs[i]; - - set_page_dirty_lock(page); - put_page(page); - } + put_user_pages_dirty_lock(umem->pgs, umem->npgs, true); kfree(umem->pgs); umem->pgs = NULL;