You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mass storage gadget: default stall=1 gives dmesg errors/warnings #7452
Loading g_mass_storage (or g_multi) with defaults (i.e. stall=1), generates many errors into dmesg.
Unclear if it affects performances and how. Linux docs suggest defaults may be disabled on some USB devices known not to work correctly.
Are Pi devices known to be such citizens, and require use of stall=0 because default driver does not work-around some issues?
Steps to reproduce the behaviour
Load g_mass_storage with options g_mass_storage file=/drive.bin stall=1 removable=1
(same goes with g_multi driver)
After a little while dmesg shows errors as below, repeatedly...
No more dmesg errors with stall=0
Device (s)
Raspberry Pi Zero 2 W
System
any kernel up to 6.18.y, experimented with all PiZeros versions.
$ vcgencmd version
Copyright (c) 2012 Broadcom
version 9e19353907b3bc5c36ea355a409e3a5a151de89e (clean) (release) (start_cd)
These messages are from the dwc2 USB gadget (device-mode) driver on a Raspberry Pi (BCM2835/6/7, USB base at 0x20980000), where ep5in is bulk IN
endpoint 5. Here's what each line means:
Message
Meaning
sethalt(..., 1)
Endpoint is being stalled (HALT feature set)
sethalt(..., 0)
Endpoint stall is being cleared
start_req: ep5 is stalled
A queued transfer was attempted but the endpoint is still stalled, so it was skipped
The sequence tells a story:
The gadget function driver explicitly stalls ep5in (e.g., to signal a protocol error to the host)
The USB host notices the stall and sends a CLEAR_FEATURE(ENDPOINT_HALT) control request
dwc2 clears the stall (sethalt(..., 0))
The gadget driver immediately re-stalls it (sethalt(..., 1)) — because whatever error condition caused the original stall hasn't been resolved
The cycle repeats
Root cause is in the gadget function driver sitting above dwc2 — something is calling usb_ep_set_halt() on this endpoint repeatedly. Common triggers:
A USB Mass Storage gadget signalling a SCSI error (sense data) to the host
A CDC or other class driver receiving a request it can't satisfy
A queued request completing with an error, and the driver responding by stalling rather than re-queuing
The dwc2 driver itself is behaving correctly — it's just faithfully executing what the upper layer asks. The fix, if this is a problem, would be in
whichever gadget function driver owns ep5in.
Yes, and got no response there on actual matter: hoping there would be more insight through this channel about the root cause and remedies.
This fail is 100% repeatable on my end (whatever disk used), and had been observed in various other instances (ref1 ,ref2 and al.): the only workaround that spread-out is to use stall=0 with no more explanations (like in PiOS whitepaper)...
Is there any evidence that isn't correct?
Is baseline g_mass_storage usecase supposed to always have failure?
Dunno why the common triggers (SCSI error for instance) would ever happen in such circumstance.
Further diagnosis, looking now at the mass storage gadget driver:
The main loop at line 2600–2604 is:
get_next_command → do_scsi_command → finish_reply → send_status
finish_reply calls halt_bulk_in_endpoint after queuing the last data buffer via start_in_transfer (line 1613–1618). At that moment the endpoint queue is non-empty (the data transfer is in progress), so dwc2_hsotg_ep_sethalt returns -EAGAIN — generating the first sethalt(ep5in, 1) log entry at t=34.516 without actually stalling the hardware.
halt_bulk_in_endpoint then sits in a 100 ms polling loop, sleeping and retrying. After ~105 ms the data request completes and the queue is empty, so the retry at t=34.621578 succeeds and the endpoint is actually stalled.
The main loop then falls through to send_status, which immediately queues the CSW (13-byte status packet) on the now-stalled endpoint. dwc2_hsotg_start_req sees the hardware stall bit set and emits the warning at t=34.621655, leaving the request sitting in the queue.
When the host sends CLEAR_FEATURE(ENDPOINT_HALT) at t=34.621802, dwc2 clears the stall and starts the queued CSW. The CSW completes quickly, the thread wakes, processes the next buffered CBW from bulk_out, runs through do_scsi_command → finish_reply again with another residue, and the whole cycle repeats — producing the stall at t=34.622059 and the next ~100 ms gap.
The problem is the 100 ms fixed-sleep retry loop in halt_bulk_in_endpoint. Rather than waiting for the in-flight transfer to complete via the existing io_wait / buffer-state mechanism, it just sleeps and polls. This means:
Every command with residue has at least a 100 ms forced latency before the stall is actually applied, during which the hardware is still active.
The 100 ms delay is also longer than strictly necessary — the pending transfer could complete in microseconds, but the thread always sleeps the full interval.
The fix would be to replace the msleep_interruptible(100) retry with a proper wait on common->io_wait for the pending buffer to drain, similar to how sleep_thread() works elsewhere in the driver.
[ Updated to make the quotation clearer - this is not my analysis ]
wow... Do you think same would apply to g_multi or even plain libcomposite configfs composition? (the same error happens in any of the 3 configurations)
Looking at the host side (6.17.0-35-generic #35~24.04.1-Ubuntu), while PiZeroW runs: modprobe g_mass_storage file=/dev/mmcblk0p1 stall=1 removable=1
Pi side dmesg:
[361986.419359] usb 1-6: device descriptor read/64, error -110
[362002.289402] usb 1-6: device descriptor read/64, error -110
[362002.393669] usb usb1-port6: attempt power cycle
[362002.772343] usb 1-6: new full-speed USB device number 82 using xhci_hcd
[362007.809029] xhci_hcd 0000:00:14.0: Timeout while waiting for setup device command
[362013.441224] xhci_hcd 0000:00:14.0: Timeout while waiting for setup device command
[362013.648150] usb 1-6: device not accepting address 82, error -62
[362013.648253] usb 1-6: WARN: invalid context state for evaluate context command.
[362013.760280] usb 1-6: new full-speed USB device number 83 using xhci_hcd
[362019.071648] xhci_hcd 0000:00:14.0: Timeout while waiting for setup device command
[362024.703001] xhci_hcd 0000:00:14.0: Timeout while waiting for setup device command
[362024.911864] usb 1-6: device not accepting address 83, error -62
[362024.912005] usb 1-6: WARN: invalid context state for evaluate context command.
[362024.912143] usb usb1-port6: unable to enumerate USB device
[362028.448572] usb 1-6: new high-speed USB device number 84 using xhci_hcd
[362028.572506] usb 1-6: New USB device found, idVendor=0525, idProduct=a4a5, bcdDevice= 6.18
[362028.572525] usb 1-6: New USB device strings: Mfr=3, Product=4, SerialNumber=0
[362028.572533] usb 1-6: Product: Mass Storage Gadget
[362028.572539] usb 1-6: Manufacturer: Linux 6.18.35-0-rpi with 20980000.usb
[362028.575346] usb-storage 1-6:1.0: USB Mass Storage device detected
[362028.575776] usb-storage 1-6:1.0: Quirks match for vid 0525 pid a4a5: 10000
[362028.575911] scsi host1: usb-storage 1-6:1.0
[362029.631098] scsi 1:0:0:0: Direct-Access Linux File-Stor Gadget 0618 PQ: 0 ANSI: 2
[362029.632092] sd 1:0:0:0: Attached scsi generic sg0 type 0
[362029.633409] sd 1:0:0:0: Power-on or device reset occurred
[362029.634210] sd 1:0:0:0: [sda] 215040 512-byte logical blocks: (110 MB/105 MiB)
[362029.745031] sd 1:0:0:0: [sda] Write Protect is off
[362029.745046] sd 1:0:0:0: [sda] Mode Sense: 0f 00 00 00
[362029.854710] sd 1:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[362030.081233] sda:
[362030.081389] sd 1:0:0:0: [sda] Attached SCSI removable disk
Unsure what cause the initial dwc2_hsotg_ep_sethalt (may even be after Attached SCSI removable disk)
I see those stall messages using g_mass_storage_gadget - it seems to be intentional:
/*
* For Bulk-only, mark the end of the data with a short
* packet. If we are allowed to stall, halt the bulk-in
* endpoint. (Note: This violates the Bulk-Only Transport
* specification, which requires us to pad the data if we
* don't halt the endpoint. Presumably nobody will mind.)
*/
} else {
bh->inreq->zero = 1;
if (!start_in_transfer(common, bh))
rc = -EIO;
common->next_buffhd_to_fill = bh->next;
if (common->can_stall)
rc = halt_bulk_in_endpoint(common->fsg);
}
I don't get any such messages using libcomposite and usb_f_mass_storage.
So should we just consider those dmesg entries as not harmful, and assume this would not affect reliability or performances?
(don't have non-Pi gadget-capable device to test, and check same messages are shown too with other HW)
Would (default) stall=1 option then be recommended over stall=0 despite those messages?
Activity
pelwell commentedon Jun 22, 2026
A quick AI diagnosis:
These messages are from the dwc2 USB gadget (device-mode) driver on a Raspberry Pi (BCM2835/6/7, USB base at 0x20980000), where ep5in is bulk IN
endpoint 5. Here's what each line means:
The sequence tells a story:
Root cause is in the gadget function driver sitting above dwc2 — something is calling usb_ep_set_halt() on this endpoint repeatedly. Common triggers:
The dwc2 driver itself is behaving correctly — it's just faithfully executing what the upper layer asks. The fix, if this is a problem, would be in
whichever gadget function driver owns ep5in.
Is there any evidence that isn't correct?
pelwell commentedon Jun 22, 2026
Previously discussed in your Forum thread: https://forums.raspberrypi.com/viewtopic.php?t=395143
macmpi commentedon Jun 22, 2026
Yes, and got no response there on actual matter: hoping there would be more insight through this channel about the root cause and remedies.
This fail is 100% repeatable on my end (whatever disk used), and had been observed in various other instances (ref1 ,ref2 and al.): the only workaround that spread-out is to use
stall=0with no more explanations (like in PiOS whitepaper)...Is baseline
g_mass_storageusecase supposed to always have failure?Dunno why the common triggers (SCSI error for instance) would ever happen in such circumstance.
pelwell commentedon Jun 22, 2026
Further diagnosis, looking now at the mass storage gadget driver:
[ Updated to make the quotation clearer - this is not my analysis ]
macmpi commentedon Jun 22, 2026
wow... Do you think same would apply to
g_multior even plainlibcomposite configfscomposition? (the same error happens in any of the 3 configurations)macmpi commentedon Jun 23, 2026
Looking at the host side (
6.17.0-35-generic #35~24.04.1-Ubuntu), while PiZeroW runs:modprobe g_mass_storage file=/dev/mmcblk0p1 stall=1 removable=1Pi side
dmesg:Host side
dmesg:Unsure what cause the initial
dwc2_hsotg_ep_sethalt(may even be afterAttached SCSI removable disk)pelwell commentedon Jun 23, 2026
I see those stall messages using g_mass_storage_gadget - it seems to be intentional:
I don't get any such messages using libcomposite and usb_f_mass_storage.
pelwell commentedon Jun 23, 2026
Correction - I do if it is properly configured with
stall=1.macmpi commentedon Jun 23, 2026
So should we just consider those
dmesgentries as not harmful, and assume this would not affect reliability or performances?(don't have non-Pi gadget-capable device to test, and check same messages are shown too with other HW)
Would (default)
stall=1option then be recommended overstall=0despite those messages?pelwell commentedon Jun 23, 2026
I think it's pointless log spam. See #7453. I think you know what to do with these.
macmpi commentedon Jun 23, 2026
Ok, thanks a lot for investigating and clearing it-up!
FYI @JamesH65 this might help for the remaining bits on related whitepaper:
stall=0may be safely removed in samples.Closing.
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages
42 remaining items
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages
usb: dwc2: gadget: Demote stall-related messages