* [PATCH] usb: musb: host: don't add the sg offset twice in PIO TX
@ 2026-11-25 16:49 Dmitry Dagunts
2026-11-25 16:55 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Dagunts @ 2026-11-25 16:49 UTC (permalink / raw)
To: Bin Liu, Greg Kroah-Hartman; +Cc: linux-usb
A PIO OUT URB without a transfer_buffer gets its first packet through a
sg_mapping_iter. sg_miter.addr already includes the offset of the sg
entry, but musb_ep_program() adds urb->sg->offset again. With a nonzero
offset the first packet is read from the wrong address: wrong data is
sent, or the read faults if that address is past the mapped page. The
packets that follow are loaded by musb_host_tx(), which uses
sg_miter.addr as it is.
With usb-storage this needs CONFIG_HIGHMEM, because usb_sg_init() leaves
transfer_buffer NULL only for highmem pages, and a sub-page write. The
highmem check in usb-storage does not catch it, as musb sets HCD_DMA even
if it is built PIO only.
Drop urb->actual_length too: for bulk and interrupt URBs it is always 0
if buf is NULL.
Seen as an oops when writing to a USB stick on an LG TV (MediaTek MT5398,
6.12.119, MUSB_PIO_ONLY, out-of-tree musb glue). Tested there with this
change and a debug switch that selects the old address, using O_DIRECT
writes of 512 to 4096 bytes from highmem, read back from the stick:
sg offset old address new address
0 correct correct
0x200, 0x400, 0x600 first 512 bytes wrong correct
0x800, 0xe00 not mapped (probed only) correct
Only compile-tested on the current tree.
Claude Code (Claude Opus 5.5) was used to diagnose the oops, to write and
run the test, and to write this fix and changelog.
Fixes: 8e8a55165469 ("usb: musb: host: Handle highmem in PIO mode")
Cc: stable@vger.kernel.org
Signed-off-by: Dmitry Dagunts <ddagunts@gmail.com>
---
drivers/usb/musb/musb_host.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 31b061248..6f78fd985 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -821,8 +821,7 @@ static void musb_ep_program(struct musb *musb, u8 epnum,
sg_miter_stop(&qh->sg_miter);
goto finish;
}
- buf = qh->sg_miter.addr + urb->sg->offset +
- urb->actual_length;
+ buf = qh->sg_miter.addr;
load_count = min_t(u32, load_count,
qh->sg_miter.length);
musb_write_fifo(hw_ep, load_count, buf);
base-commit: 730acad0b83da0d7b658d99cf87ef979012ec638
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: musb: host: don't add the sg offset twice in PIO TX
2026-11-25 16:49 [PATCH] usb: musb: host: don't add the sg offset twice in PIO TX Dmitry Dagunts
@ 2026-11-25 16:55 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-25 16:55 UTC (permalink / raw)
To: Dmitry Dagunts; +Cc: linux-usb
> A PIO OUT URB without a transfer_buffer gets its first packet through a
> sg_mapping_iter. sg_miter.addr already includes the offset of the sg
> entry, but musb_ep_program() adds urb->sg->offset again. With a nonzero
> offset the first packet is read from the wrong address: wrong data is
> sent, or the read faults if that address is past the mapped page. The
> packets that follow are loaded by musb_host_tx(), which uses
> sg_miter.addr as it is.
>
> With usb-storage this needs CONFIG_HIGHMEM, because usb_sg_init() leaves
> transfer_buffer NULL only for highmem pages, and a sub-page write. The
> highmem check in usb-storage does not catch it, as musb sets HCD_DMA even
> if it is built PIO only.
>
> Drop urb->actual_length too: for bulk and interrupt URBs it is always 0
> if buf is NULL.
> [ ... ]
> run the test, and to write this fix and changelog.
>
> Fixes: 8e8a55165469 ("usb: musb: host: Handle highmem in PIO mode")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dmitry Dagunts <ddagunts@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125164942.1310501-1-ddagunts@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-25 16:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 16:49 [PATCH] usb: musb: host: don't add the sg offset twice in PIO TX Dmitry Dagunts
2026-11-25 16:55 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox