linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* usb: gadget: f_fs: O_NONBLOCK waits MAX_SCHEDULE_TIMEOUT
@ 2015-03-31 18:53 Baxter, Jim
  2015-03-31 20:28 ` Felipe Balbi
  2015-04-01  8:06 ` Robert Baldyga
  0 siblings, 2 replies; 9+ messages in thread
From: Baxter, Jim @ 2015-03-31 18:53 UTC (permalink / raw)
  To: linux-kernel, linux-usb; +Cc: Zapolskiy, Vladimir

Hi,

I have been looking at an issue where a phone that is the Function FS
host sometimes locks up and causes the function:
static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data
*io_data) in drivers/usb/gadget/function/f_fs.c to timeout after
MAX_SCHEDULE_TIMEOUT jiffies.

We are opening the ffs connection with the O_NONBLOCK option and this
timeout seems to be far too long.

The code causing the wait is here (line 834):

if (unlikely(ret < 0)) {
    /* nop */
} else if (unlikely(
        wait_for_completion_interruptible(&done))) {
    ret = -EINTR;
    usb_ep_dequeue(ep->ep, req);
} else {

The function call wait_for_completion_interruptible(&done) equates to:
wait_for_completion_interruptible_timeout(&done, MAX_SCHEDULE_TIMEOUT);


I was wondering what to change to fix this, is it reasonable to use a
very small timeout if it is O_NONBLOCK or is any blocking not allowed?

I would appreciate any thoughts on how this should work?

Thank you,
Jim

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: usb: gadget: f_fs: O_NONBLOCK waits MAX_SCHEDULE_TIMEOUT
  2015-03-31 18:53 usb: gadget: f_fs: O_NONBLOCK waits MAX_SCHEDULE_TIMEOUT Baxter, Jim
@ 2015-03-31 20:28 ` Felipe Balbi
  2015-04-01  8:06 ` Robert Baldyga
  1 sibling, 0 replies; 9+ messages in thread
From: Felipe Balbi @ 2015-03-31 20:28 UTC (permalink / raw)
  To: Baxter, Jim; +Cc: linux-kernel, linux-usb, Zapolskiy, Vladimir

[-- Attachment #1: Type: text/plain, Size: 1721 bytes --]

Hi,

(it helps if you Cc the maintainer too :-)

On Tue, Mar 31, 2015 at 07:53:39PM +0100, Baxter, Jim wrote:
> I have been looking at an issue where a phone that is the Function FS
> host sometimes locks up and causes the function:

which USB controller ? which kernel ? which platform ?

> static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data
> *io_data) in drivers/usb/gadget/function/f_fs.c to timeout after
> MAX_SCHEDULE_TIMEOUT jiffies.

yeah, that's pretty much "never timeout" :-)

> We are opening the ffs connection with the O_NONBLOCK option and this
> timeout seems to be far too long.

is this your own application ? How can I make sure it's correct ?

> The code causing the wait is here (line 834):
> 
> if (unlikely(ret < 0)) {
>     /* nop */
> } else if (unlikely(
>         wait_for_completion_interruptible(&done))) {

right, this is waiting for the previous usb_ep_queue() to complete. Why
hasn't it completed yet ? Do you have a USB sniffer to check if data has
passed over the wire ? Did the host shifted any token in the wire trying
to move data around ?

>     ret = -EINTR;
>     usb_ep_dequeue(ep->ep, req);
> } else {
> 
> The function call wait_for_completion_interruptible(&done) equates to:
> wait_for_completion_interruptible_timeout(&done, MAX_SCHEDULE_TIMEOUT);
> 
> 
> I was wondering what to change to fix this, is it reasonable to use a
> very small timeout if it is O_NONBLOCK or is any blocking not allowed?
> 
> I would appreciate any thoughts on how this should work?

sounds like a bug on your USB peripheral controller driver. Which one is
that ? Again, which kernel ? Where are the logs ?

regards

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: usb: gadget: f_fs: O_NONBLOCK waits MAX_SCHEDULE_TIMEOUT
  2015-03-31 18:53 usb: gadget: f_fs: O_NONBLOCK waits MAX_SCHEDULE_TIMEOUT Baxter, Jim
  2015-03-31 20:28 ` Felipe Balbi
@ 2015-04-01  8:06 ` Robert Baldyga
  2015-04-01 17:29   ` Baxter, Jim
  1 sibling, 1 reply; 9+ messages in thread
From: Robert Baldyga @ 2015-04-01  8:06 UTC (permalink / raw)
  To: Baxter, Jim; +Cc: linux-kernel, linux-usb, Zapolskiy, Vladimir, balbi

Hi,

On 03/31/2015 08:53 PM, Baxter, Jim wrote:
> Hi,
> 
> I have been looking at an issue where a phone that is the Function FS
> host sometimes locks up and causes the function:
> static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data
> *io_data) in drivers/usb/gadget/function/f_fs.c to timeout after
> MAX_SCHEDULE_TIMEOUT jiffies.
> 
> We are opening the ffs connection with the O_NONBLOCK option and this
> timeout seems to be far too long.
> 
> The code causing the wait is here (line 834):
> 
> if (unlikely(ret < 0)) {
>     /* nop */
> } else if (unlikely(
>         wait_for_completion_interruptible(&done))) {
>     ret = -EINTR;
>     usb_ep_dequeue(ep->ep, req);
> } else {
> 
> The function call wait_for_completion_interruptible(&done) equates to:
> wait_for_completion_interruptible_timeout(&done, MAX_SCHEDULE_TIMEOUT);
> 
> 
> I was wondering what to change to fix this, is it reasonable to use a
> very small timeout if it is O_NONBLOCK or is any blocking not allowed?
> 
> I would appreciate any thoughts on how this should work?

FunctionFS is very specific, because read/write operations are directly
translated into USB requests, which are asynchronous, so you cannot use
O_NONBLOCK.

If you need non-blocking API you can use Asynchronous I/O (AIO). You can
find some examples in kernel sources (tools/usb/ffs-aio-example/).

Br,
Robert Baldyga

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: usb: gadget: f_fs: O_NONBLOCK waits MAX_SCHEDULE_TIMEOUT
  2015-04-01  8:06 ` Robert Baldyga
@ 2015-04-01 17:29   ` Baxter, Jim
  2015-04-02  0:23     ` Peter Chen
  0 siblings, 1 reply; 9+ messages in thread
From: Baxter, Jim @ 2015-04-01 17:29 UTC (permalink / raw)
  To: Robert Baldyga; +Cc: linux-kernel, linux-usb, Zapolskiy, Vladimir, balbi

> 
> FunctionFS is very specific, because read/write operations are directly
> translated into USB requests, which are asynchronous, so you cannot use
> O_NONBLOCK.
> 
> If you need non-blocking API you can use Asynchronous I/O (AIO). You can
> find some examples in kernel sources (tools/usb/ffs-aio-example/).
> 
> Br,
> Robert Baldyga
> 

Thank you, that sounds like the best approach.
In this case I think perhaps the long wait without any data is an
problem with the imx6 Chipidea USB controller.

I guess it should suspend and drop the connections if there is no
traffic for more than 10ms?

Thanks.
Jim Baxter

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: usb: gadget: f_fs: O_NONBLOCK waits MAX_SCHEDULE_TIMEOUT
  2015-04-01 17:29   ` Baxter, Jim
@ 2015-04-02  0:23     ` Peter Chen
  2015-05-22 11:12       ` Baxter, Jim
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Chen @ 2015-04-02  0:23 UTC (permalink / raw)
  To: Baxter, Jim
  Cc: Robert Baldyga, linux-kernel, linux-usb, Zapolskiy, Vladimir, balbi

On Wed, Apr 01, 2015 at 06:29:05PM +0100, Baxter, Jim wrote:
> > 
> > FunctionFS is very specific, because read/write operations are directly
> > translated into USB requests, which are asynchronous, so you cannot use
> > O_NONBLOCK.
> > 
> > If you need non-blocking API you can use Asynchronous I/O (AIO). You can
> > find some examples in kernel sources (tools/usb/ffs-aio-example/).
> > 
> > Br,
> > Robert Baldyga
> > 
> 
> Thank you, that sounds like the best approach.
> In this case I think perhaps the long wait without any data is an
> problem with the imx6 Chipidea USB controller.

What's the possible problem?

> 
> I guess it should suspend and drop the connections if there is no
> traffic for more than 10ms?
> 

If the Device side NAK host's IN/OUT token continually, the pipe will 
not be stopped, the host will send token continually until the application
cancel this request.

-- 

Best Regards,
Peter Chen

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: usb: gadget: f_fs: O_NONBLOCK waits MAX_SCHEDULE_TIMEOUT
  2015-04-02  0:23     ` Peter Chen
@ 2015-05-22 11:12       ` Baxter, Jim
  2015-05-25  1:55         ` Peter Chen
  0 siblings, 1 reply; 9+ messages in thread
From: Baxter, Jim @ 2015-05-22 11:12 UTC (permalink / raw)
  To: Peter Chen
  Cc: Robert Baldyga, linux-kernel, linux-usb, Zapolskiy, Vladimir, balbi


> On Wed, Apr 01, 2015 at 06:29:05PM +0100, Baxter, Jim wrote:
>>>
>>> FunctionFS is very specific, because read/write operations are directly
>>> translated into USB requests, which are asynchronous, so you cannot use
>>> O_NONBLOCK.
>>>
>>> If you need non-blocking API you can use Asynchronous I/O (AIO). You can
>>> find some examples in kernel sources (tools/usb/ffs-aio-example/).
>>>
>>> Br,
>>> Robert Baldyga
>>>
>>
>> Thank you, that sounds like the best approach.
>> In this case I think perhaps the long wait without any data is an
>> problem with the imx6 Chipidea USB controller.
> 
> What's the possible problem?

Sorry for the delay in replying, I have been getting some more details
with a USB Analyser.

The scenario is that the NCM  device is enumerating so we see the
messages to:

SetAddress (1)
GetDescriptor (Device)
GetDescriptor (StringN)
GetDescriptor (Configuration)
SetConfiguration (1)
GetDescriptor (String iInterface)
GetDescriptor (String iInterface)

At this point the NCM host sends Writes to the F_FS EP0 but for some
reason the host device does not respond and only issues SOF packets for
hours. This happens occasionally and is fixed by turning the device off
and on again.


Unless I am mistaken from a NCM gadget point of view the attached device
is working correctly and there is no way to know it has failed, is that
correct?

> 
>>
>> I guess it should suspend and drop the connections if there is no
>> traffic for more than 10ms?
>>
> 
> If the Device side NAK host's IN/OUT token continually, the pipe will 
> not be stopped, the host will send token continually until the application
> cancel this request.
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: usb: gadget: f_fs: O_NONBLOCK waits MAX_SCHEDULE_TIMEOUT
  2015-05-22 11:12       ` Baxter, Jim
@ 2015-05-25  1:55         ` Peter Chen
  2015-06-01 16:25           ` Baxter, Jim
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Chen @ 2015-05-25  1:55 UTC (permalink / raw)
  To: Baxter, Jim
  Cc: Robert Baldyga, linux-kernel, linux-usb, Zapolskiy, Vladimir, balbi

 
> >>>
> >>> FunctionFS is very specific, because read/write operations are
> >>> directly translated into USB requests, which are asynchronous, so
> >>> you cannot use O_NONBLOCK.
> >>>
> >>> If you need non-blocking API you can use Asynchronous I/O (AIO). You
> >>> can find some examples in kernel sources (tools/usb/ffs-aio-example/).
> >>>
> >>> Br,
> >>> Robert Baldyga
> >>>
> >>
> >> Thank you, that sounds like the best approach.
> >> In this case I think perhaps the long wait without any data is an
> >> problem with the imx6 Chipidea USB controller.
> >
> > What's the possible problem?
> 
> Sorry for the delay in replying, I have been getting some more details with a
> USB Analyser.
> 
> The scenario is that the NCM  device is enumerating so we see the messages to:
> 
> SetAddress (1)
> GetDescriptor (Device)
> GetDescriptor (StringN)
> GetDescriptor (Configuration)
> SetConfiguration (1)
> GetDescriptor (String iInterface)
> GetDescriptor (String iInterface)
> 
> At this point the NCM host sends Writes to the F_FS EP0 but for some reason
> the host device does not respond and only issues SOF packets for hours. This
> happens occasionally and is fixed by turning the device off and on again.
> 
> 

We may find this 'some reason', is it device error or host error?

Do you have below patch in your code:

commit 953c66469735aed8d2ada639a72b150f01dae605
Author: Abbas Raza <Abbas_Raza@mentor.com>
Date:   Thu Jul 17 19:34:31 2014 +0800

    usb: chipidea: udc: Disable auto ZLP generation on ep0
    
    There are 2 methods for ZLP (zero-length packet) generation:
    1) In software
    2) Automatic generation by device controller
    
    1) is implemented in UDC driver and it attaches ZLP to IN packet if
       descriptor->size < wLength
    2) can be enabled/disabled by setting ZLT bit in the QH
    
Peter

> Unless I am mistaken from a NCM gadget point of view the attached device is
> working correctly and there is no way to know it has failed, is that correct?
> 
> >
> >>
> >> I guess it should suspend and drop the connections if there is no
> >> traffic for more than 10ms?
> >>
> >
> > If the Device side NAK host's IN/OUT token continually, the pipe will
> > not be stopped, the host will send token continually until the
> > application cancel this request.
> >

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: usb: gadget: f_fs: O_NONBLOCK waits MAX_SCHEDULE_TIMEOUT
  2015-05-25  1:55         ` Peter Chen
@ 2015-06-01 16:25           ` Baxter, Jim
  2015-06-02  3:01             ` Peter Chen
  0 siblings, 1 reply; 9+ messages in thread
From: Baxter, Jim @ 2015-06-01 16:25 UTC (permalink / raw)
  To: Peter Chen
  Cc: Robert Baldyga, linux-kernel, linux-usb, Zapolskiy, Vladimir, balbi

>>>>>
>>>>> FunctionFS is very specific, because read/write operations are
>>>>> directly translated into USB requests, which are asynchronous, so
>>>>> you cannot use O_NONBLOCK.
>>>>>
>>>>> If you need non-blocking API you can use Asynchronous I/O (AIO). You
>>>>> can find some examples in kernel sources (tools/usb/ffs-aio-example/).
>>>>>
>>>>> Br,
>>>>> Robert Baldyga
>>>>>
>>>>
>>>> Thank you, that sounds like the best approach.
>>>> In this case I think perhaps the long wait without any data is an
>>>> problem with the imx6 Chipidea USB controller.
>>>
>>> What's the possible problem?
>>
>> Sorry for the delay in replying, I have been getting some more details with a
>> USB Analyser.
>>
>> The scenario is that the NCM  device is enumerating so we see the messages to:
>>
>> SetAddress (1)
>> GetDescriptor (Device)
>> GetDescriptor (StringN)
>> GetDescriptor (Configuration)
>> SetConfiguration (1)
>> GetDescriptor (String iInterface)
>> GetDescriptor (String iInterface)
>>
>> At this point the NCM host sends Writes to the F_FS EP0 but for some reason
>> the host device does not respond and only issues SOF packets for hours. This
>> happens occasionally and is fixed by turning the device off and on again.
>>
>>
> 
> We may find this 'some reason', is it device error or host error?
> 
> Do you have below patch in your code:
> 
> commit 953c66469735aed8d2ada639a72b150f01dae605
> Author: Abbas Raza <Abbas_Raza@mentor.com>
> Date:   Thu Jul 17 19:34:31 2014 +0800
> 
>     usb: chipidea: udc: Disable auto ZLP generation on ep0
>     
>     There are 2 methods for ZLP (zero-length packet) generation:
>     1) In software
>     2) Automatic generation by device controller
>     
>     1) is implemented in UDC driver and it attaches ZLP to IN packet if
>        descriptor->size < wLength
>     2) can be enabled/disabled by setting ZLT bit in the QH
>     
> Peter

