Skip to contentSkip to conversation

cdx: add support for bus mastering

PATCH Superseded Nipun Gupta 3 participants 6 messages Jul 26, 2023 – Jul 28, 2023

Subsystems (3)

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Nipun Gupta

author maintainer
#0 lore raw

PATCH v4 1/2 cdx: add support for bus mastering

Introduce cdx_set_master() and cdx_clear_master() APIs to support enable and disable of bus mastering. Drivers need to use these APIs to enable/disable DMAs from the CDX devices.

---
Changes v3->v4:
- Added user of the Bus master enable and disable APIs in patch 2/2. There is no change in this patch.

Changes v2->v3:
- Changed return value from EOPNOTSUPP to -EOPNOTSUPP in cdx_set_master()

Changes v1->v2:
- Replace bme with bus_master_enable
- Added check for dev_configure API callback
- remove un-necessary error prints
- changed conditional to if-else
- updated commit message to use 72 columns

 drivers/cdx/cdx.c                       | 29 +++++++++++++
 drivers/cdx/controller/cdx_controller.c |  4 ++
 drivers/cdx/controller/mcdi_functions.c | 58 +++++++++++++++++++++++++
 drivers/cdx/controller/mcdi_functions.h | 13 ++++++
 include/linux/cdx/cdx_bus.h             | 16 +++++++
 5 files changed, 120 insertions(+)
drivers/cdx/cdx.c +29 -0
index d2cad4c670a0..10c6281b59c3 100644
@@ -182,6 +182,35 @@ cdx_match_id(const struct cdx_device_id *ids, struct cdx_device *dev)
 	return NULL;
 }
 
