All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] vdpa/mlx5: Add support for doorbell bypassing
@ 2021-06-02  9:53 Eli Cohen
  2021-06-03  7:11   ` Jason Wang
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Cohen @ 2021-06-02  9:53 UTC (permalink / raw)
  To: mst, jasowang, virtualization, linux-kernel; +Cc: elic

Implement mlx5_get_vq_notification() to return the doorbell address.
Since the notification area is mapped to userspace, make sure that the
BAR size is at least PAGE_SIZE large.

Signed-off-by: Eli Cohen <elic@nvidia.com>
---
v0 --> v1:
  Make sure SF bar size is not smaller than PAGE_SIZE

 drivers/vdpa/mlx5/core/mlx5_vdpa.h |  1 +
 drivers/vdpa/mlx5/core/resources.c |  1 +
 drivers/vdpa/mlx5/net/mlx5_vnet.c  | 17 +++++++++++++++++
 3 files changed, 19 insertions(+)

diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
index 09a16a3d1b2a..0002b2136b48 100644
--- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h
+++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
@@ -42,6 +42,7 @@ struct mlx5_vdpa_resources {
 	u32 pdn;
 	struct mlx5_uars_page *uar;
 	void __iomem *kick_addr;
+	u64 phys_kick_addr;
 	u16 uid;
 	u32 null_mkey;
 	bool valid;
diff --git a/drivers/vdpa/mlx5/core/resources.c b/drivers/vdpa/mlx5/core/resources.c
index 836ab9ef0fa6..d4606213f88a 100644
--- a/drivers/vdpa/mlx5/core/resources.c
+++ b/drivers/vdpa/mlx5/core/resources.c
@@ -253,6 +253,7 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev)
 		goto err_key;
 
 	kick_addr = mdev->bar_addr + offset;
+	res->phys_kick_addr = kick_addr;
 
 	res->kick_addr = ioremap(kick_addr, PAGE_SIZE);
 	if (!res->kick_addr) {
diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 5500bcfe84b4..1936039e05bd 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -1871,8 +1871,25 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev)
 
 static struct vdpa_notification_area mlx5_get_vq_notification(struct vdpa_device *vdev, u16 idx)
 {
+	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
 	struct vdpa_notification_area ret = {};
+	struct mlx5_vdpa_net *ndev;
+	phys_addr_t addr;
+
+	/* If SF BAR size is smaller than PAGE_SIZE, do not use direct
+	 * notification to avoid the risk of mapping pages that contain BAR of more
+	 * than one SF
+	 */
+	if (MLX5_CAP_GEN(mvdev->mdev, log_min_sf_size) + 12 < PAGE_SHIFT)
+		return ret;
+
+	ndev = to_mlx5_vdpa_ndev(mvdev);
+	addr = (phys_addr_t)ndev->mvdev.res.phys_kick_addr;
+	if (addr & ~PAGE_MASK)
+		return ret;
 
+	ret.addr = (phys_addr_t)ndev->mvdev.res.phys_kick_addr;
+	ret.size = PAGE_SIZE;
 	return ret;
 }
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v1] vdpa/mlx5: Add support for doorbell bypassing
  2021-06-02  9:53 [PATCH v1] vdpa/mlx5: Add support for doorbell bypassing Eli Cohen
@ 2021-06-03  7:11   ` Jason Wang
  0 siblings, 0 replies; 7+ messages in thread
From: Jason Wang @ 2021-06-03  7:11 UTC (permalink / raw)
  To: Eli Cohen, mst, virtualization, linux-kernel


