vhost: NULL callback checks
cover vhost: NULL callback checks
Not a normal case, but noticed that setting some callbacks to NULL in rte_vhost_driver_callback_register() causes a seg fault e.g. [0].
Added missing checks before calling. Alternative fix is to make some callbacks mandatory and check during register - is that an API change? maybe, so took simpler approach.
A bit hard to find fixed commit due to the time and amount of development in vhost code.
[0]
3302│ if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
3303├> if (dev->notify_ops->new_device(dev->vid) == 0)
3304│ dev->flags |= VIRTIO_DEV_RUNNING;
3305│ }(gdb) frame 1
at ../lib/vhost/vhost_user.c:3303
(gdb) p dev->notify_ops->new_device
$3 = (int (*)(int)) 0x0
Kevin Traynor (1):
vhost: add NULL callback checks
lib/vhost/vduse.c | 3 ++- lib/vhost/vhost.c | 5 +++-- lib/vhost/vhost_user.c | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-)
Signature · 1 line
2.48.1
PATCH 1/1 vhost: add NULL callback checks
rte_vhost_driver_callback_register() does not specify any mandatory callbacks in struct rte_vhost_device_ops.
Add some missing NULL checks before calling rte_vhost_device_ops callbacks.
--- lib/vhost/vduse.c | 3 ++- lib/vhost/vhost.c | 5 +++-- lib/vhost/vhost_user.c | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-)
lib/vhost/vduse.c +2 -1
@@ -319,5 +319,6 @@ vduse_device_start(struct virtio_net *dev, bool reconnect) dev->flags |=VIRTIO_DEV_READY ; -if (dev->notify_ops->new_device (dev->vid) ==0 ) +if (!dev->notify_ops->new_device || + dev->notify_ops->new_device (dev->vid) ==0 ) dev->flags |=VIRTIO_DEV_RUNNING ;
lib/vhost/vhost.c +3 -2
@@ -752,8 +752,9 @@ vhost_destroy_device_notify(struct virtio_net *dev)if (dev->flags &VIRTIO_DEV_RUNNING ) { vdpa_dev = dev->vdpa_dev; -if (vdpa_dev) +if (vdpa_dev && vdpa_dev->ops->dev_close) vdpa_dev->ops->dev_close (dev->vid); dev->flags &= ~VIRTIO_DEV_RUNNING ; - dev->notify_ops->destroy_device (dev->vid); +if (dev->notify_ops->destroy_device) + dev->notify_ops->destroy_device (dev->vid); } }
lib/vhost/vhost_user.c +2 -1
@@ -3302,5 +3302,6 @@ vhost_user_msg_handler(int vid, int fd)if (!(dev->flags &VIRTIO_DEV_RUNNING )) { -if (dev->notify_ops->new_device (dev->vid) ==0 ) +if (!dev->notify_ops->new_device || + dev->notify_ops->new_device (dev->vid) ==0 ) dev->flags |=VIRTIO_DEV_RUNNING ; }
Signature · 1 line
2.48.1
Re: [PATCH 1/1] vhost: add NULL callback checks
Quoted 49 lines · Kevin Traynor
rte_vhost_driver_callback_register()does not specify any mandatory callbacks in structrte_vhost_device_ops.Add some missing NULL checks before calling
rte_vhost_device_opscallbacks.Fixes 4796ad63ba1f ("examples/vhost: import userspace vhost application")Signed-off-by Kevin Traynor <[email protected]>--- lib/vhost/vduse.c | 3 ++- lib/vhost/vhost.c | 5 +++-- lib/vhost/vhost_user.c | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-)lib/vhost/vduse.c +2
-1@@ -319,5 +319,6 @@ vduse_device_start(struct virtio_net *dev, bool reconnect) dev->flags |=VIRTIO_DEV_READY ; -if (dev->notify_ops->new_device (dev->vid) ==0 ) +if (!dev->notify_ops->new_device || + dev->notify_ops->new_device (dev->vid) ==0 ) dev->flags |=VIRTIO_DEV_RUNNING ;lib/vhost/vhost.c +3
-2@@ -752,8 +752,9 @@ vhost_destroy_device_notify(struct virtio_net *dev)if (dev->flags &VIRTIO_DEV_RUNNING ) { vdpa_dev = dev->vdpa_dev; -if (vdpa_dev) +if (vdpa_dev && vdpa_dev->ops->dev_close) vdpa_dev->ops->dev_close (dev->vid); dev->flags &= ~VIRTIO_DEV_RUNNING ; - dev->notify_ops->destroy_device (dev->vid); +if (dev->notify_ops->destroy_device) + dev->notify_ops->destroy_device (dev->vid); } }lib/vhost/vhost_user.c +0
-0
lib/vhost/vhost_user.c vhost_user_msg_handler(int vid, int fd) · line 3307
Quoted 7 lines
lib/vhost/vhost_user.c +2
-1@@ -3302,5 +3302,6 @@ vhost_user_msg_handler(int vid, int fd)if (!(dev->flags &VIRTIO_DEV_RUNNING )) { -if (dev->notify_ops->new_device (dev->vid) ==0 ) +if (!dev->notify_ops->new_device || + dev->notify_ops->new_device (dev->vid) ==0 ) dev->flags |=VIRTIO_DEV_RUNNING ; }
Thanks,
Maxime
Maxime Coquelin
AppliedRe: [PATCH 1/1] vhost: add NULL callback checks
In reply to Kevin TraynorQuoted 9 lines · Kevin Traynor
rte_vhost_driver_callback_register()does not specify any mandatory callbacks in structrte_vhost_device_ops.Add some missing NULL checks before calling
rte_vhost_device_opscallbacks.Fixes 4796ad63ba1f ("examples/vhost: import userspace vhost application")
Quoted 6 lines
Signed-off-by Kevin Traynor <[email protected]>--- lib/vhost/vduse.c | 3 ++- lib/vhost/vhost.c | 5 +++-- lib/vhost/vhost_user.c | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-
Applied to next-virtio/for-next-net.
Thanks,
Maxime