On Sat, 23 Dec 2023 15:16:12 -0700 Matthew W Carlis <mattc@xxxxxxxxxxxxxxx> wrote: > We often would like to know when a device is unbound or bound > to vfio. Since I have a belief that such events should be > infrequent & in low volume; after this change the driver > will log when it decides to bind and unbind a device. > > vfio-pci doesn't log when it binds to a device or is unbound > from a device. There may be logging from vfio when a device > is opened or closed by some user process which is good, but > even when the device is never opened vfio may have taken some > action as a result of binding. One such example might be > putting it into D3 low power state. > > Additionally, the lifecycle of some applications that use > vfio-pci may be infrequent or defered for a significant time. > We have found that some third party tools or perhaps ignorant > super-users may choose to bind or unbind devices with a fairly > inexplicit policy leaving applictions that might have wanted > to use a device confused about its absence from vfio. > > Signed-Off-by: Matthew W Carlis <mattc@xxxxxxxxxxxxxxx> > --- > drivers/vfio/pci/vfio_pci_core.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c > index 1929103ee59a..3e463a7d25f9 100644 > --- a/drivers/vfio/pci/vfio_pci_core.c > +++ b/drivers/vfio/pci/vfio_pci_core.c > @@ -2265,6 +2265,8 @@ int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev) > ret = vfio_register_group_dev(&vdev->vdev); > if (ret) > goto out_power; > + > + pci_info(pdev, "binding to vfio control\n"); > return 0; > > out_power: > @@ -2291,6 +2293,8 @@ void vfio_pci_core_unregister_device(struct vfio_pci_core_device *vdev) > pm_runtime_get_noresume(&vdev->pdev->dev); > > pm_runtime_forbid(&vdev->pdev->dev); > + > + pci_info(vdev->pdev, "unbinding from vfio control\n"); > } > EXPORT_SYMBOL_GPL(vfio_pci_core_unregister_device); Parsing dmesg is a poor means to track driver bindings. There are already udev events, why aren't those sufficient? They're certainly more generic. Thanks, Alex