在 2021/6/2 下午5:53, Eli Cohen 写道:
> Implement mlx5_get_vq_notification() to return the doorbell address.
> Since the notification area is mapped to userspace, make sure that the
> BAR size is at least PAGE_SIZE large.
>
> Signed-off-by: Eli Cohen <elic@nvidia.com>
> ---
> v0 --> v1:
>    Make sure SF bar size is not smaller than PAGE_SIZE
>
>   drivers/vdpa/mlx5/core/mlx5_vdpa.h |  1 +
>   drivers/vdpa/mlx5/core/resources.c |  1 +
>   drivers/vdpa/mlx5/net/mlx5_vnet.c  | 17 +++++++++++++++++
>   3 files changed, 19 insertions(+)
>
> diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
> index 09a16a3d1b2a..0002b2136b48 100644
> --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h
> +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
> @@ -42,6 +42,7 @@ struct mlx5_vdpa_resources {
>   	u32 pdn;
>   	struct mlx5_uars_page *uar;
>   	void __iomem *kick_addr;
> +	u64 phys_kick_addr;
>   	u16 uid;
>   	u32 null_mkey;
>   	bool valid;
> diff --git a/drivers/vdpa/mlx5/core/resources.c b/drivers/vdpa/mlx5/core/resources.c
> index 836ab9ef0fa6..d4606213f88a 100644
> --- a/drivers/vdpa/mlx5/core/resources.c
> +++ b/drivers/vdpa/mlx5/core/resources.c
> @@ -253,6 +253,7 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev)
>   		goto err_key;
>   
>   	kick_addr = mdev->bar_addr + offset;
> +	res->phys_kick_addr = kick_addr;
>   
>   	res->kick_addr = ioremap(kick_addr, PAGE_SIZE);
>   	if (!res->kick_addr) {
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 5500bcfe84b4..1936039e05bd 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -1871,8 +1871,25 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev)
>   
>   static struct vdpa_notification_area mlx5_get_vq_notification(struct vdpa_device *vdev, u16 idx)
>   {
> +	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
>   	struct vdpa_notification_area ret = {};
> +	struct mlx5_vdpa_net *ndev;
> +	phys_addr_t addr;
> +
> +	/* If SF BAR size is smaller than PAGE_SIZE, do not use direct
> +	 * notification to avoid the risk of mapping pages that contain BAR of more
> +	 * than one SF
> +	 */
> +	if (MLX5_CAP_GEN(mvdev->mdev, log_min_sf_size) + 12 < PAGE_SHIFT)
> +		return ret;
> +
> +	ndev = to_mlx5_vdpa_ndev(mvdev);
> +	addr = (phys_addr_t)ndev->mvdev.res.phys_kick_addr;
> +	if (addr & ~PAGE_MASK)
> +		return ret;


This has been checked by vhost-vDPA, and it's better to leave those 
policy checking to them driver instead of checking it in the parent.

Thanks


>   
> +	ret.addr = (phys_addr_t)ndev->mvdev.res.phys_kick_addr;
> +	ret.size = PAGE_SIZE;
>   	return ret;
>   }
>   


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1] vdpa/mlx5: Add support for doorbell bypassing
@ 2021-06-03  7:11   ` Jason Wang
  0 siblings, 0 replies; 7+ messages in thread
From: Jason Wang @ 2021-06-03  7:11 UTC (permalink / raw)
  To: Eli Cohen, mst, virtualization, linux-kernel


在 2021/6/2 下午5:53, Eli Cohen 写道:
> Implement mlx5_get_vq_notification() to return the doorbell address.
> Since the notification area is mapped to userspace, make sure that the
> BAR size is at least PAGE_SIZE large.
>
> Signed-off-by: Eli Cohen <elic@nvidia.com>
> ---
> v0 --> v1:
>    Make sure SF bar size is not smaller than PAGE_SIZE
>
>   drivers/vdpa/mlx5/core/mlx5_vdpa.h |  1 +
>   drivers/vdpa/mlx5/core/resources.c |  1 +
>   drivers/vdpa/mlx5/net/mlx5_vnet.c  | 17 +++++++++++++++++
>   3 files changed, 19 insertions(+)
>
> diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
> index 09a16a3d1b2a..0002b2136b48 100644
> --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h
> +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
> @@ -42,6 +42,7 @@ struct mlx5_vdpa_resources {
>   	u32 pdn;
>   	struct mlx5_uars_page *uar;
>   	void __iomem *kick_addr;
> +	u64 phys_kick_addr;
>   	u16 uid;
>   	u32 null_mkey;
>   	bool valid;
> diff --git a/drivers/vdpa/mlx5/core/resources.c b/drivers/vdpa/mlx5/core/resources.c
> index 836ab9ef0fa6..d4606213f88a 100644
> --- a/drivers/vdpa/mlx5/core/resources.c
> +++ b/drivers/vdpa/mlx5/core/resources.c
> @@ -253,6 +253,7 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev)
>   		goto err_key;
>   
>   	kick_addr = mdev->bar_addr + offset;
> +	res->phys_kick_addr = kick_addr;
>   
>   	res->kick_addr = ioremap(kick_addr, PAGE_SIZE);
>   	if (!res->kick_addr) {
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 5500bcfe84b4..1936039e05bd 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -1871,8 +1871,25 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev)
>   
>   static struct vdpa_notification_area mlx5_get_vq_notification(struct vdpa_device *vdev, u16 idx)
>   {
> +	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
>   	struct vdpa_notification_area ret = {};
> +	struct mlx5_vdpa_net *ndev;
> +	phys_addr_t addr;
> +
> +	/* If SF BAR size is smaller than PAGE_SIZE, do not use direct
> +	 * notification to avoid the risk of mapping pages that contain BAR of more
> +	 * than one SF
> +	 */
> +	if (MLX5_CAP_GEN(mvdev->mdev, log_min_sf_size) + 12 < PAGE_SHIFT)
> +		return ret;
> +
> +	ndev = to_mlx5_vdpa_ndev(mvdev);
> +	addr = (phys_addr_t)ndev->mvdev.res.phys_kick_addr;
> +	if (addr & ~PAGE_MASK)
> +		return ret;


This has been checked by vhost-vDPA, and it's better to leave those 
policy checking to them driver instead of checking it in the parent.

Thanks


>   
> +	ret.addr = (phys_addr_t)ndev->mvdev.res.phys_kick_addr;
> +	ret.size = PAGE_SIZE;
>   	return ret;
>   }
>   

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1] vdpa/mlx5: Add support for doorbell bypassing
  2021-06-03  7:11   ` Jason Wang
  (?)
