Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/ttm: fix re-init of global structures

When a driver unloads without unloading TTM we don't correctly
clear the global structures leading to errors on re-init.

Next step should probably be to remove the global structures and
kobjs all together, but this is tricky since we need to maintain
backward compatibility.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Tested-by: Karol Herbst <kherbst@redhat.com>
CC: stable@vger.kernel.org # 5.0.x
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Christian König and committed by
Alex Deucher
bd426411 00fd14ff

+8 -8
+5 -5
drivers/gpu/drm/ttm/ttm_bo.c
··· 49 49 * ttm_global_mutex - protecting the global BO state 50 50 */ 51 51 DEFINE_MUTEX(ttm_global_mutex); 52 - struct ttm_bo_global ttm_bo_glob = { 53 - .use_count = 0 54 - }; 52 + unsigned ttm_bo_glob_use_count; 53 + struct ttm_bo_global ttm_bo_glob; 55 54 56 55 static struct attribute ttm_bo_count = { 57 56 .name = "bo_count", ··· 1530 1531 struct ttm_bo_global *glob = &ttm_bo_glob; 1531 1532 1532 1533 mutex_lock(&ttm_global_mutex); 1533 - if (--glob->use_count > 0) 1534 + if (--ttm_bo_glob_use_count > 0) 1534 1535 goto out; 1535 1536 1536 1537 kobject_del(&glob->kobj); 1537 1538 kobject_put(&glob->kobj); 1538 1539 ttm_mem_global_release(&ttm_mem_glob); 1540 + memset(glob, 0, sizeof(*glob)); 1539 1541 out: 1540 1542 mutex_unlock(&ttm_global_mutex); 1541 1543 } ··· 1548 1548 unsigned i; 1549 1549 1550 1550 mutex_lock(&ttm_global_mutex); 1551 - if (++glob->use_count > 1) 1551 + if (++ttm_bo_glob_use_count > 1) 1552 1552 goto out; 1553 1553 1554 1554 ret = ttm_mem_global_init(&ttm_mem_glob);
+3 -2
drivers/gpu/drm/ttm/ttm_memory.c
··· 461 461 462 462 void ttm_mem_global_release(struct ttm_mem_global *glob) 463 463 { 464 - unsigned int i; 465 464 struct ttm_mem_zone *zone; 465 + unsigned int i; 466 466 467 467 /* let the page allocator first stop the shrink work. */ 468 468 ttm_page_alloc_fini(); ··· 475 475 zone = glob->zones[i]; 476 476 kobject_del(&zone->kobj); 477 477 kobject_put(&zone->kobj); 478 - } 478 + } 479 479 kobject_del(&glob->kobj); 480 480 kobject_put(&glob->kobj); 481 + memset(glob, 0, sizeof(*glob)); 481 482 } 482 483 483 484 static void ttm_check_swapping(struct ttm_mem_global *glob)
-1
include/drm/ttm/ttm_bo_driver.h
··· 420 420 /** 421 421 * Protected by ttm_global_mutex. 422 422 */ 423 - unsigned int use_count; 424 423 struct list_head device_list; 425 424 426 425 /**