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 updates from Michael Tsirkin:
"Tests, fixes and cleanups.

Just minor tweaks, there's nothing major in this cycle"

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
virtio_ring: mark vring_dma_dev inline
virtio/vhost: add Jason to list of maintainers
virtio_blk: Delete an unnecessary initialisation in init_vq()
virtio_blk: Use kmalloc_array() in init_vq()
virtio: remove config.c
virtio: console: Unlock vqs while freeing buffers
ringtest: poll for new buffers once before updating event index
ringtest: commonize implementation of poll_avail/poll_used
ringtest: use link-time optimization
virtio: update balloon size in balloon "probe"
virtio_ring: Make interrupt suppression spec compliant
virtio_pci: Limit DMA mask to 44 bits for legacy virtio devices

+96 -122
+2
MAINTAINERS
··· 12783 12783 12784 12784 VIRTIO CORE, NET AND BLOCK DRIVERS 12785 12785 M: "Michael S. Tsirkin" <mst@redhat.com> 12786 + M: Jason Wang <jasowang@redhat.com> 12786 12787 L: virtualization@lists.linux-foundation.org 12787 12788 S: Maintained 12788 12789 F: Documentation/devicetree/bindings/virtio/ ··· 12814 12813 12815 12814 VIRTIO HOST (VHOST) 12816 12815 M: "Michael S. Tsirkin" <mst@redhat.com> 12816 + M: Jason Wang <jasowang@redhat.com> 12817 12817 L: kvm@vger.kernel.org 12818 12818 L: virtualization@lists.linux-foundation.org 12819 12819 L: netdev@vger.kernel.org
+5 -5
drivers/block/virtio_blk.c
··· 376 376 377 377 static int init_vq(struct virtio_blk *vblk) 378 378 { 379 - int err = 0; 379 + int err; 380 380 int i; 381 381 vq_callback_t **callbacks; 382 382 const char **names; ··· 390 390 if (err) 391 391 num_vqs = 1; 392 392 393 - vblk->vqs = kmalloc(sizeof(*vblk->vqs) * num_vqs, GFP_KERNEL); 393 + vblk->vqs = kmalloc_array(num_vqs, sizeof(*vblk->vqs), GFP_KERNEL); 394 394 if (!vblk->vqs) 395 395 return -ENOMEM; 396 396 397 - names = kmalloc(sizeof(*names) * num_vqs, GFP_KERNEL); 398 - callbacks = kmalloc(sizeof(*callbacks) * num_vqs, GFP_KERNEL); 399 - vqs = kmalloc(sizeof(*vqs) * num_vqs, GFP_KERNEL); 397 + names = kmalloc_array(num_vqs, sizeof(*names), GFP_KERNEL); 398 + callbacks = kmalloc_array(num_vqs, sizeof(*callbacks), GFP_KERNEL); 399 + vqs = kmalloc_array(num_vqs, sizeof(*vqs), GFP_KERNEL); 400 400 if (!names || !callbacks || !vqs) { 401 401 err = -ENOMEM; 402 402 goto out;
+16 -6
drivers/char/virtio_console.c
··· 1539 1539 spin_lock_irq(&port->inbuf_lock); 1540 1540 /* Remove unused data this port might have received. */ 1541 1541 discard_port_data(port); 1542 + spin_unlock_irq(&port->inbuf_lock); 1542 1543 1543 1544 /* Remove buffers we queued up for the Host to send us data in. */ 1544 - while ((buf = virtqueue_detach_unused_buf(port->in_vq))) 1545 - free_buf(buf, true); 1546 - spin_unlock_irq(&port->inbuf_lock); 1545 + do { 1546 + spin_lock_irq(&port->inbuf_lock); 1547 + buf = virtqueue_detach_unused_buf(port->in_vq); 1548 + spin_unlock_irq(&port->inbuf_lock); 1549 + if (buf) 1550 + free_buf(buf, true); 1551 + } while (buf); 1547 1552 1548 1553 spin_lock_irq(&port->outvq_lock); 1549 1554 reclaim_consumed_buffers(port); 1555 + spin_unlock_irq(&port->outvq_lock); 1550 1556 1551 1557 /* Free pending buffers from the out-queue. */ 1552 - while ((buf = virtqueue_detach_unused_buf(port->out_vq))) 1553 - free_buf(buf, true); 1554 - spin_unlock_irq(&port->outvq_lock); 1558 + do { 1559 + spin_lock_irq(&port->outvq_lock); 1560 + buf = virtqueue_detach_unused_buf(port->out_vq); 1561 + spin_unlock_irq(&port->outvq_lock); 1562 + if (buf) 1563 + free_buf(buf, true); 1564 + } while (buf); 1555 1565 } 1556 1566 1557 1567 /*
-12
drivers/virtio/config.c
··· 1 - /* Configuration space parsing helpers for virtio. 2 - * 3 - * The configuration is [type][len][... len bytes ...] fields. 4 - * 5 - * Copyright 2007 Rusty Russell, IBM Corporation. 6 - * GPL v2 or later. 7 - */ 8 - #include <linux/err.h> 9 - #include <linux/virtio.h> 10 - #include <linux/virtio_config.h> 11 - #include <linux/bug.h> 12 -
+2
drivers/virtio/virtio_balloon.c
··· 577 577 578 578 virtio_device_ready(vdev); 579 579 580 + if (towards_target(vb)) 581 + virtballoon_changed(vdev); 580 582 return 0; 581 583 582 584 out_del_vqs:
+12 -4
drivers/virtio/virtio_pci_legacy.c
··· 212 212 return -ENODEV; 213 213 } 214 214 215 - rc = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(64)); 216 - if (rc) 217 - rc = dma_set_mask_and_coherent(&pci_dev->dev, 218 - DMA_BIT_MASK(32)); 215 + rc = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(64)); 216 + if (rc) { 217 + rc = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(32)); 218 + } else { 219 + /* 220 + * The virtio ring base address is expressed as a 32-bit PFN, 221 + * with a page size of 1 << VIRTIO_PCI_QUEUE_ADDR_SHIFT. 222 + */ 223 + dma_set_coherent_mask(&pci_dev->dev, 224 + DMA_BIT_MASK(32 + VIRTIO_PCI_QUEUE_ADDR_SHIFT)); 225 + } 226 + 219 227 if (rc) 220 228 dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n"); 221 229
+10 -6
drivers/virtio/virtio_ring.c
··· 167 167 * making all of the arch DMA ops work on the vring device itself 168 168 * is a mess. For now, we use the parent device for DMA ops. 169 169 */ 170 - static struct device *vring_dma_dev(const struct vring_virtqueue *vq) 170 + static inline struct device *vring_dma_dev(const struct vring_virtqueue *vq) 171 171 { 172 172 return vq->vq.vdev->dev.parent; 173 173 } ··· 732 732 733 733 if (!(vq->avail_flags_shadow & VRING_AVAIL_F_NO_INTERRUPT)) { 734 734 vq->avail_flags_shadow |= VRING_AVAIL_F_NO_INTERRUPT; 735 - vq->vring.avail->flags = cpu_to_virtio16(_vq->vdev, vq->avail_flags_shadow); 735 + if (!vq->event) 736 + vq->vring.avail->flags = cpu_to_virtio16(_vq->vdev, vq->avail_flags_shadow); 736 737 } 737 738 738 739 } ··· 765 764 * entry. Always do both to keep code simple. */ 766 765 if (vq->avail_flags_shadow & VRING_AVAIL_F_NO_INTERRUPT) { 767 766 vq->avail_flags_shadow &= ~VRING_AVAIL_F_NO_INTERRUPT; 768 - vq->vring.avail->flags = cpu_to_virtio16(_vq->vdev, vq->avail_flags_shadow); 767 + if (!vq->event) 768 + vq->vring.avail->flags = cpu_to_virtio16(_vq->vdev, vq->avail_flags_shadow); 769 769 } 770 770 vring_used_event(&vq->vring) = cpu_to_virtio16(_vq->vdev, last_used_idx = vq->last_used_idx); 771 771 END_USE(vq); ··· 834 832 * more to do. */ 835 833 /* Depending on the VIRTIO_RING_F_USED_EVENT_IDX feature, we need to 836 834 * either clear the flags bit or point the event index at the next 837 - * entry. Always do both to keep code simple. */ 835 + * entry. Always update the event index to keep code simple. */ 838 836 if (vq->avail_flags_shadow & VRING_AVAIL_F_NO_INTERRUPT) { 839 837 vq->avail_flags_shadow &= ~VRING_AVAIL_F_NO_INTERRUPT; 840 - vq->vring.avail->flags = cpu_to_virtio16(_vq->vdev, vq->avail_flags_shadow); 838 + if (!vq->event) 839 + vq->vring.avail->flags = cpu_to_virtio16(_vq->vdev, vq->avail_flags_shadow); 841 840 } 842 841 /* TODO: tune this threshold */ 843 842 bufs = (u16)(vq->avail_idx_shadow - vq->last_used_idx) * 3 / 4; ··· 956 953 /* No callback? Tell other side not to bother us. */ 957 954 if (!callback) { 958 955 vq->avail_flags_shadow |= VRING_AVAIL_F_NO_INTERRUPT; 959 - vq->vring.avail->flags = cpu_to_virtio16(vdev, vq->avail_flags_shadow); 956 + if (!vq->event) 957 + vq->vring.avail->flags = cpu_to_virtio16(vdev, vq->avail_flags_shadow); 960 958 } 961 959 962 960 /* Put everything in free lists. */
+2 -2
tools/virtio/ringtest/Makefile
··· 3 3 all: ring virtio_ring_0_9 virtio_ring_poll virtio_ring_inorder ptr_ring noring 4 4 5 5 CFLAGS += -Wall 6 - CFLAGS += -pthread -O2 -ggdb 7 - LDFLAGS += -pthread -O2 -ggdb 6 + CFLAGS += -pthread -O2 -ggdb -flto -fwhole-program 7 + LDFLAGS += -pthread -O2 -ggdb -flto -fwhole-program 8 8 9 9 main.o: main.c main.h 10 10 ring.o: ring.c main.h
+16 -4
tools/virtio/ringtest/main.c
··· 96 96 assert(!ret); 97 97 } 98 98 99 - static void run_guest(void) 99 + void poll_used(void) 100 + { 101 + while (used_empty()) 102 + busy_wait(); 103 + } 104 + 105 + static void __attribute__((__flatten__)) run_guest(void) 100 106 { 101 107 int completed_before; 102 108 int completed = 0; ··· 147 141 assert(completed <= bufs); 148 142 assert(started <= bufs); 149 143 if (do_sleep) { 150 - if (enable_call()) 144 + if (used_empty() && enable_call()) 151 145 wait_for_call(); 152 146 } else { 153 147 poll_used(); ··· 155 149 } 156 150 } 157 151 158 - static void run_host(void) 152 + void poll_avail(void) 153 + { 154 + while (avail_empty()) 155 + busy_wait(); 156 + } 157 + 158 + static void __attribute__((__flatten__)) run_host(void) 159 159 { 160 160 int completed_before; 161 161 int completed = 0; ··· 172 160 173 161 for (;;) { 174 162 if (do_sleep) { 175 - if (enable_kick()) 163 + if (avail_empty() && enable_kick()) 176 164 wait_for_kick(); 177 165 } else { 178 166 poll_avail();
+2 -2
tools/virtio/ringtest/main.h
··· 56 56 int add_inbuf(unsigned, void *, void *); 57 57 void *get_buf(unsigned *, void **); 58 58 void disable_call(); 59 + bool used_empty(); 59 60 bool enable_call(); 60 61 void kick_available(); 61 - void poll_used(); 62 62 /* host side */ 63 63 void disable_kick(); 64 + bool avail_empty(); 64 65 bool enable_kick(); 65 66 bool use_buf(unsigned *, void **); 66 67 void call_used(); 67 - void poll_avail(); 68 68 69 69 /* implemented by main */ 70 70 extern bool do_sleep;
+4 -2
tools/virtio/ringtest/noring.c
··· 24 24 return "Buffer"; 25 25 } 26 26 27 - void poll_used(void) 27 + bool used_empty() 28 28 { 29 + return false; 29 30 } 30 31 31 32 void disable_call() ··· 55 54 assert(0); 56 55 } 57 56 58 - void poll_avail(void) 57 + bool avail_empty() 59 58 { 59 + return false; 60 60 } 61 61 62 62 bool use_buf(unsigned *lenp, void **bufp)
+4 -18
tools/virtio/ringtest/ptr_ring.c
··· 133 133 return datap; 134 134 } 135 135 136 - void poll_used(void) 136 + bool used_empty() 137 137 { 138 - void *b; 139 - 140 - do { 141 - if (tailcnt == headcnt || __ptr_ring_full(&array)) { 142 - b = NULL; 143 - barrier(); 144 - } else { 145 - b = "Buffer\n"; 146 - } 147 - } while (!b); 138 + return (tailcnt == headcnt || __ptr_ring_full(&array)); 148 139 } 149 140 150 141 void disable_call() ··· 164 173 assert(0); 165 174 } 166 175 167 - void poll_avail(void) 176 + bool avail_empty() 168 177 { 169 - void *b; 170 - 171 - do { 172 - barrier(); 173 - b = __ptr_ring_peek(&array); 174 - } while (!b); 178 + return !__ptr_ring_peek(&array); 175 179 } 176 180 177 181 bool use_buf(unsigned *lenp, void **bufp)
+6 -12
tools/virtio/ringtest/ring.c
··· 163 163 return datap; 164 164 } 165 165 166 - void poll_used(void) 166 + bool used_empty() 167 167 { 168 168 unsigned head = (ring_size - 1) & guest.last_used_idx; 169 169 170 - while (ring[head].flags & DESC_HW) 171 - busy_wait(); 170 + return (ring[head].flags & DESC_HW); 172 171 } 173 172 174 173 void disable_call() ··· 179 180 180 181 bool enable_call() 181 182 { 182 - unsigned head = (ring_size - 1) & guest.last_used_idx; 183 - 184 183 event->call_index = guest.last_used_idx; 185 184 /* Flush call index write */ 186 185 /* Barrier D (for pairing) */ 187 186 smp_mb(); 188 - return ring[head].flags & DESC_HW; 187 + return used_empty(); 189 188 } 190 189 191 190 void kick_available(void) ··· 210 213 211 214 bool enable_kick() 212 215 { 213 - unsigned head = (ring_size - 1) & host.used_idx; 214 - 215 216 event->kick_index = host.used_idx; 216 217 /* Barrier C (for pairing) */ 217 218 smp_mb(); 218 - return !(ring[head].flags & DESC_HW); 219 + return avail_empty(); 219 220 } 220 221 221 - void poll_avail(void) 222 + bool avail_empty() 222 223 { 223 224 unsigned head = (ring_size - 1) & host.used_idx; 224 225 225 - while (!(ring[head].flags & DESC_HW)) 226 - busy_wait(); 226 + return !(ring[head].flags & DESC_HW); 227 227 } 228 228 229 229 bool use_buf(unsigned *lenp, void **bufp)
+15 -49
tools/virtio/ringtest/virtio_ring_0_9.c
··· 194 194 return datap; 195 195 } 196 196 197 - void poll_used(void) 197 + bool used_empty() 198 198 { 199 + unsigned short last_used_idx = guest.last_used_idx; 199 200 #ifdef RING_POLL 200 - unsigned head = (ring_size - 1) & guest.last_used_idx; 201 + unsigned short head = last_used_idx & (ring_size - 1); 202 + unsigned index = ring.used->ring[head].id; 201 203 202 - for (;;) { 203 - unsigned index = ring.used->ring[head].id; 204 - 205 - if ((index ^ guest.last_used_idx ^ 0x8000) & ~(ring_size - 1)) 206 - busy_wait(); 207 - else 208 - break; 209 - } 204 + return (index ^ last_used_idx ^ 0x8000) & ~(ring_size - 1); 210 205 #else 211 - unsigned head = guest.last_used_idx; 212 - 213 - while (ring.used->idx == head) 214 - busy_wait(); 206 + return ring.used->idx == last_used_idx; 215 207 #endif 216 208 } 217 209 ··· 216 224 217 225 bool enable_call() 218 226 { 219 - unsigned short last_used_idx; 220 - 221 - vring_used_event(&ring) = (last_used_idx = guest.last_used_idx); 227 + vring_used_event(&ring) = guest.last_used_idx; 222 228 /* Flush call index write */ 223 229 /* Barrier D (for pairing) */ 224 230 smp_mb(); 225 - #ifdef RING_POLL 226 - { 227 - unsigned short head = last_used_idx & (ring_size - 1); 228 - unsigned index = ring.used->ring[head].id; 229 - 230 - return (index ^ last_used_idx ^ 0x8000) & ~(ring_size - 1); 231 - } 232 - #else 233 - return ring.used->idx == last_used_idx; 234 - #endif 231 + return used_empty(); 235 232 } 236 233 237 234 void kick_available(void) ··· 247 266 248 267 bool enable_kick() 249 268 { 250 - unsigned head = host.used_idx; 251 - 252 - vring_avail_event(&ring) = head; 269 + vring_avail_event(&ring) = host.used_idx; 253 270 /* Barrier C (for pairing) */ 254 271 smp_mb(); 255 - #ifdef RING_POLL 256 - { 257 - unsigned index = ring.avail->ring[head & (ring_size - 1)]; 258 - 259 - return (index ^ head ^ 0x8000) & ~(ring_size - 1); 260 - } 261 - #else 262 - return head == ring.avail->idx; 263 - #endif 272 + return avail_empty(); 264 273 } 265 274 266 - void poll_avail(void) 275 + bool avail_empty() 267 276 { 268 277 unsigned head = host.used_idx; 269 278 #ifdef RING_POLL 270 - for (;;) { 271 - unsigned index = ring.avail->ring[head & (ring_size - 1)]; 272 - if ((index ^ head ^ 0x8000) & ~(ring_size - 1)) 273 - busy_wait(); 274 - else 275 - break; 276 - } 279 + unsigned index = ring.avail->ring[head & (ring_size - 1)]; 280 + 281 + return ((index ^ head ^ 0x8000) & ~(ring_size - 1)); 277 282 #else 278 - while (ring.avail->idx == head) 279 - busy_wait(); 283 + return head == ring.avail->idx; 280 284 #endif 281 285 } 282 286