[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87mu1ecruw.fsf@kernel.org>
Date: Fri, 25 Sep 2020 09:06:47 +0300
From: Felipe Balbi <balbi@...nel.org>
To: Alan Stern <stern@...land.harvard.edu>
Cc: Wesley Cheng <wcheng@...eaurora.org>, gregkh@...uxfoundation.org,
Thinh.Nguyen@...opsys.com, linux-kernel@...r.kernel.org,
linux-usb@...r.kernel.org, jackp@...eaurora.org
Subject: Re: [PATCH v3] usb: dwc3: Stop active transfers before halting the
controller
Hi,
Alan Stern <stern@...land.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
Download attachment "signature.asc" of type "application/pgp-signature" (858 bytes)
Powered by blists - more mailing lists