Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost

Pull virtio fixups from Michael Tsirkin:

- Latest header update will break QEMU (if it's rebuilt with the new
header) - and it seems that the code there is so fragile that any
change in this header will break it. Add a better interface so users
do not need to change their code every time that header changes.

- Fix virtio console for spec compliance.

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
virtio_console: reset on out of memory
virtio_console: move removal code
virtio_console: drop custom control queue cleanup
virtio_console: free buffers after reset
virtio: add ability to iterate over vqs
virtio_console: don't tie bufs to a vq
virtio_balloon: add array of stat names

+89 -86
+71 -86
drivers/char/virtio_console.c
··· 422 422 } 423 423 } 424 424 425 - static struct port_buffer *alloc_buf(struct virtqueue *vq, size_t buf_size, 425 + static struct port_buffer *alloc_buf(struct virtio_device *vdev, size_t buf_size, 426 426 int pages) 427 427 { 428 428 struct port_buffer *buf; ··· 445 445 return buf; 446 446 } 447 447 448 - if (is_rproc_serial(vq->vdev)) { 448 + if (is_rproc_serial(vdev)) { 449 449 /* 450 450 * Allocate DMA memory from ancestor. When a virtio 451 451 * device is created by remoteproc, the DMA memory is 452 452 * associated with the grandparent device: 453 453 * vdev => rproc => platform-dev. 454 454 */ 455 - if (!vq->vdev->dev.parent || !vq->vdev->dev.parent->parent) 455 + if (!vdev->dev.parent || !vdev->dev.parent->parent) 456 456 goto free_buf; 457 - buf->dev = vq->vdev->dev.parent->parent; 457 + buf->dev = vdev->dev.parent->parent; 458 458 459 459 /* Increase device refcnt to avoid freeing it */ 460 460 get_device(buf->dev); ··· 838 838 839 839 count = min((size_t)(32 * 1024), count); 840 840 841 - buf = alloc_buf(port->out_vq, count, 0); 841 + buf = alloc_buf(port->portdev->vdev, count, 0); 842 842 if (!buf) 843 843 return -ENOMEM; 844 844 ··· 957 957 if (ret < 0) 958 958 goto error_out; 959 959 960 - buf = alloc_buf(port->out_vq, 0, pipe->nrbufs); 960 + buf = alloc_buf(port->portdev->vdev, 0, pipe->nrbufs); 961 961 if (!buf) { 962 962 ret = -ENOMEM; 963 963 goto error_out; ··· 1374 1374 1375 1375 nr_added_bufs = 0; 1376 1376 do { 1377 - buf = alloc_buf(vq, PAGE_SIZE, 0); 1377 + buf = alloc_buf(vq->vdev, PAGE_SIZE, 0); 1378 1378 if (!buf) 1379 1379 break; 1380 1380 ··· 1402 1402 { 1403 1403 char debugfs_name[16]; 1404 1404 struct port *port; 1405 - struct port_buffer *buf; 1406 1405 dev_t devt; 1407 1406 unsigned int nr_added_bufs; 1408 1407 int err; ··· 1512 1513 return 0; 1513 1514 1514 1515 free_inbufs: 1515 - while ((buf = virtqueue_detach_unused_buf(port->in_vq))) 1516 - free_buf(buf, true); 1517 1516 free_device: 1518 1517 device_destroy(pdrvdata.class, port->dev->devt); 1519 1518 free_cdev: ··· 1536 1539 1537 1540 static void remove_port_data(struct port *port) 1538 1541 { 1539 - struct port_buffer *buf; 1540 - 1541 1542 spin_lock_irq(&port->inbuf_lock); 1542 1543 /* Remove unused data this port might have received. */ 1543 1544 discard_port_data(port); 1544 1545 spin_unlock_irq(&port->inbuf_lock); 1545 1546 1546 - /* Remove buffers we queued up for the Host to send us data in. */ 1547 - do { 1548 - spin_lock_irq(&port->inbuf_lock); 1549 - buf = virtqueue_detach_unused_buf(port->in_vq); 1550 - spin_unlock_irq(&port->inbuf_lock); 1551 - if (buf) 1552 - free_buf(buf, true); 1553 - } while (buf); 1554 - 1555 1547 spin_lock_irq(&port->outvq_lock); 1556 1548 reclaim_consumed_buffers(port); 1557 1549 spin_unlock_irq(&port->outvq_lock); 1558 - 1559 - /* Free pending buffers from the out-queue. */ 1560 - do { 1561 - spin_lock_irq(&port->outvq_lock); 1562 - buf = virtqueue_detach_unused_buf(port->out_vq); 1563 - spin_unlock_irq(&port->outvq_lock); 1564 - if (buf) 1565 - free_buf(buf, true); 1566 - } while (buf); 1567 1550 } 1568 1551 1569 1552 /* ··· 1768 1791 spin_unlock(&portdev->c_ivq_lock); 1769 1792 } 1770 1793 1794 + static void flush_bufs(struct virtqueue *vq, bool can_sleep) 1795 + { 1796 + struct port_buffer *buf; 1797 + unsigned int len; 1798 + 1799 + while ((buf = virtqueue_get_buf(vq, &len))) 1800 + free_buf(buf, can_sleep); 1801 + } 1802 + 1771 1803 static void out_intr(struct virtqueue *vq) 1772 1804 { 1773 1805 struct port *port; 1774 1806 1775 1807 port = find_port_by_vq(vq->vdev->priv, vq); 1776 - if (!port) 1808 + if (!port) { 1809 + flush_bufs(vq, false); 1777 1810 return; 1811 + } 1778 1812 1779 1813 wake_up_interruptible(&port->waitqueue); 1780 1814 } ··· 1796 1808 unsigned long flags; 1797 1809 1798 1810 port = find_port_by_vq(vq->vdev->priv, vq); 1799 - if (!port) 1811 + if (!port) { 1812 + flush_bufs(vq, false); 1800 1813 return; 1814 + } 1801 1815 1802 1816 spin_lock_irqsave(&port->inbuf_lock, flags); 1803 1817 port->inbuf = get_inbuf(port); ··· 1974 1984 1975 1985 static void remove_vqs(struct ports_device *portdev) 1976 1986 { 1987 + struct virtqueue *vq; 1988 + 1989 + virtio_device_for_each_vq(portdev->vdev, vq) { 1990 + struct port_buffer *buf; 1991 + 1992 + flush_bufs(vq, true); 1993 + while ((buf = virtqueue_detach_unused_buf(vq))) 1994 + free_buf(buf, true); 1995 + } 1977 1996 portdev->vdev->config->del_vqs(portdev->vdev); 1978 1997 kfree(portdev->in_vqs); 1979 1998 kfree(portdev->out_vqs); 1980 1999 } 1981 2000 1982 - static void remove_controlq_data(struct ports_device *portdev) 2001 + static void virtcons_remove(struct virtio_device *vdev) 1983 2002 { 1984 - struct port_buffer *buf; 1985 - unsigned int len; 2003 + struct ports_device *portdev; 2004 + struct port *port, *port2; 1986 2005 1987 - if (!use_multiport(portdev)) 1988 - return; 2006 + portdev = vdev->priv; 1989 2007 1990 - while ((buf = virtqueue_get_buf(portdev->c_ivq, &len))) 1991 - free_buf(buf, true); 2008 + spin_lock_irq(&pdrvdata_lock); 2009 + list_del(&portdev->list); 2010 + spin_unlock_irq(&pdrvdata_lock); 1992 2011 1993 - while ((buf = virtqueue_detach_unused_buf(portdev->c_ivq))) 1994 - free_buf(buf, true); 2012 + /* Disable interrupts for vqs */ 2013 + vdev->config->reset(vdev); 2014 + /* Finish up work that's lined up */ 2015 + if (use_multiport(portdev)) 2016 + cancel_work_sync(&portdev->control_work); 2017 + else 2018 + cancel_work_sync(&portdev->config_work); 2019 + 2020 + list_for_each_entry_safe(port, port2, &portdev->ports, list) 2021 + unplug_port(port); 2022 + 2023 + unregister_chrdev(portdev->chr_major, "virtio-portsdev"); 2024 + 2025 + /* 2026 + * When yanking out a device, we immediately lose the 2027 + * (device-side) queues. So there's no point in keeping the 2028 + * guest side around till we drop our final reference. This 2029 + * also means that any ports which are in an open state will 2030 + * have to just stop using the port, as the vqs are going 2031 + * away. 2032 + */ 2033 + remove_vqs(portdev); 2034 + kfree(portdev); 1995 2035 } 1996 2036 1997 2037 /* ··· 2090 2070 2091 2071 spin_lock_init(&portdev->ports_lock); 2092 2072 INIT_LIST_HEAD(&portdev->ports); 2073 + INIT_LIST_HEAD(&portdev->list); 2093 2074 2094 2075 virtio_device_ready(portdev->vdev); 2095 2076 ··· 2108 2087 if (!nr_added_bufs) { 2109 2088 dev_err(&vdev->dev, 2110 2089 "Error allocating buffers for control queue\n"); 2111 - err = -ENOMEM; 2112 - goto free_vqs; 2090 + /* 2091 + * The host might want to notify mgmt sw about device 2092 + * add failure. 2093 + */ 2094 + __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID, 2095 + VIRTIO_CONSOLE_DEVICE_READY, 0); 2096 + /* Device was functional: we need full cleanup. */ 2097 + virtcons_remove(vdev); 2098 + return -ENOMEM; 2113 2099 } 2114 2100 } else { 2115 2101 /* ··· 2147 2119 2148 2120 return 0; 2149 2121 2150 - free_vqs: 2151 - /* The host might want to notify mgmt sw about device add failure */ 2152 - __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID, 2153 - VIRTIO_CONSOLE_DEVICE_READY, 0); 2154 - remove_vqs(portdev); 2155 2122 free_chrdev: 2156 2123 unregister_chrdev(portdev->chr_major, "virtio-portsdev"); 2157 2124 free: 2158 2125 kfree(portdev); 2159 2126 fail: 2160 2127 return err; 2161 - } 2162 - 2163 - static void virtcons_remove(struct virtio_device *vdev) 2164 - { 2165 - struct ports_device *portdev; 2166 - struct port *port, *port2; 2167 - 2168 - portdev = vdev->priv; 2169 - 2170 - spin_lock_irq(&pdrvdata_lock); 2171 - list_del(&portdev->list); 2172 - spin_unlock_irq(&pdrvdata_lock); 2173 - 2174 - /* Disable interrupts for vqs */ 2175 - vdev->config->reset(vdev); 2176 - /* Finish up work that's lined up */ 2177 - if (use_multiport(portdev)) 2178 - cancel_work_sync(&portdev->control_work); 2179 - else 2180 - cancel_work_sync(&portdev->config_work); 2181 - 2182 - list_for_each_entry_safe(port, port2, &portdev->ports, list) 2183 - unplug_port(port); 2184 - 2185 - unregister_chrdev(portdev->chr_major, "virtio-portsdev"); 2186 - 2187 - /* 2188 - * When yanking out a device, we immediately lose the 2189 - * (device-side) queues. So there's no point in keeping the 2190 - * guest side around till we drop our final reference. This 2191 - * also means that any ports which are in an open state will 2192 - * have to just stop using the port, as the vqs are going 2193 - * away. 2194 - */ 2195 - remove_controlq_data(portdev); 2196 - remove_vqs(portdev); 2197 - kfree(portdev); 2198 2128 } 2199 2129 2200 2130 static struct virtio_device_id id_table[] = { ··· 2195 2209 */ 2196 2210 if (use_multiport(portdev)) 2197 2211 virtqueue_disable_cb(portdev->c_ivq); 2198 - remove_controlq_data(portdev); 2199 2212 2200 2213 list_for_each_entry(port, &portdev->ports, list) { 2201 2214 virtqueue_disable_cb(port->in_vq);
+3
include/linux/virtio.h
··· 157 157 int virtio_device_restore(struct virtio_device *dev); 158 158 #endif 159 159 160 + #define virtio_device_for_each_vq(vdev, vq) \ 161 + list_for_each_entry(vq, &vdev->vqs, list) 162 + 160 163 /** 161 164 * virtio_driver - operations for a virtio I/O driver 162 165 * @driver: underlying device driver (populate name and owner).
+15
include/uapi/linux/virtio_balloon.h
··· 57 57 #define VIRTIO_BALLOON_S_HTLB_PGFAIL 9 /* Hugetlb page allocation failures */ 58 58 #define VIRTIO_BALLOON_S_NR 10 59 59 60 + #define VIRTIO_BALLOON_S_NAMES_WITH_PREFIX(VIRTIO_BALLOON_S_NAMES_prefix) { \ 61 + VIRTIO_BALLOON_S_NAMES_prefix "swap-in", \ 62 + VIRTIO_BALLOON_S_NAMES_prefix "swap-out", \ 63 + VIRTIO_BALLOON_S_NAMES_prefix "major-faults", \ 64 + VIRTIO_BALLOON_S_NAMES_prefix "minor-faults", \ 65 + VIRTIO_BALLOON_S_NAMES_prefix "free-memory", \ 66 + VIRTIO_BALLOON_S_NAMES_prefix "total-memory", \ 67 + VIRTIO_BALLOON_S_NAMES_prefix "available-memory", \ 68 + VIRTIO_BALLOON_S_NAMES_prefix "disk-caches", \ 69 + VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-allocations", \ 70 + VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-failures" \ 71 + } 72 + 73 + #define VIRTIO_BALLOON_S_NAMES VIRTIO_BALLOON_S_NAMES_WITH_PREFIX("") 74 + 60 75 /* 61 76 * Memory statistics structure. 62 77 * Driver fills an array of these structures and passes to device.