All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oliver Neukum <oneukum@suse.com>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
	Greg KH <greg@kroah.com>
Cc: Colin Ian King <colin.king@canonical.com>,
	Arnd Bergmann <arnd@arndb.de>,
	linux-usb@vger.kernel.org
Subject: Re: [PATCH] USB: cdc-wdm: Call wake_up_all() when clearing WDM_IN_USE bit.
Date: Fri, 22 May 2020 10:04:22 +0200	[thread overview]
Message-ID: <1590134662.19681.12.camel@suse.com> (raw)
In-Reply-To: <a72cbcc6-df68-2043-1580-a8b4e4053079@i-love.sakura.ne.jp>

Am Freitag, den 22.05.2020, 07:48 +0900 schrieb Tetsuo Handa:


Hi,

I looked at your patch again and I am impressed and I need to
apologize. I looked at only the intended use, but overlooked
the unintended use.

I think we need to work on the description of the patch though.

> On 2020/05/22 4:50, Oliver Neukum wrote:
> > interesting. Do you have a test case for these patches working?
> 
> No.

Yes, going through the logs it looks that you need to trigger
an error case for this race to strike.

> > > 	wait_event(desc->wait,
> > > 			/*
> > > 			 * needs both flags. We cannot do with one
> > > 			 * because resetting it would cause a race
> > > 			 * with write() yet we need to signal
> > > 			 * a disconnect
> > > 			 */
> > > 			!test_bit(WDM_IN_USE, &desc->flags) ||
> > > 			test_bit(WDM_DISCONNECTING, &desc->flags));
> > > 
> > > but wdm_write() is not calling wake_up(&desc->wait) after
> > > clear_bit(WDM_IN_USE, &desc->flags) when usb_submit_urb() failed.
> > 
> > Yes, because desc->wlock is held. There can be nobody sleeping here.
> 
> Then, this patch is not needed. (But adding some comment is welcomed.)

OK and here I screwed up. wlock is held in wdm_write(), but not in
wdm_flush()

So may I suggest the following log:

--

WDM_IN_USE is used in wdm_write() to protect against concurrent writes
and in wdm_flush() to wait for all messages to flush, so that errors
are not lost. The former use is guarded by a mutex, the later, as
it does no IO, is not.
In the error case of wdm_write(), however, there is a race, which
can make wdm_flush() wait for IO that was supposed to be started
but was never started due to an error condition.
Hence if an error is detected in wdm_write() after WDM_IN_USE was
toggeled, all potential waiters must be woken. As multiple tasks
can be in wdm_flush, wake_up_all() must be used in all cases
WDM_IN_USE is reset.

--

May I ask you to redo the patch with comments added stating
that the wake up is done for the sake of wdm_flush(), change
the description and add the link to syzkaller?

> > > > And is this a bugfix?  For what?  Does it need to go to stable kernels?

Yes, it is. The bug is ancient. It goes back to afba937e540c9,
which introduced the driver.


Again, thank you for this impressive piece of debugging.

	Regards
		Oliver



  reply	other threads:[~2020-05-22  8:04 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-20 23:31 [PATCH] USB: cdc-wdm: Call wake_up_all() when clearing WDM_IN_USE bit Tetsuo Handa
2020-05-21  7:33 ` Greg KH
2020-05-21 10:01   ` Tetsuo Handa
2020-05-21 19:50     ` Oliver Neukum
2020-05-21 22:48       ` Tetsuo Handa
2020-05-22  8:04         ` Oliver Neukum [this message]
2020-05-22  8:26           ` Tetsuo Handa
2020-05-25 12:06             ` Oliver Neukum
2020-05-25 13:32               ` Tetsuo Handa
2020-05-27  4:47                 ` Tetsuo Handa
2020-05-28 15:18                   ` Andrey Konovalov
2020-05-28 16:03                     ` Tetsuo Handa
2020-05-28 19:03                       ` Andrey Konovalov
2020-05-28 19:40                         ` Alan Stern
2020-05-28 19:51                           ` Andrey Konovalov
2020-05-28 20:58                             ` Alan Stern
2020-05-29 20:41                               ` Andrey Konovalov
2020-05-30  0:42                                 ` Tetsuo Handa
2020-05-30  1:10                                   ` Alan Stern
2020-05-30  4:58                                     ` Tetsuo Handa
2020-06-24 11:57                                       ` Oliver Neukum
2020-06-24 12:48                                         ` Tetsuo Handa
2020-05-30  6:08                                   ` Greg Kroah-Hartman
2020-06-01 12:26                                   ` Andrey Konovalov
2020-05-30 15:25                               ` Oliver Neukum
2020-05-30 15:47                                 ` Alan Stern
2020-06-08  2:24                                   ` Tetsuo Handa
2020-06-18  0:48                                     ` Tetsuo Handa
2020-06-19 13:56                                       ` Andrey Konovalov
2020-06-23 11:20                                         ` Tetsuo Handa
2020-07-02  5:44                                           ` Tetsuo Handa
2020-07-02  7:24                                             ` Oliver Neukum
2020-07-15  6:15                                               ` Tetsuo Handa
2020-08-10 10:47                                                 ` Tetsuo Handa
2020-09-24 15:09                                                   ` [PATCH] USB: cdc-wdm: Make wdm_flush() interruptible and add wdm_fsync() Tetsuo Handa
2020-09-28 14:17                                                     ` [PATCH (repost)] " Tetsuo Handa
2020-06-25  9:56                                     ` [PATCH] USB: cdc-wdm: Call wake_up_all() when clearing WDM_IN_USE bit Oliver Neukum
2020-06-25 11:15                                       ` Tetsuo Handa
2020-07-01  7:08                                     ` [TEST]Re: " Oliver Neukum

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=1590134662.19681.12.camel@suse.com \
    --to=oneukum@suse.com \
    --cc=arnd@arndb.de \
    --cc=colin.king@canonical.com \
    --cc=greg@kroah.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    /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.