Skip to content

Commit 29ce8b8

Browse files
siwliu-kernelmstsirkin
authored andcommitted
vdpa/mlx5: Fix PA offset with unaligned starting iotlb map
When calculating the physical address range based on the iotlb and mr [start,end) ranges, the offset of mr->start relative to map->start is not taken into account. This leads to some incorrect and duplicate mappings. For the case when mr->start < map->start the code is already correct: the range in [mr->start, map->start) was handled by a different iteration. Fixes: 94abbcc ("vdpa/mlx5: Add shared memory registration code") Cc: [email protected] Signed-off-by: Si-Wei Liu <[email protected]> Signed-off-by: Dragos Tatulea <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Jason Wang <[email protected]>
1 parent 83e445e commit 29ce8b8

File tree

1 file changed

+5
-3
lines changed
  • drivers/vdpa/mlx5/core

1 file changed

+5
-3
lines changed

drivers/vdpa/mlx5/core/mr.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static int map_direct_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_direct_mr
373373
struct page *pg;
374374
unsigned int nsg;
375375
int sglen;
376-
u64 pa;
376+
u64 pa, offset;
377377
u64 paend;
378378
struct scatterlist *sg;
379379
struct device *dma = mvdev->vdev.dma_dev;
@@ -396,8 +396,10 @@ static int map_direct_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_direct_mr
396396
sg = mr->sg_head.sgl;
397397
for (map = vhost_iotlb_itree_first(iotlb, mr->start, mr->end - 1);
398398
map; map = vhost_iotlb_itree_next(map, mr->start, mr->end - 1)) {
399-
paend = map->addr + maplen(map, mr);
400-
for (pa = map->addr; pa < paend; pa += sglen) {
399+
offset = mr->start > map->start ? mr->start - map->start : 0;
400+
pa = map->addr + offset;
401+
paend = map->addr + offset + maplen(map, mr);
402+
for (; pa < paend; pa += sglen) {
401403
pg = pfn_to_page(__phys_to_pfn(pa));
402404
if (!sg) {
403405
mlx5_vdpa_warn(mvdev, "sg null. start 0x%llx, end 0x%llx\n",

0 commit comments

Comments
 (0)