From: Takashi Iwai <tiwai@suse.de>
To: Junjie Cao <junjie.cao@intel.com>
Cc: Takashi Iwai <tiwai@suse.com>, Jaroslav Kysela <perex@perex.cz>,
John Keeping <jkeeping@inmusicbrands.com>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
Ruslan <ruslan.panasiuk@gmail.com>
Subject: Re: [PATCH] ALSA: seq: midi: wait for output buffer space on non-atomic delivery
Date: Tue, 01 Sep 2026 12:49:43 +0200 [thread overview]
Message-ID: <871pbddz5k.wl-tiwai@suse.de> (raw)
In-Reply-To: <20260831143200.412572-1-junjie.cao@intel.com>
On Mon, 31 Aug 2026 16:32:00 +0200,
Junjie Cao wrote:
>
> dump_midi() drops a chunk with -ENOMEM as soon as it does not fit in the
> rawmidi output buffer, whatever context it runs in. When a client
> write(2)s one large SysEx event, the event is dispatched directly with
> atomic == 0 and the payload is copied from user memory chunk by chunk
> (snd_seq_deliver_event() rejects USRPTR events with atomic set), so the
> caller can sleep, yet the transfer still dies as soon as it gets ahead
> of the device by output_buffer_size bytes:
>
> ALSA: seq_midi: MIDI output buffer overrun
>
> The report is a sample upload to a Novation Circuit Tracks over Web
> MIDI, failing after about a second with the default 4096-byte buffer.
> Raising output_buffer_size only moves the limit.
>
> When atomic is clear, wait for the device to drain instead, the way
> snd_rawmidi_write() does for a userspace writer: sleep on
> runtime->sleep with the same 30-second no-progress timeout and feed the
> buffer in pieces. Atomic delivery keeps the fail-fast path.
>
> A writer sleeping here still holds the source port's subscriber list
> read-side, so unsubscribing that connection waits for the transfer to
> finish or the timeout to fire. midisynth_unuse() wakes a sleeping
> writer after clearing output_substream, so once teardown gets there it
> does not sit in snd_use_lock_sync() waiting out a stalled device.
>
> Compile-tested only; no device with a large SysEx sink here.
>
> Reported-by: Ruslan <ruslan.panasiuk@gmail.com>
> Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2517136
> Signed-off-by: Junjie Cao <junjie.cao@intel.com>
A large SYSEX is a long-standing PITA, and I appreciate your attempt
to fix it. But, the problem is that you can't take long time in
dump_midi() which is called from the sequencer event handler, per
design; the atomic=false there doesn't mean that you are allowed to
block for a too long time like 30 seconds.
For working around this problem, we need a basic design change in ALSA
sequencer core, I'm afraid.
thanks,
Takashi
next prev parent reply other threads:[~2026-09-01 10:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 14:32 Junjie Cao
2026-09-01 10:49 ` Takashi Iwai [this message]
2026-09-01 14:38 ` Junjie Cao
2026-09-02 13:59 ` Takashi Iwai
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=871pbddz5k.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=jkeeping@inmusicbrands.com \
--cc=junjie.cao@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=ruslan.panasiuk@gmail.com \
--cc=tiwai@suse.com \
/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
all inboxes | Powered by JetHome®