* [PATCH v2 00/13] Remove vfio_mdev.c, mdev_parent_ops and more
@ 2021-04-26 20:00 Jason Gunthorpe
2021-04-26 20:00 ` [PATCH v2 01/13] vfio/mdev: Remove CONFIG_VFIO_MDEV_DEVICE Jason Gunthorpe
` (4 more replies)
0 siblings, 5 replies; 26+ messages in thread
From: Jason Gunthorpe @ 2021-04-26 20:00 UTC (permalink / raw)
To: David Airlie, Tony Krowiak, Alex Williamson,
Christian Borntraeger, Cornelia Huck, Jonathan Corbet,
Daniel Vetter, dri-devel, Eric Farman, Harald Freudenberger,
Vasily Gorbik, Heiko Carstens, intel-gfx, intel-gvt-dev,
Jani Nikula, Joonas Lahtinen, kvm, Kirti Wankhede, linux-doc,
linux-s390, Peter Oberparleiter, Halil Pasic, Pierre Morel,
Rodrigo Vivi, Vineeth Vijayan, Zhenyu Wang, Zhi Wang
Cc: Raj, Ashok, Dan Williams, Christoph Hellwig, Leon Romanovsky,
Max Gurtovoy, Tarun Gupta
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 and the actual device driver.
Make every one of the mdev drivers implement an actual struct mdev_driver
and directly call vfio_register_group_dev() in the probe() function for
the mdev.
Squash what is left of the mdev_parent_ops into the mdev_driver and remap
create(), remove() and mdev_attr_groups to their driver core
equivalents. 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.
This allows deleting the entire mdev_drvdata, and tidying some of the
sysfs. Many places in the drivers start using container_of()
This cleanly splits the mdev sysfs GUID lifecycle management stuff from
the vfio_device implementation part, the only VFIO special part of mdev
that remains is the mdev specific iommu intervention.
v2:
- 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
Cc: Leon Romanovsky <leonro@nvidia.com>
Cc: "Raj, Ashok" <ashok.raj@intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Max Gurtovoy <mgurtovoy@nvidia.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Tarun Gupta <targupta@nvidia.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Jason Gunthorpe (13):
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()
vfio/ap_ops: Convert to use vfio_register_group_dev()
vfio/ccw: Convert to use vfio_register_group_dev()
vfio/gvt: Convert to use vfio_register_group_dev()
vfio/mdev: Remove vfio_mdev.c
vfio/mdev: Remove mdev_parent_ops dev_attr_groups
vfio/mdev: Remove mdev_parent_ops
vfio/mdev: Use the driver core to create the 'remove' file
vfio/mdev: Remove mdev drvdata
.../driver-api/vfio-mediated-device.rst | 56 ++---
Documentation/s390/vfio-ap.rst | 1 -
arch/s390/Kconfig | 2 +-
drivers/gpu/drm/i915/Kconfig | 2 +-
drivers/gpu/drm/i915/gvt/kvmgt.c | 210 +++++++++--------
drivers/s390/cio/vfio_ccw_drv.c | 21 +-
drivers/s390/cio/vfio_ccw_ops.c | 136 ++++++-----
drivers/s390/cio/vfio_ccw_private.h | 5 +
drivers/s390/crypto/vfio_ap_ops.c | 138 ++++++-----
drivers/s390/crypto/vfio_ap_private.h | 2 +
drivers/vfio/mdev/Kconfig | 7 -
drivers/vfio/mdev/Makefile | 1 -
drivers/vfio/mdev/mdev_core.c | 67 ++++--
drivers/vfio/mdev/mdev_driver.c | 20 +-
drivers/vfio/mdev/mdev_private.h | 4 +-
drivers/vfio/mdev/mdev_sysfs.c | 37 ++-
drivers/vfio/mdev/vfio_mdev.c | 180 ---------------
drivers/vfio/vfio.c | 6 +-
include/linux/mdev.h | 86 +------
include/linux/vfio.h | 4 +
samples/Kconfig | 6 +-
samples/vfio-mdev/mbochs.c | 166 +++++++------
samples/vfio-mdev/mdpy.c | 162 +++++++------
samples/vfio-mdev/mtty.c | 218 +++++++-----------
24 files changed, 651 insertions(+), 886 deletions(-)
delete mode 100644 drivers/vfio/mdev/vfio_mdev.c
--
2.31.1
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 01/13] vfio/mdev: Remove CONFIG_VFIO_MDEV_DEVICE
2021-04-26 20:00 [PATCH v2 00/13] Remove vfio_mdev.c, mdev_parent_ops and more Jason Gunthorpe
@ 2021-04-26 20:00 ` Jason Gunthorpe
2021-04-27 11:05 ` Cornelia Huck
2021-04-26 20:00 ` [PATCH v2 06/13] vfio/ap_ops: Convert to use vfio_register_group_dev() Jason Gunthorpe
` (3 subsequent siblings)
4 siblings, 1 reply; 26+ messages in thread
From: Jason Gunthorpe @ 2021-04-26 20:00 UTC (permalink / raw)
To: David Airlie, Tony Krowiak, Alex Williamson,
Christian Borntraeger, Cornelia Huck, Jonathan Corbet,
Daniel Vetter, dri-devel, Vasily Gorbik, Heiko Carstens,
intel-gfx, Jani Nikula, Joonas Lahtinen, kvm, Kirti Wankhede,
linux-doc, linux-s390, Halil Pasic, Pierre Morel, Rodrigo Vivi
Cc: Raj, Ashok, Dan Williams, Christoph Hellwig, Leon Romanovsky,
Max Gurtovoy, Tarun Gupta
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 c1ff874e6c2e63..dc7928e37fa409 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -773,7 +773,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 483e9ff8ca1d23..388bc41aa1a75b 100644
--- a/drivers/gpu/drm/i915/Kconfig
+++ b/drivers/gpu/drm/i915/Kconfig
@@ -125,7 +125,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 a656cfe0346c33..5461b67582289f 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 e76cdfc50e257d..5708abcc55c4df 100644
--- a/samples/Kconfig
+++ b/samples/Kconfig
@@ -147,14 +147,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
@@ -171,7 +171,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
--
2.31.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 06/13] vfio/ap_ops: Convert to use vfio_register_group_dev()
2021-04-26 20:00 [PATCH v2 00/13] Remove vfio_mdev.c, mdev_parent_ops and more Jason Gunthorpe
2021-04-26 20:00 ` [PATCH v2 01/13] vfio/mdev: Remove CONFIG_VFIO_MDEV_DEVICE Jason Gunthorpe
@ 2021-04-26 20:00 ` Jason Gunthorpe
2021-05-04 14:42 ` Tony Krowiak
2021-04-26 20:00 ` [PATCH v2 07/13] vfio/ccw: " Jason Gunthorpe
` (2 subsequent siblings)
4 siblings, 1 reply; 26+ messages in thread
From: Jason Gunthorpe @ 2021-04-26 20:00 UTC (permalink / raw)
To: Tony Krowiak, Christian Borntraeger, Harald Freudenberger,
Vasily Gorbik, Heiko Carstens, linux-s390, Halil Pasic,
Pierre Morel
Cc: Raj, Ashok, Dan Williams, Daniel Vetter, Christoph Hellwig,
Leon Romanovsky, Max Gurtovoy, Tarun Gupta
This is straightforward conversion, the ap_matrix_mdev is actually serving
as the vfio_device and we can replace all the mdev_get_drvdata()'s with a
simple container_of().
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
drivers/s390/crypto/vfio_ap_ops.c | 137 ++++++++++++++++----------
drivers/s390/crypto/vfio_ap_private.h | 2 +
2 files changed, 89 insertions(+), 50 deletions(-)
diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
index 0ce00c9311d378..79872c857dd522 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -24,8 +24,9 @@
#define VFIO_AP_MDEV_TYPE_HWVIRT "passthrough"
#define VFIO_AP_MDEV_NAME_HWVIRT "VFIO AP Passthrough Device"
-static int vfio_ap_mdev_reset_queues(struct mdev_device *mdev);
+static int vfio_ap_mdev_reset_queues(struct ap_matrix_mdev *matrix_mdev);
static struct vfio_ap_queue *vfio_ap_find_queue(int apqn);
+static const struct vfio_device_ops vfio_ap_matrix_dev_ops;
static int match_apqn(struct device *dev, const void *data)
{
@@ -322,48 +323,63 @@ static void vfio_ap_matrix_init(struct ap_config_info *info,
matrix->adm_max = info->apxa ? info->Nd : 15;
}
-static int vfio_ap_mdev_create(struct mdev_device *mdev)
+static int vfio_ap_mdev_probe(struct mdev_device *mdev)
{
struct ap_matrix_mdev *matrix_mdev;
+ int ret;
if ((atomic_dec_if_positive(&matrix_dev->available_instances) < 0))
return -EPERM;
matrix_mdev = kzalloc(sizeof(*matrix_mdev), GFP_KERNEL);
if (!matrix_mdev) {
- atomic_inc(&matrix_dev->available_instances);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto err_atomic;
}
+ vfio_init_group_dev(&matrix_mdev->vdev, &mdev->dev,
+ &vfio_ap_matrix_dev_ops);
matrix_mdev->mdev = mdev;
vfio_ap_matrix_init(&matrix_dev->info, &matrix_mdev->matrix);
- mdev_set_drvdata(mdev, matrix_mdev);
matrix_mdev->pqap_hook.hook = handle_pqap;
matrix_mdev->pqap_hook.owner = THIS_MODULE;
mutex_lock(&matrix_dev->lock);
list_add(&matrix_mdev->node, &matrix_dev->mdev_list);
mutex_unlock(&matrix_dev->lock);
+ ret = vfio_register_group_dev(&matrix_mdev->vdev);
+ if (ret)
+ goto err_list;
+ dev_set_drvdata(&mdev->dev, matrix_mdev);
return 0;
+
+err_list:
+ mutex_lock(&matrix_dev->lock);
+ list_del(&matrix_mdev->node);
+ mutex_unlock(&matrix_dev->lock);
+ kfree(matrix_mdev);
+err_atomic:
+ atomic_inc(&matrix_dev->available_instances);
+ return ret;
}
-static int vfio_ap_mdev_remove(struct mdev_device *mdev)
+static void vfio_ap_mdev_remove(struct mdev_device *mdev)
{
- struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+ struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(&mdev->dev);
- if (matrix_mdev->kvm)
- return -EBUSY;
+ /* FIXME: Remove isn't allowed to fail */
+ if (WARN_ON(matrix_mdev->kvm))
+ return;
+
+ vfio_unregister_group_dev(&matrix_mdev->vdev);
mutex_lock(&matrix_dev->lock);
- vfio_ap_mdev_reset_queues(mdev);
+ vfio_ap_mdev_reset_queues(matrix_mdev);
list_del(&matrix_mdev->node);
mutex_unlock(&matrix_dev->lock);
kfree(matrix_mdev);
- mdev_set_drvdata(mdev, NULL);
atomic_inc(&matrix_dev->available_instances);
-
- return 0;
}
static ssize_t name_show(struct mdev_type *mtype,
@@ -605,8 +621,7 @@ static ssize_t assign_adapter_store(struct device *dev,
{
int ret;
unsigned long apid;
- struct mdev_device *mdev = mdev_from_dev(dev);
- struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+ struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
/* If the guest is running, disallow assignment of adapter */
if (matrix_mdev->kvm)
@@ -671,8 +686,7 @@ static ssize_t unassign_adapter_store(struct device *dev,
{
int ret;
unsigned long apid;
- struct mdev_device *mdev = mdev_from_dev(dev);
- struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+ struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
/* If the guest is running, disallow un-assignment of adapter */
if (matrix_mdev->kvm)
@@ -751,8 +765,7 @@ static ssize_t assign_domain_store(struct device *dev,
{
int ret;
unsigned long apqi;
- struct mdev_device *mdev = mdev_from_dev(dev);
- struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+ struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
unsigned long max_apqi = matrix_mdev->matrix.aqm_max;
/* If the guest is running, disallow assignment of domain */
@@ -813,8 +826,7 @@ static ssize_t unassign_domain_store(struct device *dev,
{
int ret;
unsigned long apqi;
- struct mdev_device *mdev = mdev_from_dev(dev);
- struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+ struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
/* If the guest is running, disallow un-assignment of domain */
if (matrix_mdev->kvm)
@@ -857,8 +869,7 @@ static ssize_t assign_control_domain_store(struct device *dev,
{
int ret;
unsigned long id;
- struct mdev_device *mdev = mdev_from_dev(dev);
- struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+ struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
/* If the guest is running, disallow assignment of control domain */
if (matrix_mdev->kvm)
@@ -906,8 +917,7 @@ static ssize_t unassign_control_domain_store(struct device *dev,
{
int ret;
unsigned long domid;
- struct mdev_device *mdev = mdev_from_dev(dev);
- struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+ struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
unsigned long max_domid = matrix_mdev->matrix.adm_max;
/* If the guest is running, disallow un-assignment of control domain */
@@ -936,8 +946,7 @@ static ssize_t control_domains_show(struct device *dev,
int nchars = 0;
int n;
char *bufpos = buf;
- struct mdev_device *mdev = mdev_from_dev(dev);
- struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+ struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
unsigned long max_domid = matrix_mdev->matrix.adm_max;
mutex_lock(&matrix_dev->lock);
@@ -955,8 +964,7 @@ static DEVICE_ATTR_RO(control_domains);
static ssize_t matrix_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
- struct mdev_device *mdev = mdev_from_dev(dev);
- struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+ struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
char *bufpos = buf;
unsigned long apid;
unsigned long apqi;
@@ -1085,7 +1093,7 @@ static void vfio_ap_mdev_unset_kvm(struct ap_matrix_mdev *matrix_mdev)
{
kvm_arch_crypto_clear_masks(matrix_mdev->kvm);
matrix_mdev->kvm->arch.crypto.pqap_hook = NULL;
- vfio_ap_mdev_reset_queues(matrix_mdev->mdev);
+ vfio_ap_mdev_reset_queues(matrix_mdev);
kvm_put_kvm(matrix_mdev->kvm);
matrix_mdev->kvm = NULL;
}
@@ -1195,13 +1203,12 @@ int vfio_ap_mdev_reset_queue(struct vfio_ap_queue *q,
return ret;
}
-static int vfio_ap_mdev_reset_queues(struct mdev_device *mdev)
+static int vfio_ap_mdev_reset_queues(struct ap_matrix_mdev *matrix_mdev)
{
int ret;
int rc = 0;
unsigned long apid, apqi;
struct vfio_ap_queue *q;
- struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
for_each_set_bit_inv(apid, matrix_mdev->matrix.apm,
matrix_mdev->matrix.apm_max + 1) {
@@ -1222,9 +1229,10 @@ static int vfio_ap_mdev_reset_queues(struct mdev_device *mdev)
return rc;
}
-static int vfio_ap_mdev_open(struct mdev_device *mdev)
+static int vfio_ap_mdev_open(struct vfio_device *vdev)
{
- struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+ struct ap_matrix_mdev *matrix_mdev =
+ container_of(vdev, struct ap_matrix_mdev, vdev);
unsigned long events;
int ret;
@@ -1235,7 +1243,7 @@ static int vfio_ap_mdev_open(struct mdev_device *mdev)
matrix_mdev->group_notifier.notifier_call = vfio_ap_mdev_group_notifier;
events = VFIO_GROUP_NOTIFY_SET_KVM;
- ret = vfio_register_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY,
+ ret = vfio_register_notifier(vdev->dev, VFIO_GROUP_NOTIFY,
&events, &matrix_mdev->group_notifier);
if (ret) {
module_put(THIS_MODULE);
@@ -1244,29 +1252,30 @@ static int vfio_ap_mdev_open(struct mdev_device *mdev)
matrix_mdev->iommu_notifier.notifier_call = vfio_ap_mdev_iommu_notifier;
events = VFIO_IOMMU_NOTIFY_DMA_UNMAP;
- ret = vfio_register_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY,
+ ret = vfio_register_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,
&events, &matrix_mdev->iommu_notifier);
if (!ret)
return ret;
- vfio_unregister_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY,
+ vfio_unregister_notifier(vdev->dev, VFIO_GROUP_NOTIFY,
&matrix_mdev->group_notifier);
module_put(THIS_MODULE);
return ret;
}
-static void vfio_ap_mdev_release(struct mdev_device *mdev)
+static void vfio_ap_mdev_release(struct vfio_device *vdev)
{
- struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
+ struct ap_matrix_mdev *matrix_mdev =
+ container_of(vdev, struct ap_matrix_mdev, vdev);
mutex_lock(&matrix_dev->lock);
if (matrix_mdev->kvm)
vfio_ap_mdev_unset_kvm(matrix_mdev);
mutex_unlock(&matrix_dev->lock);
- vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY,
+ vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,
&matrix_mdev->iommu_notifier);
- vfio_unregister_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY,
+ vfio_unregister_notifier(vdev->dev, VFIO_GROUP_NOTIFY,
&matrix_mdev->group_notifier);
module_put(THIS_MODULE);
}
@@ -1291,9 +1300,11 @@ static int vfio_ap_mdev_get_device_info(unsigned long arg)
return copy_to_user((void __user *)arg, &info, minsz) ? -EFAULT : 0;
}
-static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
+static ssize_t vfio_ap_mdev_ioctl(struct vfio_device *vdev,
unsigned int cmd, unsigned long arg)
{
+ struct ap_matrix_mdev *matrix_mdev =
+ container_of(vdev, struct ap_matrix_mdev, vdev);
int ret;
mutex_lock(&matrix_dev->lock);
@@ -1302,7 +1313,7 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
ret = vfio_ap_mdev_get_device_info(arg);
break;
case VFIO_DEVICE_RESET:
- ret = vfio_ap_mdev_reset_queues(mdev);
+ ret = vfio_ap_mdev_reset_queues(matrix_mdev);
break;
default:
ret = -EOPNOTSUPP;
@@ -1313,25 +1324,51 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
return ret;
}
+static const struct vfio_device_ops vfio_ap_matrix_dev_ops = {
+ .open = vfio_ap_mdev_open,
+ .release = vfio_ap_mdev_release,
+ .ioctl = vfio_ap_mdev_ioctl,
+};
+
+static struct mdev_driver vfio_ap_matrix_driver = {
+ .driver = {
+ .name = "vfio_ap_mdev",
+ .owner = THIS_MODULE,
+ .mod_name = KBUILD_MODNAME,
+ .dev_groups = vfio_ap_mdev_attr_groups,
+ },
+ .probe = vfio_ap_mdev_probe,
+ .remove = vfio_ap_mdev_remove,
+};
+
static const struct mdev_parent_ops vfio_ap_matrix_ops = {
.owner = THIS_MODULE,
+ .device_driver = &vfio_ap_matrix_driver,
.supported_type_groups = vfio_ap_mdev_type_groups,
- .mdev_attr_groups = vfio_ap_mdev_attr_groups,
- .create = vfio_ap_mdev_create,
- .remove = vfio_ap_mdev_remove,
- .open = vfio_ap_mdev_open,
- .release = vfio_ap_mdev_release,
- .ioctl = vfio_ap_mdev_ioctl,
};
int vfio_ap_mdev_register(void)
{
+ int ret;
+
atomic_set(&matrix_dev->available_instances, MAX_ZDEV_ENTRIES_EXT);
- return mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_ops);
+ ret = mdev_register_driver(&vfio_ap_matrix_driver);
+ if (ret)
+ return ret;
+
+ ret = mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_ops);
+ if (ret)
+ goto err_driver;
+ return 0;
+
+err_driver:
+ mdev_unregister_driver(&vfio_ap_matrix_driver);
+ return ret;
}
void vfio_ap_mdev_unregister(void)
{
mdev_unregister_device(&matrix_dev->device);
+ mdev_unregister_driver(&vfio_ap_matrix_driver);
}
diff --git a/drivers/s390/crypto/vfio_ap_private.h b/drivers/s390/crypto/vfio_ap_private.h
index 28e9d998976820..b95ba674f60b1b 100644
--- a/drivers/s390/crypto/vfio_ap_private.h
+++ b/drivers/s390/crypto/vfio_ap_private.h
@@ -18,6 +18,7 @@
#include <linux/delay.h>
#include <linux/mutex.h>
#include <linux/kvm_host.h>
+#include <linux/vfio.h>
#include "ap_bus.h"
@@ -79,6 +80,7 @@ struct ap_matrix {
* @kvm: the struct holding guest's state
*/
struct ap_matrix_mdev {
+ struct vfio_device vdev;
struct list_head node;
struct ap_matrix matrix;
struct notifier_block group_notifier;
--
2.31.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev()
2021-04-26 20:00 [PATCH v2 00/13] Remove vfio_mdev.c, mdev_parent_ops and more Jason Gunthorpe
2021-04-26 20:00 ` [PATCH v2 01/13] vfio/mdev: Remove CONFIG_VFIO_MDEV_DEVICE Jason Gunthorpe
2021-04-26 20:00 ` [PATCH v2 06/13] vfio/ap_ops: Convert to use vfio_register_group_dev() Jason Gunthorpe
@ 2021-04-26 20:00 ` Jason Gunthorpe
2021-04-27 20:06 ` Eric Farman
2021-04-28 17:09 ` Cornelia Huck
2021-04-26 20:00 ` [PATCH v2 11/13] vfio/mdev: Remove mdev_parent_ops Jason Gunthorpe
2021-04-27 21:30 ` [PATCH v2 00/13] Remove vfio_mdev.c, mdev_parent_ops and more Alex Williamson
4 siblings, 2 replies; 26+ messages in thread
From: Jason Gunthorpe @ 2021-04-26 20:00 UTC (permalink / raw)
To: Christian Borntraeger, Cornelia Huck, Eric Farman, Vasily Gorbik,
Heiko Carstens, kvm, linux-s390, Peter Oberparleiter, Halil Pasic,
Vineeth Vijayan
Cc: Raj, Ashok, Dan Williams, Daniel Vetter, Christoph Hellwig,
Leon Romanovsky, Max Gurtovoy, Tarun Gupta
This is more complicated because vfio_ccw is sharing the vfio_device
between both the mdev_device and its vfio_device and the css_driver.
The mdev is a singleton, and the reason for this sharing appears to be to
allow the extra css_driver function callbacks to be delivered to the
vfio_device.
This keeps things as they were, with the css_driver allocating the
singleton, not the mdev_driver, this is pretty confusing. I'm also
uncertain how the lifetime model for the mdev works in the css_driver
callbacks.
At this point embed the vfio_device in the vfio_ccw_private and
instantiate it as a vfio_device when the mdev probes. The drvdata of both
the css_device and the mdev_device point at the private, and container_of
is used to get it back from the vfio_device.
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
drivers/s390/cio/vfio_ccw_drv.c | 21 +++--
drivers/s390/cio/vfio_ccw_ops.c | 135 +++++++++++++++-------------
drivers/s390/cio/vfio_ccw_private.h | 5 ++
3 files changed, 94 insertions(+), 67 deletions(-)
diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c
index 8c625b530035f5..55c4876dfd139d 100644
--- a/drivers/s390/cio/vfio_ccw_drv.c
+++ b/drivers/s390/cio/vfio_ccw_drv.c
@@ -442,7 +442,7 @@ static int __init vfio_ccw_sch_init(void)
vfio_ccw_work_q = create_singlethread_workqueue("vfio-ccw");
if (!vfio_ccw_work_q) {
ret = -ENOMEM;
- goto out_err;
+ goto out_regions;
}
vfio_ccw_io_region = kmem_cache_create_usercopy("vfio_ccw_io_region",
@@ -451,7 +451,7 @@ static int __init vfio_ccw_sch_init(void)
sizeof(struct ccw_io_region), NULL);
if (!vfio_ccw_io_region) {
ret = -ENOMEM;
- goto out_err;
+ goto out_regions;
}
vfio_ccw_cmd_region = kmem_cache_create_usercopy("vfio_ccw_cmd_region",
@@ -460,7 +460,7 @@ static int __init vfio_ccw_sch_init(void)
sizeof(struct ccw_cmd_region), NULL);
if (!vfio_ccw_cmd_region) {
ret = -ENOMEM;
- goto out_err;
+ goto out_regions;
}
vfio_ccw_schib_region = kmem_cache_create_usercopy("vfio_ccw_schib_region",
@@ -470,7 +470,7 @@ static int __init vfio_ccw_sch_init(void)
if (!vfio_ccw_schib_region) {
ret = -ENOMEM;
- goto out_err;
+ goto out_regions;
}
vfio_ccw_crw_region = kmem_cache_create_usercopy("vfio_ccw_crw_region",
@@ -480,19 +480,25 @@ static int __init vfio_ccw_sch_init(void)
if (!vfio_ccw_crw_region) {
ret = -ENOMEM;
- goto out_err;
+ goto out_regions;
}
+ ret = mdev_register_driver(&vfio_ccw_mdev_driver);
+ if (ret)
+ goto out_regions;
+
isc_register(VFIO_CCW_ISC);
ret = css_driver_register(&vfio_ccw_sch_driver);
if (ret) {
isc_unregister(VFIO_CCW_ISC);
- goto out_err;
+ goto out_driver;
}
return ret;
-out_err:
+out_driver:
+ mdev_unregister_driver(&vfio_ccw_mdev_driver);
+out_regions:
vfio_ccw_destroy_regions();
destroy_workqueue(vfio_ccw_work_q);
vfio_ccw_debug_exit();
@@ -501,6 +507,7 @@ static int __init vfio_ccw_sch_init(void)
static void __exit vfio_ccw_sch_exit(void)
{
+ mdev_unregister_driver(&vfio_ccw_mdev_driver);
css_driver_unregister(&vfio_ccw_sch_driver);
isc_unregister(VFIO_CCW_ISC);
vfio_ccw_destroy_regions();
diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
index 491a64c61fff1a..0fcf46031d3821 100644
--- a/drivers/s390/cio/vfio_ccw_ops.c
+++ b/drivers/s390/cio/vfio_ccw_ops.c
@@ -17,13 +17,13 @@
#include "vfio_ccw_private.h"
-static int vfio_ccw_mdev_reset(struct mdev_device *mdev)
+static const struct vfio_device_ops vfio_ccw_dev_ops;
+
+static int vfio_ccw_mdev_reset(struct vfio_ccw_private *private)
{
- struct vfio_ccw_private *private;
struct subchannel *sch;
int ret;
- private = dev_get_drvdata(mdev_parent_dev(mdev));
sch = private->sch;
/*
* TODO:
@@ -61,7 +61,7 @@ static int vfio_ccw_mdev_notifier(struct notifier_block *nb,
if (!cp_iova_pinned(&private->cp, unmap->iova))
return NOTIFY_OK;
- if (vfio_ccw_mdev_reset(private->mdev))
+ if (vfio_ccw_mdev_reset(private))
return NOTIFY_BAD;
cp_free(&private->cp);
@@ -113,10 +113,11 @@ static struct attribute_group *mdev_type_groups[] = {
NULL,
};
-static int vfio_ccw_mdev_create(struct mdev_device *mdev)
+static int vfio_ccw_mdev_probe(struct mdev_device *mdev)
{
struct vfio_ccw_private *private =
dev_get_drvdata(mdev_parent_dev(mdev));
+ int ret;
if (private->state == VFIO_CCW_STATE_NOT_OPER)
return -ENODEV;
@@ -124,6 +125,10 @@ static int vfio_ccw_mdev_create(struct mdev_device *mdev)
if (atomic_dec_if_positive(&private->avail) < 0)
return -EPERM;
+ memset(&private->vdev, 0, sizeof(private->vdev));
+ vfio_init_group_dev(&private->vdev, &mdev->dev,
+ &vfio_ccw_dev_ops);
+
private->mdev = mdev;
private->state = VFIO_CCW_STATE_IDLE;
@@ -132,19 +137,28 @@ static int vfio_ccw_mdev_create(struct mdev_device *mdev)
private->sch->schid.ssid,
private->sch->schid.sch_no);
+ ret = vfio_register_group_dev(&private->vdev);
+ if (ret)
+ goto err_atomic;
+ dev_set_drvdata(&mdev->dev, private);
return 0;
+
+err_atomic:
+ atomic_inc(&private->avail);
+ return ret;
}
-static int vfio_ccw_mdev_remove(struct mdev_device *mdev)
+static void vfio_ccw_mdev_remove(struct mdev_device *mdev)
{
- struct vfio_ccw_private *private =
- dev_get_drvdata(mdev_parent_dev(mdev));
+ struct vfio_ccw_private *private = dev_get_drvdata(&mdev->dev);
VFIO_CCW_MSG_EVENT(2, "mdev %pUl, sch %x.%x.%04x: remove\n",
mdev_uuid(mdev), private->sch->schid.cssid,
private->sch->schid.ssid,
private->sch->schid.sch_no);
+ vfio_unregister_group_dev(&private->vdev);
+
if ((private->state != VFIO_CCW_STATE_NOT_OPER) &&
(private->state != VFIO_CCW_STATE_STANDBY)) {
if (!vfio_ccw_sch_quiesce(private->sch))
@@ -155,20 +169,18 @@ static int vfio_ccw_mdev_remove(struct mdev_device *mdev)
cp_free(&private->cp);
private->mdev = NULL;
atomic_inc(&private->avail);
-
- return 0;
}
-static int vfio_ccw_mdev_open(struct mdev_device *mdev)
+static int vfio_ccw_mdev_open(struct vfio_device *vdev)
{
struct vfio_ccw_private *private =
- dev_get_drvdata(mdev_parent_dev(mdev));
+ container_of(vdev, struct vfio_ccw_private, vdev);
unsigned long events = VFIO_IOMMU_NOTIFY_DMA_UNMAP;
int ret;
private->nb.notifier_call = vfio_ccw_mdev_notifier;
- ret = vfio_register_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY,
+ ret = vfio_register_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,
&events, &private->nb);
if (ret)
return ret;
@@ -189,27 +201,26 @@ static int vfio_ccw_mdev_open(struct mdev_device *mdev)
out_unregister:
vfio_ccw_unregister_dev_regions(private);
- vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY,
+ vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,
&private->nb);
return ret;
}
-static void vfio_ccw_mdev_release(struct mdev_device *mdev)
+static void vfio_ccw_mdev_release(struct vfio_device *vdev)
{
struct vfio_ccw_private *private =
- dev_get_drvdata(mdev_parent_dev(mdev));
+ container_of(vdev, struct vfio_ccw_private, vdev);
if ((private->state != VFIO_CCW_STATE_NOT_OPER) &&
(private->state != VFIO_CCW_STATE_STANDBY)) {
- if (!vfio_ccw_mdev_reset(mdev))
+ if (!vfio_ccw_mdev_reset(private))
private->state = VFIO_CCW_STATE_STANDBY;
/* The state will be NOT_OPER on error. */
}
cp_free(&private->cp);
vfio_ccw_unregister_dev_regions(private);
- vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY,
- &private->nb);
+ vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY, &private->nb);
}
static ssize_t vfio_ccw_mdev_read_io_region(struct vfio_ccw_private *private,
@@ -233,15 +244,14 @@ static ssize_t vfio_ccw_mdev_read_io_region(struct vfio_ccw_private *private,
return ret;
}
-static ssize_t vfio_ccw_mdev_read(struct mdev_device *mdev,
+static ssize_t vfio_ccw_mdev_read(struct vfio_device *vdev,
char __user *buf,
size_t count,
loff_t *ppos)
{
+ struct vfio_ccw_private *private =
+ container_of(vdev, struct vfio_ccw_private, vdev);
unsigned int index = VFIO_CCW_OFFSET_TO_INDEX(*ppos);
- struct vfio_ccw_private *private;
-
- private = dev_get_drvdata(mdev_parent_dev(mdev));
if (index >= VFIO_CCW_NUM_REGIONS + private->num_regions)
return -EINVAL;
@@ -288,15 +298,14 @@ static ssize_t vfio_ccw_mdev_write_io_region(struct vfio_ccw_private *private,
return ret;
}
-static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev,
+static ssize_t vfio_ccw_mdev_write(struct vfio_device *vdev,
const char __user *buf,
size_t count,
loff_t *ppos)
{
+ struct vfio_ccw_private *private =
+ container_of(vdev, struct vfio_ccw_private, vdev);
unsigned int index = VFIO_CCW_OFFSET_TO_INDEX(*ppos);
- struct vfio_ccw_private *private;
-
- private = dev_get_drvdata(mdev_parent_dev(mdev));
if (index >= VFIO_CCW_NUM_REGIONS + private->num_regions)
return -EINVAL;
@@ -313,12 +322,9 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev,
return -EINVAL;
}
-static int vfio_ccw_mdev_get_device_info(struct vfio_device_info *info,
- struct mdev_device *mdev)
+static int vfio_ccw_mdev_get_device_info(struct vfio_ccw_private *private,
+ struct vfio_device_info *info)
{
- struct vfio_ccw_private *private;
-
- private = dev_get_drvdata(mdev_parent_dev(mdev));
info->flags = VFIO_DEVICE_FLAGS_CCW | VFIO_DEVICE_FLAGS_RESET;
info->num_regions = VFIO_CCW_NUM_REGIONS + private->num_regions;
info->num_irqs = VFIO_CCW_NUM_IRQS;
@@ -326,14 +332,12 @@ static int vfio_ccw_mdev_get_device_info(struct vfio_device_info *info,
return 0;
}
-static int vfio_ccw_mdev_get_region_info(struct vfio_region_info *info,
- struct mdev_device *mdev,
+static int vfio_ccw_mdev_get_region_info(struct vfio_ccw_private *private,
+ struct vfio_region_info *info,
unsigned long arg)
{
- struct vfio_ccw_private *private;
int i;
- private = dev_get_drvdata(mdev_parent_dev(mdev));
switch (info->index) {
case VFIO_CCW_CONFIG_REGION_INDEX:
info->offset = 0;
@@ -408,19 +412,16 @@ static int vfio_ccw_mdev_get_irq_info(struct vfio_irq_info *info)
return 0;
}
-static int vfio_ccw_mdev_set_irqs(struct mdev_device *mdev,
+static int vfio_ccw_mdev_set_irqs(struct vfio_ccw_private *private,
uint32_t flags,
uint32_t index,
void __user *data)
{
- struct vfio_ccw_private *private;
struct eventfd_ctx **ctx;
if (!(flags & VFIO_IRQ_SET_ACTION_TRIGGER))
return -EINVAL;
- private = dev_get_drvdata(mdev_parent_dev(mdev));
-
switch (index) {
case VFIO_CCW_IO_IRQ_INDEX:
ctx = &private->io_trigger;
@@ -522,10 +523,12 @@ void vfio_ccw_unregister_dev_regions(struct vfio_ccw_private *private)
private->region = NULL;
}
-static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev,
+static ssize_t vfio_ccw_mdev_ioctl(struct vfio_device *vdev,
unsigned int cmd,
unsigned long arg)
{
+ struct vfio_ccw_private *private =
+ container_of(vdev, struct vfio_ccw_private, vdev);
int ret = 0;
unsigned long minsz;
@@ -542,7 +545,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev,
if (info.argsz < minsz)
return -EINVAL;
- ret = vfio_ccw_mdev_get_device_info(&info, mdev);
+ ret = vfio_ccw_mdev_get_device_info(private, &info);
if (ret)
return ret;
@@ -560,7 +563,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev,
if (info.argsz < minsz)
return -EINVAL;
- ret = vfio_ccw_mdev_get_region_info(&info, mdev, arg);
+ ret = vfio_ccw_mdev_get_region_info(private, &info, arg);
if (ret)
return ret;
@@ -605,47 +608,59 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev,
return ret;
data = (void __user *)(arg + minsz);
- return vfio_ccw_mdev_set_irqs(mdev, hdr.flags, hdr.index, data);
+ return vfio_ccw_mdev_set_irqs(private, hdr.flags, hdr.index,
+ data);
}
case VFIO_DEVICE_RESET:
- return vfio_ccw_mdev_reset(mdev);
+ return vfio_ccw_mdev_reset(private);
default:
return -ENOTTY;
}
}
/* Request removal of the device*/
-static void vfio_ccw_mdev_request(struct mdev_device *mdev, unsigned int count)
+static void vfio_ccw_mdev_request(struct vfio_device *vdev, unsigned int count)
{
- struct vfio_ccw_private *private = dev_get_drvdata(mdev_parent_dev(mdev));
-
- if (!private)
- return;
+ struct vfio_ccw_private *private =
+ container_of(vdev, struct vfio_ccw_private, vdev);
+ struct device *dev = private->vdev.dev;
if (private->req_trigger) {
if (!(count % 10))
- dev_notice_ratelimited(mdev_dev(private->mdev),
+ dev_notice_ratelimited(dev,
"Relaying device request to user (#%u)\n",
count);
eventfd_signal(private->req_trigger, 1);
} else if (count == 0) {
- dev_notice(mdev_dev(private->mdev),
+ dev_notice(dev,
"No device request channel registered, blocked until released by user\n");
}
}
+static const struct vfio_device_ops vfio_ccw_dev_ops = {
+ .open = vfio_ccw_mdev_open,
+ .release = vfio_ccw_mdev_release,
+ .read = vfio_ccw_mdev_read,
+ .write = vfio_ccw_mdev_write,
+ .ioctl = vfio_ccw_mdev_ioctl,
+ .request = vfio_ccw_mdev_request,
+};
+
+struct mdev_driver vfio_ccw_mdev_driver = {
+ .driver = {
+ .name = "vfio_ccw_mdev",
+ .owner = THIS_MODULE,
+ .mod_name = KBUILD_MODNAME,
+ },
+ .probe = vfio_ccw_mdev_probe,
+ .remove = vfio_ccw_mdev_remove,
+};
+
static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
.owner = THIS_MODULE,
+ .device_driver = &vfio_ccw_mdev_driver,
.supported_type_groups = mdev_type_groups,
- .create = vfio_ccw_mdev_create,
- .remove = vfio_ccw_mdev_remove,
- .open = vfio_ccw_mdev_open,
- .release = vfio_ccw_mdev_release,
- .read = vfio_ccw_mdev_read,
- .write = vfio_ccw_mdev_write,
- .ioctl = vfio_ccw_mdev_ioctl,
- .request = vfio_ccw_mdev_request,
};
int vfio_ccw_mdev_reg(struct subchannel *sch)
diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h
index b2c762eb42b9bb..7272eb78861244 100644
--- a/drivers/s390/cio/vfio_ccw_private.h
+++ b/drivers/s390/cio/vfio_ccw_private.h
@@ -17,6 +17,7 @@
#include <linux/eventfd.h>
#include <linux/workqueue.h>
#include <linux/vfio_ccw.h>
+#include <linux/vfio.h>
#include <asm/crw.h>
#include <asm/debug.h>
@@ -67,6 +68,7 @@ struct vfio_ccw_crw {
/**
* struct vfio_ccw_private
+ * @vdev: Embedded VFIO device
* @sch: pointer to the subchannel
* @state: internal state of the device
* @completion: synchronization helper of the I/O completion
@@ -90,6 +92,7 @@ struct vfio_ccw_crw {
* @crw_work: work for deferral process of CRW handling
*/
struct vfio_ccw_private {
+ struct vfio_device vdev;
struct subchannel *sch;
int state;
struct completion *completion;
@@ -121,6 +124,8 @@ extern void vfio_ccw_mdev_unreg(struct subchannel *sch);
extern int vfio_ccw_sch_quiesce(struct subchannel *sch);
+extern struct mdev_driver vfio_ccw_mdev_driver;
+
/*
* States of the device statemachine.
*/
--
2.31.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v2 11/13] vfio/mdev: Remove mdev_parent_ops
2021-04-26 20:00 [PATCH v2 00/13] Remove vfio_mdev.c, mdev_parent_ops and more Jason Gunthorpe
` (2 preceding siblings ...)
2021-04-26 20:00 ` [PATCH v2 07/13] vfio/ccw: " Jason Gunthorpe
@ 2021-04-26 20:00 ` Jason Gunthorpe
2021-04-27 21:30 ` [PATCH v2 00/13] Remove vfio_mdev.c, mdev_parent_ops and more Alex Williamson
4 siblings, 0 replies; 26+ messages in thread
From: Jason Gunthorpe @ 2021-04-26 20:00 UTC (permalink / raw)
To: David Airlie, Tony Krowiak, Alex Williamson,
Christian Borntraeger, Cornelia Huck, Jonathan Corbet,
Daniel Vetter, dri-devel, Eric Farman, Harald Freudenberger,
Vasily Gorbik, Heiko Carstens, intel-gfx, intel-gvt-dev,
Jani Nikula, Joonas Lahtinen, kvm, Kirti Wankhede, linux-doc,
linux-s390, Peter Oberparleiter, Halil Pasic, Pierre Morel,
Rodrigo Vivi, Vineeth Vijayan, Zhenyu Wang, Zhi Wang
Cc: Raj, Ashok, Dan Williams, Christoph Hellwig, Leon Romanovsky,
Max Gurtovoy, Tarun Gupta
The last useful member in this struct is the supported_type_groups, move
it to the mdev_driver and delete mdev_parent_ops.
Replace it with mdev_driver as an argument to mdev_register_device()
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
.../driver-api/vfio-mediated-device.rst | 37 +++++++------------
drivers/gpu/drm/i915/gvt/kvmgt.c | 8 +---
drivers/s390/cio/vfio_ccw_ops.c | 7 +---
drivers/s390/crypto/vfio_ap_ops.c | 9 +----
drivers/vfio/mdev/mdev_core.c | 13 +++----
drivers/vfio/mdev/mdev_driver.c | 2 +-
drivers/vfio/mdev/mdev_private.h | 2 +-
drivers/vfio/mdev/mdev_sysfs.c | 6 +--
include/linux/mdev.h | 24 ++----------
samples/vfio-mdev/mbochs.c | 9 +----
samples/vfio-mdev/mdpy.c | 9 +----
samples/vfio-mdev/mtty.c | 9 +----
12 files changed, 39 insertions(+), 96 deletions(-)
diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst
index 5f866b17c93e69..a073d0bb06e7fd 100644
--- a/Documentation/driver-api/vfio-mediated-device.rst
+++ b/Documentation/driver-api/vfio-mediated-device.rst
@@ -93,7 +93,7 @@ interfaces:
Registration Interface for a Mediated Bus Driver
------------------------------------------------
-The registration interface for a mediated bus driver provides the following
+The registration interface for a mediated device driver provides the following
structure to represent a mediated device's driver::
/*
@@ -105,6 +105,7 @@ structure to represent a mediated device's driver::
struct mdev_driver {
int (*probe) (struct mdev_device *dev);
void (*remove) (struct mdev_device *dev);
+ struct attribute_group **supported_type_groups;
struct device_driver driver;
};
@@ -119,35 +120,25 @@ to register and unregister itself with the core driver:
extern void mdev_unregister_driver(struct mdev_driver *drv);
-The mediated bus driver is responsible for adding mediated devices to the VFIO
-group when devices are bound to the driver and removing mediated devices from
-the VFIO when devices are unbound from the driver.
+The mediated bus driver's probe function should create a vfio_device on top of
+the mdev_device and connect it to an appropriate implementation of
+vfio_device_ops.
-
-Physical Device Driver Interface
---------------------------------
-
-The physical device driver interface provides the mdev_parent_ops[3] structure
-to define the APIs to manage work in the mediated core driver that is related
-to the physical device.
-
-The structures in the mdev_parent_ops structure are as follows:
-
-* dev_attr_groups: attributes of the parent device
-* mdev_attr_groups: attributes of the mediated device
-* supported_config: attributes to define supported configurations
-
-A driver should use the mdev_parent_ops structure in the function call to
-register itself with the mdev core driver::
+When a driver wants to add the GUID creation sysfs to an existing device it has
+probe'd to then it should call:
extern int mdev_register_device(struct device *dev,
- const struct mdev_parent_ops *ops);
+ struct mdev_driver *mdev_driver);
+
+This will provide the 'mdev_supported_types/XX/create' files which can then be
+used to trigger the creation of a mdev_device. The created mdev_device will be
+attached to the specified driver.
-However, the mdev_parent_ops structure is not required in the function call
-that a driver should use to unregister itself with the mdev core driver::
+When the driver needs to remove itself it calls:
extern void mdev_unregister_device(struct device *dev);
+Which will unbind and destroy all the created mdevs and remove the sysfs files.
Mediated Device Management Interface Through sysfs
==================================================
diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index 85ef300087e091..02089efd15bb92 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -1669,10 +1669,6 @@ static struct mdev_driver intel_vgpu_mdev_driver = {
.remove = intel_vgpu_remove,
};
-static struct mdev_parent_ops intel_vgpu_ops = {
- .device_driver = &intel_vgpu_mdev_driver,
-};
-
static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)
{
struct attribute_group **kvm_vgpu_type_groups;
@@ -1680,9 +1676,9 @@ static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)
intel_gvt_ops = ops;
if (!intel_gvt_ops->get_gvt_attrs(&kvm_vgpu_type_groups))
return -EFAULT;
- intel_vgpu_ops.supported_type_groups = kvm_vgpu_type_groups;
+ intel_vgpu_mdev_driver.supported_type_groups = kvm_vgpu_type_groups;
- return mdev_register_device(dev, &intel_vgpu_ops);
+ return mdev_register_device(dev, &intel_vgpu_mdev_driver);
}
static void kvmgt_host_exit(struct device *dev)
diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
index 0fcf46031d3821..161697529dcc41 100644
--- a/drivers/s390/cio/vfio_ccw_ops.c
+++ b/drivers/s390/cio/vfio_ccw_ops.c
@@ -655,17 +655,12 @@ struct mdev_driver vfio_ccw_mdev_driver = {
},
.probe = vfio_ccw_mdev_probe,
.remove = vfio_ccw_mdev_remove,
-};
-
-static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
- .owner = THIS_MODULE,
- .device_driver = &vfio_ccw_mdev_driver,
.supported_type_groups = mdev_type_groups,
};
int vfio_ccw_mdev_reg(struct subchannel *sch)
{
- return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops);
+ return mdev_register_device(&sch->dev, &vfio_ccw_mdev_driver);
}
void vfio_ccw_mdev_unreg(struct subchannel *sch)
diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
index 79872c857dd522..92789257c87639 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -1339,12 +1339,7 @@ static struct mdev_driver vfio_ap_matrix_driver = {
},
.probe = vfio_ap_mdev_probe,
.remove = vfio_ap_mdev_remove,
-};
-
-static const struct mdev_parent_ops vfio_ap_matrix_ops = {
- .owner = THIS_MODULE,
- .device_driver = &vfio_ap_matrix_driver,
- .supported_type_groups = vfio_ap_mdev_type_groups,
+ .supported_type_groups = vfio_ap_mdev_type_groups,
};
int vfio_ap_mdev_register(void)
@@ -1357,7 +1352,7 @@ int vfio_ap_mdev_register(void)
if (ret)
return ret;
- ret = mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_ops);
+ ret = mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_driver);
if (ret)
goto err_driver;
return 0;
diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index d507047e6ecf4a..cd1ab9fe299445 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -109,12 +109,12 @@ static int mdev_device_remove_cb(struct device *dev, void *data)
/*
* mdev_register_device : Register a device
* @dev: device structure representing parent device.
- * @ops: Parent device operation structure to be registered.
+ * @mdev_driver: Device driver to bind to the newly created mdev
*
* Add device to list of registered parent devices.
* Returns a negative value on error, otherwise 0.
*/
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
+int mdev_register_device(struct device *dev, struct mdev_driver *mdev_driver)
{
int ret;
struct mdev_parent *parent;
@@ -122,9 +122,7 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
char *envp[] = { env_string, NULL };
/* check for mandatory ops */
- if (!ops || !ops->supported_type_groups)
- return -EINVAL;
- if (!ops->device_driver)
+ if (!mdev_driver->supported_type_groups)
return -EINVAL;
dev = get_device(dev);
@@ -151,7 +149,7 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
init_rwsem(&parent->unreg_sem);
parent->dev = dev;
- parent->ops = ops;
+ parent->mdev_driver = mdev_driver;
if (!mdev_bus_compat_class) {
mdev_bus_compat_class = class_compat_register("mdev_bus");
@@ -257,7 +255,7 @@ static int mdev_bind_driver(struct mdev_device *mdev)
while (1) {
device_lock(&mdev->dev);
if (mdev->dev.driver ==
- &mdev->type->parent->ops->device_driver->driver) {
+ &mdev->type->parent->mdev_driver->driver) {
ret = 0;
goto out_unlock;
}
@@ -304,7 +302,6 @@ int mdev_device_create(struct mdev_type *type, const guid_t *uuid)
mdev->dev.parent = parent->dev;
mdev->dev.bus = &mdev_bus_type;
mdev->dev.release = mdev_device_release;
- mdev->dev.groups = parent->ops->mdev_attr_groups;
mdev->type = type;
/* Pairs with the put in mdev_device_release() */
kobject_get(&type->kobj);
diff --git a/drivers/vfio/mdev/mdev_driver.c b/drivers/vfio/mdev/mdev_driver.c
index 07ada55efd6228..d743a9f51f4c90 100644
--- a/drivers/vfio/mdev/mdev_driver.c
+++ b/drivers/vfio/mdev/mdev_driver.c
@@ -75,7 +75,7 @@ static int mdev_match(struct device *dev, struct device_driver *drv)
{
struct mdev_device *mdev = to_mdev_device(dev);
- return drv == &mdev->type->parent->ops->device_driver->driver;
+ return drv == &mdev->type->parent->mdev_driver->driver;
}
struct bus_type mdev_bus_type = {
diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h
index a656cfe0346c33..839567d059a07d 100644
--- a/drivers/vfio/mdev/mdev_private.h
+++ b/drivers/vfio/mdev/mdev_private.h
@@ -15,7 +15,7 @@ void mdev_bus_unregister(void);
struct mdev_parent {
struct device *dev;
- const struct mdev_parent_ops *ops;
+ const struct mdev_driver *mdev_driver;
struct kref ref;
struct list_head next;
struct kset *mdev_types_kset;
diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
index 66eef08833a4ef..5a3873d1a275ae 100644
--- a/drivers/vfio/mdev/mdev_sysfs.c
+++ b/drivers/vfio/mdev/mdev_sysfs.c
@@ -97,7 +97,7 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent,
{
struct mdev_type *type;
struct attribute_group *group =
- parent->ops->supported_type_groups[type_group_id];
+ parent->mdev_driver->supported_type_groups[type_group_id];
int ret;
if (!group->name) {
@@ -154,7 +154,7 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent,
static void remove_mdev_supported_type(struct mdev_type *type)
{
struct attribute_group *group =
- type->parent->ops->supported_type_groups[type->type_group_id];
+ type->parent->mdev_driver->supported_type_groups[type->type_group_id];
sysfs_remove_files(&type->kobj,
(const struct attribute **)group->attrs);
@@ -168,7 +168,7 @@ static int add_mdev_supported_type_groups(struct mdev_parent *parent)
{
int i;
- for (i = 0; parent->ops->supported_type_groups[i]; i++) {
+ for (i = 0; parent->mdev_driver->supported_type_groups[i]; i++) {
struct mdev_type *type;
type = add_mdev_supported_type(parent, i);
diff --git a/include/linux/mdev.h b/include/linux/mdev.h
index fd9fe1dcf0e230..af807c77c1e0f5 100644
--- a/include/linux/mdev.h
+++ b/include/linux/mdev.h
@@ -51,25 +51,6 @@ unsigned int mdev_get_type_group_id(struct mdev_device *mdev);
unsigned int mtype_get_type_group_id(struct mdev_type *mtype);
struct device *mtype_get_parent_dev(struct mdev_type *mtype);
-/**
- * struct mdev_parent_ops - Structure to be registered for each parent device to
- * register the device to mdev module.
- *
- * @owner: The module owner.
- * @device_driver: Which device driver to probe() on newly created devices
- * @mdev_attr_groups: Attributes of the mediated device.
- * @supported_type_groups: Attributes to define supported types. It is mandatory
- * to provide supported types.
- * Parent device that support mediated device should be registered with mdev
- * module with mdev_parent_ops structure.
- **/
-struct mdev_parent_ops {
- struct module *owner;
- struct mdev_driver *device_driver;
- const struct attribute_group **mdev_attr_groups;
- struct attribute_group **supported_type_groups;
-};
-
/* interface for exporting mdev supported type attributes */
struct mdev_type_attribute {
struct attribute attr;
@@ -94,12 +75,15 @@ struct mdev_type_attribute mdev_type_attr_##_name = \
* struct mdev_driver - Mediated device driver
* @probe: called when new device created
* @remove: called when device removed
+ * @supported_type_groups: Attributes to define supported types. It is mandatory
+ * to provide supported types.
* @driver: device driver structure
*
**/
struct mdev_driver {
int (*probe)(struct mdev_device *dev);
void (*remove)(struct mdev_device *dev);
+ struct attribute_group **supported_type_groups;
struct device_driver driver;
};
@@ -118,7 +102,7 @@ static inline const guid_t *mdev_uuid(struct mdev_device *mdev)
extern struct bus_type mdev_bus_type;
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops);
+int mdev_register_device(struct device *dev, struct mdev_driver *mdev_driver);
void mdev_unregister_device(struct device *dev);
int mdev_register_driver(struct mdev_driver *drv);
diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c
index e18821a8a6beb8..c76ceec584b41b 100644
--- a/samples/vfio-mdev/mbochs.c
+++ b/samples/vfio-mdev/mbochs.c
@@ -1418,12 +1418,7 @@ static struct mdev_driver mbochs_driver = {
},
.probe = mbochs_probe,
.remove = mbochs_remove,
-};
-
-static const struct mdev_parent_ops mdev_fops = {
- .owner = THIS_MODULE,
- .device_driver = &mbochs_driver,
- .supported_type_groups = mdev_type_groups,
+ .supported_type_groups = mdev_type_groups,
};
static const struct file_operations vd_fops = {
@@ -1466,7 +1461,7 @@ static int __init mbochs_dev_init(void)
if (ret)
goto err_class;
- ret = mdev_register_device(&mbochs_dev, &mdev_fops);
+ ret = mdev_register_device(&mbochs_dev, &mbochs_driver);
if (ret)
goto err_device;
diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c
index 82638de333330d..c22b2c808d132d 100644
--- a/samples/vfio-mdev/mdpy.c
+++ b/samples/vfio-mdev/mdpy.c
@@ -735,12 +735,7 @@ static struct mdev_driver mdpy_driver = {
},
.probe = mdpy_probe,
.remove = mdpy_remove,
-};
-
-static const struct mdev_parent_ops mdev_fops = {
- .owner = THIS_MODULE,
- .device_driver = &mdpy_driver,
- .supported_type_groups = mdev_type_groups,
+ .supported_type_groups = mdev_type_groups,
};
static const struct file_operations vd_fops = {
@@ -783,7 +778,7 @@ static int __init mdpy_dev_init(void)
if (ret)
goto err_class;
- ret = mdev_register_device(&mdpy_dev, &mdev_fops);
+ ret = mdev_register_device(&mdpy_dev, &mdpy_driver);
if (ret)
goto err_device;
diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c
index 31eec76bc553ce..87f5ba12a230e3 100644
--- a/samples/vfio-mdev/mtty.c
+++ b/samples/vfio-mdev/mtty.c
@@ -1308,12 +1308,7 @@ static struct mdev_driver mtty_driver = {
},
.probe = mtty_probe,
.remove = mtty_remove,
-};
-
-static const struct mdev_parent_ops mdev_fops = {
- .owner = THIS_MODULE,
- .device_driver = &mtty_driver,
- .supported_type_groups = mdev_type_groups,
+ .supported_type_groups = mdev_type_groups,
};
static void mtty_device_release(struct device *dev)
@@ -1364,7 +1359,7 @@ static int __init mtty_dev_init(void)
if (ret)
goto err_class;
- ret = mdev_register_device(&mtty_dev.dev, &mdev_fops);
+ ret = mdev_register_device(&mtty_dev.dev, &mtty_driver);
if (ret)
goto err_device;
--
2.31.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v2 01/13] vfio/mdev: Remove CONFIG_VFIO_MDEV_DEVICE
2021-04-26 20:00 ` [PATCH v2 01/13] vfio/mdev: Remove CONFIG_VFIO_MDEV_DEVICE Jason Gunthorpe
@ 2021-04-27 11:05 ` Cornelia Huck
0 siblings, 0 replies; 26+ messages in thread
From: Cornelia Huck @ 2021-04-27 11:05 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: David Airlie, Tony Krowiak, Alex Williamson,
Christian Borntraeger, Jonathan Corbet, Daniel Vetter, dri-devel,
Vasily Gorbik, Heiko Carstens, intel-gfx, Jani Nikula,
Joonas Lahtinen, kvm, Kirti Wankhede, linux-doc, linux-s390,
Halil Pasic, Pierre Morel, Rodrigo Vivi, Raj, Ashok, Dan Williams,
Christoph Hellwig, Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Mon, 26 Apr 2021 17:00:03 -0300
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(-)
This also fixes the dependencies for vfio-ccw, which never depended on
VFIO_MDEV_DEVICE directly...
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev()
2021-04-26 20:00 ` [PATCH v2 07/13] vfio/ccw: " Jason Gunthorpe
@ 2021-04-27 20:06 ` Eric Farman
2021-04-27 22:10 ` Jason Gunthorpe
2021-04-28 17:09 ` Cornelia Huck
1 sibling, 1 reply; 26+ messages in thread
From: Eric Farman @ 2021-04-27 20:06 UTC (permalink / raw)
To: Jason Gunthorpe, Christian Borntraeger, Cornelia Huck,
Vasily Gorbik, Heiko Carstens, kvm, linux-s390,
Peter Oberparleiter, Halil Pasic, Vineeth Vijayan
Cc: Raj, Ashok, Dan Williams, Daniel Vetter, Christoph Hellwig,
Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Mon, 2021-04-26 at 17:00 -0300, Jason Gunthorpe wrote:
> This is more complicated because vfio_ccw is sharing the vfio_device
> between both the mdev_device and its vfio_device and the css_driver.
>
> The mdev is a singleton, and the reason for this sharing appears to
> be to
> allow the extra css_driver function callbacks to be delivered to the
> vfio_device.
>
> This keeps things as they were, with the css_driver allocating the
> singleton, not the mdev_driver, this is pretty confusing. I'm also
> uncertain how the lifetime model for the mdev works in the css_driver
> callbacks.
>
> At this point embed the vfio_device in the vfio_ccw_private and
> instantiate it as a vfio_device when the mdev probes. The drvdata of
> both
> the css_device and the mdev_device point at the private, and
> container_of
> is used to get it back from the vfio_device.
>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
> drivers/s390/cio/vfio_ccw_drv.c | 21 +++--
> drivers/s390/cio/vfio_ccw_ops.c | 135 +++++++++++++++-----------
> --
> drivers/s390/cio/vfio_ccw_private.h | 5 ++
> 3 files changed, 94 insertions(+), 67 deletions(-)
>
>
...snip...
> diff --git a/drivers/s390/cio/vfio_ccw_ops.c
> b/drivers/s390/cio/vfio_ccw_ops.c
> index 491a64c61fff1a..0fcf46031d3821 100644
> --- a/drivers/s390/cio/vfio_ccw_ops.c
> +++ b/drivers/s390/cio/vfio_ccw_ops.c
> @@ -17,13 +17,13 @@
>
> #include "vfio_ccw_private.h"
>
> -static int vfio_ccw_mdev_reset(struct mdev_device *mdev)
> +static const struct vfio_device_ops vfio_ccw_dev_ops;
> +
> +static int vfio_ccw_mdev_reset(struct vfio_ccw_private *private)
> {
> - struct vfio_ccw_private *private;
> struct subchannel *sch;
> int ret;
>
> - private = dev_get_drvdata(mdev_parent_dev(mdev));
> sch = private->sch;
> /*
> * TODO:
> @@ -61,7 +61,7 @@ static int vfio_ccw_mdev_notifier(struct
> notifier_block *nb,
> if (!cp_iova_pinned(&private->cp, unmap->iova))
> return NOTIFY_OK;
>
> - if (vfio_ccw_mdev_reset(private->mdev))
> + if (vfio_ccw_mdev_reset(private))
> return NOTIFY_BAD;
>
> cp_free(&private->cp);
> @@ -113,10 +113,11 @@ static struct attribute_group
> *mdev_type_groups[] = {
> NULL,
> };
>
> -static int vfio_ccw_mdev_create(struct mdev_device *mdev)
> +static int vfio_ccw_mdev_probe(struct mdev_device *mdev)
> {
> struct vfio_ccw_private *private =
> dev_get_drvdata(mdev_parent_dev(mdev));
> + int ret;
>
> if (private->state == VFIO_CCW_STATE_NOT_OPER)
> return -ENODEV;
> @@ -124,6 +125,10 @@ static int vfio_ccw_mdev_create(struct
> mdev_device *mdev)
> if (atomic_dec_if_positive(&private->avail) < 0)
> return -EPERM;
>
> + memset(&private->vdev, 0, sizeof(private->vdev));
> + vfio_init_group_dev(&private->vdev, &mdev->dev,
> + &vfio_ccw_dev_ops);
> +
> private->mdev = mdev;
> private->state = VFIO_CCW_STATE_IDLE;
>
> @@ -132,19 +137,28 @@ static int vfio_ccw_mdev_create(struct
> mdev_device *mdev)
> private->sch->schid.ssid,
> private->sch->schid.sch_no);
>
> + ret = vfio_register_group_dev(&private->vdev);
> + if (ret)
> + goto err_atomic;
> + dev_set_drvdata(&mdev->dev, private);
> return 0;
> +
> +err_atomic:
> + atomic_inc(&private->avail);
Since we're unwinding, should also do
private->mdev = NULL
private->state = VFIO_CCW_STATE_STANDBY
> + return ret;
> }
>
> -static int vfio_ccw_mdev_remove(struct mdev_device *mdev)
> +static void vfio_ccw_mdev_remove(struct mdev_device *mdev)
> {
> - struct vfio_ccw_private *private =
> - dev_get_drvdata(mdev_parent_dev(mdev));
> + struct vfio_ccw_private *private = dev_get_drvdata(&mdev->dev);
>
> VFIO_CCW_MSG_EVENT(2, "mdev %pUl, sch %x.%x.%04x: remove\n",
> mdev_uuid(mdev), private->sch->schid.cssid,
> private->sch->schid.ssid,
> private->sch->schid.sch_no);
>
> + vfio_unregister_group_dev(&private->vdev);
> +
> if ((private->state != VFIO_CCW_STATE_NOT_OPER) &&
> (private->state != VFIO_CCW_STATE_STANDBY)) {
> if (!vfio_ccw_sch_quiesce(private->sch))
> @@ -155,20 +169,18 @@ static int vfio_ccw_mdev_remove(struct
> mdev_device *mdev)
> cp_free(&private->cp);
> private->mdev = NULL;
> atomic_inc(&private->avail);
> -
> - return 0;
> }
>
> -static int vfio_ccw_mdev_open(struct mdev_device *mdev)
> +static int vfio_ccw_mdev_open(struct vfio_device *vdev)
> {
> struct vfio_ccw_private *private =
> - dev_get_drvdata(mdev_parent_dev(mdev));
> + container_of(vdev, struct vfio_ccw_private, vdev);
> unsigned long events = VFIO_IOMMU_NOTIFY_DMA_UNMAP;
> int ret;
>
> private->nb.notifier_call = vfio_ccw_mdev_notifier;
>
> - ret = vfio_register_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY,
> + ret = vfio_register_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,
> &events, &private->nb);
> if (ret)
> return ret;
> @@ -189,27 +201,26 @@ static int vfio_ccw_mdev_open(struct
> mdev_device *mdev)
>
> out_unregister:
> vfio_ccw_unregister_dev_regions(private);
> - vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY,
> + vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,
> &private->nb);
> return ret;
> }
>
> -static void vfio_ccw_mdev_release(struct mdev_device *mdev)
> +static void vfio_ccw_mdev_release(struct vfio_device *vdev)
> {
> struct vfio_ccw_private *private =
> - dev_get_drvdata(mdev_parent_dev(mdev));
> + container_of(vdev, struct vfio_ccw_private, vdev);
>
> if ((private->state != VFIO_CCW_STATE_NOT_OPER) &&
> (private->state != VFIO_CCW_STATE_STANDBY)) {
> - if (!vfio_ccw_mdev_reset(mdev))
> + if (!vfio_ccw_mdev_reset(private))
> private->state = VFIO_CCW_STATE_STANDBY;
> /* The state will be NOT_OPER on error. */
> }
>
> cp_free(&private->cp);
> vfio_ccw_unregister_dev_regions(private);
> - vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY,
> - &private->nb);
> + vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,
> &private->nb);
> }
>
> static ssize_t vfio_ccw_mdev_read_io_region(struct vfio_ccw_private
> *private,
> @@ -233,15 +244,14 @@ static ssize_t
> vfio_ccw_mdev_read_io_region(struct vfio_ccw_private *private,
> return ret;
> }
>
> -static ssize_t vfio_ccw_mdev_read(struct mdev_device *mdev,
> +static ssize_t vfio_ccw_mdev_read(struct vfio_device *vdev,
> char __user *buf,
> size_t count,
> loff_t *ppos)
> {
> + struct vfio_ccw_private *private =
> + container_of(vdev, struct vfio_ccw_private, vdev);
> unsigned int index = VFIO_CCW_OFFSET_TO_INDEX(*ppos);
> - struct vfio_ccw_private *private;
> -
> - private = dev_get_drvdata(mdev_parent_dev(mdev));
>
> if (index >= VFIO_CCW_NUM_REGIONS + private->num_regions)
> return -EINVAL;
> @@ -288,15 +298,14 @@ static ssize_t
> vfio_ccw_mdev_write_io_region(struct vfio_ccw_private *private,
> return ret;
> }
>
> -static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev,
> +static ssize_t vfio_ccw_mdev_write(struct vfio_device *vdev,
> const char __user *buf,
> size_t count,
> loff_t *ppos)
> {
> + struct vfio_ccw_private *private =
> + container_of(vdev, struct vfio_ccw_private, vdev);
> unsigned int index = VFIO_CCW_OFFSET_TO_INDEX(*ppos);
> - struct vfio_ccw_private *private;
> -
> - private = dev_get_drvdata(mdev_parent_dev(mdev));
>
> if (index >= VFIO_CCW_NUM_REGIONS + private->num_regions)
> return -EINVAL;
> @@ -313,12 +322,9 @@ static ssize_t vfio_ccw_mdev_write(struct
> mdev_device *mdev,
> return -EINVAL;
> }
>
> -static int vfio_ccw_mdev_get_device_info(struct vfio_device_info
> *info,
> - struct mdev_device *mdev)
> +static int vfio_ccw_mdev_get_device_info(struct vfio_ccw_private
> *private,
> + struct vfio_device_info *info)
> {
> - struct vfio_ccw_private *private;
> -
> - private = dev_get_drvdata(mdev_parent_dev(mdev));
> info->flags = VFIO_DEVICE_FLAGS_CCW | VFIO_DEVICE_FLAGS_RESET;
> info->num_regions = VFIO_CCW_NUM_REGIONS + private-
> >num_regions;
> info->num_irqs = VFIO_CCW_NUM_IRQS;
> @@ -326,14 +332,12 @@ static int vfio_ccw_mdev_get_device_info(struct
> vfio_device_info *info,
> return 0;
> }
>
> -static int vfio_ccw_mdev_get_region_info(struct vfio_region_info
> *info,
> - struct mdev_device *mdev,
> +static int vfio_ccw_mdev_get_region_info(struct vfio_ccw_private
> *private,
> + struct vfio_region_info *info,
> unsigned long arg)
> {
> - struct vfio_ccw_private *private;
> int i;
>
> - private = dev_get_drvdata(mdev_parent_dev(mdev));
> switch (info->index) {
> case VFIO_CCW_CONFIG_REGION_INDEX:
> info->offset = 0;
> @@ -408,19 +412,16 @@ static int vfio_ccw_mdev_get_irq_info(struct
> vfio_irq_info *info)
> return 0;
> }
>
> -static int vfio_ccw_mdev_set_irqs(struct mdev_device *mdev,
> +static int vfio_ccw_mdev_set_irqs(struct vfio_ccw_private *private,
> uint32_t flags,
> uint32_t index,
> void __user *data)
> {
> - struct vfio_ccw_private *private;
> struct eventfd_ctx **ctx;
>
> if (!(flags & VFIO_IRQ_SET_ACTION_TRIGGER))
> return -EINVAL;
>
> - private = dev_get_drvdata(mdev_parent_dev(mdev));
> -
> switch (index) {
> case VFIO_CCW_IO_IRQ_INDEX:
> ctx = &private->io_trigger;
> @@ -522,10 +523,12 @@ void vfio_ccw_unregister_dev_regions(struct
> vfio_ccw_private *private)
> private->region = NULL;
> }
>
> -static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev,
> +static ssize_t vfio_ccw_mdev_ioctl(struct vfio_device *vdev,
> unsigned int cmd,
> unsigned long arg)
> {
> + struct vfio_ccw_private *private =
> + container_of(vdev, struct vfio_ccw_private, vdev);
> int ret = 0;
> unsigned long minsz;
>
> @@ -542,7 +545,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct
> mdev_device *mdev,
> if (info.argsz < minsz)
> return -EINVAL;
>
> - ret = vfio_ccw_mdev_get_device_info(&info, mdev);
> + ret = vfio_ccw_mdev_get_device_info(private, &info);
> if (ret)
> return ret;
>
> @@ -560,7 +563,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct
> mdev_device *mdev,
> if (info.argsz < minsz)
> return -EINVAL;
>
> - ret = vfio_ccw_mdev_get_region_info(&info, mdev, arg);
> + ret = vfio_ccw_mdev_get_region_info(private, &info,
> arg);
> if (ret)
> return ret;
>
> @@ -605,47 +608,59 @@ static ssize_t vfio_ccw_mdev_ioctl(struct
> mdev_device *mdev,
> return ret;
>
> data = (void __user *)(arg + minsz);
> - return vfio_ccw_mdev_set_irqs(mdev, hdr.flags,
> hdr.index, data);
> + return vfio_ccw_mdev_set_irqs(private, hdr.flags,
> hdr.index,
> + data);
> }
> case VFIO_DEVICE_RESET:
> - return vfio_ccw_mdev_reset(mdev);
> + return vfio_ccw_mdev_reset(private);
> default:
> return -ENOTTY;
> }
> }
>
> /* Request removal of the device*/
> -static void vfio_ccw_mdev_request(struct mdev_device *mdev, unsigned
> int count)
> +static void vfio_ccw_mdev_request(struct vfio_device *vdev, unsigned
> int count)
> {
> - struct vfio_ccw_private *private =
> dev_get_drvdata(mdev_parent_dev(mdev));
> -
> - if (!private)
> - return;
> + struct vfio_ccw_private *private =
> + container_of(vdev, struct vfio_ccw_private, vdev);
> + struct device *dev = private->vdev.dev;
This could be simply vdev->dev.
The rest seems okay.
Thanks,
Eric
>
> if (private->req_trigger) {
> if (!(count % 10))
> - dev_notice_ratelimited(mdev_dev(private->mdev),
> + dev_notice_ratelimited(dev,
> "Relaying device request
> to user (#%u)\n",
> count);
>
> eventfd_signal(private->req_trigger, 1);
> } else if (count == 0) {
> - dev_notice(mdev_dev(private->mdev),
> + dev_notice(dev,
> "No device request channel registered,
> blocked until released by user\n");
> }
> }
>
> +static const struct vfio_device_ops vfio_ccw_dev_ops = {
> + .open = vfio_ccw_mdev_open,
> + .release = vfio_ccw_mdev_release,
> + .read = vfio_ccw_mdev_read,
> + .write = vfio_ccw_mdev_write,
> + .ioctl = vfio_ccw_mdev_ioctl,
> + .request = vfio_ccw_mdev_request,
> +};
> +
> +struct mdev_driver vfio_ccw_mdev_driver = {
> + .driver = {
> + .name = "vfio_ccw_mdev",
> + .owner = THIS_MODULE,
> + .mod_name = KBUILD_MODNAME,
> + },
> + .probe = vfio_ccw_mdev_probe,
> + .remove = vfio_ccw_mdev_remove,
> +};
> +
> static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
> .owner = THIS_MODULE,
> + .device_driver = &vfio_ccw_mdev_driver,
> .supported_type_groups = mdev_type_groups,
> - .create = vfio_ccw_mdev_create,
> - .remove = vfio_ccw_mdev_remove,
> - .open = vfio_ccw_mdev_open,
> - .release = vfio_ccw_mdev_release,
> - .read = vfio_ccw_mdev_read,
> - .write = vfio_ccw_mdev_write,
> - .ioctl = vfio_ccw_mdev_ioctl,
> - .request = vfio_ccw_mdev_request,
> };
>
> int vfio_ccw_mdev_reg(struct subchannel *sch)
> diff --git a/drivers/s390/cio/vfio_ccw_private.h
> b/drivers/s390/cio/vfio_ccw_private.h
> index b2c762eb42b9bb..7272eb78861244 100644
> --- a/drivers/s390/cio/vfio_ccw_private.h
> +++ b/drivers/s390/cio/vfio_ccw_private.h
> @@ -17,6 +17,7 @@
> #include <linux/eventfd.h>
> #include <linux/workqueue.h>
> #include <linux/vfio_ccw.h>
> +#include <linux/vfio.h>
> #include <asm/crw.h>
> #include <asm/debug.h>
>
> @@ -67,6 +68,7 @@ struct vfio_ccw_crw {
>
> /**
> * struct vfio_ccw_private
> + * @vdev: Embedded VFIO device
> * @sch: pointer to the subchannel
> * @state: internal state of the device
> * @completion: synchronization helper of the I/O completion
> @@ -90,6 +92,7 @@ struct vfio_ccw_crw {
> * @crw_work: work for deferral process of CRW handling
> */
> struct vfio_ccw_private {
> + struct vfio_device vdev;
> struct subchannel *sch;
> int state;
> struct completion *completion;
> @@ -121,6 +124,8 @@ extern void vfio_ccw_mdev_unreg(struct subchannel
> *sch);
>
> extern int vfio_ccw_sch_quiesce(struct subchannel *sch);
>
> +extern struct mdev_driver vfio_ccw_mdev_driver;
> +
> /*
> * States of the device statemachine.
> */
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 00/13] Remove vfio_mdev.c, mdev_parent_ops and more
2021-04-26 20:00 [PATCH v2 00/13] Remove vfio_mdev.c, mdev_parent_ops and more Jason Gunthorpe
` (3 preceding siblings ...)
2021-04-26 20:00 ` [PATCH v2 11/13] vfio/mdev: Remove mdev_parent_ops Jason Gunthorpe
@ 2021-04-27 21:30 ` Alex Williamson
2021-04-27 22:20 ` Jason Gunthorpe
4 siblings, 1 reply; 26+ messages in thread
From: Alex Williamson @ 2021-04-27 21:30 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: David Airlie, Tony Krowiak, Christian Borntraeger, Cornelia Huck,
Jonathan Corbet, Daniel Vetter, dri-devel, Eric Farman,
Harald Freudenberger, Vasily Gorbik, Heiko Carstens, intel-gfx,
intel-gvt-dev, Jani Nikula, Joonas Lahtinen, kvm, Kirti Wankhede,
linux-doc, linux-s390, Peter Oberparleiter, Halil Pasic,
Pierre Morel, Rodrigo Vivi, Vineeth Vijayan, Zhenyu Wang,
Zhi Wang, Raj, Ashok, Dan Williams, Christoph Hellwig,
Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Mon, 26 Apr 2021 17:00:02 -0300
Jason Gunthorpe <jgg@nvidia.com> wrote:
> 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 and the actual device driver.
>
> Make every one of the mdev drivers implement an actual struct mdev_driver
> and directly call vfio_register_group_dev() in the probe() function for
> the mdev.
>
> Squash what is left of the mdev_parent_ops into the mdev_driver and remap
> create(), remove() and mdev_attr_groups to their driver core
> equivalents. 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.
>
> This allows deleting the entire mdev_drvdata, and tidying some of the
> sysfs. Many places in the drivers start using container_of()
>
> This cleanly splits the mdev sysfs GUID lifecycle management stuff from
> the vfio_device implementation part, the only VFIO special part of mdev
> that remains is the mdev specific iommu intervention.
>
> v2:
> - 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
>
> Cc: Leon Romanovsky <leonro@nvidia.com>
> Cc: "Raj, Ashok" <ashok.raj@intel.com>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Max Gurtovoy <mgurtovoy@nvidia.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Tarun Gupta <targupta@nvidia.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
>
>
> Jason Gunthorpe (13):
> 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()
> vfio/ap_ops: Convert to use vfio_register_group_dev()
> vfio/ccw: Convert to use vfio_register_group_dev()
> vfio/gvt: Convert to use vfio_register_group_dev()
> vfio/mdev: Remove vfio_mdev.c
> vfio/mdev: Remove mdev_parent_ops dev_attr_groups
> vfio/mdev: Remove mdev_parent_ops
> vfio/mdev: Use the driver core to create the 'remove' file
> vfio/mdev: Remove mdev drvdata
It'd be really helpful if you could consistently copy at least one
list, preferably one monitored by patchwork, for an entire series. The
kvm list is missing patches 06 and 08. I can find the latter hopping
over to the intel-gfx or dri-devel projects as I did for the last
series, but 06 only copied linux-s390, where I need to use lore and
can't find a patchwork. Thanks,
Alex
>
> .../driver-api/vfio-mediated-device.rst | 56 ++---
> Documentation/s390/vfio-ap.rst | 1 -
> arch/s390/Kconfig | 2 +-
> drivers/gpu/drm/i915/Kconfig | 2 +-
> drivers/gpu/drm/i915/gvt/kvmgt.c | 210 +++++++++--------
> drivers/s390/cio/vfio_ccw_drv.c | 21 +-
> drivers/s390/cio/vfio_ccw_ops.c | 136 ++++++-----
> drivers/s390/cio/vfio_ccw_private.h | 5 +
> drivers/s390/crypto/vfio_ap_ops.c | 138 ++++++-----
> drivers/s390/crypto/vfio_ap_private.h | 2 +
> drivers/vfio/mdev/Kconfig | 7 -
> drivers/vfio/mdev/Makefile | 1 -
> drivers/vfio/mdev/mdev_core.c | 67 ++++--
> drivers/vfio/mdev/mdev_driver.c | 20 +-
> drivers/vfio/mdev/mdev_private.h | 4 +-
> drivers/vfio/mdev/mdev_sysfs.c | 37 ++-
> drivers/vfio/mdev/vfio_mdev.c | 180 ---------------
> drivers/vfio/vfio.c | 6 +-
> include/linux/mdev.h | 86 +------
> include/linux/vfio.h | 4 +
> samples/Kconfig | 6 +-
> samples/vfio-mdev/mbochs.c | 166 +++++++------
> samples/vfio-mdev/mdpy.c | 162 +++++++------
> samples/vfio-mdev/mtty.c | 218 +++++++-----------
> 24 files changed, 651 insertions(+), 886 deletions(-)
> delete mode 100644 drivers/vfio/mdev/vfio_mdev.c
>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev()
2021-04-27 20:06 ` Eric Farman
@ 2021-04-27 22:10 ` Jason Gunthorpe
2021-04-28 12:55 ` Eric Farman
0 siblings, 1 reply; 26+ messages in thread
From: Jason Gunthorpe @ 2021-04-27 22:10 UTC (permalink / raw)
To: Eric Farman
Cc: Christian Borntraeger, Cornelia Huck, Vasily Gorbik,
Heiko Carstens, kvm, linux-s390, Peter Oberparleiter, Halil Pasic,
Vineeth Vijayan, Raj, Ashok, Dan Williams, Daniel Vetter,
Christoph Hellwig, Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Tue, Apr 27, 2021 at 04:06:04PM -0400, Eric Farman wrote:
> > @@ -132,19 +137,28 @@ static int vfio_ccw_mdev_create(struct
> > mdev_device *mdev)
> > private->sch->schid.ssid,
> > private->sch->schid.sch_no);
> >
> > + ret = vfio_register_group_dev(&private->vdev);
> > + if (ret)
> > + goto err_atomic;
> > + dev_set_drvdata(&mdev->dev, private);
> > return 0;
> > +
> > +err_atomic:
> > + atomic_inc(&private->avail);
>
> Since we're unwinding, should also do
>
> private->mdev = NULL
> private->state = VFIO_CCW_STATE_STANDBY
I can change this, but it looks quite weird to do stuff like this with
no locking.
eg the only reads are here:
drivers/s390/cio/vfio_ccw_drv.c: if (private->mdev && is_final)
drivers/s390/cio/vfio_ccw_drv.c: private->state = private->mdev ? VFIO_CCW_STATE_IDLE :
Which is from a WQ, if someone thinks setting mdev to NULL should
effect those WQs then there are problems...
The non-atomic state is equally confusing
Jason
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 00/13] Remove vfio_mdev.c, mdev_parent_ops and more
2021-04-27 21:30 ` [PATCH v2 00/13] Remove vfio_mdev.c, mdev_parent_ops and more Alex Williamson
@ 2021-04-27 22:20 ` Jason Gunthorpe
2021-04-27 22:49 ` Alex Williamson
0 siblings, 1 reply; 26+ messages in thread
From: Jason Gunthorpe @ 2021-04-27 22:20 UTC (permalink / raw)
To: Alex Williamson
Cc: David Airlie, Tony Krowiak, Christian Borntraeger, Cornelia Huck,
Jonathan Corbet, Daniel Vetter, dri-devel, Eric Farman,
Harald Freudenberger, Vasily Gorbik, Heiko Carstens, intel-gfx,
intel-gvt-dev, Jani Nikula, Joonas Lahtinen, kvm, Kirti Wankhede,
linux-doc, linux-s390, Peter Oberparleiter, Halil Pasic,
Pierre Morel, Rodrigo Vivi, Vineeth Vijayan, Zhenyu Wang,
Zhi Wang, Raj, Ashok, Dan Williams, Christoph Hellwig,
Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Tue, Apr 27, 2021 at 03:30:42PM -0600, Alex Williamson wrote:
> It'd be really helpful if you could consistently copy at least one
> list, preferably one monitored by patchwork, for an entire series. The
> kvm list is missing patches 06 and 08. I can find the latter hopping
> over to the intel-gfx or dri-devel projects as I did for the last
> series, but 06 only copied linux-s390, where I need to use lore and
> can't find a patchwork. Thanks,
Oh wow, that is not intentional, sorry! Thanks for pointing it out
I didn't notice this was happening, basically a side effect of having
so many different people and lists to get on this series - kvm should
have been CC on them all, I fixed it up going forward.
FWIW you may be interested in b4 if you haven't seen it before, it is
a good alternative if there isn't an offical patchworks.
Jason
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 00/13] Remove vfio_mdev.c, mdev_parent_ops and more
2021-04-27 22:20 ` Jason Gunthorpe
@ 2021-04-27 22:49 ` Alex Williamson
0 siblings, 0 replies; 26+ messages in thread
From: Alex Williamson @ 2021-04-27 22:49 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: David Airlie, Tony Krowiak, Christian Borntraeger, Cornelia Huck,
Jonathan Corbet, Daniel Vetter, dri-devel, Eric Farman,
Harald Freudenberger, Vasily Gorbik, Heiko Carstens, intel-gfx,
intel-gvt-dev, Jani Nikula, Joonas Lahtinen, kvm, Kirti Wankhede,
linux-doc, linux-s390, Peter Oberparleiter, Halil Pasic,
Pierre Morel, Rodrigo Vivi, Vineeth Vijayan, Zhenyu Wang,
Zhi Wang, Raj, Ashok, Dan Williams, Christoph Hellwig,
Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Tue, 27 Apr 2021 19:20:26 -0300
Jason Gunthorpe <jgg@nvidia.com> wrote:
> On Tue, Apr 27, 2021 at 03:30:42PM -0600, Alex Williamson wrote:
>
> > It'd be really helpful if you could consistently copy at least one
> > list, preferably one monitored by patchwork, for an entire series. The
> > kvm list is missing patches 06 and 08. I can find the latter hopping
> > over to the intel-gfx or dri-devel projects as I did for the last
> > series, but 06 only copied linux-s390, where I need to use lore and
> > can't find a patchwork. Thanks,
>
> Oh wow, that is not intentional, sorry! Thanks for pointing it out
>
> I didn't notice this was happening, basically a side effect of having
> so many different people and lists to get on this series - kvm should
> have been CC on them all, I fixed it up going forward.
>
> FWIW you may be interested in b4 if you haven't seen it before, it is
> a good alternative if there isn't an offical patchworks.
I'm sold! Thanks,
Alex
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev()
2021-04-27 22:10 ` Jason Gunthorpe
@ 2021-04-28 12:55 ` Eric Farman
2021-04-28 13:21 ` Jason Gunthorpe
0 siblings, 1 reply; 26+ messages in thread
From: Eric Farman @ 2021-04-28 12:55 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Christian Borntraeger, Cornelia Huck, Vasily Gorbik,
Heiko Carstens, kvm, linux-s390, Peter Oberparleiter, Halil Pasic,
Vineeth Vijayan, Raj, Ashok, Dan Williams, Daniel Vetter,
Christoph Hellwig, Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Tue, 2021-04-27 at 19:10 -0300, Jason Gunthorpe wrote:
> On Tue, Apr 27, 2021 at 04:06:04PM -0400, Eric Farman wrote:
> > > @@ -132,19 +137,28 @@ static int vfio_ccw_mdev_create(struct
> > > mdev_device *mdev)
> > > private->sch->schid.ssid,
> > > private->sch->schid.sch_no);
> > >
> > > + ret = vfio_register_group_dev(&private->vdev);
> > > + if (ret)
> > > + goto err_atomic;
> > > + dev_set_drvdata(&mdev->dev, private);
> > > return 0;
> > > +
> > > +err_atomic:
> > > + atomic_inc(&private->avail);
> >
> > Since we're unwinding, should also do
> >
> > private->mdev = NULL
> > private->state = VFIO_CCW_STATE_STANDBY
>
> I can change this, but it looks quite weird to do stuff like this
> with
> no locking.
I agree, but mdev_create didn't fail before, so backing out part of its
work seems weird too.
>
> eg the only reads are here:
>
> drivers/s390/cio/vfio_ccw_drv.c: if (private->mdev &&
> is_final)
> drivers/s390/cio/vfio_ccw_drv.c: private->state =
> private->mdev ? VFIO_CCW_STATE_IDLE :
>
> Which is from a WQ, if someone thinks setting mdev to NULL should
> effect those WQs then there are problems...
>
> The non-atomic state is equally confusing
Agreed, it's already on the list.
Eric
>
> Jason
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev()
2021-04-28 12:55 ` Eric Farman
@ 2021-04-28 13:21 ` Jason Gunthorpe
0 siblings, 0 replies; 26+ messages in thread
From: Jason Gunthorpe @ 2021-04-28 13:21 UTC (permalink / raw)
To: Eric Farman
Cc: Christian Borntraeger, Cornelia Huck, Vasily Gorbik,
Heiko Carstens, kvm, linux-s390, Peter Oberparleiter, Halil Pasic,
Vineeth Vijayan, Raj, Ashok, Dan Williams, Daniel Vetter,
Christoph Hellwig, Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Wed, Apr 28, 2021 at 08:55:51AM -0400, Eric Farman wrote:
> On Tue, 2021-04-27 at 19:10 -0300, Jason Gunthorpe wrote:
> > On Tue, Apr 27, 2021 at 04:06:04PM -0400, Eric Farman wrote:
> > > > @@ -132,19 +137,28 @@ static int vfio_ccw_mdev_create(struct
> > > > mdev_device *mdev)
> > > > private->sch->schid.ssid,
> > > > private->sch->schid.sch_no);
> > > >
> > > > + ret = vfio_register_group_dev(&private->vdev);
> > > > + if (ret)
> > > > + goto err_atomic;
> > > > + dev_set_drvdata(&mdev->dev, private);
> > > > return 0;
> > > > +
> > > > +err_atomic:
> > > > + atomic_inc(&private->avail);
> > >
> > > Since we're unwinding, should also do
> > >
> > > private->mdev = NULL
> > > private->state = VFIO_CCW_STATE_STANDBY
> >
> > I can change this, but it looks quite weird to do stuff like this
> > with
> > no locking.
>
> I agree, but mdev_create didn't fail before, so backing out part of its
> work seems weird too.
Before if vfio_register_group_dev() failed the device would be left
half created but without a driver attached. It wasn't good.
The way it should work is up until vfio_register_group_dev() returns
success there should be no concurrancy and no touches to 'private' -
those WQs should all be shutdown.
Ideally the private would be allocated here as well so these rules are
clear and obvious
Jason
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev()
2021-04-26 20:00 ` [PATCH v2 07/13] vfio/ccw: " Jason Gunthorpe
2021-04-27 20:06 ` Eric Farman
@ 2021-04-28 17:09 ` Cornelia Huck
2021-04-28 17:20 ` Jason Gunthorpe
1 sibling, 1 reply; 26+ messages in thread
From: Cornelia Huck @ 2021-04-28 17:09 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Christian Borntraeger, Eric Farman, Vasily Gorbik, Heiko Carstens,
kvm, linux-s390, Peter Oberparleiter, Halil Pasic,
Vineeth Vijayan, Raj, Ashok, Dan Williams, Daniel Vetter,
Christoph Hellwig, Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Mon, 26 Apr 2021 17:00:09 -0300
Jason Gunthorpe <jgg@nvidia.com> wrote:
> This is more complicated because vfio_ccw is sharing the vfio_device
> between both the mdev_device and its vfio_device and the css_driver.
>
> The mdev is a singleton, and the reason for this sharing appears to be to
> allow the extra css_driver function callbacks to be delivered to the
> vfio_device.
>
> This keeps things as they were, with the css_driver allocating the
> singleton, not the mdev_driver, this is pretty confusing. I'm also
> uncertain how the lifetime model for the mdev works in the css_driver
> callbacks.
>
> At this point embed the vfio_device in the vfio_ccw_private and
> instantiate it as a vfio_device when the mdev probes. The drvdata of both
> the css_device and the mdev_device point at the private, and container_of
> is used to get it back from the vfio_device.
I've been staring at this for some time, and I'm not sure whether this
is a good approach.
We allow at most one mdev per subchannel (slicing it up does not make
sense), so we can be sure that there's a 1:1 relationship between mdev
and parent device, and we can track it via a single pointer.
The vfio_ccw_private driver data is allocated during probe (same as for
other css_drivers.) Embedding a vfio_device here means that we have a
structure tied into it that is operating with different lifetime rules.
What about creating a second structure instead that can embed the
vfio_device, is allocated during mdev probing, and is linked up with
the vfio_ccw_private structure? That would follow the pattern of other
drivers more closely.
>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
> drivers/s390/cio/vfio_ccw_drv.c | 21 +++--
> drivers/s390/cio/vfio_ccw_ops.c | 135 +++++++++++++++-------------
> drivers/s390/cio/vfio_ccw_private.h | 5 ++
> 3 files changed, 94 insertions(+), 67 deletions(-)
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev()
2021-04-28 17:09 ` Cornelia Huck
@ 2021-04-28 17:20 ` Jason Gunthorpe
2021-04-29 11:58 ` Cornelia Huck
0 siblings, 1 reply; 26+ messages in thread
From: Jason Gunthorpe @ 2021-04-28 17:20 UTC (permalink / raw)
To: Cornelia Huck
Cc: Christian Borntraeger, Eric Farman, Vasily Gorbik, Heiko Carstens,
kvm, linux-s390, Peter Oberparleiter, Halil Pasic,
Vineeth Vijayan, Raj, Ashok, Dan Williams, Daniel Vetter,
Christoph Hellwig, Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Wed, Apr 28, 2021 at 07:09:49PM +0200, Cornelia Huck wrote:
> On Mon, 26 Apr 2021 17:00:09 -0300
> Jason Gunthorpe <jgg@nvidia.com> wrote:
>
> > This is more complicated because vfio_ccw is sharing the vfio_device
> > between both the mdev_device and its vfio_device and the css_driver.
> >
> > The mdev is a singleton, and the reason for this sharing appears to be to
> > allow the extra css_driver function callbacks to be delivered to the
> > vfio_device.
> >
> > This keeps things as they were, with the css_driver allocating the
> > singleton, not the mdev_driver, this is pretty confusing. I'm also
> > uncertain how the lifetime model for the mdev works in the css_driver
> > callbacks.
> >
> > At this point embed the vfio_device in the vfio_ccw_private and
> > instantiate it as a vfio_device when the mdev probes. The drvdata of both
> > the css_device and the mdev_device point at the private, and container_of
> > is used to get it back from the vfio_device.
>
> I've been staring at this for some time, and I'm not sure whether this
> is a good approach.
>
> We allow at most one mdev per subchannel (slicing it up does not make
> sense), so we can be sure that there's a 1:1 relationship between mdev
> and parent device, and we can track it via a single pointer.
This seems like one of these cases where using the mdev GUID API was not a
great fit. The ccs_driver should have just directly created a
vfio_device and not gone into the mdev guid lifecycle world.
> The vfio_ccw_private driver data is allocated during probe (same as for
> other css_drivers.) Embedding a vfio_device here means that we have a
> structure tied into it that is operating with different lifetime rules.
>
> What about creating a second structure instead that can embed the
> vfio_device, is allocated during mdev probing, and is linked up with
> the vfio_ccw_private structure? That would follow the pattern of other
> drivers more closely.
IIRC we still end up with pointers crossing between the two
structs. If you can't convince yourself that is correct (and I could
not) then it is already buggy today.
It is as I said to Eric, either there is no concurrency when there is
no mdev and everything is correct today, or there is concurrency and
it seems buggy today too.
The right answer it to move the allocations out of the css_driver
probe and put them only in the mdev driver probe because they can only
make sense when the mdev driver is instantiated. Then everything is
clear and very understandable how it should work.
I almost did this, but couldn't figure out how the lifetime of the
ccs_driver callbacks are working relative to the lifetime of the mdev
device since they also reach into these structs. Maybe they can't be
called for some css related reason?
Jason
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev()
2021-04-28 17:20 ` Jason Gunthorpe
@ 2021-04-29 11:58 ` Cornelia Huck
2021-04-29 18:13 ` Jason Gunthorpe
0 siblings, 1 reply; 26+ messages in thread
From: Cornelia Huck @ 2021-04-29 11:58 UTC (permalink / raw)
To: Jason Gunthorpe, Eric Farman
Cc: Christian Borntraeger, Vasily Gorbik, Heiko Carstens, kvm,
linux-s390, Peter Oberparleiter, Halil Pasic, Vineeth Vijayan,
Raj, Ashok, Dan Williams, Daniel Vetter, Christoph Hellwig,
Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Wed, 28 Apr 2021 14:20:08 -0300
Jason Gunthorpe <jgg@nvidia.com> wrote:
> On Wed, Apr 28, 2021 at 07:09:49PM +0200, Cornelia Huck wrote:
> > On Mon, 26 Apr 2021 17:00:09 -0300
> > Jason Gunthorpe <jgg@nvidia.com> wrote:
> >
> > > This is more complicated because vfio_ccw is sharing the vfio_device
> > > between both the mdev_device and its vfio_device and the css_driver.
> > >
> > > The mdev is a singleton, and the reason for this sharing appears to be to
> > > allow the extra css_driver function callbacks to be delivered to the
> > > vfio_device.
> > >
> > > This keeps things as they were, with the css_driver allocating the
> > > singleton, not the mdev_driver, this is pretty confusing. I'm also
> > > uncertain how the lifetime model for the mdev works in the css_driver
> > > callbacks.
> > >
> > > At this point embed the vfio_device in the vfio_ccw_private and
> > > instantiate it as a vfio_device when the mdev probes. The drvdata of both
> > > the css_device and the mdev_device point at the private, and container_of
> > > is used to get it back from the vfio_device.
> >
> > I've been staring at this for some time, and I'm not sure whether this
> > is a good approach.
> >
> > We allow at most one mdev per subchannel (slicing it up does not make
> > sense), so we can be sure that there's a 1:1 relationship between mdev
> > and parent device, and we can track it via a single pointer.
>
> This seems like one of these cases where using the mdev GUID API was not a
> great fit. The ccs_driver should have just directly created a
> vfio_device and not gone into the mdev guid lifecycle world.
I don't remember much of the discussion back then, but I don't think
the explicit generation of devices was the part we needed, but rather
some other kind of mediation -- probably iommu related, as subchannels
don't have that concept on their own. Anyway, too late to change now.
>
> > The vfio_ccw_private driver data is allocated during probe (same as for
> > other css_drivers.) Embedding a vfio_device here means that we have a
> > structure tied into it that is operating with different lifetime rules.
> >
> > What about creating a second structure instead that can embed the
> > vfio_device, is allocated during mdev probing, and is linked up with
> > the vfio_ccw_private structure? That would follow the pattern of other
> > drivers more closely.
>
> IIRC we still end up with pointers crossing between the two
> structs. If you can't convince yourself that is correct (and I could
> not) then it is already buggy today.
>
> It is as I said to Eric, either there is no concurrency when there is
> no mdev and everything is correct today, or there is concurrency and
> it seems buggy today too.
>
> The right answer it to move the allocations out of the css_driver
> probe and put them only in the mdev driver probe because they can only
> make sense when the mdev driver is instantiated. Then everything is
> clear and very understandable how it should work.
>
> I almost did this, but couldn't figure out how the lifetime of the
> ccs_driver callbacks are working relative to the lifetime of the mdev
> device since they also reach into these structs. Maybe they can't be
> called for some css related reason?
Moving allocations to the mdev driver probe makes sense, I guess. We
should also move enabling the subchannel to that point in time (I don't
remember why we enable it in the css probe function, and can't think of
a good reason for that; obviously needs to be paired with quiescing and
disabling the subchannel in the mdev driver remove function); that
leaves the uevent dance (which can hopefully also be removed, if some
discussed changes are implemented in the common I/O layer) and fencing
QDIO.
Regarding the other callbacks,
- vfio_ccw_sch_irq should not be invoked if the subchannel is not
enabled; maybe log a message before returning for !private.
- vfio_ccw_sch_remove should be able to return 0 for !private (nothing
to quiesce, if the subchannel is not enabled).
- vfio_ccw_sch_shutdown has nothing to do for !private (same reason.)
- In vfio_ccw_sch_event, we should either skip the fsm_event and the
state change for !private, or return 0 in that case.
- vfio_ccw_chp_event already checks for !private. Not sure whether we
should try to update some control blocks and return -ENODEV if the
subchannel is not operational, but it's probably not needed.
Eric, what do you think?
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev()
2021-04-29 11:58 ` Cornelia Huck
@ 2021-04-29 18:13 ` Jason Gunthorpe
2021-04-30 12:31 ` Cornelia Huck
0 siblings, 1 reply; 26+ messages in thread
From: Jason Gunthorpe @ 2021-04-29 18:13 UTC (permalink / raw)
To: Cornelia Huck
Cc: Eric Farman, Christian Borntraeger, Vasily Gorbik, Heiko Carstens,
kvm, linux-s390, Peter Oberparleiter, Halil Pasic,
Vineeth Vijayan, Raj, Ashok, Dan Williams, Daniel Vetter,
Christoph Hellwig, Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Thu, Apr 29, 2021 at 01:58:55PM +0200, Cornelia Huck wrote:
> > This seems like one of these cases where using the mdev GUID API
> > was not a great fit. The ccs_driver should have just directly
> > created a vfio_device and not gone into the mdev guid lifecycle
> > world.
>
> I don't remember much of the discussion back then, but I don't think
> the explicit generation of devices was the part we needed, but rather
> some other kind of mediation -- probably iommu related, as subchannels
> don't have that concept on their own. Anyway, too late to change now.
The mdev part does three significant things:
- Provide a lifecycle model based on sysfs and the GUIDs
- Hackily inject itself into the VFIO IOMMU code as a special case
- Force the creation of a unique iommu group as the group FD is
mandatory to get the device FD.
This is why PASID is such a mess for mdev because it requires even
more special hacky stuff to link up the dummy IOMMU but still operate
within the iommu group of the parent device.
I can see an alternative arrangement using the /dev/ioasid idea that
is a lot less hacky and does not force the mdev guid lifecycle on
everyone that wants to create vfio_device.
> > I almost did this, but couldn't figure out how the lifetime of the
> > ccs_driver callbacks are working relative to the lifetime of the mdev
> > device since they also reach into these structs. Maybe they can't be
> > called for some css related reason?
>
> Moving allocations to the mdev driver probe makes sense, I guess. We
> should also move enabling the subchannel to that point in time (I don't
> remember why we enable it in the css probe function, and can't think of
> a good reason for that; obviously needs to be paired with quiescing and
> disabling the subchannel in the mdev driver remove function); that
> leaves the uevent dance (which can hopefully also be removed, if some
> discussed changes are implemented in the common I/O layer) and fencing
> QDIO.
>
> Regarding the other callbacks,
> - vfio_ccw_sch_irq should not be invoked if the subchannel is not
> enabled; maybe log a message before returning for !private.
> - vfio_ccw_sch_remove should be able to return 0 for !private (nothing
> to quiesce, if the subchannel is not enabled).
> - vfio_ccw_sch_shutdown has nothing to do for !private (same reason.)
> - In vfio_ccw_sch_event, we should either skip the fsm_event and the
> state change for !private, or return 0 in that case.
> - vfio_ccw_chp_event already checks for !private. Not sure whether we
> should try to update some control blocks and return -ENODEV if the
> subchannel is not operational, but it's probably not needed.
All the checks for !private need some kind of locking. The driver core
model is that the 'struct device_driver' callbacks are all called
under the device_lock (this prevents the driver unbinding during the
callback). I didn't check if ccs does this or not..
So if we NULL drvdata under the device_lock everything can be
quite simple here.
Jason
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev()
2021-04-29 18:13 ` Jason Gunthorpe
@ 2021-04-30 12:31 ` Cornelia Huck
2021-04-30 17:19 ` Jason Gunthorpe
0 siblings, 1 reply; 26+ messages in thread
From: Cornelia Huck @ 2021-04-30 12:31 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Eric Farman, Christian Borntraeger, Vasily Gorbik, Heiko Carstens,
kvm, linux-s390, Peter Oberparleiter, Halil Pasic,
Vineeth Vijayan, Raj, Ashok, Dan Williams, Daniel Vetter,
Christoph Hellwig, Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Thu, 29 Apr 2021 15:13:47 -0300
Jason Gunthorpe <jgg@nvidia.com> wrote:
> On Thu, Apr 29, 2021 at 01:58:55PM +0200, Cornelia Huck wrote:
>
> > > This seems like one of these cases where using the mdev GUID API
> > > was not a great fit. The ccs_driver should have just directly
> > > created a vfio_device and not gone into the mdev guid lifecycle
> > > world.
> >
> > I don't remember much of the discussion back then, but I don't think
> > the explicit generation of devices was the part we needed, but rather
> > some other kind of mediation -- probably iommu related, as subchannels
> > don't have that concept on their own. Anyway, too late to change now.
>
> The mdev part does three significant things:
> - Provide a lifecycle model based on sysfs and the GUIDs
> - Hackily inject itself into the VFIO IOMMU code as a special case
> - Force the creation of a unique iommu group as the group FD is
> mandatory to get the device FD.
>
> This is why PASID is such a mess for mdev because it requires even
> more special hacky stuff to link up the dummy IOMMU but still operate
> within the iommu group of the parent device.
>
> I can see an alternative arrangement using the /dev/ioasid idea that
> is a lot less hacky and does not force the mdev guid lifecycle on
> everyone that wants to create vfio_device.
I have not followed that discussion -- do you have a summary or a
pointer?
>
> > > I almost did this, but couldn't figure out how the lifetime of the
> > > ccs_driver callbacks are working relative to the lifetime of the mdev
> > > device since they also reach into these structs. Maybe they can't be
> > > called for some css related reason?
> >
> > Moving allocations to the mdev driver probe makes sense, I guess. We
> > should also move enabling the subchannel to that point in time (I don't
> > remember why we enable it in the css probe function, and can't think of
> > a good reason for that; obviously needs to be paired with quiescing and
> > disabling the subchannel in the mdev driver remove function); that
> > leaves the uevent dance (which can hopefully also be removed, if some
> > discussed changes are implemented in the common I/O layer) and fencing
> > QDIO.
> >
> > Regarding the other callbacks,
> > - vfio_ccw_sch_irq should not be invoked if the subchannel is not
> > enabled; maybe log a message before returning for !private.
> > - vfio_ccw_sch_remove should be able to return 0 for !private (nothing
> > to quiesce, if the subchannel is not enabled).
> > - vfio_ccw_sch_shutdown has nothing to do for !private (same reason.)
> > - In vfio_ccw_sch_event, we should either skip the fsm_event and the
> > state change for !private, or return 0 in that case.
> > - vfio_ccw_chp_event already checks for !private. Not sure whether we
> > should try to update some control blocks and return -ENODEV if the
> > subchannel is not operational, but it's probably not needed.
>
> All the checks for !private need some kind of locking. The driver core
> model is that the 'struct device_driver' callbacks are all called
> under the device_lock (this prevents the driver unbinding during the
> callback). I didn't check if ccs does this or not..
probe/remove/shutdown are basically a forward of the callbacks at the
bus level. The css bus should make sure that we serialize
irq/sch_event/chp_event with probe/remove.
>
> So if we NULL drvdata under the device_lock everything can be
> quite simple here.
>
> Jason
>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev()
2021-04-30 12:31 ` Cornelia Huck
@ 2021-04-30 17:19 ` Jason Gunthorpe
2021-05-03 10:54 ` s390 common I/O layer locking (was: [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev()) Cornelia Huck
0 siblings, 1 reply; 26+ messages in thread
From: Jason Gunthorpe @ 2021-04-30 17:19 UTC (permalink / raw)
To: Cornelia Huck
Cc: Eric Farman, Christian Borntraeger, Vasily Gorbik, Heiko Carstens,
kvm, linux-s390, Peter Oberparleiter, Halil Pasic,
Vineeth Vijayan, Raj, Ashok, Dan Williams, Daniel Vetter,
Christoph Hellwig, Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Fri, Apr 30, 2021 at 02:31:40PM +0200, Cornelia Huck wrote:
> On Thu, 29 Apr 2021 15:13:47 -0300
> Jason Gunthorpe <jgg@nvidia.com> wrote:
>
> > On Thu, Apr 29, 2021 at 01:58:55PM +0200, Cornelia Huck wrote:
> >
> > > > This seems like one of these cases where using the mdev GUID API
> > > > was not a great fit. The ccs_driver should have just directly
> > > > created a vfio_device and not gone into the mdev guid lifecycle
> > > > world.
> > >
> > > I don't remember much of the discussion back then, but I don't think
> > > the explicit generation of devices was the part we needed, but rather
> > > some other kind of mediation -- probably iommu related, as subchannels
> > > don't have that concept on their own. Anyway, too late to change now.
> >
> > The mdev part does three significant things:
> > - Provide a lifecycle model based on sysfs and the GUIDs
> > - Hackily inject itself into the VFIO IOMMU code as a special case
> > - Force the creation of a unique iommu group as the group FD is
> > mandatory to get the device FD.
> >
> > This is why PASID is such a mess for mdev because it requires even
> > more special hacky stuff to link up the dummy IOMMU but still operate
> > within the iommu group of the parent device.
> >
> > I can see an alternative arrangement using the /dev/ioasid idea that
> > is a lot less hacky and does not force the mdev guid lifecycle on
> > everyone that wants to create vfio_device.
>
> I have not followed that discussion -- do you have a summary or a
> pointer?
I think it is still evolving, I'm hoping Intel can draft some RFC
soonish
Basically, I'd imagine to put the mdev driver itself directly in
charge of how the iommu is operated. When the driver is commanded to
connect to an ioasid (which is sort of like a VFIO container) it can
tell drivers/iommu exactly what it wants, be it a PASID in a physical
iommu device or a simple SW "page table" like the current mdevs use.
This would replace all the round about stuff to try and get other
components to setup things the way they hope the mdev driver needs.
> > All the checks for !private need some kind of locking. The driver core
> > model is that the 'struct device_driver' callbacks are all called
> > under the device_lock (this prevents the driver unbinding during the
> > callback). I didn't check if ccs does this or not..
>
> probe/remove/shutdown are basically a forward of the callbacks at the
> bus level.
These are all covered by device_lock
> The css bus should make sure that we serialize
> irq/sch_event/chp_event with probe/remove.
Hum it doesn't look OK, like here:
css_process_crw()
css_evaluate_subchannel()
sch = bus_find_device()
-- So we have a refcount on the struct device
css_evaluate_known_subchannel() {
if (sch->driver) {
if (sch->driver->sch_event)
ret = sch->driver->sch_event(sch, slow);
}
But the above call and touches to sch->driver (which is really just
sch->dev.driver) are unlocked and racy.
I would hold the device_lock() over all touches to sch->driver outside
of a driver core callback.
Jason
^ permalink raw reply [flat|nested] 26+ messages in thread
* s390 common I/O layer locking (was: [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev())
2021-04-30 17:19 ` Jason Gunthorpe
@ 2021-05-03 10:54 ` Cornelia Huck
2021-05-04 15:10 ` s390 common I/O layer locking Vineeth Vijayan
0 siblings, 1 reply; 26+ messages in thread
From: Cornelia Huck @ 2021-05-03 10:54 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Eric Farman, Christian Borntraeger, Vasily Gorbik, Heiko Carstens,
kvm, linux-s390, Peter Oberparleiter, Halil Pasic,
Vineeth Vijayan, Raj, Ashok, Dan Williams, Daniel Vetter,
Christoph Hellwig, Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Fri, 30 Apr 2021 14:19:08 -0300
Jason Gunthorpe <jgg@nvidia.com> wrote:
> On Fri, Apr 30, 2021 at 02:31:40PM +0200, Cornelia Huck wrote:
> > On Thu, 29 Apr 2021 15:13:47 -0300
> > Jason Gunthorpe <jgg@nvidia.com> wrote:
> > > All the checks for !private need some kind of locking. The driver core
> > > model is that the 'struct device_driver' callbacks are all called
> > > under the device_lock (this prevents the driver unbinding during the
> > > callback). I didn't check if ccs does this or not..
> >
> > probe/remove/shutdown are basically a forward of the callbacks at the
> > bus level.
>
> These are all covered by device_lock
>
> > The css bus should make sure that we serialize
> > irq/sch_event/chp_event with probe/remove.
>
> Hum it doesn't look OK, like here:
>
> css_process_crw()
> css_evaluate_subchannel()
> sch = bus_find_device()
> -- So we have a refcount on the struct device
> css_evaluate_known_subchannel() {
> if (sch->driver) {
> if (sch->driver->sch_event)
> ret = sch->driver->sch_event(sch, slow);
> }
>
> But the above call and touches to sch->driver (which is really just
> sch->dev.driver) are unlocked and racy.
>
> I would hold the device_lock() over all touches to sch->driver outside
> of a driver core callback.
I think this issue did not come up much before, as most drivers on the
css bus tend to stay put during the lifetime of the device; but yes, it
seems we're missing some locking.
For the css bus, we need locking for the event callbacks; for irq, this
may interact with the subchannel lock and likely needs some care.
I also looked at the other busses in the common I/O layer: scm looks
good at a glance, ccwgroup and ccw have locking for online/offline; the
other callbacks for the ccw drivers probably need to take the device
lock as well.
Common I/O layer maintainers, does that look right?
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 06/13] vfio/ap_ops: Convert to use vfio_register_group_dev()
2021-04-26 20:00 ` [PATCH v2 06/13] vfio/ap_ops: Convert to use vfio_register_group_dev() Jason Gunthorpe
@ 2021-05-04 14:42 ` Tony Krowiak
2021-05-04 16:55 ` Jason Gunthorpe
0 siblings, 1 reply; 26+ messages in thread
From: Tony Krowiak @ 2021-05-04 14:42 UTC (permalink / raw)
To: Jason Gunthorpe, Christian Borntraeger, Harald Freudenberger,
Vasily Gorbik, Heiko Carstens, linux-s390, Halil Pasic,
Pierre Morel
Cc: Raj, Ashok, Dan Williams, Daniel Vetter, Christoph Hellwig,
Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On 4/26/21 4:00 PM, Jason Gunthorpe wrote:
> This is straightforward conversion, the ap_matrix_mdev is actually serving
> as the vfio_device and we can replace all the mdev_get_drvdata()'s with a
> simple container_of().
This is a nit, but most of the mdev_get_drvdata()'s are not being
replaced by container_of(); in most places, the replacement is
dev_get_drvdata().
>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
> drivers/s390/crypto/vfio_ap_ops.c | 137 ++++++++++++++++----------
> drivers/s390/crypto/vfio_ap_private.h | 2 +
> 2 files changed, 89 insertions(+), 50 deletions(-)
>
> diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
> index 0ce00c9311d378..79872c857dd522 100644
> --- a/drivers/s390/crypto/vfio_ap_ops.c
> +++ b/drivers/s390/crypto/vfio_ap_ops.c
> @@ -24,8 +24,9 @@
> #define VFIO_AP_MDEV_TYPE_HWVIRT "passthrough"
> #define VFIO_AP_MDEV_NAME_HWVIRT "VFIO AP Passthrough Device"
>
> -static int vfio_ap_mdev_reset_queues(struct mdev_device *mdev);
> +static int vfio_ap_mdev_reset_queues(struct ap_matrix_mdev *matrix_mdev);
> static struct vfio_ap_queue *vfio_ap_find_queue(int apqn);
> +static const struct vfio_device_ops vfio_ap_matrix_dev_ops;
>
> static int match_apqn(struct device *dev, const void *data)
> {
> @@ -322,48 +323,63 @@ static void vfio_ap_matrix_init(struct ap_config_info *info,
> matrix->adm_max = info->apxa ? info->Nd : 15;
> }
>
> -static int vfio_ap_mdev_create(struct mdev_device *mdev)
> +static int vfio_ap_mdev_probe(struct mdev_device *mdev)
> {
> struct ap_matrix_mdev *matrix_mdev;
> + int ret;
>
> if ((atomic_dec_if_positive(&matrix_dev->available_instances) < 0))
> return -EPERM;
>
> matrix_mdev = kzalloc(sizeof(*matrix_mdev), GFP_KERNEL);
> if (!matrix_mdev) {
> - atomic_inc(&matrix_dev->available_instances);
> - return -ENOMEM;
> + ret = -ENOMEM;
> + goto err_atomic;
> }
> + vfio_init_group_dev(&matrix_mdev->vdev, &mdev->dev,
> + &vfio_ap_matrix_dev_ops);
>
> matrix_mdev->mdev = mdev;
> vfio_ap_matrix_init(&matrix_dev->info, &matrix_mdev->matrix);
> - mdev_set_drvdata(mdev, matrix_mdev);
> matrix_mdev->pqap_hook.hook = handle_pqap;
> matrix_mdev->pqap_hook.owner = THIS_MODULE;
> mutex_lock(&matrix_dev->lock);
> list_add(&matrix_mdev->node, &matrix_dev->mdev_list);
> mutex_unlock(&matrix_dev->lock);
>
> + ret = vfio_register_group_dev(&matrix_mdev->vdev);
> + if (ret)
> + goto err_list;
> + dev_set_drvdata(&mdev->dev, matrix_mdev);
I'm wondering whether the code above should be done under
the matrix_dev->lock. Does the mdev exist in the sysfs at the
point the probe is called? If so, then is it possible for functions
that acquire the matrix_mdev from the drvdata to get called before
the drvdata is set?
> return 0;
> +
> +err_list:
> + mutex_lock(&matrix_dev->lock);
> + list_del(&matrix_mdev->node);
> + mutex_unlock(&matrix_dev->lock);
> + kfree(matrix_mdev);
> +err_atomic:
> + atomic_inc(&matrix_dev->available_instances);
> + return ret;
> }
>
> -static int vfio_ap_mdev_remove(struct mdev_device *mdev)
> +static void vfio_ap_mdev_remove(struct mdev_device *mdev)
> {
> - struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
> + struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(&mdev->dev);
>
> - if (matrix_mdev->kvm)
> - return -EBUSY;
> + /* FIXME: Remove isn't allowed to fail */
> + if (WARN_ON(matrix_mdev->kvm))
> + return;
> +
> + vfio_unregister_group_dev(&matrix_mdev->vdev);
>
> mutex_lock(&matrix_dev->lock);
> - vfio_ap_mdev_reset_queues(mdev);
> + vfio_ap_mdev_reset_queues(matrix_mdev);
> list_del(&matrix_mdev->node);
> mutex_unlock(&matrix_dev->lock);
>
> kfree(matrix_mdev);
> - mdev_set_drvdata(mdev, NULL);
> atomic_inc(&matrix_dev->available_instances);
> -
> - return 0;
> }
>
> static ssize_t name_show(struct mdev_type *mtype,
> @@ -605,8 +621,7 @@ static ssize_t assign_adapter_store(struct device *dev,
> {
> int ret;
> unsigned long apid;
> - struct mdev_device *mdev = mdev_from_dev(dev);
> - struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
> + struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
>
> /* If the guest is running, disallow assignment of adapter */
> if (matrix_mdev->kvm)
> @@ -671,8 +686,7 @@ static ssize_t unassign_adapter_store(struct device *dev,
> {
> int ret;
> unsigned long apid;
> - struct mdev_device *mdev = mdev_from_dev(dev);
> - struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
> + struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
>
> /* If the guest is running, disallow un-assignment of adapter */
> if (matrix_mdev->kvm)
> @@ -751,8 +765,7 @@ static ssize_t assign_domain_store(struct device *dev,
> {
> int ret;
> unsigned long apqi;
> - struct mdev_device *mdev = mdev_from_dev(dev);
> - struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
> + struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
> unsigned long max_apqi = matrix_mdev->matrix.aqm_max;
>
> /* If the guest is running, disallow assignment of domain */
> @@ -813,8 +826,7 @@ static ssize_t unassign_domain_store(struct device *dev,
> {
> int ret;
> unsigned long apqi;
> - struct mdev_device *mdev = mdev_from_dev(dev);
> - struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
> + struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
>
> /* If the guest is running, disallow un-assignment of domain */
> if (matrix_mdev->kvm)
> @@ -857,8 +869,7 @@ static ssize_t assign_control_domain_store(struct device *dev,
> {
> int ret;
> unsigned long id;
> - struct mdev_device *mdev = mdev_from_dev(dev);
> - struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
> + struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
>
> /* If the guest is running, disallow assignment of control domain */
> if (matrix_mdev->kvm)
> @@ -906,8 +917,7 @@ static ssize_t unassign_control_domain_store(struct device *dev,
> {
> int ret;
> unsigned long domid;
> - struct mdev_device *mdev = mdev_from_dev(dev);
> - struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
> + struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
> unsigned long max_domid = matrix_mdev->matrix.adm_max;
>
> /* If the guest is running, disallow un-assignment of control domain */
> @@ -936,8 +946,7 @@ static ssize_t control_domains_show(struct device *dev,
> int nchars = 0;
> int n;
> char *bufpos = buf;
> - struct mdev_device *mdev = mdev_from_dev(dev);
> - struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
> + struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
> unsigned long max_domid = matrix_mdev->matrix.adm_max;
>
> mutex_lock(&matrix_dev->lock);
> @@ -955,8 +964,7 @@ static DEVICE_ATTR_RO(control_domains);
> static ssize_t matrix_show(struct device *dev, struct device_attribute *attr,
> char *buf)
> {
> - struct mdev_device *mdev = mdev_from_dev(dev);
> - struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
> + struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(dev);
> char *bufpos = buf;
> unsigned long apid;
> unsigned long apqi;
> @@ -1085,7 +1093,7 @@ static void vfio_ap_mdev_unset_kvm(struct ap_matrix_mdev *matrix_mdev)
> {
> kvm_arch_crypto_clear_masks(matrix_mdev->kvm);
> matrix_mdev->kvm->arch.crypto.pqap_hook = NULL;
> - vfio_ap_mdev_reset_queues(matrix_mdev->mdev);
> + vfio_ap_mdev_reset_queues(matrix_mdev);
> kvm_put_kvm(matrix_mdev->kvm);
> matrix_mdev->kvm = NULL;
> }
> @@ -1195,13 +1203,12 @@ int vfio_ap_mdev_reset_queue(struct vfio_ap_queue *q,
> return ret;
> }
>
> -static int vfio_ap_mdev_reset_queues(struct mdev_device *mdev)
> +static int vfio_ap_mdev_reset_queues(struct ap_matrix_mdev *matrix_mdev)
> {
> int ret;
> int rc = 0;
> unsigned long apid, apqi;
> struct vfio_ap_queue *q;
> - struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
>
> for_each_set_bit_inv(apid, matrix_mdev->matrix.apm,
> matrix_mdev->matrix.apm_max + 1) {
> @@ -1222,9 +1229,10 @@ static int vfio_ap_mdev_reset_queues(struct mdev_device *mdev)
> return rc;
> }
>
> -static int vfio_ap_mdev_open(struct mdev_device *mdev)
> +static int vfio_ap_mdev_open(struct vfio_device *vdev)
> {
> - struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
> + struct ap_matrix_mdev *matrix_mdev =
> + container_of(vdev, struct ap_matrix_mdev, vdev);
> unsigned long events;
> int ret;
>
> @@ -1235,7 +1243,7 @@ static int vfio_ap_mdev_open(struct mdev_device *mdev)
> matrix_mdev->group_notifier.notifier_call = vfio_ap_mdev_group_notifier;
> events = VFIO_GROUP_NOTIFY_SET_KVM;
>
> - ret = vfio_register_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY,
> + ret = vfio_register_notifier(vdev->dev, VFIO_GROUP_NOTIFY,
> &events, &matrix_mdev->group_notifier);
> if (ret) {
> module_put(THIS_MODULE);
> @@ -1244,29 +1252,30 @@ static int vfio_ap_mdev_open(struct mdev_device *mdev)
>
> matrix_mdev->iommu_notifier.notifier_call = vfio_ap_mdev_iommu_notifier;
> events = VFIO_IOMMU_NOTIFY_DMA_UNMAP;
> - ret = vfio_register_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY,
> + ret = vfio_register_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,
> &events, &matrix_mdev->iommu_notifier);
> if (!ret)
> return ret;
>
> - vfio_unregister_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY,
> + vfio_unregister_notifier(vdev->dev, VFIO_GROUP_NOTIFY,
> &matrix_mdev->group_notifier);
> module_put(THIS_MODULE);
> return ret;
> }
>
> -static void vfio_ap_mdev_release(struct mdev_device *mdev)
> +static void vfio_ap_mdev_release(struct vfio_device *vdev)
> {
> - struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
> + struct ap_matrix_mdev *matrix_mdev =
> + container_of(vdev, struct ap_matrix_mdev, vdev);
>
> mutex_lock(&matrix_dev->lock);
> if (matrix_mdev->kvm)
> vfio_ap_mdev_unset_kvm(matrix_mdev);
> mutex_unlock(&matrix_dev->lock);
>
> - vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY,
> + vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY,
> &matrix_mdev->iommu_notifier);
> - vfio_unregister_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY,
> + vfio_unregister_notifier(vdev->dev, VFIO_GROUP_NOTIFY,
> &matrix_mdev->group_notifier);
> module_put(THIS_MODULE);
> }
> @@ -1291,9 +1300,11 @@ static int vfio_ap_mdev_get_device_info(unsigned long arg)
> return copy_to_user((void __user *)arg, &info, minsz) ? -EFAULT : 0;
> }
>
> -static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
> +static ssize_t vfio_ap_mdev_ioctl(struct vfio_device *vdev,
> unsigned int cmd, unsigned long arg)
> {
> + struct ap_matrix_mdev *matrix_mdev =
> + container_of(vdev, struct ap_matrix_mdev, vdev);
> int ret;
>
> mutex_lock(&matrix_dev->lock);
> @@ -1302,7 +1313,7 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
> ret = vfio_ap_mdev_get_device_info(arg);
> break;
> case VFIO_DEVICE_RESET:
> - ret = vfio_ap_mdev_reset_queues(mdev);
> + ret = vfio_ap_mdev_reset_queues(matrix_mdev);
> break;
> default:
> ret = -EOPNOTSUPP;
> @@ -1313,25 +1324,51 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
> return ret;
> }
>
> +static const struct vfio_device_ops vfio_ap_matrix_dev_ops = {
> + .open = vfio_ap_mdev_open,
> + .release = vfio_ap_mdev_release,
> + .ioctl = vfio_ap_mdev_ioctl,
> +};
> +
> +static struct mdev_driver vfio_ap_matrix_driver = {
> + .driver = {
> + .name = "vfio_ap_mdev",
> + .owner = THIS_MODULE,
> + .mod_name = KBUILD_MODNAME,
> + .dev_groups = vfio_ap_mdev_attr_groups,
> + },
> + .probe = vfio_ap_mdev_probe,
> + .remove = vfio_ap_mdev_remove,
> +};
> +
> static const struct mdev_parent_ops vfio_ap_matrix_ops = {
> .owner = THIS_MODULE,
> + .device_driver = &vfio_ap_matrix_driver,
> .supported_type_groups = vfio_ap_mdev_type_groups,
> - .mdev_attr_groups = vfio_ap_mdev_attr_groups,
> - .create = vfio_ap_mdev_create,
> - .remove = vfio_ap_mdev_remove,
> - .open = vfio_ap_mdev_open,
> - .release = vfio_ap_mdev_release,
> - .ioctl = vfio_ap_mdev_ioctl,
> };
>
> int vfio_ap_mdev_register(void)
> {
> + int ret;
> +
> atomic_set(&matrix_dev->available_instances, MAX_ZDEV_ENTRIES_EXT);
>
> - return mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_ops);
> + ret = mdev_register_driver(&vfio_ap_matrix_driver);
> + if (ret)
> + return ret;
> +
> + ret = mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_ops);
> + if (ret)
> + goto err_driver;
> + return 0;
> +
> +err_driver:
> + mdev_unregister_driver(&vfio_ap_matrix_driver);
> + return ret;
> }
>
> void vfio_ap_mdev_unregister(void)
> {
> mdev_unregister_device(&matrix_dev->device);
> + mdev_unregister_driver(&vfio_ap_matrix_driver);
> }
> diff --git a/drivers/s390/crypto/vfio_ap_private.h b/drivers/s390/crypto/vfio_ap_private.h
> index 28e9d998976820..b95ba674f60b1b 100644
> --- a/drivers/s390/crypto/vfio_ap_private.h
> +++ b/drivers/s390/crypto/vfio_ap_private.h
> @@ -18,6 +18,7 @@
> #include <linux/delay.h>
> #include <linux/mutex.h>
> #include <linux/kvm_host.h>
> +#include <linux/vfio.h>
>
> #include "ap_bus.h"
>
> @@ -79,6 +80,7 @@ struct ap_matrix {
> * @kvm: the struct holding guest's state
> */
> struct ap_matrix_mdev {
> + struct vfio_device vdev;
> struct list_head node;
> struct ap_matrix matrix;
> struct notifier_block group_notifier;
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: s390 common I/O layer locking
2021-05-03 10:54 ` s390 common I/O layer locking (was: [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev()) Cornelia Huck
@ 2021-05-04 15:10 ` Vineeth Vijayan
2021-07-24 13:24 ` Christoph Hellwig
0 siblings, 1 reply; 26+ messages in thread
From: Vineeth Vijayan @ 2021-05-04 15:10 UTC (permalink / raw)
To: Cornelia Huck, Jason Gunthorpe
Cc: Eric Farman, Christian Borntraeger, Vasily Gorbik, Heiko Carstens,
kvm, linux-s390, Peter Oberparleiter, Halil Pasic, Raj, Ashok,
Dan Williams, Daniel Vetter, Christoph Hellwig, Leon Romanovsky,
Max Gurtovoy, Tarun Gupta
On 5/3/21 12:54 PM, Cornelia Huck wrote:
> On Fri, 30 Apr 2021 14:19:08 -0300
> Jason Gunthorpe <jgg@nvidia.com> wrote:
>
>> On Fri, Apr 30, 2021 at 02:31:40PM +0200, Cornelia Huck wrote:
>>> On Thu, 29 Apr 2021 15:13:47 -0300
>>> Jason Gunthorpe <jgg@nvidia.com> wrote:
>>>> All the checks for !private need some kind of locking. The driver core
>>>> model is that the 'struct device_driver' callbacks are all called
>>>> under the device_lock (this prevents the driver unbinding during the
>>>> callback). I didn't check if ccs does this or not..
>>> probe/remove/shutdown are basically a forward of the callbacks at the
>>> bus level.
>> These are all covered by device_lock
>>
>>> The css bus should make sure that we serialize
>>> irq/sch_event/chp_event with probe/remove.
>> Hum it doesn't look OK, like here:
>>
>> css_process_crw()
>> css_evaluate_subchannel()
>> sch = bus_find_device()
>> -- So we have a refcount on the struct device
>> css_evaluate_known_subchannel() {
>> if (sch->driver) {
>> if (sch->driver->sch_event)
>> ret = sch->driver->sch_event(sch, slow);
>> }
>>
>> But the above call and touches to sch->driver (which is really just
>> sch->dev.driver) are unlocked and racy.
>>
>> I would hold the device_lock() over all touches to sch->driver outside
>> of a driver core callback.
> I think this issue did not come up much before, as most drivers on the
> css bus tend to stay put during the lifetime of the device; but yes, it
> seems we're missing some locking.
>
> For the css bus, we need locking for the event callbacks; for irq, this
> may interact with the subchannel lock and likely needs some care.
>
> I also looked at the other busses in the common I/O layer: scm looks
> good at a glance, ccwgroup and ccw have locking for online/offline; the
> other callbacks for the ccw drivers probably need to take the device
> lock as well.
>
> Common I/O layer maintainers, does that look right?
>
I just had a quick glance on the CIO layer drivers. And at first look,
you are right.
It looks likewe need modifications in the event callbacks (referring css
here)
Let me go thoughthis thoroughly and update.
Thank you.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 06/13] vfio/ap_ops: Convert to use vfio_register_group_dev()
2021-05-04 14:42 ` Tony Krowiak
@ 2021-05-04 16:55 ` Jason Gunthorpe
0 siblings, 0 replies; 26+ messages in thread
From: Jason Gunthorpe @ 2021-05-04 16:55 UTC (permalink / raw)
To: Tony Krowiak
Cc: Christian Borntraeger, Harald Freudenberger, Vasily Gorbik,
Heiko Carstens, linux-s390, Halil Pasic, Pierre Morel, Raj, Ashok,
Dan Williams, Daniel Vetter, Christoph Hellwig, Leon Romanovsky,
Max Gurtovoy, Tarun Gupta
On Tue, May 04, 2021 at 10:42:04AM -0400, Tony Krowiak wrote:
>
>
> On 4/26/21 4:00 PM, Jason Gunthorpe wrote:
> > This is straightforward conversion, the ap_matrix_mdev is actually serving
> > as the vfio_device and we can replace all the mdev_get_drvdata()'s with a
> > simple container_of().
>
> This is a nit, but most of the mdev_get_drvdata()'s are not being
> replaced by container_of(); in most places, the replacement is
> dev_get_drvdata().
Hum, only sysfs uses dev_get_drvdata(), but OK but numbers there are
more of them.
> > vfio_ap_matrix_init(&matrix_dev->info, &matrix_mdev->matrix);
> > - mdev_set_drvdata(mdev, matrix_mdev);
> > matrix_mdev->pqap_hook.hook = handle_pqap;
> > matrix_mdev->pqap_hook.owner = THIS_MODULE;
> > mutex_lock(&matrix_dev->lock);
> > list_add(&matrix_mdev->node, &matrix_dev->mdev_list);
> > mutex_unlock(&matrix_dev->lock);
> > + ret = vfio_register_group_dev(&matrix_mdev->vdev);
> > + if (ret)
> > + goto err_list;
> > + dev_set_drvdata(&mdev->dev, matrix_mdev);
>
> I'm wondering whether the code above should be done under
> the matrix_dev->lock. Does the mdev exist in the sysfs at the
> point the probe is called? If so, then is it possible for functions
> that acquire the matrix_mdev from the drvdata to get called before
> the drvdata is set?
The sysfs is inserted by
vfio_ap_matrix_driver.driver.dev_groups = vfio_ap_mdev_attr_groups
And if you look in really_probe() you can see the order is:
ret = drv->probe(dev);
if (device_add_groups(dev, drv->dev_groups)) {
Any access to drvdata has to be protected by the device_lock or inside
one of these special ordered regions like a driver core created sysfs
callback.
Thanks,
Jason
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: s390 common I/O layer locking
2021-05-04 15:10 ` s390 common I/O layer locking Vineeth Vijayan
@ 2021-07-24 13:24 ` Christoph Hellwig
2021-08-03 14:27 ` Vineeth Vijayan
0 siblings, 1 reply; 26+ messages in thread
From: Christoph Hellwig @ 2021-07-24 13:24 UTC (permalink / raw)
To: Vineeth Vijayan
Cc: Cornelia Huck, Jason Gunthorpe, Eric Farman,
Christian Borntraeger, Vasily Gorbik, Heiko Carstens, kvm,
linux-s390, Peter Oberparleiter, Halil Pasic, Raj, Ashok,
Dan Williams, Daniel Vetter, Christoph Hellwig, Leon Romanovsky,
Max Gurtovoy, Tarun Gupta
On Tue, May 04, 2021 at 05:10:42PM +0200, Vineeth Vijayan wrote:
>> For the css bus, we need locking for the event callbacks; for irq, this
>> may interact with the subchannel lock and likely needs some care.
>>
>> I also looked at the other busses in the common I/O layer: scm looks
>> good at a glance, ccwgroup and ccw have locking for online/offline; the
>> other callbacks for the ccw drivers probably need to take the device
>> lock as well.
>>
>> Common I/O layer maintainers, does that look right?
>>
> I just had a quick glance on the CIO layer drivers. And at first look, you
> are right.
> It looks likewe need modifications in the event callbacks (referring css
> here)
> Let me go thoughthis thoroughly and update.
Did this go anywhere?
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: s390 common I/O layer locking
2021-07-24 13:24 ` Christoph Hellwig
@ 2021-08-03 14:27 ` Vineeth Vijayan
2021-08-10 15:00 ` Cornelia Huck
0 siblings, 1 reply; 26+ messages in thread
From: Vineeth Vijayan @ 2021-08-03 14:27 UTC (permalink / raw)
To: Christoph Hellwig, Cornelia Huck
Cc: Jason Gunthorpe, Eric Farman, Christian Borntraeger,
Vasily Gorbik, Heiko Carstens, kvm, linux-s390,
Peter Oberparleiter, Halil Pasic, Raj, Ashok, Dan Williams,
Daniel Vetter, Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On 7/24/21 3:24 PM, Christoph Hellwig wrote:
> On Tue, May 04, 2021 at 05:10:42PM +0200, Vineeth Vijayan wrote:
...snip...
>> I just had a quick glance on the CIO layer drivers. And at first
>> look, you
>> are right.
>> It looks likewe need modifications in the event callbacks (referring css
>> here)
>> Let me go thoughthis thoroughly and update.
> Did this go anywhere?
Hello Christoph,
Thank you for this reminder. Also, my apologies for the slow reply; This
was one of those item which really needed this reminder :-)
Coming to the point, The event-callbacks are under sch->lock, which i
think is the right thing to do. But i also agree on your feedback about
the sch->driver accesses in the css_evaluate_known_subchannel() call. My
first impression was to add them under device_lock(). As Conny
mentioned, most of the drivers on the css-bus remained-stable during the
lifetime of the devices, and we never got this racy scenario. And then
having this change with device_lock(), as you mentioned,this code-base
would need significant change in the sch_event callbacks. I am not sure
if there is a straight forward solution for this locking-issue scenario.
Currently, i am trying to see the "minimal" change i can work on on the
event-callbacks and the css_evaluate_known_subchannel() call, to make
sure that, this racy condition can never occur.
Conny,
Please do let me know if you think i am missing something here. I would
like to concentrate more on the sch->driver() access scenario first and
would like to see how it can have minimal impact on the event-callbacks.
especially io_subchannel_sch_event.
Vineeth
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: s390 common I/O layer locking
2021-08-03 14:27 ` Vineeth Vijayan
@ 2021-08-10 15:00 ` Cornelia Huck
0 siblings, 0 replies; 26+ messages in thread
From: Cornelia Huck @ 2021-08-10 15:00 UTC (permalink / raw)
To: Vineeth Vijayan, Christoph Hellwig
Cc: Jason Gunthorpe, Eric Farman, Christian Borntraeger,
Vasily Gorbik, Heiko Carstens, kvm, linux-s390,
Peter Oberparleiter, Halil Pasic, Raj, Ashok, Dan Williams,
Daniel Vetter, Leon Romanovsky, Max Gurtovoy, Tarun Gupta
On Tue, Aug 03 2021, Vineeth Vijayan <vneethv@linux.ibm.com> wrote:
> On 7/24/21 3:24 PM, Christoph Hellwig wrote:
>> On Tue, May 04, 2021 at 05:10:42PM +0200, Vineeth Vijayan wrote:
> ...snip...
>>> I just had a quick glance on the CIO layer drivers. And at first
>>> look, you
>>> are right.
>>> It looks likewe need modifications in the event callbacks (referring css
>>> here)
>>> Let me go thoughthis thoroughly and update.
>> Did this go anywhere?
> Hello Christoph,
>
> Thank you for this reminder. Also, my apologies for the slow reply; This
> was one of those item which really needed this reminder :-)
>
> Coming to the point, The event-callbacks are under sch->lock, which i
> think is the right thing to do. But i also agree on your feedback about
> the sch->driver accesses in the css_evaluate_known_subchannel() call. My
> first impression was to add them under device_lock(). As Conny
> mentioned, most of the drivers on the css-bus remained-stable during the
> lifetime of the devices, and we never got this racy scenario. And then
> having this change with device_lock(), as you mentioned,this code-base
> would need significant change in the sch_event callbacks. I am not sure
> if there is a straight forward solution for this locking-issue
> scenario.
Hm, I may have lost my way in the code, but I think ->sch_event is
called _without_ the subchannel lock being held? It is only taken in
e.g. io_subchannel_sch_event.
->chp_event is called with the subchannel lock held, though.
>
> Currently, i am trying to see the "minimal" change i can work on on the
> event-callbacks and the css_evaluate_known_subchannel() call, to make
> sure that, this racy condition can never occur.
>
> Conny,
>
> Please do let me know if you think i am missing something here. I would
> like to concentrate more on the sch->driver() access scenario first and
> would like to see how it can have minimal impact on the event-callbacks.
> especially io_subchannel_sch_event.
Given that the code changing sch->driver holds the device lock, but not
the subchannel lock, you probably need to make sure that the device lock
is held? It has been some time since I've done more complicated work in
the common I/O layer, though, and I might be missing something.
^ permalink raw reply [flat|nested] 26+ messages in thread
end of thread, other threads:[~2021-08-10 15:01 UTC | newest]
Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-26 20:00 [PATCH v2 00/13] Remove vfio_mdev.c, mdev_parent_ops and more Jason Gunthorpe
2021-04-26 20:00 ` [PATCH v2 01/13] vfio/mdev: Remove CONFIG_VFIO_MDEV_DEVICE Jason Gunthorpe
2021-04-27 11:05 ` Cornelia Huck
2021-04-26 20:00 ` [PATCH v2 06/13] vfio/ap_ops: Convert to use vfio_register_group_dev() Jason Gunthorpe
2021-05-04 14:42 ` Tony Krowiak
2021-05-04 16:55 ` Jason Gunthorpe
2021-04-26 20:00 ` [PATCH v2 07/13] vfio/ccw: " Jason Gunthorpe
2021-04-27 20:06 ` Eric Farman
2021-04-27 22:10 ` Jason Gunthorpe
2021-04-28 12:55 ` Eric Farman
2021-04-28 13:21 ` Jason Gunthorpe
2021-04-28 17:09 ` Cornelia Huck
2021-04-28 17:20 ` Jason Gunthorpe
2021-04-29 11:58 ` Cornelia Huck
2021-04-29 18:13 ` Jason Gunthorpe
2021-04-30 12:31 ` Cornelia Huck
2021-04-30 17:19 ` Jason Gunthorpe
2021-05-03 10:54 ` s390 common I/O layer locking (was: [PATCH v2 07/13] vfio/ccw: Convert to use vfio_register_group_dev()) Cornelia Huck
2021-05-04 15:10 ` s390 common I/O layer locking Vineeth Vijayan
2021-07-24 13:24 ` Christoph Hellwig
2021-08-03 14:27 ` Vineeth Vijayan
2021-08-10 15:00 ` Cornelia Huck
2021-04-26 20:00 ` [PATCH v2 11/13] vfio/mdev: Remove mdev_parent_ops Jason Gunthorpe
2021-04-27 21:30 ` [PATCH v2 00/13] Remove vfio_mdev.c, mdev_parent_ops and more Alex Williamson
2021-04-27 22:20 ` Jason Gunthorpe
2021-04-27 22:49 ` Alex Williamson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox