mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oliver Neukum <oneukum@suse.com>
To: Hongyu Xie <xy521521@gmail.com>,
	stern@rowland.harvard.edu, oneukum@suse.com
Cc: gregkh@linuxfoundation.org, brauner@kernel.org,
	jlayton@kernel.org, jack@suse.cz, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, xiehongyu1@kylinos.cn
Subject: Re: [PATCH next] usb: usbfs: Add reset_resume for usbfs
Date: Wed, 17 Jul 2024 09:42:01 +0200	[thread overview]
Message-ID: <a648a2b3-026a-445c-8154-2da43b641570@suse.com> (raw)
In-Reply-To: <6419a4e9-e084-4eb6-8376-9202930ea8be@kylinos.cn>

On 17.07.24 03:43, Hongyu Xie wrote:
> From: Hongyu Xie <xiehongyu1@kylinos.cn>

Hi,

sorry for being incomprehensible. I'll try to do better.

>  From what I know, that CONFIG_USB_DEFAULT_PERSIST is enabled by default. Then udev->persist_enabled is set to 1 and this causing udev->reset_resume set to 1 during init2 in hub_activate.
> During resume,
> usb_resume_both
>    usb_resume_device
>      generic_resume
>        usb_port_resume
>          finish_port_resume
>            usb_reset_and_verify_device (if udev->reset_resume is 1)
>              hub_port_init
>                hub_port_reset
>    usb_resume_interface (udev->reset_resume is 1 but usbfs doesn't have reset_resume implementation so set intf->needs_binding to 1, and it will be rebind in usb_resume_complete)

That is correct. But even if CONFIG_USB_DEFAULT_PERSIST were not set, losing power
would just lead to reenumeration by another code path. Devices reset themselves
when they are power cycled. There is no way around that.

> Even before usbfs->reset_resume is called (if there is one), the USB device has already been reset

Yes, it has been reset.

> and in a good state.

No, it is not. Or rather, it is in the wrong state. This is not a question of good and bad.
It is a question of being in the same state.
  
> After all that thaw_processes is called and user-space application runs again.

Yes. And user space does not know what has happened.
> 
> So I still don't understand why "the race necessarily exists". Can you show me an example that usbfs->reset_resume causes race?

Sure. Let's look at the example of a scanner attached to the host.

OS			Scanning process (in user space)
			1. Set a resolution
2. Going to S4
3. Returning to S0
			4. Initiate a scan

As you can see the system would now scan at the wrong resolution. Step#4
has to fail. As there is no synchronization between S4 and user space, initiating
the scan can always be the last step.
For this to work, reset_resume() would have to restore the correct resolution. The kernel
cannot do so.

	Regards
		Oliver

  parent reply	other threads:[~2024-07-17  7:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-11  8:43 Hongyu Xie
2024-07-11  8:59 ` Oliver Neukum
2024-07-11 14:41   ` Alan Stern
2024-07-15  8:53     ` Oliver Neukum
2024-07-15 14:22       ` Alan Stern
2024-07-16 12:44         ` Oliver Neukum
2024-07-17  1:43           ` Hongyu Xie
2024-07-17  2:05             ` Alan Stern
2024-07-17  3:13               ` Hongyu Xie
2024-07-17  7:52                 ` Oliver Neukum
2024-07-17 13:44                 ` Alan Stern
2024-07-17 15:27                   ` Oliver Neukum
2024-07-17  7:42             ` Oliver Neukum [this message]
2024-07-18  3:23               ` Hongyu Xie
2024-07-12  3:10   ` Hongyu Xie
2024-07-13  2:22     ` Alan Stern
2024-07-15  1:13       ` Hongyu Xie
2024-07-15  8:40         ` Oliver Neukum

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=a648a2b3-026a-445c-8154-2da43b641570@suse.com \
    --to=oneukum@suse.com \
    --cc=brauner@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jack@suse.cz \
    --cc=jlayton@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=xiehongyu1@kylinos.cn \
    --cc=xy521521@gmail.com \
    /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

all inboxes | Powered by JetHome®