All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Yang,Wei" <Wei.Yang@windriver.com>
To: "Yang,Wei" <Wei.Yang@windriver.com>,
	Alan Stern <stern@rowland.harvard.edu>,
	Michal Nazarewicz <mina86@mina86.com>,
	Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Cc: Felipe Balbi <balbi@ti.com>, <gregkh@linuxfoundation.org>,
	USB list <linux-usb@vger.kernel.org>,
	Kernel development list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1] USB:gadget: Fix a warning while loading g_mass_storage
Date: Wed, 4 Jun 2014 10:34:22 +0800	[thread overview]
Message-ID: <538E85AE.5080601@windriver.com> (raw)
In-Reply-To: <538E745B.1020200@windriver.com>

Guys,

It seems the previous description is out of order. I describe it again. 
Sorry for it.

irq handler
  |
  |-> s3c_hsotg_disconnect()
        |
        |-> common->new_fsg = NULL
        |-> common->state = FSG_STATE_CONFIG
        |-> wakes up fsg_main_thread.
  |->set USB device address.

fsg_main_thread
              |
              |-> handle_exception
                      |
                      |-> common->state = FSG_STATE_IDLE
                      |-> do_set_interface()
  irq happens -------------->

irq handler needs to handle USB_REQ_SET_CONFIGURATION request
  |
  |-> set_config()
         |
         |-> common->new_fsg = new_fsg;
         |-> common->state = FSG_STATE_CONFIG
         |-> cdev->delayed_status++
         |-> wakes up fsg_main_thread

fsg_main_thread
              |
              |-> if(common->new_fsg)
                        |-> usb_composite_setup_continue()
                                       |-> cdev->delayed_status--
              |-> fsg_main_thread still finds the common->state is equal 
to FSG_STATE_IDLE
              |-> so it invokes handle_exception again, subsequently the 
usb_composite_setup_continue
              |-> is executed again. It would fininally results in the 
warning.

Thanks
Wei
On 06/04/2014 09:20 AM, Yang,Wei wrote:
> On 06/03/2014 10:48 PM, Alan Stern wrote:
>> On Tue, 3 Jun 2014 Wei.Yang@windriver.com wrote:
>>
>>> From: Yang Wei <Wei.Yang@windriver.com>
>>>
>>> While loading g_mass_storage module, the following warning is 
>>> triggered.
>>> In fact, it is more easy to reproduce it with RT kernel.
>>>
>>> WARNING: at drivers/usb/gadget/composite.c:
>>> usb_composite_setup_continue: Unexpected call
>>> Modules linked in: fat vfat minix nls_cp437 nls_iso8859_1 
>>> g_mass_storage
>>> [<800179cc>] (unwind_backtrace+0x0/0x104) from [<80619608>] 
>>> (dump_stack+0x20/0x24)
>>> [<80619608>] (dump_stack+0x20/0x24) from [<80025100>] 
>>> (warn_slowpath_common+0x64/0x74)
>>> [<80025100>] (warn_slowpath_common+0x64/0x74) from [<800251cc>] 
>>> (warn_slowpath_fmt+0x40/0x48)
>>> [<800251cc>] (warn_slowpath_fmt+0x40/0x48) from [<7f047774>] 
>>> (usb_composite_setup_continue+0xb4/0xbc [g_mass_storage])
>>> [<7f047774>] (usb_composite_setup_continue+0xb4/0xbc 
>>> [g_mass_storage]) from [<7f047ad4>] (handle_exception+0x358/0x3e4 
>>> [g_mass_storage])
>>> [<7f047ad4>] (handle_exception+0x358/0x3e4 [g_mass_storage]) from 
>>> [<7f048080>] (fsg_main_thread+0x520/0x157c [g_mass_storage])
>>> [<7f048080>] (fsg_main_thread+0x520/0x157c [g_mass_storage]) from 
>>> [<8004bc90>] (kthread+0x98/0x9c)
>>> [<8004bc90>] (kthread+0x98/0x9c) from [<8000faec>] 
>>> (kernel_thread_exit+0x0/0x8)
>>>
>>> The root cause just likes the following scenario.
>>>
>>> irq thread
>>>
>>> composite_disconnect()
>>> |
>>> |->fsg_disable() fsg->common->new_fsg = NULL
>>>                   and then wake fsg_main_thread
>>>                   with seting common->state to
>>>                   FSG_STATE_CONFIG_CHANGE.
>>> fsg_main_thread
>>>                                                      |
>>> |->do_set_interface()
>>> irq thread
>>>
>>> set_config()
>>> |
>>> |->fsg_set_alt() fsg->common->new_fsg = new_fsg
>>>                   and then also wake up fsg_main_thread
>>>                   with setting common->state to
>>>                   FSG_STATE_CONFIG_CHANGE.
>>>                                                      |-> 
>>> if(common->new_fsg)
>>> usb_composite_setup_continue()
>>>
>>> In this case, fsg_main_thread would invoke usb_composite_setup_continue
>>> twice, so the second call would trigger the above call trace, as we 
>>> also
>>> save common->new_fsg while changing the common->state.
>> Michal and Andrzej:
>>
>> I haven't paid much attention to these matters, because you handled the
>> conversion from g_file_storage to f_mass_storage using the composite
>> framework.  But this patch seemed odd, so I took a closer look.
>
> Let me make sense it, Robert once introduced the following patch to 
> fix disconnect handling of s3c-hsotg.
>
> commit d18f7116a5ddb8263fe62b05ad63e5ceb5875791
> Author: Robert Baldyga <r.baldyga@samsung.com>
> Date:   Thu Nov 21 13:49:18 2013 +0100
>
>     usb: gadget: s3c-hsotg: fix disconnect handling
>
>     This patch moves s3c_hsotg_disconnect function call from USBSusp 
> interrupt
>     handler to SET_ADDRESS request handler.
>
>     It's because disconnected state can't be detected directly, 
> because this
>     hardware doesn't support Disconnected interrupt for device mode. 
> For both
>     Suspend and Disconnect events there is one interrupt USBSusp, but 
> calling
>     s3c_hsotg_disconnect from this interrupt handler causes config 
> reset in
>     composite layer, which is not undesirable for Suspended state.
>
>     For this reason s3c_hsotg_disconnect is called from SET_ADDRESS 
> request
>     handler, which occurs always after disconnection, so we do disconnect
>     immediately before we are connected again. It's probably only way we
>     can do handle disconnection correctly.
>
>     Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
>     Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
>     Signed-off-by: Felipe Balbi <balbi@ti.com>
>
> Just like what the commit log described, s3c_hsotg_disconnect is 
> called from SET_ADDRESS request handler, therefore,
> reset_config would finally be called, it raises a 
> FSG_STATE_CONFIG_CHANGE exception and wakes up fsg_main_thread to
> handle this exception. After handling SET_ADDRESS, subsequently the 
> irq hanler of s3c-hsotg would also invokes composite_setup()
> function to handle USB_REQ_SET_CONFIGURATION request, set_config would 
> be invoked, it also raises a FSG_STATE_CONFIG_CHANGE
> exception and wakes up fsg_main_thread, in mean time, 
> cdev->delayed_status would be plus one. Right? If I am missing 
> something, please
> let me know it.:-) If so, the following scenario would trigger the 
> above call trace.
>
> irq handler
>   |
>   |-> s3c_hsotg_disconnect()
>            |
>            |-> common->new_fsg = NULL
>            |-> common->state to FSG_STATE_CONFIG.
>            |-> wakes up fsg_main_thread.
>   |-> set USB device address
>
> fsg_main_thread finds the common->state == FSG_STATE_CONFIG
> |
> |-> handle_execption
> |
> |-> set common->state to FSG_STATE_IDLE
> irq hanppens ------------>|
>  irq handler needs to hanle USB_REQ_SET_CONFIGURATION request. 
> |->do_set_interface()
>   |-> set_config()
>          |
>          |-> common->new_fsg = new_fsg;
>          |-> common->state = FSG_STATE_CONFIG
>          |-> cdev->delayed_status++
>          |-> wakes up fsg_main_thread
>
> |-> Now the common->state == FSG_STATE_CONFIG
> |-> if(common->new_fsg)
> usb_composite_setup_continue()
> |->cdev->delayed_status--
>                                                                  | 
> fsg_main_thread finds the common->state still is FSG_STATE_CONFIG,
>                     | so it would invoke handle_execption again.
>                     |->hanle_execption
>                              |->  set common->state to FSG_STATE_IDLE
>                              |->  do_set_interface()
>                              |-> if (common->new_fsg)
> usb_composite_setup_continue()
>                                             |-> cdev->delayed_status 
> == 0, so
> this warning is triggered.
>
>
> Thanks
> Wei
>
>>
>> In f_mass_storage.c, struct fsg_common is shared among all the function
>> instances.  This structure includes things like cmnd and nluns, which
>> will in general be different for different functions.
>>
>> That's okay if each function is in a separate config, but what happens
>> when there are multiple functions in the same config, using different
>> interfaces?  What if the host sends concurrent commands to two of these
>> functions?
>>
>> Am I missing something?
>>
>> Alan Stern
>>
>>
>>
>


  parent reply	other threads:[~2014-06-04  2:34 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-03  9:37 [PATCH v1] USB:gadget: Fix a warning while loading g_mass_storage Wei.Yang
2014-06-03 14:48 ` Alan Stern
2014-06-04  1:20   ` Yang,Wei
2014-06-04  1:45     ` Peter Chen
2014-06-04  3:16       ` Yang,Wei
2014-06-04  4:41         ` Peter Chen
2014-06-04 13:56         ` Alan Stern
2014-06-04 18:48           ` Paul Zimmerman
2014-06-05  1:30           ` Peter Chen
2014-06-05 14:21             ` Alan Stern
2014-06-04  2:34     ` Yang,Wei [this message]
2014-06-04 12:06   ` Andrzej Pietrasiewicz
2014-06-04 15:26     ` Alan Stern
2014-06-05 10:00       ` Andrzej Pietrasiewicz
2014-06-05 18:10         ` Alan Stern
2014-06-04  4:32 ` [PATCH v2] " Wei.Yang
2014-06-05 18:08   ` Alan Stern
2014-06-09  6:02     ` Yang,Wei
2014-06-09  6:19   ` [PATCH v3] " Wei.Yang
2014-06-13  6:22     ` Yang,Wei
2014-06-13 13:39       ` Alan Stern
2014-06-14 13:10         ` Yang,Wei
2014-06-13  9:44     ` Michal Nazarewicz
2014-06-13 13:43       ` Alan Stern
2014-06-13 14:57         ` Michal Nazarewicz
2014-06-15  2:40   ` [PATCH] " Wei.Yang
2014-06-15  2:42     ` Yang,Wei
2014-06-17  5:59       ` Yang,Wei
2014-06-17 14:18         ` Alan Stern
2014-06-18  1:08           ` Yang,Wei
2014-06-18 11:44             ` Michal Nazarewicz
2014-06-18 14:22               ` Alan Stern
2014-06-19  1:48               ` Yang,Wei
2014-06-17 18:20     ` Michal Nazarewicz

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=538E85AE.5080601@windriver.com \
    --to=wei.yang@windriver.com \
    --cc=andrzej.p@samsung.com \
    --cc=balbi@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mina86@mina86.com \
    --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 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.