From: "Petr Mládek" <pmladek@suse.cz>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Tejun Heo <tj@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Joe Lawrence <joe.lawrence@stratus.com>,
Jiri Kosina <jkosina@suse.cz>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 4/4] usb: hub: rename khubd to hub_wq in documentation and comments
Date: Thu, 18 Sep 2014 18:15:02 +0200 [thread overview]
Message-ID: <20140918161501.GG2168@dhcp128.suse.cz> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1409181013550.1326-100000@iolanthe.rowland.org>
On Thu 18-09-14 10:24:23, Alan Stern wrote:
> On Thu, 18 Sep 2014, Tejun Heo wrote:
>
> > Hello, Alan, Petr.
> >
> > On Wed, Sep 17, 2014 at 01:36:26PM -0400, Alan Stern wrote:
> > > > - /* If khubd ever becomes multithreaded, this will need a lock */
> > > > + /* If hub_wq ever becomes multithreaded, this will need a lock */
> > > > if (udev->wusb) {
> > > > devnum = udev->portnum + 1;
> > > > BUG_ON(test_bit(devnum, bus->devmap.devicemap));
> > >
> > > You probably didn't notice when changing this comment. But in fact,
> > > workqueues _are_ multithreaded. Therefore you need to add a lock to
> > > this routine.
>
> > Haven't read the code but if this function is called from a single
> > work_struct, workqueue guarantees that there's only single thread of
> > execution at any given time. A work item is never executed
> > concurrently no matter what.
>
> This routine can be called from multiple work_structs, because a USB
> bus can have multiple hubs.
The easiest solution would be to allocate the work queue with
the flag WQ_UNBOUND and max_active = 1. It will force serialization
of all work items.
Alternatively, we might add the locking. But to be honest, I am not
sure that I am brave enough to do so.
First, I am not sure if this is the only location that might be
affected by the parallel execution of hub_event().
Second, there are used so many locks and the code is so complex that I
would need many days and maybe weeks to understand it.
Well, if we assume that this is the only problematic location, here
are the ideas how to prevent the parallel execution:
1. Use some brand new lock, e.g. call it hub_devnum_lock, and do:
static void choose_devnum(struct usb_device *udev)
{
spin_lock_irq(&hub_devnum_lock);
[...]
spin_unlock_irq(&hub_event_lock);
}
This looks clean but it creates another lock.
2. Alternatively, we could use an existing global lock the same way,
for example usb_bus_list_lock.
But this looks like a hack and I do not like it much.
3. Alternatively, it seems the the function affects one
"struct usb_device" and one "struct usb_bus". It might
be enough to take the appropriate locks for these
structures.
This would mean to take two locks. It would be slower
and we would need to make sure that it does not cause
a dead lock.
Best Regards,
Petr
next prev parent reply other threads:[~2014-09-18 16:15 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-17 15:19 [PATCH v2 0/4] usb: hub: convert khubd into workqueue Petr Mladek
2014-09-17 15:19 ` [PATCH v2 1/4] " Petr Mladek
2014-09-17 17:31 ` Alan Stern
2014-09-17 15:19 ` [PATCH v2 2/4] usb: hub: remove obsolete while cycle in hub_event() Petr Mladek
2014-09-17 17:33 ` Alan Stern
2014-09-17 15:19 ` [PATCH v2 3/4] usb: hub: rename usb_kick_khubd() to usb_kick_hub_wq() Petr Mladek
2014-09-17 15:19 ` [PATCH v2 4/4] usb: hub: rename khubd to hub_wq in documentation and comments Petr Mladek
2014-09-17 17:36 ` Alan Stern
2014-09-17 21:22 ` Tejun Heo
2014-09-18 14:24 ` Alan Stern
2014-09-18 16:15 ` Petr Mládek [this message]
2014-09-18 16:31 ` Tejun Heo
2014-09-18 17:21 ` Alan Stern
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=20140918161501.GG2168@dhcp128.suse.cz \
--to=pmladek@suse.cz \
--cc=gregkh@linuxfoundation.org \
--cc=jkosina@suse.cz \
--cc=joe.lawrence@stratus.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=tj@kernel.org \
/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®