@ 2021-06-03  7:38   ` Eli Cohen
  2021-06-03  7:49       ` Jason Wang
  -1 siblings, 1 reply; 7+ messages in thread
From: Eli Cohen @ 2021-06-03  7:38 UTC (permalink / raw)
  To: Jason Wang; +Cc: mst, virtualization, linux-kernel

On Thu, Jun 03, 2021 at 03:11:51PM +0800, Jason Wang wrote:
> 
> 在 2021/6/2 下午5:53, Eli Cohen 写道:
> > Implement mlx5_get_vq_notification() to return the doorbell address.
> > Since the notification area is mapped to userspace, make sure that the
> > BAR size is at least PAGE_SIZE large.
> > 
> > Signed-off-by: Eli Cohen <elic@nvidia.com>
> > ---
> > v0 --> v1:
> >    Make sure SF bar size is not smaller than PAGE_SIZE
> > 
> >   drivers/vdpa/mlx5/core/mlx5_vdpa.h |  1 +
> >   drivers/vdpa/mlx5/core/resources.c |  1 +
> >   drivers/vdpa/mlx5/net/mlx5_vnet.c  | 17 +++++++++++++++++
> >   3 files changed, 19 insertions(+)
> > 
> > diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
> > index 09a16a3d1b2a..0002b2136b48 100644
> > --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h
> > +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
> > @@ -42,6 +42,7 @@ struct mlx5_vdpa_resources {
> >   	u32 pdn;
> >   	struct mlx5_uars_page *uar;
> >   	void __iomem *kick_addr;
> > +	u64 phys_kick_addr;
> >   	u16 uid;
> >   	u32 null_mkey;
> >   	bool valid;
> > diff --git a/drivers/vdpa/mlx5/core/resources.c b/drivers/vdpa/mlx5/core/resources.c
> > index 836ab9ef0fa6..d4606213f88a 100644
> > --- a/drivers/vdpa/mlx5/core/resources.c
> > +++ b/drivers/vdpa/mlx5/core/resources.c
> > @@ -253,6 +253,7 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev)
> >   		goto err_key;
> >   	kick_addr = mdev->bar_addr + offset;
> > +	res->phys_kick_addr = kick_addr;
> >   	res->kick_addr = ioremap(kick_addr, PAGE_SIZE);
> >   	if (!res->kick_addr) {
> > diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > index 5500bcfe84b4..1936039e05bd 100644
> > --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > @@ -1871,8 +1871,25 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev)
> >   static struct vdpa_notification_area mlx5_get_vq_notification(struct vdpa_device *vdev, u16 idx)
> >   {
> > +	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
> >   	struct vdpa_notification_area ret = {};
> > +	struct mlx5_vdpa_net *ndev;
> > +	phys_addr_t addr;
> > +
> > +	/* If SF BAR size is smaller than PAGE_SIZE, do not use direct
> > +	 * notification to avoid the risk of mapping pages that contain BAR of more
> > +	 * than one SF
> > +	 */
> > +	if (MLX5_CAP_GEN(mvdev->mdev, log_min_sf_size) + 12 < PAGE_SHIFT)
> > +		return ret;
> > +
> > +	ndev = to_mlx5_vdpa_ndev(mvdev);
> > +	addr = (phys_addr_t)ndev->mvdev.res.phys_kick_addr;
> > +	if (addr & ~PAGE_MASK)
> > +		return ret;
> 
> 
> This has been checked by vhost-vDPA, and it's better to leave those policy
> checking to them driver instead of checking it in the parent.
> 

Not in all invocations of get_vq_notification(). For example, in
vhost_vdpa_fault() you call remap_pfn_range() with notify.addr >>
PAGE_SHIFT so it it was not aligned you mask this misalignment.

> Thanks
> 
> 
> > +	ret.addr = (phys_addr_t)ndev->mvdev.res.phys_kick_addr;
> > +	ret.size = PAGE_SIZE;
> >   	return ret;
> >   }
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1] vdpa/mlx5: Add support for doorbell bypassing
  2021-06-03  7:38   ` Eli Cohen
@ 2021-06-03  7:49       ` Jason Wang
  0 siblings, 0 replies; 7+ messages in thread
