All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Dagunts <ddagunts@gmail.com>
To: Bin Liu <b-liu@ti.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org
Subject: [PATCH] usb: musb: host: don't add the sg offset twice in PIO TX
Date: Wed, 25 Nov 2026 11:49:42 -0500	[thread overview]
Message-ID: <20261125164942.1310501-1-ddagunts@gmail.com> (raw)

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


             reply	other threads:[~2026-11-25 16:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 16:49 Dmitry Dagunts [this message]
2026-11-25 16:55 ` [PATCH] usb: musb: host: don't add the sg offset twice in PIO TX sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125164942.1310501-1-ddagunts@gmail.com \
    --to=ddagunts@gmail.com \
    --cc=b-liu@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.