[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230803143253.7817-3-nipun.gupta@amd.com>
Date: Thu, 3 Aug 2023 20:02:53 +0530
From: Nipun Gupta <nipun.gupta@....com>
To: <gregkh@...uxfoundation.org>, <alex.williamson@...hat.com>,
<linux-kernel@...r.kernel.org>
CC: <git@....com>, <pieter.jansen-van-vuuren@....com>,
<nikhil.agarwal@....com>, <michal.simek@....com>,
<abhijit.gangurde@....com>, Nipun Gupta <nipun.gupta@....com>,
Shubham Rohila <shubham.rohila@....com>
Subject: [PATCH v5 3/3] vfio-cdx: add bus mastering device feature support
Support Bus master enable and disable on VFIO-CDX devices using
VFIO_DEVICE_FEATURE_BUS_MASTER flag over VFIO_DEVICE_FEATURE IOCTL.
Co-developed-by: Shubham Rohila <shubham.rohila@....com>
Signed-off-by: Shubham Rohila <shubham.rohila@....com>
Signed-off-by: Nipun Gupta <nipun.gupta@....com>
---
Changes v4->v5:
- Use device feature IOCTL instead of adding a new VFIO IOCTL
for bus master feature.
Changes in v4:
- This patch is newly added which uses cdx_set_master() and
cdx_clear_master() APIs.
drivers/vfio/cdx/main.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/drivers/vfio/cdx/main.c b/drivers/vfio/cdx/main.c
index c376a69d2db2..6420cf6eb2f9 100644
--- a/drivers/vfio/cdx/main.c
+++ b/drivers/vfio/cdx/main.c
@@ -52,6 +52,45 @@ static void vfio_cdx_close_device(struct vfio_device *core_vdev)
cdx_dev_reset(core_vdev->dev);
}
+static int vfio_cdx_bm_ctrl(struct vfio_device *core_vdev, u32 flags,
+ void __user *arg, size_t argsz)
+{
+ size_t minsz =
+ offsetofend(struct vfio_device_feature_bus_master, op);
+ struct cdx_device *cdx_dev = to_cdx_device(core_vdev->dev);
+ struct vfio_device_feature_bus_master ops;
+ int ret;
+
+ ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET,
+ sizeof(ops));
+ if (ret != 1)
+ return ret;
+
+ if (copy_from_user(&ops, arg, minsz))
+ return -EFAULT;
+
+ switch (ops.op) {
+ case VFIO_DEVICE_FEATURE_CLEAR_MASTER:
+ cdx_clear_master(cdx_dev);
+ return 0;
+ case VFIO_DEVICE_FEATURE_SET_MASTER:
+ return cdx_set_master(cdx_dev);
+ default:
+ return -EINVAL;
+ }
+}
+
+static int vfio_cdx_ioctl_feature(struct vfio_device *device, u32 flags,
+ void __user *arg, size_t argsz)
+{
+ switch (flags & VFIO_DEVICE_FEATURE_MASK) {
+ case VFIO_DEVICE_FEATURE_BUS_MASTER:
+ return vfio_cdx_bm_ctrl(device, flags, arg, argsz);
+ default:
+ return -ENOTTY;
+ }
+}
+
static int vfio_cdx_ioctl_get_info(struct vfio_cdx_device *vdev,
struct vfio_device_info __user *arg)
{
@@ -169,6 +208,7 @@ static const struct vfio_device_ops vfio_cdx_ops = {
.open_device = vfio_cdx_open_device,
.close_device = vfio_cdx_close_device,
.ioctl = vfio_cdx_ioctl,
+ .device_feature = vfio_cdx_ioctl_feature,
.mmap = vfio_cdx_mmap,
.bind_iommufd = vfio_iommufd_physical_bind,
.unbind_iommufd = vfio_iommufd_physical_unbind,
--
2.17.1
Powered by blists - more mailing lists