public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Cc: Felipe Balbi <balbi@kernel.org>, USB <linux-usb@vger.kernel.org>
Subject: Re: dwc3 spin_lock_irq flags
Date: Tue, 10 Aug 2021 21:51:08 -0400	[thread overview]
Message-ID: <20210811015108.GA618534@rowland.harvard.edu> (raw)
In-Reply-To: <a034f2ef-c2a3-962e-d72b-0db6a34e67a2@synopsys.com>

On Tue, Aug 10, 2021 at 10:10:00PM +0000, Thinh Nguyen wrote:
> Hi,
> 
> Typically when we use spin_lock_irqsave and spin_unlock_irqrestore,
> we save the irq state in the "flags" variable and pass it down to any
> function that may need to do spin_unlock_irqrestore and update the flags
> again.
> 
> I don't see that we're doing it for dwc3 when we give back the requests:
> 
> void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
> 		int status)
> {
> 	struct dwc3			*dwc = dep->dwc;
> 
> 	dwc3_gadget_del_and_unmap_request(dep, req, status);
> 	req->status = DWC3_REQUEST_STATUS_COMPLETED;
> 
> 	spin_unlock(&dwc->lock);
> 	usb_gadget_giveback_request(&dep->endpoint, &req->request);
> 	spin_lock(&dwc->lock);
> }
> 
> Then we would use the stale "flags" to do spin_unlock_irqrestore() at a later
> time. Maybe someone can help shed some light on what issue this would cause
> (if any). From our hardware testing, there's no obvious failure or performance
> impact that we see.

There are no issues with this code pattern; it is perfectl valid.  Its 
only effect is that sometimes the request's completion handler will be 
called with interrupts disabled when in theory, it could have been 
called with interrupts enabled.  This won't cause any problem because 
completion handlers are _always_ called with interrupts disabled; this 
is mentioned in the kerneldoc for the @complete member of struct 
usb_request.

When the spin_unlock_irqrestore() call runs later on, its "flags" 
argument won't be stale.  It will accurately reflect whether interrupts 
were enabled when the original spin_lock_irqsave() ran.  By themselves, 
spin_unlock() and spin_lock() don't change the enable state for 
interrupts.

Alan Stern

  reply	other threads:[~2021-08-11  1:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-10 22:10 dwc3 spin_lock_irq flags Thinh Nguyen
2021-08-11  1:51 ` Alan Stern [this message]
2021-08-11  2:20   ` Thinh Nguyen

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=20210811015108.GA618534@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=balbi@kernel.org \
    --cc=linux-usb@vger.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