Commit 238da4d0 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

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

Pull VFIO updates from Alex Williamson:

 - Embed struct vfio_device into vfio driver structures (Jason
   Gunthorpe)

 - Make vfio_mdev type safe (Jason Gunthorpe)

 - Remove vfio-pci NVLink2 extensions for POWER9 (Christoph Hellwig)

 - Update vfio-pci IGD extensions for OpRegion 2.1+ (Fred Gao)

 - Various spelling/blank line fixes (Zhen Lei, Zhou Wang, Bhaskar
   Chowdhury)

 - Simplify unpin_pages error handling (Shenming Lu)

 - Fix i915 mdev Kconfig dependency (Arnd Bergmann)

 - Remove unused structure member (Keqian Zhu)

* tag 'vfio-v5.13-rc1' of git://github.com/awilliam/linux-vfio: (43 commits)
  vfio/gvt: fix DRM_I915_GVT dependency on VFIO_MDEV
  vfio/iommu_type1: Remove unused pinned_page_dirty_scope in vfio_iommu
  vfio/mdev: Correct the function signatures for the mdev_type_attributes
  vfio/mdev: Remove kobj from mdev_parent_ops->create()
  vfio/gvt: Use mdev_get_type_group_id()
  vfio/gvt: Make DRM_I915_GVT depend on VFIO_MDEV
  vfio/mbochs: Use mdev_get_type_group_id()
  vfio/mdpy: Use mdev_get_type_group_id()
  vfio/mtty: Use mdev_get_type_group_id()
  vfio/mdev: Add mdev/mtype_get_type_group_id()
  vfio/mdev: Remove duplicate storage of parent in mdev_device
  vfio/mdev: Add missing error handling to dev_set_name()
  vfio/mdev: Reorganize mdev_device_create()
  vfio/mdev: Add missing reference counting to mdev_type
  vfio/mdev: Expose mdev_get/put_parent to mdev_private.h
  vfio/mdev: Use struct mdev_type in struct mdev_device
  vfio/mdev: Simplify driver registration
  vfio/mdev: Add missing typesafety around mdev_device
  vfio/mdev: Do not allow a mdev_type to have a NULL parent pointer
  vfio/mdev: Fix missing static's on MDEV_TYPE_ATTR's
  ...
parents 35655ceb adaeb718
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -98,15 +98,13 @@ structure to represent a mediated device's driver::

     /*
      * struct mdev_driver [2] - Mediated device's driver
      * @name: driver name
      * @probe: called when new device created
      * @remove: called when device removed
      * @driver: device driver structure
      */
     struct mdev_driver {
	     const char *name;
	     int  (*probe)  (struct device *dev);
	     void (*remove) (struct device *dev);
	     int  (*probe)  (struct mdev_device *dev);
	     void (*remove) (struct mdev_device *dev);
	     struct device_driver    driver;
     };

@@ -115,8 +113,7 @@ to register and unregister itself with the core driver:

* Register::

    extern int  mdev_register_driver(struct mdev_driver *drv,
				   struct module *owner);
    extern int  mdev_register_driver(struct mdev_driver *drv);

* Unregister::

+27 −21
Original line number Diff line number Diff line
@@ -249,35 +249,41 @@ VFIO bus driver API

VFIO bus drivers, such as vfio-pci make use of only a few interfaces
into VFIO core.  When devices are bound and unbound to the driver,
the driver should call vfio_add_group_dev() and vfio_del_group_dev()
respectively::

	extern int vfio_add_group_dev(struct device *dev,
				      const struct vfio_device_ops *ops,
				      void *device_data);

	extern void *vfio_del_group_dev(struct device *dev);

vfio_add_group_dev() indicates to the core to begin tracking the
iommu_group of the specified dev and register the dev as owned by
a VFIO bus driver.  The driver provides an ops structure for callbacks
the driver should call vfio_register_group_dev() and
vfio_unregister_group_dev() respectively::

	void vfio_init_group_dev(struct vfio_device *device,
				struct device *dev,
				const struct vfio_device_ops *ops);
	int vfio_register_group_dev(struct vfio_device *device);
	void vfio_unregister_group_dev(struct vfio_device *device);

The driver should embed the vfio_device in its own structure and call
vfio_init_group_dev() to pre-configure it before going to registration.
vfio_register_group_dev() indicates to the core to begin tracking the
iommu_group of the specified dev and register the dev as owned by a VFIO bus
driver. Once vfio_register_group_dev() returns it is possible for userspace to
start accessing the driver, thus the driver should ensure it is completely
ready before calling it. The driver provides an ops structure for callbacks
similar to a file operations structure::

	struct vfio_device_ops {
		int	(*open)(void *device_data);
		void	(*release)(void *device_data);
		ssize_t	(*read)(void *device_data, char __user *buf,
		int	(*open)(struct vfio_device *vdev);
		void	(*release)(struct vfio_device *vdev);
		ssize_t	(*read)(struct vfio_device *vdev, char __user *buf,
				size_t count, loff_t *ppos);
		ssize_t	(*write)(void *device_data, const char __user *buf,
		ssize_t	(*write)(struct vfio_device *vdev,
				 const char __user *buf,
				 size_t size, loff_t *ppos);
		long	(*ioctl)(void *device_data, unsigned int cmd,
		long	(*ioctl)(struct vfio_device *vdev, unsigned int cmd,
				 unsigned long arg);
		int	(*mmap)(void *device_data, struct vm_area_struct *vma);
		int	(*mmap)(struct vfio_device *vdev,
				struct vm_area_struct *vma);
	};

Each function is passed the device_data that was originally registered
in the vfio_add_group_dev() call above.  This allows the bus driver
an easy place to store its opaque, private data.  The open/release
Each function is passed the vdev that was originally registered
in the vfio_register_group_dev() call above.  This allows the bus driver
to obtain its private data using container_of().  The open/release
callbacks are issued when a new file descriptor is created for a
device (via VFIO_GROUP_GET_DEVICE_FD).  The ioctl interface provides
a direct pass through for VFIO_DEVICE_* ioctls.  The read/write/mmap
+1 −0
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@ config DRM_I915_GVT
	bool "Enable Intel GVT-g graphics virtualization host support"
	depends on DRM_I915
	depends on 64BIT
	depends on VFIO_MDEV=y || VFIO_MDEV=DRM_I915
	default n
	help
	  Choose this option if you want to enable Intel GVT-g graphics
+16 −25
Original line number Diff line number Diff line
@@ -46,32 +46,23 @@ static const char * const supported_hypervisors[] = {
	[INTEL_GVT_HYPERVISOR_KVM] = "KVM",
};

static struct intel_vgpu_type *intel_gvt_find_vgpu_type(struct intel_gvt *gvt,
		const char *name)
static struct intel_vgpu_type *
intel_gvt_find_vgpu_type(struct intel_gvt *gvt, unsigned int type_group_id)
{
	const char *driver_name =
		dev_driver_string(gvt->gt->i915->drm.dev);
	int i;

	name += strlen(driver_name) + 1;
	for (i = 0; i < gvt->num_types; i++) {
		struct intel_vgpu_type *t = &gvt->types[i];

		if (!strncmp(t->name, name, sizeof(t->name)))
			return t;
	}

	if (WARN_ON(type_group_id >= gvt->num_types))
		return NULL;
	return &gvt->types[type_group_id];
}

static ssize_t available_instances_show(struct kobject *kobj,
					struct device *dev, char *buf)
static ssize_t available_instances_show(struct mdev_type *mtype,
					struct mdev_type_attribute *attr,
					char *buf)
{
	struct intel_vgpu_type *type;
	unsigned int num = 0;
	void *gvt = kdev_to_i915(dev)->gvt;
	void *gvt = kdev_to_i915(mtype_get_parent_dev(mtype))->gvt;

	type = intel_gvt_find_vgpu_type(gvt, kobject_name(kobj));
	type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(mtype));
	if (!type)
		num = 0;
	else
@@ -80,19 +71,19 @@ static ssize_t available_instances_show(struct kobject *kobj,
	return sprintf(buf, "%u\n", num);
}

static ssize_t device_api_show(struct kobject *kobj, struct device *dev,
		char *buf)
static ssize_t device_api_show(struct mdev_type *mtype,
			       struct mdev_type_attribute *attr, char *buf)
{
	return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING);
}

static ssize_t description_show(struct kobject *kobj, struct device *dev,
		char *buf)
static ssize_t description_show(struct mdev_type *mtype,
				struct mdev_type_attribute *attr, char *buf)
{
	struct intel_vgpu_type *type;
	void *gvt = kdev_to_i915(dev)->gvt;
	void *gvt = kdev_to_i915(mtype_get_parent_dev(mtype))->gvt;

	type = intel_gvt_find_vgpu_type(gvt, kobject_name(kobj));
	type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(mtype));
	if (!type)
		return 0;

+2 −2
Original line number Diff line number Diff line
@@ -574,8 +574,8 @@ struct intel_gvt_ops {
	void (*vgpu_reset)(struct intel_vgpu *);
	void (*vgpu_activate)(struct intel_vgpu *);
	void (*vgpu_deactivate)(struct intel_vgpu *);
	struct intel_vgpu_type *(*gvt_find_vgpu_type)(struct intel_gvt *gvt,
			const char *name);
	struct intel_vgpu_type *(*gvt_find_vgpu_type)(
		struct intel_gvt *gvt, unsigned int type_group_id);
	bool (*get_gvt_attrs)(struct attribute_group ***intel_vgpu_type_groups);
	int (*vgpu_query_plane)(struct intel_vgpu *vgpu, void *);
	int (*vgpu_get_dmabuf)(struct intel_vgpu *vgpu, unsigned int);
Loading