Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH rdma-rc] RDMA/rxe: Bound MR copy and flush chunks to MR pages
@ 2026-11-28 14:08 Andrew Stellman
  2026-11-28 14:14 ` sashiko-bot
  2026-11-28 17:21 ` Zhu Yanjun
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Stellman @ 2026-11-28 14:08 UTC (permalink / raw)
  To: Zhu Yanjun
  Cc: Zhu Yanjun, Li Zhijian, Jason Gunthorpe, Leon Romanovsky,
	linux-rdma, linux-kernel

From: Andrew Stellman <astellman@stellman-greene.com>

A fast-reg MR can use 4 KiB pages on a 64 KiB-page kernel, with each
MR page in its own page_info entry. rxe_mr_copy_xarray() limits each
chunk to the end of the system page, not the end of the MR page, so a
copy that crosses an MR-page boundary continues in the same system
page instead of moving to the next page_info entry.
rxe_mr_flush_pmem_iova() has the same bound.

Limit each chunk to the end of the MR page when MR pages are smaller
than PAGE_SIZE. For MR pages of PAGE_SIZE or larger the bound is
unchanged.

On arm64 with 64 KiB pages (QEMU TCG, mainline 7cd8495c0f16), a
test-only hook built an MR by hand with two 4 KiB pages at offsets
0x1000 and 0x3000 of two different system pages and called
rxe_mr_copy() for 32 bytes starting 16 bytes before the MR-page
boundary, checking that the last 16 bytes came from or went to the
second MR page. Without this patch, both the read and the write check
failed. With it, both passed, and they failed again with it reverted.
A 32-byte read within one MR page passed on all three builds. The
flush path was not run.

The issue was found by Claude Opus 5.5 running Quality Playbook, an
LLM-driven code review tool:
https://github.com/andrewstellman/quality-playbook
The fix was drafted with OpenAI GPT-6 (Codex) and this changelog with
Claude Opus 5.5, and both were reviewed by me.

Fixes: 12985e5915a0 ("RDMA/rxe: Fix iova-to-va conversion for MR page sizes != PAGE_SIZE")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
A reproducer is available on request.

 drivers/infiniband/sw/rxe/rxe_mr.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c
index 13cb28d3916f6e..258f8524ef06b4 100644
--- a/drivers/infiniband/sw/rxe/rxe_mr.c
+++ b/drivers/infiniband/sw/rxe/rxe_mr.c
@@ -333,12 +333,14 @@ static int rxe_mr_copy_xarray(struct rxe_mr *mr, u64 iova, void *addr,
 		unsigned long index = rxe_mr_iova_to_index(mr, iova);
 		struct rxe_mr_page *info = &mr->page_info[index];
 		unsigned int page_offset = rxe_mr_iova_to_page_offset(mr, iova);
+		unsigned int chunk = min_t(unsigned int, PAGE_SIZE,
+					   mr_page_size(mr)) - page_offset;
 
 		if (!info->page)
 			return -EFAULT;
 
 		page_offset += info->offset;
-		bytes = min_t(unsigned int, length, PAGE_SIZE - page_offset);
+		bytes = min_t(unsigned int, length, chunk);
 		va = kmap_local_page(info->page);
 
 		if (dir == RXE_FROM_MR_OBJ)
@@ -519,12 +521,14 @@ static int rxe_mr_flush_pmem_iova(struct rxe_mr *mr, u64 iova, unsigned int leng
 		unsigned long index = rxe_mr_iova_to_index(mr, iova);
 		struct rxe_mr_page *info = &mr->page_info[index];
 		unsigned int page_offset = rxe_mr_iova_to_page_offset(mr, iova);
+		unsigned int chunk = min_t(unsigned int, PAGE_SIZE,
+					   mr_page_size(mr)) - page_offset;
 
 		if (!info->page)
 			return -EFAULT;
 
 		page_offset += info->offset;
-		bytes = min_t(unsigned int, length, PAGE_SIZE - page_offset);
+		bytes = min_t(unsigned int, length, chunk);
 
 		va = kmap_local_page(info->page);
 		arch_wb_cache_pmem(va + page_offset, bytes);
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-28 17:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28 14:08 [PATCH rdma-rc] RDMA/rxe: Bound MR copy and flush chunks to MR pages Andrew Stellman
2026-11-28 14:14 ` sashiko-bot
2026-11-28 17:21 ` Zhu Yanjun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox