Skip to content

Commit 238da4d

Browse files
committed
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 ...
2 parents 35655ce + adaeb71 commit 238da4d

35 files changed

+793
-1361
lines changed

Documentation/driver-api/vfio-mediated-device.rst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,13 @@ structure to represent a mediated device's driver::
9898

9999
/*
100100
* struct mdev_driver [2] - Mediated device's driver
101-
* @name: driver name
102101
* @probe: called when new device created
103102
* @remove: called when device removed
104103
* @driver: device driver structure
105104
*/
106105
struct mdev_driver {
107-
const char *name;
108-
int (*probe) (struct device *dev);
109-
void (*remove) (struct device *dev);
106+
int (*probe) (struct mdev_device *dev);
107+
void (*remove) (struct mdev_device *dev);
110108
struct device_driver driver;
111109
};
112110

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

116114
* Register::
117115

118-
extern int mdev_register_driver(struct mdev_driver *drv,
119-
struct module *owner);
116+
extern int mdev_register_driver(struct mdev_driver *drv);
120117

121118
* Unregister::
122119

Documentation/driver-api/vfio.rst

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -249,35 +249,41 @@ VFIO bus driver API
249249

250250
VFIO bus drivers, such as vfio-pci make use of only a few interfaces
251251
into VFIO core. When devices are bound and unbound to the driver,
252-
the driver should call vfio_add_group_dev() and vfio_del_group_dev()
253-
respectively::
254-
255-
extern int vfio_add_group_dev(struct device *dev,
256-
const struct vfio_device_ops *ops,
257-
void *device_data);
258-
259-
extern void *vfio_del_group_dev(struct device *dev);
260-
261-
vfio_add_group_dev() indicates to the core to begin tracking the
262-
iommu_group of the specified dev and register the dev as owned by
263-
a VFIO bus driver. The driver provides an ops structure for callbacks
252+
the driver should call vfio_register_group_dev() and
253+
vfio_unregister_group_dev() respectively::
254+
255+
void vfio_init_group_dev(struct vfio_device *device,
256+
struct device *dev,
257+
const struct vfio_device_ops *ops);
258+
int vfio_register_group_dev(struct vfio_device *device);
259+
void vfio_unregister_group_dev(struct vfio_device *device);
260+
261+
The driver should embed the vfio_device in its own structure and call
262+
vfio_init_group_dev() to pre-configure it before going to registration.
263+
vfio_register_group_dev() indicates to the core to begin tracking the
264+
iommu_group of the specified dev and register the dev as owned by a VFIO bus
265+
driver. Once vfio_register_group_dev() returns it is possible for userspace to
266+
start accessing the driver, thus the driver should ensure it is completely
267+
ready before calling it. The driver provides an ops structure for callbacks
264268
similar to a file operations structure::
265269

