@@ -161,17 +161,15 @@ static const struct dma_buf_ops vfio_pci_dmabuf_ops = {
.unmap_dma_buf = vfio_pci_dma_buf_unmap,
};
-int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,
- struct vfio_device_feature_dma_buf __user *arg,
- size_t argsz)
+int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev,
+ struct vfio_device_p2p_dma_buf *p2p_dma_buf)
{
- struct vfio_device_feature_dma_buf get_dma_buf;
+ struct vfio_device_p2p_dma_buf get_dma_buf;
DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
struct vfio_pci_dma_buf *priv;
int ret;
- if (copy_from_user(&get_dma_buf, arg, sizeof(get_dma_buf)))
- return -EFAULT;
+ memcpy(&get_dma_buf, p2p_dma_buf, sizeof(get_dma_buf));
/* For PCI the region_index is the BAR number like everything else */
if (get_dma_buf.region_index >= VFIO_PCI_ROM_REGION_INDEX)
@@ -1195,13 +1195,17 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
mutex_unlock(&vdev->vf_token->lock);
return 0;
- case VFIO_DEVICE_FEATURE_DMA_BUF:
- return vfio_pci_core_feature_dma_buf(vdev, feature.flags,
- (void __user *)(arg + minsz),
- feature.argsz);
default:
return -ENOTTY;
}
+ } else if (cmd == VFIO_DEVICE_P2P_DMA_BUF) {
+ struct vfio_device_p2p_dma_buf p2p_dma_buf;
+
+ if (copy_from_user(&p2p_dma_buf, (void __user *)arg,
+ sizeof(p2p_dma_buf)))
+ return -EFAULT;
+
+ return vfio_pci_core_feature_dma_buf(vdev, &p2p_dma_buf);
}
return -ENOTTY;
@@ -5,16 +5,14 @@
int vfio_pci_try_reset_function(struct vfio_pci_core_device *vdev);
#ifdef CONFIG_DMA_SHARED_BUFFER
-int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,
- struct vfio_device_feature_dma_buf __user *arg,
- size_t argsz);
+int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev,
+ struct vfio_device_p2p_dma_buf *arg);
void vfio_pci_dma_buf_cleanup(struct vfio_pci_core_device *vdev);
void vfio_pci_dma_buf_move(struct vfio_pci_core_device *vdev, bool revoked);
#else
static int
-vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,
- struct vfio_device_feature_dma_buf __user *arg,
- size_t argsz)
+vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev,
+ struct vfio_device_p2p_dma_buf *arg)
{
return -ENOTTY;
}
@@ -1012,13 +1012,23 @@ struct vfio_device_feature {
*
* Return: The fd number on success, -1 and errno is set on failure.
*/
-struct vfio_device_feature_dma_buf {
+
+/**
+ * VFIO_DEVICE_P2P_DMA_BUF - _IORW(VFIO_TYPE, VFIO_BASE + 22,
+ * struct vfio_device_p2p_dma_buf)
+ *
+ * Set the region index, open flags, offset and length to create a dma_buf
+ * for p2p dma.
+ *
+ * Return 0 on success, -errno on failure.
+ */
+struct vfio_device_p2p_dma_buf {
__u32 region_index;
__u32 open_flags;
__u32 offset;
__u64 length;
};
-#define VFIO_DEVICE_FEATURE_DMA_BUF 3 // FIXME numbers wrong
+#define VFIO_DEVICE_P2P_DMA_BUF _IO(VFIO_TYPE, VFIO_BASE + 22)
/* -------- API for Type1 VFIO IOMMU -------- */
Introduce new ioctl number for VFIO P2P dmabuf, with ioctl input struct vfio_device_p2p_dma_buf. Signed-off-by: William Tu <witu@nvidia.com> --- drivers/vfio/pci/dma_buf.c | 10 ++++------ drivers/vfio/pci/vfio_pci_core.c | 12 ++++++++---- drivers/vfio/pci/vfio_pci_priv.h | 10 ++++------ include/uapi/linux/vfio.h | 14 ++++++++++++-- 4 files changed, 28 insertions(+), 18 deletions(-)