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

vfio/mdev: Correct the function signatures for the mdev_type_attributes

The driver core standard is to pass in the properly typed object, the
properly typed attribute and the buffer data. It stems from the root
kobject method:

ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,..)

Each subclass of kobject should provide their own function with the same
signature but more specific types, eg struct device uses:

ssize_t (*show)(struct device *dev, struct device_attribute *attr,..)

In this case the existing signature is:

ssize_t (*show)(struct kobject *kobj, struct device *dev,..)

Where kobj is a 'struct mdev_type *' and dev is 'mdev_type->parent->dev'.

Change the mdev_type related sysfs attribute functions to:

ssize_t (*show)(struct mdev_type *mtype, struct mdev_type_attribute *attr,..)

In order to restore type safety and match the driver core standard

There are no current users of 'attr', but if it is ever needed it would be
hard to add in retroactively, so do it now.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Message-Id: <18-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

Jason Gunthorpe and committed by
Alex Williamson
9169cff1 c2ef2f50

+90 -62
+11 -10
drivers/gpu/drm/i915/gvt/gvt.c
··· 54 54 return &gvt->types[type_group_id]; 55 55 } 56 56 57 - static ssize_t available_instances_show(struct kobject *kobj, 58 - 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) 59 60 { 60 61 struct intel_vgpu_type *type; 61 62 unsigned int num = 0; 62 - void *gvt = kdev_to_i915(dev)->gvt; 63 + void *gvt = kdev_to_i915(mtype_get_parent_dev(mtype))->gvt; 63 64 64 - type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(kobj)); 65 + type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(mtype)); 65 66 if (!type) 66 67 num = 0; 67 68 else ··· 71 70 return sprintf(buf, "%u\n", num); 72 71 } 73 72 74 - static ssize_t device_api_show(struct kobject *kobj, struct device *dev, 75 - char *buf) 73 + static ssize_t device_api_show(struct mdev_type *mtype, 74 + struct mdev_type_attribute *attr, char *buf) 76 75 { 77 76 return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); 78 77 } 79 78 80 - static ssize_t description_show(struct kobject *kobj, struct device *dev, 81 - char *buf) 79 + static ssize_t description_show(struct mdev_type *mtype, 80 + struct mdev_type_attribute *attr, char *buf) 82 81 { 83 82 struct intel_vgpu_type *type; 84 - void *gvt = kdev_to_i915(dev)->gvt; 83 + void *gvt = kdev_to_i915(mtype_get_parent_dev(mtype))->gvt; 85 84 86 - type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(kobj)); 85 + type = intel_gvt_find_vgpu_type(gvt, mtype_get_type_group_id(mtype)); 87 86 if (!type) 88 87 return 0; 89 88
+9 -6
drivers/s390/cio/vfio_ccw_ops.c
··· 71 71 return NOTIFY_DONE; 72 72 } 73 73 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) 75 76 { 76 77 return sprintf(buf, "I/O subchannel (Non-QDIO)\n"); 77 78 } 78 79 static MDEV_TYPE_ATTR_RO(name); 79 80 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) 82 83 { 83 84 return sprintf(buf, "%s\n", VFIO_DEVICE_API_CCW_STRING); 84 85 } 85 86 static MDEV_TYPE_ATTR_RO(device_api); 86 87 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) 89 91 { 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)); 91 94 92 95 return sprintf(buf, "%d\n", atomic_read(&private->avail)); 93 96 }
+7 -5
drivers/s390/crypto/vfio_ap_ops.c
··· 366 366 return 0; 367 367 } 368 368 369 - static ssize_t name_show(struct kobject *kobj, struct device *dev, char *buf) 369 + static ssize_t name_show(struct mdev_type *mtype, 370 + struct mdev_type_attribute *attr, char *buf) 370 371 { 371 372 return sprintf(buf, "%s\n", VFIO_AP_MDEV_NAME_HWVIRT); 372 373 } 373 374 374 375 static MDEV_TYPE_ATTR_RO(name); 375 376 376 - static ssize_t available_instances_show(struct kobject *kobj, 377 - struct device *dev, char *buf) 377 + static ssize_t available_instances_show(struct mdev_type *mtype, 378 + struct mdev_type_attribute *attr, 379 + char *buf) 378 380 { 379 381 return sprintf(buf, "%d\n", 380 382 atomic_read(&matrix_dev->available_instances)); ··· 384 382 385 383 static MDEV_TYPE_ATTR_RO(available_instances); 386 384 387 - static ssize_t device_api_show(struct kobject *kobj, struct device *dev, 388 - char *buf) 385 + static ssize_t device_api_show(struct mdev_type *mtype, 386 + struct mdev_type_attribute *attr, char *buf) 389 387 { 390 388 return sprintf(buf, "%s\n", VFIO_DEVICE_API_AP_STRING); 391 389 }
+12 -2
drivers/vfio/mdev/mdev_core.c
··· 47 47 * Used in mdev_type_attribute sysfs functions to return the index in the 48 48 * supported_type_groups that the sysfs is called from. 49 49 */ 50 - unsigned int mtype_get_type_group_id(struct kobject *mtype_kobj) 50 + unsigned int mtype_get_type_group_id(struct mdev_type *mtype) 51 51 { 52 - return container_of(mtype_kobj, struct mdev_type, kobj)->type_group_id; 52 + return mtype->type_group_id; 53 53 } 54 54 EXPORT_SYMBOL(mtype_get_type_group_id); 55 + 56 + /* 57 + * Used in mdev_type_attribute sysfs functions to return the parent struct 58 + * device 59 + */ 60 + struct device *mtype_get_parent_dev(struct mdev_type *mtype) 61 + { 62 + return mtype->parent->dev; 63 + } 64 + EXPORT_SYMBOL(mtype_get_parent_dev); 55 65 56 66 /* Should be called holding parent_list_lock */ 57 67 static struct mdev_parent *__find_parent_device(struct device *dev)
+6 -5
drivers/vfio/mdev/mdev_sysfs.c
··· 26 26 ssize_t ret = -EIO; 27 27 28 28 if (attr->show) 29 - ret = attr->show(kobj, type->parent->dev, buf); 29 + ret = attr->show(type, attr, buf); 30 30 return ret; 31 31 } 32 32 ··· 39 39 ssize_t ret = -EIO; 40 40 41 41 if (attr->store) 42 - ret = attr->store(&type->kobj, type->parent->dev, buf, count); 42 + ret = attr->store(type, attr, buf, count); 43 43 return ret; 44 44 } 45 45 ··· 48 48 .store = mdev_type_attr_store, 49 49 }; 50 50 51 - static ssize_t create_store(struct kobject *kobj, struct device *dev, 52 - const char *buf, size_t count) 51 + static ssize_t create_store(struct mdev_type *mtype, 52 + struct mdev_type_attribute *attr, const char *buf, 53 + size_t count) 53 54 { 54 55 char *str; 55 56 guid_t uuid; ··· 68 67 if (ret) 69 68 return ret; 70 69 71 - ret = mdev_device_create(to_mdev_type(kobj), &uuid); 70 + ret = mdev_device_create(mtype, &uuid); 72 71 if (ret) 73 72 return ret; 74 73
+7 -4
include/linux/mdev.h
··· 47 47 } 48 48 49 49 unsigned int mdev_get_type_group_id(struct mdev_device *mdev); 50 - unsigned int mtype_get_type_group_id(struct kobject *mtype_kobj); 50 + unsigned int mtype_get_type_group_id(struct mdev_type *mtype); 51 + struct device *mtype_get_parent_dev(struct mdev_type *mtype); 51 52 52 53 /** 53 54 * struct mdev_parent_ops - Structure to be registered for each parent device to ··· 124 123 /* interface for exporting mdev supported type attributes */ 125 124 struct mdev_type_attribute { 126 125 struct attribute attr; 127 - ssize_t (*show)(struct kobject *kobj, struct device *dev, char *buf); 128 - ssize_t (*store)(struct kobject *kobj, struct device *dev, 129 - const char *buf, size_t count); 126 + ssize_t (*show)(struct mdev_type *mtype, 127 + struct mdev_type_attribute *attr, char *buf); 128 + ssize_t (*store)(struct mdev_type *mtype, 129 + struct mdev_type_attribute *attr, const char *buf, 130 + size_t count); 130 131 }; 131 132 132 133 #define MDEV_TYPE_ATTR(_name, _mode, _show, _store) \
+15 -11
samples/vfio-mdev/mbochs.c
··· 1330 1330 NULL, 1331 1331 }; 1332 1332 1333 - static ssize_t 1334 - name_show(struct kobject *kobj, struct device *dev, char *buf) 1333 + static ssize_t name_show(struct mdev_type *mtype, 1334 + struct mdev_type_attribute *attr, char *buf) 1335 1335 { 1336 - return sprintf(buf, "%s\n", kobj->name); 1336 + const struct mbochs_type *type = 1337 + &mbochs_types[mtype_get_type_group_id(mtype)]; 1338 + 1339 + return sprintf(buf, "%s\n", type->name); 1337 1340 } 1338 1341 static MDEV_TYPE_ATTR_RO(name); 1339 1342 1340 - static ssize_t 1341 - description_show(struct kobject *kobj, struct device *dev, char *buf) 1343 + static ssize_t description_show(struct mdev_type *mtype, 1344 + struct mdev_type_attribute *attr, char *buf) 1342 1345 { 1343 1346 const struct mbochs_type *type = 1344 - &mbochs_types[mtype_get_type_group_id(kobj)]; 1347 + &mbochs_types[mtype_get_type_group_id(mtype)]; 1345 1348 1346 1349 return sprintf(buf, "virtual display, %d MB video memory\n", 1347 1350 type ? type->mbytes : 0); 1348 1351 } 1349 1352 static MDEV_TYPE_ATTR_RO(description); 1350 1353 1351 - static ssize_t 1352 - available_instances_show(struct kobject *kobj, struct device *dev, char *buf) 1354 + static ssize_t available_instances_show(struct mdev_type *mtype, 1355 + struct mdev_type_attribute *attr, 1356 + char *buf) 1353 1357 { 1354 1358 const struct mbochs_type *type = 1355 - &mbochs_types[mtype_get_type_group_id(kobj)]; 1359 + &mbochs_types[mtype_get_type_group_id(mtype)]; 1356 1360 int count = (max_mbytes - mbochs_used_mbytes) / type->mbytes; 1357 1361 1358 1362 return sprintf(buf, "%d\n", count); 1359 1363 } 1360 1364 static MDEV_TYPE_ATTR_RO(available_instances); 1361 1365 1362 - static ssize_t device_api_show(struct kobject *kobj, struct device *dev, 1363 - char *buf) 1366 + static ssize_t device_api_show(struct mdev_type *mtype, 1367 + struct mdev_type_attribute *attr, char *buf) 1364 1368 { 1365 1369 return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); 1366 1370 }
+14 -10
samples/vfio-mdev/mdpy.c
··· 652 652 NULL, 653 653 }; 654 654 655 - static ssize_t 656 - name_show(struct kobject *kobj, struct device *dev, char *buf) 655 + static ssize_t name_show(struct mdev_type *mtype, 656 + struct mdev_type_attribute *attr, char *buf) 657 657 { 658 - return sprintf(buf, "%s\n", kobj->name); 658 + const struct mdpy_type *type = 659 + &mdpy_types[mtype_get_type_group_id(mtype)]; 660 + 661 + return sprintf(buf, "%s\n", type->name); 659 662 } 660 663 static MDEV_TYPE_ATTR_RO(name); 661 664 662 - static ssize_t 663 - description_show(struct kobject *kobj, struct device *dev, char *buf) 665 + static ssize_t description_show(struct mdev_type *mtype, 666 + struct mdev_type_attribute *attr, char *buf) 664 667 { 665 668 const struct mdpy_type *type = 666 - &mdpy_types[mtype_get_type_group_id(kobj)]; 669 + &mdpy_types[mtype_get_type_group_id(mtype)]; 667 670 668 671 return sprintf(buf, "virtual display, %dx%d framebuffer\n", 669 672 type ? type->width : 0, ··· 674 671 } 675 672 static MDEV_TYPE_ATTR_RO(description); 676 673 677 - static ssize_t 678 - available_instances_show(struct kobject *kobj, struct device *dev, char *buf) 674 + static ssize_t available_instances_show(struct mdev_type *mtype, 675 + struct mdev_type_attribute *attr, 676 + char *buf) 679 677 { 680 678 return sprintf(buf, "%d\n", max_devices - mdpy_count); 681 679 } 682 680 static MDEV_TYPE_ATTR_RO(available_instances); 683 681 684 - static ssize_t device_api_show(struct kobject *kobj, struct device *dev, 685 - char *buf) 682 + static ssize_t device_api_show(struct mdev_type *mtype, 683 + struct mdev_type_attribute *attr, char *buf) 686 684 { 687 685 return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); 688 686 }
+9 -9
samples/vfio-mdev/mtty.c
··· 1292 1292 NULL, 1293 1293 }; 1294 1294 1295 - static ssize_t 1296 - name_show(struct kobject *kobj, struct device *dev, char *buf) 1295 + static ssize_t name_show(struct mdev_type *mtype, 1296 + struct mdev_type_attribute *attr, char *buf) 1297 1297 { 1298 1298 static const char *name_str[2] = { "Single port serial", 1299 1299 "Dual port serial" }; 1300 1300 1301 1301 return sysfs_emit(buf, "%s\n", 1302 - name_str[mtype_get_type_group_id(kobj)]); 1302 + name_str[mtype_get_type_group_id(mtype)]); 1303 1303 } 1304 1304 1305 1305 static MDEV_TYPE_ATTR_RO(name); 1306 1306 1307 - static ssize_t 1308 - available_instances_show(struct kobject *kobj, struct device *dev, char *buf) 1307 + static ssize_t available_instances_show(struct mdev_type *mtype, 1308 + struct mdev_type_attribute *attr, 1309 + char *buf) 1309 1310 { 1310 1311 struct mdev_state *mds; 1311 - unsigned int ports = mtype_get_type_group_id(kobj) + 1; 1312 + unsigned int ports = mtype_get_type_group_id(mtype) + 1; 1312 1313 int used = 0; 1313 1314 1314 1315 list_for_each_entry(mds, &mdev_devices_list, next) ··· 1320 1319 1321 1320 static MDEV_TYPE_ATTR_RO(available_instances); 1322 1321 1323 - 1324 - static ssize_t device_api_show(struct kobject *kobj, struct device *dev, 1325 - char *buf) 1322 + static ssize_t device_api_show(struct mdev_type *mtype, 1323 + struct mdev_type_attribute *attr, char *buf) 1326 1324 { 1327 1325 return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); 1328 1326 }