put_user_page: new put_user_page_dirty*() helpers
Subsystems (10)
cover put_user_page: new put_user_page_dirty*() helpers
From: John Hubbard <[email protected]>
Hi,
Here is the first small batch of call site conversions for put_page() to put_user_page().
This batch includes some, but not all of the places that benefit from the two new put_user_page_dirty*() helper functions. (The ordering of call site conversion patch submission makes it better to wait until later, to convert the rest.)
There are about 50+ patches in my tree [1], and I'll be sending out the remaining ones in a few more groups:
* The block/bio related changes (Jerome mostly wrote those, but I've had to move stuff around extensively, and add a little code)
* mm/ changes
* other subsystem patches
* an RFC that shows the current state of the tracking patch set. That can only be applied after all call sites are converted, but it's good to get an early look at it.
This is part a tree-wide conversion, as described in commit fc1d8e7cca2d ("mm: introduce put_user_page*(), placeholder versions").
[1] https://github.com/johnhubbard/linux/tree/gup_dma_core
John Hubbard (4):
drivers/gpu/drm/via: convert put_page() to put_user_page*() net/xdp: convert put_page() to put_user_page*() net/rds: convert put_page() to put_user_page*()
gup: new put_user_page_dirty*() helpers
drivers/gpu/drm/via/via_dmablit.c | 5 +++-- drivers/infiniband/core/umem.c | 2 +- drivers/infiniband/hw/usnic/usnic_uiom.c | 2 +- include/linux/mm.h | 10 ++++++++++ net/rds/info.c | 5 ++--- net/rds/message.c | 2 +- net/rds/rdma.c | 15 +++++++-------- net/xdp/xdp_umem.c | 3 +-- 8 files changed, 26 insertions(+), 18 deletions(-)
Signature · 1 line
2.22.0
PATCH 1/3 drivers/gpu/drm/via: convert put_page() to put_user_page*()
From: John Hubbard <[email protected]>
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").
--- drivers/gpu/drm/via/via_dmablit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/via/via_dmablit.c +3 -2
@@ -189,8 +189,9 @@ via_free_sg_info(struct pci_dev *pdev, drm_via_sg_info_t *vsg)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 (&page,1 ); +else +put_user_page (page); } }/* fall through */
Signature · 1 line
2.22.0
Re: [PATCH 1/3] drivers/gpu/drm/via: convert put_page() to put_user_page*()
drivers/gpu/drm/via/via_dmablit.c via_free_sg_info(struct pci_dev *pdev, drm_via_sg_info_t *vsg) · line 195
Quoted 9 lines · On Sun, Jul 21, 2019 at 09:30:10PM -0700, [email protected] wrote:
drivers/gpu/drm/via/via_dmablit.c +3
-2for (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 (&page,1 ); +else +put_user_page (page); }
Can't just pass a dirty argument to put_user_pages? Also do we really need a separate put_user_page for the single page case? put_user_pages_dirty?
Also the PageReserved check looks bogus, as I can't see how a reserved page can end up here. So IMHO the above snippled should really look something like this:
put_user_pages(vsg->pages[i], vsg->num_pages, vsg->direction == DMA_FROM_DEVICE);
in the end.
Re: [PATCH 1/3] drivers/gpu/drm/via: convert put_page() to put_user_page*()
Quoted 12 lines · Christoph Hellwig
drivers/gpu/drm/via/via_dmablit.c via_free_sg_info(struct pci_dev *pdev, drm_via_sg_info_t *vsg) · line 195
Quoted 9 lines · On Sun, Jul 21, 2019 at 09:30:10PM -0700, [email protected] wrote:
drivers/gpu/drm/via/via_dmablit.c +3
-2for (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 (&page,1 ); +else +put_user_page (page); }Can't just pass a dirty argument to
put_user_pages? Also do we really
Yes, and in fact that would help a lot more than the single page case, which is really just cosmetic after all.
Quoted 2 lines
need a separate
put_user_pagefor the single page case?put_user_pages_dirty?
Not really. I'm still zeroing in on the ideal API for all these call sites, and I agree that the approach below is cleaner.
Quoted 10 lines
Also the PageReserved check looks bogus, as I can't see how a reserved page can end up here. So IMHO the above snippled should really look something like this:
put_user_pages(vsg->pages[i], vsg->num_pages, vsg->direction == DMA_FROM_DEVICE);in the end.
Agreed.
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Re: [PATCH 1/3] drivers/gpu/drm/via: convert put_page() to put_user_page*()
Quoted 14 lines · John Hubbard
Quoted 12 lines · Christoph Hellwig
drivers/gpu/drm/via/via_dmablit.c via_free_sg_info(struct pci_dev *pdev, drm_via_sg_info_t *vsg) · line 195
Quoted 9 lines · On Sun, Jul 21, 2019 at 09:30:10PM -0700, [email protected] wrote:
drivers/gpu/drm/via/via_dmablit.c +3
-2for (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 (&page,1 ); +else +put_user_page (page); }Can't just pass a dirty argument to
put_user_pages? Also do we really
Quoted 8 lines
Yes, and in fact that would help a lot more than the single page case, which is really just cosmetic after all.
Quoted 2 lines
need a separate
put_user_pagefor the single page case?put_user_pages_dirty?Not really. I'm still zeroing in on the ideal API for all these call sites, and I agree that the approach below is cleaner.
so enum { CLEAN = 0, DIRTY = 1, LOCK = 2, DIRTY_LOCK = 3 }; ?
Re: [PATCH 1/3] drivers/gpu/drm/via: convert put_page() to put_user_page*()
Quoted 18 lines · Matthew Wilcox
Quoted 17 lines · John Hubbard
Quoted 12 lines · Christoph Hellwig
drivers/gpu/drm/via/via_dmablit.c via_free_sg_info(struct pci_dev *pdev, drm_via_sg_info_t *vsg) · line 195
Quoted 9 lines · On Sun, Jul 21, 2019 at 09:30:10PM -0700, [email protected] wrote:
drivers/gpu/drm/via/via_dmablit.c +3
-2for (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 (&page,1 ); +else +put_user_page (page); }Can't just pass a dirty argument to
put_user_pages? Also do we reallyYes, and in fact that would help a lot more than the single page case, which is really just cosmetic after all.
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
need a separate
put_user_pagefor the single page case?put_user_pages_dirty?Not really. I'm still zeroing in on the ideal API for all these call sites, and I agree that the approach below is cleaner.
so enum { CLEAN = 0, DIRTY = 1, LOCK = 2,
DIRTY_LOCK= 3 }; ?
Sure. In fact, I just applied something similar to bio_release_pages() locally, in order to reconcile Christoph's and Jerome's approaches (they each needed to add a bool arg), so I'm all about the enums in the arg lists. :)
I'm going to post that one shortly, let's see how it goes over. heh.
thanks,
Signature · 2 lines
John Hubbard NVIDIA
PATCH 2/3 net/xdp: convert put_page() to put_user_page*()
In reply to [email protected]From: John Hubbard <[email protected]>
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").
--- net/xdp/xdp_umem.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/xdp/xdp_umem.c +1 -2
@@ -171,8 +171,7 @@ static void xdp_umem_unpin_pages(struct xdp_umem *umem)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 (&page,1 ); }kfree (umem->pgs);
Signature · 1 line
2.22.0
Re: [PATCH 2/3] net/xdp: convert put_page() to put_user_page*()
net/xdp/xdp_umem.c static void xdp_umem_unpin_pages(struct xdp_umem *umem) · line 174
Quoted 11 lines
net/xdp/xdp_umem.c +1
-2@@ -171,8 +171,7 @@ static void xdp_umem_unpin_pages(struct xdp_umem *umem)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 (&page,1 );
Same here, we really should avoid the need for the loop here and do the looping inside the helper.
PATCH 3/3 gup: new put_user_page_dirty*() helpers
In reply to [email protected]From: John Hubbard <[email protected]>
While converting call sites to use put_user_page*() [1], quite a few places ended up needing a single-page routine to put and dirty a page.
Provide put_user_page_dirty() and put_user_page_dirty_lock(), and use them in a few places: net/xdp, drm/via/, drivers/infiniband.
--- drivers/gpu/drm/via/via_dmablit.c | 2 +- drivers/infiniband/core/umem.c | 2 +- drivers/infiniband/hw/usnic/usnic_uiom.c | 2 +- include/linux/mm.h | 10 ++++++++++ net/xdp/xdp_umem.c | 2 +- 5 files changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/via/via_dmablit.c +1 -1
@@ -189,7 +189,7 @@ via_free_sg_info(struct pci_dev *pdev, drm_via_sg_info_t *vsg)for (i =0 ; i < vsg->num_pages; ++i) {if (NULL != (page = vsg->pages[i])) {if (!PageReserved (page) && (DMA_FROM_DEVICE == vsg->direction)) -put_user_pages_dirty (&page,1 ); +put_user_page_dirty (page);else put_user_page (page); }
drivers/infiniband/core/umem.c +1 -1
@@ -55,7 +55,7 @@ static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int dfor_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 ); +put_user_page_dirty_lock (page);else put_user_page (page); }
drivers/infiniband/hw/usnic/usnic_uiom.c +1 -1
@@ -76,7 +76,7 @@ static void usnic_uiom_put_pages(struct list_head *chunk_list, int dirty) page =sg_page (sg); pa =sg_phys (sg);if (dirty) -put_user_pages_dirty_lock (&page,1 ); +put_user_page_dirty_lock (page);else put_user_page (page);usnic_dbg ("pa: %pa\n" , &pa);
include/linux/mm.h +10 -0
@@ -1061,6 +1061,16 @@ 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 (struct page **pages,unsigned long npages); +static inline void put_user_page_dirty (struct page *page) +{ +put_user_pages_dirty (&page,1 ); +} + +static inline void put_user_page_dirty_lock (struct page *page) +{ +put_user_pages_dirty_lock (&page,1 ); +} +#if defined(CONFIG_SPARSEMEM ) && !defined(CONFIG_SPARSEMEM_VMEMMAP )#define SECTION_IN_PAGE_FLAGS #endif
net/xdp/xdp_umem.c +1 -1
@@ -171,7 +171,7 @@ static void xdp_umem_unpin_pages(struct xdp_umem *umem)for (i =0 ; i < umem->npgs; i++) {struct page *page = umem->pgs[i]; -put_user_pages_dirty_lock (&page,1 ); +put_user_page_dirty_lock (page); }kfree (umem->pgs);
Signature · 1 line
2.22.0
Re: [PATCH 3/3] gup: new put_user_page_dirty*() helpers
Quoted 9 lines · On 7/21/19 9:30 PM, [email protected] wrote:
From: John Hubbard <[email protected]>
While converting call sites to use put_user_page*() [1], quite a few places ended up needing a single-page routine to put and dirty a page.
Provide
put_user_page_dirty()andput_user_page_dirty_lock(), and use them in a few places: net/xdp, drm/via/,drivers/infiniband.
Please disregard this one, I'm going to drop it, as per the discussion in patch 1.
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Quoted 85 lines
Cc Jason Gunthorpe <[email protected]>Cc Jan Kara <[email protected]>Signed-off-by John Hubbard <[email protected]>--- drivers/gpu/drm/via/via_dmablit.c | 2 +- drivers/infiniband/core/umem.c | 2 +- drivers/infiniband/hw/usnic/usnic_uiom.c | 2 +- include/linux/mm.h | 10 ++++++++++ net/xdp/xdp_umem.c | 2 +- 5 files changed, 14 insertions(+), 4 deletions(-)drivers/gpu/drm/via/via_dmablit.c +1
-1@@ -189,7 +189,7 @@ via_free_sg_info(struct pci_dev *pdev, drm_via_sg_info_t *vsg)for (i =0 ; i < vsg->num_pages; ++i) {if (NULL != (page = vsg->pages[i])) {if (!PageReserved (page) && (DMA_FROM_DEVICE == vsg->direction)) -put_user_pages_dirty (&page,1 ); +put_user_page_dirty (page);else put_user_page (page); }drivers/infiniband/core/umem.c +1
-1@@ -55,7 +55,7 @@ static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int dfor_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 ); +put_user_page_dirty_lock (page);else put_user_page (page); }drivers/infiniband/hw/usnic/usnic_uiom.c +1
-1@@ -76,7 +76,7 @@ static void usnic_uiom_put_pages(struct list_head *chunk_list, int dirty) page =sg_page (sg); pa =sg_phys (sg);if (dirty) -put_user_pages_dirty_lock (&page,1 ); +put_user_page_dirty_lock (page);else put_user_page (page);usnic_dbg ("pa: %pa\n" , &pa);include/linux/mm.h +10
-0@@ -1061,6 +1061,16 @@ 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 (struct page **pages,unsigned long npages); +static inline void put_user_page_dirty (struct page *page) +{ +put_user_pages_dirty (&page,1 ); +} + +static inline void put_user_page_dirty_lock (struct page *page) +{ +put_user_pages_dirty_lock (&page,1 ); +} +#if defined(CONFIG_SPARSEMEM ) && !defined(CONFIG_SPARSEMEM_VMEMMAP )#define SECTION_IN_PAGE_FLAGS #endif net/xdp/xdp_umem.c +1
-1@@ -171,7 +171,7 @@ static void xdp_umem_unpin_pages(struct xdp_umem *umem)for (i =0 ; i < umem->npgs; i++) {struct page *page = umem->pgs[i]; -put_user_pages_dirty_lock (&page,1 ); +put_user_page_dirty_lock (page); }kfree (umem->pgs);