[14/15] net/virtio: add vDPA op to get notification area
Checks
Commit Message
This patch implements the vDPA .get_notify_area()
callback.
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
drivers/net/virtio/virtio_vdpa.c | 33 ++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
Comments
On Thu, Aug 29, 2019 at 09:59:59AM +0200, Maxime Coquelin wrote:
> This patch implements the vDPA .get_notify_area()
> callback.
>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
> drivers/net/virtio/virtio_vdpa.c | 33 ++++++++++++++++++++++++++++++++
> 1 file changed, 33 insertions(+)
>
> diff --git a/drivers/net/virtio/virtio_vdpa.c b/drivers/net/virtio/virtio_vdpa.c
> index e0b2f99ba..e681f527a 100644
> --- a/drivers/net/virtio/virtio_vdpa.c
> +++ b/drivers/net/virtio/virtio_vdpa.c
> @@ -707,6 +707,38 @@ virtio_vdpa_get_vfio_device_fd(int vid)
> return list->dev->vfio_dev_fd;
> }
>
> +static int
> +virtio_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size)
> +{
> + int did;
> + struct internal_list *list;
> + struct virtio_vdpa_device *dev;
> + struct vfio_region_info reg = { .argsz = sizeof(reg) };
> + int ret;
> +
> + did = rte_vhost_get_vdpa_device_id(vid);
> + list = find_internal_resource_by_did(did);
> + if (list == NULL) {
> + DRV_LOG(ERR, "Invalid device id: %d", did);
> + return -1;
> + }
> +
> + dev = list->dev;
> +
> + reg.index = dev->hw.notify_region;
> + ret = ioctl(dev->vfio_dev_fd, VFIO_DEVICE_GET_REGION_INFO, ®);
> + if (ret) {
> + DRV_LOG(ERR, "Get not get device region info: %s",
> + strerror(errno));
> + return -1;
> + }
> +
> + *offset = dev->vqs[qid].notify_addr - dev->hw.notify_base + reg.offset;
> + *size = 0x1000;
It would be better to check whether the size is no less
than 0x1000, otherwise it's possible to give guest the
access to other registers of the vdpa device.
Regards,
Tiwei
> +
> + return 0;
> +}
> +
> static struct rte_vdpa_dev_ops virtio_vdpa_ops = {
> .get_queue_num = virtio_vdpa_get_queue_num,
> .get_features = virtio_vdpa_get_features,
> @@ -716,6 +748,7 @@ static struct rte_vdpa_dev_ops virtio_vdpa_ops = {
> .set_features = virtio_vdpa_set_features,
> .get_vfio_group_fd = virtio_vdpa_get_vfio_group_fd,
> .get_vfio_device_fd = virtio_vdpa_get_vfio_device_fd,
> + .get_notify_area = virtio_vdpa_get_notify_area,
> };
>
> static inline int
> --
> 2.21.0
>
On 9/3/19 7:02 AM, Tiwei Bie wrote:
> On Thu, Aug 29, 2019 at 09:59:59AM +0200, Maxime Coquelin wrote:
>> This patch implements the vDPA .get_notify_area()
>> callback.
>>
>> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>> ---
>> drivers/net/virtio/virtio_vdpa.c | 33 ++++++++++++++++++++++++++++++++
>> 1 file changed, 33 insertions(+)
>>
>> diff --git a/drivers/net/virtio/virtio_vdpa.c b/drivers/net/virtio/virtio_vdpa.c
>> index e0b2f99ba..e681f527a 100644
>> --- a/drivers/net/virtio/virtio_vdpa.c
>> +++ b/drivers/net/virtio/virtio_vdpa.c
>> @@ -707,6 +707,38 @@ virtio_vdpa_get_vfio_device_fd(int vid)
>> return list->dev->vfio_dev_fd;
>> }
>>
>> +static int
>> +virtio_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size)
>> +{
>> + int did;
>> + struct internal_list *list;
>> + struct virtio_vdpa_device *dev;
>> + struct vfio_region_info reg = { .argsz = sizeof(reg) };
>> + int ret;
>> +
>> + did = rte_vhost_get_vdpa_device_id(vid);
>> + list = find_internal_resource_by_did(did);
>> + if (list == NULL) {
>> + DRV_LOG(ERR, "Invalid device id: %d", did);
>> + return -1;
>> + }
>> +
>> + dev = list->dev;
>> +
>> + reg.index = dev->hw.notify_region;
>> + ret = ioctl(dev->vfio_dev_fd, VFIO_DEVICE_GET_REGION_INFO, ®);
>> + if (ret) {
>> + DRV_LOG(ERR, "Get not get device region info: %s",
>> + strerror(errno));
>> + return -1;
>> + }
>> +
>> + *offset = dev->vqs[qid].notify_addr - dev->hw.notify_base + reg.offset;
>> + *size = 0x1000;
>
> It would be better to check whether the size is no less
> than 0x1000, otherwise it's possible to give guest the
> access to other registers of the vdpa device.
Correct, if offset is not page-aligned, then it would mean one page may
be mapped while not needed. I took the ifcvf driver as example and
forgot to fix it. (Maybe it should also be fixed in ifcvf driver?)
Thanks,
Maxime
> Regards,
> Tiwei
>
>> +
>> + return 0;
>> +}
>> +
>> static struct rte_vdpa_dev_ops virtio_vdpa_ops = {
>> .get_queue_num = virtio_vdpa_get_queue_num,
>> .get_features = virtio_vdpa_get_features,
>> @@ -716,6 +748,7 @@ static struct rte_vdpa_dev_ops virtio_vdpa_ops = {
>> .set_features = virtio_vdpa_set_features,
>> .get_vfio_group_fd = virtio_vdpa_get_vfio_group_fd,
>> .get_vfio_device_fd = virtio_vdpa_get_vfio_device_fd,
>> + .get_notify_area = virtio_vdpa_get_notify_area,
>> };
>>
>> static inline int
>> --
>> 2.21.0
>>
On Tue, Sep 03, 2019 at 09:36:54AM +0200, Maxime Coquelin wrote:
> On 9/3/19 7:02 AM, Tiwei Bie wrote:
> > On Thu, Aug 29, 2019 at 09:59:59AM +0200, Maxime Coquelin wrote:
> >> This patch implements the vDPA .get_notify_area()
> >> callback.
> >>
> >> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> >> ---
> >> drivers/net/virtio/virtio_vdpa.c | 33 ++++++++++++++++++++++++++++++++
> >> 1 file changed, 33 insertions(+)
> >>
> >> diff --git a/drivers/net/virtio/virtio_vdpa.c b/drivers/net/virtio/virtio_vdpa.c
> >> index e0b2f99ba..e681f527a 100644
> >> --- a/drivers/net/virtio/virtio_vdpa.c
> >> +++ b/drivers/net/virtio/virtio_vdpa.c
> >> @@ -707,6 +707,38 @@ virtio_vdpa_get_vfio_device_fd(int vid)
> >> return list->dev->vfio_dev_fd;
> >> }
> >>
> >> +static int
> >> +virtio_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size)
> >> +{
> >> + int did;
> >> + struct internal_list *list;
> >> + struct virtio_vdpa_device *dev;
> >> + struct vfio_region_info reg = { .argsz = sizeof(reg) };
> >> + int ret;
> >> +
> >> + did = rte_vhost_get_vdpa_device_id(vid);
> >> + list = find_internal_resource_by_did(did);
> >> + if (list == NULL) {
> >> + DRV_LOG(ERR, "Invalid device id: %d", did);
> >> + return -1;
> >> + }
> >> +
> >> + dev = list->dev;
> >> +
> >> + reg.index = dev->hw.notify_region;
> >> + ret = ioctl(dev->vfio_dev_fd, VFIO_DEVICE_GET_REGION_INFO, ®);
> >> + if (ret) {
> >> + DRV_LOG(ERR, "Get not get device region info: %s",
> >> + strerror(errno));
> >> + return -1;
> >> + }
> >> +
> >> + *offset = dev->vqs[qid].notify_addr - dev->hw.notify_base + reg.offset;
> >> + *size = 0x1000;
> >
> > It would be better to check whether the size is no less
> > than 0x1000, otherwise it's possible to give guest the
> > access to other registers of the vdpa device.
>
> Correct, if offset is not page-aligned, then it would mean one page may
> be mapped while not needed. I took the ifcvf driver as example and
> forgot to fix it. (Maybe it should also be fixed in ifcvf driver?)
The ifcvf hardware will make sure that the notify register will
stay in a separate page, so the size is hardcoded in ifcvf driver.
Regards,
Tiwei
>
> Thanks,
> Maxime
> > Regards,
> > Tiwei
> >
> >> +
> >> + return 0;
> >> +}
> >> +
> >> static struct rte_vdpa_dev_ops virtio_vdpa_ops = {
> >> .get_queue_num = virtio_vdpa_get_queue_num,
> >> .get_features = virtio_vdpa_get_features,
> >> @@ -716,6 +748,7 @@ static struct rte_vdpa_dev_ops virtio_vdpa_ops = {
> >> .set_features = virtio_vdpa_set_features,
> >> .get_vfio_group_fd = virtio_vdpa_get_vfio_group_fd,
> >> .get_vfio_device_fd = virtio_vdpa_get_vfio_device_fd,
> >> + .get_notify_area = virtio_vdpa_get_notify_area,
> >> };
> >>
> >> static inline int
> >> --
> >> 2.21.0
> >>
@@ -707,6 +707,38 @@ virtio_vdpa_get_vfio_device_fd(int vid)
return list->dev->vfio_dev_fd;
}
+static int
+virtio_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size)
+{
+ int did;
+ struct internal_list *list;
+ struct virtio_vdpa_device *dev;
+ struct vfio_region_info reg = { .argsz = sizeof(reg) };
+ int ret;
+
+ did = rte_vhost_get_vdpa_device_id(vid);
+ list = find_internal_resource_by_did(did);
+ if (list == NULL) {
+ DRV_LOG(ERR, "Invalid device id: %d", did);
+ return -1;
+ }
+
+ dev = list->dev;
+
+ reg.index = dev->hw.notify_region;
+ ret = ioctl(dev->vfio_dev_fd, VFIO_DEVICE_GET_REGION_INFO, ®);
+ if (ret) {
+ DRV_LOG(ERR, "Get not get device region info: %s",
+ strerror(errno));
+ return -1;
+ }
+
+ *offset = dev->vqs[qid].notify_addr - dev->hw.notify_base + reg.offset;
+ *size = 0x1000;
+
+ return 0;
+}
+
static struct rte_vdpa_dev_ops virtio_vdpa_ops = {
.get_queue_num = virtio_vdpa_get_queue_num,
.get_features = virtio_vdpa_get_features,
@@ -716,6 +748,7 @@ static struct rte_vdpa_dev_ops virtio_vdpa_ops = {
.set_features = virtio_vdpa_set_features,
.get_vfio_group_fd = virtio_vdpa_get_vfio_group_fd,
.get_vfio_device_fd = virtio_vdpa_get_vfio_device_fd,
+ .get_notify_area = virtio_vdpa_get_notify_area,
};
static inline int