Skip to contentSkip to conversation

RDMA/hns: Fix wrong PBL offset when VA is not aligned to PAGE_SIZE

PATCH Applied Weihang Li 2 participants 2 messages Jul 14, 2020 – Jul 16, 2020

Subsystems (2)
lore
Share & tools
lore

Weihang Li

author
#0 lore raw

PATCH 1/1 RDMA/hns: Fix wrong PBL offset when VA is not aligned to PAGE_SIZE

From: Xi Wang <[email protected]>

The ROCEE use "VA % buf_page_size" to caclulate the offset in the PBL's first page, the actual PA corresponding to the MR's VA is equal to MR's PA plus this offset. The first PA in PBL has already been aligned to PAGE_SIZE after calling ib_umem_get(), but the MR's VA may not. If the buf_page_size is small than the PAGE_SIZE, this will lead the ROCEE to access the wrong memory because the offset is smaller than expected.

Fixes 9b2cf76c9f05 ("RDMA/hns: Optimize PBL buffer allocation process")
---
 drivers/infiniband/hw/hns/hns_roce_mr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/hns/hns_roce_mr.c +1 -1
index 0e71ebe..6b226a5 100644
@@ -120,7 +120,7 @@ static int alloc_mr_pbl(struct hns_roce_dev *hr_dev, struct hns_roce_mr *mr,
 
 	mr->pbl_hop_num = is_fast ? 1 : hr_dev->caps.pbl_hop_num;
 	buf_attr.page_shift = is_fast ? PAGE_SHIFT :
-			      hr_dev->caps.pbl_buf_pg_sz + HNS_HW_PAGE_SHIFT;
+			      hr_dev->caps.pbl_buf_pg_sz + PAGE_SHIFT;
 	buf_attr.region[0].size = length;
 	buf_attr.region[0].hopnum = mr->pbl_hop_num;
 	buf_attr.region_count = 1;
Signature · 1 line
2.8.1
maintainer Applied
#1 lore raw
Quoted 9 lines · Weihang Li

From: Xi Wang <[email protected]>

The ROCEE use "VA % buf_page_size" to caclulate the offset in the PBL's first page, the actual PA corresponding to the MR's VA is equal to MR's PA plus this offset. The first PA in PBL has already been aligned to PAGE_SIZE after calling ib_umem_get(), but the MR's VA may not. If the buf_page_size is small than the PAGE_SIZE, this will lead the ROCEE to access the wrong memory because the offset is smaller than expected.

Quoted 6 lines
Fixes 9b2cf76c9f05 ("RDMA/hns: Optimize PBL buffer allocation process")
---
 drivers/infiniband/hw/hns/hns_roce_mr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to for-rc, thanks

Jason