Merge tag 'vfio-v5.14-rc1' of git://github.com/awilliam/linux-vfio
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 3 Jul 2021 18:49:33 +0000 (11:49 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 3 Jul 2021 18:49:33 +0000 (11:49 -0700)
Pull VFIO updates from Alex Williamson:

 - Module reference fixes, structure renaming (Max Gurtovoy)

 - Export and use common pci_dev_trylock() (Luis Chamberlain)

 - Enable direct mdev device creation and probing by parent (Christoph
   Hellwig & Jason Gunthorpe)

 - Fix mdpy error path leak (Colin Ian King)

 - Fix mtty list entry leak (Jason Gunthorpe)

 - Enforce mtty device limit (Alex Williamson)

 - Resolve concurrent vfio-pci mmap faults (Alex Williamson)

* tag 'vfio-v5.14-rc1' of git://github.com/awilliam/linux-vfio:
  vfio/pci: Handle concurrent vma faults
  vfio/mtty: Enforce available_instances
  vfio/mtty: Delete mdev_devices_list
  vfio: use the new pci_dev_trylock() helper to simplify try lock
  PCI: Export pci_dev_trylock() and pci_dev_unlock()
  vfio/mdpy: Fix memory leak of object mdev_state->vconfig
  vfio/iommu_type1: rename vfio_group struck to vfio_iommu_group
  vfio/mbochs: Convert to use vfio_register_group_dev()
  vfio/mdpy: Convert to use vfio_register_group_dev()
  vfio/mtty: Convert to use vfio_register_group_dev()
  vfio/mdev: Allow the mdev_parent_ops to specify the device driver to bind
  vfio/mdev: Remove CONFIG_VFIO_MDEV_DEVICE
  driver core: Export device_driver_attach()
  driver core: Don't return EPROBE_DEFER to userspace during sysfs bind
  driver core: Flow the return code from ->probe() through to sysfs bind
  driver core: Better distinguish probe errors in really_probe
  driver core: Pull required checks into driver_probe_device()
  vfio/platform: remove unneeded parent_module attribute
  vfio: centralize module refcount in subsystem layer

1  2 
arch/s390/Kconfig
drivers/gpu/drm/i915/Kconfig
drivers/pci/pci.c
drivers/vfio/vfio_iommu_type1.c
include/linux/device.h
include/linux/pci.h

diff --combined arch/s390/Kconfig
@@@ -2,6 -2,9 +2,6 @@@
  config MMU
        def_bool y
  
 -config ZONE_DMA
 -      def_bool y
 -
  config CPU_BIG_ENDIAN
        def_bool y
  
@@@ -59,7 -62,7 +59,7 @@@ config S39
        select ARCH_BINFMT_ELF_STATE
        select ARCH_ENABLE_MEMORY_HOTPLUG if SPARSEMEM
        select ARCH_ENABLE_MEMORY_HOTREMOVE
 -      select ARCH_ENABLE_SPLIT_PMD_PTLOCK
 +      select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2
        select ARCH_HAS_DEBUG_VM_PGTABLE
        select ARCH_HAS_DEBUG_WX
        select ARCH_HAS_DEVMEM_IS_ALLOWED
        select ARCH_USE_BUILTIN_BSWAP
        select ARCH_USE_CMPXCHG_LOCKREF
        select ARCH_WANTS_DYNAMIC_TASK_STRUCT
 +      select ARCH_WANTS_NO_INSTR
        select ARCH_WANT_DEFAULT_BPF_JIT
        select ARCH_WANT_IPC_PARSE_VERSION
        select BUILDTIME_TABLE_SORT
        select THREAD_INFO_IN_TASK
        select TTY
        select VIRT_CPU_ACCOUNTING
 +      select ZONE_DMA
        # Note: keep the above list sorted alphabetically
  
  config SCHED_OMIT_FRAME_POINTER
@@@ -474,7 -475,7 +474,7 @@@ config NUM
  
  config NODES_SHIFT
        int
 -      depends on NEED_MULTIPLE_NODES
 +      depends on NUMA
        default "1"
  
  config SCHED_SMT
@@@ -767,7 -768,7 +767,7 @@@ config VFIO_CC
  config VFIO_AP
        def_tristate n
        prompt "VFIO support for AP devices"
-       depends on S390_AP_IOMMU && VFIO_MDEV_DEVICE && KVM
+       depends on S390_AP_IOMMU && VFIO_MDEV && KVM
        depends on ZCRYPT
        help
                This driver grants access to Adjunct Processor (AP) devices
@@@ -26,7 -26,6 +26,7 @@@ config DRM_I91
        select SND_HDA_I915 if SND_HDA_CORE
        select CEC_CORE if CEC_NOTIFIER
        select VMAP_PFN
 +      select DRM_TTM
        help
          Choose this option if you have a system that has "Intel Graphics
          Media Accelerator" or "HD Graphics" integrated graphics,
@@@ -125,7 -124,7 +125,7 @@@ config DRM_I915_GVT_KVMG
        tristate "Enable KVM/VFIO support for Intel GVT-g"
        depends on DRM_I915_GVT
        depends on KVM
-       depends on VFIO_MDEV && VFIO_MDEV_DEVICE
+       depends on VFIO_MDEV
        default n
        help
          Choose this option if you want to enable KVMGT support for
diff --combined drivers/pci/pci.c
@@@ -1900,21 -1900,11 +1900,21 @@@ static int pci_enable_device_flags(stru
        int err;
        int i, bars = 0;
  
 -      if (atomic_inc_return(&dev->enable_cnt) > 1) {
 -              pci_update_current_state(dev, dev->current_state);
 -              return 0;               /* already enabled */
 +      /*
 +       * Power state could be unknown at this point, either due to a fresh
 +       * boot or a device removal call.  So get the current power state
 +       * so that things like MSI message writing will behave as expected
 +       * (e.g. if the device really is in D0 at enable time).
 +       */
 +      if (dev->pm_cap) {
 +              u16 pmcsr;
 +              pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
 +              dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
        }
  
 +      if (atomic_inc_return(&dev->enable_cnt) > 1)
 +              return 0;               /* already enabled */
 +
        bridge = pci_upstream_bridge(dev);
        if (bridge)
                pci_enable_bridge(bridge);
@@@ -5038,7 -5028,7 +5038,7 @@@ static void pci_dev_lock(struct pci_de
  }
  
  /* Return 1 on successful lock, 0 on contention */
static int pci_dev_trylock(struct pci_dev *dev)
+ int pci_dev_trylock(struct pci_dev *dev)
  {
        if (pci_cfg_access_trylock(dev)) {
                if (device_trylock(&dev->dev))
  
        return 0;
  }
+ EXPORT_SYMBOL_GPL(pci_dev_trylock);
  
static void pci_dev_unlock(struct pci_dev *dev)
+ void pci_dev_unlock(struct pci_dev *dev)
  {
        device_unlock(&dev->dev);
        pci_cfg_access_unlock(dev);
  }
+ EXPORT_SYMBOL_GPL(pci_dev_unlock);
  
  static void pci_dev_save_and_disable(struct pci_dev *dev)
  {
@@@ -110,7 -110,7 +110,7 @@@ struct vfio_batch 
        int                     offset;         /* of next entry in pages */
  };
  
- struct vfio_group {
+ struct vfio_iommu_group {
        struct iommu_group      *iommu_group;
        struct list_head        next;
        bool                    mdev_group;     /* An mdev group */
@@@ -160,8 -160,9 +160,9 @@@ struct vfio_regions 
  
  static int put_pfn(unsigned long pfn, int prot);
  
- static struct vfio_group *vfio_iommu_find_iommu_group(struct vfio_iommu *iommu,
-                                              struct iommu_group *iommu_group);
+ static struct vfio_iommu_group*
+ vfio_iommu_find_iommu_group(struct vfio_iommu *iommu,
+                           struct iommu_group *iommu_group);
  
  /*
   * This code handles mapping and unmapping of user data buffers
@@@ -567,7 -568,7 +568,7 @@@ static int vaddr_get_pfns(struct mm_str
        vaddr = untagged_addr(vaddr);
  
  retry:
 -      vma = find_vma_intersection(mm, vaddr, vaddr + 1);
 +      vma = vma_lookup(mm, vaddr);
  
        if (vma && vma->vm_flags & VM_PFNMAP) {
                ret = follow_fault_pfn(vma, mm, vaddr, pfn, prot & IOMMU_WRITE);
@@@ -836,7 -837,7 +837,7 @@@ static int vfio_iommu_type1_pin_pages(v
                                      unsigned long *phys_pfn)
  {
        struct vfio_iommu *iommu = iommu_data;
-       struct vfio_group *group;
+       struct vfio_iommu_group *group;
        int i, j, ret;
        unsigned long remote_vaddr;
        struct vfio_dma *dma;
@@@ -1875,10 -1876,10 +1876,10 @@@ static void vfio_test_domain_fgsp(struc
        __free_pages(pages, order);
  }
  
- static struct vfio_group *find_iommu_group(struct vfio_domain *domain,
-                                          struct iommu_group *iommu_group)
+ static struct vfio_iommu_group *find_iommu_group(struct vfio_domain *domain,
+                                                struct iommu_group *iommu_group)
  {
-       struct vfio_group *g;
+       struct vfio_iommu_group *g;
  
        list_for_each_entry(g, &domain->group_list, next) {
                if (g->iommu_group == iommu_group)
        return NULL;
  }
  
- static struct vfio_group *vfio_iommu_find_iommu_group(struct vfio_iommu *iommu,
-                                              struct iommu_group *iommu_group)
+ static struct vfio_iommu_group*
+ vfio_iommu_find_iommu_group(struct vfio_iommu *iommu,
+                           struct iommu_group *iommu_group)
  {
        struct vfio_domain *domain;
-       struct vfio_group *group = NULL;
+       struct vfio_iommu_group *group = NULL;
  
        list_for_each_entry(domain, &iommu->domain_list, next) {
                group = find_iommu_group(domain, iommu_group);
@@@ -1967,7 -1969,7 +1969,7 @@@ static int vfio_mdev_detach_domain(stru
  }
  
  static int vfio_iommu_attach_group(struct vfio_domain *domain,
-                                  struct vfio_group *group)
+                                  struct vfio_iommu_group *group)
  {
        if (group->mdev_group)
                return iommu_group_for_each_dev(group->iommu_group,
  }
  
  static void vfio_iommu_detach_group(struct vfio_domain *domain,
-                                   struct vfio_group *group)
+                                   struct vfio_iommu_group *group)
  {
        if (group->mdev_group)
                iommu_group_for_each_dev(group->iommu_group, domain->domain,
@@@ -2242,7 -2244,7 +2244,7 @@@ static int vfio_iommu_type1_attach_grou
                                         struct iommu_group *iommu_group)
  {
        struct vfio_iommu *iommu = iommu_data;
-       struct vfio_group *group;
+       struct vfio_iommu_group *group;
        struct vfio_domain *domain, *d;
        struct bus_type *bus = NULL;
        int ret;
@@@ -2518,7 -2520,7 +2520,7 @@@ static int vfio_iommu_resv_refresh(stru
                                   struct list_head *iova_copy)
  {
        struct vfio_domain *d;
-       struct vfio_group *g;
+       struct vfio_iommu_group *g;
        struct vfio_iova *node;
        dma_addr_t start, end;
        LIST_HEAD(resv_regions);
@@@ -2560,7 -2562,7 +2562,7 @@@ static void vfio_iommu_type1_detach_gro
  {
        struct vfio_iommu *iommu = iommu_data;
        struct vfio_domain *domain;
-       struct vfio_group *group;
+       struct vfio_iommu_group *group;
        bool update_dirty_scope = false;
        LIST_HEAD(iova_copy);
  
@@@ -2681,7 -2683,7 +2683,7 @@@ static void *vfio_iommu_type1_open(unsi
  
  static void vfio_release_domain(struct vfio_domain *domain, bool external)
  {
-       struct vfio_group *group, *group_tmp;
+       struct vfio_iommu_group *group, *group_tmp;
  
        list_for_each_entry_safe(group, group_tmp,
                                 &domain->group_list, next) {
diff --combined include/linux/device.h
@@@ -399,7 -399,7 +399,7 @@@ struct dev_links_info 
   *            along with subsystem-level and driver-level callbacks.
   * @em_pd:    device's energy model performance domain
   * @pins:     For device pin management.
 - *            See Documentation/driver-api/pinctl.rst for details.
 + *            See Documentation/driver-api/pin-control.rst for details.
   * @msi_list: Hosts MSI descriptors
   * @msi_domain: The generic MSI domain this device is using.
   * @numa_node:        NUMA node this device is close to.
@@@ -817,7 -817,6 +817,7 @@@ int device_online(struct device *dev)
  void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
  void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
  void device_set_of_node_from_dev(struct device *dev, const struct device *dev2);
 +void device_set_node(struct device *dev, struct fwnode_handle *fwnode);
  
  static inline int dev_num_vf(struct device *dev)
  {
@@@ -846,6 -845,8 +846,8 @@@ static inline void *dev_get_platdata(co
   * Manual binding of a device to driver. See drivers/base/bus.c
   * for information on use.
   */
+ int __must_check device_driver_attach(struct device_driver *drv,
+                                     struct device *dev);
  int __must_check device_bind_driver(struct device *dev);
  void device_release_driver(struct device *dev);
  int  __must_check device_attach(struct device *dev);
diff --combined include/linux/pci.h
@@@ -862,8 -862,6 +862,8 @@@ struct module
   *              MSI-X vectors available for distribution to the VFs.
   * @err_handler: See Documentation/PCI/pci-error-recovery.rst
   * @groups:   Sysfs attribute groups.
 + * @dev_groups: Attributes attached to the device that will be
 + *              created once it is bound to the driver.
   * @driver:   Driver model structure.
   * @dynids:   List of dynamically added device IDs.
   */
@@@ -881,7 -879,6 +881,7 @@@ struct pci_driver 
        u32  (*sriov_get_vf_total_msix)(struct pci_dev *pf);
        const struct pci_error_handlers *err_handler;
        const struct attribute_group **groups;
 +      const struct attribute_group **dev_groups;
        struct device_driver    driver;
        struct pci_dynids       dynids;
  };
@@@ -1624,6 -1621,9 +1624,9 @@@ void pci_cfg_access_lock(struct pci_de
  bool pci_cfg_access_trylock(struct pci_dev *dev);
  void pci_cfg_access_unlock(struct pci_dev *dev);
  
+ int pci_dev_trylock(struct pci_dev *dev);
+ void pci_dev_unlock(struct pci_dev *dev);
  /*
   * PCI domain support.  Sometimes called PCI segment (eg by ACPI),
   * a PCI domain is defined to be a set of PCI buses which share
@@@ -1775,10 -1775,6 +1778,10 @@@ static inline int pci_request_regions(s
  { return -EIO; }
  static inline void pci_release_regions(struct pci_dev *dev) { }
  
 +static inline int pci_register_io_range(struct fwnode_handle *fwnode,
 +                                      phys_addr_t addr, resource_size_t size)
 +{ return -EINVAL; }
 +
  static inline unsigned long pci_address_to_pio(phys_addr_t addr) { return -1; }
  
  static inline struct pci_bus *pci_find_next_bus(const struct pci_bus *from)