Skip to content

Commit 6b8a794

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull last minute virtio bugfixes from Michael Tsirkin: "Minor bugfixes all over the place" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: virtio_balloon: fix shrinker count virtio_balloon: fix shrinker scan number of pages virtio_console: allocate inbufs in add_port() only if it is needed virtio_ring: fix return code on DMA mapping fails
2 parents 2027cab + c9a6820 commit 6b8a794

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

drivers/char/virtio_console.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,24 +1325,24 @@ static void set_console_size(struct port *port, u16 rows, u16 cols)
13251325
port->cons.ws.ws_col = cols;
13261326
}
13271327

1328-
static unsigned int fill_queue(struct virtqueue *vq, spinlock_t *lock)
1328+
static int fill_queue(struct virtqueue *vq, spinlock_t *lock)
13291329
{
13301330
struct port_buffer *buf;
1331-
unsigned int nr_added_bufs;
1331+
int nr_added_bufs;
13321332
int ret;
13331333

13341334
nr_added_bufs = 0;
13351335
do {
13361336
buf = alloc_buf(vq->vdev, PAGE_SIZE, 0);
13371337
if (!buf)
1338-
break;
1338+
return -ENOMEM;
13391339

13401340
spin_lock_irq(lock);
13411341
ret = add_inbuf(vq, buf);
13421342
if (ret < 0) {
13431343
spin_unlock_irq(lock);
13441344
free_buf(buf, true);
1345-
break;
1345+
return ret;
13461346
}
13471347
nr_added_bufs++;
13481348
spin_unlock_irq(lock);
@@ -1362,7 +1362,6 @@ static int add_port(struct ports_device *portdev, u32 id)
13621362
char debugfs_name[16];
13631363
struct port *port;
13641364
dev_t devt;
1365-
unsigned int nr_added_bufs;
13661365
int err;
13671366

13681367
port = kmalloc(sizeof(*port), GFP_KERNEL);
@@ -1421,11 +1420,13 @@ static int add_port(struct ports_device *portdev, u32 id)
14211420
spin_lock_init(&port->outvq_lock);
14221421
init_waitqueue_head(&port->waitqueue);
14231422

1424-
/* Fill the in_vq with buffers so the host can send us data. */
1425-
nr_added_bufs = fill_queue(port->in_vq, &port->inbuf_lock);
1426-
if (!nr_added_bufs) {
1423+
/* We can safely ignore ENOSPC because it means
1424+
* the queue already has buffers. Buffers are removed
1425+
* only by virtcons_remove(), not by unplug_port()
1426+
*/
1427+
err = fill_queue(port->in_vq, &port->inbuf_lock);
1428+
if (err < 0 && err != -ENOSPC) {
14271429
dev_err(port->dev, "Error allocating inbufs\n");
1428-
err = -ENOMEM;
14291430
goto free_device;
14301431
}
14311432

@@ -2059,14 +2060,11 @@ static int virtcons_probe(struct virtio_device *vdev)
20592060
INIT_WORK(&portdev->control_work, &control_work_handler);
20602061

20612062
if (multiport) {
2062-
unsigned int nr_added_bufs;
2063-
20642063
spin_lock_init(&portdev->c_ivq_lock);
20652064
spin_lock_init(&portdev->c_ovq_lock);
20662065

2067-
nr_added_bufs = fill_queue(portdev->c_ivq,
2068-
&portdev->c_ivq_lock);
2069-
if (!nr_added_bufs) {
2066+
err = fill_queue(portdev->c_ivq, &portdev->c_ivq_lock);
2067+
if (err < 0) {
20702068
dev_err(&vdev->dev,
20712069
"Error allocating buffers for control queue\n");
20722070
/*
@@ -2077,7 +2075,7 @@ static int virtcons_probe(struct virtio_device *vdev)
20772075
VIRTIO_CONSOLE_DEVICE_READY, 0);
20782076
/* Device was functional: we need full cleanup. */
20792077
virtcons_remove(vdev);
2080-
return -ENOMEM;
2078+
return err;
20812079
}
20822080
} else {
20832081
/*

drivers/virtio/virtio_balloon.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,13 @@ static unsigned long shrink_free_pages(struct virtio_balloon *vb,
772772
return blocks_freed << VIRTIO_BALLOON_FREE_PAGE_ORDER;
773773
}
774774

775+
static unsigned long leak_balloon_pages(struct virtio_balloon *vb,
776+
unsigned long pages_to_free)
777+
{
778+
return leak_balloon(vb, pages_to_free * VIRTIO_BALLOON_PAGES_PER_PAGE) /
779+
VIRTIO_BALLOON_PAGES_PER_PAGE;
780+
}
781+
775782
static unsigned long shrink_balloon_pages(struct virtio_balloon *vb,
776783
unsigned long pages_to_free)
777784
{
@@ -782,11 +789,10 @@ static unsigned long shrink_balloon_pages(struct virtio_balloon *vb,
782789
* VIRTIO_BALLOON_ARRAY_PFNS_MAX balloon pages, so we call it
783790
* multiple times to deflate pages till reaching pages_to_free.
784791
*/
785-
while (vb->num_pages && pages_to_free) {
786-
pages_freed += leak_balloon(vb, pages_to_free) /
787-
VIRTIO_BALLOON_PAGES_PER_PAGE;
788-
pages_to_free -= pages_freed;
789-
}
792+
while (vb->num_pages && pages_freed < pages_to_free)
793+
pages_freed += leak_balloon_pages(vb,
794+
pages_to_free - pages_freed);
795+
790796
update_balloon_size(vb);
791797

792798
return pages_freed;
@@ -799,7 +805,7 @@ static unsigned long virtio_balloon_shrinker_scan(struct shrinker *shrinker,
799805
struct virtio_balloon *vb = container_of(shrinker,
800806
struct virtio_balloon, shrinker);
801807

802-
pages_to_free = sc->nr_to_scan * VIRTIO_BALLOON_PAGES_PER_PAGE;
808+
pages_to_free = sc->nr_to_scan;
803809

804810
if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT))
805811
pages_freed = shrink_free_pages(vb, pages_to_free);
@@ -820,7 +826,7 @@ static unsigned long virtio_balloon_shrinker_count(struct shrinker *shrinker,
820826
unsigned long count;
821827

822828
count = vb->num_pages / VIRTIO_BALLOON_PAGES_PER_PAGE;
823-
count += vb->num_free_page_blocks >> VIRTIO_BALLOON_FREE_PAGE_ORDER;
829+
count += vb->num_free_page_blocks << VIRTIO_BALLOON_FREE_PAGE_ORDER;
824830

825831
return count;
826832
}

drivers/virtio/virtio_ring.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq,
583583
kfree(desc);
584584

585585
END_USE(vq);
586-
return -EIO;
586+
return -ENOMEM;
587587
}
588588

589589
static bool virtqueue_kick_prepare_split(struct virtqueue *_vq)
@@ -1085,7 +1085,7 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
10851085
kfree(desc);
10861086

10871087
END_USE(vq);
1088-
return -EIO;
1088+
return -ENOMEM;
10891089
}
10901090

10911091
static inline int virtqueue_add_packed(struct virtqueue *_vq,

0 commit comments

Comments
 (0)