XDMA: proper write-read selection for get_user_pages_fast

Open Beginner friendly
#388 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
c

Research direction

Start in XDMA/linux-kernel/xdma/cdev_sgdma.c at char_sgdma_map_user_buf_to_sgl and inspect how the write argument maps to H2C and C2H transfers. Verify get_user_pages_fast requests writable pages only when DMA writes to user memory, then validate the driver or kernel build; done means read-only H2C buffers can be pinned without requesting write access.

Written by the indexing model from the issue text.

Description

diff --git a/XDMA/linux-kernel/xdma/cdev_sgdma.c b/XDMA/linux-kernel/xdma/cdev_sgdma.c
index 4271173..0333c27 100755
--- a/XDMA/linux-kernel/xdma/cdev_sgdma.c
+++ b/XDMA/linux-kernel/xdma/cdev_sgdma.c
@@ -319,7 +319,9 @@ static int char_sgdma_map_user_buf_to_sgl(struct xdma_io_cb *cb, bool write)
 		goto err_out;
 	}
 
-	rv = get_user_pages_fast((unsigned long)buf, pages_nr, 1/* write */,
+	/* write=true means H2C (DMA reads user pages): pin read-only.
+	 * write=false means C2H (DMA writes user pages): pin writable. */
+	rv = get_user_pages_fast((unsigned long)buf, pages_nr, !write,
 				cb->pages);
 	/* No pages were pinned */
 	if (rv < 0) {

With the hardcoded 1, H2C always pins writable. That's overly broad — if your H2C source buffer is a read-only mmap() (e.g., a mapped file opened O_RDONLY), the kernel refuses the pin because you're requesting write access to a read-only VMA, even though you only need to read from it.

Dominant language
C
Stars
856
Forks
570
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Xilinx/dma_ip_drivers

All issues in Xilinx/dma_ip_drivers

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.