All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hui Wang <hui.wang@canonical.com>
To: Hans de Goede <hdegoede@redhat.com>,
	linux-usb@vger.kernel.org, oneukum@suse.com,
	gregkh@linuxfoundation.org
Subject: Re: [PATCH] USB: UAS: don't unbind and rebind the driver during usb_reset_device
Date: Sun, 21 Feb 2021 21:23:17 +0800	[thread overview]
Message-ID: <b4e51bb9-8717-979b-1060-2d821b3c4e23@canonical.com> (raw)
In-Reply-To: <b1fe6cf4-b48f-c7e6-17c0-2ed04d8f3aa1@redhat.com>


On 2/21/21 6:20 PM, Hans de Goede wrote:
> Hi,
>
> On 2/21/21 9:51 AM, Hui Wang wrote:
>> Once pre_reset() or post_reset() returns non-zero, the disconnect()
>> and probe() of the usb_driver will be called. In the disconnect(),
>> the scsi_host will be removed and be freed after scsi_host_put(), in
>> the probe(), the new scsi_host and uas_dev_info will be created.
>>
>> If the usb_reset_device() is triggered by eh_device_reset_handler(),
>> and pre_reset()/post_reset() returns non-zero, the disconnect() and
>> probe() will be called, then returns to the eh_device_reset_handler(),
>> it still accesses old scsi related variables and uas_dev_info, and so
>> do its caller functions.
>>
>> Here change the pre_reset() and post_reset() to let them only return
>> 0, after this change, the usb_reset_device() will only reset this
>> usb devcie from its hub port, will not execute unbind and rebind
>> usb_driver during reset.
> We only return non 0 from the pre/post reset handles if we failed
> to ensure the device is in a known state.
>
> E.g. in uas_post_reset() we only fail if we failed to switch the
> device from the good old usb-storage protocol back to the UAS mode
> which it was in before.
>
> Continuing with the UAS driver bound, as if everything is fine,
> while the device is actually in longer in UAS mode is a bad idea.
>
> Summarizing this patch is wrong: NACK.
>
> ###
>
> I assume that you wrote this patch because of some bug report ?
>
> In such a case please always include a link to the bug (or forum
> discussion) in the commit message.

OK, got it, so far there is no bug about it. I just wrote some code and 
called usb_reset_device(), found it will trigger to call disconnect() 
and probe() in some cases. I found uas.c could trigger to call 
disconnect() and probe() in eh_device_reset_handler(), and could 
possibility introduce use-after-free issue. I thought resetting the 
device from the hub port is enough to let it back to normal work mode, 
if it doesn't, calling disconnect() and probe() will not help either. 
And I checked some eh_device_reset_handler callback in other drivers, 
looks like they don't trigger unbind and rebind, then I wrote this patch.

Thanks,

Hui.

>
> UAS problems typically are caused by people shoving a 2.5 inch
> or m2 SSD in an USB enclosure which is powered from the USB bus
> only. SSD-s can cause pretty hefty power-consumption peaks when
> high queue depts are used; and these bus powered devices typically
> cannot handle these peaks. Either because the port they are
> plugged in does not deliver enough current; and/or because they
> don't have enough buffering (capacitors) on the enclosure's PCB
> to deal with short but quite large consumption peaks.
>
> Regards,
>
> Hans
>
>
>
>
>
>
>
>
>> Signed-off-by: Hui Wang <hui.wang@canonical.com>
>> ---
>>   drivers/usb/storage/uas.c | 3 +--
>>   1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
>> index bef89c6bd1d7..c66287448e34 100644
>> --- a/drivers/usb/storage/uas.c
>> +++ b/drivers/usb/storage/uas.c
>> @@ -1121,7 +1121,6 @@ static int uas_pre_reset(struct usb_interface *intf)
>>   	if (uas_wait_for_pending_cmnds(devinfo) != 0) {
>>   		shost_printk(KERN_ERR, shost, "%s: timed out\n", __func__);
>>   		scsi_unblock_requests(shost);
>> -		return 1;
>>   	}
>>   
>>   	uas_free_streams(devinfo);
>> @@ -1152,7 +1151,7 @@ static int uas_post_reset(struct usb_interface *intf)
>>   
>>   	scsi_unblock_requests(shost);
>>   
>> -	return err ? 1 : 0;
>> +	return 0;
>>   }
>>   
>>   static int uas_suspend(struct usb_interface *intf, pm_message_t message)
>>

  reply	other threads:[~2021-02-21 13:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-21  8:51 [PATCH] USB: UAS: don't unbind and rebind the driver during usb_reset_device Hui Wang
2021-02-21 10:20 ` Hans de Goede
2021-02-21 13:23   ` Hui Wang [this message]
2021-02-22  7:59   ` Oliver Neukum
2021-02-22 12:40     ` Hui Wang
2021-02-22 12:51       ` Oliver Neukum
2021-02-22 13:02         ` Hui Wang
2021-02-22 13:50           ` Oliver Neukum
2021-02-22 15:14             ` Hui Wang

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=b4e51bb9-8717-979b-1060-2d821b3c4e23@canonical.com \
    --to=hui.wang@canonical.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=oneukum@suse.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 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.