Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 29 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@
[![Test](https://github.com/xnvme/devbind/actions/workflows/test.yml/badge.svg)](https://github.com/xnvme/devbind/actions/workflows/test.yml)

`devbind` is a small CLI for binding and unbinding PCI devices to a
chosen kernel driver via sysfs. The typical use is moving a device
between its native driver (e.g. `nvme`) and a user space driver
framework (`vfio-pci`, `uio_pci_generic`) for DPDK/SPDK and xNVMe/uPCIe
workloads. `devbind --list` also reports the process `RLIMIT_MEMLOCK`
and warns when the soft limit is below the 64 MiB threshold those
frameworks inherit.
chosen kernel driver. The typical use is moving a device between its
native driver (e.g. `nvme`) and a user space driver framework for
DPDK/SPDK and xNVMe/uPCIe workloads. `devbind --list` also reports the
process `RLIMIT_MEMLOCK` and warns when the soft limit is below the
64 MiB threshold those frameworks inherit.

Both **Linux** and **FreeBSD** are supported; the platform-specific
operations are handled by a backend selected at runtime:

| | Linux | FreeBSD |
|---|---|---|
| enumerate / inspect | `lspci`, sysfs | `pciconf -l`, `camcontrol` |
| user space framework | `vfio-pci`, `uio_pci_generic` | `nic_uio` |
| unbind | sysfs `driver/unbind` | `devctl detach` |
| bind | sysfs `drivers/<drv>/bind` | `devctl set driver` |

(The Linux-only `iommugroup` is reported as `None` on FreeBSD.)

## Install

Expand All @@ -33,7 +44,7 @@ curl -fsSL https://raw.githubusercontent.com/xnvme/devbind/main/src/devbind/devb
devbind --print-completion bash > ~/.local/share/bash-completion/completions/devbind
```

Open a new shell (or `source` the file) and tab-completion is live: `devbind --bind <TAB>` lists `nvme vfio-pci vfio-noiommu uio_pci_generic`.
Open a new shell (or `source` the file) and tab-completion is live: `devbind --bind <TAB>` lists `nvme vfio-pci vfio-noiommu uio_pci_generic nic_uio`.

## Usage

Expand All @@ -43,7 +54,7 @@ usage: devbind [-h] [--version] [--classcode CLASSCODE] [--device DEVICE]
[--list] [--unbind] [--bind BIND] [--verbose]
[--print-completion SHELL]

Inspect and control PCI device-driver binding in Linux
Inspect and control PCI device-driver binding on Linux and FreeBSD

options:
-h, --help show this help message and exit
Expand All @@ -55,8 +66,8 @@ options:
association.
--unbind Unbind if bound.
--bind BIND Unbind if bound; then bind to the given driver-name
[nvme, vfio-pci, uio_pci_generic] or to a .ko driver
file (path)
[nvme, vfio-pci, uio_pci_generic, nic_uio] or to a
driver file (path)
--verbose Enable verbose logging
--print-completion SHELL
Print shell completion script to stdout and exit
Expand All @@ -71,6 +82,14 @@ sudo devbind --bind nvme --device 0000:01:00.0 # rebind to the native driv
sudo devbind --unbind --device 0000:01:00.0 # unbind without rebinding
```

On FreeBSD, bind to `nic_uio` instead of `vfio-pci`/`uio_pci_generic`
(`--device` always takes the `domain:bus:device.function` form `0000:01:00.0` on both platforms):

```
sudo devbind --bind nic_uio --device 0000:01:00.0 # hand device to DPDK/SPDK
sudo devbind --bind nvme --device 0000:01:00.0 # rebind to the native driver
```

`devbind --list` sample output (stock WSL host, no NVMe devices visible):

```
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "devbind"
dynamic = ["version"]
description = "Inspect and control PCI device-driver binding in Linux"
description = "Inspect and control PCI device-driver binding on Linux and FreeBSD"
readme = "README.md"
license = "BSD-3-Clause"
requires-python = ">=3.10"
Expand All @@ -18,6 +18,7 @@ classifiers = [
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"Operating System :: POSIX :: Linux",
"Operating System :: POSIX :: BSD :: FreeBSD",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down
Loading