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

Configure Feed

Select the types of activity you want to include in your feed.

vfio/mdev: consolidate all the device_api sysfs into the core code

Every driver just emits a static string, simply feed it through the ops
and provide a standard sysfs show function.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Tony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com>
Reviewed-by: Eric Farman <farman@linux.ibm.com>
Link: https://lore.kernel.org/r/20220923092652.100656-11-hch@lst.de
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

Jason Gunthorpe and committed by
Alex Williamson
290aac5d c7c1f38f

+37 -67
+1 -1
Documentation/driver-api/vfio-mediated-device.rst
··· 202 202 203 203 * device_api 204 204 205 - This attribute should show which device API is being created, for example, 205 + This attribute shows which device API is being created, for example, 206 206 "vfio-pci" for a PCI device. 207 207 208 208 * available_instances
+1 -8
drivers/gpu/drm/i915/gvt/kvmgt.c
··· 123 123 return sprintf(buf, "%u\n", type->avail_instance); 124 124 } 125 125 126 - static ssize_t device_api_show(struct mdev_type *mtype, 127 - struct mdev_type_attribute *attr, char *buf) 128 - { 129 - return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); 130 - } 131 - 132 126 static ssize_t description_show(struct mdev_type *mtype, 133 127 struct mdev_type_attribute *attr, char *buf) 134 128 { ··· 145 151 } 146 152 147 153 static MDEV_TYPE_ATTR_RO(available_instances); 148 - static MDEV_TYPE_ATTR_RO(device_api); 149 154 static MDEV_TYPE_ATTR_RO(description); 150 155 static MDEV_TYPE_ATTR_RO(name); 151 156 152 157 static const struct attribute *gvt_type_attrs[] = { 153 158 &mdev_type_attr_available_instances.attr, 154 - &mdev_type_attr_device_api.attr, 155 159 &mdev_type_attr_description.attr, 156 160 &mdev_type_attr_name.attr, 157 161 NULL, ··· 1542 1550 } 1543 1551 1544 1552 static struct mdev_driver intel_vgpu_mdev_driver = { 1553 + .device_api = VFIO_DEVICE_API_PCI_STRING, 1545 1554 .driver = { 1546 1555 .name = "intel_vgpu_mdev", 1547 1556 .owner = THIS_MODULE,
+1 -8
drivers/s390/cio/vfio_ccw_ops.c
··· 51 51 } 52 52 static MDEV_TYPE_ATTR_RO(name); 53 53 54 - static ssize_t device_api_show(struct mdev_type *mtype, 55 - struct mdev_type_attribute *attr, char *buf) 56 - { 57 - return sprintf(buf, "%s\n", VFIO_DEVICE_API_CCW_STRING); 58 - } 59 - static MDEV_TYPE_ATTR_RO(device_api); 60 - 61 54 static ssize_t available_instances_show(struct mdev_type *mtype, 62 55 struct mdev_type_attribute *attr, 63 56 char *buf) ··· 63 70 64 71 static const struct attribute *mdev_types_attrs[] = { 65 72 &mdev_type_attr_name.attr, 66 - &mdev_type_attr_device_api.attr, 67 73 &mdev_type_attr_available_instances.attr, 68 74 NULL, 69 75 }; ··· 620 628 }; 621 629 622 630 struct mdev_driver vfio_ccw_mdev_driver = { 631 + .device_api = VFIO_DEVICE_API_CCW_STRING, 623 632 .driver = { 624 633 .name = "vfio_ccw_mdev", 625 634 .owner = THIS_MODULE,
+1 -9
drivers/s390/crypto/vfio_ap_ops.c
··· 808 808 809 809 static MDEV_TYPE_ATTR_RO(available_instances); 810 810 811 - static ssize_t device_api_show(struct mdev_type *mtype, 812 - struct mdev_type_attribute *attr, char *buf) 813 - { 814 - return sprintf(buf, "%s\n", VFIO_DEVICE_API_AP_STRING); 815 - } 816 - 817 - static MDEV_TYPE_ATTR_RO(device_api); 818 - 819 811 static const struct attribute *vfio_ap_mdev_type_attrs[] = { 820 812 &mdev_type_attr_name.attr, 821 - &mdev_type_attr_device_api.attr, 822 813 &mdev_type_attr_available_instances.attr, 823 814 NULL, 824 815 }; ··· 1790 1799 }; 1791 1800 1792 1801 static struct mdev_driver vfio_ap_matrix_driver = { 1802 + .device_api = VFIO_DEVICE_API_AP_STRING, 1793 1803 .driver = { 1794 1804 .name = "vfio_ap_mdev", 1795 1805 .owner = THIS_MODULE,
+3 -1
drivers/vfio/mdev/mdev_driver.c
··· 55 55 **/ 56 56 int mdev_register_driver(struct mdev_driver *drv) 57 57 { 58 - if (!drv->types_attrs) 58 + if (!drv->types_attrs || !drv->device_api) 59 59 return -EINVAL; 60 + 61 + /* initialize common driver fields */ 60 62 drv->driver.bus = &mdev_bus_type; 61 63 return driver_register(&drv->driver); 62 64 }
+25 -10
drivers/vfio/mdev/mdev_sysfs.c
··· 72 72 73 73 return count; 74 74 } 75 - 76 75 static MDEV_TYPE_ATTR_WO(create); 76 + 77 + static ssize_t device_api_show(struct mdev_type *mtype, 78 + struct mdev_type_attribute *attr, char *buf) 79 + { 80 + return sysfs_emit(buf, "%s\n", mtype->parent->mdev_driver->device_api); 81 + } 82 + static MDEV_TYPE_ATTR_RO(device_api); 83 + 84 + static struct attribute *mdev_types_core_attrs[] = { 85 + &mdev_type_attr_create.attr, 86 + &mdev_type_attr_device_api.attr, 87 + NULL, 88 + }; 89 + 90 + static struct attribute_group mdev_type_core_group = { 91 + .attrs = mdev_types_core_attrs, 92 + }; 93 + 94 + static const struct attribute_group *mdev_type_groups[] = { 95 + &mdev_type_core_group, 96 + NULL, 97 + }; 77 98 78 99 static void mdev_type_release(struct kobject *kobj) 79 100 { ··· 106 85 } 107 86 108 87 static struct kobj_type mdev_type_ktype = { 109 - .sysfs_ops = &mdev_type_sysfs_ops, 110 - .release = mdev_type_release, 88 + .sysfs_ops = &mdev_type_sysfs_ops, 89 + .release = mdev_type_release, 90 + .default_groups = mdev_type_groups, 111 91 }; 112 92 113 93 static int mdev_type_add(struct mdev_parent *parent, struct mdev_type *type) ··· 128 106 return ret; 129 107 } 130 108 131 - ret = sysfs_create_file(&type->kobj, &mdev_type_attr_create.attr); 132 - if (ret) 133 - goto attr_create_failed; 134 - 135 109 type->devices_kobj = kobject_create_and_add("devices", &type->kobj); 136 110 if (!type->devices_kobj) { 137 111 ret = -ENOMEM; ··· 142 124 attrs_failed: 143 125 kobject_put(type->devices_kobj); 144 126 attr_devices_failed: 145 - sysfs_remove_file(&type->kobj, &mdev_type_attr_create.attr); 146 - attr_create_failed: 147 127 kobject_del(&type->kobj); 148 128 kobject_put(&type->kobj); 149 129 return ret; ··· 152 136 sysfs_remove_files(&type->kobj, type->parent->mdev_driver->types_attrs); 153 137 154 138 kobject_put(type->devices_kobj); 155 - sysfs_remove_file(&type->kobj, &mdev_type_attr_create.attr); 156 139 kobject_del(&type->kobj); 157 140 kobject_put(&type->kobj); 158 141 }
+2 -5
include/linux/mdev.h
··· 61 61 size_t count); 62 62 }; 63 63 64 - #define MDEV_TYPE_ATTR(_name, _mode, _show, _store) \ 65 - struct mdev_type_attribute mdev_type_attr_##_name = \ 66 - __ATTR(_name, _mode, _show, _store) 67 - #define MDEV_TYPE_ATTR_RW(_name) \ 68 - struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name) 69 64 #define MDEV_TYPE_ATTR_RO(_name) \ 70 65 struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name) 71 66 #define MDEV_TYPE_ATTR_WO(_name) \ ··· 68 73 69 74 /** 70 75 * struct mdev_driver - Mediated device driver 76 + * @device_api: string to return for the device_api sysfs 71 77 * @probe: called when new device created 72 78 * @remove: called when device removed 73 79 * @types_attrs: attributes to the type kobjects. 74 80 * @driver: device driver structure 75 81 **/ 76 82 struct mdev_driver { 83 + const char *device_api; 77 84 int (*probe)(struct mdev_device *dev); 78 85 void (*remove)(struct mdev_device *dev); 79 86 const struct attribute * const *types_attrs;
+1 -8
samples/vfio-mdev/mbochs.c
··· 1384 1384 } 1385 1385 static MDEV_TYPE_ATTR_RO(available_instances); 1386 1386 1387 - static ssize_t device_api_show(struct mdev_type *mtype, 1388 - struct mdev_type_attribute *attr, char *buf) 1389 - { 1390 - return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); 1391 - } 1392 - static MDEV_TYPE_ATTR_RO(device_api); 1393 - 1394 1387 static const struct attribute *mdev_types_attrs[] = { 1395 1388 &mdev_type_attr_name.attr, 1396 1389 &mdev_type_attr_description.attr, 1397 - &mdev_type_attr_device_api.attr, 1398 1390 &mdev_type_attr_available_instances.attr, 1399 1391 NULL, 1400 1392 }; ··· 1402 1410 }; 1403 1411 1404 1412 static struct mdev_driver mbochs_driver = { 1413 + .device_api = VFIO_DEVICE_API_PCI_STRING, 1405 1414 .driver = { 1406 1415 .name = "mbochs", 1407 1416 .owner = THIS_MODULE,
+1 -8
samples/vfio-mdev/mdpy.c
··· 689 689 } 690 690 static MDEV_TYPE_ATTR_RO(available_instances); 691 691 692 - static ssize_t device_api_show(struct mdev_type *mtype, 693 - struct mdev_type_attribute *attr, char *buf) 694 - { 695 - return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); 696 - } 697 - static MDEV_TYPE_ATTR_RO(device_api); 698 - 699 692 static const struct attribute *mdev_types_attrs[] = { 700 693 &mdev_type_attr_name.attr, 701 694 &mdev_type_attr_description.attr, 702 - &mdev_type_attr_device_api.attr, 703 695 &mdev_type_attr_available_instances.attr, 704 696 NULL, 705 697 }; ··· 706 714 }; 707 715 708 716 static struct mdev_driver mdpy_driver = { 717 + .device_api = VFIO_DEVICE_API_PCI_STRING, 709 718 .driver = { 710 719 .name = "mdpy", 711 720 .owner = THIS_MODULE,
+1 -9
samples/vfio-mdev/mtty.c
··· 1277 1277 1278 1278 static MDEV_TYPE_ATTR_RO(available_instances); 1279 1279 1280 - static ssize_t device_api_show(struct mdev_type *mtype, 1281 - struct mdev_type_attribute *attr, char *buf) 1282 - { 1283 - return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING); 1284 - } 1285 - 1286 - static MDEV_TYPE_ATTR_RO(device_api); 1287 - 1288 1280 static const struct attribute *mdev_types_attrs[] = { 1289 1281 &mdev_type_attr_name.attr, 1290 - &mdev_type_attr_device_api.attr, 1291 1282 &mdev_type_attr_available_instances.attr, 1292 1283 NULL, 1293 1284 }; ··· 1293 1302 }; 1294 1303 1295 1304 static struct mdev_driver mtty_driver = { 1305 + .device_api = VFIO_DEVICE_API_PCI_STRING, 1296 1306 .driver = { 1297 1307 .name = "mtty", 1298 1308 .owner = THIS_MODULE,