From: Jason Wang @ 2021-06-03  7:49 UTC (permalink / raw)
  To: Eli Cohen; +Cc: mst, virtualization, linux-kernel


在 2021/6/3 下午3:38, Eli Cohen 写道:
> On Thu, Jun 03, 2021 at 03:11:51PM +0800, Jason Wang wrote:
>> 在 2021/6/2 下午5:53, Eli Cohen 写道:
>>> Implement mlx5_get_vq_notification() to return the doorbell address.
>>> Since the notification area is mapped to userspace, make sure that the
>>> BAR size is at least PAGE_SIZE large.
>>>
>>> Signed-off-by: Eli Cohen <elic@nvidia.com>
>>> ---
>>> v0 --> v1:
>>>     Make sure SF bar size is not smaller than PAGE_SIZE
>>>
>>>    drivers/vdpa/mlx5/core/mlx5_vdpa.h |  1 +
>>>    drivers/vdpa/mlx5/core/resources.c |  1 +
>>>    drivers/vdpa/mlx5/net/mlx5_vnet.c  | 17 +++++++++++++++++
>>>    3 files changed, 19 insertions(+)
>>>
>>> diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
>>> index 09a16a3d1b2a..0002b2136b48 100644
>>> --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h
>>> +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
>>> @@ -42,6 +42,7 @@ struct mlx5_vdpa_resources {
>>>    	u32 pdn;
>>>    	struct mlx5_uars_page *uar;
>>>    	void __iomem *kick_addr;
>>> +	u64 phys_kick_addr;
>>>    	u16 uid;
>>>    	u32 null_mkey;
>>>    	bool valid;
>>> diff --git a/drivers/vdpa/mlx5/core/resources.c b/drivers/vdpa/mlx5/core/resources.c
>>> index 836ab9ef0fa6..d4606213f88a 100644
>>> --- a/drivers/vdpa/mlx5/core/resources.c
>>> +++ b/drivers/vdpa/mlx5/core/resources.c
>>> @@ -253,6 +253,7 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev)
>>>    		goto err_key;
>>>    	kick_addr = mdev->bar_addr + offset;
>>> +	res->phys_kick_addr = kick_addr;
>>>    	res->kick_addr = ioremap(kick_addr, PAGE_SIZE);
>>>    	if (!res->kick_addr) {
>>> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>>> index 5500bcfe84b4..1936039e05bd 100644
>>> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
>>> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>>> @@ -1871,8 +1871,25 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev)
>>>    static struct vdpa_notification_area mlx5_get_vq_notification(struct vdpa_device *vdev, u16 idx)
>>>    {
>>> +	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
>>>    	struct vdpa_notification_area ret = {};
>>> +	struct mlx5_vdpa_net *ndev;
>>> +	phys_addr_t addr;
>>> +
>>> +	/* If SF BAR size is smaller than PAGE_SIZE, do not use direct
>>> +	 * notification to avoid the risk of mapping pages that contain BAR of more
>>> +	 * than one SF
>>> +	 */
>>> +	if (MLX5_CAP_GEN(mvdev->mdev, log_min_sf_size) + 12 < PAGE_SHIFT)
>>> +		return ret;
>>> +
>>> +	ndev = to_mlx5_vdpa_ndev(mvdev);
>>> +	addr = (phys_addr_t)ndev->mvdev.res.phys_kick_addr;
>>> +	if (addr & ~PAGE_MASK)
>>> +		return ret;
>>
>> This has been checked by vhost-vDPA, and it's better to leave those policy
>> checking to them driver instead of checking it in the parent.
>>
> Not in all invocations of get_vq_notification(). For example, in
> vhost_vdpa_fault() you call remap_pfn_range() with notify.addr >>
> PAGE_SHIFT so it it was not aligned you mask this misalignment.


In order to have vhost_vdpa_fault() works, it should first pass the 
check of vhost_vdpa_mmap().

Othewise we won't install vma->vm_ops so there won't be a page fault for 
the doorbell.

Thanks


>
>> Thanks
>>
>>
>>> +	ret.addr = (phys_addr_t)ndev->mvdev.res.phys_kick_addr;
>>> +	ret.size = PAGE_SIZE;
>>>    	return ret;
>>>    }


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1] vdpa/mlx5: Add support for doorbell bypassing
@ 2021-06-03  7:49       ` Jason Wang
  0 siblings, 0 replies; 7+ messages in thread
From: Jason Wang @ 2021-06-03  7:49 UTC (permalink / raw)
  To: Eli Cohen; +Cc: virtualization, linux-kernel, mst


在 2021/6/3 下午3:38, Eli Cohen 写道:
> On Thu, Jun 03, 2021 at 03:11:51PM +0800, Jason Wang wrote:
>> 在 2021/6/2 下午5:53, Eli Cohen 写道:
>>> Implement mlx5_get_vq_notification() to return the doorbell address.
>>> Since the notification area is mapped to userspace, make sure that the
>>> BAR size is at least PAGE_SIZE large.
>>>
>>> Signed-off-by: Eli Cohen <elic@nvidia.com>
>>> ---
>>> v0 --> v1:
>>>     Make sure SF bar size is not smaller than PAGE_SIZE
>>>
>>>    drivers/vdpa/mlx5/core/mlx5_vdpa.h |  1 +
>>>    drivers/vdpa/mlx5/core/resources.c |  1 +
>>>    drivers/vdpa/mlx5/net/mlx5_vnet.c  | 17 +++++++++++++++++
>>>    3 files changed, 19 insertions(+)
>>>
>>> diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
>>> index 09a16a3d1b2a..0002b2136b48 100644
>>> --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h
>>> +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
>>> @@ -42,6 +42,7 @@ struct mlx5_vdpa_resources {
>>>    	u32 pdn;
>>>    	struct mlx5_uars_page *uar;
>>>    	void __iomem *kick_addr;
>>> +	u64 phys_kick_addr;
>>>    	u16 uid;
>>>    	u32 null_mkey;
>>>    	bool valid;
>>> diff --git a/drivers/vdpa/mlx5/core/resources.c b/drivers/vdpa/mlx5/core/resources.c
>>> index 836ab9ef0fa6..d4606213f88a 100644
>>> --- a/drivers/vdpa/mlx5/core/resources.c
>>> +++ b/drivers/vdpa/mlx5/core/resources.c
>>> @@ -253,6 +253,7 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev)
>>>    		goto err_key;
>>>    	kick_addr = mdev->bar_addr + offset;
>>> +	res->phys_kick_addr = kick_addr;
>>>    	res->kick_addr = ioremap(kick_addr, PAGE_SIZE);
>>>    	if (!res->kick_addr) {
>>> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>>> index 5500bcfe84b4..1936039e05bd 100644
>>> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
>>> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>>> @@ -1871,8 +1871,25 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev)
>>>    static struct vdpa_notification_area mlx5_get_vq_notification(struct vdpa_device *vdev, u16 idx)
>>>    {
>>> +	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
>>>    	struct vdpa_notification_area ret = {};
>>> +	struct mlx5_vdpa_net *ndev;
>>> +	phys_addr_t addr;
>>> +
>>> +	/* If SF BAR size is smaller than PAGE_SIZE, do not use direct
>>> +	 * notification to avoid the risk of mapping pages that contain BAR of more
>>> +	 * than one SF
>>> +	 */
>>> +	if (MLX5_CAP_GEN(mvdev->mdev, log_min_sf_size) + 12 < PAGE_SHIFT)
>>> +		return ret;
>>> +
>>> +	ndev = to_mlx5_vdpa_ndev(mvdev);
>>> +	addr = (phys_addr_t)ndev->mvdev.res.phys_kick_addr;
>>> +	if (addr & ~PAGE_MASK)
>>> +		return ret;
>>
>> This has been checked by vhost-vDPA, and it's better to leave those policy
>> checking to them driver instead of checking it in the parent.
>>
> Not in all invocations of get_vq_notification(). For example, in
> vhost_vdpa_fault() you call remap_pfn_range() with notify.addr >>
> PAGE_SHIFT so it it was not aligned you mask this misalignment.


In order to have vhost_vdpa_fault() works, it should first pass the 
check of vhost_vdpa_mmap().

Othewise we won't install vma->vm_ops so there won't be a page fault for 
the doorbell.

Thanks


>
>> Thanks
>>
>>
>>> +	ret.addr = (phys_addr_t)ndev->mvdev.res.phys_kick_addr;
>>> +	ret.size = PAGE_SIZE;
>>>    	return ret;
>>>    }

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1] vdpa/mlx5: Add support for doorbell bypassing
  2021-06-03  7:49       ` Jason Wang
  (?)
@ 2021-06-03  8:02       ` Eli Cohen
  -1 siblings, 0 replies; 7+ messages in thread
From: Eli Cohen @ 2021-06-03  8:02 UTC (permalink / raw)
  To: Jason Wang; +Cc: mst, virtualization, linux-kernel

On Thu, Jun 03, 2021 at 03:49:04PM +0800, Jason Wang wrote:
> 
> 在 2021/6/3 下午3:38, Eli Cohen 写道:
> > On Thu, Jun 03, 2021 at 03:11:51PM +0800, Jason Wang wrote:
> > > 在 2021/6/2 下午5:53, Eli Cohen 写道:
> > > > Implement mlx5_get_vq_notification() to return the doorbell address.
> > > > Since the notification area is mapped to userspace, make sure that the
> > > > BAR size is at least PAGE_SIZE large.
> > > > 
> > > > Signed-off-by: Eli Cohen <elic@nvidia.com>
> > > > ---
> > > > v0 --> v1:
> > > >     Make sure SF bar size is not smaller than PAGE_SIZE
> > > > 
> > > >    drivers/vdpa/mlx5/core/mlx5_vdpa.h |  1 +
> > > >    drivers/vdpa/mlx5/core/resources.c |  1 +
> > > >    drivers/vdpa/mlx5/net/mlx5_vnet.c  | 17 +++++++++++++++++
> > > >    3 files changed, 19 insertions(+)
> > > > 
> > > > diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
> > > > index 09a16a3d1b2a..0002b2136b48 100644
> > > > --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h
> > > > +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h
> > > > @@ -42,6 +42,7 @@ struct mlx5_vdpa_resources {
> > > >    	u32 pdn;
> > > >    	struct mlx5_uars_page *uar;
> > > >    	void __iomem *kick_addr;
> > > > +	u64 phys_kick_addr;
> > > >    	u16 uid;
> > > >    	u32 null_mkey;
> > > >    	bool valid;
> > > > diff --git a/drivers/vdpa/mlx5/core/resources.c b/drivers/vdpa/mlx5/core/resources.c
> > > > index 836ab9ef0fa6..d4606213f88a 100644
> > > > --- a/drivers/vdpa/mlx5/core/resources.c
> > > > +++ b/drivers/vdpa/mlx5/core/resources.c
> > > > @@ -253,6 +253,7 @@ int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev)
> > > >    		goto err_key;
> > > >    	kick_addr = mdev->bar_addr + offset;
> > > > +	res->phys_kick_addr = kick_addr;
> > > >    	res->kick_addr = ioremap(kick_addr, PAGE_SIZE);
> > > >    	if (!res->kick_addr) {
> > > > diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > > > index 5500bcfe84b4..1936039e05bd 100644
> > > > --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > > > +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > > > @@ -1871,8 +1871,25 @@ static void mlx5_vdpa_free(struct vdpa_device *vdev)
> > > >    static struct vdpa_notification_area mlx5_get_vq_notification(struct vdpa_device *vdev, u16 idx)
> > > >    {
> > > > +	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
> > > >    	struct vdpa_notification_area ret = {};
> > > > +	struct mlx5_vdpa_net *ndev;
> > > > +	phys_addr_t addr;
> > > > +
> > > > +	/* If SF BAR size is smaller than PAGE_SIZE, do not use direct
> > > > +	 * notification to avoid the risk of mapping pages that contain BAR of more
> > > > +	 * than one SF
> > > > +	 */
> > > > +	if (MLX5_CAP_GEN(mvdev->mdev, log_min_sf_size) + 12 < PAGE_SHIFT)
> > > > +		return ret;
> > > > +
> > > > +	ndev = to_mlx5_vdpa_ndev(mvdev);
> > > > +	addr = (phys_addr_t)ndev->mvdev.res.phys_kick_addr;
> > > > +	if (addr & ~PAGE_MASK)
> > > > +		return ret;
> > > 
> > > This has been checked by vhost-vDPA, and it's better to leave those policy
> > > checking to them driver instead of checking it in the parent.
> > > 
> > Not in all invocations of get_vq_notification(). For example, in
> > vhost_vdpa_fault() you call remap_pfn_range() with notify.addr >>
> > PAGE_SHIFT so it it was not aligned you mask this misalignment.
> 
> 
> In order to have vhost_vdpa_fault() works, it should first pass the check of
> vhost_vdpa_mmap().
> 
> Othewise we won't install vma->vm_ops so there won't be a page fault for the
> doorbell.

Right, thanks for pointing this out.
Will send another version.

> 
> Thanks
> 
> 
> > 
> > > Thanks
> > > 
> > > 
> > > > +	ret.addr = (phys_addr_t)ndev->mvdev.res.phys_kick_addr;
> > > > +	ret.size = PAGE_SIZE;
> > > >    	return ret;
> > > >    }
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-06-03  8:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02  9:53 [PATCH v1] vdpa/mlx5: Add support for doorbell bypassing Eli Cohen
2021-06-03  7:11 ` Jason Wang
2021-06-03  7:11   ` Jason Wang
2021-06-03  7:38   ` Eli Cohen
2021-06-03  7:49     ` Jason Wang
2021-06-03  7:49       ` Jason Wang
2021-06-03  8:02       ` Eli Cohen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.