Skip to content

Commit

Permalink
Fix race in obtaining index of CU (Xilinx#7522)
Browse files Browse the repository at this point in the history
Add lock around accessing cu index in core device.

Fixes a potential race when a thread access cu indices while another
thread is updating the indices after an xclbin was loaded.  The race
can only occur when multiple hardware contexts are used because CU
contexts are managed per hardware context by XRT coreutil.

xrt_core::device::get_cuidx lazy gathers cu indices from KMD when a
thread tries to open a CU as part of creating a kernel object.  The
first thread to access the index of a CU can cause all indices to be
updated if the requested CU is not yet registered.
  • Loading branch information
stsoe authored Apr 27, 2023
1 parent d7a2e03 commit 1ea7373
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/runtime_src/core/common/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ const std::vector<uint64_t>&
device::
get_cus() const
{
// This function returns a reference to internal data
// that is modified when an xclbin is loaded. Normally
// not an issue since only single xclbin is supported
// when using this API.
if (m_cu2idx.size() > 1)
throw error(std::errc::not_supported, "multiple xclbins not supported");

Expand All @@ -358,6 +362,7 @@ cuidx_type
device::
get_cuidx(slot_id slot, const std::string& cuname) const
{
std::lock_guard lk(m_mutex);
auto slot_itr = m_cu2idx.find(slot);
if (slot_itr == m_cu2idx.end())
throw error(EINVAL, "No such compute unit '" + cuname + "'");
Expand Down

0 comments on commit 1ea7373

Please sign in to comment.