Yes I have that patch, could that be a problem?

Jim

> 
>> Unless I am mistaken from a NCM gadget point of view the attached device is
>> working correctly and there is no way to know it has failed, is that correct?
>>
>>>
>>>>
>>>> I guess it should suspend and drop the connections if there is no
>>>> traffic for more than 10ms?
>>>>
>>>
>>> If the Device side NAK host's IN/OUT token continually, the pipe will
>>> not be stopped, the host will send token continually until the
>>> application cancel this request.
>>>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: usb: gadget: f_fs: O_NONBLOCK waits MAX_SCHEDULE_TIMEOUT
  2015-06-01 16:25           ` Baxter, Jim
@ 2015-06-02  3:01             ` Peter Chen
  0 siblings, 0 replies; 9+ messages in thread
From: Peter Chen @ 2015-06-02  3:01 UTC (permalink / raw)
  To: Baxter, Jim
  Cc: Robert Baldyga, linux-kernel, linux-usb, Zapolskiy, Vladimir, balbi

 
> >>>>
> >>>> Thank you, that sounds like the best approach.
> >>>> In this case I think perhaps the long wait without any data is an
> >>>> problem with the imx6 Chipidea USB controller.
> >>>
> >>> What's the possible problem?
> >>
> >> Sorry for the delay in replying, I have been getting some more
> >> details with a USB Analyser.
> >>
> >> The scenario is that the NCM  device is enumerating so we see the
> messages to:
> >>
> >> SetAddress (1)
> >> GetDescriptor (Device)
> >> GetDescriptor (StringN)
> >> GetDescriptor (Configuration)
> >> SetConfiguration (1)
> >> GetDescriptor (String iInterface)
> >> GetDescriptor (String iInterface)
> >>
> >> At this point the NCM host sends Writes to the F_FS EP0 but for some
> >> reason the host device does not respond and only issues SOF packets
> >> for hours. This happens occasionally and is fixed by turning the device off
> and on again.
> >>
> >>
> >
> > We may find this 'some reason', is it device error or host error?
> >
> > Do you have below patch in your code:
> >
> > commit 953c66469735aed8d2ada639a72b150f01dae605
> > Author: Abbas Raza <Abbas_Raza@mentor.com>
> > Date:   Thu Jul 17 19:34:31 2014 +0800
> >
> >     usb: chipidea: udc: Disable auto ZLP generation on ep0
> >
> >     There are 2 methods for ZLP (zero-length packet) generation:
> >     1) In software
> >     2) Automatic generation by device controller
> >
> >     1) is implemented in UDC driver and it attaches ZLP to IN packet if
> >        descriptor->size < wLength
> >     2) can be enabled/disabled by setting ZLT bit in the QH
> >
> > Peter
> 
> Yes I have that patch, could that be a problem?
> 

No, you need that patch.
Get to know which side has problem first.

Peter

> Jim
> 
> >
> >> Unless I am mistaken from a NCM gadget point of view the attached
> >> device is working correctly and there is no way to know it has failed, is that
> correct?
> >>
> >>>
> >>>>
> >>>> I guess it should suspend and drop the connections if there is no
> >>>> traffic for more than 10ms?
> >>>>
> >>>
> >>> If the Device side NAK host's IN/OUT token continually, the pipe
> >>> will not be stopped, the host will send token continually until the
> >>> application cancel this request.
> >>>

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-06-02  3:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-31 18:53 usb: gadget: f_fs: O_NONBLOCK waits MAX_SCHEDULE_TIMEOUT Baxter, Jim
2015-03-31 20:28 ` Felipe Balbi
2015-04-01  8:06 ` Robert Baldyga
2015-04-01 17:29   ` Baxter, Jim
2015-04-02  0:23     ` Peter Chen
2015-05-22 11:12       ` Baxter, Jim
2015-05-25  1:55         ` Peter Chen
2015-06-01 16:25           ` Baxter, Jim
2015-06-02  3:01             ` Peter Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).