From: Lu Baolu <baolu.lu@linux.intel.com>
To: Alan Stern <stern@rowland.harvard.edu>,
Felipe Balbi <felipe.balbi@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH 1/1] usb: misc: usbtest: add fix for driver hang
Date: Wed, 10 Aug 2016 13:11:43 +0800 [thread overview]
Message-ID: <57AAB78F.8030203@linux.intel.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1608091008380.1919-100000@iolanthe.rowland.org>
Hi,
On 08/09/2016 10:18 PM, Alan Stern wrote:
> On Tue, 9 Aug 2016, Felipe Balbi wrote:
>
>> Hi,
>>
>> Lu Baolu <baolu.lu@linux.intel.com> writes:
>>> In sg_timeout(), req->status is set to "-ETIMEDOUT" before calling
>>> into usb_sg_cancel(). usb_sg_cancel() will do nothing and return
>>> directly if req->status has been set to a non-zero value. This will
>>> cause driver hang as soon as transfer time out is triggered.
> ...
>
>>> This patch fixes this driver hang. It should be back-ported to stable
>>> kernel with version after v3.15.
>>>
>>> Cc: stable@vger.kernel.org
>>> Cc: Alan Stern <stern@rowland.harvard.edu>
>>> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
>>> ---
>>> drivers/usb/misc/usbtest.c | 1 -
>>> 1 file changed, 1 deletion(-)
>>>
>>> diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
>>> index 6b978f0..6c6586d 100644
>>> --- a/drivers/usb/misc/usbtest.c
>>> +++ b/drivers/usb/misc/usbtest.c
>>> @@ -585,7 +585,6 @@ static void sg_timeout(unsigned long _req)
>>> {
>>> struct usb_sg_request *req = (struct usb_sg_request *) _req;
>>>
>>> - req->status = -ETIMEDOUT;
>>> usb_sg_cancel(req);
>>> }
>> IMO, req->status = -ETIMEDOUT should still be done, but perhaps after
>> usb_sg_cancel(). Alan?
> That would race with sg_complete(), perhaps causing a bunch of error
> messages. A better approach would be to delete the assignment as
> above and then change perform_sglist():
>
> usb_sg_wait(req);
> - del_timer_sync(&sg_timer);
> retval = req->status;
> + if (!del_timer_sync(&sg_timer))
> + retval = -ETIMEDOUT;
I agree. I will send v2 with this change included.
I am afraid that req->status is managed by usb core. A spin lock
is used to serialize the change of it. The driver could check the
value of req->status, but should not change it (especially change
it without the hold of the lock). Otherwise, it could cause race or
errors in usb core.
This happens in another driver implemented in drivers/mfd/rtsx_usb.c.
static void rtsx_usb_sg_timed_out(unsigned long data)
{
struct rtsx_ucr *ucr = (struct rtsx_ucr *)data;
dev_dbg(&ucr->pusb_intf->dev, "%s: sg transfer timed out", __func__);
usb_sg_cancel(&ucr->current_sg);
/* we know the cancellation is caused by time-out */
ucr->current_sg.status = -ETIMEDOUT;
(^^^^ status being changed by driver without hold of lock)
}
I will send another patch to enhance this later.
Best regards,
Lu Baolu
prev parent reply other threads:[~2016-08-10 18:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-09 5:01 [PATCH 1/1] usb: misc: usbtest: add fix for driver hang Lu Baolu
2016-08-09 9:17 ` Felipe Balbi
2016-08-09 14:18 ` Alan Stern
2016-08-10 5:11 ` Lu Baolu [this message]
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=57AAB78F.8030203@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=felipe.balbi@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stable@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