266270
struct vfio_device_ops {
267-
int (*open)(void *device_data);
268-
void (*release)(void *device_data);
269-
ssize_t (*read)(void *device_data, char __user *buf,
271+
int (*open)(struct vfio_device *vdev);
272+
void (*release)(struct vfio_device *vdev);
273+
ssize_t (*read)(struct vfio_device *vdev, char __user *buf,
270274
size_t count, loff_t *ppos);
271-
ssize_t (*write)(void *device_data, const char __user *buf,
275+
ssize_t (*write)(struct vfio_device *vdev,
276+
const char __user *buf,
272277
size_t size, loff_t *ppos);
273-
long (*ioctl)(void *device_data, unsigned int cmd,
278+
long (*ioctl)(struct vfio_device *vdev, unsigned int cmd,
274279
unsigned long arg);
275-
int (*mmap)(void *device_data, struct vm_area_struct *vma);
280+
int (*mmap)(struct vfio_device *vdev,
281+
struct vm_area_struct *vma);
276282
};
277283

278-
Each function is passed the device_data that was originally registered
279-
in the vfio_add_group_dev() call above. This allows the bus driver
280-
an easy place to store its opaque, private data. The open/release
284+
Each function is passed the vdev that was originally registered
285+
in the vfio_register_group_dev() call above. This allows the bus driver
286+
to obtain its private data using container_of(). The open/release
281287
callbacks are issued when a new file descriptor is created for a
282288
device (via VFIO_GROUP_GET_DEVICE_FD). The ioctl interface provides
283289
a direct pass through for VFIO_DEVICE_* ioctls. The read/write/mmap

drivers/gpu/drm/i915/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ config DRM_I915_GVT
101101
bool "Enable Intel GVT-g graphics virtualization host support"
102102
depends on DRM_I915
103103
depends on 64BIT
104+
depends on VFIO_MDEV=y || VFIO_MDEV=DRM_I915
104105
default n
105106
help
106107
Choose this option if you want to enable Intel GVT-g graphics

drivers/gpu/drm/i915/gvt/gvt.c

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,23 @@ static const char * const supported_hypervisors[] = {
4646
[INTEL_GVT_HYPERVISOR_KVM] = "KVM",
4747
};
4848

49-
static struct intel_vgpu_type *intel_gvt_find_vgpu_type(struct intel_gvt *gvt,
50-
const char *name)
49+
static struct intel_vgpu_type *
50+
intel_gvt_find_vgpu_type(struct intel_gvt *gvt, unsigned int type_group_id)
5151
{
52-
const char *driver_name =
53-
dev_driver_string(gvt->gt->i915->drm.dev);
54-
int i;
55-
56-
name += strlen(driver_name) + 1;
57-
for (i = 0; i < gvt->num_types; i++) {
58-
struct intel_vgpu_type *t = &gvt->types[i];
59-
60-
if (!strncmp(t->name, name, sizeof(t->name)))
61-
return t;
62-
}
63-
64-
return NULL;
52+
if (WARN_ON(type_group_id >= gvt->num_types))
53+
return NULL;
54+
return &gvt->types[type_group_id];
6555
}
6656

67-
static ssize_t available_instances_show(struct kobject *kobj,
68-
struct device *dev, char *buf)
57+
static ssize_t available_instances_show(struct mdev_type *mtype,
58+
struct mdev_type_attribute *attr,
59+
char *buf)
6960
{
7061
struct intel_vgpu_type *type;
7162
unsigned int num = 0;
72-
void *gvt = kdev_to_i915(dev)->gvt;
63+
void *gvt = kdev_to_i915(mtype_get_parent_dev(mtype))->gvt;
7364

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

83-
static ssize_t device_api_show(struct kobject *kobj, struct device *dev,
84-
char *buf)
74+
static ssize_t device_api_show(struct mdev_type *mtype,
75+
struct mdev_type_attribute *attr, char *buf)
8576
{
8677
return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING);
8778
}
8879

89-
static ssize_t description_show(struct kobject *kobj, struct device *dev,
90-
char *buf)
80+
static ssize_t description_show(struct mdev_type *mtype,
81+
struct mdev_type_attribute *attr, char *buf)
9182
{
9283
struct intel_vgpu_type *type;
93-
void *gvt = kdev_to_i915(dev)->gvt;
84+
void *gvt = kdev_to_i915(mtype_get_parent_dev(mtype))->gvt;
9485

95-
type = intel_gvt_find_vgpu_type(gvt, kobject_name(kobj));
86+
type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(mtype));
9687
if (!type)
9788
return 0;
9889

drivers/gpu/drm/i915/gvt/gvt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,8 @@ struct intel_gvt_ops {
574574
void (*vgpu_reset)(struct intel_vgpu *);
575575
void (*vgpu_activate)(struct intel_vgpu *);
576576
void (*vgpu_deactivate)(struct intel_vgpu *);
577-
struct intel_vgpu_type *(*gvt_find_vgpu_type)(struct intel_gvt *gvt,
578-
const char *name);
577+
struct intel_vgpu_type *(*gvt_find_vgpu_type)(
578+
struct intel_gvt *gvt, unsigned int type_group_id);
579579
bool (*get_gvt_attrs)(struct attribute_group ***intel_vgpu_type_groups);
580580
int (*vgpu_query_plane)(struct intel_vgpu *vgpu, void *);
581581
int (*vgpu_get_dmabuf)(struct intel_vgpu *vgpu, unsigned int);

drivers/gpu/drm/i915/gvt/kvmgt.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ static void kvmgt_put_vfio_device(void *vgpu)
689689
vfio_device_put(vdev->vfio_device);
690690
}
691691

692-
static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
692+
static int intel_vgpu_create(struct mdev_device *mdev)
693693
{
694694
struct intel_vgpu *vgpu = NULL;
695695
struct intel_vgpu_type *type;
@@ -700,10 +700,9 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
700700
pdev = mdev_parent_dev(mdev);
701701
gvt = kdev_to_i915(pdev)->gvt;
702702

703-
type = intel_gvt_ops->gvt_find_vgpu_type(gvt, kobject_name(kobj));
703+
type = intel_gvt_ops->gvt_find_vgpu_type(gvt,
704+
mdev_get_type_group_id(mdev));
704705
if (!type) {
705-
gvt_vgpu_err("failed to find type %s to create\n",
706-
kobject_name(kobj));
707706
ret = -EINVAL;
708707
goto out;
709708
}

drivers/s390/cio/vfio_ccw_ops.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,26 @@ static int vfio_ccw_mdev_notifier(struct notifier_block *nb,
7171
return NOTIFY_DONE;
7272
}
7373

74-
static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf)
74+
static ssize_t name_show(struct mdev_type *mtype,
75+
struct mdev_type_attribute *attr, char *buf)
7576
{
7677
return sprintf(buf, "I/O subchannel (Non-QDIO)\n");
7778
}
7879
static MDEV_TYPE_ATTR_RO(name);
7980

80-
static ssize_t device_api_show(struct kobject *kobj, struct device *dev,
81-
char *buf)
81+
static ssize_t device_api_show(struct mdev_type *mtype,
82+
struct mdev_type_attribute *attr, char *buf)
8283
{
8384
return sprintf(buf, "%s\n", VFIO_DEVICE_API_CCW_STRING);
8485
}
8586
static MDEV_TYPE_ATTR_RO(device_api);
8687

87-
static ssize_t available_instances_show(struct kobject *kobj,
88-
struct device *dev, char *buf)
88+
static ssize_t available_instances_show(struct mdev_type *mtype,
89+
struct mdev_type_attribute *attr,
90+
char *buf)
8991
{
90-
struct vfio_ccw_private *private = dev_get_drvdata(dev);
92+
struct vfio_ccw_private *private =
93+
dev_get_drvdata(mtype_get_parent_dev(mtype));
9194

9295
return sprintf(buf, "%d\n", atomic_read(&private->avail));
9396
}
@@ -110,7 +113,7 @@ static struct attribute_group *mdev_type_groups[] = {
110113
NULL,
111114
};
112115

113-
static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
116+
static int vfio_ccw_mdev_create(struct mdev_device *mdev)
114117
{
115118
struct vfio_ccw_private *private =
116119
dev_get_drvdata(mdev_parent_dev(mdev));

drivers/s390/crypto/vfio_ap_ops.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static void vfio_ap_matrix_init(struct ap_config_info *info,
335335
matrix->adm_max = info->apxa ? info->Nd : 15;
336336
}
337337

338-
static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
338+
static int vfio_ap_mdev_create(struct mdev_device *mdev)
339339
{
340340
struct ap_matrix_mdev *matrix_mdev;
341341

@@ -386,24 +386,26 @@ static int vfio_ap_mdev_remove(struct mdev_device *mdev)
386386
return 0;
387387
}
388388

389-
static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf)
389+
static ssize_t name_show(struct mdev_type *mtype,
390+
struct mdev_type_attribute *attr, char *buf)
390391
{
391392
return sprintf(buf, "%s\n", VFIO_AP_MDEV_NAME_HWVIRT);
392393
}
393394

394395
static MDEV_TYPE_ATTR_RO(name);
395396

396-
static ssize_t available_instances_show(struct kobject *kobj,
397-
struct device *dev, char *buf)
397+
static ssize_t available_instances_show(struct mdev_type *mtype,
398+
struct mdev_type_attribute *attr,
399+
char *buf)
398400
{
399401
return sprintf(buf, "%d\n",
400402
atomic_read(&matrix_dev->available_instances));
401403
}
402404

403405
static MDEV_TYPE_ATTR_RO(available_instances);
404406

405-
static ssize_t device_api_show(struct kobject *kobj, struct device *dev,
406-
char *buf)
407+
static ssize_t device_api_show(struct mdev_type *mtype,
408+
struct mdev_type_attribute *attr, char *buf)
407409
{
408410
return sprintf(buf, "%s\n", VFIO_DEVICE_API_AP_STRING);
409411
}

0 commit comments

Comments
 (0)