Switch old api get_user_pages to pin_user_pages according to [1].
It guarantees these DMA pages are pinned.

Also pass FOLL_LONGTERM: these userptr pages stay pinned for the
lifetime of the GEM userptr BO's GART binding, not just for the
duration of a single call, so this is a long-term pin.

[1] Documentation/core-api/pin_user_pages.rst

Signed-off-by: Seongjun Hong <[email protected]>
---
v2:
- Add FOLL_LONGTERM

 drivers/gpu/drm/radeon/radeon_ttm.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c 
b/drivers/gpu/drm/radeon/radeon_ttm.c
index e7ab8162ac69..c14b215c7e3e 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -346,11 +346,12 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_device 
*bdev, struct ttm_tt *ttm
 
        do {
                unsigned num_pages = ttm->num_pages - pinned;
+               unsigned gup_flags = (write) ? FOLL_WRITE | FOLL_LONGTERM :
+                                              FOLL_LONGTERM;
                uint64_t userptr = gtt->userptr + pinned * PAGE_SIZE;
                struct page **pages = ttm->pages + pinned;
 
-               r = get_user_pages(userptr, num_pages, write ? FOLL_WRITE : 0,
-                                  pages);
+               r = pin_user_pages(userptr, num_pages, gup_flags, pages);
                if (r < 0)
                        goto release_pages;
 
@@ -377,7 +378,7 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_device 
*bdev, struct ttm_tt *ttm
        kfree(ttm->sg);
 
 release_pages:
-       release_pages(ttm->pages, pinned);
+       unpin_user_pages(ttm->pages, pinned);
        return r;
 }
 
@@ -404,7 +405,7 @@ static void radeon_ttm_tt_unpin_userptr(struct ttm_device 
*bdev, struct ttm_tt *
                        set_page_dirty(page);
 
                mark_page_accessed(page);
-               put_page(page);
+               unpin_user_page(page);
        }
 
        sg_free_table(ttm->sg);
-- 
2.43.0

Reply via email to