Skip to content

Commit 89345d5

Browse files
Christoph HellwigAlex Williamson
authored andcommitted
vfio/mdev: embedd struct mdev_parent in the parent data structure
Simplify mdev_{un}register_device by requiring the caller to pass in a structure allocate as part of the parent device structure. This removes the need for a list of parents and the separate mdev_parent refcount as we can simplify rely on the reference to the parent device. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> 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-5-hch@lst.de Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent bdef2b7 commit 89345d5

File tree

17 files changed

+71
-146
lines changed

17 files changed

+71
-146
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ devices as examples, as these devices are the first devices to use this module::
5858
| MDEV CORE |
5959
| MODULE |
6060
| mdev.ko |
61-
| +-----------+ | mdev_register_device() +--------------+
61+
| +-----------+ | mdev_register_parent() +--------------+
6262
| | | +<------------------------+ |
6363
| | | | | nvidia.ko |<-> physical
6464
| | | +------------------------>+ | device
6565
| | | | callbacks +--------------+
6666
| | Physical | |
67-
| | device | | mdev_register_device() +--------------+
67+
| | device | | mdev_register_parent() +--------------+
6868
| | interface | |<------------------------+ |
6969
| | | | | i915.ko |<-> physical
7070
| | | +------------------------>+ | device
7171
| | | | callbacks +--------------+
7272
| | | |
73-
| | | | mdev_register_device() +--------------+
73+
| | | | mdev_register_parent() +--------------+
7474
| | | +<------------------------+ |
7575
| | | | | ccw_device.ko|<-> physical
7676
| | | +------------------------>+ | device
@@ -125,16 +125,16 @@ vfio_device_ops.
125125
When a driver wants to add the GUID creation sysfs to an existing device it has
126126
probe'd to then it should call::
127127

128-
int mdev_register_device(struct device *dev,
129-
struct mdev_driver *mdev_driver);
128+
int mdev_register_parent(struct mdev_parent *parent, struct device *dev,
129+
struct mdev_driver *mdev_driver);
130130

131131
This will provide the 'mdev_supported_types/XX/create' files which can then be
132132
used to trigger the creation of a mdev_device. The created mdev_device will be
133133
attached to the specified driver.
134134

135135
When the driver needs to remove itself it calls::
136136

137-
void mdev_unregister_device(struct device *dev);
137+
void mdev_unregister_parent(struct mdev_parent *parent);
138138

139139
Which will unbind and destroy all the created mdevs and remove the sysfs files.
140140

Documentation/s390/vfio-ap.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ of the VFIO AP mediated device driver::
297297
| MDEV CORE |
298298
| MODULE |
299299
| mdev.ko |
300-
| +---------+ | mdev_register_device() +--------------+
300+
| +---------+ | mdev_register_parent() +--------------+
301301
| |Physical | +<-----------------------+ |
302302
| | device | | | vfio_ap.ko |<-> matrix
303303
| |interface| +----------------------->+ | device

Documentation/s390/vfio-ccw.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Below is a high Level block diagram::
156156
| MDEV CORE |
157157
| MODULE |
158158
| mdev.ko |
159-
| +---------+ | mdev_register_device() +--------------+
159+
| +---------+ | mdev_register_parent() +--------------+
160160
| |Physical | +<-----------------------+ |
161161
| | device | | | vfio_ccw.ko |<-> subchannel
162162
| |interface| +----------------------->+ | device

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <uapi/linux/pci_regs.h>
3737
#include <linux/kvm_host.h>
3838
#include <linux/vfio.h>
39+
#include <linux/mdev.h>
3940

