Message ID | 20191209225344.99740-21-jhubbard@nvidia.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | mm/gup: track dma-pinned pages: FOLL_PIN | expand |
On 12/9/19 2:53 PM, John Hubbard wrote: ... > @@ -212,10 +211,9 @@ static void mm_iommu_unpin(struct mm_iommu_table_group_mem_t *mem) > if (!page) > continue; > > - if (mem->hpas[i] & MM_IOMMU_TABLE_GROUP_PAGE_DIRTY) > - SetPageDirty(page); > + put_user_pages_dirty_lock(&page, 1, > + mem->hpas[i] & MM_IOMMU_TABLE_GROUP_PAGE_DIRTY); > > - put_page(page); Correction: this is somehow missing the fixes that resulted from Jan Kara's review (he noted that we can't take a page lock in this context). I must have picked up the wrong version of it, when I rebased for -rc1. Will fix in the next version (including the commit description). Here's what the corrected hunk will look like: @@ -215,7 +214,8 @@ static void mm_iommu_unpin(struct mm_iommu_table_group_mem_t *mem) if (mem->hpas[i] & MM_IOMMU_TABLE_GROUP_PAGE_DIRTY) SetPageDirty(page); - put_page(page); + put_user_page(page); + mem->hpas[i] = 0; } } thanks,
On 12/9/19 3:46 PM, John Hubbard wrote: > On 12/9/19 2:53 PM, John Hubbard wrote: > ... >> @@ -212,10 +211,9 @@ static void mm_iommu_unpin(struct mm_iommu_table_group_mem_t *mem) >> if (!page) >> continue; >> >> - if (mem->hpas[i] & MM_IOMMU_TABLE_GROUP_PAGE_DIRTY) >> - SetPageDirty(page); >> + put_user_pages_dirty_lock(&page, 1, >> + mem->hpas[i] & MM_IOMMU_TABLE_GROUP_PAGE_DIRTY); >> >> - put_page(page); > > > Correction: this is somehow missing the fixes that resulted from Jan Kara's review (he > noted that we can't take a page lock in this context). I must have picked up the > wrong version of it, when I rebased for -rc1. > Andrew, given that the series is now in -mm, what's the preferred way for me to fix this? Send a v9 version of the whole series? Or something else? I'm still learning the ropes... thanks,
On Mon, 9 Dec 2019 21:53:00 -0800 John Hubbard <jhubbard@nvidia.com> wrote: > > Correction: this is somehow missing the fixes that resulted from Jan Kara's review (he > > noted that we can't take a page lock in this context). I must have picked up the > > wrong version of it, when I rebased for -rc1. > > > > Andrew, given that the series is now in -mm, what's the preferred way for me to fix this? > Send a v9 version of the whole series? Or something else? I think a full resend is warranted at this time - it's only been in there a day and there seem to be quite a number of changes to be made.
diff --git a/arch/powerpc/mm/book3s64/iommu_api.c b/arch/powerpc/mm/book3s64/iommu_api.c index 56cc84520577..fc1670a6fc3c 100644 --- a/arch/powerpc/mm/book3s64/iommu_api.c +++ b/arch/powerpc/mm/book3s64/iommu_api.c @@ -103,7 +103,7 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua, for (entry = 0; entry < entries; entry += chunk) { unsigned long n = min(entries - entry, chunk); - ret = get_user_pages(ua + (entry << PAGE_SHIFT), n, + ret = pin_user_pages(ua + (entry << PAGE_SHIFT), n, FOLL_WRITE | FOLL_LONGTERM, mem->hpages + entry, NULL); if (ret == n) { @@ -167,9 +167,8 @@ static long mm_iommu_do_alloc(struct mm_struct *mm, unsigned long ua, return 0; free_exit: - /* free the reference taken */ - for (i = 0; i < pinned; i++) - put_page(mem->hpages[i]); + /* free the references taken */ + put_user_pages(mem->hpages, pinned); vfree(mem->hpas); kfree(mem); @@ -212,10 +211,9 @@ static void mm_iommu_unpin(struct mm_iommu_table_group_mem_t *mem) if (!page) continue; - if (mem->hpas[i] & MM_IOMMU_TABLE_GROUP_PAGE_DIRTY) - SetPageDirty(page); + put_user_pages_dirty_lock(&page, 1, + mem->hpas[i] & MM_IOMMU_TABLE_GROUP_PAGE_DIRTY); - put_page(page); mem->hpas[i] = 0; } }
1. Convert from get_user_pages() to pin_user_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] [1] https://lore.kernel.org/r/20190723153640.GB720@lst.de Cc: Jan Kara <jack@suse.cz> Signed-off-by: John Hubbard <jhubbard@nvidia.com> --- arch/powerpc/mm/book3s64/iommu_api.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)