[v2] vdpa/mlx5: workaround var offset within page

Message ID 20220315024733.507162-1-yajunw@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series [v2] vdpa/mlx5: workaround var offset within page |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-broadcom-Functional fail Functional Testing issues

Commit Message

Yajun Wu March 15, 2022, 2:47 a.m. UTC
  vDPA driver first uses kernel driver to allocate doorbell(VAR) area for
each device. Then uses var->mmap_off and var->length to mmap uverbs device
file as doorbell userspace virtual address.

Current kernel driver provides var->mmap_off equal to page start of VAR.
It's fine with x86 4K page server, because VAR physical address is only 4K
aligned thus locate in 4K page start.

But with aarch64 64K page server, the actual VAR physical address has
offset within page(not locate in 64K page start). So vDPA driver need add
this within page offset(caps.doorbell_bar_offset) to get right VAR virtual
address.

Fixes: 62c813706e4 ("vdpa/mlx5: map doorbell")
Cc: stable@dpdk.org

Signed-off-by: Yajun Wu <yajunw@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/vdpa/mlx5/mlx5_vdpa_virtq.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
  

Comments

Maxime Coquelin June 1, 2022, 7:55 a.m. UTC | #1
Hi Yajun,

On 3/15/22 03:47, Yajun Wu wrote:
> vDPA driver first uses kernel driver to allocate doorbell(VAR) area for
> each device. Then uses var->mmap_off and var->length to mmap uverbs device
> file as doorbell userspace virtual address.
> 
> Current kernel driver provides var->mmap_off equal to page start of VAR.
> It's fine with x86 4K page server, because VAR physical address is only 4K
> aligned thus locate in 4K page start.
> 
> But with aarch64 64K page server, the actual VAR physical address has
> offset within page(not locate in 64K page start). So vDPA driver need add
> this within page offset(caps.doorbell_bar_offset) to get right VAR virtual
> address.
> 
> Fixes: 62c813706e4 ("vdpa/mlx5: map doorbell")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yajun Wu <yajunw@nvidia.com>
> Acked-by: Matan Azrad <matan@nvidia.com>
> ---
>   drivers/vdpa/mlx5/mlx5_vdpa_virtq.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  
Maxime Coquelin June 1, 2022, 9:46 a.m. UTC | #2
On 6/1/22 09:55, Maxime Coquelin wrote:
> Hi Yajun,
> 
> On 3/15/22 03:47, Yajun Wu wrote:
>> vDPA driver first uses kernel driver to allocate doorbell(VAR) area for
>> each device. Then uses var->mmap_off and var->length to mmap uverbs 
>> device
>> file as doorbell userspace virtual address.
>>
>> Current kernel driver provides var->mmap_off equal to page start of VAR.
>> It's fine with x86 4K page server, because VAR physical address is 
>> only 4K
>> aligned thus locate in 4K page start.
>>
>> But with aarch64 64K page server, the actual VAR physical address has
>> offset within page(not locate in 64K page start). So vDPA driver need add
>> this within page offset(caps.doorbell_bar_offset) to get right VAR 
>> virtual
>> address.
>>
>> Fixes: 62c813706e4 ("vdpa/mlx5: map doorbell")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Yajun Wu <yajunw@nvidia.com>
>> Acked-by: Matan Azrad <matan@nvidia.com>
>> ---
>>   drivers/vdpa/mlx5/mlx5_vdpa_virtq.c | 9 ++++++++-
>>   1 file changed, 8 insertions(+), 1 deletion(-)
>>
> 
> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> 
> Thanks,
> Maxime
> 


The patch does not apply, could you please rebase it on top of next-
virtio?

Thanks in advance,
Maxime
  
Maxime Coquelin June 14, 2022, 9:45 a.m. UTC | #3
Hi Yajun,

On 6/1/22 11:46, Maxime Coquelin wrote:
> 
> 
> On 6/1/22 09:55, Maxime Coquelin wrote:
>> Hi Yajun,
>>
>> On 3/15/22 03:47, Yajun Wu wrote:
>>> vDPA driver first uses kernel driver to allocate doorbell(VAR) area for
>>> each device. Then uses var->mmap_off and var->length to mmap uverbs 
>>> device
>>> file as doorbell userspace virtual address.
>>>
>>> Current kernel driver provides var->mmap_off equal to page start of VAR.
>>> It's fine with x86 4K page server, because VAR physical address is 
>>> only 4K
>>> aligned thus locate in 4K page start.
>>>
>>> But with aarch64 64K page server, the actual VAR physical address has
>>> offset within page(not locate in 64K page start). So vDPA driver need 
>>> add
>>> this within page offset(caps.doorbell_bar_offset) to get right VAR 
>>> virtual
>>> address.
>>>
>>> Fixes: 62c813706e4 ("vdpa/mlx5: map doorbell")
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Yajun Wu <yajunw@nvidia.com>
>>> Acked-by: Matan Azrad <matan@nvidia.com>
>>> ---
>>>   drivers/vdpa/mlx5/mlx5_vdpa_virtq.c | 9 ++++++++-
>>>   1 file changed, 8 insertions(+), 1 deletion(-)
>>>
>>
>> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>>
>> Thanks,
>> Maxime
>>
> 
> 
> The patch does not apply, could you please rebase it on top of next-
> virtio?

Gentle reminder if you want your patch to be part of the next pull
request.

> Thanks in advance,
> Maxime
  

Patch

diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c b/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c
index 3416797d28..52287e7e58 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c
+++ b/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c
@@ -9,6 +9,7 @@ 
 #include <rte_malloc.h>
 #include <rte_errno.h>
 #include <rte_io.h>
+#include <rte_eal_paging.h>
 
 #include <mlx5_common.h>
 
@@ -123,7 +124,9 @@  mlx5_vdpa_virtqs_release(struct mlx5_vdpa_priv *priv)
 		priv->td = NULL;
 	}
 	if (priv->virtq_db_addr) {
-		claim_zero(munmap(priv->virtq_db_addr, priv->var->length));
+		/* Mask out the within page offset for munmap. */
+		claim_zero(munmap((void *)((uintptr_t)priv->virtq_db_addr &
+			~(rte_mem_page_size() - 1)), priv->var->length));
 		priv->virtq_db_addr = NULL;
 	}
 	priv->features = 0;
@@ -486,6 +489,10 @@  mlx5_vdpa_virtqs_prepare(struct mlx5_vdpa_priv *priv)
 		priv->virtq_db_addr = NULL;
 		goto error;
 	} else {
+		/* Add within page offset for 64K page system. */
+		priv->virtq_db_addr = (char *)priv->virtq_db_addr +
+			((rte_mem_page_size() - 1) &
+			priv->caps.doorbell_bar_offset);
 		DRV_LOG(DEBUG, "VAR address of doorbell mapping is %p.",
 			priv->virtq_db_addr);
 	}