MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / register_vfio_new_id

Function register_vfio_new_id

crates/openshell-vfio/src/bind.rs:32–59  ·  view source on GitHub ↗

Best-effort registration of a device's vendor:device ID with `vfio-pci`. Some kernel configurations require the ID to be pre-registered in `/sys/bus/pci/drivers/vfio-pci/new_id` before `drivers_probe` will bind the device, even when `driver_override` is set. Writing an already registered ID returns `EEXIST`, which we silently ignore.

(sysfs: &SysfsRoot, bdf: &str)

Source from the content-addressed store, hash-verified

30/// the device, even when `driver_override` is set. Writing an already
31/// registered ID returns `EEXIST`, which we silently ignore.
32pub(crate) fn register_vfio_new_id(sysfs: &SysfsRoot, bdf: &str) {
33 let Some(id_str) = vfio_id_string(sysfs, bdf) else {
34 return;
35 };
36
37 let registration = VFIO_ID_REGISTRY.lock().unwrap().register(&id_str);
38
39 if registration != VfioIdRegistration::FirstUser {
40 tracing::debug!(
41 bdf, id = %id_str,
42 "vfio-pci new_id already registered by another device, refcount incremented"
43 );
44 return;
45 }
46
47 let new_id_path = sysfs.vfio_pci_new_id();
48 match write_sysfs(&new_id_path, &id_str) {
49 Ok(()) => {
50 tracing::debug!(bdf, id = %id_str, "registered vfio-pci new_id");
51 }
52 Err(_) => {
53 tracing::debug!(
54 bdf, id = %id_str,
55 "vfio-pci new_id write skipped (already registered or driver not loaded)"
56 );
57 }
58 }
59}
60
61/// Best-effort deregistration of a device's vendor:device ID from `vfio-pci`.
62///

Calls 4

vfio_id_stringFunction · 0.85
write_sysfsFunction · 0.85
vfio_pci_new_idMethod · 0.80
registerMethod · 0.45