Skip to content

Commit 89ff453

Browse files
committed
accel/amdxdna: Fill invalid payload for failed command
Newer userspace applications may read the payload of a failed command to obtain detailed error information. However, the driver and old firmware versions may not support returning advanced error information. In this case, initialize the command payload with an invalid value so userspace can detect that no detailed error information is available. Fixes: aac2430 ("accel/amdxdna: Add command execution") Reviewed-by: Mario Limonciello (AMD) <[email protected]> Signed-off-by: Lizhi Hou <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 6e3f451 commit 89ff453

3 files changed

Lines changed: 38 additions & 15 deletions

File tree

drivers/accel/amdxdna/aie2_ctx.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@ aie2_sched_resp_handler(void *handle, void __iomem *data, size_t size)
186186
cmd_abo = job->cmd_bo;
187187

188188
if (unlikely(job->job_timeout)) {
189-
amdxdna_cmd_set_state(cmd_abo, ERT_CMD_STATE_TIMEOUT);
189+
amdxdna_cmd_set_error(cmd_abo, job, 0, ERT_CMD_STATE_TIMEOUT);
190190
ret = -EINVAL;
191191
goto out;
192192
}
193193

194194
if (unlikely(!data) || unlikely(size != sizeof(u32))) {
195-
amdxdna_cmd_set_state(cmd_abo, ERT_CMD_STATE_ABORT);
195+
amdxdna_cmd_set_error(cmd_abo, job, 0, ERT_CMD_STATE_ABORT);
196196
ret = -EINVAL;
197197
goto out;
198198
}
@@ -202,7 +202,7 @@ aie2_sched_resp_handler(void *handle, void __iomem *data, size_t size)
202202
if (status == AIE2_STATUS_SUCCESS)
203203
amdxdna_cmd_set_state(cmd_abo, ERT_CMD_STATE_COMPLETED);
204204
else
205-
amdxdna_cmd_set_state(cmd_abo, ERT_CMD_STATE_ERROR);
205+
amdxdna_cmd_set_error(cmd_abo, job, 0, ERT_CMD_STATE_ERROR);
206206

207207
out:
208208
aie2_sched_notify(job);
@@ -244,13 +244,13 @@ aie2_sched_cmdlist_resp_handler(void *handle, void __iomem *data, size_t size)
244244
cmd_abo = job->cmd_bo;
245245

246246
if (unlikely(job->job_timeout)) {
247-
amdxdna_cmd_set_state(cmd_abo, ERT_CMD_STATE_TIMEOUT);
247+
amdxdna_cmd_set_error(cmd_abo, job, 0, ERT_CMD_STATE_TIMEOUT);
248248
ret = -EINVAL;
249249
goto out;
250250
}
251251

252252
if (unlikely(!data) || unlikely(size != sizeof(u32) * 3)) {
253-
amdxdna_cmd_set_state(cmd_abo, ERT_CMD_STATE_ABORT);
253+
amdxdna_cmd_set_error(cmd_abo, job, 0, ERT_CMD_STATE_ABORT);
254254
ret = -EINVAL;
255255
goto out;
256256
}
@@ -270,19 +270,12 @@ aie2_sched_cmdlist_resp_handler(void *handle, void __iomem *data, size_t size)
270270
fail_cmd_idx, fail_cmd_status);
271271

272272
if (fail_cmd_status == AIE2_STATUS_SUCCESS) {
273-
amdxdna_cmd_set_state(cmd_abo, ERT_CMD_STATE_ABORT);
273+
amdxdna_cmd_set_error(cmd_abo, job, fail_cmd_idx, ERT_CMD_STATE_ABORT);
274274
ret = -EINVAL;
275-
goto out;
275+
} else {
276+
amdxdna_cmd_set_error(cmd_abo, job, fail_cmd_idx, ERT_CMD_STATE_ERROR);
276277
}
277-
amdxdna_cmd_set_state(cmd_abo, ERT_CMD_STATE_ERROR);
278278

279-
if (amdxdna_cmd_get_op(cmd_abo) == ERT_CMD_CHAIN) {
280-
struct amdxdna_cmd_chain *cc = amdxdna_cmd_get_payload(cmd_abo, NULL);
281-
282-
cc->error_index = fail_cmd_idx;
283-
if (cc->error_index >= cc->command_count)
284-
cc->error_index = 0;
285-
}
286279
out:
287280
aie2_sched_notify(job);
288281
return ret;

drivers/accel/amdxdna/amdxdna_ctx.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,33 @@ u32 amdxdna_cmd_get_cu_idx(struct amdxdna_gem_obj *abo)
135135
return INVALID_CU_IDX;
136136
}
137137

138+
int amdxdna_cmd_set_error(struct amdxdna_gem_obj *abo,
139+
struct amdxdna_sched_job *job, u32 cmd_idx,
140+
enum ert_cmd_state error_state)
141+
{
142+
struct amdxdna_client *client = job->hwctx->client;
143+
struct amdxdna_cmd *cmd = abo->mem.kva;
144+
struct amdxdna_cmd_chain *cc = NULL;
145+
146+
cmd->header &= ~AMDXDNA_CMD_STATE;
147+
cmd->header |= FIELD_PREP(AMDXDNA_CMD_STATE, error_state);
148+
149+
if (amdxdna_cmd_get_op(abo) == ERT_CMD_CHAIN) {
150+
cc = amdxdna_cmd_get_payload(abo, NULL);
151+
cc->error_index = (cmd_idx < cc->command_count) ? cmd_idx : 0;
152+
abo = amdxdna_gem_get_obj(client, cc->data[0], AMDXDNA_BO_CMD);
153+
if (!abo)
154+
return -EINVAL;
155+
cmd = abo->mem.kva;
156+
}
157+
158+
memset(cmd->data, 0xff, abo->mem.size - sizeof(*cmd));
159+
if (cc)
160+
amdxdna_gem_put_obj(abo);
161+
162+
return 0;
163+
}
164+
138165
/*
139166
* This should be called in close() and remove(). DO NOT call in other syscalls.
140167
* This guarantee that when hwctx and resources will be released, if user

drivers/accel/amdxdna/amdxdna_ctx.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ amdxdna_cmd_get_state(struct amdxdna_gem_obj *abo)
167167

168168
void *amdxdna_cmd_get_payload(struct amdxdna_gem_obj *abo, u32 *size);
169169
u32 amdxdna_cmd_get_cu_idx(struct amdxdna_gem_obj *abo);
170+
int amdxdna_cmd_set_error(struct amdxdna_gem_obj *abo,
171+
struct amdxdna_sched_job *job, u32 cmd_idx,
172+
enum ert_cmd_state error_state);
170173

171174
void amdxdna_sched_job_cleanup(struct amdxdna_sched_job *job);
172175
void amdxdna_hwctx_remove_all(struct amdxdna_client *client);

0 commit comments

Comments
 (0)