linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi@kernel.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Wesley Cheng <wcheng@codeaurora.org>,
	gregkh@linuxfoundation.org, Thinh.Nguyen@synopsys.com,
	linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	jackp@codeaurora.org
Subject: Re: [PATCH v3] usb: dwc3: Stop active transfers before halting the controller
Date: Fri, 25 Sep 2020 09:06:47 +0300	[thread overview]
Message-ID: <87mu1ecruw.fsf@kernel.org> (raw)
In-Reply-To: <20200924155005.GB1337044@rowland.harvard.edu>

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


Hi,

Alan Stern <stern@rowland.harvard.edu> writes:
>> > Hence, the reason if there was already a pending IRQ triggered, the
>> > dwc3_gadget_disable_irq() won't ensure the IRQ is handled.  We can do
>> > something like:
>> > if (!is_on)
>> > 	dwc3_gadget_disable_irq()
>> > synchronize_irq()
>> > spin_lock_irqsave()
>> > if(!is_on) {
>> > ...
>> >
>> > But the logic to only apply this on the pullup removal case is a little
>> > messy.  Also, from my understanding, the spin_lock_irqsave() will only
>> > disable the local CPU IRQs, but not the interrupt line on the GIC, which
>> > means other CPUs can handle it, unless we explicitly set the IRQ
>> > affinity to CPUX.
>> 
>> Yeah, the way I understand this can't really happen. But I'm open to
>> being educated. Maybe Alan can explain if this is really possibility?
>
> It depends on the details of the hardware, but yes, it is possible in
> general for an interrupt handler to run after you have turned off the
> device's interrupt-request line.  For example:
>
> 	CPU A				CPU B
> 	---------------------------	----------------------
> 	Gets an IRQ from the device
> 	Calls handler routine		spin_lock_irq
> 	  spin_lock_irq			Turns off the IRQ line
> 	  ...spins...			spin_unlock_irq
> 	  Rest of handler runs
> 	  spin_unlock_irq
>
> That's why we have synchronize_irq().  The usual pattern is something
> like this:
>
> 	spin_lock_irq(&priv->lock);
> 	priv->disconnected = true;
> 	my_disable_irq(priv);
> 	spin_unlock_irq(&priv->lock);
> 	synchronize_irq(priv->irq);
>
> And of course this has to be done in a context that can sleep.
>
> Does this answer your question?

It does, thank you Alan. It seems like we don't need a call to
disable_irq(), only synchronize_irq() is enough, however it should be
called with spinlocks released, not held.

Thanks

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 857 bytes --]

  reply	other threads:[~2020-09-25  6:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-03 21:09 [PATCH v3] usb: dwc3: Stop active transfers before halting the controller Wesley Cheng
2020-09-04  0:47 ` Thinh Nguyen
2020-09-07  6:20 ` Felipe Balbi
2020-09-08 21:42   ` Wesley Cheng
2020-09-24  7:39     ` Felipe Balbi
2020-09-24 15:50       ` Alan Stern
2020-09-25  6:06         ` Felipe Balbi [this message]
2020-09-25 19:33           ` Wesley Cheng

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=87mu1ecruw.fsf@kernel.org \
    --to=balbi@kernel.org \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jackp@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=wcheng@codeaurora.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;
as well as URLs for NNTP newsgroup(s).