Skip to content

Commit 6270ee2

Browse files
committed
accel/amdxdna: Fix NULL pointer dereference of mgmt_chann
mgmt_chann may be set to NULL if the firmware returns an unexpected error in aie2_send_mgmt_msg_wait(). This can later lead to a NULL pointer dereference in aie2_hw_stop(). Fix this by introducing a dedicated helper to destroy mgmt_chann and by adding proper NULL checks before accessing it. Fixes: b87f920 ("accel/amdxdna: Support hardware mailbox") Reviewed-by: Mario Limonciello (AMD) <[email protected]> Signed-off-by: Lizhi Hou <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 2e3649e commit 6270ee2

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

drivers/accel/amdxdna/aie2_message.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@ static int aie2_send_mgmt_msg_wait(struct amdxdna_dev_hdl *ndev,
4040
return -ENODEV;
4141

4242
ret = xdna_send_msg_wait(xdna, ndev->mgmt_chann, msg);
43-
if (ret == -ETIME) {
44-
xdna_mailbox_stop_channel(ndev->mgmt_chann);
45-
xdna_mailbox_destroy_channel(ndev->mgmt_chann);
46-
ndev->mgmt_chann = NULL;
47-
}
43+
if (ret == -ETIME)
44+
aie2_destroy_mgmt_chann(ndev);
4845

4946
if (!ret && *hdl->status != AIE2_STATUS_SUCCESS) {
5047
XDNA_ERR(xdna, "command opcode 0x%x failed, status 0x%x",
@@ -914,6 +911,20 @@ void aie2_msg_init(struct amdxdna_dev_hdl *ndev)
914911
ndev->exec_msg_ops = &legacy_exec_message_ops;
915912
}
916913

914+
void aie2_destroy_mgmt_chann(struct amdxdna_dev_hdl *ndev)
915+
{
916+
struct amdxdna_dev *xdna = ndev->xdna;
917+
918+
drm_WARN_ON(&xdna->ddev, !mutex_is_locked(&xdna->dev_lock));
919+
920+
if (!ndev->mgmt_chann)
921+
return;
922+
923+
xdna_mailbox_stop_channel(ndev->mgmt_chann);
924+
xdna_mailbox_destroy_channel(ndev->mgmt_chann);
925+
ndev->mgmt_chann = NULL;
926+
}
927+
917928
static inline struct amdxdna_gem_obj *
918929
aie2_cmdlist_get_cmd_buf(struct amdxdna_sched_job *job)
919930
{

drivers/accel/amdxdna/aie2_pci.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,7 @@ static void aie2_hw_stop(struct amdxdna_dev *xdna)
330330

331331
aie2_runtime_cfg(ndev, AIE2_RT_CFG_CLK_GATING, NULL);
332332
aie2_mgmt_fw_fini(ndev);
333-
xdna_mailbox_stop_channel(ndev->mgmt_chann);
334-
xdna_mailbox_destroy_channel(ndev->mgmt_chann);
335-
ndev->mgmt_chann = NULL;
333+
aie2_destroy_mgmt_chann(ndev);
336334
drmm_kfree(&xdna->ddev, ndev->mbox);
337335
ndev->mbox = NULL;
338336
aie2_psp_stop(ndev->psp_hdl);
@@ -441,8 +439,7 @@ static int aie2_hw_start(struct amdxdna_dev *xdna)
441439
return 0;
442440

443441
destroy_mgmt_chann:
444-
xdna_mailbox_stop_channel(ndev->mgmt_chann);
445-
xdna_mailbox_destroy_channel(ndev->mgmt_chann);
442+
aie2_destroy_mgmt_chann(ndev);
446443
stop_psp:
447444
aie2_psp_stop(ndev->psp_hdl);
448445
fini_smu:

drivers/accel/amdxdna/aie2_pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ int aie2_get_array_async_error(struct amdxdna_dev_hdl *ndev,
303303

304304
/* aie2_message.c */
305305
void aie2_msg_init(struct amdxdna_dev_hdl *ndev);
306+
void aie2_destroy_mgmt_chann(struct amdxdna_dev_hdl *ndev);
306307
int aie2_suspend_fw(struct amdxdna_dev_hdl *ndev);
307308
int aie2_resume_fw(struct amdxdna_dev_hdl *ndev);
308309
int aie2_set_runtime_cfg(struct amdxdna_dev_hdl *ndev, u32 type, u64 value);

0 commit comments

Comments
 (0)