Thread (63 messages) 63 messages, 5 authors, 2018-10-15

Re: [PATCH v3 4/4] vfio: enable vfio hotplug by req notifier handler

From: Jeff Guo <hidden>
Date: 2018-10-04 05:05:36

On 10/2/2018 10:15 PM, Burakov, Anatoly wrote:
On 02-Oct-18 1:58 PM, Jeff Guo wrote:
quoted
When device is be hot-unplugged, the vfio kernel module will sent req
notifier to request user space to release the allocated resources at
first. After that, vfio kernel module will detect the device disappear,
and then delete the device in kernel.

This patch aim to add req notifier processing to enable hotplug for 
vfio.
By enable the req notifier monitoring and register the notifier 
callback,
when device be hot-unplugged, the hot-unplug handler will be called to
process hotplug for vfio.

Signed-off-by: Jeff Guo <redacted>
---
v3->v2:
change some code style and typo.
---
<snip>
quoted
+/* enable notifier (only enable req now) */
+static int
+pci_vfio_enable_notifier(struct rte_pci_device *dev, int vfio_dev_fd)
+{
+    int ret;
+    int fd = -1;
+
+    /* set up an eventfd for req notifier */
+    fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
+    if (fd < 0) {
+        RTE_LOG(ERR, EAL, "Cannot set up eventfd, error %i (%s)\n",
+            errno, strerror(errno));
+        return -1;
+    }
+
+    dev->req_notifier_handler.fd = fd;
+    dev->req_notifier_handler.type = RTE_INTR_HANDLE_VFIO_REQ;
+    dev->req_notifier_handler.vfio_dev_fd = vfio_dev_fd;
+    ret = rte_intr_callback_register(&dev->req_notifier_handler,
+                     pci_vfio_req_handler,
+                     (void *)&dev->device);
+    if (ret) {
+        RTE_LOG(ERR, EAL, "Fail to register req notifier handler.\n");
+        goto error;
At this point (and further down as well), if we go to error, we've 
already modified the req_notifier_handler data. Do we need to 
overwrite it? Maybe just do these operations on a local struct, and 
then do a memcpy into dev->req_notifier_handler on success?
I think just overwrite it in error process should be clear and simple.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help