This is a "v3" of the previous posted full conversion: https://lore.kernel.org/r/0-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com
Without the trailing patches that are running into complications: - The CCW conversion has some complicated remarks - AP is waiting for some locking stuff to get worked out - No feedback on GT - The license change topic for removing vfio_mdev.c
Getting the baseline functionality merged will allow Intel's IDXD mdev driver to advance. It has already been RFC posted in the new format:
https://lore.kernel.org/kvm/162164243591.261970.3439987543338120797.stgit@dj...
This series includes base infrastructure and the sample conversions. The remaining four issues can be sorted out one by one.
The major change in v3 is to enhance the driver core support for binding based on the request from Christoph Hellwig and Dan Williams. Based on some light analysis this looks broadly useful:
https://lore.kernel.org/kvm/20210428233856.GY1370958@nvidia.com/
====
The mdev bus's core part for managing the lifecycle of devices is mostly as one would expect for a driver core bus subsystem.
However instead of having a normal 'struct device_driver' and binding the actual mdev drivers through the standard driver core mechanisms it open codes this with the struct mdev_parent_ops and provides a single driver that shims between the VFIO core's struct vfio_device and the actual device driver.
Instead, allow mdev drivers implement an actual struct mdev_driver and directly call vfio_register_group_dev() in the probe() function for the mdev. Arrange to bind the created mdev_device to the mdev_driver that is provided by the end driver.
The actual execution flow doesn't change much, eg what was parent_ops->create is now device_driver->probe and it is called at almost the exact same time - except under the normal control of the driver core.
Ultimately converting all the drivers unlocks a fair number of additional VFIO simplifications and cleanups.
v3: - Use device_driver_attach() from the driver core - 5 new patches to make device_driver_attach() exported and usable for this - Remove trailing patches for now v2: https://lore.kernel.org/r/0-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com - Keep && m in samples kconfig - Restore accidently squashed removeal of vfio_mdev.c - Remove indirections to call bus_register()/bus_unregister() - Reflow long doc lines v1: https://lore.kernel.org/r/0-v1-d88406ed308e+418-vfio3_jgg@nvidia.com
Jason Gunthorpe (10): driver core: Do not continue searching for drivers if deferred probe is used driver core: Pull required checks into driver_probe_device() driver core: Flow the return code from ->probe() through to sysfs bind driver core: Don't return EPROBE_DEFER to userspace during sysfs bind driver core: Export device_driver_attach() vfio/mdev: Remove CONFIG_VFIO_MDEV_DEVICE vfio/mdev: Allow the mdev_parent_ops to specify the device driver to bind vfio/mtty: Convert to use vfio_register_group_dev() vfio/mdpy: Convert to use vfio_register_group_dev() vfio/mbochs: Convert to use vfio_register_group_dev()
Documentation/s390/vfio-ap.rst | 1 - arch/s390/Kconfig | 2 +- drivers/base/base.h | 1 - drivers/base/bus.c | 6 +- drivers/base/dd.c | 116 ++++++++++++------- drivers/gpu/drm/i915/Kconfig | 2 +- drivers/vfio/mdev/Kconfig | 7 -- drivers/vfio/mdev/Makefile | 3 +- drivers/vfio/mdev/mdev_core.c | 46 ++++++-- drivers/vfio/mdev/mdev_driver.c | 10 ++ drivers/vfio/mdev/mdev_private.h | 2 + drivers/vfio/mdev/vfio_mdev.c | 24 +--- include/linux/device.h | 2 + include/linux/mdev.h | 2 + samples/Kconfig | 6 +- samples/vfio-mdev/mbochs.c | 163 +++++++++++++++------------ samples/vfio-mdev/mdpy.c | 159 ++++++++++++++------------ samples/vfio-mdev/mtty.c | 185 ++++++++++++++----------------- 18 files changed, 397 insertions(+), 340 deletions(-)
For some reason the vfio_mdev shim mdev_driver has its own module and kconfig. As the next patch requires access to it from mdev.ko merge the two modules together and remove VFIO_MDEV_DEVICE.
A later patch deletes this driver entirely.
Signed-off-by: Jason Gunthorpe jgg@nvidia.com --- Documentation/s390/vfio-ap.rst | 1 - arch/s390/Kconfig | 2 +- drivers/gpu/drm/i915/Kconfig | 2 +- drivers/vfio/mdev/Kconfig | 7 ------- drivers/vfio/mdev/Makefile | 3 +-- drivers/vfio/mdev/mdev_core.c | 16 ++++++++++++++-- drivers/vfio/mdev/mdev_private.h | 2 ++ drivers/vfio/mdev/vfio_mdev.c | 24 +----------------------- samples/Kconfig | 6 +++--- 9 files changed, 23 insertions(+), 40 deletions(-)
diff --git a/Documentation/s390/vfio-ap.rst b/Documentation/s390/vfio-ap.rst index e15436599086b7..f57ae621f33e89 100644 --- a/Documentation/s390/vfio-ap.rst +++ b/Documentation/s390/vfio-ap.rst @@ -514,7 +514,6 @@ These are the steps: * S390_AP_IOMMU * VFIO * VFIO_MDEV - * VFIO_MDEV_DEVICE * KVM
If using make menuconfig select the following to build the vfio_ap module:: diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index b4c7c34069f81a..ea63fd22e1198a 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -768,7 +768,7 @@ config VFIO_CCW config VFIO_AP def_tristate n prompt "VFIO support for AP devices" - depends on S390_AP_IOMMU && VFIO_MDEV_DEVICE && KVM + depends on S390_AP_IOMMU && VFIO_MDEV && KVM depends on ZCRYPT help This driver grants access to Adjunct Processor (AP) devices diff --git a/drivers/gpu/drm/i915/Kconfig b/drivers/gpu/drm/i915/Kconfig index 69f57ca9c68d73..9ab1cecd69b2a0 100644 --- a/drivers/gpu/drm/i915/Kconfig +++ b/drivers/gpu/drm/i915/Kconfig @@ -126,7 +126,7 @@ config DRM_I915_GVT_KVMGT tristate "Enable KVM/VFIO support for Intel GVT-g" depends on DRM_I915_GVT depends on KVM - depends on VFIO_MDEV && VFIO_MDEV_DEVICE + depends on VFIO_MDEV default n help Choose this option if you want to enable KVMGT support for diff --git a/drivers/vfio/mdev/Kconfig b/drivers/vfio/mdev/Kconfig index 5da27f2100f9bd..763c877a1318bc 100644 --- a/drivers/vfio/mdev/Kconfig +++ b/drivers/vfio/mdev/Kconfig @@ -9,10 +9,3 @@ config VFIO_MDEV See Documentation/driver-api/vfio-mediated-device.rst for more details.
If you don't know what do here, say N. - -config VFIO_MDEV_DEVICE - tristate "VFIO driver for Mediated devices" - depends on VFIO && VFIO_MDEV - default n - help - VFIO based driver for Mediated devices. diff --git a/drivers/vfio/mdev/Makefile b/drivers/vfio/mdev/Makefile index 101516fdf3753e..ff9ecd80212503 100644 --- a/drivers/vfio/mdev/Makefile +++ b/drivers/vfio/mdev/Makefile @@ -1,6 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only
-mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o +mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o vfio_mdev.o
obj-$(CONFIG_VFIO_MDEV) += mdev.o -obj-$(CONFIG_VFIO_MDEV_DEVICE) += vfio_mdev.o diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 2a85d6fcb7ddd0..ff8c1a84516698 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -360,11 +360,24 @@ int mdev_device_remove(struct mdev_device *mdev)
static int __init mdev_init(void) { - return mdev_bus_register(); + int rc; + + rc = mdev_bus_register(); + if (rc) + return rc; + rc = mdev_register_driver(&vfio_mdev_driver); + if (rc) + goto err_bus; + return 0; +err_bus: + mdev_bus_unregister(); + return rc; }
static void __exit mdev_exit(void) { + mdev_unregister_driver(&vfio_mdev_driver); + if (mdev_bus_compat_class) class_compat_unregister(mdev_bus_compat_class);
@@ -378,4 +391,3 @@ MODULE_VERSION(DRIVER_VERSION); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); -MODULE_SOFTDEP("post: vfio_mdev"); diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index 6999c89db7b162..afbad7b0a14a17 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -37,6 +37,8 @@ struct mdev_type { #define to_mdev_type(_kobj) \ container_of(_kobj, struct mdev_type, kobj)
+extern struct mdev_driver vfio_mdev_driver; + int parent_create_sysfs_files(struct mdev_parent *parent); void parent_remove_sysfs_files(struct mdev_parent *parent);
diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c index 922729071c5a8e..d5b4eede47c1a5 100644 --- a/drivers/vfio/mdev/vfio_mdev.c +++ b/drivers/vfio/mdev/vfio_mdev.c @@ -17,10 +17,6 @@
#include "mdev_private.h"
-#define DRIVER_VERSION "0.1" -#define DRIVER_AUTHOR "NVIDIA Corporation" -#define DRIVER_DESC "VFIO based driver for Mediated device" - static int vfio_mdev_open(struct vfio_device *core_vdev) { struct mdev_device *mdev = to_mdev_device(core_vdev->dev); @@ -151,7 +147,7 @@ static void vfio_mdev_remove(struct mdev_device *mdev) kfree(vdev); }
-static struct mdev_driver vfio_mdev_driver = { +struct mdev_driver vfio_mdev_driver = { .driver = { .name = "vfio_mdev", .owner = THIS_MODULE, @@ -160,21 +156,3 @@ static struct mdev_driver vfio_mdev_driver = { .probe = vfio_mdev_probe, .remove = vfio_mdev_remove, }; - -static int __init vfio_mdev_init(void) -{ - return mdev_register_driver(&vfio_mdev_driver); -} - -static void __exit vfio_mdev_exit(void) -{ - mdev_unregister_driver(&vfio_mdev_driver); -} - -module_init(vfio_mdev_init) -module_exit(vfio_mdev_exit) - -MODULE_VERSION(DRIVER_VERSION); -MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR(DRIVER_AUTHOR); -MODULE_DESCRIPTION(DRIVER_DESC); diff --git a/samples/Kconfig b/samples/Kconfig index b5a1a7aa7e23ab..b0503ef058d334 100644 --- a/samples/Kconfig +++ b/samples/Kconfig @@ -154,14 +154,14 @@ config SAMPLE_UHID
config SAMPLE_VFIO_MDEV_MTTY tristate "Build VFIO mtty example mediated device sample code -- loadable modules only" - depends on VFIO_MDEV_DEVICE && m + depends on VFIO_MDEV && m help Build a virtual tty sample driver for use as a VFIO mediated device
config SAMPLE_VFIO_MDEV_MDPY tristate "Build VFIO mdpy example mediated device sample code -- loadable modules only" - depends on VFIO_MDEV_DEVICE && m + depends on VFIO_MDEV && m help Build a virtual display sample driver for use as a VFIO mediated device. It is a simple framebuffer and supports @@ -178,7 +178,7 @@ config SAMPLE_VFIO_MDEV_MDPY_FB
config SAMPLE_VFIO_MDEV_MBOCHS tristate "Build VFIO mdpy example mediated device sample code -- loadable modules only" - depends on VFIO_MDEV_DEVICE && m + depends on VFIO_MDEV && m select DMA_SHARED_BUFFER help Build a virtual display sample driver for use as a VFIO
On Mon, Jun 07 2021, Jason Gunthorpe jgg@nvidia.com wrote:
For some reason the vfio_mdev shim mdev_driver has its own module and kconfig. As the next patch requires access to it from mdev.ko merge the two modules together and remove VFIO_MDEV_DEVICE.
A later patch deletes this driver entirely.
Signed-off-by: Jason Gunthorpe jgg@nvidia.com
Documentation/s390/vfio-ap.rst | 1 - arch/s390/Kconfig | 2 +- drivers/gpu/drm/i915/Kconfig | 2 +- drivers/vfio/mdev/Kconfig | 7 ------- drivers/vfio/mdev/Makefile | 3 +-- drivers/vfio/mdev/mdev_core.c | 16 ++++++++++++++-- drivers/vfio/mdev/mdev_private.h | 2 ++ drivers/vfio/mdev/vfio_mdev.c | 24 +----------------------- samples/Kconfig | 6 +++--- 9 files changed, 23 insertions(+), 40 deletions(-)
I think you missed my earlier
Reviewed-by: Cornelia Huck cohuck@redhat.com
On Fri, Jun 11, 2021 at 02:40:41PM +0200, Cornelia Huck wrote:
On Mon, Jun 07 2021, Jason Gunthorpe jgg@nvidia.com wrote:
For some reason the vfio_mdev shim mdev_driver has its own module and kconfig. As the next patch requires access to it from mdev.ko merge the two modules together and remove VFIO_MDEV_DEVICE.
A later patch deletes this driver entirely.
Signed-off-by: Jason Gunthorpe jgg@nvidia.com Documentation/s390/vfio-ap.rst | 1 - arch/s390/Kconfig | 2 +- drivers/gpu/drm/i915/Kconfig | 2 +- drivers/vfio/mdev/Kconfig | 7 ------- drivers/vfio/mdev/Makefile | 3 +-- drivers/vfio/mdev/mdev_core.c | 16 ++++++++++++++-- drivers/vfio/mdev/mdev_private.h | 2 ++ drivers/vfio/mdev/vfio_mdev.c | 24 +----------------------- samples/Kconfig | 6 +++--- 9 files changed, 23 insertions(+), 40 deletions(-)
I think you missed my earlier
Reviewed-by: Cornelia Huck cohuck@redhat.com
Yes, my mistake, I didn't think there were any tags in the v1 posting
Thanks, Jason
Jason,
I couldn't find patch 1,2,4 and 5 of these series. Can you please keep kvm@vger.kernel.org cc for all patches?
Also it will be helpful if you can add version prefix, eg. 'v3' for this series, in subject line.
Thanks, Kirti
On 6/8/2021 6:25 AM, Jason Gunthorpe wrote:
This is a "v3" of the previous posted full conversion: https://lore.kernel.org/r/0-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com
Without the trailing patches that are running into complications:
- The CCW conversion has some complicated remarks
- AP is waiting for some locking stuff to get worked out
- No feedback on GT
- The license change topic for removing vfio_mdev.c
Getting the baseline functionality merged will allow Intel's IDXD mdev driver to advance. It has already been RFC posted in the new format:
https://lore.kernel.org/kvm/162164243591.261970.3439987543338120797.stgit@dj...
This series includes base infrastructure and the sample conversions. The remaining four issues can be sorted out one by one.
The major change in v3 is to enhance the driver core support for binding based on the request from Christoph Hellwig and Dan Williams. Based on some light analysis this looks broadly useful:
https://lore.kernel.org/kvm/20210428233856.GY1370958@nvidia.com/
====
The mdev bus's core part for managing the lifecycle of devices is mostly as one would expect for a driver core bus subsystem.
However instead of having a normal 'struct device_driver' and binding the actual mdev drivers through the standard driver core mechanisms it open codes this with the struct mdev_parent_ops and provides a single driver that shims between the VFIO core's struct vfio_device and the actual device driver.
Instead, allow mdev drivers implement an actual struct mdev_driver and directly call vfio_register_group_dev() in the probe() function for the mdev. Arrange to bind the created mdev_device to the mdev_driver that is provided by the end driver.
The actual execution flow doesn't change much, eg what was parent_ops->create is now device_driver->probe and it is called at almost the exact same time - except under the normal control of the driver core.
Ultimately converting all the drivers unlocks a fair number of additional VFIO simplifications and cleanups.
v3:
- Use device_driver_attach() from the driver core
- 5 new patches to make device_driver_attach() exported and usable for this
- Remove trailing patches for now
v2: https://lore.kernel.org/r/0-v2-7667f42c9bad+935-vfio3_jgg@nvidia.com
- Keep && m in samples kconfig
- Restore accidently squashed removeal of vfio_mdev.c
- Remove indirections to call bus_register()/bus_unregister()
- Reflow long doc lines
v1: https://lore.kernel.org/r/0-v1-d88406ed308e+418-vfio3_jgg@nvidia.com
Jason Gunthorpe (10): driver core: Do not continue searching for drivers if deferred probe is used driver core: Pull required checks into driver_probe_device() driver core: Flow the return code from ->probe() through to sysfs bind driver core: Don't return EPROBE_DEFER to userspace during sysfs bind driver core: Export device_driver_attach() vfio/mdev: Remove CONFIG_VFIO_MDEV_DEVICE vfio/mdev: Allow the mdev_parent_ops to specify the device driver to bind vfio/mtty: Convert to use vfio_register_group_dev() vfio/mdpy: Convert to use vfio_register_group_dev() vfio/mbochs: Convert to use vfio_register_group_dev()
Documentation/s390/vfio-ap.rst | 1 - arch/s390/Kconfig | 2 +- drivers/base/base.h | 1 - drivers/base/bus.c | 6 +- drivers/base/dd.c | 116 ++++++++++++------- drivers/gpu/drm/i915/Kconfig | 2 +- drivers/vfio/mdev/Kconfig | 7 -- drivers/vfio/mdev/Makefile | 3 +- drivers/vfio/mdev/mdev_core.c | 46 ++++++-- drivers/vfio/mdev/mdev_driver.c | 10 ++ drivers/vfio/mdev/mdev_private.h | 2 + drivers/vfio/mdev/vfio_mdev.c | 24 +--- include/linux/device.h | 2 + include/linux/mdev.h | 2 + samples/Kconfig | 6 +- samples/vfio-mdev/mbochs.c | 163 +++++++++++++++------------ samples/vfio-mdev/mdpy.c | 159 ++++++++++++++------------ samples/vfio-mdev/mtty.c | 185 ++++++++++++++----------------- 18 files changed, 397 insertions(+), 340 deletions(-)
On Mon, Jun 14, 2021 at 08:04:03PM +0530, Kirti Wankhede wrote:
Jason,
I couldn't find patch 1,2,4 and 5 of these series. Can you please keep kvm@vger.kernel.org cc for all patches?
It is an error, sorry
Also it will be helpful if you can add version prefix, eg. 'v3' for this series, in subject line.
This is not v3, it is a different but related series
Jason
dri-devel@lists.freedesktop.org