Commit 21856e1e authored by Matthew Auld's avatar Matthew Auld Committed by Christian König

drm/ttm: move ttm_tt_{add, clear}_mapping into amdgpu

Now that setting page->index shouldn't be needed anymore, we are just
left with setting page->mapping, and here it looks like amdgpu is the
only user, where pointing the page->mapping at the dev_mapping is used
to verify that the pages do indeed belong to the device, if userspace
later tries to touch them.

v2(Christian):
  - Drop the functions altogether and just inline modifying
    the page->mapping
Signed-off-by: default avatarMatthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Christian König <christian.koenig@amd.com>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210927114114.152310-3-matthew.auld@intel.comSigned-off-by: default avatarChristian König <christian.koenig@amd.com>
parent 635138f7
...@@ -1119,6 +1119,8 @@ static int amdgpu_ttm_tt_populate(struct ttm_device *bdev, ...@@ -1119,6 +1119,8 @@ static int amdgpu_ttm_tt_populate(struct ttm_device *bdev,
{ {
struct amdgpu_device *adev = amdgpu_ttm_adev(bdev); struct amdgpu_device *adev = amdgpu_ttm_adev(bdev);
struct amdgpu_ttm_tt *gtt = (void *)ttm; struct amdgpu_ttm_tt *gtt = (void *)ttm;
pgoff_t i;
int ret;
/* user pages are bound by amdgpu_ttm_tt_pin_userptr() */ /* user pages are bound by amdgpu_ttm_tt_pin_userptr() */
if (gtt->userptr) { if (gtt->userptr) {
...@@ -1131,7 +1133,14 @@ static int amdgpu_ttm_tt_populate(struct ttm_device *bdev, ...@@ -1131,7 +1133,14 @@ static int amdgpu_ttm_tt_populate(struct ttm_device *bdev,
if (ttm->page_flags & TTM_PAGE_FLAG_SG) if (ttm->page_flags & TTM_PAGE_FLAG_SG)
return 0; return 0;
return ttm_pool_alloc(&adev->mman.bdev.pool, ttm, ctx); ret = ttm_pool_alloc(&adev->mman.bdev.pool, ttm, ctx);
if (ret)
return ret;
for (i = 0; i < ttm->num_pages; ++i)
ttm->pages[i]->mapping = bdev->dev_mapping;
return 0;
} }
/* /*
...@@ -1145,6 +1154,7 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_device *bdev, ...@@ -1145,6 +1154,7 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_device *bdev,
{ {
struct amdgpu_ttm_tt *gtt = (void *)ttm; struct amdgpu_ttm_tt *gtt = (void *)ttm;
struct amdgpu_device *adev; struct amdgpu_device *adev;
pgoff_t i;
amdgpu_ttm_backend_unbind(bdev, ttm); amdgpu_ttm_backend_unbind(bdev, ttm);
...@@ -1158,6 +1168,9 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_device *bdev, ...@@ -1158,6 +1168,9 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_device *bdev,
if (ttm->page_flags & TTM_PAGE_FLAG_SG) if (ttm->page_flags & TTM_PAGE_FLAG_SG)
return; return;
for (i = 0; i < ttm->num_pages; ++i)
ttm->pages[i]->mapping = NULL;
adev = amdgpu_ttm_adev(bdev); adev = amdgpu_ttm_adev(bdev);
return ttm_pool_free(&adev->mman.bdev.pool, ttm); return ttm_pool_free(&adev->mman.bdev.pool, ttm);
} }
......
...@@ -289,17 +289,6 @@ int ttm_tt_swapout(struct ttm_device *bdev, struct ttm_tt *ttm, ...@@ -289,17 +289,6 @@ int ttm_tt_swapout(struct ttm_device *bdev, struct ttm_tt *ttm,
return ret; return ret;
} }
static void ttm_tt_add_mapping(struct ttm_device *bdev, struct ttm_tt *ttm)
{
pgoff_t i;
if (ttm->page_flags & TTM_PAGE_FLAG_SG)
return;
for (i = 0; i < ttm->num_pages; ++i)
ttm->pages[i]->mapping = bdev->dev_mapping;
}
int ttm_tt_populate(struct ttm_device *bdev, int ttm_tt_populate(struct ttm_device *bdev,
struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
{ {
...@@ -336,7 +325,6 @@ int ttm_tt_populate(struct ttm_device *bdev, ...@@ -336,7 +325,6 @@ int ttm_tt_populate(struct ttm_device *bdev,
if (ret) if (ret)
goto error; goto error;
ttm_tt_add_mapping(bdev, ttm);
ttm->page_flags |= TTM_PAGE_FLAG_PRIV_POPULATED; ttm->page_flags |= TTM_PAGE_FLAG_PRIV_POPULATED;
if (unlikely(ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)) { if (unlikely(ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)) {
ret = ttm_tt_swapin(ttm); ret = ttm_tt_swapin(ttm);
...@@ -359,24 +347,11 @@ int ttm_tt_populate(struct ttm_device *bdev, ...@@ -359,24 +347,11 @@ int ttm_tt_populate(struct ttm_device *bdev,
} }
EXPORT_SYMBOL(ttm_tt_populate); EXPORT_SYMBOL(ttm_tt_populate);
static void ttm_tt_clear_mapping(struct ttm_tt *ttm)
{
pgoff_t i;
struct page **page = ttm->pages;
if (ttm->page_flags & TTM_PAGE_FLAG_SG)
return;
for (i = 0; i < ttm->num_pages; ++i)
(*page)->mapping = NULL;
}
void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm) void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm)
{ {
if (!ttm_tt_is_populated(ttm)) if (!ttm_tt_is_populated(ttm))
return; return;
ttm_tt_clear_mapping(ttm);
if (bdev->funcs->ttm_tt_unpopulate) if (bdev->funcs->ttm_tt_unpopulate)
bdev->funcs->ttm_tt_unpopulate(bdev, ttm); bdev->funcs->ttm_tt_unpopulate(bdev, ttm);
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment