Skip to content

Commit b7d85e1

Browse files
ChristianKoenigAMDalexdeucher
authored andcommitted
drm/amdgpu: fix TTM move entity init order
We are initializing the entity before the scheduler is actually initialized. This can lead to all kind of problem, but especially NULL pointer deref because of Nayan's scheduler work. Signed-off-by: Christian König <christian.koenig@amd.com> Acked-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 44a99b6 commit b7d85e1

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

‎drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ static void amdgpu_ttm_mem_global_release(struct drm_global_reference *ref)
104104
static int amdgpu_ttm_global_init(struct amdgpu_device *adev)
105105
{
106106
struct drm_global_reference *global_ref;
107-
struct amdgpu_ring *ring;
108-
struct drm_sched_rq *rq;
109107
int r;
110108

111109
/* ensure reference is false in case init fails */
@@ -138,21 +136,10 @@ static int amdgpu_ttm_global_init(struct amdgpu_device *adev)
138136

139137
mutex_init(&adev->mman.gtt_window_lock);
140138

141-
ring = adev->mman.buffer_funcs_ring;
142-
rq = &ring->sched.sched_rq[DRM_SCHED_PRIORITY_KERNEL];
143-
r = drm_sched_entity_init(&ring->sched, &adev->mman.entity,
144-
rq, NULL);
145-
if (r) {
146-
DRM_ERROR("Failed setting up TTM BO move run queue.\n");
147-
goto error_entity;
148-
}
149-
150139
adev->mman.mem_global_referenced = true;
151140

152141
return 0;
153142

154-
error_entity:
155-
drm_global_item_unref(&adev->mman.bo_global_ref.ref);
156143
error_bo:
157144
drm_global_item_unref(&adev->mman.mem_global_ref);
158145
error_mem:
@@ -162,8 +149,6 @@ static int amdgpu_ttm_global_init(struct amdgpu_device *adev)
162149
static void amdgpu_ttm_global_fini(struct amdgpu_device *adev)
163150
{
164151
if (adev->mman.mem_global_referenced) {
165-
drm_sched_entity_destroy(adev->mman.entity.sched,
166-
&adev->mman.entity);
167152
mutex_destroy(&adev->mman.gtt_window_lock);
168153
drm_global_item_unref(&adev->mman.bo_global_ref.ref);
169154
drm_global_item_unref(&adev->mman.mem_global_ref);
@@ -1921,10 +1906,30 @@ void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable)
19211906
{
19221907
struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_VRAM];
19231908
uint64_t size;
1909+
int r;
19241910

1925-
if (!adev->mman.initialized || adev->in_gpu_reset)
1911+
if (!adev->mman.initialized || adev->in_gpu_reset ||
1912+
adev->mman.buffer_funcs_enabled == enable)
19261913
return;
19271914

1915+
if (enable) {
1916+
struct amdgpu_ring *ring;
1917+
struct drm_sched_rq *rq;
1918+
1919+
ring = adev->mman.buffer_funcs_ring;
1920+
rq = &ring->sched.sched_rq[DRM_SCHED_PRIORITY_KERNEL];
1921+
r = drm_sched_entity_init(&ring->sched, &adev->mman.entity,
1922+
rq, NULL);
1923+
if (r) {
1924+
DRM_ERROR("Failed setting up TTM BO move entity (%d)\n",
1925+
r);
1926+
return;
1927+
}
1928+
} else {
1929+
drm_sched_entity_destroy(adev->mman.entity.sched,
1930+
&adev->mman.entity);
1931+
}
1932+
19281933
/* this just adjusts TTM size idea, which sets lpfn to the correct value */
19291934
if (enable)
19301935
size = adev->gmc.real_vram_size;

0 commit comments

Comments
 (0)