linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-renesas-soc@vger.kernel.org" 
	<linux-renesas-soc@vger.kernel.org>
Subject: RE: [PATCH] usb: host: ohci: fix a race condition between shutdown and irq
Date: Tue, 27 Aug 2019 01:59:39 +0000	[thread overview]
Message-ID: <TYAPR01MB4544CF02687CFD8B8F53A706D8A00@TYAPR01MB4544.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1908261157340.1662-100000@iolanthe.rowland.org>

Hi Alan,

> From: Alan Stern, Sent: Tuesday, August 27, 2019 12:58 AM
> 
> On Mon, 26 Aug 2019, Yoshihiro Shimoda wrote:
> 
> > Hi Alan,
> >
> > > From: Alan Stern, Sent: Saturday, August 24, 2019 12:33 AM
> > >
> > > On Fri, 23 Aug 2019, Yoshihiro Shimoda wrote:
<snip>
> > > > The ohci_shutdown() should hold the spin lock while disabling
> > > > the interruption and changing the rh_state flag. Note that
> > > > io_watchdog_func() also calls the ohci_shutdown() and it
> > > > already held the spin lock, so that the patch makes a new
> > > > function as _ohci_shutdown().
> > >
> > > I don't understand this description.  It sounds like the OHCI
> > > controller generates an interrupt request, and then ohci_shutdown()
> > > disables the interrupt request before the handler can run.  When the
> > > handler does run, it sees that no interrupts are enabled and so it
> > > returns IRQ_NOTMINE, leading to the error shown above.
> > >
> > > How will holding the spinlock fix this problem?
> >
> > I'm sorry for lacking description. I should have described the following
> > descriptions instead of that. What do you think?
> >
> > --
> > ohci_shutdown() disables all the interrupt and rh_state is set to
> > OHCI_RH_HALTED. In other hand, ohci_irq() is possible to enable
> > OHCI_INTR_SF and OHCI_INTR_MIE on ohci_irq(). Note that OHCI_INTR_SF
> > is possible to be set by start_ed_unlink() which is called:
> >  ohci_irq()
> >   -> process_done_list()
> >    -> takeback_td()
> >     -> start_ed_unlink()
> >
> > So, ohci_irq() has the following condition, the issue happens by
> > &ohci->regs->intrenable = OHCI_INTR_MIE | OHCI_INTR_SF and
> > ohci->rh_state = OHCI_RH_HALTED:
> >
> > 	/* interrupt for some other device? */
> > 	if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
> > 		return IRQ_NOTMINE;
> >
> > To fix the issue, ohci_shutdown() holds the spin lock while disabling
> > the interruption and changing the rh_state flag to prevent reenable
> > the OHCI_INTR_MIE unexpectedly. Note that io_watchdog_func() also calls
> > the ohci_shutdown() and it already held the spin lock, so that the patch
> > makes a new function as _ohci_shutdown().
> 
> Okay, that's a lot better.  Please resubmit the patch with the new
> description.

Thank you for your review! I have submitted v2 patch as the following:
https://patchwork.kernel.org/patch/11115947/

Best regards,
Yoshihiro Shimoda


      reply	other threads:[~2019-08-27  1:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-23 10:32 [PATCH] usb: host: ohci: fix a race condition between shutdown and irq Yoshihiro Shimoda
2019-08-23 15:33 ` Alan Stern
2019-08-26  2:34   ` Yoshihiro Shimoda
2019-08-26 15:58     ` Alan Stern
2019-08-27  1:59       ` Yoshihiro Shimoda [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=TYAPR01MB4544CF02687CFD8B8F53A706D8A00@TYAPR01MB4544.jpnprd01.prod.outlook.com \
    --to=yoshihiro.shimoda.uh@renesas.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-usb@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;
as well as URLs for NNTP newsgroup(s).