Message ID | 20210209190224.62827-2-dgilbert@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | virtiofs dax patches | expand |
On Tue, Feb 09, 2021 at 07:02:01PM +0000, Dr. David Alan Gilbert (git) wrote: > +static uint64_t vhost_user_slave_handle_vring_host_notifier( > + struct vhost_dev *dev, > + VhostUserVringArea *area, > + int fd) Indentation looks off. Only worth changing if you respin. > @@ -1398,7 +1399,8 @@ static void slave_read(void *opaque) > struct vhost_user *u = dev->opaque; > VhostUserHeader hdr = { 0, }; > VhostUserPayload payload = { 0, }; > - int size, ret = 0; > + int size; > + uint64_t ret = 0; > struct iovec iov; > struct msghdr msgh; > int fd[VHOST_USER_SLAVE_MAX_FDS]; > @@ -1472,7 +1474,7 @@ static void slave_read(void *opaque) > break; > default: > error_report("Received unexpected msg type: %d.", hdr.request); > - ret = -EINVAL; > + ret = (uint64_t)-EINVAL; The !!ret was removed below so it would have previously been true (1). Now it has changed value. If there is no specific reason to change the value, please keep it true (1) just in case a vhost-user device backend depends on that value.
On Thu, Feb 11, 2021 at 09:59:36AM +0000, Stefan Hajnoczi wrote: > On Tue, Feb 09, 2021 at 07:02:01PM +0000, Dr. David Alan Gilbert (git) wrote: > > +static uint64_t vhost_user_slave_handle_vring_host_notifier( > > + struct vhost_dev *dev, > > + VhostUserVringArea *area, > > + int fd) > > Indentation looks off. Only worth changing if you respin. > > > @@ -1398,7 +1399,8 @@ static void slave_read(void *opaque) > > struct vhost_user *u = dev->opaque; > > VhostUserHeader hdr = { 0, }; > > VhostUserPayload payload = { 0, }; > > - int size, ret = 0; > > + int size; > > + uint64_t ret = 0; > > struct iovec iov; > > struct msghdr msgh; > > int fd[VHOST_USER_SLAVE_MAX_FDS]; > > @@ -1472,7 +1474,7 @@ static void slave_read(void *opaque) > > break; > > default: > > error_report("Received unexpected msg type: %d.", hdr.request); > > - ret = -EINVAL; > > + ret = (uint64_t)-EINVAL; > > The !!ret was removed below so it would have previously been true (1). > Now it has changed value. > > If there is no specific reason to change the value, please keep it true > (1) just in case a vhost-user device backend depends on that value. Good catch. I guess it will be nice to send -EINVAL back but we probably can't change it now due to backward compatibility issue. Just in case, someone is relying on reading back true (instead of -EINVAL). Vivek
* Stefan Hajnoczi (stefanha@redhat.com) wrote: > On Tue, Feb 09, 2021 at 07:02:01PM +0000, Dr. David Alan Gilbert (git) wrote: > > +static uint64_t vhost_user_slave_handle_vring_host_notifier( > > + struct vhost_dev *dev, > > + VhostUserVringArea *area, > > + int fd) > > Indentation looks off. Only worth changing if you respin. Done. > > @@ -1398,7 +1399,8 @@ static void slave_read(void *opaque) > > struct vhost_user *u = dev->opaque; > > VhostUserHeader hdr = { 0, }; > > VhostUserPayload payload = { 0, }; > > - int size, ret = 0; > > + int size; > > + uint64_t ret = 0; > > struct iovec iov; > > struct msghdr msgh; > > int fd[VHOST_USER_SLAVE_MAX_FDS]; > > @@ -1472,7 +1474,7 @@ static void slave_read(void *opaque) > > break; > > default: > > error_report("Received unexpected msg type: %d.", hdr.request); > > - ret = -EINVAL; > > + ret = (uint64_t)-EINVAL; > > The !!ret was removed below so it would have previously been true (1). > Now it has changed value. > > If there is no specific reason to change the value, please keep it true > (1) just in case a vhost-user device backend depends on that value. Done; although moving to errnos there feels a bit better to me; but yes the callers aren't audited. Dave
diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 31b33bde37..21082084ea 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -401,7 +401,7 @@ int vhost_backend_invalidate_device_iotlb(struct vhost_dev *dev, return -ENODEV; } -int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, +uint64_t vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, struct vhost_iotlb_msg *imsg) { int ret = 0; @@ -429,5 +429,5 @@ int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, break; } - return ret; + return !!ret; } diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 2fdd5daf74..13789cc55e 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1317,24 +1317,25 @@ static int vhost_user_reset_device(struct vhost_dev *dev) return 0; } -static int vhost_user_slave_handle_config_change(struct vhost_dev *dev) +static uint64_t vhost_user_slave_handle_config_change(struct vhost_dev *dev) { int ret = -1; if (!dev->config_ops) { - return -1; + return true; } if (dev->config_ops->vhost_dev_config_notifier) { ret = dev->config_ops->vhost_dev_config_notifier(dev); } - return ret; + return !!ret; } -static int vhost_user_slave_handle_vring_host_notifier(struct vhost_dev *dev, - VhostUserVringArea *area, - int fd) +static uint64_t vhost_user_slave_handle_vring_host_notifier( + struct vhost_dev *dev, + VhostUserVringArea *area, + int fd) { int queue_idx = area->u64 & VHOST_USER_VRING_IDX_MASK; size_t page_size = qemu_real_host_page_size; @@ -1348,7 +1349,7 @@ static int vhost_user_slave_handle_vring_host_notifier(struct vhost_dev *dev, if (!virtio_has_feature(dev->protocol_features, VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) || vdev == NULL || queue_idx >= virtio_get_num_queues(vdev)) { - return -1; + return true; } n = &user->notifier[queue_idx]; @@ -1361,18 +1362,18 @@ static int vhost_user_slave_handle_vring_host_notifier(struct vhost_dev *dev, } if (area->u64 & VHOST_USER_VRING_NOFD_MASK) { - return 0; + return false; } /* Sanity check. */ if (area->size != page_size) { - return -1; + return true; } addr = mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, area->offset); if (addr == MAP_FAILED) { - return -1; + return true; } name = g_strdup_printf("vhost-user/host-notifier@%p mmaps[%d]", @@ -1383,13 +1384,13 @@ static int vhost_user_slave_handle_vring_host_notifier(struct vhost_dev *dev, if (virtio_queue_set_host_notifier_mr(vdev, queue_idx, &n->mr, true)) { munmap(addr, page_size); - return -1; + return true; } n->addr = addr; n->set = true; - return 0; + return false; } static void slave_read(void *opaque) @@ -1398,7 +1399,8 @@ static void slave_read(void *opaque) struct vhost_user *u = dev->opaque; VhostUserHeader hdr = { 0, }; VhostUserPayload payload = { 0, }; - int size, ret = 0; + int size; + uint64_t ret = 0; struct iovec iov; struct msghdr msgh; int fd[VHOST_USER_SLAVE_MAX_FDS]; @@ -1472,7 +1474,7 @@ static void slave_read(void *opaque) break; default: error_report("Received unexpected msg type: %d.", hdr.request); - ret = -EINVAL; + ret = (uint64_t)-EINVAL; } /* Close the remaining file descriptors. */ @@ -1493,7 +1495,7 @@ static void slave_read(void *opaque) hdr.flags &= ~VHOST_USER_NEED_REPLY_MASK; hdr.flags |= VHOST_USER_REPLY_MASK; - payload.u64 = !!ret; + payload.u64 = ret; hdr.size = sizeof(payload.u64); iovec[0].iov_base = &hdr; diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index 8a6f8e2a7a..64ac6b6444 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -186,7 +186,7 @@ int vhost_backend_update_device_iotlb(struct vhost_dev *dev, int vhost_backend_invalidate_device_iotlb(struct vhost_dev *dev, uint64_t iova, uint64_t len); -int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, +uint64_t vhost_backend_handle_iotlb_msg(struct vhost_dev *dev, struct vhost_iotlb_msg *imsg); int vhost_user_gpu_set_socket(struct vhost_dev *dev, int fd);