Skip to contentSkip to conversation

vdpa/mlx5: Fix oversized null mkey longer than 32bit

PATCH In review Dragos Tatulea 3 participants 3 messages Feb 20, 2025 – Mar 3, 2025

Subsystems (4)
lore
Share & tools
lore

Dragos Tatulea

author maintainer
#0 lore raw

PATCH v2 1/1 vdpa/mlx5: Fix oversized null mkey longer than 32bit

From: Si-Wei Liu <[email protected]>

create_user_mr() has correct code to count the number of null keys used to fill in a hole for the memory map. However, fill_indir() does not follow the same to cap the range up to the 1GB limit correspondingly. Fill in more null keys for the gaps in between, so that null keys are correctly populated.

Fixes 94abbccdf291 ("vdpa/mlx5: Add shared memory registration code")

---
Changes in v2:
- Added Reported-by tag.
- Fixed typo found during review.

---
 drivers/vdpa/mlx5/core/mr.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/vdpa/mlx5/core/mr.c +5 -2
index 8455f08f5d40..61424342c096 100644
@@ -190,9 +190,12 @@ static void fill_indir(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mkey, v
 			klm->bcount = cpu_to_be32(klm_bcount(dmr->end - dmr->start));
 			preve = dmr->end;
 		} else {
+			u64 bcount = min_t(u64, dmr->start - preve, MAX_KLM_SIZE);
+
 			klm->key = cpu_to_be32(mvdev->res.null_mkey);
-			klm->bcount = cpu_to_be32(klm_bcount(dmr->start - preve));
-			preve = dmr->start;
+			klm->bcount = cpu_to_be32(klm_bcount(bcount));
+			preve += bcount;
+
 			goto again;
 		}
 	}
Signature · 1 line
2.43.0
Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · Dragos Tatulea

From: Si-Wei Liu <[email protected]>

create_user_mr() has correct code to count the number of null keys used to fill in a hole for the memory map. However, fill_indir() does not follow the same to cap the range up to the 1GB limit correspondingly. Fill in more null keys for the gaps in between, so that null keys are correctly populated.

Quoted 6 lines
Fixes 94abbccdf291 ("vdpa/mlx5: Add shared memory registration code")

Thanks

Tested-by
#2 lore raw

I tested this patch with virtio-net and mlx5 vdpa regression tests, everything works fine.

Quoted 23 lines · Jason Wang
Quoted 9 lines · Dragos Tatulea

From: Si-Wei Liu <[email protected]>

create_user_mr() has correct code to count the number of null keys used to fill in a hole for the memory map. However, fill_indir() does not follow the same to cap the range up to the 1GB limit correspondingly. Fill in more null keys for the gaps in between, so that null keys are correctly populated.

Quoted 6 lines
Fixes 94abbccdf291 ("vdpa/mlx5: Add shared memory registration code")

Thanks