[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PULL v2 40/41] vhost-vdpa: introduce vhost-vdpa backend
From: |
Peter Maydell |
Subject: |
Re: [PULL v2 40/41] vhost-vdpa: introduce vhost-vdpa backend |
Date: |
Thu, 9 Jul 2020 16:14:52 +0100 |
On Sat, 4 Jul 2020 at 19:31, Michael S. Tsirkin <mst@redhat.com> wrote:
>
> From: Cindy Lu <lulu@redhat.com>
>
> Currently we have 2 types of vhost backends in QEMU: vhost kernel and
> vhost-user. The above patch provides a generic device for vDPA purpose,
> this vDPA device exposes to user space a non-vendor-specific configuration
> interface for setting up a vhost HW accelerator, this patch set introduces
> a third vhost backend called vhost-vdpa based on the vDPA interface.
>
> Vhost-vdpa usage:
>
> qemu-system-x86_64 -cpu host -enable-kvm \
> ......
> -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-id,id=vhost-vdpa0 \
> -device virtio-net-pci,netdev=vhost-vdpa0,page-per-vq=on \
Hi; Coverity reports some issues with this change:
> +static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,
> + void *vaddr, bool readonly)
> +{
> + struct vhost_msg_v2 msg;
> + int fd = v->device_fd;
> + int ret = 0;
> +
> + msg.type = v->msg_type;
> + msg.iotlb.iova = iova;
> + msg.iotlb.size = size;
> + msg.iotlb.uaddr = (uint64_t)vaddr;
> + msg.iotlb.perm = readonly ? VHOST_ACCESS_RO : VHOST_ACCESS_RW;
> + msg.iotlb.type = VHOST_IOTLB_UPDATE;
> +
> + if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) {
Here we write the contents of the struct down the pipe,
but we have not initialized all its fields; specifically,
msg.reserved is not initialized and so those bytes will
be random. We'll also transfer random contents from the
stack in the padding, potentially.
This is CID 1420267.
The easy fix is to zero-initialize the whole struct at the start:
struct vhost_msg_v2 msg = {};
> + error_report("failed to write, fd=%d, errno=%d (%s)",
> + fd, errno, strerror(errno));
> + return -EIO ;
> + }
> +
> + return ret;
> +}
> +
> +static int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova,
> + hwaddr size)
> +{
> + struct vhost_msg_v2 msg;
> + int fd = v->device_fd;
> + int ret = 0;
> +
> + msg.type = v->msg_type;
> + msg.iotlb.iova = iova;
> + msg.iotlb.size = size;
> + msg.iotlb.type = VHOST_IOTLB_INVALIDATE;
> +
> + if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) {
> + error_report("failed to write, fd=%d, errno=%d (%s)",
> + fd, errno, strerror(errno));
> + return -EIO ;
> + }
Same here (CID 1430270)
> +
> + return ret;
> +}
> +
thanks
-- PMM
- [PULL v2 31/41] virtio-pci: implement queue_enabled method, (continued)
- [PULL v2 31/41] virtio-pci: implement queue_enabled method, Michael S. Tsirkin, 2020/07/04
- [PULL v2 32/41] vhost: check the existence of vhost_set_iotlb_callback, Michael S. Tsirkin, 2020/07/04
- [PULL v2 33/41] vhost: introduce new VhostOps vhost_dev_start, Michael S. Tsirkin, 2020/07/04
- [PULL v2 34/41] vhost: implement vhost_dev_start method, Michael S. Tsirkin, 2020/07/04
- [PULL v2 35/41] vhost: introduce new VhostOps vhost_vq_get_addr, Michael S. Tsirkin, 2020/07/04
- [PULL v2 36/41] vhost: implement vhost_vq_get_addr method, Michael S. Tsirkin, 2020/07/04
- [PULL v2 37/41] vhost: introduce new VhostOps vhost_force_iommu, Michael S. Tsirkin, 2020/07/04
- [PULL v2 39/41] vhost_net: introduce set_config & get_config, Michael S. Tsirkin, 2020/07/04
- [PULL v2 38/41] vhost: implement vhost_force_iommu method, Michael S. Tsirkin, 2020/07/04
- [PULL v2 40/41] vhost-vdpa: introduce vhost-vdpa backend, Michael S. Tsirkin, 2020/07/04
- Re: [PULL v2 40/41] vhost-vdpa: introduce vhost-vdpa backend,
Peter Maydell <=
- [PULL v2 41/41] vhost-vdpa: introduce vhost-vdpa net client, Michael S. Tsirkin, 2020/07/04
- [PULL v2 21/41] virtio-mem: Migration sanity checks, Michael S. Tsirkin, 2020/07/04
- Re: [PULL v2 00/41] virtio,acpi: features, fixes, cleanups., Peter Maydell, 2020/07/07
- Re: [PULL v2 00/41] virtio,acpi: features, fixes, cleanups., Michael S. Tsirkin, 2020/07/07
- Re: [PULL v2 00/41] virtio,acpi: features, fixes, cleanups., Peter Maydell, 2020/07/07
- Re: [PULL v2 00/41] virtio,acpi: features, fixes, cleanups., Michael S. Tsirkin, 2020/07/08
- Re: [PULL v2 00/41] virtio,acpi: features, fixes, cleanups., Peter Maydell, 2020/07/08
- Re: [PULL v2 00/41] virtio,acpi: features, fixes, cleanups., Peter Maydell, 2020/07/09
- Re: [PULL v2 00/41] virtio,acpi: features, fixes, cleanups., Michael S. Tsirkin, 2020/07/09