Linux USB
 help / color / mirror / Atom feed
From: Cheng Yongkang <teel4res@gmail.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [QUESTION] usb: usbfs SETINTERFACE during a runtime reset-resume
Date: Sun, 15 Nov 2026 08:37:09 -0800	[thread overview]
Message-ID: <20261115163709.226641-1-teel4res@gmail.com> (raw)

Hi Alan,

I have a question about usbfs and runtime reset-resume. I am not sure
it is a bug, so I would like to ask before sending anything.

The kerneldoc of usb_reset_and_verify_device() says:

  Locking exception: This routine may also be called from within an
  autoresume handler.  Such usage won't conflict with other tasks
  holding the device lock because these tasks should always call
  usb_autopm_resume_device(), thereby preventing any unwanted
  autoresume.

(usb_autopm_resume_device() no longer exists; I assume
usb_autoresume_device() is meant.)

proc_setintf() runs under the device lock but takes no PM reference.
After USBDEVFS_ALLOW_SUSPEND, the device can be runtime suspended
while the file is open. If it then resumes through reset-resume,
finish_port_resume() sets USB_STATE_CONFIGURED before
usb_reset_and_verify_device() runs its restore loop. A SETINTERFACE
issued at that moment passes checkintf() and calls usb_set_interface()
while the restore loop is still reading intf->cur_altsetting and
calling usb_set_interface() to put the interfaces back into their old
altsettings.

On v7.3, with dummy_hcd and a gadget that forces reset-resume, I saw
1097 SETINTERFACE calls complete inside the resume window over ten
rounds, all with -EPROTO. There were no KASAN or lockdep reports, and
I did not see any corrupted state afterwards. I know 7794f486ed0b says
that I/O to a suspended device fails with an error code, so -EPROTO by
itself may be expected.

My questions are:

1. Is usbfs expected to follow the assumption in that comment, so
   that proc_setintf() should hold a PM reference while it changes the
   altsetting?

2. Or is it up to the program to call USBDEVFS_FORBID_SUSPEND or
   USBDEVFS_WAIT_FOR_RESUME first, so that this overlap with the
   restore loop is acceptable?

3. If it is the first, would taking usb_autoresume_device() around
   checkintf() and usb_set_interface() be the right fix? In my test
   the ioctl then waited until the resume finished and returned 0,
   which changes the current behavior of failing with an error.

Thanks,
Cheng Yongkang

                 reply	other threads:[~2026-11-15 16:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261115163709.226641-1-teel4res@gmail.com \
    --to=teel4res@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox