Skip to content

Commit 6da7e95

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/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()
2 parents 3b3ce01 + 3b2fbb3 commit 6da7e95

File tree

8 files changed

+40
-24
lines changed

8 files changed

+40
-24
lines changed

arch/s390/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,4 +872,17 @@ config S390_GUEST
872872
Select this option if you want to run the kernel as a guest under
873873
the KVM hypervisor.
874874

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

drivers/block/virtio_blk.c

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -391,22 +391,16 @@ static int init_vq(struct virtio_blk *vblk)
391391
num_vqs = 1;
392392

393393
vblk->vqs = kmalloc(sizeof(*vblk->vqs) * num_vqs, GFP_KERNEL);
394-
if (!vblk->vqs) {
395-
err = -ENOMEM;
396-
goto out;
397-
}
394+
if (!vblk->vqs)
395+
return -ENOMEM;
398396

399397
names = kmalloc(sizeof(*names) * num_vqs, GFP_KERNEL);
400-
if (!names)
401-
goto err_names;
402-
403398
callbacks = kmalloc(sizeof(*callbacks) * num_vqs, GFP_KERNEL);
404-
if (!callbacks)
405-
goto err_callbacks;
406-
407399
vqs = kmalloc(sizeof(*vqs) * num_vqs, GFP_KERNEL);
408-
if (!vqs)
409-
goto err_vqs;
400+
if (!names || !callbacks || !vqs) {
401+
err = -ENOMEM;
402+
goto out;
403+
}
410404

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

422416
for (i = 0; i < num_vqs; i++) {
423417
spin_lock_init(&vblk->vqs[i].lock);
424418
vblk->vqs[i].vq = vqs[i];
425419
}
426420
vblk->num_vqs = num_vqs;
427421

428-
err_find_vqs:
422+
out:
429423
kfree(vqs);
430-
err_vqs:
431424
kfree(callbacks);
432-
err_callbacks:
433425
kfree(names);
434-
err_names:
435426
if (err)
436427
kfree(vblk->vqs);
437-
out:
438428
return err;
439429
}
440430

drivers/s390/virtio/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
# it under the terms of the GNU General Public License (version 2 only)
77
# as published by the Free Software Foundation.
88

9-
obj-$(CONFIG_S390_GUEST) += kvm_virtio.o virtio_ccw.o
9+
s390-virtio-objs := virtio_ccw.o
10+
ifdef CONFIG_S390_GUEST_OLD_TRANSPORT
11+
s390-virtio-objs += kvm_virtio.o
12+
endif
13+
obj-$(CONFIG_S390_GUEST) += $(s390-virtio-objs)

drivers/s390/virtio/kvm_virtio.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ static int __init kvm_devices_init(void)
458458
if (test_devices_support(total_memory_size) < 0)
459459
return -ENODEV;
460460

461+
pr_warn("The s390-virtio transport is deprecated. Please switch to a modern host providing virtio-ccw.\n");
462+
461463
rc = vmem_add_mapping(total_memory_size, PAGE_SIZE);
462464
if (rc)
463465
return rc;
@@ -482,7 +484,7 @@ static int __init kvm_devices_init(void)
482484
}
483485

484486
/* code for early console output with virtio_console */
485-
static __init int early_put_chars(u32 vtermno, const char *buf, int count)
487+
static int early_put_chars(u32 vtermno, const char *buf, int count)
486488
{
487489
char scratch[17];
488490
unsigned int len = count;

drivers/vhost/vsock.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
307307

308308
vhost_disable_notify(&vsock->dev, vq);
309309
for (;;) {
310+
u32 len;
311+
310312
if (!vhost_vsock_more_replies(vsock)) {
311313
/* Stop tx until the device processes already
312314
* pending replies. Leave tx virtqueue
@@ -334,13 +336,15 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
334336
continue;
335337
}
336338

339+
len = pkt->len;
340+
337341
/* Only accept correctly addressed packets */
338342
if (le64_to_cpu(pkt->hdr.src_cid) == vsock->guest_cid)
339343
virtio_transport_recv_pkt(pkt);
340344
else
341345
virtio_transport_free_pkt(pkt);
342346

343-
vhost_add_used(vq, head, sizeof(pkt->hdr) + pkt->len);
347+
vhost_add_used(vq, head, sizeof(pkt->hdr) + len);
344348
added = true;
345349
}
346350

drivers/virtio/virtio_ring.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ static inline int virtqueue_add(struct virtqueue *_vq,
327327
* host should service the ring ASAP. */
328328
if (out_sgs)
329329
vq->notify(&vq->vq);
330+
if (indirect)
331+
kfree(desc);
330332
END_USE(vq);
331333
return -ENOSPC;
332334
}
@@ -426,6 +428,7 @@ static inline int virtqueue_add(struct virtqueue *_vq,
426428
if (indirect)
427429
kfree(desc);
428430

431+
END_USE(vq);
429432
return -EIO;
430433
}
431434

include/uapi/linux/virtio_vsock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333

3434
#ifndef _UAPI_LINUX_VIRTIO_VSOCK_H
35-
#define _UAPI_LINUX_VIRTIO_VOSCK_H
35+
#define _UAPI_LINUX_VIRTIO_VSOCK_H
3636

3737
#include <linux/types.h>
3838
#include <linux/virtio_ids.h>

net/9p/trans_virtio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,8 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,
507507
/* wakeup anybody waiting for slots to pin pages */
508508
wake_up(&vp_wq);
509509
}
510-
kfree(in_pages);
511-
kfree(out_pages);
510+
kvfree(in_pages);
511+
kvfree(out_pages);
512512
return err;
513513
}
514514

0 commit comments

Comments
 (0)