Skip to contentSkip to conversation

vdpa/mlx5: workaround var offset within page

PATCH Superseded Yajun Wu 2 participants 7 messages Mar 14, 2022 – Jun 17, 2022

Subsystems (2)
lore
Share & tools
lore

Yajun Wu

author
#0 lore raw

PATCH 1/1 vdpa/mlx5: workaround var offset within page

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")
---
 drivers/vdpa/mlx5/mlx5_vdpa_virtq.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/vdpa/mlx5/mlx5_vdpa_virtq.c +9 -1
index 3416797d28..0748710a76 100644
@@ -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,10 @@ 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 ummap. */
+		claim_zero(munmap((void *)((uint64_t)priv->virtq_db_addr &
+			~(rte_mem_page_size() - 1ULL)),
+			priv->var->length));
 		priv->virtq_db_addr = NULL;
 	}
 	priv->features = 0;
@@ -486,6 +490,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);
 	}
Signature · 1 line
2.27.0
author
#1 lore raw

PATCH v2 1/1 vdpa/mlx5: workaround var offset within page

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")
---
 drivers/vdpa/mlx5/mlx5_vdpa_virtq.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/vdpa/mlx5/mlx5_vdpa_virtq.c +8 -1
index 3416797d28..52287e7e58 100644
@@ -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);
 	}
Signature · 1 line
2.27.0
Reviewed-by on v2 1/1
#2 lore raw

Hi Yajun,

Quoted 13 lines · Yajun Wu

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.

Quoted 9 lines
Fixes 62c813706e4 ("vdpa/mlx5: map doorbell")
---
  drivers/vdpa/mlx5/mlx5_vdpa_virtq.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)

Thanks,
Maxime

#3 lore raw
Quoted 26 lines · Maxime Coquelin

Hi Yajun,

Quoted 13 lines · Yajun Wu

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.

Quoted 9 lines
Fixes 62c813706e4 ("vdpa/mlx5: map doorbell")

---
  drivers/vdpa/mlx5/mlx5_vdpa_virtq.c | 9 ++++++++-

  1 file changed, 8 insertions(+), 1 deletion(-)
Quoted 5 lines

Thanks,
Maxime

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

Thanks in advance,
Maxime

#4 lore raw

Hi Yajun,

Quoted 31 lines · Maxime Coquelin
Quoted 28 lines · Maxime Coquelin

Hi Yajun,

Quoted 13 lines · Yajun Wu

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.

Quoted 9 lines
Fixes 62c813706e4 ("vdpa/mlx5: map doorbell")

---
  drivers/vdpa/mlx5/mlx5_vdpa_virtq.c | 9 ++++++++-

  1 file changed, 8 insertions(+), 1 deletion(-)
Quoted 7 lines
Quoted 3 lines

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.

Quoted 2 lines

Thanks in advance,
Maxime

author
#5 lore raw

PATCH v3 1/1 vdpa/mlx5: workaround var offset within page

In reply to Yajun Wu

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")
---
 drivers/vdpa/mlx5/mlx5_vdpa.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/vdpa/mlx5/mlx5_vdpa.c +7 -1
index 76fa5d4299..8a33a0c9a1 100644
@@ -14,6 +14,7 @@
 #include <rte_errno.h>
 #include <rte_string_fns.h>
 #include <rte_bus_pci.h>
+#include <rte_eal_paging.h>
 
 #include <mlx5_glue.h>
 #include <mlx5_common.h>
@@ -560,6 +561,9 @@ mlx5_vdpa_create_dev_resources(struct mlx5_vdpa_priv *priv)
 		rte_errno = errno;
 		return -rte_errno;
 	}
+	/* 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);
 	priv->td = mlx5_devx_cmd_create_td(ctx);
@@ -705,7 +709,9 @@ mlx5_vdpa_release_dev_resources(struct mlx5_vdpa_priv *priv)
 	if (priv->td)
 		claim_zero(mlx5_devx_cmd_destroy(priv->td));
 	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));
 	if (priv->var)
 		mlx5_glue->dv_free_var(priv->var);
 }
Signature · 1 line
2.30.2
#6 lore raw
Quoted 16 lines · Yajun Wu

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")
Quoted 7 lines
---
  drivers/vdpa/mlx5/mlx5_vdpa.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)

Applied to dpdk-next-virtio/main.

Thanks,
Maxime