4041
#include "i915_drv.h"
4142
#include "intel_gvt.h"
@@ -337,6 +338,7 @@ struct intel_gvt {
337338
struct intel_gvt_workload_scheduler scheduler;
338339
struct notifier_block shadow_ctx_notifier_block[I915_NUM_ENGINES];
339340
DECLARE_HASHTABLE(cmd_table, GVT_CMD_HASH_BITS);
341+
struct mdev_parent parent;
340342
struct intel_vgpu_type *types;
341343
unsigned int num_types;
342344
struct intel_vgpu *idle_vgpu;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,7 @@ static void intel_gvt_clean_device(struct drm_i915_private *i915)
19231923
if (drm_WARN_ON(&i915->drm, !gvt))
19241924
return;
19251925

1926-
mdev_unregister_device(i915->drm.dev);
1926+
mdev_unregister_parent(&gvt->parent);
19271927
intel_gvt_cleanup_vgpu_type_groups(gvt);
19281928
intel_gvt_destroy_idle_vgpu(gvt->idle_vgpu);
19291929
intel_gvt_clean_vgpu_types(gvt);
@@ -2028,7 +2028,8 @@ static int intel_gvt_init_device(struct drm_i915_private *i915)
20282028
if (ret)
20292029
goto out_destroy_idle_vgpu;
20302030

2031-
ret = mdev_register_device(i915->drm.dev, &intel_vgpu_mdev_driver);
2031+
ret = mdev_register_parent(&gvt->parent, i915->drm.dev,
2032+
&intel_vgpu_mdev_driver);
20322033
if (ret)
20332034
goto out_cleanup_vgpu_type_groups;
20342035

drivers/s390/cio/vfio_ccw_drv.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)
221221

222222
dev_set_drvdata(&sch->dev, private);
223223

224-
ret = mdev_register_device(&sch->dev, &vfio_ccw_mdev_driver);
224+
ret = mdev_register_parent(&private->parent, &sch->dev,
225+
&vfio_ccw_mdev_driver);
225226
if (ret)
226227
goto out_free;
227228

@@ -240,7 +241,7 @@ static void vfio_ccw_sch_remove(struct subchannel *sch)
240241
{
241242
struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev);
242243

243-
mdev_unregister_device(&sch->dev);
244+
mdev_unregister_parent(&private->parent);
244245

245246
dev_set_drvdata(&sch->dev, NULL);
246247

drivers/s390/cio/vfio_ccw_ops.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
*/
1212

1313
#include <linux/vfio.h>
14-
#include <linux/mdev.h>
1514
#include <linux/nospec.h>
1615
#include <linux/slab.h>
1716

drivers/s390/cio/vfio_ccw_private.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/workqueue.h>
1919
#include <linux/vfio_ccw.h>
2020
#include <linux/vfio.h>
21+
#include <linux/mdev.h>
2122
#include <asm/crw.h>
2223
#include <asm/debug.h>
2324

@@ -89,6 +90,7 @@ struct vfio_ccw_crw {
8990
* @io_work: work for deferral process of I/O handling
9091
* @crw_work: work for deferral process of CRW handling
9192
* @release_comp: synchronization helper for vfio device release
93+
* @parent: parent data structures for mdevs created
9294
*/
9395
struct vfio_ccw_private {
9496
struct vfio_device vdev;
@@ -116,6 +118,8 @@ struct vfio_ccw_private {
116118
struct work_struct crw_work;
117119

118120
struct completion release_comp;
121+
122+
struct mdev_parent parent;
119123
} __aligned(8);
120124

121125
int vfio_ccw_sch_quiesce(struct subchannel *sch);

drivers/s390/crypto/vfio_ap_ops.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,8 @@ int vfio_ap_mdev_register(void)
18301830
if (ret)
18311831
return ret;
18321832

1833-
ret = mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_driver);
1833+
ret = mdev_register_parent(&matrix_dev->parent, &matrix_dev->device,
1834+
&vfio_ap_matrix_driver);
18341835
if (ret)
18351836
goto err_driver;
18361837
return 0;
@@ -1842,7 +1843,7 @@ int vfio_ap_mdev_register(void)
18421843

18431844
void vfio_ap_mdev_unregister(void)
18441845
{
1845-
mdev_unregister_device(&matrix_dev->device);
1846+
mdev_unregister_parent(&matrix_dev->parent);
18461847
mdev_unregister_driver(&vfio_ap_matrix_driver);
18471848
}
18481849

drivers/s390/crypto/vfio_ap_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct ap_matrix_dev {
5252
struct mutex mdevs_lock; /* serializes access to each ap_matrix_mdev */
5353
struct ap_driver *vfio_ap_drv;
5454
struct mutex guests_lock; /* serializes access to each KVM guest */
55+
struct mdev_parent parent;
5556
};
5657

5758
extern struct ap_matrix_dev *matrix_dev;

0 commit comments

Comments
 (0)