Skip to content

fix(AIESW-42718,AIESW-42772,AIESW-42780,AIESW-42800): zocl sysfs, copy-BO, aied, and KDS stat safety - #10107

Merged
chvamshi-xilinx merged 4 commits into
Xilinx:masterfrom
ManojTakasi:fix/AIESW-42718
Oct 10, 2026
Merged

chvamshi-xilinx merged 4 commits into
Xilinx:masterfrom
ManojTakasi:fix/AIESW-42718

Conversation

@ManojTakasi

@ManojTakasi ManojTakasi commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Problem solved by the commit

  • AIESW-42718. The zocl sysfs readers read_aie_metadata, read_debug_ip_layout, read_ip_layout, read_connectivity, and read_mem_topology walk every populated PR slot and memcpy up to count bytes per slot. buf advances, but count does not, so a second slot writes past the buffer kernfs allocated for that read().
  • AIESW-42772. zocl_can_dma_performed() checks dst_offset + size and src_offset + size as uint64_t additions. An offset near 2^64 -1 wraps, the check passes, and zocl_copy_bo_async() adds that offset to the buffer-object physical address before DMA.
  • AIESW-42780. aied::poll_aie() reads m_graphs while register_graph() and deregister_graph() insert and erase it. A reallocation or a graph destructor can free memory the poll thread is still using. done was a plain bool shared with the poll thread.
  • AIESW-42800. show_kds_cuctx_stat_raw() walks kds->clients, cu_ctx_list, and hw_ctx_list while holding only cu_mgmt->lock. Those lists are updated under kds->lock and client->lock. A concurrent kds_free_cu_ctx() or kds_free_hw_ctx() can list_del and vfree a node the sysfs walk still dereferences. cu_idx was also used to index xcus[] with no upper bound.

Bug / issue (if any) fixed, which PR introduced the bug, how it was discovered

How problem was solved, alternative solutions (if any) and why they were rejected

  • AIESW-42718. Each reader stops when count is exhausted and subtracts nread after every slot copy. A single helper was rejected so the five existing copy sites stay local and the per-slot offset behavior is unchanged.

  • AIESW-42772. The check is now offset > bo_size || size > bo_size - offset, for both source and destination, before any addition. check_add_overflow() was rejected because the needed condition is "this range lies inside the buffer object," which the compare-before-subtract states directly.

  • AIESW-42780. m_graphs_lock covers register, deregister, the empty check, and the status loop, including getname() and getstatus(). done is std::atomic. std::lock_guard unlocks at the end of its scope. Copying the vector and dropping the lock before getname()/getstatus() was rejected because the graph object can still be destroyed. std::shared_mutex was rejected because the poll thread must exclude deregister for the whole call. On rebase, upstream had renamed Aied to aied; the same lock was applied to m_graphs.

  • AIESW-42800. The walk takes kds->lock around kds->clients and client->lock around each client's lists. cu_mgmt->lock is taken only while reading xcus[], and only after client->lock, because the ioctl path already uses that order. cu_idx >= MAX_CUS is skipped. RCU was rejected because these lists already have mutexes. Holding cu_mgmt->lock and then taking client->lock was rejected because kds_add_context() and kds_del_context() take client->lock and then cu_mgmt->lock.

Risks (if any) associated the changes in the commit

low

What has been tested and how, request additional testing if necessary

Testd on vck190 hw

Documentation impact (if any)

None

ManojTakasi and others added 4 commits October 9, 2026 06:48
Each populated PR slot copied up to the original count into the kernfs buffer. Shrink the remaining budget after every copy so later slots cannot write past it.

Co-authored-by: Cursor <cursoragent@cursor.com>
dst_offset and src_offset are attacker-controlled uint64_t values. Compare each offset to the BO size before adding so a wrapped sum cannot pass the DMA bounds check.

Co-authored-by: Cursor <cursoragent@cursor.com>
pollAIE reads mGraphs while register and deregister mutate it. Hold a mutex around those accesses and publish the shutdown flag with an atomic so the poll thread cannot use a freed graph.

Co-authored-by: Cursor <cursoragent@cursor.com>
show_kds_cuctx_stat_raw walked client and CU-context lists under cu_mgmt->lock, which does not protect those lists. Take kds->lock and client->lock in the same order as the writers, and reject a cu_idx outside xcus[].

Co-authored-by: Cursor <cursoragent@cursor.com>
@ManojTakasi ManojTakasi changed the title Fix/aiesw 42718 fix(AIESW-42718,AIESW-42772,AIESW-42780,AIESW-42800): zocl sysfs, copy-BO, aied, and KDS stat safety Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@chvamshi-xilinx
chvamshi-xilinx merged commit f7dbdc9 into Xilinx:master Oct 10, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants