vDPA: API for reporting IOVA range
Subsystems (2)
cover vDPA: API for reporting IOVA range
Hi All:
This series introduces API for reporing IOVA range. This is a must for userspace to work correclty:
- for the process that uses vhost-vDPA directly to properly allocate IOVA
- for VM(qemu), when vIOMMU is not enabled, fail early if GPA is out of range
- for VM(qemu), when vIOMMU is enabled, determine a valid guest address width
Please review.
Thanks
Jason Wang (4):
vdpa: introduce config op to get valid iova range
vdpa_sim: implement get_iova_range bus operation
vdpa: get_iova_range() is mandatory for device specific DMA
translation
vhost: vdpa: report iova range
drivers/vdpa/vdpa.c | 4 ++++ drivers/vdpa/vdpa_sim/vdpa_sim.c | 11 +++++++++++ drivers/vhost/vdpa.c | 27 +++++++++++++++++++++++++++ include/linux/vdpa.h | 14 ++++++++++++++ include/uapi/linux/vhost.h | 4 ++++ include/uapi/linux/vhost_types.h | 5 +++++ 6 files changed, 65 insertions(+)
Signature · 1 line
2.20.1
PATCH 1/4 vdpa: introduce config op to get valid iova range
This patch introduce a config op to get valid iova range from the vDPA device.
--- include/linux/vdpa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/linux/vdpa.h +14 -0
@@ -41,6 +41,16 @@ struct vdpa_device {unsigned int index; }; +/** +* vDPA IOVA range - the IOVA range support by the device +* @start: start of the IOVA range +* @end: end of the IOVA range +*/ +struct vdpa_iova_range { +u64 start; +u64 end; +}; +/** * vDPA_config_ops - operations for configuring a vDPA device. * Note: vDPA device drivers are required to implement all of the
@@ -134,6 +144,9 @@ struct vdpa_device {* @get_generation: Get device config generation (optional) * @vdev: vdpa device * Returns u32: device generation +* @get_iova_range: Get supported iova range (on-chip IOMMU) +* @vdev: vdpa device +* Returns the iova range supported by the device * @set_map: Set device memory mapping (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU)
@@ -195,6 +208,7 @@ struct vdpa_config_ops {void (*set_config)(struct vdpa_device *vdev,unsigned int offset,const void *buf,unsigned int len);u32 (*get_generation)(struct vdpa_device *vdev); +struct vdpa_iova_range (*get_iova_range)(struct vdpa_device *vdev);/* DMA ops */ int (*set_map)(struct vdpa_device *vdev,struct vhost_iotlb *iotlb);
Signature · 1 line
2.20.1
PATCH 2/4 vdpa_sim: implement get_iova_range bus operation
In reply to Jason WangThis patch implements get_iova_range method for vdpa_sim. Since vdpa_sim is a software device, simply advertise a [0ULL, ~0ULL] range.
--- drivers/vdpa/vdpa_sim/vdpa_sim.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/vdpa/vdpa_sim/vdpa_sim.c +11 -0
@@ -524,6 +524,16 @@ static u32 vdpasim_get_generation(struct vdpa_device *vdpa)return vdpasim->generation; } +static struct vdpa_iova_range vdpasim_get_iova_range (struct vdpa_device *vdpa) +{ +struct vdpa_iova_range range; + + range.start =0ULL ; + range.end = ~0ULL ; + +return range; +} +static int vdpasim_set_map (struct vdpa_device *vdpa,struct vhost_iotlb *iotlb) {
@@ -597,6 +607,7 @@ static const struct vdpa_config_ops vdpasim_net_config_ops = { .get_config = vdpasim_get_config, .set_config = vdpasim_set_config, .get_generation = vdpasim_get_generation, + .get_iova_range = vdpasim_get_iova_range, .set_map = vdpasim_set_map, .dma_map = vdpasim_dma_map, .dma_unmap = vdpasim_dma_unmap,
Signature · 1 line
2.20.1
PATCH 3/4 vdpa: get_iova_range() is mandatory for device specific DMA translation
In reply to Jason WangIn order to let userspace work correctly, get_iova_range() is a must for the device that has its own DMA translation logic.
--- drivers/vdpa/vdpa.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/vdpa/vdpa.c +4 -0
@@ -82,6 +82,10 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,if (!!config->dma_map != !!config->dma_unmap) goto err; +if ((config->dma_map || config->set_map) && + !config->get_iova_range) + goto err; + err = -ENOMEM ; vdev =kzalloc (size,GFP_KERNEL );if (!vdev)
Signature · 1 line
2.20.1
PATCH 4/4 vhost: vdpa: report iova range
In reply to Jason WangThis patch introduces a new ioctl for vhost-vdpa device that can report the iova range by the device. For device that depends on platform IOMMU, we fetch the iova range via DOMAIN_ATTR_GEOMETRY. For devices that has its own DMA translation unit, we fetch it directly from vDPA bus operation.
--- drivers/vhost/vdpa.c | 27 +++++++++++++++++++++++++++ include/uapi/linux/vhost.h | 4 ++++ include/uapi/linux/vhost_types.h | 5 +++++ 3 files changed, 36 insertions(+)
drivers/vhost/vdpa.c +27 -0
@@ -332,6 +332,30 @@ static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp)return 0 ; } + +static long vhost_vdpa_get_iova_range (struct vhost_vdpa *v,u32 __user *argp) +{ +struct iommu_domain_geometry geo; +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; +struct vhost_vdpa_iova_range range; +struct vdpa_iova_range vdpa_range; + +if (!ops->set_map && !ops->dma_map) { +iommu_domain_get_attr (v->domain, +DOMAIN_ATTR_GEOMETRY , &geo); + range.start = geo.aperture_start; + range.end = geo.aperture_end; + }else { + vdpa_range = ops->get_iova_range (vdpa); + range.start = vdpa_range.start; + range.end = vdpa_range.end; + } + +return copy_to_user (argp, &range,sizeof (range)); + +} +static long vhost_vdpa_vring_ioctl (struct vhost_vdpa *v,unsigned int cmd,void __user *argp) {
@@ -442,6 +466,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,case VHOST_VDPA_SET_CONFIG_CALL : r =vhost_vdpa_set_config_call (v, argp);break ; +case VHOST_VDPA_GET_IOVA_RANGE : + r =vhost_vdpa_get_iova_range (v, argp); +break ;default : r =vhost_dev_ioctl (&v->vdev, cmd, argp);if (r == -ENOIOCTLCMD )
include/uapi/linux/vhost.h +4 -0
@@ -144,4 +144,8 @@/* Set event fd for config interrupt*/ #define VHOST_VDPA_SET_CONFIG_CALL _IOW(VHOST_VIRTIO, 0x77, int) + +/* Get the valid iova range */ +#define VHOST_VDPA_GET_IOVA_RANGE _IOW(VHOST_VIRTIO, 0x78, \ + struct vhost_vdpa_iova_range)#endif
include/uapi/linux/vhost_types.h +5 -0
@@ -127,6 +127,11 @@ struct vhost_vdpa_config {__u8 buf[0 ]; }; +struct vhost_vdpa_iova_range { +__u64 start; +__u64 end; +}; +/* Feature bits */ /* Log all write descriptors. Can be changed while device is active. */ #define VHOST_F_LOG_ALL 26
Signature · 1 line
2.20.1
Michael S. Tsirkin
maintainerRe: [PATCH 1/4] vdpa: introduce config op to get valid iova range
In reply to Jason WangQuoted 16 lines · Jason Wang
This patch introduce a config op to get valid iova range from the vDPA device.
Signed-off-by Jason Wang <[email protected]>--- include/linux/vdpa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/vdpa.h +0
-0@@ -41,6 +41,16 @@ struct vdpa_device {unsigned int index; };
include/linux/vdpa.h struct vdpa_device { · line 53
Quoted 10 lines
include/linux/vdpa.h +10
-0+/** +* vDPA IOVA range - the IOVA range support by the device +* @start: start of the IOVA range +* @end: end of the IOVA range +*/ +struct vdpa_iova_range { +u64 start; +u64 end; +}; +
This is ambiguous. Is end in the range or just behind it? How about first/last?
Quoted 23 lines
include/linux/vdpa.h +4
-0/** * vDPA_config_ops - operations for configuring a vDPA device. * Note: vDPA device drivers are required to implement all of the @@ -134,6 +144,9 @@ struct vdpa_device {* @get_generation: Get device config generation (optional) * @vdev: vdpa device * Returns u32: device generation +* @get_iova_range: Get supported iova range (on-chip IOMMU) +* @vdev: vdpa device +* Returns the iova range supported by the device * @set_map: Set device memory mapping (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU) @@ -195,6 +208,7 @@ struct vdpa_config_ops {void (*set_config)(struct vdpa_device *vdev,unsigned int offset,const void *buf,unsigned int len);u32 (*get_generation)(struct vdpa_device *vdev); +struct vdpa_iova_range (*get_iova_range)(struct vdpa_device *vdev);/* DMA ops */ int (*set_map)(struct vdpa_device *vdev,struct vhost_iotlb *iotlb);Signature · 1 line
2.20.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerRe: [PATCH 3/4] vdpa: get_iova_range() is mandatory for device specific DMA translation
In reply to Jason WangQuoted 2 lines · Jason Wang
In order to let userspace work correctly,
get_iova_range()is a must for the device that has its own DMA translation logic.
I guess you mean for a device.
However in absence of ths op, I don't see what is wrong with just assuming device can access any address.
Quoted 11 lines
Signed-off-by Jason Wang <[email protected]>--- drivers/vdpa/vdpa.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/vdpa/vdpa.c +0
-0
drivers/vdpa/vdpa.c struct vdpa_device *__vdpa_alloc_device(struct device *parent, · line 91
Quoted 10 lines
drivers/vdpa/vdpa.c +4
-0@@ -82,6 +82,10 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,if (!!config->dma_map != !!config->dma_unmap) goto err; +if ((config->dma_map || config->set_map) && + !config->get_iova_range) + goto err; + err = -ENOMEM ; vdev =kzalloc (size,GFP_KERNEL );if (!vdev)
What about devices using an IOMMU for translation? IOMMUs generally have a limited IOVA range too, right?
Quoted 2 lines
Signature · 1 line
2.20.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerRe: [PATCH 4/4] vhost: vdpa: report iova range
In reply to Jason WangQuoted 21 lines · Jason Wang
This patch introduces a new ioctl for vhost-vdpa device that can report the iova range by the device. For device that depends on platform IOMMU, we fetch the iova range via
DOMAIN_ATTR_GEOMETRY. For devices that has its own DMA translation unit, we fetch it directly from vDPA bus operation.Signed-off-by Jason Wang <[email protected]>--- drivers/vhost/vdpa.c | 27 +++++++++++++++++++++++++++ include/uapi/linux/vhost.h | 4 ++++ include/uapi/linux/vhost_types.h | 5 +++++ 3 files changed, 36 insertions(+)drivers/vhost/vdpa.c +0
-0@@ -332,6 +332,30 @@ static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp)return 0 ; }
drivers/vhost/vdpa.c static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp) · line 344
Quoted 10 lines
drivers/vhost/vdpa.c +10
-0+ +static long vhost_vdpa_get_iova_range (struct vhost_vdpa *v,u32 __user *argp) +{ +struct iommu_domain_geometry geo; +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; +struct vhost_vdpa_iova_range range; +struct vdpa_iova_range vdpa_range; + +if (!ops->set_map && !ops->dma_map) {
Why not just check if (ops->get_iova_range) directly?
Quoted 45 lines
drivers/vhost/vdpa.c +17
-0+iommu_domain_get_attr (v->domain, +DOMAIN_ATTR_GEOMETRY , &geo); + range.start = geo.aperture_start; + range.end = geo.aperture_end; + }else { + vdpa_range = ops->get_iova_range (vdpa); + range.start = vdpa_range.start; + range.end = vdpa_range.end; + } + +return copy_to_user (argp, &range,sizeof (range)); + +} +static long vhost_vdpa_vring_ioctl (struct vhost_vdpa *v,unsigned int cmd,void __user *argp) {@@ -442,6 +466,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,case VHOST_VDPA_SET_CONFIG_CALL : r =vhost_vdpa_set_config_call (v, argp);break ; +case VHOST_VDPA_GET_IOVA_RANGE : + r =vhost_vdpa_get_iova_range (v, argp); +break ;default : r =vhost_dev_ioctl (&v->vdev, cmd, argp);if (r == -ENOIOCTLCMD )include/uapi/linux/vhost.h +4
-0@@ -144,4 +144,8 @@/* Set event fd for config interrupt*/ #define VHOST_VDPA_SET_CONFIG_CALL _IOW(VHOST_VIRTIO, 0x77, int) + +/* Get the valid iova range */ +#define VHOST_VDPA_GET_IOVA_RANGE _IOW(VHOST_VIRTIO, 0x78, \ + struct vhost_vdpa_iova_range)#endif include/uapi/linux/vhost_types.h +0
-0
include/uapi/linux/vhost_types.h struct vhost_vdpa_config { · line 134
Quoted 8 lines
include/uapi/linux/vhost_types.h +5
-0@@ -127,6 +127,11 @@ struct vhost_vdpa_config {__u8 buf[0 ]; }; +struct vhost_vdpa_iova_range { +__u64 start; +__u64 end; +}; +
Pls document fields. And I think first/last is a better API ...
Quoted 5 lines
include/uapi/linux/vhost_types.h +0
-0/* Feature bits */ /* Log all write descriptors. Can be changed while device is active. */ #define VHOST_F_LOG_ALL 26Signature · 1 line
2.20.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 1/4] vdpa: introduce config op to get valid iova range
In reply to Michael S. TsirkinQuoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Jason Wang
This patch introduce a config op to get valid iova range from the vDPA device.
Signed-off-by Jason Wang<[email protected]>--- include/linux/vdpa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/vdpa.h +0
-0@@ -41,6 +41,16 @@ struct vdpa_device {unsigned int index; };
Quoted 11 lines
include/linux/vdpa.h struct vdpa_device { · line 53
Quoted 10 lines
include/linux/vdpa.h +10
-0+/** +* vDPA IOVA range - the IOVA range support by the device +* @start: start of the IOVA range +* @end: end of the IOVA range +*/ +struct vdpa_iova_range { +u64 start; +u64 end; +}; +This is ambiguous. Is end in the range or just behind it?
In the range.
Quoted 1 line
How about first/last?
Sure.
Thanks
Quoted 3 lines
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 3/4] vdpa: get_iova_range() is mandatory for device specific DMA translation
In reply to Michael S. TsirkinQuoted 7 lines · Michael S. Tsirkin
Quoted 2 lines · Jason Wang
In order to let userspace work correctly,
get_iova_range()is a must for the device that has its own DMA translation logic.I guess you mean for a device.
However in absence of ths op, I don't see what is wrong with just assuming device can access any address.
It's just for safe, if you want, we can assume any address without this op.
Quoted 14 lines
Quoted 14 lines
Signed-off-by Jason Wang <[email protected]>--- drivers/vdpa/vdpa.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/vdpa/vdpa.c +0
-0@@ -82,6 +82,10 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,if (!!config->dma_map != !!config->dma_unmap) goto err;
Quoted 9 lines
drivers/vdpa/vdpa.c struct vdpa_device *__vdpa_alloc_device(struct device *parent, · line 91
Quoted 7 lines
drivers/vdpa/vdpa.c +4
-0+if ((config->dma_map || config->set_map) && + !config->get_iova_range) + goto err; + err = -ENOMEM ; vdev =kzalloc (size,GFP_KERNEL );if (!vdev)What about devices using an IOMMU for translation? IOMMUs generally have a limited IOVA range too, right?
See patch 4 which query the IOMMU geometry in this case:
+ iommu_domain_get_attr(v->domain,
+ DOMAIN_ATTR_GEOMETRY, &geo); + range.start = geo.aperture_start; + range.end = geo.aperture_end;
Thanks
Quoted 5 lines
Quoted 5 lines
Signature · 2 lines
-- 2.20.1
Re: [PATCH 4/4] vhost: vdpa: report iova range
In reply to Michael S. TsirkinQuoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Jason Wang
This patch introduces a new ioctl for vhost-vdpa device that can report the iova range by the device. For device that depends on platform IOMMU, we fetch the iova range via
DOMAIN_ATTR_GEOMETRY. For devices that has its own DMA translation unit, we fetch it directly from vDPA bus operation.Signed-off-by Jason Wang <[email protected]>--- drivers/vhost/vdpa.c | 27 +++++++++++++++++++++++++++ include/uapi/linux/vhost.h | 4 ++++ include/uapi/linux/vhost_types.h | 5 +++++ 3 files changed, 36 insertions(+)drivers/vhost/vdpa.c +0
-0@@ -332,6 +332,30 @@ static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp)
Quoted 13 lines
drivers/vhost/vdpa.c static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp) · line 344
Quoted 12 lines
drivers/vhost/vdpa.c +10
-0return 0 ; } + +static long vhost_vdpa_get_iova_range (struct vhost_vdpa *v,u32 __user *argp) +{ +struct iommu_domain_geometry geo; +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; +struct vhost_vdpa_iova_range range; +struct vdpa_iova_range vdpa_range; + +if (!ops->set_map && !ops->dma_map) {Why not just check if (
ops->get_iova_range) directly?
Because set_map || dma_ops is a hint that the device has its own DMA translation logic.
Device without get_iova_range does not necessarily meant it use IOMMU driver.
Thanks
Quoted 65 lines
Quoted 49 lines
drivers/vhost/vdpa.c +17
-0+iommu_domain_get_attr (v->domain, +DOMAIN_ATTR_GEOMETRY , &geo); + range.start = geo.aperture_start; + range.end = geo.aperture_end; + }else { + vdpa_range = ops->get_iova_range (vdpa); + range.start = vdpa_range.start; + range.end = vdpa_range.end; + } + +return copy_to_user (argp, &range,sizeof (range)); + +} +static long vhost_vdpa_vring_ioctl (struct vhost_vdpa *v,unsigned int cmd,void __user *argp) {@@ -442,6 +466,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,case VHOST_VDPA_SET_CONFIG_CALL : r =vhost_vdpa_set_config_call (v, argp);break ; +case VHOST_VDPA_GET_IOVA_RANGE : + r =vhost_vdpa_get_iova_range (v, argp); +break ;default : r =vhost_dev_ioctl (&v->vdev, cmd, argp);if (r == -ENOIOCTLCMD )include/uapi/linux/vhost.h +4
-0@@ -144,4 +144,8 @@/* Set event fd for config interrupt*/ #define VHOST_VDPA_SET_CONFIG_CALL _IOW(VHOST_VIRTIO, 0x77, int) + +/* Get the valid iova range */ +#define VHOST_VDPA_GET_IOVA_RANGE _IOW(VHOST_VIRTIO, 0x78, \ + struct vhost_vdpa_iova_range)#endif include/uapi/linux/vhost_types.h +0
-0include/uapi/linux/vhost_types.h struct vhost_vdpa_config { · line 134
Quoted 8 lines
include/uapi/linux/vhost_types.h +5
-0@@ -127,6 +127,11 @@ struct vhost_vdpa_config {__u8 buf[0 ]; }; +struct vhost_vdpa_iova_range { +__u64 start; +__u64 end; +}; +Pls document fields. And I think first/last is a better API ...
Quoted 5 lines
include/uapi/linux/vhost_types.h +0
-0/* Feature bits */ /* Log all write descriptors. Can be changed while device is active. */ #define VHOST_F_LOG_ALL 26Signature · 1 line
2.20.1
Michael S. Tsirkin
maintainerRe: [PATCH 1/4] vdpa: introduce config op to get valid iova range
In reply to Jason WangQuoted 31 lines · Jason Wang
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Jason Wang
This patch introduce a config op to get valid iova range from the vDPA device.
Signed-off-by Jason Wang<[email protected]>--- include/linux/vdpa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/vdpa.h +3
-0@@ -41,6 +41,16 @@ struct vdpa_device {unsigned int index; }; +/** +* vDPA IOVA range - the IOVA range support by the device +* @start: start of the IOVA range Quoted 8 lines
include/linux/vdpa.h struct vdpa_device { · line 53
Quoted 7 lines
include/linux/vdpa.h +7
-0+* @end: end of the IOVA range +*/ +struct vdpa_iova_range { +u64 start; +u64 end; +}; +This is ambiguous. Is end in the range or just behind it?
Quoted 1 line
In the range.
OK I guess we can treat it as a bugfix and merge after rc1, but pls add a bit more in the commit log about what's currently broken.
Quoted 12 lines
Quoted 2 lines
How about first/last?
Sure.
Thanks
Quoted 3 lines
Michael S. Tsirkin
maintainerRe: [PATCH 4/4] vhost: vdpa: report iova range
In reply to Jason WangQuoted 36 lines · Jason Wang
Quoted 24 lines · Michael S. Tsirkin
Quoted 23 lines · Jason Wang
This patch introduces a new ioctl for vhost-vdpa device that can report the iova range by the device. For device that depends on platform IOMMU, we fetch the iova range via
DOMAIN_ATTR_GEOMETRY. For devices that has its own DMA translation unit, we fetch it directly from vDPA bus operation.Signed-off-by Jason Wang <[email protected]>--- drivers/vhost/vdpa.c | 27 +++++++++++++++++++++++++++ include/uapi/linux/vhost.h | 4 ++++ include/uapi/linux/vhost_types.h | 5 +++++ 3 files changed, 36 insertions(+)drivers/vhost/vdpa.c +3
-0@@ -332,6 +332,30 @@ static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp)return 0 ; } + +static long vhost_vdpa_get_iova_range (struct vhost_vdpa *v,u32 __user *argp) +{Quoted 8 lines
drivers/vhost/vdpa.c static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp) · line 344
Quoted 7 lines
drivers/vhost/vdpa.c +7
-0+struct iommu_domain_geometry geo; +struct vdpa_device *vdpa = v->vdpa; +const struct vdpa_config_ops *ops = vdpa->config; +struct vhost_vdpa_iova_range range; +struct vdpa_iova_range vdpa_range; + +if (!ops->set_map && !ops->dma_map) {Why not just check if (
ops->get_iova_range) directly?
Quoted 7 lines
Because
set_map||dma_opsis a hint that the device has its own DMA translation logic.Device without
get_iova_rangedoes not necessarily meant it use IOMMU driver.Thanks
OK let's add some code comments please, and check get_iova_range is actually there before calling.
Quoted 64 lines
Quoted 64 lines
Quoted 49 lines
drivers/vhost/vdpa.c +17
-0+iommu_domain_get_attr (v->domain, +DOMAIN_ATTR_GEOMETRY , &geo); + range.start = geo.aperture_start; + range.end = geo.aperture_end; + }else { + vdpa_range = ops->get_iova_range (vdpa); + range.start = vdpa_range.start; + range.end = vdpa_range.end; + } + +return copy_to_user (argp, &range,sizeof (range)); + +} +static long vhost_vdpa_vring_ioctl (struct vhost_vdpa *v,unsigned int cmd,void __user *argp) {@@ -442,6 +466,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,case VHOST_VDPA_SET_CONFIG_CALL : r =vhost_vdpa_set_config_call (v, argp);break ; +case VHOST_VDPA_GET_IOVA_RANGE : + r =vhost_vdpa_get_iova_range (v, argp); +break ;default : r =vhost_dev_ioctl (&v->vdev, cmd, argp);if (r == -ENOIOCTLCMD )include/uapi/linux/vhost.h +4
-0@@ -144,4 +144,8 @@/* Set event fd for config interrupt*/ #define VHOST_VDPA_SET_CONFIG_CALL _IOW(VHOST_VIRTIO, 0x77, int) + +/* Get the valid iova range */ +#define VHOST_VDPA_GET_IOVA_RANGE _IOW(VHOST_VIRTIO, 0x78, \ + struct vhost_vdpa_iova_range)#endif include/uapi/linux/vhost_types.h +0
-0include/uapi/linux/vhost_types.h struct vhost_vdpa_config { · line 133
Quoted 7 lines
include/uapi/linux/vhost_types.h +5
-0@@ -127,6 +127,11 @@ struct vhost_vdpa_config {__u8 buf[0 ]; }; +struct vhost_vdpa_iova_range { +__u64 start; +__u64 end; +}; +Pls document fields. And I think first/last is a better API ...
Quoted 5 lines
include/uapi/linux/vhost_types.h +0
-0/* Feature bits */ /* Log all write descriptors. Can be changed while device is active. */ #define VHOST_F_LOG_ALL 26Signature · 1 line
2.20.1
Michael S. Tsirkin
maintainerRe: [PATCH 1/4] vdpa: introduce config op to get valid iova range
In reply to Eli CohenQuoted 33 lines · Eli Cohen
Quoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Jason Wang
This patch introduce a config op to get valid iova range from the vDPA device.
Signed-off-by Jason Wang <[email protected]>--- include/linux/vdpa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/vdpa.h +0
-0@@ -41,6 +41,16 @@ struct vdpa_device {unsigned int index; };Quoted 14 lines
include/linux/vdpa.h struct vdpa_device { · line 53
Quoted 10 lines
include/linux/vdpa.h +10
-0+/** +* vDPA IOVA range - the IOVA range support by the device +* @start: start of the IOVA range +* @end: end of the IOVA range +*/ +struct vdpa_iova_range { +u64 start; +u64 end; +}; +This is ambiguous. Is end in the range or just behind it? How about first/last?
Quoted 3 lines
It is customary in the kernel to use start-end where end corresponds to the byte following the last in the range. See struct
vm_area_structvm_startandvm_endfields
Exactly my point:
include/linux/mm_types.h: unsigned long vm_end; /* The first byte after our end address
in this case Jason wants it to be the last byte, not one behind.
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
include/linux/vdpa.h +4
-0/** * vDPA_config_ops - operations for configuring a vDPA device. * Note: vDPA device drivers are required to implement all of the @@ -134,6 +144,9 @@ struct vdpa_device {* @get_generation: Get device config generation (optional) * @vdev: vdpa device * Returns u32: device generation +* @get_iova_range: Get supported iova range (on-chip IOMMU) +* @vdev: vdpa device +* Returns the iova range supported by the device * @set_map: Set device memory mapping (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU) @@ -195,6 +208,7 @@ struct vdpa_config_ops {void (*set_config)(struct vdpa_device *vdev,unsigned int offset,const void *buf,unsigned int len);u32 (*get_generation)(struct vdpa_device *vdev); +struct vdpa_iova_range (*get_iova_range)(struct vdpa_device *vdev);
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
include/linux/vdpa.h +0
-0/* DMA ops */ int (*set_map)(struct vdpa_device *vdev,struct vhost_iotlb *iotlb);Signature · 1 line
2.20.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 1/4] vdpa: introduce config op to get valid iova range
In reply to Jason WangQuoted 16 lines · Jason Wang
This patch introduce a config op to get valid iova range from the vDPA device.
Signed-off-by Jason Wang <[email protected]>--- include/linux/vdpa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/vdpa.h +0
-0@@ -41,6 +41,16 @@ struct vdpa_device {unsigned int index; };
include/linux/vdpa.h struct vdpa_device { · line 53
Quoted 10 lines
include/linux/vdpa.h +10
-0+/** +* vDPA IOVA range - the IOVA range support by the device +* @start: start of the IOVA range +* @end: end of the IOVA range +*/ +struct vdpa_iova_range { +u64 start; +u64 end; +}; +
What do you do with this information? Suppose some device tells you it supports some limited range, say, from 0x40000000 to 0x80000000. What does qemu do with this information?
Quoted 24 lines
include/linux/vdpa.h +4
-0/** * vDPA_config_ops - operations for configuring a vDPA device. * Note: vDPA device drivers are required to implement all of the @@ -134,6 +144,9 @@ struct vdpa_device {* @get_generation: Get device config generation (optional) * @vdev: vdpa device * Returns u32: device generation +* @get_iova_range: Get supported iova range (on-chip IOMMU) +* @vdev: vdpa device +* Returns the iova range supported by the device * @set_map: Set device memory mapping (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU) @@ -195,6 +208,7 @@ struct vdpa_config_ops {void (*set_config)(struct vdpa_device *vdev,unsigned int offset,const void *buf,unsigned int len);u32 (*get_generation)(struct vdpa_device *vdev); +struct vdpa_iova_range (*get_iova_range)(struct vdpa_device *vdev);/* DMA ops */ int (*set_map)(struct vdpa_device *vdev,struct vhost_iotlb *iotlb);Signature · 1 line
2.20.1
Re: [PATCH 1/4] vdpa: introduce config op to get valid iova range
In reply to Michael S. TsirkinQuoted 38 lines · Michael S. Tsirkin
Quoted 33 lines · Eli Cohen
Quoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Jason Wang
This patch introduce a config op to get valid iova range from the vDPA device.
Signed-off-by Jason Wang <[email protected]>--- include/linux/vdpa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/vdpa.h +0
-0@@ -41,6 +41,16 @@ struct vdpa_device {unsigned int index; };Quoted 14 lines
include/linux/vdpa.h struct vdpa_device { · line 53
Quoted 10 lines
include/linux/vdpa.h +10
-0+/** +* vDPA IOVA range - the IOVA range support by the device +* @start: start of the IOVA range +* @end: end of the IOVA range +*/ +struct vdpa_iova_range { +u64 start; +u64 end; +}; +This is ambiguous. Is end in the range or just behind it? How about first/last?
Quoted 3 lines
It is customary in the kernel to use start-end where end corresponds to the byte following the last in the range. See struct
vm_area_structvm_startandvm_endfields
Quoted 7 lines
Exactly my point:
include/linux/mm_types.h: unsigned longvm_end; /* The first byte after our end addressin this case Jason wants it to be the last byte, not one behind.
Maybe start, size? Not ambiguous, and you don't need to do annoying calculations like size = last - start + 1
Re: [PATCH 1/4] vdpa: introduce config op to get valid iova range
In reply to Michael S. TsirkinQuoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Jason Wang
This patch introduce a config op to get valid iova range from the vDPA device.
Signed-off-by Jason Wang <[email protected]>--- include/linux/vdpa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/vdpa.h +0
-0@@ -41,6 +41,16 @@ struct vdpa_device {unsigned int index; };
Quoted 14 lines
include/linux/vdpa.h struct vdpa_device { · line 53
Quoted 10 lines
include/linux/vdpa.h +10
-0+/** +* vDPA IOVA range - the IOVA range support by the device +* @start: start of the IOVA range +* @end: end of the IOVA range +*/ +struct vdpa_iova_range { +u64 start; +u64 end; +}; +This is ambiguous. Is end in the range or just behind it? How about first/last?
It is customary in the kernel to use start-end where end corresponds to the byte following the last in the range. See struct vm_area_struct vm_start and vm_end fields
Quoted 27 lines
Quoted 26 lines
include/linux/vdpa.h +4
-0/** * vDPA_config_ops - operations for configuring a vDPA device. * Note: vDPA device drivers are required to implement all of the @@ -134,6 +144,9 @@ struct vdpa_device {* @get_generation: Get device config generation (optional) * @vdev: vdpa device * Returns u32: device generation +* @get_iova_range: Get supported iova range (on-chip IOMMU) +* @vdev: vdpa device +* Returns the iova range supported by the device * @set_map: Set device memory mapping (optional) * Needed for device that using device * specific DMA translation (on-chip IOMMU) @@ -195,6 +208,7 @@ struct vdpa_config_ops {void (*set_config)(struct vdpa_device *vdev,unsigned int offset,const void *buf,unsigned int len);u32 (*get_generation)(struct vdpa_device *vdev); +struct vdpa_iova_range (*get_iova_range)(struct vdpa_device *vdev);/* DMA ops */ int (*set_map)(struct vdpa_device *vdev,struct vhost_iotlb *iotlb);Signature · 1 line
2.20.1
Re: [PATCH 1/4] vdpa: introduce config op to get valid iova range
In reply to Eli CohenQuoted 17 lines · Eli Cohen
Quoted 16 lines · Jason Wang
This patch introduce a config op to get valid iova range from the vDPA device.
Signed-off-by Jason Wang<[email protected]>--- include/linux/vdpa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/vdpa.h +0
-0@@ -41,6 +41,16 @@ struct vdpa_device {unsigned int index; };
Quoted 13 lines
include/linux/vdpa.h struct vdpa_device { · line 53
Quoted 10 lines
include/linux/vdpa.h +10
-0+/** +* vDPA IOVA range - the IOVA range support by the device +* @start: start of the IOVA range +* @end: end of the IOVA range +*/ +struct vdpa_iova_range { +u64 start; +u64 end; +}; +What do you do with this information? Suppose some device tells you it supports some limited range, say, from
0x40000000to0x80000000. What does qemu do with this information?
For qemu, when qemu will fail the vDPA device creation when:
1) vIOMMU is not enabled and GPA is out of this range
2) vIOMMU is enabled but it can't report such range to guest
For other userspace application, it will know it can only use this range as its IOVA.
Thanks
Re: [PATCH 1/4] vdpa: introduce config op to get valid iova range
In reply to Michael S. TsirkinQuoted 31 lines · Michael S. Tsirkin
Quoted 30 lines · Eli Cohen
Quoted 29 lines · Michael S. Tsirkin
Quoted 16 lines · Jason Wang
This patch introduce a config op to get valid iova range from the vDPA device.
Signed-off-by Jason Wang<[email protected]>--- include/linux/vdpa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/vdpa.h +0
-0@@ -41,6 +41,16 @@ struct vdpa_device {unsigned int index; };include/linux/vdpa.h struct vdpa_device { · line 53
Quoted 10 lines
include/linux/vdpa.h +10
-0+/** +* vDPA IOVA range - the IOVA range support by the device +* @start: start of the IOVA range +* @end: end of the IOVA range +*/ +struct vdpa_iova_range { +u64 start; +u64 end; +}; +This is ambiguous. Is end in the range or just behind it? How about first/last?
Quoted 8 lines
Quoted 3 lines
It is customary in the kernel to use start-end where end corresponds to the byte following the last in the range. See struct
vm_area_structvm_startandvm_endfieldsExactly my point:
include/linux/mm_types.h: unsigned longvm_end; /* The first byte after our end addressin this case Jason wants it to be the last byte, not one behind.
Ok, I somehow recall the reason :)
See:
struct iommu_domain_geometry {
dma_addr_t aperture_start; /* First address that can be mapped */ dma_addr_t aperture_end; /* Last address that can be mapped */ bool force_aperture; /* DMA only allowed in mappable range? */ };
So what I proposed here is to be consistent with it.
Thanks
Quoted 2 lines
Michael S. Tsirkin
maintainerRe: [PATCH 1/4] vdpa: introduce config op to get valid iova range
In reply to Eli CohenQuoted 41 lines · Eli Cohen
Quoted 40 lines · Michael S. Tsirkin
Quoted 33 lines · Eli Cohen
Quoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Jason Wang
This patch introduce a config op to get valid iova range from the vDPA device.
Signed-off-by Jason Wang <[email protected]>--- include/linux/vdpa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/vdpa.h +0
-0@@ -41,6 +41,16 @@ struct vdpa_device {unsigned int index; };Quoted 14 lines
include/linux/vdpa.h struct vdpa_device { · line 53
Quoted 10 lines
include/linux/vdpa.h +10
-0+/** +* vDPA IOVA range - the IOVA range support by the device +* @start: start of the IOVA range +* @end: end of the IOVA range +*/ +struct vdpa_iova_range { +u64 start; +u64 end; +}; +This is ambiguous. Is end in the range or just behind it? How about first/last?
Quoted 3 lines
It is customary in the kernel to use start-end where end corresponds to the byte following the last in the range. See struct
vm_area_structvm_startandvm_endfieldsExactly my point:
Quoted 7 lines
Quoted 5 lines
include/linux/mm_types.h: unsigned longvm_end; /* The first byte after our end addressin this case Jason wants it to be the last byte, not one behind.
Maybe start, size? Not ambiguous, and you don't need to do annoying calculations like size = last - start + 1
Size has a bunch of issues: can overlap, can not cover the entire 64 bit range. The requisite checks are arguably easier to get wrong than getting the size if you need it.
Re: [PATCH 1/4] vdpa: introduce config op to get valid iova range
Quoted 41 lines · Michael S. Tsirkin
Quoted 40 lines · Eli Cohen
Quoted 39 lines · Michael S. Tsirkin
Quoted 31 lines · Eli Cohen
Quoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Jason Wang
This patch introduce a config op to get valid iova range from the vDPA device.
Signed-off-by Jason Wang <[email protected]>--- include/linux/vdpa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/vdpa.h +0
-0@@ -41,6 +41,16 @@ struct vdpa_device {unsigned int index; };Quoted 13 lines
include/linux/vdpa.h struct vdpa_device { · line 53
Quoted 10 lines
include/linux/vdpa.h +10
-0+/** +* vDPA IOVA range - the IOVA range support by the device +* @start: start of the IOVA range +* @end: end of the IOVA range +*/ +struct vdpa_iova_range { +u64 start; +u64 end; +}; +This is ambiguous. Is end in the range or just behind it? How about first/last?
Quoted 3 lines
It is customary in the kernel to use start-end where end corresponds to the byte following the last in the range. See struct
vm_area_structvm_startandvm_endfieldsExactly my point:
include/linux/mm_types.h: unsigned longvm_end; /* The first byte after our end address
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
in this case Jason wants it to be the last byte, not one behind.
Maybe start, size? Not ambiguous, and you don't need to do annoying calculations like size = last - start + 1
Size has a bunch of issues: can overlap, can not cover the entire 64 bit range. The requisite checks are arguably easier to get wrong than getting the size if you need it.
Yes, so do you still prefer first/last or just begin/end which is consistent with iommu_domain_geometry?
Thanks
Quoted 1 line
Michael S. Tsirkin
maintainerRe: [PATCH 1/4] vdpa: introduce config op to get valid iova range
Quoted 52 lines · Jason Wang
Quoted 40 lines · Michael S. Tsirkin
Quoted 39 lines · Eli Cohen
Quoted 38 lines · Michael S. Tsirkin
Quoted 30 lines · Eli Cohen
Quoted 21 lines · Michael S. Tsirkin
Quoted 20 lines · Jason Wang
This patch introduce a config op to get valid iova range from the vDPA device.
Signed-off-by Jason Wang <[email protected]>--- include/linux/vdpa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/vdpa.h +5
-0@@ -41,6 +41,16 @@ struct vdpa_device {unsigned int index; }; +/** +* vDPA IOVA range - the IOVA range support by the device +* @start: start of the IOVA range +* @end: end of the IOVA range +*/ Quoted 8 lines
include/linux/vdpa.h struct vdpa_device { · line 52
Quoted 5 lines
include/linux/vdpa.h +5
-0+struct vdpa_iova_range { +u64 start; +u64 end; +}; +This is ambiguous. Is end in the range or just behind it? How about first/last?
Quoted 3 lines
It is customary in the kernel to use start-end where end corresponds to the byte following the last in the range. See struct
vm_area_structvm_startandvm_endfieldsExactly my point:
include/linux/mm_types.h: unsigned longvm_end; /* The first byte after our end addressQuoted 8 lines
Quoted 5 lines
Quoted 3 lines
in this case Jason wants it to be the last byte, not one behind.
Maybe start, size? Not ambiguous, and you don't need to do annoying calculations like size = last - start + 1
Size has a bunch of issues: can overlap, can not cover the entire 64 bit range. The requisite checks are arguably easier to get wrong than getting the size if you need it.
Quoted 4 lines
Yes, so do you still prefer first/last or just begin/end which is consistent with
iommu_domain_geometry?Thanks
I prefer first/last I think, these are unambiguous. E.g.
dma_addr_t aperture_start; /* First address that can be mapped */
dma_addr_t aperture_end; /* Last address that can be mapped */
instead of addressing ambiguity with a comment, let's just name the field well.
Quoted 2 lines
Quoted 2 lines
Re: [PATCH 1/4] vdpa: introduce config op to get valid iova range
Quoted 52 lines · Michael S. Tsirkin
Quoted 51 lines · Jason Wang
Quoted 39 lines · Michael S. Tsirkin
Quoted 38 lines · Eli Cohen
Quoted 37 lines · Michael S. Tsirkin
Quoted 29 lines · Eli Cohen
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Jason Wang
This patch introduce a config op to get valid iova range from the vDPA device.
Signed-off-by Jason Wang<[email protected]>--- include/linux/vdpa.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/vdpa.h +4
-0@@ -41,6 +41,16 @@ struct vdpa_device {unsigned int index; }; +/** +* vDPA IOVA range - the IOVA range support by the device +* @start: start of the IOVA range +* @end: end of the IOVA range Quoted 8 lines
include/linux/vdpa.h struct vdpa_device { · line 52
Quoted 6 lines
include/linux/vdpa.h +6
-0+*/ +struct vdpa_iova_range { +u64 start; +u64 end; +}; +This is ambiguous. Is end in the range or just behind it? How about first/last?
Quoted 3 lines
It is customary in the kernel to use start-end where end corresponds to the byte following the last in the range. See struct
vm_area_structvm_startandvm_endfieldsExactly my point:
include/linux/mm_types.h: unsigned longvm_end; /* The first byte after our end addressQuoted 8 lines
Quoted 5 lines
Quoted 3 lines
in this case Jason wants it to be the last byte, not one behind.
Maybe start, size? Not ambiguous, and you don't need to do annoying calculations like size = last - start + 1
Size has a bunch of issues: can overlap, can not cover the entire 64 bit range. The requisite checks are arguably easier to get wrong than getting the size if you need it.
Yes, so do you still prefer first/last or just begin/end which is consistent with
iommu_domain_geometry?
Quoted 8 lines
Quoted 1 line
Thanks
I prefer first/last I think, these are unambiguous. E.g.
dma_addr_taperture_start; /* First address that can be mapped */
dma_addr_taperture_end; /* Last address that can be mapped */instead of addressing ambiguity with a comment, let's just name the field well.
Ok, will do.
Thanks
Quoted 3 lines
Michael S. Tsirkin
maintainerQuoted 12 lines · Jason Wang
Hi All:
This series introduces API for reporing IOVA range. This is a must for userspace to work correclty:
- for the process that uses vhost-vDPA directly to properly allocate IOVA
- for VM(qemu), when vIOMMU is not enabled, fail early if GPA is out of range
- for VM(qemu), when vIOMMU is enabled, determine a valid guest address width
Quoted 3 lines
Please review.
Thanks
OK so what is the plan here? Change begin-end->first-last and repost?
Quoted 17 lines
Jason Wang (4):
vdpa: introduce config op to get valid iova range
vdpa_sim: implementget_iova_rangebus operation
vdpa:get_iova_range()is mandatory for device specific DMA
translation
vhost: vdpa: report iova rangedrivers/vdpa/vdpa.c | 4 ++++ drivers/vdpa/vdpa_sim/vdpa_sim.c | 11 +++++++++++ drivers/vhost/vdpa.c | 27 +++++++++++++++++++++++++++ include/linux/vdpa.h | 14 ++++++++++++++ include/uapi/linux/vhost.h | 4 ++++ include/uapi/linux/vhost_types.h | 5 +++++ 6 files changed, 65 insertions(+)Signature · 1 line
2.20.1
Quoted 13 lines · Michael S. Tsirkin
Quoted 12 lines · Jason Wang
Hi All:
This series introduces API for reporing IOVA range. This is a must for userspace to work correclty:
- for the process that uses vhost-vDPA directly to properly allocate IOVA
- for VM(qemu), when vIOMMU is not enabled, fail early if GPA is out of range
- for VM(qemu), when vIOMMU is enabled, determine a valid guest address width
Quoted 4 lines
Quoted 3 lines
Please review.
Thanks
OK so what is the plan here? Change begin-end->first-last and repost?
I've posted V2 with this change, but it get some warning for buildbot.
Will post a V3.
Thanks
Quoted 18 lines
Quoted 18 lines
Jason Wang (4):
vdpa: introduce config op to get valid iova range
vdpa_sim: implementget_iova_rangebus operation
vdpa:get_iova_range()is mandatory for device specific DMA
translation
vhost: vdpa: report iova rangedrivers/vdpa/vdpa.c | 4 ++++ drivers/vdpa/vdpa_sim/vdpa_sim.c | 11 +++++++++++ drivers/vhost/vdpa.c | 27 +++++++++++++++++++++++++++ include/linux/vdpa.h | 14 ++++++++++++++ include/uapi/linux/vhost.h | 4 ++++ include/uapi/linux/vhost_types.h | 5 +++++ 6 files changed, 65 insertions(+)Signature · 1 line
2.20.1