Skip to content

Commit 1c46f3c

Browse files
committed
Merge tag 'amd-drm-fixes-5.19-2022-07-20' of https://gitlab.freedesktop.org/agd5f/linux into drm-fixes
amd-drm-fixes-5.19-2022-07-20: amdgpu: - Drop redundant buffer cleanup that can lead to a segfault - Add a bo_list mutex to avoid possible list corruption in CS Signed-off-by: Dave Airlie <airlied@redhat.com> From: Alex Deucher <alexander.deucher@amd.com> Link: https://patchwork.freedesktop.org/patch/msgid/20220720210917.6202-1-alexander.deucher@amd.com
2 parents 4b2b2ee + 90af0ca commit 1c46f3c

File tree

5 files changed

+38
-18
lines changed

5 files changed

+38
-18
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,16 +1364,10 @@ void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev,
13641364
struct amdgpu_vm *vm)
13651365
{
13661366
struct amdkfd_process_info *process_info = vm->process_info;
1367-
struct amdgpu_bo *pd = vm->root.bo;
13681367

13691368
if (!process_info)
13701369
return;
13711370

1372-
/* Release eviction fence from PD */
1373-
amdgpu_bo_reserve(pd, false);
1374-
amdgpu_bo_fence(pd, NULL, false);
1375-
amdgpu_bo_unreserve(pd);
1376-
13771371
/* Update process info */
13781372
mutex_lock(&process_info->lock);
13791373
process_info->n_vms--;

drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void amdgpu_bo_list_free_rcu(struct rcu_head *rcu)
4040
{
4141
struct amdgpu_bo_list *list = container_of(rcu, struct amdgpu_bo_list,
4242
rhead);
43-
43+
mutex_destroy(&list->bo_list_mutex);
4444
kvfree(list);
4545
}
4646

@@ -136,6 +136,7 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
136136

137137
trace_amdgpu_cs_bo_status(list->num_entries, total_size);
138138

139+
mutex_init(&list->bo_list_mutex);
139140
*result = list;
140141
return 0;
141142

drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ struct amdgpu_bo_list {
4747
struct amdgpu_bo *oa_obj;
4848
unsigned first_userptr;
4949
unsigned num_entries;
50+
51+
/* Protect access during command submission.
52+
*/
53+
struct mutex bo_list_mutex;
5054
};
5155

5256
int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
519519
return r;
520520
}
521521

522+
mutex_lock(&p->bo_list->bo_list_mutex);
523+
522524
/* One for TTM and one for the CS job */
523525
amdgpu_bo_list_for_each_entry(e, p->bo_list)
524526
e->tv.num_shared = 2;
@@ -651,6 +653,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
651653
kvfree(e->user_pages);
652654
e->user_pages = NULL;
653655
}
656+
mutex_unlock(&p->bo_list->bo_list_mutex);
654657
}
655658
return r;
656659
}
@@ -690,9 +693,11 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
690693
{
691694
unsigned i;
692695

693-
if (error && backoff)
696+
if (error && backoff) {
694697
ttm_eu_backoff_reservation(&parser->ticket,
695698
&parser->validated);
699+
mutex_unlock(&parser->bo_list->bo_list_mutex);
700+
}
696701

697702
for (i = 0; i < parser->num_post_deps; i++) {
698703
drm_syncobj_put(parser->post_deps[i].syncobj);
@@ -832,12 +837,16 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
832837
continue;
833838

834839
r = amdgpu_vm_bo_update(adev, bo_va, false);
835-
if (r)
840+
if (r) {
841+
mutex_unlock(&p->bo_list->bo_list_mutex);
836842
return r;
843+
}
837844

838845
r = amdgpu_sync_fence(&p->job->sync, bo_va->last_pt_update);
839-
if (r)
846+
if (r) {
847+
mutex_unlock(&p->bo_list->bo_list_mutex);
840848
return r;
849+
}
841850
}
842851

843852
r = amdgpu_vm_handle_moved(adev, vm);
@@ -1278,6 +1287,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
12781287

12791288
ttm_eu_fence_buffer_objects(&p->ticket, &p->validated, p->fence);
12801289
mutex_unlock(&p->adev->notifier_lock);
1290+
mutex_unlock(&p->bo_list->bo_list_mutex);
12811291

12821292
return 0;
12831293

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
16531653
#if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
16541654
adev->dm.crc_rd_wrk = amdgpu_dm_crtc_secure_display_create_work();
16551655
#endif
1656-
if (dc_enable_dmub_notifications(adev->dm.dc)) {
1656+
if (dc_is_dmub_outbox_supported(adev->dm.dc)) {
16571657
init_completion(&adev->dm.dmub_aux_transfer_done);
16581658
adev->dm.dmub_notify = kzalloc(sizeof(struct dmub_notification), GFP_KERNEL);
16591659
if (!adev->dm.dmub_notify) {
@@ -1689,6 +1689,13 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
16891689
goto error;
16901690
}
16911691

1692+
/* Enable outbox notification only after IRQ handlers are registered and DMUB is alive.
1693+
* It is expected that DMUB will resend any pending notifications at this point, for
1694+
* example HPD from DPIA.
1695+
*/
1696+
if (dc_is_dmub_outbox_supported(adev->dm.dc))
1697+
dc_enable_dmub_outbox(adev->dm.dc);
1698+
16921699
/* create fake encoders for MST */
16931700
dm_dp_create_fake_mst_encoders(adev);
16941701

@@ -2678,9 +2685,6 @@ static int dm_resume(void *handle)
26782685
*/
26792686
link_enc_cfg_copy(adev->dm.dc->current_state, dc_state);
26802687

2681-
if (dc_enable_dmub_notifications(adev->dm.dc))
2682-
amdgpu_dm_outbox_init(adev);
2683-
26842688
r = dm_dmub_hw_init(adev);
26852689
if (r)
26862690
DRM_ERROR("DMUB interface failed to initialize: status=%d\n", r);
@@ -2698,6 +2702,11 @@ static int dm_resume(void *handle)
26982702
}
26992703
}
27002704

2705+
if (dc_is_dmub_outbox_supported(adev->dm.dc)) {
2706+
amdgpu_dm_outbox_init(adev);
2707+
dc_enable_dmub_outbox(adev->dm.dc);
2708+
}
2709+
27012710
WARN_ON(!dc_commit_state(dm->dc, dc_state));
27022711

27032712
dm_gpureset_commit_state(dm->cached_dc_state, dm);
@@ -2719,13 +2728,15 @@ static int dm_resume(void *handle)
27192728
/* TODO: Remove dc_state->dccg, use dc->dccg directly. */
27202729
dc_resource_state_construct(dm->dc, dm_state->context);
27212730

2722-
/* Re-enable outbox interrupts for DPIA. */
2723-
if (dc_enable_dmub_notifications(adev->dm.dc))
2724-
amdgpu_dm_outbox_init(adev);
2725-
27262731
/* Before powering on DC we need to re-initialize DMUB. */
27272732
dm_dmub_hw_resume(adev);
27282733

2734+
/* Re-enable outbox interrupts for DPIA. */
2735+
if (dc_is_dmub_outbox_supported(adev->dm.dc)) {
2736+
amdgpu_dm_outbox_init(adev);
2737+
dc_enable_dmub_outbox(adev->dm.dc);
2738+
}
2739+
27292740
/* power on hardware */
27302741
dc_set_power_state(dm->dc, DC_ACPI_CM_POWER_STATE_D0);
27312742

0 commit comments

Comments
 (0)