Skip to content

Commit

Permalink
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/gi…
Browse files Browse the repository at this point in the history
…t/mst/vhost

Pull virtio/vhost fixes and cleanups from Michael Tsirkin:
 "Misc fixes and cleanups all over the place"

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
  virtio/s390: deprecate old transport
  virtio/s390: keep early_put_chars
  virtio_blk: Fix a slient kernel panic
  virtio-vsock: fix include guard typo
  vhost/vsock: fix vhost virtio_vsock_pkt use-after-free
  9p/trans_virtio: use kvfree() for iov_iter_get_pages_alloc()
  virtio: fix error handling for debug builds
  virtio: fix memory leak in virtqueue_add()
  • Loading branch information
torvalds committed Aug 11, 2016
2 parents 3b3ce01 + 3b2fbb3 commit 6da7e95
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 24 deletions.
13 changes: 13 additions & 0 deletions arch/s390/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -872,4 +872,17 @@ config S390_GUEST
Select this option if you want to run the kernel as a guest under
the KVM hypervisor.

config S390_GUEST_OLD_TRANSPORT
def_bool y
prompt "Guest support for old s390 virtio transport (DEPRECATED)"
depends on S390_GUEST
help
Enable this option to add support for the old s390-virtio
transport (i.e. virtio devices NOT based on virtio-ccw). This
type of virtio devices is only available on the experimental
kuli userspace or with old (< 2.6) qemu. If you are running
with a modern version of qemu (which supports virtio-ccw since
1.4 and uses it by default since version 2.4), you probably won't
need this.

endmenu
26 changes: 8 additions & 18 deletions drivers/block/virtio_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,22 +391,16 @@ static int init_vq(struct virtio_blk *vblk)
num_vqs = 1;

vblk->vqs = kmalloc(sizeof(*vblk->vqs) * num_vqs, GFP_KERNEL);
if (!vblk->vqs) {
err = -ENOMEM;
goto out;
}
if (!vblk->vqs)
return -ENOMEM;

names = kmalloc(sizeof(*names) * num_vqs, GFP_KERNEL);
if (!names)
goto err_names;

callbacks = kmalloc(sizeof(*callbacks) * num_vqs, GFP_KERNEL);
if (!callbacks)
goto err_callbacks;

vqs = kmalloc(sizeof(*vqs) * num_vqs, GFP_KERNEL);
if (!vqs)
goto err_vqs;
if (!names || !callbacks || !vqs) {
err = -ENOMEM;
goto out;
}

for (i = 0; i < num_vqs; i++) {
callbacks[i] = virtblk_done;
Expand All @@ -417,24 +411,20 @@ static int init_vq(struct virtio_blk *vblk)
/* Discover virtqueues and write information to configuration. */
err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names);
if (err)
goto err_find_vqs;
goto out;

for (i = 0; i < num_vqs; i++) {
spin_lock_init(&vblk->vqs[i].lock);
vblk->vqs[i].vq = vqs[i];
}
vblk->num_vqs = num_vqs;

err_find_vqs:
out:
kfree(vqs);
err_vqs:
kfree(callbacks);
err_callbacks:
kfree(names);
err_names:
if (err)
kfree(vblk->vqs);
out:
return err;
}

Expand Down
6 changes: 5 additions & 1 deletion drivers/s390/virtio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
# it under the terms of the GNU General Public License (version 2 only)
# as published by the Free Software Foundation.

obj-$(CONFIG_S390_GUEST) += kvm_virtio.o virtio_ccw.o
s390-virtio-objs := virtio_ccw.o
ifdef CONFIG_S390_GUEST_OLD_TRANSPORT
s390-virtio-objs += kvm_virtio.o
endif
obj-$(CONFIG_S390_GUEST) += $(s390-virtio-objs)
4 changes: 3 additions & 1 deletion drivers/s390/virtio/kvm_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ static int __init kvm_devices_init(void)
if (test_devices_support(total_memory_size) < 0)
return -ENODEV;

pr_warn("The s390-virtio transport is deprecated. Please switch to a modern host providing virtio-ccw.\n");

rc = vmem_add_mapping(total_memory_size, PAGE_SIZE);
if (rc)
return rc;
Expand All @@ -482,7 +484,7 @@ static int __init kvm_devices_init(void)
}

/* code for early console output with virtio_console */
static __init int early_put_chars(u32 vtermno, const char *buf, int count)
static int early_put_chars(u32 vtermno, const char *buf, int count)
{
char scratch[17];
unsigned int len = count;
Expand Down
6 changes: 5 additions & 1 deletion drivers/vhost/vsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)

vhost_disable_notify(&vsock->dev, vq);
for (;;) {
u32 len;

if (!vhost_vsock_more_replies(vsock)) {
/* Stop tx until the device processes already
* pending replies. Leave tx virtqueue
Expand Down Expand Up @@ -334,13 +336,15 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
continue;
}

len = pkt->len;

/* Only accept correctly addressed packets */
if (le64_to_cpu(pkt->hdr.src_cid) == vsock->guest_cid)
virtio_transport_recv_pkt(pkt);
else
virtio_transport_free_pkt(pkt);

vhost_add_used(vq, head, sizeof(pkt->hdr) + pkt->len);
vhost_add_used(vq, head, sizeof(pkt->hdr) + len);
added = true;
}

Expand Down
3 changes: 3 additions & 0 deletions drivers/virtio/virtio_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ static inline int virtqueue_add(struct virtqueue *_vq,
* host should service the ring ASAP. */
if (out_sgs)
vq->notify(&vq->vq);
if (indirect)
kfree(desc);
END_USE(vq);
return -ENOSPC;
}
Expand Down Expand Up @@ -426,6 +428,7 @@ static inline int virtqueue_add(struct virtqueue *_vq,
if (indirect)
kfree(desc);

END_USE(vq);
return -EIO;
}

Expand Down
2 changes: 1 addition & 1 deletion include/uapi/linux/virtio_vsock.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/

#ifndef _UAPI_LINUX_VIRTIO_VSOCK_H
#define _UAPI_LINUX_VIRTIO_VOSCK_H
#define _UAPI_LINUX_VIRTIO_VSOCK_H

#include <linux/types.h>
#include <linux/virtio_ids.h>
Expand Down
4 changes: 2 additions & 2 deletions net/9p/trans_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,
/* wakeup anybody waiting for slots to pin pages */
wake_up(&vp_wq);
}
kfree(in_pages);
kfree(out_pages);
kvfree(in_pages);
kvfree(out_pages);
return err;
}

Expand Down

0 comments on commit 6da7e95

Please sign in to comment.