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

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

Pull virtio updates from Michael Tsirkin:
"Several new features here:

- virtio-net is finally supported in vduse

- virtio (balloon and mem) interaction with suspend is improved

- vhost-scsi now handles signals better/faster

And fixes, cleanups all over the place"

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: (48 commits)
virtio-pci: Check if is_avq is NULL
virtio: delete vq in vp_find_vqs_msix() when request_irq() fails
MAINTAINERS: add Eugenio Pérez as reviewer
vhost-vdpa: Remove usage of the deprecated ida_simple_xx() API
vp_vdpa: don't allocate unused msix vectors
sound: virtio: drop owner assignment
fuse: virtio: drop owner assignment
scsi: virtio: drop owner assignment
rpmsg: virtio: drop owner assignment
nvdimm: virtio_pmem: drop owner assignment
wifi: mac80211_hwsim: drop owner assignment
vsock/virtio: drop owner assignment
net: 9p: virtio: drop owner assignment
net: virtio: drop owner assignment
net: caif: virtio: drop owner assignment
misc: nsm: drop owner assignment
iommu: virtio: drop owner assignment
drm/virtio: drop owner assignment
gpio: virtio: drop owner assignment
firmware: arm_scmi: virtio: drop owner assignment
...

+355 -177
+8 -2
MAINTAINERS
··· 10654 10654 F: net/ieee802154/ 10655 10655 F: net/mac802154/ 10656 10656 10657 - IFCVF VIRTIO DATA PATH ACCELERATOR 10658 - R: Zhu Lingshan <lingshan.zhu@intel.com> 10657 + Intel VIRTIO DATA PATH ACCELERATOR 10658 + M: Zhu Lingshan <lingshan.zhu@intel.com> 10659 + L: virtualization@lists.linux.dev 10660 + S: Supported 10659 10661 F: drivers/vdpa/ifcvf/ 10660 10662 10661 10663 IFE PROTOCOL ··· 23748 23746 M: Jason Wang <jasowang@redhat.com> 23749 23747 R: Paolo Bonzini <pbonzini@redhat.com> 23750 23748 R: Stefan Hajnoczi <stefanha@redhat.com> 23749 + R: Eugenio Pérez <eperezma@redhat.com> 23751 23750 L: virtualization@lists.linux.dev 23752 23751 S: Maintained 23753 23752 F: drivers/block/virtio_blk.c ··· 23767 23764 M: "Michael S. Tsirkin" <mst@redhat.com> 23768 23765 M: Jason Wang <jasowang@redhat.com> 23769 23766 R: Xuan Zhuo <xuanzhuo@linux.alibaba.com> 23767 + R: Eugenio Pérez <eperezma@redhat.com> 23770 23768 L: virtualization@lists.linux.dev 23771 23769 S: Maintained 23772 23770 F: Documentation/ABI/testing/sysfs-bus-vdpa ··· 23809 23805 M: Vivek Goyal <vgoyal@redhat.com> 23810 23806 M: Stefan Hajnoczi <stefanha@redhat.com> 23811 23807 M: Miklos Szeredi <miklos@szeredi.hu> 23808 + R: Eugenio Pérez <eperezma@redhat.com> 23812 23809 L: virtualization@lists.linux.dev 23813 23810 L: linux-fsdevel@vger.kernel.org 23814 23811 S: Supported ··· 23843 23838 VIRTIO HOST (VHOST) 23844 23839 M: "Michael S. Tsirkin" <mst@redhat.com> 23845 23840 M: Jason Wang <jasowang@redhat.com> 23841 + R: Eugenio Pérez <eperezma@redhat.com> 23846 23842 L: kvm@vger.kernel.org 23847 23843 L: virtualization@lists.linux.dev 23848 23844 L: netdev@vger.kernel.org
-1
arch/um/drivers/virt-pci.c
··· 752 752 753 753 static struct virtio_driver um_pci_virtio_driver = { 754 754 .driver.name = "virtio-pci", 755 - .driver.owner = THIS_MODULE, 756 755 .id_table = id_table, 757 756 .probe = um_pci_virtio_probe, 758 757 .remove = um_pci_virtio_remove,
-1
drivers/block/virtio_blk.c
··· 1658 1658 .feature_table_legacy = features_legacy, 1659 1659 .feature_table_size_legacy = ARRAY_SIZE(features_legacy), 1660 1660 .driver.name = KBUILD_MODNAME, 1661 - .driver.owner = THIS_MODULE, 1662 1661 .id_table = id_table, 1663 1662 .probe = virtblk_probe, 1664 1663 .remove = virtblk_remove,
-1
drivers/bluetooth/virtio_bt.c
··· 415 415 416 416 static struct virtio_driver virtbt_driver = { 417 417 .driver.name = KBUILD_MODNAME, 418 - .driver.owner = THIS_MODULE, 419 418 .feature_table = virtbt_features, 420 419 .feature_table_size = ARRAY_SIZE(virtbt_features), 421 420 .id_table = virtbt_table,
-1
drivers/char/hw_random/virtio-rng.c
··· 245 245 246 246 static struct virtio_driver virtio_rng_driver = { 247 247 .driver.name = KBUILD_MODNAME, 248 - .driver.owner = THIS_MODULE, 249 248 .id_table = id_table, 250 249 .probe = virtrng_probe, 251 250 .remove = virtrng_remove,
-2
drivers/char/virtio_console.c
··· 2173 2173 .feature_table = features, 2174 2174 .feature_table_size = ARRAY_SIZE(features), 2175 2175 .driver.name = KBUILD_MODNAME, 2176 - .driver.owner = THIS_MODULE, 2177 2176 .id_table = id_table, 2178 2177 .probe = virtcons_probe, 2179 2178 .remove = virtcons_remove, ··· 2187 2188 .feature_table = rproc_serial_features, 2188 2189 .feature_table_size = ARRAY_SIZE(rproc_serial_features), 2189 2190 .driver.name = "virtio_rproc_serial", 2190 - .driver.owner = THIS_MODULE, 2191 2191 .id_table = rproc_serial_id_table, 2192 2192 .probe = virtcons_probe, 2193 2193 .remove = virtcons_remove,
-1
drivers/crypto/virtio/virtio_crypto_core.c
··· 581 581 582 582 static struct virtio_driver virtio_crypto_driver = { 583 583 .driver.name = KBUILD_MODNAME, 584 - .driver.owner = THIS_MODULE, 585 584 .feature_table = features, 586 585 .feature_table_size = ARRAY_SIZE(features), 587 586 .id_table = id_table,
-1
drivers/firmware/arm_scmi/virtio.c
··· 908 908 909 909 static struct virtio_driver virtio_scmi_driver = { 910 910 .driver.name = "scmi-virtio", 911 - .driver.owner = THIS_MODULE, 912 911 .feature_table = features, 913 912 .feature_table_size = ARRAY_SIZE(features), 914 913 .id_table = id_table,
-1
drivers/gpio/gpio-virtio.c
··· 653 653 .remove = virtio_gpio_remove, 654 654 .driver = { 655 655 .name = KBUILD_MODNAME, 656 - .owner = THIS_MODULE, 657 656 }, 658 657 }; 659 658 module_virtio_driver(virtio_gpio_driver);
-1
drivers/gpu/drm/virtio/virtgpu_drv.c
··· 154 154 .feature_table = features, 155 155 .feature_table_size = ARRAY_SIZE(features), 156 156 .driver.name = KBUILD_MODNAME, 157 - .driver.owner = THIS_MODULE, 158 157 .id_table = id_table, 159 158 .probe = virtio_gpu_probe, 160 159 .remove = virtio_gpu_remove,
-1
drivers/iommu/virtio-iommu.c
··· 1251 1251 1252 1252 static struct virtio_driver virtio_iommu_drv = { 1253 1253 .driver.name = KBUILD_MODNAME, 1254 - .driver.owner = THIS_MODULE, 1255 1254 .id_table = id_table, 1256 1255 .feature_table = features, 1257 1256 .feature_table_size = ARRAY_SIZE(features),
-1
drivers/misc/nsm.c
··· 494 494 .feature_table_legacy = 0, 495 495 .feature_table_size_legacy = 0, 496 496 .driver.name = KBUILD_MODNAME, 497 - .driver.owner = THIS_MODULE, 498 497 .id_table = id_table, 499 498 .probe = nsm_device_probe, 500 499 .remove = nsm_device_remove,
-1
drivers/net/caif/caif_virtio.c
··· 782 782 .feature_table = features, 783 783 .feature_table_size = ARRAY_SIZE(features), 784 784 .driver.name = KBUILD_MODNAME, 785 - .driver.owner = THIS_MODULE, 786 785 .id_table = id_table, 787 786 .probe = cfv_probe, 788 787 .remove = cfv_remove,
-1
drivers/net/virtio_net.c
··· 6039 6039 .feature_table_legacy = features_legacy, 6040 6040 .feature_table_size_legacy = ARRAY_SIZE(features_legacy), 6041 6041 .driver.name = KBUILD_MODNAME, 6042 - .driver.owner = THIS_MODULE, 6043 6042 .id_table = id_table, 6044 6043 .validate = virtnet_validate, 6045 6044 .probe = virtnet_probe,
-1
drivers/net/wireless/virtual/mac80211_hwsim.c
··· 6678 6678 6679 6679 static struct virtio_driver virtio_hwsim = { 6680 6680 .driver.name = KBUILD_MODNAME, 6681 - .driver.owner = THIS_MODULE, 6682 6681 .id_table = id_table, 6683 6682 .probe = hwsim_virtio_probe, 6684 6683 .remove = hwsim_virtio_remove,
-1
drivers/nvdimm/virtio_pmem.c
··· 151 151 .feature_table = features, 152 152 .feature_table_size = ARRAY_SIZE(features), 153 153 .driver.name = KBUILD_MODNAME, 154 - .driver.owner = THIS_MODULE, 155 154 .id_table = id_table, 156 155 .validate = virtio_pmem_validate, 157 156 .probe = virtio_pmem_probe,
-1
drivers/rpmsg/virtio_rpmsg_bus.c
··· 1053 1053 .feature_table = features, 1054 1054 .feature_table_size = ARRAY_SIZE(features), 1055 1055 .driver.name = KBUILD_MODNAME, 1056 - .driver.owner = THIS_MODULE, 1057 1056 .id_table = id_table, 1058 1057 .probe = rpmsg_probe, 1059 1058 .remove = rpmsg_remove,
-1
drivers/scsi/virtio_scsi.c
··· 1052 1052 .feature_table = features, 1053 1053 .feature_table_size = ARRAY_SIZE(features), 1054 1054 .driver.name = KBUILD_MODNAME, 1055 - .driver.owner = THIS_MODULE, 1056 1055 .id_table = id_table, 1057 1056 .probe = virtscsi_probe, 1058 1057 #ifdef CONFIG_PM_SLEEP
+1 -1
drivers/vdpa/vdpa.c
··· 98 98 ssize_t len; 99 99 100 100 device_lock(dev); 101 - len = snprintf(buf, PAGE_SIZE, "%s\n", vdev->driver_override); 101 + len = sysfs_emit(buf, "%s\n", vdev->driver_override); 102 102 device_unlock(dev); 103 103 104 104 return len;
+20 -4
drivers/vdpa/vdpa_user/vduse_dev.c
··· 8 8 * 9 9 */ 10 10 11 + #include "linux/virtio_net.h" 11 12 #include <linux/init.h> 12 13 #include <linux/module.h> 13 14 #include <linux/cdev.h> ··· 29 28 #include <uapi/linux/virtio_config.h> 30 29 #include <uapi/linux/virtio_ids.h> 31 30 #include <uapi/linux/virtio_blk.h> 31 + #include <uapi/linux/virtio_ring.h> 32 32 #include <linux/mod_devicetable.h> 33 33 34 34 #include "iova_domain.h" ··· 143 141 144 142 static u32 allowed_device_id[] = { 145 143 VIRTIO_ID_BLOCK, 144 + VIRTIO_ID_NET, 146 145 }; 147 146 148 147 static inline struct vduse_dev *vdpa_to_vduse(struct vdpa_device *vdpa) ··· 1708 1705 return false; 1709 1706 } 1710 1707 1711 - static bool features_is_valid(u64 features) 1708 + static bool features_is_valid(struct vduse_dev_config *config) 1712 1709 { 1713 - if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM))) 1710 + if (!(config->features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM))) 1714 1711 return false; 1715 1712 1716 1713 /* Now we only support read-only configuration space */ 1717 - if (features & (1ULL << VIRTIO_BLK_F_CONFIG_WCE)) 1714 + if ((config->device_id == VIRTIO_ID_BLOCK) && 1715 + (config->features & BIT_ULL(VIRTIO_BLK_F_CONFIG_WCE))) 1716 + return false; 1717 + else if ((config->device_id == VIRTIO_ID_NET) && 1718 + (config->features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ))) 1719 + return false; 1720 + 1721 + if ((config->device_id == VIRTIO_ID_NET) && 1722 + !(config->features & BIT_ULL(VIRTIO_F_VERSION_1))) 1718 1723 return false; 1719 1724 1720 1725 return true; ··· 1749 1738 if (!device_is_allowed(config->device_id)) 1750 1739 return false; 1751 1740 1752 - if (!features_is_valid(config->features)) 1741 + if (!features_is_valid(config)) 1753 1742 return false; 1754 1743 1755 1744 return true; ··· 1831 1820 { 1832 1821 int ret; 1833 1822 struct vduse_dev *dev; 1823 + 1824 + ret = -EPERM; 1825 + if ((config->device_id == VIRTIO_ID_NET) && !capable(CAP_NET_ADMIN)) 1826 + goto err; 1834 1827 1835 1828 ret = -EEXIST; 1836 1829 if (vduse_find_dev(config->name)) ··· 2079 2064 2080 2065 static struct virtio_device_id id_table[] = { 2081 2066 { VIRTIO_ID_BLOCK, VIRTIO_DEV_ANY_ID }, 2067 + { VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID }, 2082 2068 { 0 }, 2083 2069 }; 2084 2070
+20 -7
drivers/vdpa/virtio_pci/vp_vdpa.c
··· 160 160 struct pci_dev *pdev = mdev->pci_dev; 161 161 int i, ret, irq; 162 162 int queues = vp_vdpa->queues; 163 - int vectors = queues + 1; 163 + int vectors = 1; 164 + int msix_vec = 0; 165 + 166 + for (i = 0; i < queues; i++) { 167 + if (vp_vdpa->vring[i].cb.callback) 168 + vectors++; 169 + } 164 170 165 171 ret = pci_alloc_irq_vectors(pdev, vectors, vectors, PCI_IRQ_MSIX); 166 172 if (ret != vectors) { ··· 179 173 vp_vdpa->vectors = vectors; 180 174 181 175 for (i = 0; i < queues; i++) { 176 + if (!vp_vdpa->vring[i].cb.callback) 177 + continue; 178 + 182 179 snprintf(vp_vdpa->vring[i].msix_name, VP_VDPA_NAME_SIZE, 183 180 "vp-vdpa[%s]-%d\n", pci_name(pdev), i); 184 - irq = pci_irq_vector(pdev, i); 181 + irq = pci_irq_vector(pdev, msix_vec); 185 182 ret = devm_request_irq(&pdev->dev, irq, 186 183 vp_vdpa_vq_handler, 187 184 0, vp_vdpa->vring[i].msix_name, ··· 194 185 "vp_vdpa: fail to request irq for vq %d\n", i); 195 186 goto err; 196 187 } 197 - vp_modern_queue_vector(mdev, i, i); 188 + vp_modern_queue_vector(mdev, i, msix_vec); 198 189 vp_vdpa->vring[i].irq = irq; 190 + msix_vec++; 199 191 } 200 192 201 193 snprintf(vp_vdpa->msix_name, VP_VDPA_NAME_SIZE, "vp-vdpa[%s]-config\n", 202 194 pci_name(pdev)); 203 - irq = pci_irq_vector(pdev, queues); 195 + irq = pci_irq_vector(pdev, msix_vec); 204 196 ret = devm_request_irq(&pdev->dev, irq, vp_vdpa_config_handler, 0, 205 197 vp_vdpa->msix_name, vp_vdpa); 206 198 if (ret) { 207 199 dev_err(&pdev->dev, 208 - "vp_vdpa: fail to request irq for vq %d\n", i); 200 + "vp_vdpa: fail to request irq for config: %d\n", ret); 209 201 goto err; 210 202 } 211 - vp_modern_config_vector(mdev, queues); 203 + vp_modern_config_vector(mdev, msix_vec); 212 204 vp_vdpa->config_irq = irq; 213 205 214 206 return 0; ··· 226 216 227 217 if (status & VIRTIO_CONFIG_S_DRIVER_OK && 228 218 !(s & VIRTIO_CONFIG_S_DRIVER_OK)) { 229 - vp_vdpa_request_irq(vp_vdpa); 219 + if (vp_vdpa_request_irq(vp_vdpa)) { 220 + WARN_ON(1); 221 + return; 222 + } 230 223 } 231 224 232 225 vp_modern_set_status(mdev, status);
+44 -26
drivers/vhost/scsi.c
··· 210 210 211 211 struct vhost_scsi_tmf { 212 212 struct vhost_work vwork; 213 + struct work_struct flush_work; 213 214 struct vhost_scsi *vhost; 214 215 struct vhost_scsi_virtqueue *svq; 215 216 ··· 359 358 vhost_scsi_put_inflight(inflight); 360 359 } 361 360 361 + static void vhost_scsi_drop_cmds(struct vhost_scsi_virtqueue *svq) 362 + { 363 + struct vhost_scsi_cmd *cmd, *t; 364 + struct llist_node *llnode; 365 + 366 + llnode = llist_del_all(&svq->completion_list); 367 + llist_for_each_entry_safe(cmd, t, llnode, tvc_completion_list) 368 + vhost_scsi_release_cmd_res(&cmd->tvc_se_cmd); 369 + } 370 + 362 371 static void vhost_scsi_release_cmd(struct se_cmd *se_cmd) 363 372 { 364 373 if (se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) { 365 374 struct vhost_scsi_tmf *tmf = container_of(se_cmd, 366 375 struct vhost_scsi_tmf, se_cmd); 367 - struct vhost_virtqueue *vq = &tmf->svq->vq; 368 376 369 - vhost_vq_work_queue(vq, &tmf->vwork); 377 + schedule_work(&tmf->flush_work); 370 378 } else { 371 379 struct vhost_scsi_cmd *cmd = container_of(se_cmd, 372 380 struct vhost_scsi_cmd, tvc_se_cmd); ··· 383 373 struct vhost_scsi_virtqueue, vq); 384 374 385 375 llist_add(&cmd->tvc_completion_list, &svq->completion_list); 386 - vhost_vq_work_queue(&svq->vq, &svq->completion_work); 376 + if (!vhost_vq_work_queue(&svq->vq, &svq->completion_work)) 377 + vhost_scsi_drop_cmds(svq); 387 378 } 388 379 } 389 380 ··· 508 497 vq_err(vq, "Faulted on vhost_scsi_send_event\n"); 509 498 } 510 499 511 - static void vhost_scsi_evt_work(struct vhost_work *work) 500 + static void vhost_scsi_complete_events(struct vhost_scsi *vs, bool drop) 512 501 { 513 - struct vhost_scsi *vs = container_of(work, struct vhost_scsi, 514 - vs_event_work); 515 502 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; 516 503 struct vhost_scsi_evt *evt, *t; 517 504 struct llist_node *llnode; ··· 517 508 mutex_lock(&vq->mutex); 518 509 llnode = llist_del_all(&vs->vs_event_list); 519 510 llist_for_each_entry_safe(evt, t, llnode, list) { 520 - vhost_scsi_do_evt_work(vs, evt); 511 + if (!drop) 512 + vhost_scsi_do_evt_work(vs, evt); 521 513 vhost_scsi_free_evt(vs, evt); 522 514 } 523 515 mutex_unlock(&vq->mutex); 516 + } 517 + 518 + static void vhost_scsi_evt_work(struct vhost_work *work) 519 + { 520 + struct vhost_scsi *vs = container_of(work, struct vhost_scsi, 521 + vs_event_work); 522 + vhost_scsi_complete_events(vs, false); 524 523 } 525 524 526 525 static int vhost_scsi_copy_sgl_to_iov(struct vhost_scsi_cmd *cmd) ··· 1287 1270 { 1288 1271 struct vhost_scsi_tmf *tmf = container_of(work, struct vhost_scsi_tmf, 1289 1272 vwork); 1290 - struct vhost_virtqueue *ctl_vq, *vq; 1291 - int resp_code, i; 1273 + int resp_code; 1292 1274 1293 - if (tmf->scsi_resp == TMR_FUNCTION_COMPLETE) { 1294 - /* 1295 - * Flush IO vqs that don't share a worker with the ctl to make 1296 - * sure they have sent their responses before us. 1297 - */ 1298 - ctl_vq = &tmf->vhost->vqs[VHOST_SCSI_VQ_CTL].vq; 1299 - for (i = VHOST_SCSI_VQ_IO; i < tmf->vhost->dev.nvqs; i++) { 1300 - vq = &tmf->vhost->vqs[i].vq; 1301 - 1302 - if (vhost_vq_is_setup(vq) && 1303 - vq->worker != ctl_vq->worker) 1304 - vhost_vq_flush(vq); 1305 - } 1306 - 1275 + if (tmf->scsi_resp == TMR_FUNCTION_COMPLETE) 1307 1276 resp_code = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED; 1308 - } else { 1277 + else 1309 1278 resp_code = VIRTIO_SCSI_S_FUNCTION_REJECTED; 1310 - } 1311 1279 1312 1280 vhost_scsi_send_tmf_resp(tmf->vhost, &tmf->svq->vq, tmf->in_iovs, 1313 1281 tmf->vq_desc, &tmf->resp_iov, resp_code); 1314 1282 vhost_scsi_release_tmf_res(tmf); 1283 + } 1284 + 1285 + static void vhost_scsi_tmf_flush_work(struct work_struct *work) 1286 + { 1287 + struct vhost_scsi_tmf *tmf = container_of(work, struct vhost_scsi_tmf, 1288 + flush_work); 1289 + struct vhost_virtqueue *vq = &tmf->svq->vq; 1290 + /* 1291 + * Make sure we have sent responses for other commands before we 1292 + * send our response. 1293 + */ 1294 + vhost_dev_flush(vq->dev); 1295 + if (!vhost_vq_work_queue(vq, &tmf->vwork)) 1296 + vhost_scsi_release_tmf_res(tmf); 1315 1297 } 1316 1298 1317 1299 static void ··· 1336 1320 if (!tmf) 1337 1321 goto send_reject; 1338 1322 1323 + INIT_WORK(&tmf->flush_work, vhost_scsi_tmf_flush_work); 1339 1324 vhost_work_init(&tmf->vwork, vhost_scsi_tmf_resp_work); 1340 1325 tmf->vhost = vs; 1341 1326 tmf->svq = svq; ··· 1526 1509 } 1527 1510 1528 1511 llist_add(&evt->list, &vs->vs_event_list); 1529 - vhost_vq_work_queue(vq, &vs->vs_event_work); 1512 + if (!vhost_vq_work_queue(vq, &vs->vs_event_work)) 1513 + vhost_scsi_complete_events(vs, true); 1530 1514 } 1531 1515 1532 1516 static void vhost_scsi_evt_handle_kick(struct vhost_work *work)
+3 -3
drivers/vhost/vdpa.c
··· 1548 1548 struct vhost_vdpa *v = 1549 1549 container_of(device, struct vhost_vdpa, dev); 1550 1550 1551 - ida_simple_remove(&vhost_vdpa_ida, v->minor); 1551 + ida_free(&vhost_vdpa_ida, v->minor); 1552 1552 kfree(v->vqs); 1553 1553 kfree(v); 1554 1554 } ··· 1571 1571 if (!v) 1572 1572 return -ENOMEM; 1573 1573 1574 - minor = ida_simple_get(&vhost_vdpa_ida, 0, 1575 - VHOST_VDPA_DEV_MAX, GFP_KERNEL); 1574 + minor = ida_alloc_max(&vhost_vdpa_ida, VHOST_VDPA_DEV_MAX - 1, 1575 + GFP_KERNEL); 1576 1576 if (minor < 0) { 1577 1577 kfree(v); 1578 1578 return minor;
+93 -37
drivers/vhost/vhost.c
··· 263 263 } 264 264 EXPORT_SYMBOL_GPL(vhost_vq_work_queue); 265 265 266 - void vhost_vq_flush(struct vhost_virtqueue *vq) 267 - { 268 - struct vhost_flush_struct flush; 269 - 270 - init_completion(&flush.wait_event); 271 - vhost_work_init(&flush.work, vhost_flush_work); 272 - 273 - if (vhost_vq_work_queue(vq, &flush.work)) 274 - wait_for_completion(&flush.wait_event); 275 - } 276 - EXPORT_SYMBOL_GPL(vhost_vq_flush); 277 - 278 266 /** 279 - * vhost_worker_flush - flush a worker 267 + * __vhost_worker_flush - flush a worker 280 268 * @worker: worker to flush 281 269 * 282 - * This does not use RCU to protect the worker, so the device or worker 283 - * mutex must be held. 270 + * The worker's flush_mutex must be held. 284 271 */ 285 - static void vhost_worker_flush(struct vhost_worker *worker) 272 + static void __vhost_worker_flush(struct vhost_worker *worker) 286 273 { 287 274 struct vhost_flush_struct flush; 275 + 276 + if (!worker->attachment_cnt || worker->killed) 277 + return; 288 278 289 279 init_completion(&flush.wait_event); 290 280 vhost_work_init(&flush.work, vhost_flush_work); 291 281 292 282 vhost_worker_queue(worker, &flush.work); 283 + /* 284 + * Drop mutex in case our worker is killed and it needs to take the 285 + * mutex to force cleanup. 286 + */ 287 + mutex_unlock(&worker->mutex); 293 288 wait_for_completion(&flush.wait_event); 289 + mutex_lock(&worker->mutex); 290 + } 291 + 292 + static void vhost_worker_flush(struct vhost_worker *worker) 293 + { 294 + mutex_lock(&worker->mutex); 295 + __vhost_worker_flush(worker); 296 + mutex_unlock(&worker->mutex); 294 297 } 295 298 296 299 void vhost_dev_flush(struct vhost_dev *dev) ··· 301 298 struct vhost_worker *worker; 302 299 unsigned long i; 303 300 304 - xa_for_each(&dev->worker_xa, i, worker) { 305 - mutex_lock(&worker->mutex); 306 - if (!worker->attachment_cnt) { 307 - mutex_unlock(&worker->mutex); 308 - continue; 309 - } 301 + xa_for_each(&dev->worker_xa, i, worker) 310 302 vhost_worker_flush(worker); 311 - mutex_unlock(&worker->mutex); 312 - } 313 303 } 314 304 EXPORT_SYMBOL_GPL(vhost_dev_flush); 315 305 ··· 388 392 __vhost_vq_meta_reset(vq); 389 393 } 390 394 391 - static bool vhost_worker(void *data) 395 + static bool vhost_run_work_list(void *data) 392 396 { 393 397 struct vhost_worker *worker = data; 394 398 struct vhost_work *work, *work_next; ··· 411 415 } 412 416 413 417 return !!node; 418 + } 419 + 420 + static void vhost_worker_killed(void *data) 421 + { 422 + struct vhost_worker *worker = data; 423 + struct vhost_dev *dev = worker->dev; 424 + struct vhost_virtqueue *vq; 425 + int i, attach_cnt = 0; 426 + 427 + mutex_lock(&worker->mutex); 428 + worker->killed = true; 429 + 430 + for (i = 0; i < dev->nvqs; i++) { 431 + vq = dev->vqs[i]; 432 + 433 + mutex_lock(&vq->mutex); 434 + if (worker == 435 + rcu_dereference_check(vq->worker, 436 + lockdep_is_held(&vq->mutex))) { 437 + rcu_assign_pointer(vq->worker, NULL); 438 + attach_cnt++; 439 + } 440 + mutex_unlock(&vq->mutex); 441 + } 442 + 443 + worker->attachment_cnt -= attach_cnt; 444 + if (attach_cnt) 445 + synchronize_rcu(); 446 + /* 447 + * Finish vhost_worker_flush calls and any other works that snuck in 448 + * before the synchronize_rcu. 449 + */ 450 + vhost_run_work_list(worker); 451 + mutex_unlock(&worker->mutex); 414 452 } 415 453 416 454 static void vhost_vq_free_iovecs(struct vhost_virtqueue *vq) ··· 661 631 if (!worker) 662 632 return NULL; 663 633 634 + worker->dev = dev; 664 635 snprintf(name, sizeof(name), "vhost-%d", current->pid); 665 636 666 - vtsk = vhost_task_create(vhost_worker, worker, name); 637 + vtsk = vhost_task_create(vhost_run_work_list, vhost_worker_killed, 638 + worker, name); 667 639 if (!vtsk) 668 640 goto free_worker; 669 641 ··· 696 664 { 697 665 struct vhost_worker *old_worker; 698 666 699 - old_worker = rcu_dereference_check(vq->worker, 700 - lockdep_is_held(&vq->dev->mutex)); 701 - 702 667 mutex_lock(&worker->mutex); 703 - worker->attachment_cnt++; 704 - mutex_unlock(&worker->mutex); 705 - rcu_assign_pointer(vq->worker, worker); 706 - 707 - if (!old_worker) 668 + if (worker->killed) { 669 + mutex_unlock(&worker->mutex); 708 670 return; 671 + } 672 + 673 + mutex_lock(&vq->mutex); 674 + 675 + old_worker = rcu_dereference_check(vq->worker, 676 + lockdep_is_held(&vq->mutex)); 677 + rcu_assign_pointer(vq->worker, worker); 678 + worker->attachment_cnt++; 679 + 680 + if (!old_worker) { 681 + mutex_unlock(&vq->mutex); 682 + mutex_unlock(&worker->mutex); 683 + return; 684 + } 685 + mutex_unlock(&vq->mutex); 686 + mutex_unlock(&worker->mutex); 687 + 709 688 /* 710 689 * Take the worker mutex to make sure we see the work queued from 711 690 * device wide flushes which doesn't use RCU for execution. 712 691 */ 713 692 mutex_lock(&old_worker->mutex); 714 - old_worker->attachment_cnt--; 693 + if (old_worker->killed) { 694 + mutex_unlock(&old_worker->mutex); 695 + return; 696 + } 697 + 715 698 /* 716 699 * We don't want to call synchronize_rcu for every vq during setup 717 700 * because it will slow down VM startup. If we haven't done ··· 737 690 mutex_lock(&vq->mutex); 738 691 if (!vhost_vq_get_backend(vq) && !vq->kick) { 739 692 mutex_unlock(&vq->mutex); 693 + 694 + old_worker->attachment_cnt--; 740 695 mutex_unlock(&old_worker->mutex); 741 696 /* 742 697 * vsock can queue anytime after VHOST_VSOCK_SET_GUEST_CID. ··· 754 705 /* Make sure new vq queue/flush/poll calls see the new worker */ 755 706 synchronize_rcu(); 756 707 /* Make sure whatever was queued gets run */ 757 - vhost_worker_flush(old_worker); 708 + __vhost_worker_flush(old_worker); 709 + old_worker->attachment_cnt--; 758 710 mutex_unlock(&old_worker->mutex); 759 711 } 760 712 ··· 804 754 return -ENODEV; 805 755 806 756 mutex_lock(&worker->mutex); 807 - if (worker->attachment_cnt) { 757 + if (worker->attachment_cnt || worker->killed) { 808 758 mutex_unlock(&worker->mutex); 809 759 return -EBUSY; 810 760 } 761 + /* 762 + * A flush might have raced and snuck in before attachment_cnt was set 763 + * to zero. Make sure flushes are flushed from the queue before 764 + * freeing. 765 + */ 766 + __vhost_worker_flush(worker); 811 767 mutex_unlock(&worker->mutex); 812 768 813 769 vhost_worker_destroy(dev, worker);
+2 -1
drivers/vhost/vhost.h
··· 28 28 29 29 struct vhost_worker { 30 30 struct vhost_task *vtsk; 31 + struct vhost_dev *dev; 31 32 /* Used to serialize device wide flushing with worker swapping. */ 32 33 struct mutex mutex; 33 34 struct llist_head work_list; 34 35 u64 kcov_handle; 35 36 u32 id; 36 37 int attachment_cnt; 38 + bool killed; 37 39 }; 38 40 39 41 /* Poll a file (eventfd or socket) */ ··· 207 205 struct vhost_log *log, unsigned int *log_num); 208 206 void vhost_discard_vq_desc(struct vhost_virtqueue *, int n); 209 207 210 - void vhost_vq_flush(struct vhost_virtqueue *vq); 211 208 bool vhost_vq_work_queue(struct vhost_virtqueue *vq, struct vhost_work *work); 212 209 bool vhost_vq_has_work(struct vhost_virtqueue *vq); 213 210 bool vhost_vq_is_setup(struct vhost_virtqueue *vq);
+55 -30
drivers/virtio/virtio_balloon.c
··· 121 121 struct page_reporting_dev_info pr_dev_info; 122 122 123 123 /* State for keeping the wakeup_source active while adjusting the balloon */ 124 - spinlock_t adjustment_lock; 125 - bool adjustment_signal_pending; 126 - bool adjustment_in_progress; 124 + spinlock_t wakeup_lock; 125 + bool processing_wakeup_event; 126 + u32 wakeup_signal_mask; 127 127 }; 128 + 129 + #define VIRTIO_BALLOON_WAKEUP_SIGNAL_ADJUST (1 << 0) 130 + #define VIRTIO_BALLOON_WAKEUP_SIGNAL_STATS (1 << 1) 128 131 129 132 static const struct virtio_device_id id_table[] = { 130 133 { VIRTIO_ID_BALLOON, VIRTIO_DEV_ANY_ID }, ··· 141 138 BUILD_BUG_ON(PAGE_SHIFT < VIRTIO_BALLOON_PFN_SHIFT); 142 139 /* Convert pfn from Linux page size to balloon page size. */ 143 140 return pfn * VIRTIO_BALLOON_PAGES_PER_PAGE; 141 + } 142 + 143 + static void start_wakeup_event(struct virtio_balloon *vb, u32 mask) 144 + { 145 + unsigned long flags; 146 + 147 + spin_lock_irqsave(&vb->wakeup_lock, flags); 148 + vb->wakeup_signal_mask |= mask; 149 + if (!vb->processing_wakeup_event) { 150 + vb->processing_wakeup_event = true; 151 + pm_stay_awake(&vb->vdev->dev); 152 + } 153 + spin_unlock_irqrestore(&vb->wakeup_lock, flags); 154 + } 155 + 156 + static void process_wakeup_event(struct virtio_balloon *vb, u32 mask) 157 + { 158 + spin_lock_irq(&vb->wakeup_lock); 159 + vb->wakeup_signal_mask &= ~mask; 160 + spin_unlock_irq(&vb->wakeup_lock); 161 + } 162 + 163 + static void finish_wakeup_event(struct virtio_balloon *vb) 164 + { 165 + spin_lock_irq(&vb->wakeup_lock); 166 + if (!vb->wakeup_signal_mask && vb->processing_wakeup_event) { 167 + vb->processing_wakeup_event = false; 168 + pm_relax(&vb->vdev->dev); 169 + } 170 + spin_unlock_irq(&vb->wakeup_lock); 144 171 } 145 172 146 173 static void balloon_ack(struct virtqueue *vq) ··· 403 370 struct virtio_balloon *vb = vq->vdev->priv; 404 371 405 372 spin_lock(&vb->stop_update_lock); 406 - if (!vb->stop_update) 373 + if (!vb->stop_update) { 374 + start_wakeup_event(vb, VIRTIO_BALLOON_WAKEUP_SIGNAL_STATS); 407 375 queue_work(system_freezable_wq, &vb->update_balloon_stats_work); 376 + } 408 377 spin_unlock(&vb->stop_update_lock); 409 378 } 410 379 ··· 479 444 480 445 static void start_update_balloon_size(struct virtio_balloon *vb) 481 446 { 482 - unsigned long flags; 483 - 484 - spin_lock_irqsave(&vb->adjustment_lock, flags); 485 - vb->adjustment_signal_pending = true; 486 - if (!vb->adjustment_in_progress) { 487 - vb->adjustment_in_progress = true; 488 - pm_stay_awake(vb->vdev->dev.parent); 489 - } 490 - spin_unlock_irqrestore(&vb->adjustment_lock, flags); 491 - 447 + start_wakeup_event(vb, VIRTIO_BALLOON_WAKEUP_SIGNAL_ADJUST); 492 448 queue_work(system_freezable_wq, &vb->update_balloon_size_work); 493 - } 494 - 495 - static void end_update_balloon_size(struct virtio_balloon *vb) 496 - { 497 - spin_lock_irq(&vb->adjustment_lock); 498 - if (!vb->adjustment_signal_pending && vb->adjustment_in_progress) { 499 - vb->adjustment_in_progress = false; 500 - pm_relax(vb->vdev->dev.parent); 501 - } 502 - spin_unlock_irq(&vb->adjustment_lock); 503 449 } 504 450 505 451 static void virtballoon_changed(struct virtio_device *vdev) ··· 511 495 512 496 vb = container_of(work, struct virtio_balloon, 513 497 update_balloon_stats_work); 498 + 499 + process_wakeup_event(vb, VIRTIO_BALLOON_WAKEUP_SIGNAL_STATS); 514 500 stats_handle_request(vb); 501 + finish_wakeup_event(vb); 515 502 } 516 503 517 504 static void update_balloon_size_func(struct work_struct *work) ··· 525 506 vb = container_of(work, struct virtio_balloon, 526 507 update_balloon_size_work); 527 508 528 - spin_lock_irq(&vb->adjustment_lock); 529 - vb->adjustment_signal_pending = false; 530 - spin_unlock_irq(&vb->adjustment_lock); 509 + process_wakeup_event(vb, VIRTIO_BALLOON_WAKEUP_SIGNAL_ADJUST); 531 510 532 511 diff = towards_target(vb); 533 512 ··· 540 523 if (diff) 541 524 queue_work(system_freezable_wq, work); 542 525 else 543 - end_update_balloon_size(vb); 526 + finish_wakeup_event(vb); 544 527 } 545 528 546 529 static int init_vqs(struct virtio_balloon *vb) ··· 1044 1027 goto out_unregister_oom; 1045 1028 } 1046 1029 1047 - spin_lock_init(&vb->adjustment_lock); 1030 + spin_lock_init(&vb->wakeup_lock); 1031 + 1032 + /* 1033 + * The virtio balloon itself can't wake up the device, but it is 1034 + * responsible for processing wakeup events passed up from the transport 1035 + * layer. Wakeup sources don't support nesting/chaining calls, so we use 1036 + * our own wakeup source to ensure wakeup events are properly handled 1037 + * without trampling on the transport layer's wakeup source. 1038 + */ 1039 + device_set_wakeup_capable(&vb->vdev->dev, true); 1048 1040 1049 1041 virtio_device_ready(vdev); 1050 1042 ··· 1181 1155 .feature_table = features, 1182 1156 .feature_table_size = ARRAY_SIZE(features), 1183 1157 .driver.name = KBUILD_MODNAME, 1184 - .driver.owner = THIS_MODULE, 1185 1158 .id_table = id_table, 1186 1159 .validate = virtballoon_validate, 1187 1160 .probe = virtballoon_probe,
-1
drivers/virtio/virtio_input.c
··· 394 394 395 395 static struct virtio_driver virtio_input_driver = { 396 396 .driver.name = KBUILD_MODNAME, 397 - .driver.owner = THIS_MODULE, 398 397 .feature_table = features, 399 398 .feature_table_size = ARRAY_SIZE(features), 400 399 .id_table = id_table,
+62 -7
drivers/virtio/virtio_mem.c
··· 22 22 #include <linux/lockdep.h> 23 23 #include <linux/log2.h> 24 24 #include <linux/vmalloc.h> 25 + #include <linux/suspend.h> 25 26 26 27 #include <acpi/acpi_numa.h> 27 28 ··· 253 252 254 253 /* Memory notifier (online/offline events). */ 255 254 struct notifier_block memory_notifier; 255 + 256 + /* Notifier to block hibernation image storing/reloading. */ 257 + struct notifier_block pm_notifier; 256 258 257 259 #ifdef CONFIG_PROC_VMCORE 258 260 /* vmcore callback for /proc/vmcore handling in kdump mode */ ··· 1114 1110 lockdep_on(); 1115 1111 1116 1112 return rc; 1113 + } 1114 + 1115 + static int virtio_mem_pm_notifier_cb(struct notifier_block *nb, 1116 + unsigned long action, void *arg) 1117 + { 1118 + struct virtio_mem *vm = container_of(nb, struct virtio_mem, 1119 + pm_notifier); 1120 + switch (action) { 1121 + case PM_HIBERNATION_PREPARE: 1122 + case PM_RESTORE_PREPARE: 1123 + /* 1124 + * When restarting the VM, all memory is unplugged. Don't 1125 + * allow to hibernate and restore from an image. 1126 + */ 1127 + dev_err(&vm->vdev->dev, "hibernation is not supported.\n"); 1128 + return NOTIFY_BAD; 1129 + default: 1130 + return NOTIFY_OK; 1131 + } 1117 1132 } 1118 1133 1119 1134 /* ··· 2639 2616 rc = register_memory_notifier(&vm->memory_notifier); 2640 2617 if (rc) 2641 2618 goto out_unreg_group; 2642 - rc = register_virtio_mem_device(vm); 2619 + /* Block hibernation as early as possible. */ 2620 + vm->pm_notifier.priority = INT_MAX; 2621 + vm->pm_notifier.notifier_call = virtio_mem_pm_notifier_cb; 2622 + rc = register_pm_notifier(&vm->pm_notifier); 2643 2623 if (rc) 2644 2624 goto out_unreg_mem; 2625 + rc = register_virtio_mem_device(vm); 2626 + if (rc) 2627 + goto out_unreg_pm; 2645 2628 2646 2629 return 0; 2630 + out_unreg_pm: 2631 + unregister_pm_notifier(&vm->pm_notifier); 2647 2632 out_unreg_mem: 2648 2633 unregister_memory_notifier(&vm->memory_notifier); 2649 2634 out_unreg_group: ··· 2929 2898 2930 2899 /* unregister callbacks */ 2931 2900 unregister_virtio_mem_device(vm); 2901 + unregister_pm_notifier(&vm->pm_notifier); 2932 2902 unregister_memory_notifier(&vm->memory_notifier); 2933 2903 2934 2904 /* ··· 2993 2961 #ifdef CONFIG_PM_SLEEP 2994 2962 static int virtio_mem_freeze(struct virtio_device *vdev) 2995 2963 { 2964 + struct virtio_mem *vm = vdev->priv; 2965 + 2996 2966 /* 2997 - * When restarting the VM, all memory is usually unplugged. Don't 2998 - * allow to suspend/hibernate. 2967 + * We block hibernation using the PM notifier completely. The workqueue 2968 + * is already frozen by the PM core at this point, so we simply 2969 + * reset the device and cleanup the queues. 2999 2970 */ 3000 - dev_err(&vdev->dev, "save/restore not supported.\n"); 3001 - return -EPERM; 2971 + if (pm_suspend_target_state != PM_SUSPEND_TO_IDLE && 2972 + vm->plugged_size && 2973 + !virtio_has_feature(vm->vdev, VIRTIO_MEM_F_PERSISTENT_SUSPEND)) { 2974 + dev_err(&vm->vdev->dev, 2975 + "suspending with plugged memory is not supported\n"); 2976 + return -EPERM; 2977 + } 2978 + 2979 + virtio_reset_device(vdev); 2980 + vdev->config->del_vqs(vdev); 2981 + vm->vq = NULL; 2982 + return 0; 3002 2983 } 3003 2984 3004 2985 static int virtio_mem_restore(struct virtio_device *vdev) 3005 2986 { 3006 - return -EPERM; 2987 + struct virtio_mem *vm = vdev->priv; 2988 + int ret; 2989 + 2990 + ret = virtio_mem_init_vq(vm); 2991 + if (ret) 2992 + return ret; 2993 + virtio_device_ready(vdev); 2994 + 2995 + /* Let's check if anything changed. */ 2996 + virtio_mem_config_changed(vdev); 2997 + return 0; 3007 2998 } 3008 2999 #endif 3009 3000 ··· 3035 2980 VIRTIO_MEM_F_ACPI_PXM, 3036 2981 #endif 3037 2982 VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE, 2983 + VIRTIO_MEM_F_PERSISTENT_SUSPEND, 3038 2984 }; 3039 2985 3040 2986 static const struct virtio_device_id virtio_mem_id_table[] = { ··· 3047 2991 .feature_table = virtio_mem_features, 3048 2992 .feature_table_size = ARRAY_SIZE(virtio_mem_features), 3049 2993 .driver.name = KBUILD_MODNAME, 3050 - .driver.owner = THIS_MODULE, 3051 2994 .id_table = virtio_mem_id_table, 3052 2995 .probe = virtio_mem_probe, 3053 2996 .remove = virtio_mem_remove,
+2 -4
drivers/virtio/virtio_mmio.c
··· 696 696 return rc; 697 697 } 698 698 699 - static int virtio_mmio_remove(struct platform_device *pdev) 699 + static void virtio_mmio_remove(struct platform_device *pdev) 700 700 { 701 701 struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev); 702 702 unregister_virtio_device(&vm_dev->vdev); 703 - 704 - return 0; 705 703 } 706 704 707 705 ··· 845 847 846 848 static struct platform_driver virtio_mmio_driver = { 847 849 .probe = virtio_mmio_probe, 848 - .remove = virtio_mmio_remove, 850 + .remove_new = virtio_mmio_remove, 849 851 .driver = { 850 852 .name = "virtio-mmio", 851 853 .of_match_table = virtio_mmio_match,
+4 -2
drivers/virtio/virtio_pci_common.c
··· 236 236 int i; 237 237 238 238 list_for_each_entry_safe(vq, n, &vdev->vqs, list) { 239 - if (vp_dev->is_avq(vdev, vq->index)) 239 + if (vp_dev->is_avq && vp_dev->is_avq(vdev, vq->index)) 240 240 continue; 241 241 242 242 if (vp_dev->per_vq_vectors) { ··· 348 348 vring_interrupt, 0, 349 349 vp_dev->msix_names[msix_vec], 350 350 vqs[i]); 351 - if (err) 351 + if (err) { 352 + vp_del_vq(vqs[i]); 352 353 goto error_find; 354 + } 353 355 } 354 356 return 0; 355 357
+1 -3
fs/coredump.c
··· 376 376 if (t != current && !(t->flags & PF_POSTCOREDUMP)) { 377 377 sigaddset(&t->pending.signal, SIGKILL); 378 378 signal_wake_up(t, 1); 379 - /* The vhost_worker does not particpate in coredumps */ 380 - if ((t->flags & (PF_USER_WORKER | PF_IO_WORKER)) != PF_USER_WORKER) 381 - nr++; 379 + nr++; 382 380 } 383 381 } 384 382
-1
fs/fuse/virtio_fs.c
··· 1078 1078 1079 1079 static struct virtio_driver virtio_fs_driver = { 1080 1080 .driver.name = KBUILD_MODNAME, 1081 - .driver.owner = THIS_MODULE, 1082 1081 .id_table = id_table, 1083 1082 .feature_table = feature_table, 1084 1083 .feature_table_size = ARRAY_SIZE(feature_table),
+2 -1
include/linux/sched/vhost_task.h
··· 4 4 5 5 struct vhost_task; 6 6 7 - struct vhost_task *vhost_task_create(bool (*fn)(void *), void *arg, 7 + struct vhost_task *vhost_task_create(bool (*fn)(void *), 8 + void (*handle_kill)(void *), void *arg, 8 9 const char *name); 9 10 void vhost_task_start(struct vhost_task *vtsk); 10 11 void vhost_task_stop(struct vhost_task *vtsk);
+2
include/uapi/linux/virtio_mem.h
··· 90 90 #define VIRTIO_MEM_F_ACPI_PXM 0 91 91 /* unplugged memory must not be accessed */ 92 92 #define VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE 1 93 + /* plugged memory will remain plugged when suspending+resuming */ 94 + #define VIRTIO_MEM_F_PERSISTENT_SUSPEND 2 93 95 94 96 95 97 /* --- virtio-mem: guest -> host requests --- */
+1 -4
kernel/exit.c
··· 413 413 tsk->flags |= PF_POSTCOREDUMP; 414 414 core_state = tsk->signal->core_state; 415 415 spin_unlock_irq(&tsk->sighand->siglock); 416 - 417 - /* The vhost_worker does not particpate in coredumps */ 418 - if (core_state && 419 - ((tsk->flags & (PF_IO_WORKER | PF_USER_WORKER)) != PF_USER_WORKER)) { 416 + if (core_state) { 420 417 struct core_thread self; 421 418 422 419 self.task = current;
+1 -3
kernel/signal.c
··· 1375 1375 1376 1376 for_other_threads(p, t) { 1377 1377 task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK); 1378 - /* Don't require de_thread to wait for the vhost_worker */ 1379 - if ((t->flags & (PF_IO_WORKER | PF_USER_WORKER)) != PF_USER_WORKER) 1380 - count++; 1378 + count++; 1381 1379 1382 1380 /* Don't bother with already dead threads */ 1383 1381 if (t->exit_state)
+34 -19
kernel/vhost_task.c
··· 10 10 11 11 enum vhost_task_flags { 12 12 VHOST_TASK_FLAGS_STOP, 13 + VHOST_TASK_FLAGS_KILLED, 13 14 }; 14 15 15 16 struct vhost_task { 16 17 bool (*fn)(void *data); 18 + void (*handle_sigkill)(void *data); 17 19 void *data; 18 20 struct completion exited; 19 21 unsigned long flags; 20 22 struct task_struct *task; 23 + /* serialize SIGKILL and vhost_task_stop calls */ 24 + struct mutex exit_mutex; 21 25 }; 22 26 23 27 static int vhost_task_fn(void *data) 24 28 { 25 29 struct vhost_task *vtsk = data; 26 - bool dead = false; 27 30 28 31 for (;;) { 29 32 bool did_work; 30 33 31 - if (!dead && signal_pending(current)) { 34 + if (signal_pending(current)) { 32 35 struct ksignal ksig; 33 - /* 34 - * Calling get_signal will block in SIGSTOP, 35 - * or clear fatal_signal_pending, but remember 36 - * what was set. 37 - * 38 - * This thread won't actually exit until all 39 - * of the file descriptors are closed, and 40 - * the release function is called. 41 - */ 42 - dead = get_signal(&ksig); 43 - if (dead) 44 - clear_thread_flag(TIF_SIGPENDING); 36 + 37 + if (get_signal(&ksig)) 38 + break; 45 39 } 46 40 47 41 /* mb paired w/ vhost_task_stop */ ··· 51 57 schedule(); 52 58 } 53 59 60 + mutex_lock(&vtsk->exit_mutex); 61 + /* 62 + * If a vhost_task_stop and SIGKILL race, we can ignore the SIGKILL. 63 + * When the vhost layer has called vhost_task_stop it's already stopped 64 + * new work and flushed. 65 + */ 66 + if (!test_bit(VHOST_TASK_FLAGS_STOP, &vtsk->flags)) { 67 + set_bit(VHOST_TASK_FLAGS_KILLED, &vtsk->flags); 68 + vtsk->handle_sigkill(vtsk->data); 69 + } 70 + mutex_unlock(&vtsk->exit_mutex); 54 71 complete(&vtsk->exited); 72 + 55 73 do_exit(0); 56 74 } 57 75 ··· 84 78 * @vtsk: vhost_task to stop 85 79 * 86 80 * vhost_task_fn ensures the worker thread exits after 87 - * VHOST_TASK_FLAGS_SOP becomes true. 81 + * VHOST_TASK_FLAGS_STOP becomes true. 88 82 */ 89 83 void vhost_task_stop(struct vhost_task *vtsk) 90 84 { 91 - set_bit(VHOST_TASK_FLAGS_STOP, &vtsk->flags); 92 - vhost_task_wake(vtsk); 85 + mutex_lock(&vtsk->exit_mutex); 86 + if (!test_bit(VHOST_TASK_FLAGS_KILLED, &vtsk->flags)) { 87 + set_bit(VHOST_TASK_FLAGS_STOP, &vtsk->flags); 88 + vhost_task_wake(vtsk); 89 + } 90 + mutex_unlock(&vtsk->exit_mutex); 91 + 93 92 /* 94 93 * Make sure vhost_task_fn is no longer accessing the vhost_task before 95 94 * freeing it below. ··· 107 96 /** 108 97 * vhost_task_create - create a copy of a task to be used by the kernel 109 98 * @fn: vhost worker function 110 - * @arg: data to be passed to fn 99 + * @handle_sigkill: vhost function to handle when we are killed 100 + * @arg: data to be passed to fn and handled_kill 111 101 * @name: the thread's name 112 102 * 113 103 * This returns a specialized task for use by the vhost layer or NULL on 114 104 * failure. The returned task is inactive, and the caller must fire it up 115 105 * through vhost_task_start(). 116 106 */ 117 - struct vhost_task *vhost_task_create(bool (*fn)(void *), void *arg, 107 + struct vhost_task *vhost_task_create(bool (*fn)(void *), 108 + void (*handle_sigkill)(void *), void *arg, 118 109 const char *name) 119 110 { 120 111 struct kernel_clone_args args = { ··· 135 122 if (!vtsk) 136 123 return NULL; 137 124 init_completion(&vtsk->exited); 125 + mutex_init(&vtsk->exit_mutex); 138 126 vtsk->data = arg; 139 127 vtsk->fn = fn; 128 + vtsk->handle_sigkill = handle_sigkill; 140 129 141 130 args.fn_arg = vtsk; 142 131
-1
net/9p/trans_virtio.c
··· 781 781 .feature_table = features, 782 782 .feature_table_size = ARRAY_SIZE(features), 783 783 .driver.name = KBUILD_MODNAME, 784 - .driver.owner = THIS_MODULE, 785 784 .id_table = id_table, 786 785 .probe = p9_virtio_probe, 787 786 .remove = p9_virtio_remove,
-1
net/vmw_vsock/virtio_transport.c
··· 859 859 .feature_table = features, 860 860 .feature_table_size = ARRAY_SIZE(features), 861 861 .driver.name = KBUILD_MODNAME, 862 - .driver.owner = THIS_MODULE, 863 862 .id_table = id_table, 864 863 .probe = virtio_vsock_probe, 865 864 .remove = virtio_vsock_remove,
-1
sound/virtio/virtio_card.c
··· 438 438 439 439 static struct virtio_driver virtsnd_driver = { 440 440 .driver.name = KBUILD_MODNAME, 441 - .driver.owner = THIS_MODULE, 442 441 .id_table = id_table, 443 442 .feature_table = features, 444 443 .feature_table_size = ARRAY_SIZE(features),