+int cdx_set_master(struct cdx_device *cdx_dev)
+{
+	struct cdx_controller *cdx = cdx_dev->cdx;
+	struct cdx_device_config dev_config;
+	int ret = -EOPNOTSUPP;
+
+	dev_config.type = CDX_DEV_BUS_MASTER_CONF;
+	dev_config.bus_master_enable = true;
+	if (cdx->ops->dev_configure)
+		ret = cdx->ops->dev_configure(cdx, cdx_dev->bus_num,
+					      cdx_dev->dev_num, &dev_config);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(cdx_set_master);
+
+void cdx_clear_master(struct cdx_device *cdx_dev)
+{
+	struct cdx_controller *cdx = cdx_dev->cdx;
+	struct cdx_device_config dev_config;
+
+	dev_config.type = CDX_DEV_BUS_MASTER_CONF;
+	dev_config.bus_master_enable = false;
+	if (cdx->ops->dev_configure)
+		cdx->ops->dev_configure(cdx, cdx_dev->bus_num,
+					cdx_dev->dev_num, &dev_config);
+}
+EXPORT_SYMBOL_GPL(cdx_clear_master);
+
 /**
  * cdx_bus_match - device to driver matching callback
  * @dev: the cdx device to match against
drivers/cdx/controller/cdx_controller.c +4 -0
index dc52f95f8978..39aa569d8e07 100644
@@ -55,6 +55,10 @@ static int cdx_configure_device(struct cdx_controller *cdx,
 	case CDX_DEV_RESET_CONF:
 		ret = cdx_mcdi_reset_device(cdx->priv, bus_num, dev_num);
 		break;
+	case CDX_DEV_BUS_MASTER_CONF:
+		ret = cdx_mcdi_bus_master_enable(cdx->priv, bus_num, dev_num,
+						 dev_config->bus_master_enable);
+		break;
 	default:
 		ret = -EINVAL;
 	}
drivers/cdx/controller/mcdi_functions.c +58 -0

61 lines not on this page · raw message

drivers/cdx/controller/mcdi_functions.h +13 -0
index 7440ace5539a..a448d6581eb4 100644
@@ -58,4 +58,17 @@ int cdx_mcdi_get_dev_config(struct cdx_mcdi *cdx,
 int cdx_mcdi_reset_device(struct cdx_mcdi *cdx,
 			  u8 bus_num, u8 dev_num);
 
+/**
+ * cdx_mcdi_bus_master_enable - Set/Reset bus mastering for cdx device
+ *				represented by bus_num:dev_num
+ * @cdx: pointer to MCDI interface.
+ * @bus_num: Bus number.
+ * @dev_num: Device number.
+ * @enable: Enable bus mastering if set, disable otherwise.
+ *
+ * Return: 0 on success, <0 on failure
+ */
+int cdx_mcdi_bus_master_enable(struct cdx_mcdi *cdx, u8 bus_num,
+			       u8 dev_num, bool enable);
+
 #endif /* CDX_MCDI_FUNCTIONS_H */
include/linux/cdx/cdx_bus.h +16 -0
index bead71b7bc73..1816c279879e 100644
@@ -21,11 +21,13 @@
 struct cdx_controller;
 
 enum {
+	CDX_DEV_BUS_MASTER_CONF,
 	CDX_DEV_RESET_CONF,
 };
 
 struct cdx_device_config {
 	u8 type;
+	bool bus_master_enable;
 };
 
 typedef int (*cdx_scan_cb)(struct cdx_controller *cdx);
@@ -170,4 +172,18 @@ extern struct bus_type cdx_bus_type;
  */
 int cdx_dev_reset(struct device *dev);
 
+/**
+ * cdx_set_master - enables bus-mastering for CDX device
+ * @cdx_dev: the CDX device to enable
+ *
+ * Return: 0 for success, -errno on failure
+ */
+int cdx_set_master(struct cdx_device *cdx_dev);
+
+/**
+ * cdx_clear_master - disables bus-mastering for CDX device
+ * @cdx_dev: the CDX device to disable
+ */
+void cdx_clear_master(struct cdx_device *cdx_dev);
+
 #endif /* _CDX_BUS_H_ */
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH v4 2/2 vfio-cdx: add ioctl support for bus master enable

add VFIO_DEVICE_CDX_CTRL IOCTL to expose control operations for CDX devices to VFIO users. Support Bus master enable and Bus master disable on CDX bus control.

---

Changes in v4:
- This patch is newly added which uses cdx_set_master() and cdx_clear_master() APIs.

 drivers/vfio/cdx/main.c   | 26 ++++++++++++++++++++++++++
 include/uapi/linux/vfio.h | 14 ++++++++++++++
 2 files changed, 40 insertions(+)
drivers/vfio/cdx/main.c +26 -0
index c376a69d2db2..c39a965716f4 100644
@@ -98,6 +98,30 @@ static int vfio_cdx_ioctl_get_region_info(struct vfio_cdx_device *vdev,
 	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
 }
 
+static int vfio_cdx_ioctl_ctrl(struct vfio_cdx_device *vdev,
+			       struct vfio_device_cdx_ctrl __user *arg)
+{
+	unsigned long minsz = offsetofend(struct vfio_device_cdx_ctrl, op);
+	struct cdx_device *cdx_dev = to_cdx_device(vdev->vdev.dev);
+	struct vfio_device_cdx_ctrl ops;
+
+	if (copy_from_user(&ops, arg, minsz))
+		return -EFAULT;
+
+	if (ops.argsz < minsz)
+		return -EINVAL;
+
+	switch (ops.op) {
+	case VFIO_CDX_CTRL_CLEAR_MASTER:
+		cdx_clear_master(cdx_dev);
+		return 0;
+	case VFIO_CDX_CTRL_SET_MASTER:
+		return cdx_set_master(cdx_dev);
+	default:
+		return -EINVAL;
+	}
+}
+
 static long vfio_cdx_ioctl(struct vfio_device *core_vdev,
 			   unsigned int cmd, unsigned long arg)
 {
@@ -112,6 +136,8 @@ static long vfio_cdx_ioctl(struct vfio_device *core_vdev,
 		return vfio_cdx_ioctl_get_region_info(vdev, uarg);
 	case VFIO_DEVICE_RESET:
 		return cdx_dev_reset(core_vdev->dev);
+	case VFIO_DEVICE_CDX_CTRL:
+		return vfio_cdx_ioctl_ctrl(vdev, uarg);
 	default:
 		return -ENOTTY;
 	}
include/uapi/linux/vfio.h +14 -0
index 20c804bdc09c..5f6a58f9f8e2 100644
@@ -1649,6 +1649,20 @@ struct vfio_iommu_spapr_tce_remove {
 };
 #define VFIO_IOMMU_SPAPR_TCE_REMOVE	_IO(VFIO_TYPE, VFIO_BASE + 20)
 
+/**
+ * VFIO_DEVICE_CDX_CTRL - _IO(VFIO_TYPE, VFIO_BASE + 21)
+ *
+ * Control CDX device.
+ * Variable op is set as per the operation required
+ */
+struct vfio_device_cdx_ctrl {
+	__u32 argsz;
+	__u32 op;
+#define	VFIO_CDX_CTRL_SET_MASTER	0	/* Set Bus Master */
+#define	VFIO_CDX_CTRL_CLEAR_MASTER	1	/* Clear Bus Master */
+};
+#define VFIO_DEVICE_CDX_CTRL		_IO(VFIO_TYPE, VFIO_BASE + 21)
+
 /* ***************************************************************** */
 
 #endif /* _UAPIVFIO_H */
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 2/2 v4] vfio-cdx: add ioctl support for bus master enable

Quoted 6 lines · Nipun Gupta

add VFIO_DEVICE_CDX_CTRL IOCTL to expose control operations for CDX devices to VFIO users. Support Bus master enable and Bus master disable on CDX bus control.

Who wrote this? The signed-off-by ordering seems odd.

Quoted 59 lines

---

Changes in v4:
- This patch is newly added which uses cdx_set_master() and cdx_clear_master() APIs.

 drivers/vfio/cdx/main.c   | 26 ++++++++++++++++++++++++++
 include/uapi/linux/vfio.h | 14 ++++++++++++++
 2 files changed, 40 insertions(+)
drivers/vfio/cdx/main.c +26 -0
index c376a69d2db2..c39a965716f4 100644
@@ -98,6 +98,30 @@ static int vfio_cdx_ioctl_get_region_info(struct vfio_cdx_device *vdev,
 	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
 }
 
+static int vfio_cdx_ioctl_ctrl(struct vfio_cdx_device *vdev,
+			       struct vfio_device_cdx_ctrl __user *arg)
+{
+	unsigned long minsz = offsetofend(struct vfio_device_cdx_ctrl, op);
+	struct cdx_device *cdx_dev = to_cdx_device(vdev->vdev.dev);
+	struct vfio_device_cdx_ctrl ops;
+
+	if (copy_from_user(&ops, arg, minsz))
+		return -EFAULT;
+
+	if (ops.argsz < minsz)
+		return -EINVAL;
+
+	switch (ops.op) {
+	case VFIO_CDX_CTRL_CLEAR_MASTER:
+		cdx_clear_master(cdx_dev);
+		return 0;
+	case VFIO_CDX_CTRL_SET_MASTER:
+		return cdx_set_master(cdx_dev);
+	default:
+		return -EINVAL;
+	}
+}
+
 static long vfio_cdx_ioctl(struct vfio_device *core_vdev,
 			   unsigned int cmd, unsigned long arg)
 {
@@ -112,6 +136,8 @@ static long vfio_cdx_ioctl(struct vfio_device *core_vdev,
 		return vfio_cdx_ioctl_get_region_info(vdev, uarg);
 	case VFIO_DEVICE_RESET:
 		return cdx_dev_reset(core_vdev->dev);
+	case VFIO_DEVICE_CDX_CTRL:
+		return vfio_cdx_ioctl_ctrl(vdev, uarg);
 	default:
 		return -ENOTTY;
 	}
include/uapi/linux/vfio.h +0 -0
index 20c804bdc09c..5f6a58f9f8e2 100644

include/uapi/linux/vfio.h struct vfio_iommu_spapr_tce_remove { · line 1656

Quoted 8 lines
include/uapi/linux/vfio.h +5 -0
@@ -1649,6 +1649,20 @@ struct vfio_iommu_spapr_tce_remove {
 };
 #define VFIO_IOMMU_SPAPR_TCE_REMOVE	_IO(VFIO_TYPE, VFIO_BASE + 20)
 
+/**
+ * VFIO_DEVICE_CDX_CTRL - _IO(VFIO_TYPE, VFIO_BASE + 21)
+ *
+ * Control CDX device.
+ * Variable op is set as per the operation required

But what is argsz set to?

include/uapi/linux/vfio.h struct vfio_iommu_spapr_tce_remove { · line 1665

Quoted 9 lines
include/uapi/linux/vfio.h +9 -0
+ */
+struct vfio_device_cdx_ctrl {
+	__u32 argsz;
+	__u32 op;
+#define	VFIO_CDX_CTRL_SET_MASTER	0	/* Set Bus Master */
+#define	VFIO_CDX_CTRL_CLEAR_MASTER	1	/* Clear Bus Master */
+};
+#define VFIO_DEVICE_CDX_CTRL		_IO(VFIO_TYPE, VFIO_BASE + 21)
+

Doesn't vfio stuff require a spec and agreement on the interface somewhere? Has that happened here already?

And why an ioctl? Why would userspace care about this type of control?

thanks,

greg k-h

author maintainer
#3 lore raw

Re: [PATCH 2/2 v4] vfio-cdx: add ioctl support for bus master enable

Quoted 73 lines · Greg KH
Quoted 6 lines · Nipun Gupta

add VFIO_DEVICE_CDX_CTRL IOCTL to expose control operations for CDX devices to VFIO users. Support Bus master enable and Bus master disable on CDX bus control.

Who wrote this? The signed-off-by ordering seems odd.

Quoted 62 lines

---

Changes in v4:
- This patch is newly added which uses cdx_set_master() and cdx_clear_master() APIs.

  drivers/vfio/cdx/main.c   | 26 ++++++++++++++++++++++++++
  include/uapi/linux/vfio.h | 14 ++++++++++++++
  2 files changed, 40 insertions(+)
drivers/vfio/cdx/main.c +26 -0
index c376a69d2db2..c39a965716f4 100644
@@ -98,6 +98,30 @@ static int vfio_cdx_ioctl_get_region_info(struct vfio_cdx_device *vdev,
  	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
  }
 
+static int vfio_cdx_ioctl_ctrl(struct vfio_cdx_device *vdev,
+			       struct vfio_device_cdx_ctrl __user *arg)
+{
+	unsigned long minsz = offsetofend(struct vfio_device_cdx_ctrl, op);
+	struct cdx_device *cdx_dev = to_cdx_device(vdev->vdev.dev);
+	struct vfio_device_cdx_ctrl ops;
+
+	if (copy_from_user(&ops, arg, minsz))
+		return -EFAULT;
+
+	if (ops.argsz < minsz)
+		return -EINVAL;
+
+	switch (ops.op) {
+	case VFIO_CDX_CTRL_CLEAR_MASTER:
+		cdx_clear_master(cdx_dev);
+		return 0;
+	case VFIO_CDX_CTRL_SET_MASTER:
+		return cdx_set_master(cdx_dev);
+	default:
+		return -EINVAL;
+	}
+}
+
  static long vfio_cdx_ioctl(struct vfio_device *core_vdev,
  			   unsigned int cmd, unsigned long arg)
  {
@@ -112,6 +136,8 @@ static long vfio_cdx_ioctl(struct vfio_device *core_vdev,
  		return vfio_cdx_ioctl_get_region_info(vdev, uarg);
  	case VFIO_DEVICE_RESET:
  		return cdx_dev_reset(core_vdev->dev);
+	case VFIO_DEVICE_CDX_CTRL:
+		return vfio_cdx_ioctl_ctrl(vdev, uarg);
  	default:
  		return -ENOTTY;
  	}
include/uapi/linux/vfio.h +0 -0
index 20c804bdc09c..5f6a58f9f8e2 100644
@@ -1649,6 +1649,20 @@ struct vfio_iommu_spapr_tce_remove {
  };
  #define VFIO_IOMMU_SPAPR_TCE_REMOVE	_IO(VFIO_TYPE, VFIO_BASE + 20)
 
Quoted 7 lines

include/uapi/linux/vfio.h struct vfio_iommu_spapr_tce_remove { · line 1656

Quoted 5 lines
include/uapi/linux/vfio.h +5 -0
+/**
+ * VFIO_DEVICE_CDX_CTRL - _IO(VFIO_TYPE, VFIO_BASE + 21)
+ *
+ * Control CDX device.
+ * Variable op is set as per the operation required

But what is argsz set to?

This is required to be set as size of the data being passed; which in this case is sizeof(struct vfio_device_cdx_ctrl).

Quoted 13 lines

include/uapi/linux/vfio.h struct vfio_iommu_spapr_tce_remove { · line 1665

Quoted 10 lines
include/uapi/linux/vfio.h +9 -0
+ */
+struct vfio_device_cdx_ctrl {
+	__u32 argsz;
+	__u32 op;
+#define	VFIO_CDX_CTRL_SET_MASTER	0	/* Set Bus Master */
+#define	VFIO_CDX_CTRL_CLEAR_MASTER	1	/* Clear Bus Master */
+};
+#define VFIO_DEVICE_CDX_CTRL		_IO(VFIO_TYPE, VFIO_BASE + 21)
+

Doesn't vfio stuff require a spec and agreement on the interface somewhere? Has that happened here already?

As suggested by Alex, we can use VFIO_DEVICE_FEATURE which seems well suited here.

Quoted 2 lines

And why an ioctl? Why would userspace care about this type of control?

CDX devices are by default in bus master disabled state and user-space drivers will set the bus mastering once appropriate IOMMU mappings have been set-up.

Thanks,
Nipun

Quoted 4 lines

thanks,

greg k-h

#4 lore raw

Re: [PATCH 2/2 v4] vfio-cdx: add ioctl support for bus master enable

In reply to Nipun Gupta
Quoted 75 lines · On Wed, 26 Jul 2023 16:32:20 +0530 Nipun Gupta <[email protected]> wrote:

add VFIO_DEVICE_CDX_CTRL IOCTL to expose control operations for CDX devices to VFIO users. Support Bus master enable and Bus master disable on CDX bus control.

---

Changes in v4:
- This patch is newly added which uses cdx_set_master() and cdx_clear_master() APIs.

 drivers/vfio/cdx/main.c   | 26 ++++++++++++++++++++++++++
 include/uapi/linux/vfio.h | 14 ++++++++++++++
 2 files changed, 40 insertions(+)
drivers/vfio/cdx/main.c +26 -0
index c376a69d2db2..c39a965716f4 100644
@@ -98,6 +98,30 @@ static int vfio_cdx_ioctl_get_region_info(struct vfio_cdx_device *vdev,
 	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
 }
 
+static int vfio_cdx_ioctl_ctrl(struct vfio_cdx_device *vdev,
+			       struct vfio_device_cdx_ctrl __user *arg)
+{
+	unsigned long minsz = offsetofend(struct vfio_device_cdx_ctrl, op);
+	struct cdx_device *cdx_dev = to_cdx_device(vdev->vdev.dev);
+	struct vfio_device_cdx_ctrl ops;
+
+	if (copy_from_user(&ops, arg, minsz))
+		return -EFAULT;
+
+	if (ops.argsz < minsz)
+		return -EINVAL;
+
+	switch (ops.op) {
+	case VFIO_CDX_CTRL_CLEAR_MASTER:
+		cdx_clear_master(cdx_dev);
+		return 0;
+	case VFIO_CDX_CTRL_SET_MASTER:
+		return cdx_set_master(cdx_dev);
+	default:
+		return -EINVAL;
+	}
+}
+
 static long vfio_cdx_ioctl(struct vfio_device *core_vdev,
 			   unsigned int cmd, unsigned long arg)
 {
@@ -112,6 +136,8 @@ static long vfio_cdx_ioctl(struct vfio_device *core_vdev,
 		return vfio_cdx_ioctl_get_region_info(vdev, uarg);
 	case VFIO_DEVICE_RESET:
 		return cdx_dev_reset(core_vdev->dev);
+	case VFIO_DEVICE_CDX_CTRL:
+		return vfio_cdx_ioctl_ctrl(vdev, uarg);
 	default:
 		return -ENOTTY;
 	}
include/uapi/linux/vfio.h +7 -0
index 20c804bdc09c..5f6a58f9f8e2 100644
@@ -1649,6 +1649,20 @@ struct vfio_iommu_spapr_tce_remove {
 };
 #define VFIO_IOMMU_SPAPR_TCE_REMOVE	_IO(VFIO_TYPE, VFIO_BASE + 20)
 
+/**
+ * VFIO_DEVICE_CDX_CTRL - _IO(VFIO_TYPE, VFIO_BASE + 21)
+ *
+ * Control CDX device.
+ * Variable op is set as per the operation required
+ */
+struct vfio_device_cdx_ctrl {

include/uapi/linux/vfio.h struct vfio_iommu_spapr_tce_remove { · line 1668

Quoted 10 lines
include/uapi/linux/vfio.h +7 -0
+	__u32 argsz;
+	__u32 op;
+#define	VFIO_CDX_CTRL_SET_MASTER	0	/* Set Bus Master */
+#define	VFIO_CDX_CTRL_CLEAR_MASTER	1	/* Clear Bus Master */
+};
+#define VFIO_DEVICE_CDX_CTRL		_IO(VFIO_TYPE, VFIO_BASE + 21)
+
 /* ***************************************************************** */
 
 #endif /* _UAPIVFIO_H */

This doesn't follow standard conventions for a vfio ioctl. Not knowing how CDX works, is there really a need for this ioctl vs enabling bus master when the device is opened and clearing it when closed? I think this is effectively the behavior of vfio-platform. Otherwise, I assume this is not a high frequency operation, would the VFIO_DEVICE_FEATURE ioctl be an option? Thanks,

Alex

author maintainer
#5 lore raw

Re: [PATCH 2/2 v4] vfio-cdx: add ioctl support for bus master enable

Quoted 87 lines · Alex Williamson
Quoted 84 lines · On Wed, 26 Jul 2023 16:32:20 +0530 Nipun Gupta <[email protected]> wrote:

add VFIO_DEVICE_CDX_CTRL IOCTL to expose control operations for CDX devices to VFIO users. Support Bus master enable and Bus master disable on CDX bus control.

---

Changes in v4:
- This patch is newly added which uses cdx_set_master() and cdx_clear_master() APIs.

  drivers/vfio/cdx/main.c   | 26 ++++++++++++++++++++++++++
  include/uapi/linux/vfio.h | 14 ++++++++++++++
  2 files changed, 40 insertions(+)
drivers/vfio/cdx/main.c +26 -0
index c376a69d2db2..c39a965716f4 100644
@@ -98,6 +98,30 @@ static int vfio_cdx_ioctl_get_region_info(struct vfio_cdx_device *vdev,
  	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
  }
 
+static int vfio_cdx_ioctl_ctrl(struct vfio_cdx_device *vdev,
+			       struct vfio_device_cdx_ctrl __user *arg)
+{
+	unsigned long minsz = offsetofend(struct vfio_device_cdx_ctrl, op);
+	struct cdx_device *cdx_dev = to_cdx_device(vdev->vdev.dev);
+	struct vfio_device_cdx_ctrl ops;
+
+	if (copy_from_user(&ops, arg, minsz))
+		return -EFAULT;
+
+	if (ops.argsz < minsz)
+		return -EINVAL;
+
+	switch (ops.op) {
+	case VFIO_CDX_CTRL_CLEAR_MASTER:
+		cdx_clear_master(cdx_dev);
+		return 0;
+	case VFIO_CDX_CTRL_SET_MASTER:
+		return cdx_set_master(cdx_dev);
+	default:
+		return -EINVAL;
+	}
+}
+
  static long vfio_cdx_ioctl(struct vfio_device *core_vdev,
  			   unsigned int cmd, unsigned long arg)
  {
@@ -112,6 +136,8 @@ static long vfio_cdx_ioctl(struct vfio_device *core_vdev,
  		return vfio_cdx_ioctl_get_region_info(vdev, uarg);
  	case VFIO_DEVICE_RESET:
  		return cdx_dev_reset(core_vdev->dev);
+	case VFIO_DEVICE_CDX_CTRL:
+		return vfio_cdx_ioctl_ctrl(vdev, uarg);
  	default:
  		return -ENOTTY;
  	}
include/uapi/linux/vfio.h +14 -0
index 20c804bdc09c..5f6a58f9f8e2 100644
@@ -1649,6 +1649,20 @@ struct vfio_iommu_spapr_tce_remove {
  };
  #define VFIO_IOMMU_SPAPR_TCE_REMOVE	_IO(VFIO_TYPE, VFIO_BASE + 20)
 
+/**
+ * VFIO_DEVICE_CDX_CTRL - _IO(VFIO_TYPE, VFIO_BASE + 21)
+ *
+ * Control CDX device.
+ * Variable op is set as per the operation required
+ */
+struct vfio_device_cdx_ctrl {
+	__u32 argsz;
+	__u32 op;
+#define	VFIO_CDX_CTRL_SET_MASTER	0	/* Set Bus Master */
+#define	VFIO_CDX_CTRL_CLEAR_MASTER	1	/* Clear Bus Master */
+};
+#define VFIO_DEVICE_CDX_CTRL		_IO(VFIO_TYPE, VFIO_BASE + 21)
+
  /* ***************************************************************** */
 
Quoted 8 lines

include/uapi/linux/vfio.h struct vfio_iommu_spapr_tce_remove { · line 1668

Quoted 1 line
include/uapi/linux/vfio.h +0 -0
  #endif /* _UAPIVFIO_H */

This doesn't follow standard conventions for a vfio ioctl. Not knowing how CDX works, is there really a need for this ioctl vs enabling bus master when the device is opened and clearing it when closed? I think this is effectively the behavior of vfio-platform. Otherwise, I assume this is not a high frequency operation, would the VFIO_DEVICE_FEATURE ioctl be an option? Thanks,

Thank you for the quick feedback. There are few use-cases where VFIO-cdx users need to explicitly trigger bus master enable/disable. As you suggest VFIO_DEVICE_FEATURE is better suited in this case, and we will move the BME handling in this ioctl.

Regards,
Nipun

Quoted 3 lines

Alex