8000 Added debug queue support by khalshai-xilinx · Pull Request #1054 · amd/xdna-driver · GitHub
[go: up one dir, main page]

Skip to content

Added debug queue support#1054

Open
khalshai-xilinx wants to merge 10 commits intoamd:mainfrom
khalshai-xilinx:debug_queue_support
Open

Added debug queue support#1054
khalshai-xilinx wants to merge 10 commits intoamd:mainfrom
khalshai-xilinx:debug_queue_support

Conversation

@khalshai-xilinx
Copy link
Contributor
@khalshai-xilinx khalshai-xilinx commented Feb 6, 2026

Description
Added debug queue support for ve2 driver.
Merged common functions between HSA queue and DBG queue

TODO
Need to integrate the EXIT_DBG_QUEUE API once available.
Need to work on multi threaded scenario.

Copilot AI review requested due to automatic review settings February 6, 2026 07:14
Copy link
Contributor
< 10BC0 svg aria-hidden="true" height="12" viewBox="0 0 16 16" version="1.1" width="12" data-view-component="true" class="octicon octicon-copilot"> Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds debug queue support to the ve2 driver, enabling debug operations through a dedicated queue mechanism similar to the existing HSA queue implementation.

Changes:

  • Introduced a new debug queue structure (ve2_dbg_queue) with initialization, submission, and cleanup functions
  • Refactored common queue operations into generic functions that work with both HSA and debug queues
  • Updated AIE read/write operations to use the debug queue instead of direct partition read/write

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/driver/amdxdna/ve2_of.h Added debug queue fields to context structure
src/driver/amdxdna/ve2_mgmt.h Added function declaration for debug queue submission
src/driver/amdxdna/ve2_mgmt.c Updated partition setup to initialize debug queue addresses
src/driver/amdxdna/ve2_hwctx.c Implemented debug queue creation, submission, and refactored common queue functions
src/driver/amdxdna/ve2_host_queue.h Added debug queue structures and command type definitions
src/driver/amdxdna/ve2_debug.c Modified AIE read/write to use debug queue operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor
Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor
Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor
Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor
Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor
@chvamshi-xilinx chvamshi-xilinx left a comment

Choose a reason for hiding this comment

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

As discussed , PLease make the debug queue changes under a module param .

Copy link
Contributor
Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor
Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +588 to +609
hdr = &pkt->xrt_header;
slot_id = slot_id & (dbg_queue->dbg_queue_p->hq_header.capacity - 1);

hdr->common_header.opcode = opcode;
hdr->completion_signal =
(u64)(dbg_queue->hq_complete.hqc_dma_addr + slot_id * sizeof(u64));

XDNA_DBG(xdna, "Debug Queue packet opcode: %u", pkt->xrt_header.common_header.opcode);

hdr->common_header.count = sizeof(struct rw_mem);
hdr->common_header.distribute = 0;
hdr->common_header.indirect = 0;

ebp = (struct rw_mem *)pkt->data;
ebp->aie_addr = aie_addr;
ebp->host_addr_high = upper_32_bits(paddr);
ebp->host_addr_low = lower_32_bits(paddr);
ebp->length = length;

ve2_queue_commit_slot(&dbg_queue->hq_lock, &dbg_queue->reserved_write_index,
&dbg_queue->dbg_queue_p->hq_header, dbg_queue->dbg_queue_p->hq_entry,
&dbg_queue->hq_complete, slot_id);
Copy link
Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

The slot_id is being recalculated to slot_idx at line 588, but then this modified value is passed to ve2_queue_commit_slot at line 609. However, ve2_queue_commit_slot expects the original slot (sequence number), not slot_idx, as it performs its own modulo operation at line 212. This will cause ve2_queue_commit_slot to operate on the wrong slot.

Save the original slot_id in a separate variable before line 588, use slot_idx for the completion_signal calculation at line 593, and pass the original slot_id (not slot_idx) to ve2_queue_commit_slot at line 609.

Copilot uses AI. Check for mistakes.
Comment on lines +1501 to +1506
free_hsa_queue:
ve2_free_queue(xdna, "HSA", (void **)&hwctx->priv->hwctx_hsa_queue.hsa_queue_p,
&hwctx->priv->hwctx_hsa_queue.alloc_dev,
&hwctx->priv->hwctx_hsa_queue.hsa_queue_mem.dma_addr,
&hwctx->priv->hwctx_hsa_queue.hq_lock,
sizeof(struct hsa_queue) + sizeof(u64) * HOST_QUEUE_ENTRY);
Copy link
Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

If enable_debug_queue is true and ve2_create_dbg_queue fails, the error path at free_hsa_queue does not clean up the event_timer that was conditionally set up if enable_polling is true. If both enable_polling and enable_debug_queue are enabled and dbg queue creation fails, the event_timer will not be stopped, leading to a use-after-free when the timer fires after cleanup_priv frees the priv structure.

Add a conditional del_timer_sync for event_timer in the free_hsa_queue error path if enable_polling is true.

Copilot uses AI. Check for mistakes.
// hq_lock protects [read | write]_index and reserved_write_index
struct mutex hq_lock;
u64 reserved_write_index;
/* Device used for host queue allocation */
Copy link
Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

The comment for the alloc_dev field has incorrect indentation - it has an extra leading tab compared to the field declaration below it. The comment should align with the field it describes.

Suggested change
/* Device used for host queue allocation */
/* Device used for host queue allocation */

Copilot uses AI. Check for mistakes.
XDNA_ERR(xdev, "Size (%zu) must be a multiple of 4 bytes", size);
return -EINVAL;
}
/*Allocate phy memory and pass it to submit function*/
Copy link
Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

Missing space after the comment start marker. The comment should be formatted as "/* Allocate phy memory..." with a space after the opening /* for consistency with kernel coding style.

Suggested change
/*Allocate phy memory and pass it to submit function*/
/* Allocate phy memory and pass it to submit function */

Copilot uses AI. Check for mistakes.
cleanup_slot_id:
/* Reset slot to INVALID after completion (success, timeout, or interruption) */
mutex_lock(&dbg_queue->hq_lock);
dbg_queue->hq_complete.hqc_mem[slot_id] = ERT_CMD_STATE_INVALID;
Copy link
Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

After line 588 recalculates slot_id to be the slot index, line 635 uses this slot_id to reset the completion state. However, this is inconsistent - the slot_id used here should match what was passed to ve2_queue_commit_slot. Since there's a bug at line 609 where the wrong slot_id is passed to commit, this cleanup also operates on the wrong slot. This should use the original slot sequence number modulo capacity to get the correct slot_idx.

Suggested change
dbg_queue->hq_complete.hqc_mem[slot_id] = ERT_CMD_STATE_INVALID;
{
u32 slot_idx = slot_id % dbg_queue->capacity;
dbg_queue->hq_complete.hqc_mem[slot_idx] = ERT_CMD_STATE_INVALID;
}

Copilot uses AI. Check for mistakes.
XDNA_ERR(xdna, "Debug queue is not initialized");
return -EINVAL;
}
dbg_queue = (struct ve2_dbg_queue *)&ve2_ctx->hwctx_dbg_queue;
Copy link
Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

The cast from &ve2_ctx->hwctx_dbg_queue (which has type struct ve2_dbg_queue *) to struct ve2_dbg_queue * is unnecessary. The address-of operator already returns a pointer to the correct type, so the cast can be removed.

Suggested change
dbg_queue = (struct ve2_dbg_queue *)&ve2_ctx->hwctx_dbg_queue;
dbg_queue = &ve2_ctx->hwctx_dbg_queue;

Copilot uses AI. Check for mistakes.
Signed-off-by: Khaleel Shaik <khaleel.shaik@amd.com>
Signed-off-by: Khaleel Shaik <khaleel.shaik@amd.com>
Signed-off-by: Khaleel Shaik <khaleel.shaik@amd.com>
Signed-off-by: Khaleel Shaik <khaleel.shaik@amd.com>
Signed-off-by: Khaleel Shaik <khaleel.shaik@amd.com>
Signed-off-by: Khaleel Shaik <khaleel.shaik@amd.com>
Signed-off-by: Khaleel Shaik <khaleel.shaik@amd.com>
Signed-off-by: Khaleel Shaik <khaleel.shaik@amd.com>
Signed-off-by: Khaleel Shaik <khaleel.shaik@amd.com>
Signed-off-by: Khaleel Shaik <khaleel.shaik@amd.com>
Copilot AI review requested due to automatic review settings February 20, 2026 00:07
Copy link
Contributor
Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1495 to +1500
free_hsa_queue:
ve2_free_queue(xdna, "HSA", (void **)&hwctx->priv->hwctx_hsa_queue.hsa_queue_p,
&hwctx->priv->hwctx_hsa_queue.alloc_dev,
&hwctx->priv->hwctx_hsa_queue.hsa_queue_mem.dma_addr,
&hwctx->priv->hwctx_hsa_queue.hq_lock,
sizeof(struct hsa_queue) + sizeof(u64) * HOST_QUEUE_ENTRY);
Copy link
Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

If enable_polling is true and ve2_create_dbg_queue fails, the event_timer (started at line 1466) is not cleaned up in the free_hsa_queue error path. This will leave a timer running that references freed memory, leading to a potential use-after-free. Add del_timer_sync for event_timer in the free_hsa_queue label before freeing the HSA queue, conditional on enable_polling being true.

Copilot uses AI. Check for mistakes.
/* Write to AIE memory */
ret = ve2_partition_write(aie_dev, footer.col, footer.row, footer.addr,
footer.size, local_buf);
//TODO This is temporary fix to exit the debug queue.
Copy link
Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The TODO comment style is inconsistent with Linux kernel coding style. The comment should be formatted as "/* TODO: This is temporary fix to exit the debug queue. */" with a space after the comment delimiter, colon after TODO, and proper ending.

Suggested change
//TODO This is temporary fix to exit the debug queue.
/* TODO: This is temporary fix to exit the debug queue. */

Copilot uses AI. Check for mistakes.
int nslots = HOST_QUEUE_ENTRY;
dma_addr_t dma_handle;
size_t alloc_size;
int r;
Copy link
Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The loop counter 'r' is declared as 'int' but should be 'unsigned int' to match the type used in ve2_create_host_queue (line 652) and to match the unsigned comparison with MAX_MEM_REGIONS. This ensures consistency and avoids potential signed/unsigned comparison issues.

Suggested change
int r;
unsigned int r;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0