Skip to content

Commit bd42641

Browse files
ChristianKoenigAMDalexdeucher
authored andcommitted
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>
1 parent 00fd14f commit bd42641

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎drivers/gpu/drm/ttm/ttm_bo.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj);
4949
* ttm_global_mutex - protecting the global BO state
5050
*/
5151
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;
5554

5655
static struct attribute ttm_bo_count = {
5756
.name = "bo_count",
@@ -1531,12 +1530,13 @@ static void ttm_bo_global_release(void)
15311530
struct ttm_bo_global *glob = &ttm_bo_glob;
15321531

15331532
mutex_lock(&ttm_global_mutex);
1534-
if (--glob->use_count > 0)
1533+
if (--ttm_bo_glob_use_count > 0)
15351534
goto out;
15361535

15371536
kobject_del(&glob->kobj);
15381537
kobject_put(&glob->kobj);
15391538
ttm_mem_global_release(&ttm_mem_glob);
1539+
memset(glob, 0, sizeof(*glob));
15401540
out:
15411541
mutex_unlock(&ttm_global_mutex);
15421542
}
@@ -1548,7 +1548,7 @@ static int ttm_bo_global_init(void)
15481548
unsigned i;
15491549

15501550
mutex_lock(&ttm_global_mutex);
1551-
if (++glob->use_count > 1)
1551+
if (++ttm_bo_glob_use_count > 1)
15521552
goto out;
15531553

15541554
ret = ttm_mem_global_init(&ttm_mem_glob);

‎drivers/gpu/drm/ttm/ttm_memory.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,8 @@ int ttm_mem_global_init(struct ttm_mem_global *glob)
461461

462462
void ttm_mem_global_release(struct ttm_mem_global *glob)
463463
{
464-
unsigned int i;
465464
struct ttm_mem_zone *zone;
465+
unsigned int i;
466466

467467
/* let the page allocator first stop the shrink work. */
468468
ttm_page_alloc_fini();
@@ -475,9 +475,10 @@ void ttm_mem_global_release(struct ttm_mem_global *glob)
475475
zone = glob->zones[i];
476476
kobject_del(&zone->kobj);
477477
kobject_put(&zone->kobj);
478-
}
478+
}
479479
kobject_del(&glob->kobj);
480480
kobject_put(&glob->kobj);
481+
memset(glob, 0, sizeof(*glob));
481482
}
482483

483484
static void ttm_check_swapping(struct ttm_mem_global *glob)

‎include/drm/ttm/ttm_bo_driver.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ extern struct ttm_bo_global {
420420
/**
421421
* Protected by ttm_global_mutex.
422422
*/
423-
unsigned int use_count;
424423
struct list_head device_list;
425424

426425
/**

0 commit comments

Comments
 (0)