Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions drivers/accel/amdxdna/amdxdna_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ void *amdxdna_cmd_get_payload(struct amdxdna_gem_obj *abo, u32 *size)
else
num_masks = 1 + FIELD_GET(AMDXDNA_CMD_EXTRA_CU_MASK, cmd->header);

if (abo->mem.size < offsetof(struct amdxdna_cmd, data[num_masks]))

@houlz0507 houlz0507 Jun 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abo->mem.size is 4K aligned. So it will never smaller than offsetof(struct amdxdna_cmd, data[num_masks]).
How about adding a comment to avoid the future AI scans?

return NULL;
Comment thread
saifuddin-xilinx marked this conversation as resolved.

if (size) {
count = FIELD_GET(AMDXDNA_CMD_COUNT, cmd->header);
if (unlikely(count <= num_masks ||
Expand Down Expand Up @@ -195,6 +198,8 @@ int amdxdna_cmd_set_error(struct amdxdna_gem_obj *abo,

if (amdxdna_cmd_get_op(abo) == ERT_CMD_CHAIN) {
cc = amdxdna_cmd_get_payload(abo, NULL);
if (!cc)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, cmd != NULL and size == NULL. So amdxdna_cmd_get_payload() will never return NULL, correct?

return -ENOMEM;
cc->error_index = (cmd_idx < cc->command_count) ? cmd_idx : 0;
abo = amdxdna_gem_get_obj(client, cc->data[0], AMDXDNA_BO_SHARE);
if (!abo)
Expand Down
2 changes: 2 additions & 0 deletions src/driver/amdxdna/aie4_hwctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,8 @@ static int submit_one_cmd(struct amdxdna_ctx *ctx,
}

dpu = amdxdna_cmd_get_payload(cmd_abo, NULL);
if (!dpu)
return -ENOMEM;
chained = dpu->chained;
if (chained >= HSA_MAX_LEVEL1_INDIRECT_ENTRIES) {
XDNA_ERR(xdna, "Invalid DPU data");
Expand Down
3 changes: 3 additions & 0 deletions src/driver/amdxdna/amdxdna_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ amdxdna_cmd_get_payload(struct amdxdna_gem_obj *abo, u32 *size)
else
num_masks = 1 + FIELD_GET(AMDXDNA_CMD_EXTRA_CU_MASK, cmd->header);

if (abo->mem.size < offsetof(struct amdxdna_cmd, data[num_masks]))
return NULL;
Comment thread
saifuddin-xilinx marked this conversation as resolved.

if (size) {
count = FIELD_GET(AMDXDNA_CMD_COUNT, cmd->header);
if (unlikely(count <= num_masks ||
Expand Down
3 changes: 2 additions & 1 deletion src/driver/amdxdna/ve2_hwctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ static inline void ve2_hwctx_job_release_locked(struct amdxdna_ctx *hwctx,
op = amdxdna_cmd_get_op(cmd_bo);
if (op == ERT_CMD_CHAIN) {
cmd_chain = amdxdna_cmd_get_payload(cmd_bo, NULL);
cmd_cnt = cmd_chain->command_count;
if (cmd_chain)
cmd_cnt = cmd_chain->command_count;
}
hwctx->completed += cmd_cnt;

Expand Down