All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Ferreri Tonello <eu@felipetonello.com>
To: Felipe Balbi <balbi@kernel.org>, linux-usb@vger.kernel.org
Cc: "# v4 . 4+" <stable@vger.kernel.org>
Subject: Re: [PATCH] usb: gadget: f_midi: added spinlock on transmit function
Date: Wed, 9 Mar 2016 09:35:25 +0000	[thread overview]
Message-ID: <56DFEE5D.2070609@felipetonello.com> (raw)
In-Reply-To: <874mcgglsh.fsf@intel.com>

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

Hi Balbi,

On 09/03/16 07:20, Felipe Balbi wrote:
> 
> Hi,
> 
> "Felipe F. Tonello" <eu@felipetonello.com> writes:
>> [ text/plain ]
>> Since f_midi_transmit is called by both ALSA and USB sub-systems, it can
>> potentially cause a race condition between both calls because f_midi_transmit
>> is not reentrant nor thread-safe. This is due to an implementation detail that
>> the transmit function looks for the next available usb request from the fifo
>> and only enqueues it if there is data to send, otherwise just re-uses it. So,
>> if both ALSA and USB frameworks calls this function at the same time,
>> kfifo_seek() will return the same usb_request, which will cause a race
>> condition.
>>
>> To solve this problem a syncronization mechanism is necessary. In this case it
>> is used a spinlock since f_midi_transmit is also called by usb_request->complete
>> callback in interrupt context.
>>
>> Cc: <stable@vger.kernel.org> # v4.4+
> 
> this should be v4.5+
> 
> $ git describe e1e3d7ec5da3
> v4.4-rc5-59-ge1e3d7ec5da3
> 
>> @@ -651,17 +653,22 @@ static void f_midi_transmit(struct f_midi *midi)
>>  {
>>  	struct usb_ep *ep = midi->in_ep;
>>  	int ret;
>> +	unsigned long flags;
>>  
>>  	/* We only care about USB requests if IN endpoint is enabled */
>>  	if (!ep || !ep->enabled)
>>  		goto drop_out;
>>  
>> +	spin_lock_irqsave(&midi->transmit_lock, flags);
>> +
>>  	do {
>>  		ret = f_midi_do_transmit(midi, ep);
> 
> you wrote this commit on top of 'next' right ? I know that because of
> this call to f_midi_do_transmit() here which is introduced by commit
> aac887442d5e ("usb: gadget: f_midi: move some of f_midi_transmit to
> separate func") which is not in Linus' tree yet.
> 
> This prevents me from taking this patch during current -rc.

Yes, but then what should I do? Because if I patch on Linus' tree, then
the patch won't apply to your tree.

-- 
Felipe

[-- Attachment #2: 0x92698E6A.asc --]
[-- Type: application/pgp-keys, Size: 7195 bytes --]

  reply	other threads:[~2016-03-09  9:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-08 20:21 [PATCH] usb: gadget: f_midi: added spinlock on transmit function Felipe F. Tonello
2016-03-09  7:08 ` Felipe Balbi
2016-03-09  7:20 ` Felipe Balbi
2016-03-09  9:35   ` Felipe Ferreri Tonello [this message]
2016-03-09 10:33     ` Felipe Balbi
2016-03-09 16:15       ` Felipe Ferreri Tonello
  -- strict thread matches above, loose matches on Subject: below --
2016-03-09 16:17 Felipe F. Tonello
2016-03-09 16:58 ` Felipe Ferreri Tonello

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=56DFEE5D.2070609@felipetonello.com \
    --to=eu@felipetonello.com \
    --cc=balbi@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stable@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 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.