On 9/2/2024 3:57 PM, Anatoly Burakov wrote:
Currently, when binding a device to VFIO, the UID/GID for the device will
always stay as system default (`root`). Yet, when running DPDK as non-root
user, one has to change the UID/GID of the device to match the user's
UID/GID to use the device.
This patch adds an option to `dpdk-devbind.py` to change the UID/GID of
the device when binding it to VFIO.
Signed-off-by: Anatoly Burakov <anatoly.bura...@intel.com>
---
<snip>
+def own_one(dev_id, uid, gid):
+ """Set the IOMMU group ownership for a device"""
+ # find IOMMU group for a particular device
+ iommu_grp_base_path = os.path.join("/sys/bus/pci/devices", dev_id,
"iommu_group")
+ try:
+ iommu_grp = os.path.basename(os.readlink(iommu_grp_base_path))
+ # we found IOMMU group, now find the device
+ dev_path = os.path.join("/dev/vfio", iommu_grp)
+ # set the ownership
+ _uid = pwd.getpwnam(uid).pw_uid if uid else -1
+ _gid = grp.getgrnam(gid).gr_gid if gid else -1
+ os.chown(dev_path, _uid, _gid)
+ except OSError as err:
+ sys.exit(f"Error: failed to read IOMMU group for {dev_id}: {err}")
On another thought, perhaps sys.exit() here is a bit too drastic... Will
replace with error message in v2
--
Thanks,
Anatoly