Re: [PATCH] vp_vdpa: Check queue number of vdpa device from add_config

2023-06-06 Thread Jason Wang
On Tue, Jun 6, 2023 at 2:19 PM Angus Chen  wrote:
>
> Hi,Jason.
>
> > -Original Message-
> > From: Jason Wang 
> > Sent: Monday, June 5, 2023 2:54 PM
> > To: Angus Chen 
> > Cc: m...@redhat.com; virtualization@lists.linux-foundation.org;
> > linux-ker...@vger.kernel.org
> > Subject: Re: [PATCH] vp_vdpa: Check queue number of vdpa device from
> > add_config
> >
> > On Fri, Jun 2, 2023 at 3:35 PM Angus Chen 
> > wrote:
> > >
> > > When add virtio_pci vdpa device,check the vqs number of device cap
> > > and max_vq_pairs from add_config.
> > >
> > > Signed-off-by: Angus Chen 
> > > ---
> > >  drivers/vdpa/virtio_pci/vp_vdpa.c | 11 +--
> > >  1 file changed, 9 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c
> > b/drivers/vdpa/virtio_pci/vp_vdpa.c
> > > index 281287fae89f..4bf1ab637d32 100644
> > > --- a/drivers/vdpa/virtio_pci/vp_vdpa.c
> > > +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
> > > @@ -478,7 +478,7 @@ static int vp_vdpa_dev_add(struct vdpa_mgmt_dev
> > *v_mdev, const char *name,
> > > struct device *dev = >dev;
> > > struct vp_vdpa *vp_vdpa = NULL;
> > > u64 device_features;
> > > -   int ret, i;
> > > +   int ret, i, queues;
> > >
> > > vp_vdpa = vdpa_alloc_device(struct vp_vdpa, vdpa,
> > > dev, _vdpa_ops, 1, 1, name,
> > false);
> > > @@ -491,7 +491,14 @@ static int vp_vdpa_dev_add(struct vdpa_mgmt_dev
> > *v_mdev, const char *name,
> > > vp_vdpa_mgtdev->vp_vdpa = vp_vdpa;
> > >
> > > vp_vdpa->vdpa.dma_dev = >dev;
> > > -   vp_vdpa->queues = vp_modern_get_num_queues(mdev);
> > > +   queues = vp_modern_get_num_queues(mdev);
> > > +   if (add_config->mask &
> > BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP)) {
> > > +   if (add_config->net.max_vq_pairs > queues / 2)
> > > +   return -EINVAL;
> > > +   queues = min_t(u32, queues, 2 *
> > add_config->net.max_vq_pairs);
> >
> > Looks like you want to mediate the max_vqp here, but what happens:
> >
> > 1) harware have 4 queue paris
> > 2) vp_vdpa cap it into 2 queue pairs
> > 3) guest may still try to enable 4 queue paris
> >
> Yes,you are right,this situation can occur.
> > For 3), the kernel needs to mediate the control virtqueue which seems not
> > easy.
> >
> > How about simply starting from failing if the provisioned #qp is not
> > equal to the one that hardware has?
> Ok,You mean we just check it in vp_vdpa or check it in all other vdpa net 
> drivers?

vp_vdpa only, since in some other kind of parents, #qps could be provisioned.

Thanks

> >
> > Thanks
> >
> > > +   }
> > > +
> > > +   vp_vdpa->queues = queues;
> > > vp_vdpa->mdev = mdev;
> > >
> > > device_features = vp_modern_get_features(mdev);
> > > --
> > > 2.25.1
> > >
>

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH] vp_vdpa: Check queue number of vdpa device from add_config

2023-06-05 Thread Jason Wang
On Fri, Jun 2, 2023 at 3:35 PM Angus Chen  wrote:
>
> When add virtio_pci vdpa device,check the vqs number of device cap
> and max_vq_pairs from add_config.
>
> Signed-off-by: Angus Chen 
> ---
>  drivers/vdpa/virtio_pci/vp_vdpa.c | 11 +--
>  1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c 
> b/drivers/vdpa/virtio_pci/vp_vdpa.c
> index 281287fae89f..4bf1ab637d32 100644
> --- a/drivers/vdpa/virtio_pci/vp_vdpa.c
> +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
> @@ -478,7 +478,7 @@ static int vp_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, 
> const char *name,
> struct device *dev = >dev;
> struct vp_vdpa *vp_vdpa = NULL;
> u64 device_features;
> -   int ret, i;
> +   int ret, i, queues;
>
> vp_vdpa = vdpa_alloc_device(struct vp_vdpa, vdpa,
> dev, _vdpa_ops, 1, 1, name, false);
> @@ -491,7 +491,14 @@ static int vp_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, 
> const char *name,
> vp_vdpa_mgtdev->vp_vdpa = vp_vdpa;
>
> vp_vdpa->vdpa.dma_dev = >dev;
> -   vp_vdpa->queues = vp_modern_get_num_queues(mdev);
> +   queues = vp_modern_get_num_queues(mdev);
> +   if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP)) {
> +   if (add_config->net.max_vq_pairs > queues / 2)
> +   return -EINVAL;
> +   queues = min_t(u32, queues, 2 * add_config->net.max_vq_pairs);

Looks like you want to mediate the max_vqp here, but what happens:

1) harware have 4 queue paris
2) vp_vdpa cap it into 2 queue pairs
3) guest may still try to enable 4 queue paris

For 3), the kernel needs to mediate the control virtqueue which seems not easy.

How about simply starting from failing if the provisioned #qp is not
equal to the one that hardware has?

Thanks

> +   }
> +
> +   vp_vdpa->queues = queues;
> vp_vdpa->mdev = mdev;
>
> device_features = vp_modern_get_features(mdev);
> --
> 2.25.1
>

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization