Commit 4d869f25 authored by Roger He's avatar Roger He Committed by Alex Deucher

drm/ttm: add the missed global memory count update

when ttm_mem_global_alloc_page fails, we should call
ttm_mem_global_free_page to update memory count for
the ttm pages which already run ttm_mem_global_alloc_page
successfully
Signed-off-by: default avatarRoger He <Hongbo.He@amd.com>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent cb5f1a52
...@@ -1069,6 +1069,28 @@ void ttm_page_alloc_fini(void) ...@@ -1069,6 +1069,28 @@ void ttm_page_alloc_fini(void)
_manager = NULL; _manager = NULL;
} }
static void
ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update)
{
unsigned i;
if (mem_count_update == 0)
goto put_pages;
for (i = 0; i < mem_count_update; ++i) {
if (!ttm->pages[i])
continue;
ttm_mem_global_free_page(ttm->glob->mem_glob, ttm->pages[i],
PAGE_SIZE);
}
put_pages:
ttm_put_pages(ttm->pages, ttm->num_pages, ttm->page_flags,
ttm->caching_state);
ttm->state = tt_unpopulated;
}
int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
{ {
struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; struct ttm_mem_global *mem_glob = ttm->glob->mem_glob;
...@@ -1081,8 +1103,7 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) ...@@ -1081,8 +1103,7 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
ret = ttm_get_pages(ttm->pages, ttm->num_pages, ttm->page_flags, ret = ttm_get_pages(ttm->pages, ttm->num_pages, ttm->page_flags,
ttm->caching_state); ttm->caching_state);
if (unlikely(ret != 0)) { if (unlikely(ret != 0)) {
ttm_put_pages(ttm->pages, ttm->num_pages, ttm->page_flags, ttm_pool_unpopulate_helper(ttm, 0);
ttm->caching_state);
return ret; return ret;
} }
...@@ -1090,8 +1111,7 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) ...@@ -1090,8 +1111,7 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i], ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i],
PAGE_SIZE, ctx); PAGE_SIZE, ctx);
if (unlikely(ret != 0)) { if (unlikely(ret != 0)) {
ttm_put_pages(ttm->pages, ttm->num_pages, ttm_pool_unpopulate_helper(ttm, i);
ttm->page_flags, ttm->caching_state);
return -ENOMEM; return -ENOMEM;
} }
} }
...@@ -1111,18 +1131,7 @@ EXPORT_SYMBOL(ttm_pool_populate); ...@@ -1111,18 +1131,7 @@ EXPORT_SYMBOL(ttm_pool_populate);
void ttm_pool_unpopulate(struct ttm_tt *ttm) void ttm_pool_unpopulate(struct ttm_tt *ttm)
{ {
unsigned i; ttm_pool_unpopulate_helper(ttm, ttm->num_pages);
for (i = 0; i < ttm->num_pages; ++i) {
if (!ttm->pages[i])
continue;
ttm_mem_global_free_page(ttm->glob->mem_glob, ttm->pages[i],
PAGE_SIZE);
}
ttm_put_pages(ttm->pages, ttm->num_pages, ttm->page_flags,
ttm->caching_state);
ttm->state = tt_unpopulated;
} }
EXPORT_SYMBOL(ttm_pool_unpopulate); EXPORT_SYMBOL(ttm_pool_unpopulate);
......
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