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

Merge tag 'vfio-v5.11-rc1' of git://github.com/awilliam/linux-vfio

Pull VFIO updates from Alex Williamson:

- Fix uninitialized list walk in error path (Eric Auger)

- Use io_remap_pfn_range() (Jason Gunthorpe)

- Allow fallback support for NVLink on POWER8 (Alexey Kardashevskiy)

- Enable mdev request interrupt with CCW support (Eric Farman)

- Enable interface to iommu_domain from vfio_group (Lu Baolu)

* tag 'vfio-v5.11-rc1' of git://github.com/awilliam/linux-vfio:
vfio/type1: Add vfio_group_iommu_domain()
vfio-ccw: Wire in the request callback
vfio-mdev: Wire in a request handler for mdev parent
vfio/pci/nvlink2: Do not attempt NPU2 setup on POWER8NVL NPU
vfio-pci: Use io_remap_pfn_range() for PCI IO memory
vfio/pci: Move dummy_resources_list init in vfio_pci_probe()

+106 -6
+26
drivers/s390/cio/vfio_ccw_ops.c
··· 394 394 switch (info->index) { 395 395 case VFIO_CCW_IO_IRQ_INDEX: 396 396 case VFIO_CCW_CRW_IRQ_INDEX: 397 + case VFIO_CCW_REQ_IRQ_INDEX: 397 398 info->count = 1; 398 399 info->flags = VFIO_IRQ_INFO_EVENTFD; 399 400 break; ··· 424 423 break; 425 424 case VFIO_CCW_CRW_IRQ_INDEX: 426 425 ctx = &private->crw_trigger; 426 + break; 427 + case VFIO_CCW_REQ_IRQ_INDEX: 428 + ctx = &private->req_trigger; 427 429 break; 428 430 default: 429 431 return -EINVAL; ··· 611 607 } 612 608 } 613 609 610 + /* Request removal of the device*/ 611 + static void vfio_ccw_mdev_request(struct mdev_device *mdev, unsigned int count) 612 + { 613 + struct vfio_ccw_private *private = dev_get_drvdata(mdev_parent_dev(mdev)); 614 + 615 + if (!private) 616 + return; 617 + 618 + if (private->req_trigger) { 619 + if (!(count % 10)) 620 + dev_notice_ratelimited(mdev_dev(private->mdev), 621 + "Relaying device request to user (#%u)\n", 622 + count); 623 + 624 + eventfd_signal(private->req_trigger, 1); 625 + } else if (count == 0) { 626 + dev_notice(mdev_dev(private->mdev), 627 + "No device request channel registered, blocked until released by user\n"); 628 + } 629 + } 630 + 614 631 static const struct mdev_parent_ops vfio_ccw_mdev_ops = { 615 632 .owner = THIS_MODULE, 616 633 .supported_type_groups = mdev_type_groups, ··· 642 617 .read = vfio_ccw_mdev_read, 643 618 .write = vfio_ccw_mdev_write, 644 619 .ioctl = vfio_ccw_mdev_ioctl, 620 + .request = vfio_ccw_mdev_request, 645 621 }; 646 622 647 623 int vfio_ccw_mdev_reg(struct subchannel *sch)
+4
drivers/s390/cio/vfio_ccw_private.h
··· 84 84 * @irb: irb info received from interrupt 85 85 * @scsw: scsw info 86 86 * @io_trigger: eventfd ctx for signaling userspace I/O results 87 + * @crw_trigger: eventfd ctx for signaling userspace CRW information 88 + * @req_trigger: eventfd ctx for signaling userspace to return device 87 89 * @io_work: work for deferral process of I/O handling 90 + * @crw_work: work for deferral process of CRW handling 88 91 */ 89 92 struct vfio_ccw_private { 90 93 struct subchannel *sch; ··· 111 108 112 109 struct eventfd_ctx *io_trigger; 113 110 struct eventfd_ctx *crw_trigger; 111 + struct eventfd_ctx *req_trigger; 114 112 struct work_struct io_work; 115 113 struct work_struct crw_work; 116 114 } __aligned(8);
+4
drivers/vfio/mdev/mdev_core.c
··· 154 154 if (!dev) 155 155 return -EINVAL; 156 156 157 + /* Not mandatory, but its absence could be a problem */ 158 + if (!ops->request) 159 + dev_info(dev, "Driver cannot be asked to release device\n"); 160 + 157 161 mutex_lock(&parent_list_lock); 158 162 159 163 /* Check for duplicate */
+13
drivers/vfio/mdev/vfio_mdev.c
··· 98 98 return parent->ops->mmap(mdev, vma); 99 99 } 100 100 101 + static void vfio_mdev_request(void *device_data, unsigned int count) 102 + { 103 + struct mdev_device *mdev = device_data; 104 + struct mdev_parent *parent = mdev->parent; 105 + 106 + if (parent->ops->request) 107 + parent->ops->request(mdev, count); 108 + else if (count == 0) 109 + dev_notice(mdev_dev(mdev), 110 + "No mdev vendor driver request callback support, blocked until released by user\n"); 111 + } 112 + 101 113 static const struct vfio_device_ops vfio_mdev_dev_ops = { 102 114 .name = "vfio-mdev", 103 115 .open = vfio_mdev_open, ··· 118 106 .read = vfio_mdev_read, 119 107 .write = vfio_mdev_write, 120 108 .mmap = vfio_mdev_mmap, 109 + .request = vfio_mdev_request, 121 110 }; 122 111 123 112 static int vfio_mdev_probe(struct device *dev)
+3 -4
drivers/vfio/pci/vfio_pci.c
··· 161 161 int i; 162 162 struct vfio_pci_dummy_resource *dummy_res; 163 163 164 - INIT_LIST_HEAD(&vdev->dummy_resources_list); 165 - 166 164 for (i = 0; i < PCI_STD_NUM_BARS; i++) { 167 165 int bar = i + PCI_STD_RESOURCES; 168 166 ··· 1633 1635 1634 1636 mutex_unlock(&vdev->vma_lock); 1635 1637 1636 - if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, 1637 - vma->vm_end - vma->vm_start, vma->vm_page_prot)) 1638 + if (io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, 1639 + vma->vm_end - vma->vm_start, vma->vm_page_prot)) 1638 1640 ret = VM_FAULT_SIGBUS; 1639 1641 1640 1642 up_out: ··· 1964 1966 mutex_init(&vdev->igate); 1965 1967 spin_lock_init(&vdev->irqlock); 1966 1968 mutex_init(&vdev->ioeventfds_lock); 1969 + INIT_LIST_HEAD(&vdev->dummy_resources_list); 1967 1970 INIT_LIST_HEAD(&vdev->ioeventfds_list); 1968 1971 mutex_init(&vdev->vma_lock); 1969 1972 INIT_LIST_HEAD(&vdev->vma_list);
+5 -2
drivers/vfio/pci/vfio_pci_nvlink2.c
··· 231 231 return -EINVAL; 232 232 233 233 if (of_property_read_u32(npu_node, "memory-region", &mem_phandle)) 234 - return -EINVAL; 234 + return -ENODEV; 235 235 236 236 mem_node = of_find_node_by_phandle(mem_phandle); 237 237 if (!mem_node) ··· 393 393 int ret; 394 394 struct vfio_pci_npu2_data *data; 395 395 struct device_node *nvlink_dn; 396 - u32 nvlink_index = 0; 396 + u32 nvlink_index = 0, mem_phandle = 0; 397 397 struct pci_dev *npdev = vdev->pdev; 398 398 struct device_node *npu_node = pci_device_to_OF_node(npdev); 399 399 struct pci_controller *hose = pci_bus_to_host(npdev->bus); ··· 406 406 * platform does, use this. 407 407 */ 408 408 if (!pnv_pci_get_gpu_dev(vdev->pdev)) 409 + return -ENODEV; 410 + 411 + if (of_property_read_u32(npu_node, "memory-region", &mem_phandle)) 409 412 return -ENODEV; 410 413 411 414 /*
+18
drivers/vfio/vfio.c
··· 2331 2331 } 2332 2332 EXPORT_SYMBOL(vfio_unregister_notifier); 2333 2333 2334 + struct iommu_domain *vfio_group_iommu_domain(struct vfio_group *group) 2335 + { 2336 + struct vfio_container *container; 2337 + struct vfio_iommu_driver *driver; 2338 + 2339 + if (!group) 2340 + return ERR_PTR(-EINVAL); 2341 + 2342 + container = group->container; 2343 + driver = container->iommu_driver; 2344 + if (likely(driver && driver->ops->group_iommu_domain)) 2345 + return driver->ops->group_iommu_domain(container->iommu_data, 2346 + group->iommu_group); 2347 + 2348 + return ERR_PTR(-ENOTTY); 2349 + } 2350 + EXPORT_SYMBOL_GPL(vfio_group_iommu_domain); 2351 + 2334 2352 /** 2335 2353 * Module/class support 2336 2354 */
+24
drivers/vfio/vfio_iommu_type1.c
··· 2980 2980 return ret; 2981 2981 } 2982 2982 2983 + static struct iommu_domain * 2984 + vfio_iommu_type1_group_iommu_domain(void *iommu_data, 2985 + struct iommu_group *iommu_group) 2986 + { 2987 + struct iommu_domain *domain = ERR_PTR(-ENODEV); 2988 + struct vfio_iommu *iommu = iommu_data; 2989 + struct vfio_domain *d; 2990 + 2991 + if (!iommu || !iommu_group) 2992 + return ERR_PTR(-EINVAL); 2993 + 2994 + mutex_lock(&iommu->lock); 2995 + list_for_each_entry(d, &iommu->domain_list, next) { 2996 + if (find_iommu_group(d, iommu_group)) { 2997 + domain = d->domain; 2998 + break; 2999 + } 3000 + } 3001 + mutex_unlock(&iommu->lock); 3002 + 3003 + return domain; 3004 + } 3005 + 2983 3006 static const struct vfio_iommu_driver_ops vfio_iommu_driver_ops_type1 = { 2984 3007 .name = "vfio-iommu-type1", 2985 3008 .owner = THIS_MODULE, ··· 3016 2993 .register_notifier = vfio_iommu_type1_register_notifier, 3017 2994 .unregister_notifier = vfio_iommu_type1_unregister_notifier, 3018 2995 .dma_rw = vfio_iommu_type1_dma_rw, 2996 + .group_iommu_domain = vfio_iommu_type1_group_iommu_domain, 3019 2997 }; 3020 2998 3021 2999 static int __init vfio_iommu_type1_init(void)
+4
include/linux/mdev.h
··· 72 72 * @mmap: mmap callback 73 73 * @mdev: mediated device structure 74 74 * @vma: vma structure 75 + * @request: request callback to release device 76 + * @mdev: mediated device structure 77 + * @count: request sequence number 75 78 * Parent device that support mediated device should be registered with mdev 76 79 * module with mdev_parent_ops structure. 77 80 **/ ··· 95 92 long (*ioctl)(struct mdev_device *mdev, unsigned int cmd, 96 93 unsigned long arg); 97 94 int (*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma); 95 + void (*request)(struct mdev_device *mdev, unsigned int count); 98 96 }; 99 97 100 98 /* interface for exporting mdev supported type attributes */
+4
include/linux/vfio.h
··· 90 90 struct notifier_block *nb); 91 91 int (*dma_rw)(void *iommu_data, dma_addr_t user_iova, 92 92 void *data, size_t count, bool write); 93 + struct iommu_domain *(*group_iommu_domain)(void *iommu_data, 94 + struct iommu_group *group); 93 95 }; 94 96 95 97 extern int vfio_register_iommu_driver(const struct vfio_iommu_driver_ops *ops); ··· 127 125 128 126 extern int vfio_dma_rw(struct vfio_group *group, dma_addr_t user_iova, 129 127 void *data, size_t len, bool write); 128 + 129 + extern struct iommu_domain *vfio_group_iommu_domain(struct vfio_group *group); 130 130 131 131 /* each type has independent events */ 132 132 enum vfio_notify_type {
+1
include/uapi/linux/vfio.h
··· 820 820 enum { 821 821 VFIO_CCW_IO_IRQ_INDEX, 822 822 VFIO_CCW_CRW_IRQ_INDEX, 823 + VFIO_CCW_REQ_IRQ_INDEX, 823 824 VFIO_CCW_NUM_IRQS 824 825 }; 825 826