Skip to content

HID: intel-thc-hid: Use page count when copying read DMA buffer - #185

Open
technosf wants to merge 1 commit into
linux-surface:v7.2-surface-develfrom
technosf:intel-thc-read-dma-72
Open

technosf wants to merge 1 commit into
linux-surface:v7.2-surface-develfrom
technosf:intel-thc-read-dma-72

Conversation

@technosf

@technosf technosf commented Nov 3, 2026

Copy link
Copy Markdown

Refs linux-surface/linux-surface#2261.


sg_copy_to_buffer() walks the CPU-side scatterlist, so it needs the number of
pages passed to dma_map_sg(), not the number of mapped entries that
calc_message_len() derives from the PRD table. With an IOMMU, dma_map_sg()
can merge pages, so the PRD table holds fewer entries than the scatterlist has
pages. The copy then stops early ("Copied 4096 bytes instead of requested
7492") and the read fails with -EIO, which leaves the touch controller stuck
when a stylus sends large reports.


The patch uses sgls_nent_pages[], which already stores the page count: a
one-call change (2 lines added, 1 removed) in
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c. The change is the one
proposed by @ffaon in #2261.


Other callers checked: write_dma_buffer() also uses sg_copy_from_buffer(),
but it computes its count from the message length (DIV_ROUND_UP(len, 4K)),
and the CPU-side list has one page per entry (sgl_alloc()), so it does not
have this problem and is unchanged.


Tested on a Surface Pro 10 for Business with a 7.2 kernel and this patch
applied: multitouch and stylus work.

…uffer

sg_copy_to_buffer() walks the CPU-side scatterlist, so it needs the
number of pages passed to dma_map_sg(), not the number of mapped
entries that calc_message_len() derives from the PRD table. With an
IOMMU, dma_map_sg() can merge pages, so the PRD table holds fewer
entries than the scatterlist has pages. The copy then stops early
(e.g. "Copied 4096 bytes instead of requested 7492") and the read
fails with -EIO, which leaves the touch controller stuck when a
stylus sends large reports.

Use the page count stored in sgls_nent_pages[] instead.

Fixes: a688404 ("HID: intel-thc-hid: intel-thc: Add THC DMA interfaces")
Link: linux-surface/linux-surface#2261
Patchset: intel-thc
Signed-off-by: technosf <535060+technosf@users.noreply.github.com>
@technosf technosf changed the title HID: intel-thc-hid: intel-thc: Use page count when copying read DMA b… HID: intel-thc-hid: Use page count when copying read DMA buffer Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant