Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jaegyun Lee" <dreams200260@gmail.com>
Cc: linux-usb@vger.kernel.org, linux-sound@vger.kernel.org
Subject: Re: [PATCH v3] usb: gadget: midi2: serialize the IN endpoint transmit path
Date: Thu, 03 Dec 2026 14:31:20 +0000	[thread overview]
Message-ID: <sashiko-outbox-247973@kernel.org> (raw)
In-Reply-To: <20261203135832.3396094-1-dreams200260@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] usb: gadget: midi2: unbounded IRQ-off tx_lock hold in
  f_midi2_tx_run()
--

commit 4c531e02ef82b71c676e76246bc9dc99b92503af
Author: Jaegyun Lee <dreams200260@gmail.com>

usb: gadget: midi2: serialize the IN endpoint transmit path

This commit adds a per-endpoint spinlock (tx_lock) and work item (tx_work)
to serialize IN endpoint transmission with request allocation and teardown,
and defers transmission from IN completion handlers to system_highpri_wq.

> diff --git a/drivers/usb/gadget/function/f_midi2.c b/drivers/usb/gadget/function/f_midi2.c
> index 75036d4d60b35..8f34204a620c7 100644
> --- a/drivers/usb/gadget/function/f_midi2.c
> +++ b/drivers/usb/gadget/function/f_midi2.c

[ ... ]

> @@ -1052,6 +1054,26 @@ static void process_midi1_transmit(struct f_midi2 *midi2)
>  	}
>  }
>  
> +static void f_midi2_tx_run(struct f_midi2_usb_ep *usb_ep)
> +{
> +	unsigned long flags;
> +
> +	if (!usb_ep->usb_ep)
> +		return;
> +
> +	spin_lock_irqsave(&usb_ep->tx_lock, flags);
> +	if (usb_ep->ep)
> +		process_ump_transmit(usb_ep->ep);
> +	else
> +		process_midi1_transmit(usb_ep->card);
> +	spin_unlock_irqrestore(&usb_ep->tx_lock, flags);
> +}

[Severity: High]
Can holding usb_ep->tx_lock with IRQs disabled across the entire transmit
loop in f_midi2_tx_run() cause an indefinite IRQ-off stall?

In altset 0, process_midi1_transmit() runs an unbounded loop draining four
bytes per snd_ump_transmit() call and continues without queueing a request
when a UMP packet does not convert to MIDI 1.0 (such as a Utility message).

A concurrent writer in snd_rawmidi_kernel_write1() can refill the buffer
faster than the loop drains it, keeping local IRQs off indefinitely and
triggering an RCU stall or hard lockup while f_midi2_stop_eps() busy-spins
on tx_lock.

Even with valid streaming traffic, f_midi2_ep_in_complete() and
f_midi2_midi1_ep_in_complete() call put_empty_request() without taking
tx_lock, so cross-CPU completions can keep both transmit loops spinning
with IRQs disabled for the duration of sustained streaming.

Separately, f_midi2_stop_eps() holds ep_in->tx_lock across
f_midi2_drop_reqs(ep_out) for the unrelated OUT endpoint, and
f_midi2_start_eps() holds it across f_midi2_alloc_ep_reqs() while
allocating up to 32 requests.

Bounding the work done per tx_lock hold and re-queueing tx_work when more
data remains would avoid holding IRQs off indefinitely.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203135832.3396094-1-dreams200260@gmail.com?part=1

      reply	other threads:[~2026-12-03 14:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 13:58 [PATCH v3] usb: gadget: midi2: serialize the IN endpoint transmit path Jaegyun Lee
2026-12-03 14:31 ` sashiko-bot [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=sashiko-outbox-247973@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dreams200260@gmail.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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