* [PATCH] USB: cdc-acm: restore the line coding after a reset-resume
@ 2026-11-19 12:28 Piotr Kubik
2026-11-19 12:36 ` sashiko-bot
2026-11-19 12:47 ` Oliver Neukum
0 siblings, 2 replies; 3+ messages in thread
From: Piotr Kubik @ 2026-11-19 12:28 UTC (permalink / raw)
To: Greg Kroah-Hartman, Oliver Neukum
Cc: Piotr Kubik, linux-usb, linux-kernel, Francesco Lavra, stable
A device that loses power during system suspend comes back at its
power-on line coding. With USB persist, the USB core then resets the
device and calls acm_reset_resume(), but acm->line still holds the line
coding that the driver sent last. acm_tty_set_termios() sends
SET_LINE_CODING only when the termios differ from acm->line, so an open
with the same settings sends nothing. The port then runs at the wrong
rate until the termios change or the device is probed again.
Send the cached line coding from acm_reset_resume(). Send it only for
the control interface, because the USB core calls reset_resume for the
data interface too. Use the variant without the autopm reference,
because reset_resume also runs in a runtime resume of the device, where
usb_autopm_get_interface() would wait for that same resume and never
return. Ignore the result, as acm_probe() does, because a device without
USB_CDC_CAP_LINE need not support the request.
I saw the fault on my workstation while using serial consoles.
Claude Code agent (Opus 5.5) traced the cause to the cached
acm->line and wrote the first draft of this patch and this commit message.
It also wrote and ran the test: a QEMU guest with the adapter passed
through, and a USB power cut while the guest was in S3.
Two other Claude instances reviewed the patch, the message and the test
record. I reviewed the patch and I understand the change.
Fixes: a91b0c502285 ("cdc_acm: add reset_resume method")
Cc: stable@vger.kernel.org
Signed-off-by: Piotr Kubik <piotr@kubik.pl>
---
Notes:
Reproduced and tested on v7.4-rc3-178-g20eef29b7c84 in a QEMU 10.0.13
q35 guest (TCG, qemu-xhci) with a WCH CH344 quad UART (1a86:55d5) passed
through from the host. Port 0 is wired to a 115200 8N1 console that
answers a carriage return with a 24-byte login prompt. The guest holds
the port open and suspends to RAM. While the guest is suspended, the host
cuts VBUS of the hub port of the adapter for 3 s and then wakes the
guest, which reset-resumes the adapter. The host's own cdc-acm binds the
adapter between the power cut and the wakeup, so the adapter is at 9600
or at its power-on line coding when the guest resumes.
The patch is based on usb-linus f11fe7603df0, where cdc-acm.c and
cdc-acm.h are the same as in the tested tree.
Without this patch (3 runs): the read after the resume returns 1 byte
and no prompt, and usbmon shows no SET_LINE_CODING after the resume.
With this patch (3 runs): the read returns the prompt, and usbmon shows
one SET_LINE_CODING per port, with the cached line coding of that port.
Also with this patch: S3 without the power cut, and a runtime resume
with the RESET_RESUME quirk set for the adapter, both send the line
coding once per port and complete. Without the power cut the CH344 keeps
its line coding, so the unpatched driver shows no fault in those cases.
Build: make W=1 drivers/usb/class/cdc-acm.o gives no new warnings.
checkpatch.pl --strict reports no errors, warnings or checks.
Not tested:
- a device that rejects SET_LINE_CODING (no USB_CDC_CAP_LINE)
- a device with a combined control and data interface
- this patch on bare metal; the fault itself was seen on a 6.12 host
after S3
- a port that is open during a runtime reset-resume
- an autopm reference in reset_resume: the wait without end comes from
reading rpm_resume(), not from a test
drivers/usb/class/cdc-acm.c | 35 ++++++++++++++++++++++++++++-------
1 file changed, 28 insertions(+), 7 deletions(-)
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 666969ffd194..2e6710baa170 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -108,15 +108,11 @@ static void acm_release_minor(struct acm *acm)
* Functions for ACM control messages.
*/
-static int acm_ctrl_msg(struct acm *acm, int request, int value,
- void *buf, int len)
+static int __acm_ctrl_msg(struct acm *acm, int request, int value,
+ void *buf, int len)
{
int retval;
- retval = usb_autopm_get_interface(acm->control);
- if (retval)
- return retval;
-
retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0),
request, USB_RT_ACM, value,
acm->control->altsetting[0].desc.bInterfaceNumber,
@@ -126,9 +122,23 @@ static int acm_ctrl_msg(struct acm *acm, int request, int value,
"%s - rq 0x%02x, val %#x, len %#x, result %d\n",
__func__, request, value, len, retval);
+ return retval < 0 ? retval : 0;
+}
+
+static int acm_ctrl_msg(struct acm *acm, int request, int value,
+ void *buf, int len)
+{
+ int retval;
+
+ retval = usb_autopm_get_interface(acm->control);
+ if (retval)
+ return retval;
+
+ retval = __acm_ctrl_msg(acm, request, value, buf, len);
+
usb_autopm_put_interface(acm->control);
- return retval < 0 ? retval : 0;
+ return retval;
}
/* devices aren't required to support these requests.
@@ -1743,6 +1753,17 @@ static int acm_reset_resume(struct usb_interface *intf)
if (tty_port_initialized(&acm->port))
tty_port_tty_hangup(&acm->port, false);
+ /*
+ * The device can lose its line coding, for example when it loses
+ * power during system suspend, and acm_tty_set_termios() sends the
+ * line coding only when it differs from acm->line. Send it once, for
+ * the control interface. In a runtime resume of the device, an autopm
+ * reference here would wait for this resume and never return.
+ */
+ if (intf == acm->control)
+ __acm_ctrl_msg(acm, USB_CDC_REQ_SET_LINE_CODING, 0,
+ &acm->line, sizeof(acm->line));
+
return acm_resume(intf);
}
base-commit: f11fe7603df07fbb9fa02b0d385c1696c87a6dab
--
2.55.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] USB: cdc-acm: restore the line coding after a reset-resume
2026-11-19 12:28 [PATCH] USB: cdc-acm: restore the line coding after a reset-resume Piotr Kubik
@ 2026-11-19 12:36 ` sashiko-bot
2026-11-19 12:47 ` Oliver Neukum
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-19 12:36 UTC (permalink / raw)
To: Piotr Kubik; +Cc: linux-usb
> A device that loses power during system suspend comes back at its
> power-on line coding. With USB persist, the USB core then resets the
> device and calls acm_reset_resume(), but acm->line still holds the line
> coding that the driver sent last. acm_tty_set_termios() sends
> SET_LINE_CODING only when the termios differ from acm->line, so an open
> with the same settings sends nothing. The port then runs at the wrong
> rate until the termios change or the device is probed again.
>
> Send the cached line coding from acm_reset_resume(). Send it only for
> the control interface, because the USB core calls reset_resume for the
> data interface too. Use the variant without the autopm reference,
> because reset_resume also runs in a runtime resume of the device, where
> usb_autopm_get_interface() would wait for that same resume and never
> return. Ignore the result, as acm_probe() does, because a device without
> USB_CDC_CAP_LINE need not support the request.
>
> I saw the fault on my workstation while using serial consoles.
> Claude Code agent (Opus 5.5) traced the cause to the cached
> acm->line and wrote the first draft of this patch and this commit message.
> It also wrote and ran the test: a QEMU guest with the adapter passed
> through, and a USB power cut while the guest was in S3.
> Two other Claude instances reviewed the patch, the message and the test
> record. I reviewed the patch and I understand the change.
>
> Fixes: a91b0c502285 ("cdc_acm: add reset_resume method")
> Cc: stable@vger.kernel.org
> Signed-off-by: Piotr Kubik <piotr@kubik.pl>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119122842.3611681-1-piotr@kubik.pl?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] USB: cdc-acm: restore the line coding after a reset-resume
2026-11-19 12:28 [PATCH] USB: cdc-acm: restore the line coding after a reset-resume Piotr Kubik
2026-11-19 12:36 ` sashiko-bot
@ 2026-11-19 12:47 ` Oliver Neukum
1 sibling, 0 replies; 3+ messages in thread
From: Oliver Neukum @ 2026-11-19 12:47 UTC (permalink / raw)
To: Piotr Kubik, Greg Kroah-Hartman, Oliver Neukum
Cc: linux-usb, linux-kernel, Francesco Lavra, stable
On 19.11.26 13:28, Piotr Kubik wrote:
Hi,
thank you for this patch. However, it has an issue.
Let me comment on this inline.
> + /*
> + * The device can lose its line coding, for example when it loses
> + * power during system suspend, and acm_tty_set_termios() sends the
> + * line coding only when it differs from acm->line. Send it once, for
> + * the control interface. In a runtime resume of the device, an autopm
> + * reference here would wait for this resume and never return.
> + */
> + if (intf == acm->control)
This test is problematic. The interfaces may be resumed in any order.
You are setting a line coding before the rest of the device is
resumed.
To do this cleanly, you need to look at the counter.
Regards
Oliver
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-19 12:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 12:28 [PATCH] USB: cdc-acm: restore the line coding after a reset-resume Piotr Kubik
2026-11-19 12:36 ` sashiko-bot
2026-11-19 12:47 ` Oliver Neukum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox