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

Pull vhost,virtio,vdpa bugfixes from Michael Tsirkin:
"Misc fixes all over the place.

Revert of virtio used length validation series: the approach taken
does not seem to work, breaking too many guests in the process. We'll
need to do length validation using some other approach"

[ This merge also ends up reverting commit f7a36b03a732 ("vsock/virtio:
suppress used length validation"), which came in through the
networking tree in the meantime, and was part of that whole used
length validation series - Linus ]

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
vdpa_sim: avoid putting an uninitialized iova_domain
vhost-vdpa: clean irqs before reseting vdpa device
virtio-blk: modify the value type of num in virtio_queue_rq()
vhost/vsock: cleanup removing `len` variable
vhost/vsock: fix incorrect used length reported to the guest
Revert "virtio_ring: validate used buffer length"
Revert "virtio-net: don't let virtio core to validate used length"
Revert "virtio-blk: don't let virtio core to validate used length"
Revert "virtio-scsi: don't let virtio core to validate used buffer length"

Changed files
+9 -76
drivers
block
net
scsi
vdpa
vdpa_sim
vhost
virtio
include
linux
net
vmw_vsock
+1 -2
drivers/block/virtio_blk.c
··· 316 316 struct request *req = bd->rq; 317 317 struct virtblk_req *vbr = blk_mq_rq_to_pdu(req); 318 318 unsigned long flags; 319 - unsigned int num; 319 + int num; 320 320 int qid = hctx->queue_num; 321 321 bool notify = false; 322 322 blk_status_t status; ··· 1049 1049 .feature_table_size = ARRAY_SIZE(features), 1050 1050 .feature_table_legacy = features_legacy, 1051 1051 .feature_table_size_legacy = ARRAY_SIZE(features_legacy), 1052 - .suppress_used_validation = true, 1053 1052 .driver.name = KBUILD_MODNAME, 1054 1053 .driver.owner = THIS_MODULE, 1055 1054 .id_table = id_table,
-1
drivers/net/virtio_net.c
··· 3423 3423 .feature_table_size = ARRAY_SIZE(features), 3424 3424 .feature_table_legacy = features_legacy, 3425 3425 .feature_table_size_legacy = ARRAY_SIZE(features_legacy), 3426 - .suppress_used_validation = true, 3427 3426 .driver.name = KBUILD_MODNAME, 3428 3427 .driver.owner = THIS_MODULE, 3429 3428 .id_table = id_table,
-1
drivers/scsi/virtio_scsi.c
··· 977 977 static struct virtio_driver virtio_scsi_driver = { 978 978 .feature_table = features, 979 979 .feature_table_size = ARRAY_SIZE(features), 980 - .suppress_used_validation = true, 981 980 .driver.name = KBUILD_MODNAME, 982 981 .driver.owner = THIS_MODULE, 983 982 .id_table = id_table,
+5 -2
drivers/vdpa/vdpa_sim/vdpa_sim.c
··· 591 591 vringh_kiov_cleanup(&vdpasim->vqs[i].in_iov); 592 592 } 593 593 594 - put_iova_domain(&vdpasim->iova); 595 - iova_cache_put(); 594 + if (vdpa_get_dma_dev(vdpa)) { 595 + put_iova_domain(&vdpasim->iova); 596 + iova_cache_put(); 597 + } 598 + 596 599 kvfree(vdpasim->buffer); 597 600 if (vdpasim->iommu) 598 601 vhost_iotlb_free(vdpasim->iommu);
+1 -1
drivers/vhost/vdpa.c
··· 1014 1014 1015 1015 mutex_lock(&d->mutex); 1016 1016 filep->private_data = NULL; 1017 + vhost_vdpa_clean_irq(v); 1017 1018 vhost_vdpa_reset(v); 1018 1019 vhost_dev_stop(&v->vdev); 1019 1020 vhost_vdpa_iotlb_free(v); 1020 1021 vhost_vdpa_free_domain(v); 1021 1022 vhost_vdpa_config_put(v); 1022 - vhost_vdpa_clean_irq(v); 1023 1023 vhost_dev_cleanup(&v->vdev); 1024 1024 kfree(v->vdev.vqs); 1025 1025 mutex_unlock(&d->mutex);
+2 -6
drivers/vhost/vsock.c
··· 511 511 512 512 vhost_disable_notify(&vsock->dev, vq); 513 513 do { 514 - u32 len; 515 - 516 514 if (!vhost_vsock_more_replies(vsock)) { 517 515 /* Stop tx until the device processes already 518 516 * pending replies. Leave tx virtqueue ··· 538 540 continue; 539 541 } 540 542 541 - len = pkt->len; 543 + total_len += sizeof(pkt->hdr) + pkt->len; 542 544 543 545 /* Deliver to monitoring devices all received packets */ 544 546 virtio_transport_deliver_tap_pkt(pkt); ··· 551 553 else 552 554 virtio_transport_free_pkt(pkt); 553 555 554 - len += sizeof(pkt->hdr); 555 - vhost_add_used(vq, head, len); 556 - total_len += len; 556 + vhost_add_used(vq, head, 0); 557 557 added = true; 558 558 } while(likely(!vhost_exceeds_weight(vq, ++pkts, total_len))); 559 559
-60
drivers/virtio/virtio_ring.c
··· 14 14 #include <linux/spinlock.h> 15 15 #include <xen/xen.h> 16 16 17 - static bool force_used_validation = false; 18 - module_param(force_used_validation, bool, 0444); 19 - 20 17 #ifdef DEBUG 21 18 /* For development, we want to crash whenever the ring is screwed. */ 22 19 #define BAD_RING(_vq, fmt, args...) \ ··· 181 184 size_t event_size_in_bytes; 182 185 } packed; 183 186 }; 184 - 185 - /* Per-descriptor in buffer length */ 186 - u32 *buflen; 187 187 188 188 /* How to notify other side. FIXME: commonalize hcalls! */ 189 189 bool (*notify)(struct virtqueue *vq); ··· 490 496 unsigned int i, n, avail, descs_used, prev, err_idx; 491 497 int head; 492 498 bool indirect; 493 - u32 buflen = 0; 494 499 495 500 START_USE(vq); 496 501 ··· 571 578 VRING_DESC_F_NEXT | 572 579 VRING_DESC_F_WRITE, 573 580 indirect); 574 - buflen += sg->length; 575 581 } 576 582 } 577 583 /* Last one doesn't continue. */ ··· 609 617 vq->split.desc_state[head].indir_desc = desc; 610 618 else 611 619 vq->split.desc_state[head].indir_desc = ctx; 612 - 613 - /* Store in buffer length if necessary */ 614 - if (vq->buflen) 615 - vq->buflen[head] = buflen; 616 620 617 621 /* Put entry in available array (but don't update avail->idx until they 618 622 * do sync). */ ··· 782 794 } 783 795 if (unlikely(!vq->split.desc_state[i].data)) { 784 796 BAD_RING(vq, "id %u is not a head!\n", i); 785 - return NULL; 786 - } 787 - if (vq->buflen && unlikely(*len > vq->buflen[i])) { 788 - BAD_RING(vq, "used len %d is larger than in buflen %u\n", 789 - *len, vq->buflen[i]); 790 797 return NULL; 791 798 } 792 799 ··· 1062 1079 unsigned int i, n, err_idx; 1063 1080 u16 head, id; 1064 1081 dma_addr_t addr; 1065 - u32 buflen = 0; 1066 1082 1067 1083 head = vq->packed.next_avail_idx; 1068 1084 desc = alloc_indirect_packed(total_sg, gfp); ··· 1091 1109 desc[i].addr = cpu_to_le64(addr); 1092 1110 desc[i].len = cpu_to_le32(sg->length); 1093 1111 i++; 1094 - if (n >= out_sgs) 1095 - buflen += sg->length; 1096 1112 } 1097 1113 } 1098 1114 ··· 1144 1164 vq->packed.desc_state[id].indir_desc = desc; 1145 1165 vq->packed.desc_state[id].last = id; 1146 1166 1147 - /* Store in buffer length if necessary */ 1148 - if (vq->buflen) 1149 - vq->buflen[id] = buflen; 1150 - 1151 1167 vq->num_added += 1; 1152 1168 1153 1169 pr_debug("Added buffer head %i to %p\n", head, vq); ··· 1179 1203 __le16 head_flags, flags; 1180 1204 u16 head, id, prev, curr, avail_used_flags; 1181 1205 int err; 1182 - u32 buflen = 0; 1183 1206 1184 1207 START_USE(vq); 1185 1208 ··· 1258 1283 1 << VRING_PACKED_DESC_F_AVAIL | 1259 1284 1 << VRING_PACKED_DESC_F_USED; 1260 1285 } 1261 - if (n >= out_sgs) 1262 - buflen += sg->length; 1263 1286 } 1264 1287 } 1265 1288 ··· 1276 1303 vq->packed.desc_state[id].data = data; 1277 1304 vq->packed.desc_state[id].indir_desc = ctx; 1278 1305 vq->packed.desc_state[id].last = prev; 1279 - 1280 - /* Store in buffer length if necessary */ 1281 - if (vq->buflen) 1282 - vq->buflen[id] = buflen; 1283 1306 1284 1307 /* 1285 1308 * A driver MUST NOT make the first descriptor in the list ··· 1461 1492 } 1462 1493 if (unlikely(!vq->packed.desc_state[id].data)) { 1463 1494 BAD_RING(vq, "id %u is not a head!\n", id); 1464 - return NULL; 1465 - } 1466 - if (vq->buflen && unlikely(*len > vq->buflen[id])) { 1467 - BAD_RING(vq, "used len %d is larger than in buflen %u\n", 1468 - *len, vq->buflen[id]); 1469 1495 return NULL; 1470 1496 } 1471 1497 ··· 1668 1704 struct vring_virtqueue *vq; 1669 1705 struct vring_packed_desc *ring; 1670 1706 struct vring_packed_desc_event *driver, *device; 1671 - struct virtio_driver *drv = drv_to_virtio(vdev->dev.driver); 1672 1707 dma_addr_t ring_dma_addr, driver_event_dma_addr, device_event_dma_addr; 1673 1708 size_t ring_size_in_bytes, event_size_in_bytes; 1674 1709 ··· 1757 1794 if (!vq->packed.desc_extra) 1758 1795 goto err_desc_extra; 1759 1796 1760 - if (!drv->suppress_used_validation || force_used_validation) { 1761 - vq->buflen = kmalloc_array(num, sizeof(*vq->buflen), 1762 - GFP_KERNEL); 1763 - if (!vq->buflen) 1764 - goto err_buflen; 1765 - } else { 1766 - vq->buflen = NULL; 1767 - } 1768 - 1769 1797 /* No callback? Tell other side not to bother us. */ 1770 1798 if (!callback) { 1771 1799 vq->packed.event_flags_shadow = VRING_PACKED_EVENT_FLAG_DISABLE; ··· 1769 1815 spin_unlock(&vdev->vqs_list_lock); 1770 1816 return &vq->vq; 1771 1817 1772 - err_buflen: 1773 - kfree(vq->packed.desc_extra); 1774 1818 err_desc_extra: 1775 1819 kfree(vq->packed.desc_state); 1776 1820 err_desc_state: ··· 2176 2224 void (*callback)(struct virtqueue *), 2177 2225 const char *name) 2178 2226 { 2179 - struct virtio_driver *drv = drv_to_virtio(vdev->dev.driver); 2180 2227 struct vring_virtqueue *vq; 2181 2228 2182 2229 if (virtio_has_feature(vdev, VIRTIO_F_RING_PACKED)) ··· 2235 2284 if (!vq->split.desc_extra) 2236 2285 goto err_extra; 2237 2286 2238 - if (!drv->suppress_used_validation || force_used_validation) { 2239 - vq->buflen = kmalloc_array(vring.num, sizeof(*vq->buflen), 2240 - GFP_KERNEL); 2241 - if (!vq->buflen) 2242 - goto err_buflen; 2243 - } else { 2244 - vq->buflen = NULL; 2245 - } 2246 - 2247 2287 /* Put everything in free lists. */ 2248 2288 vq->free_head = 0; 2249 2289 memset(vq->split.desc_state, 0, vring.num * ··· 2245 2303 spin_unlock(&vdev->vqs_list_lock); 2246 2304 return &vq->vq; 2247 2305 2248 - err_buflen: 2249 - kfree(vq->split.desc_extra); 2250 2306 err_extra: 2251 2307 kfree(vq->split.desc_state); 2252 2308 err_state:
-2
include/linux/virtio.h
··· 152 152 * @feature_table_size: number of entries in the feature table array. 153 153 * @feature_table_legacy: same as feature_table but when working in legacy mode. 154 154 * @feature_table_size_legacy: number of entries in feature table legacy array. 155 - * @suppress_used_validation: set to not have core validate used length 156 155 * @probe: the function to call when a device is found. Returns 0 or -errno. 157 156 * @scan: optional function to call after successful probe; intended 158 157 * for virtio-scsi to invoke a scan. ··· 168 169 unsigned int feature_table_size; 169 170 const unsigned int *feature_table_legacy; 170 171 unsigned int feature_table_size_legacy; 171 - bool suppress_used_validation; 172 172 int (*validate)(struct virtio_device *dev); 173 173 int (*probe)(struct virtio_device *dev); 174 174 void (*scan)(struct virtio_device *dev);
-1
net/vmw_vsock/virtio_transport.c
··· 731 731 static struct virtio_driver virtio_vsock_driver = { 732 732 .feature_table = features, 733 733 .feature_table_size = ARRAY_SIZE(features), 734 - .suppress_used_validation = true, 735 734 .driver.name = KBUILD_MODNAME, 736 735 .driver.owner = THIS_MODULE, 737 736 .id_table = id_table,