Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
24164d6
Add Arch Linux support for xdna-driver
kashif Nov 15, 2025
126c1a5
Update submodule to use kashif/XRT fork arch branch
kashif Nov 16, 2025
dd70faa
Update paths to use build/arch instead of packaging/arch
kashif Nov 16, 2025
5aa2e92
Remove hardcoded paths from PKGBUILD-xrt-plugin
kashif Nov 16, 2025
d6fcf49
Fix PKGBUILD-xrt-plugin path resolution using $startdir
kashif Nov 16, 2025
2951bb8
Merge branch 'main' into arch
kashif Nov 17, 2025
63480a4
move to build/ dir
kashif Nov 18, 2025
16f0a4a
update xrt
kashif Nov 22, 2025
4d9eb85
Merge remote-tracking branch 'upstream/main' into arch
kashif Nov 22, 2025
88d8759
Apply suggestion from @Copilot
kashif Nov 22, 2025
e3650e4
Apply suggestion from @Copilot
kashif Nov 22, 2025
dfef9f3
Update build/PKGBUILD-xrt-plugin
kashif Nov 22, 2025
bfd2b64
Update build/xrt-plugin-amdxdna.install
kashif Nov 22, 2025
4f80d49
Update build/xrt-plugin-amdxdna.install
kashif Nov 22, 2025
ea156e0
Update README.md
kashif Nov 22, 2025
8cf1ba4
Update build/PKGBUILD-xrt-plugin
kashif Nov 24, 2025
a666c05
Switch XRT submodule to official Xilinx/XRT repo @ a07ada1
kashif Nov 28, 2025
b721228
Merge branch 'main' into arch
kashif Nov 28, 2025
3deb899
Fix CMake pkg.cmake: improve Arch comments and else() syntax
kashif Nov 28, 2025
fb81b66
Apply Copilot review suggestions from PR #866
kashif Nov 28, 2025
95a9dac
Merge branch 'main' into arch
kashif Dec 3, 2025
8d9c15d
fix merge
kashif Dec 3, 2025
d76a44b
fix nullglob
kashif Dec 3, 2025
71dd5c6
fix: Let the driver build on ArchLinux too
X-Ryl669 Dec 5, 2025
cde12fc
Merge branch 'main' into arch
kashif Dec 14, 2025
5855900
Merge pull request #1 from X-Ryl669/fix-arch-build-take2
kashif Dec 14, 2025
8e1a43b
Apply Copilot review suggestions
kashif Dec 14, 2025
81179fa
fix: Fix build for kernel built with clang
X-Ryl669 Dec 15, 2025
1e4e1c6
Merge pull request #2 from X-Ryl669/fix-clang-build
kashif Dec 15, 2025
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
34 changes: 26 additions & 8 deletions CMake/pkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ execute_process(
OUTPUT_VARIABLE XDNA_CPACK_LINUX_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND bash -c "source /etc/os-release && echo \"\$ID \$ID_LIKE\""
OUTPUT_VARIABLE XDNA_CPACK_LINUX_PKG_FLAVOR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (EXISTS "/etc/arch-release")
set(XDNA_CPACK_LINUX_PKG_FLAVOR "arch")
else()
execute_process(
COMMAND bash -c "source /etc/os-release && echo \"\$ID \$ID_LIKE\""
OUTPUT_VARIABLE XDNA_CPACK_LINUX_PKG_FLAVOR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
execute_process(
COMMAND echo ${XRT_VERSION_STRING}
COMMAND awk -F. "{print $1}"
Expand Down Expand Up @@ -129,8 +133,22 @@ elseif("${XDNA_CPACK_LINUX_PKG_FLAVOR}" MATCHES "fedora")
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/package/postinst")
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/package/prerm")
endif()
else("${XDNA_CPACK_LINUX_PKG_FLAVOR}" MATCHES "debian")
message(WARNING "Unknown Linux package flavor: ${XDNA_CPACK_LINUX_PKG_FLAVOR}")
endif("${XDNA_CPACK_LINUX_PKG_FLAVOR}" MATCHES "debian")
elseif("${XDNA_CPACK_LINUX_PKG_FLAVOR}" MATCHES "arch")
set(CPACK_GENERATOR "TGZ")
# For Arch Linux, we generate a tarball that can be repackaged into a proper
# Arch package using the provided PKGBUILD. When using the PKGBUILD, install
# hooks handle post-install/pre-remove automatically via pacman.
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
message(STATUS "Arch Linux detected - generating TGZ package")
if(NOT SKIP_KMOD)
message(STATUS "Post-install script: ${CMAKE_CURRENT_BINARY_DIR}/package/postinst")
message(STATUS "Pre-remove script: ${CMAKE_CURRENT_BINARY_DIR}/package/prerm")
message(STATUS "Note: Use the provided PKGBUILD to create an Arch package with proper install hooks")
endif()
else()
message(FATAL_ERROR "Unknown Linux package flavor: ${XDNA_CPACK_LINUX_PKG_FLAVOR}. "
"Supported distributions: Debian/Ubuntu (deb), Fedora/RHEL (rpm), Arch Linux (TGZ). "
"To add support for your distribution, please open an issue at https://github.com/amd/xdna-driver/issues")
endif()

include(CPack)
50 changes: 48 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ cd <root-of-source-tree>
exit
```

### Steps to create release build DEB package:
### Steps to create release build DEB package (Ubuntu/Debian):

``` bash
cd <root-of-source-tree>/build
Expand All @@ -121,7 +121,53 @@ cd ../../build
# To adapt according to your OS & version
sudo apt reinstall ./Release/xrt_plugin.2.19.0_ubuntu22.04-x86_64-amdxdna.deb
```
You will find `xrt_plugin\*-amdxdna.deb` in Release/ folder. This package includes:

### Steps to create release build packages (Arch Linux):

``` bash
cd <root-of-source-tree>

# Install dependencies (requires sudo)
sudo ./tools/amdxdna_deps.sh

# Get submodules
git submodule update --init --recursive

# Build XRT
cd xrt/build
./build.sh -npu -opt

# Build and install XRT packages using pacman
# PKGBUILDs are in xrt/build/arch/
cd arch
makepkg -p PKGBUILD-xrt-base
sudo pacman -U xrt-base-*.pkg.tar.zst

makepkg -p PKGBUILD-xrt-npu
sudo pacman -U xrt-npu-*.pkg.tar.zst

# Build XDNA driver
cd ../../../build
./build.sh -release

# Build and install XDNA plugin package
makepkg -p PKGBUILD-xrt-plugin
sudo pacman -U xrt-plugin-amdxdna-*.pkg.tar.zst

# Configure memory limits (required for NPU access)
sudo bash -c 'echo "* soft memlock unlimited" >> /etc/security/limits.conf'
sudo bash -c 'echo "* hard memlock unlimited" >> /etc/security/limits.conf'
Comment on lines +158 to +159
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

Using bash -c with echo and >> redirection is unnecessarily complex and potentially error-prone. A more robust approach would be to use tee -a or create a dedicated script. Additionally, directly appending to /etc/security/limits.conf without checking for existing entries could create duplicates on repeated runs. Consider: echo "* soft memlock unlimited" | sudo tee -a /etc/security/limits.conf or add a check to prevent duplicates.

Suggested change
sudo bash -c 'echo "* soft memlock unlimited" >> /etc/security/limits.conf'
sudo bash -c 'echo "* hard memlock unlimited" >> /etc/security/limits.conf'
grep -qxF '* soft memlock unlimited' /etc/security/limits.conf || echo '* soft memlock unlimited' | sudo tee -a /etc/security/limits.conf
grep -qxF '* hard memlock unlimited' /etc/security/limits.conf || echo '* hard memlock unlimited' | sudo tee -a /etc/security/limits.conf

Copilot uses AI. Check for mistakes.

# Log out and log back in (or reboot) for memory limit changes to take effect
Comment on lines +158 to +161
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The memory limits configuration could potentially cause issues on multi-user systems or systems with limited memory. Setting unlimited memlock for all users ('*') is very permissive. Consider documenting this in a warning or suggesting a more restrictive approach (e.g., adding specific users to a group with appropriate limits).

Suggested change
sudo bash -c 'echo "* soft memlock unlimited" >> /etc/security/limits.conf'
sudo bash -c 'echo "* hard memlock unlimited" >> /etc/security/limits.conf'
# Log out and log back in (or reboot) for memory limit changes to take effect
# ⚠️ **Warning:** Setting unlimited memlock for all users (`*`) is very permissive and can cause security or stability issues on multi-user or memory-constrained systems.
# It is recommended to restrict this setting to a dedicated group (e.g., `xdna`) and only add users who need NPU access.
# Create a group for XDNA users (if it doesn't exist)
sudo groupadd -f xdna
# Add your user to the group (replace $USER if needed)
sudo usermod -aG xdna $USER
# Set memlock limits for the xdna group
sudo bash -c 'echo "@xdna soft memlock unlimited" >> /etc/security/limits.conf'
sudo bash -c 'echo "@xdna hard memlock unlimited" >> /etc/security/limits.conf'
# Log out and log back in (or reboot) for group and memory limit changes to take effect

Copilot uses AI. Check for mistakes.

Choose a reason for hiding this comment

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

On many system, it's not recommanded to modify /etc/security/limits.conf directly since it's a file that's managed by the packaging system (so modifying it directly implies headaches when updating packages). In many cases (debian, arch, ...) you'll find a /etc/security/limits.d folder where you can save a file, like 99-amdxdna.conf with the same command and they'll survive package upgrade.

I don't know and can't take a decision here if this driver should create a very unrestrictive access to memlock, like it does for permissions to /dev/accel/accel0 file, it's a choice that distribution should make, not us.

Similarly, adding a group and setting permissions for this group is also a distribution specific choice. This PR decided not to mess with system's group, so I don't think this suggestion is good. Also, messing with group is a manual operation since you can't/don't know which user to append to this group. It's very fragile and debug prone, since if you only do the group fiddling for the current user, the driver will suddenly not work for all other users of the system.

If we were to follow this advice, then the same group should be used for /dev/accel/accel0 file too, since it doesn't make sense to have both of them.

So to conclude, the note in the README is, IMHO, the best we can do in the driver and let the distribution package and set permission the way they want.

As for this PR, I'm not sure it's worth adding the 2 lines in PKGBUILD. On one side, if we do, it makes the driver works out-of-the-box, on the other hand, it gives all the users the ability to crash the system. I've tried to put numerical value on my system, but while it works for benchmarks, as soon as I launch a NPU model with Lemonade, it fails because it's too small. So it's definitively a mess and if the users don't put the lines by themselves, they will never know what/where to change so it doesn't crash in lemonade. What do you think @kashif?

```

**Note for Arch Linux users**: The build system generates `.tar.gz` packages which are repackaged into proper Arch packages (`.pkg.tar.zst`) using the provided PKGBUILDs:
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

The note mentions that XRT packages are in xrt/build/arch/, but the instructions in lines 136-147 show building XRT in xrt/build and then moving to a subdirectory arch. It would be clearer to explicitly state that the PKGBUILDs are generated during the XRT build process, or if they're provided by XRT, to mention that upfront.

Suggested change
**Note for Arch Linux users**: The build system generates `.tar.gz` packages which are repackaged into proper Arch packages (`.pkg.tar.zst`) using the provided PKGBUILDs:
**Note for Arch Linux users**: The build system generates `.tar.gz` packages which are repackaged into proper Arch packages (`.pkg.tar.zst`) using PKGBUILDs.
The PKGBUILD files for XRT (`PKGBUILD-xrt-base`, `PKGBUILD-xrt-npu`) and the XDNA driver (`PKGBUILD-xrt-plugin`) are provided by the XRT repository and are available in the following locations after building:

Copilot uses AI. Check for mistakes.
- XRT packages: `xrt/build/arch/` (PKGBUILD-xrt-base, PKGBUILD-xrt-npu)
- XDNA driver: `build/` directory (PKGBUILD-xrt-plugin)

This ensures proper integration with pacman for installation, upgrades, and removal.

You will find `xrt_plugin*-amdxdna.deb` (Ubuntu/Debian) or `xrt_plugin*.tar.gz` (Arch Linux) in Release/ folder. This package includes:
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

The documentation states that the package will be in the "Release/" folder, but for Arch Linux builds, the actual .pkg.tar.zst packages are created in the respective build directories (xrt/build/arch/ and build/). Only the intermediate .tar.gz file is in Release/. Consider clarifying: "You will find the intermediate xrt_plugin*.tar.gz in Release/ folder (which is repackaged into xrt-plugin-amdxdna-*.pkg.tar.zst using the PKGBUILD)."

Suggested change
You will find `xrt_plugin*-amdxdna.deb` (Ubuntu/Debian) or `xrt_plugin*.tar.gz` (Arch Linux) in Release/ folder. This package includes:
You will find the intermediate `xrt_plugin*.tar.gz` (Arch Linux) or `xrt_plugin*-amdxdna.deb` (Ubuntu/Debian) in the Release/ folder. For Arch Linux, this `.tar.gz` is repackaged into the final installable package `xrt-plugin-amdxdna-*.pkg.tar.zst` using the provided PKGBUILD, which can be found in the respective build directories (`xrt/build/arch/` or `build/`). These packages include:

Copilot uses AI. Check for mistakes.
* The `.so` library files, which will be installed into `/opt/xilinx/xrt/lib` folder
* The XDNA driver and DKMS script, which build, install and load
`amdxdna.ko` driver when installing the .DEB package on target machine
Expand Down
43 changes: 43 additions & 0 deletions build/PKGBUILD-xrt-plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Maintainer: Your Name <your@email.com>
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

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

The maintainer information should be updated with actual contact details before distribution.

Suggested change
# Maintainer: Your Name <your@email.com>
# Maintainer: Jane Doe <jane.doe@example.com>

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

The maintainer information is a placeholder. Replace "Your Name <your@email.com>" with actual maintainer details before distribution. This is important for package maintainability and user support.

Suggested change
# Maintainer: Your Name <your@email.com>
# Maintainer: Jane Doe <jane.doe@example.com>

Copilot uses AI. Check for mistakes.
pkgname=xrt-plugin-amdxdna
pkgver=2.21.0
pkgrel=1
pkgdesc="AMD XDNA Driver plugin for Xilinx RunTime"
arch=('x86_64')
url="https://github.com/amd/xdna-driver"
license=('Apache-2.0')
depends=('xrt-base' 'xrt-npu' 'dkms' 'linux-headers')
provides=('xrt-plugin-amdxdna')
conflicts=('amdxdna-driver' 'amdxdna-driver-bin')
install=xrt-plugin-amdxdna.install

# Set this to your xdna-driver build output directory (relative to $startdir, the PKGBUILD's directory)
: ${XDNA_BUILD_DIR:="Release"}
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

The variable assignment : ${XDNA_BUILD_DIR:="Release"} uses the colon null command which is a valid bash idiom for setting defaults. However, this pattern is unconventional in PKGBUILDs. The standard approach would be to use XDNA_BUILD_DIR=${XDNA_BUILD_DIR:-Release} which is clearer and more maintainable.

Suggested change
: ${XDNA_BUILD_DIR:="Release"}
XDNA_BUILD_DIR=${XDNA_BUILD_DIR:-Release}

Copilot uses AI. Check for mistakes.

package() {
cd "$srcdir"

# Extract the tarball directly into the package directory
# The tarball should be at $startdir/$XDNA_BUILD_DIR/xrt_plugin*.tar.gz
# Use nullglob to handle case where no files match the glob pattern
local _nullglob_set=$(shopt -p nullglob)
shopt -s nullglob
local tarballs=("$startdir/${XDNA_BUILD_DIR}"/xrt_plugin*-amdxdna.tar.gz)
$_nullglob_set
if [ ${#tarballs[@]} -eq 0 ] || [ ! -f "${tarballs[0]}" ]; then
error "XDNA plugin tarball not found in ${XDNA_BUILD_DIR}"
error "Please build XDNA driver first: cd build && ./build.sh -release"
return 1
fi

local tarball="${tarballs[0]}"
msg2 "Extracting $tarball"
tar -xzf "$tarball" -C "$pkgdir"

# Copy the install scripts for reference (they'll be called from .install file)
Comment on lines +35 to +37
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

The path $startdir/${XDNA_BUILD_DIR}/package/postinst uses unquoted variable expansion which could fail if XDNA_BUILD_DIR contains spaces or special characters. While "Release" is the default and unlikely to have spaces, it's good practice to quote variable expansions: "$startdir/${XDNA_BUILD_DIR}/package/postinst"

Suggested change
tar -xzf "$tarball" -C "$pkgdir"
# Copy the install scripts for reference (they'll be called from .install file)
install -Dm755 "$startdir/${XDNA_BUILD_DIR}/package/postinst" \
"$pkgdir/opt/xilinx/xrt/share/amdxdna/package/postinst"
install -Dm755 "$startdir/${XDNA_BUILD_DIR}/package/prerm" \

Copilot uses AI. Check for mistakes.
mkdir -p "$pkgdir/opt/xilinx/xrt/share/amdxdna/package"
Comment on lines +35 to +38
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

The install commands lack proper error handling. If the postinst or prerm files don't exist in the expected location, the install command will fail silently or cause the build to fail. Consider adding existence checks before these install commands or using || true if the files are optional.

Suggested change
tar -xzf "$tarball" -C "$pkgdir"
# Copy the install scripts for reference (they'll be called from .install file)
mkdir -p "$pkgdir/opt/xilinx/xrt/share/amdxdna/package"
if [ -f "$startdir/${XDNA_BUILD_DIR}/package/postinst" ]; then
install -Dm755 "$startdir/${XDNA_BUILD_DIR}/package/postinst" \
"$pkgdir/opt/xilinx/xrt/share/amdxdna/package/postinst"
fi
if [ -f "$startdir/${XDNA_BUILD_DIR}/package/prerm" ]; then
install -Dm755 "$startdir/${XDNA_BUILD_DIR}/package/prerm" \
"$pkgdir/opt/xilinx/xrt/share/amdxdna/package/prerm"
fi

Copilot uses AI. Check for mistakes.
install -Dm755 "$startdir/${XDNA_BUILD_DIR}/package/postinst" \
"$pkgdir/opt/xilinx/xrt/share/amdxdna/package/postinst"
install -Dm755 "$startdir/${XDNA_BUILD_DIR}/package/prerm" \
"$pkgdir/opt/xilinx/xrt/share/amdxdna/package/prerm"
}
75 changes: 75 additions & 0 deletions build/xrt-plugin-amdxdna.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
post_install() {
echo "Installing AMD XDNA driver via DKMS..."

install_datadir=/opt/xilinx/xrt/share/amdxdna
udev_rules_d=/etc/udev/rules.d
amdxdna_rules_file=99-amdxdna.rules
dracut_conf_d=/etc/dracut.conf.d
dracut_conf_file=amdxdna.dracut.conf

# On systems with dracut, exclude driver from initramfs
if [ -d ${dracut_conf_d} ]; then
if [ ! -f ${dracut_conf_d}/${dracut_conf_file} ]; then
touch ${dracut_conf_d}/${dracut_conf_file}
fi
grep -q '^omit_drivers\+=\" amdxdna \"' "${dracut_conf_d}/${dracut_conf_file}" || echo 'omit_drivers+=" amdxdna "' >> "${dracut_conf_d}/${dracut_conf_file}"
fi

# Install DKMS module
echo "Installing amdxdna Linux kernel module via DKMS..."
if [ ! -x "$install_datadir/dkms_driver.sh" ]; then
echo "Error: $install_datadir/dkms_driver.sh not found or not executable." >&2
return 1
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

The error message is written to stderr but the function returns 1 without properly handling the error. In pacman install hooks, returning non-zero will abort the installation. However, this script appears to be designed to work as a shell script sourced by pacman hooks, where return statements may not behave as expected. Consider using exit 1 instead of return 1 or document the expected behavior more clearly.

Suggested change
return 1
exit 1

Copilot uses AI. Check for mistakes.
fi
"$install_datadir/dkms_driver.sh" --install

# Setup udev rules
echo "Setting up udev rules..."
if [ ! -f ${udev_rules_d}/${amdxdna_rules_file} ]; then
touch ${udev_rules_d}/${amdxdna_rules_file}
fi
grep -q '^KERNEL=="accel\*",DRIVERS=="amdxdna",MODE="0666"$' ${udev_rules_d}/${amdxdna_rules_file} || \
echo 'KERNEL=="accel*",DRIVERS=="amdxdna",MODE="0666"' >> ${udev_rules_d}/${amdxdna_rules_file}
Comment on lines +31 to +32
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

The udev rule sets MODE="0666" which grants read and write access to all users. While this may be intentional for device access, it could pose a security risk by allowing any user to access the NPU device. Consider using GROUP-based permissions with a dedicated group (e.g., "render" or "video") and MODE="0660" instead.

Suggested change
grep -q '^KERNEL=="accel\*",DRIVERS=="amdxdna",MODE="0666"$' ${udev_rules_d}/${amdxdna_rules_file} || \
echo 'KERNEL=="accel*",DRIVERS=="amdxdna",MODE="0666"' >> ${udev_rules_d}/${amdxdna_rules_file}
grep -q '^KERNEL=="accel\*",DRIVERS=="amdxdna",GROUP="video",MODE="0660"$' ${udev_rules_d}/${amdxdna_rules_file} || \
echo 'KERNEL=="accel*",DRIVERS=="amdxdna",GROUP="video",MODE="0660"' >> ${udev_rules_d}/${amdxdna_rules_file}

Copilot uses AI. Check for mistakes.

# Load the kernel module
echo "Loading amdxdna kernel module..."
rmmod amdxdna > /dev/null 2>&1 || true
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

The rmmod amdxdna > /dev/null 2>&1 || true pattern silently ignores all errors, including cases where the module is in use and cannot be unloaded. This could lead to the subsequent modprobe loading the module while stale state exists. Consider checking if the module is loaded first with lsmod | grep -q amdxdna and handling the unload more explicitly, similar to the pre_remove function at line 57.

Suggested change
rmmod amdxdna > /dev/null 2>&1 || true
if lsmod | grep -q "amdxdna"; then
rmmod amdxdna
fi

Copilot uses AI. Check for mistakes.
modprobe amdxdna || echo "Warning: Failed to load amdxdna module. Check dmesg for details."

Comment on lines +37 to +38
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

The error message "Warning: Failed to load amdxdna module. Check dmesg for details." could be more helpful by including the actual error code or suggesting specific troubleshooting steps. Consider capturing the modprobe exit status and including it in the message, or providing common failure reasons (e.g., kernel version mismatch, missing dependencies).

Suggested change
modprobe amdxdna || echo "Warning: Failed to load amdxdna module. Check dmesg for details."
if ! modprobe amdxdna; then
exit_code=$?
echo "Warning: Failed to load amdxdna module (exit code: $exit_code)."
echo "Check 'dmesg' for details. Common reasons for failure:"
echo " - Kernel version mismatch"
echo " - Missing dependencies (run 'depmod -a' and try again)"
echo " - Secure Boot enabled (may block unsigned modules)"
fi

Copilot uses AI. Check for mistakes.
echo "AMD XDNA driver installation complete!"
echo "You can test it with: source /opt/xilinx/xrt/setup.sh && xrt-smi validate"
}

post_upgrade() {
post_install
}

pre_remove() {
echo "Removing AMD XDNA driver..."

install_datadir=/opt/xilinx/xrt/share/amdxdna
udev_rules_d=/etc/udev/rules.d
amdxdna_rules_file=99-amdxdna.rules
dracut_conf_d=/etc/dracut.conf.d
dracut_conf_file=amdxdna.dracut.conf

# Unload kernel module
if lsmod | grep -q "amdxdna"; then
rmmod amdxdna
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

The rmmod amdxdna command has no error handling. If the module is in use or fails to unload for any reason, the script will fail silently or abort. Consider adding error handling with a descriptive message: rmmod amdxdna || echo "Warning: Failed to unload amdxdna module. It may be in use." This is especially important during package removal when users need to understand why the removal failed.

Suggested change
rmmod amdxdna
rmmod amdxdna || echo "Warning: Failed to unload amdxdna module. It may be in use."

Copilot uses AI. Check for mistakes.
fi

# Remove dracut config
if [ -f ${dracut_conf_d}/${dracut_conf_file} ]; then
rm -f ${dracut_conf_d}/${dracut_conf_file}
fi

# Remove udev rules
if [ -f ${udev_rules_d}/${amdxdna_rules_file} ]; then
rm -f ${udev_rules_d}/${amdxdna_rules_file}
fi

# Remove DKMS module
$install_datadir/dkms_driver.sh --remove
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

The DKMS removal script is called without error handling or existence check, unlike the installation which checks for the script's existence (line 20-23). If the script doesn't exist or fails, the removal will abort with an unclear error. Consider adding: if [ -x "$install_datadir/dkms_driver.sh" ]; then "$install_datadir/dkms_driver.sh" --remove || echo "Warning: Failed to remove DKMS module"; fi

Suggested change
$install_datadir/dkms_driver.sh --remove
if [ -x "$install_datadir/dkms_driver.sh" ]; then
"$install_datadir/dkms_driver.sh" --remove || echo "Warning: Failed to remove DKMS module"
fi

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

Missing quotes around variable expansion. On line 72, $install_datadir/dkms_driver.sh should be quoted as "$install_datadir/dkms_driver.sh" to handle paths with spaces safely and to be consistent with line 20 and 24 where the same variable is properly quoted.

Suggested change
$install_datadir/dkms_driver.sh --remove
"$install_datadir/dkms_driver.sh" --remove

Copilot uses AI. Check for mistakes.

echo "AMD XDNA driver removed!"
}
9 changes: 8 additions & 1 deletion src/driver/amdxdna/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ endif
XDNA_DRIVER_VERSION ?= 2.21.0
XDNA_DATE ?= $(shell date +%Y%m%d)
XDNA_HASH ?= $(shell git rev-parse HEAD)
# Detect if kernel was built with Clang - check /proc/config.gz first, then /boot/config-*
USE_LLVM ?= $(shell \
if [ -e /proc/config.gz ]; then \
zgrep -q "CONFIG_CC_IS_CLANG=y" /proc/config.gz 2>/dev/null && echo -n "LLVM=1"; \
elif [ -e /boot/config-$(KERNEL_VER) ]; then \
grep -q "CONFIG_CC_IS_CLANG=y" /boot/config-$(KERNEL_VER) 2>/dev/null && echo -n "LLVM=1"; \
fi)

ifndef MODULE_VER_STR
MODULE_VER_STR := $(XDNA_DRIVER_VERSION)_$(XDNA_DATE),$(XDNA_HASH)
Expand All @@ -49,7 +56,7 @@ endif
DEFINES += -DMODULE_VER_STR='\"$(MODULE_VER_STR)\"'

modules:
$(MAKE) -C $(KERNEL_SRC) M=$(SRC_DIR) CFLAGS_MODULE="$(DEFINES)" OFT_CONFIG_AMDXDNA_PCI=$(PCI) OFT_CONFIG_AMDXDNA_OF=$(OF) modules
$(MAKE) -C $(KERNEL_SRC) M=$(SRC_DIR) CFLAGS_MODULE="$(DEFINES)" OFT_CONFIG_AMDXDNA_PCI=$(PCI) OFT_CONFIG_AMDXDNA_OF=$(OF) $(USE_LLVM) modules

modules_install:
$(MAKE) -C $(KERNEL_SRC) M=$(SRC_DIR) modules_install
Expand Down
3 changes: 1 addition & 2 deletions src/driver/amdxdna/aie2_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,7 @@ static int aie2_get_coredump(struct amdxdna_client *client, struct amdxdna_drm_g
static int aie2_get_array_hwctx(struct amdxdna_client *client, struct amdxdna_drm_get_array *args)
{
struct amdxdna_dev *xdna = client->xdna;
struct amdxdna_drm_hwctx_entry input = {};
struct amdxdna_drm_hwctx_entry *tmp;
int ctx_limit, ctx_cnt, ret;
u32 buf_size;
Expand Down Expand Up @@ -1551,8 +1552,6 @@ static int aie2_get_array_hwctx(struct amdxdna_client *client, struct amdxdna_dr

break;
case DRM_AMDXDNA_HW_CONTEXT_BY_ID:
struct amdxdna_drm_hwctx_entry input = {};

ret = amdxdna_drm_copy_array_from_user(args, &input, sizeof(input), 1);
if (ret)
goto exit;
Expand Down
9 changes: 8 additions & 1 deletion src/driver/tools/configure_kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ try_compile() {
tmpdir=$(mktemp -d /tmp/conftest-XXXXXX)
conftest_c="$tmpdir/conftest.c"
conftest_mk="$tmpdir/Makefile"
USE_LLVM=""
if [ -e /proc/config.gz ]; then
USE_LLVM=$(zgrep -q "CONFIG_CC_IS_CLANG=y" /proc/config.gz 2>/dev/null && echo -n "LLVM=1");
elif [ -e /boot/config-$(KERNEL_VER) ]; then
USE_LLVM=$(grep -q "CONFIG_CC_IS_CLANG=y" /boot/config-$(KERNEL_VER) 2>/dev/null && echo -n "LLVM=1");
Comment on lines +47 to +48
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The variable KERNEL_VER is used but never defined in this script. This will cause the shell to expand it as an empty string, making the path "/boot/config-" which will likely not exist. You should either define KERNEL_VER (e.g., KERNEL_VER=$(uname -r)) or use the expansion directly in the path like /boot/config-$(uname -r).

Suggested change
elif [ -e /boot/config-$(KERNEL_VER) ]; then
USE_LLVM=$(grep -q "CONFIG_CC_IS_CLANG=y" /boot/config-$(KERNEL_VER) 2>/dev/null && echo -n "LLVM=1");
elif [ -e /boot/config-$(uname -r) ]; then
USE_LLVM=$(grep -q "CONFIG_CC_IS_CLANG=y" /boot/config-$(uname -r) 2>/dev/null && echo -n "LLVM=1");

Copilot uses AI. Check for mistakes.

Choose a reason for hiding this comment

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

My mistake, it's right.

fi


# Minimal Kbuild for an external module
cat > "$conftest_mk" <<EOF
Expand All @@ -58,7 +65,7 @@ EOF
cat >> "$conftest_c"

# Now build it like your real driver
if make -s -C "$KERNEL_SRC" M="$tmpdir" modules >/dev/null 2>&1; then
if make -s -C "$KERNEL_SRC" M="$tmpdir" modules "$USE_LLVM" >/dev/null 2>&1; then
echo "#define $macro 1" >> "$OUT"
echo ">>> + $macro: yes" >&2
else
Expand Down
2 changes: 2 additions & 0 deletions tools/amdxdna_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ if [ -x "$(command -v apt-get)" ]; then
apt-get install -y jq
elif [ -x "$(command -v dnf)" ]; then
dnf install -y jq
elif [ -x "$(command -v pacman)" ]; then
pacman -S --needed --noconfirm jq
fi

$SCRIPT_DIR/../xrt/src/runtime_src/tools/scripts/xrtdeps.sh