Skip to content

Commit b1e4b1c

Browse files
tiwaigregkh
authored andcommitted
ALSA: virmidi: Fix too long output trigger loop
commit 50e9ffb1996a5d11ff5040a266585bad4ceeca0a upstream. The virmidi output trigger tries to parse the all available bytes and process sequencer events as much as possible. In a normal situation, this is supposed to be relatively short, but a program may give a huge buffer and it'll take a long time in a single spin lock, which may eventually lead to a soft lockup. This patch simply adds a workaround, a cond_resched() call in the loop if applicable. A better solution would be to move the event processor into a work, but let's put a duct-tape quickly at first. Reported-and-tested-by: Dae R. Jeong <[email protected]> Reported-by: [email protected] Cc: <[email protected]> Signed-off-by: Takashi Iwai <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5cb1203 commit b1e4b1c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

sound/core/seq/seq_virmidi.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ static void snd_virmidi_output_trigger(struct snd_rawmidi_substream *substream,
163163
int count, res;
164164
unsigned char buf[32], *pbuf;
165165
unsigned long flags;
166+
bool check_resched = !in_atomic();
166167

167168
if (up) {
168169
vmidi->trigger = 1;
@@ -200,6 +201,15 @@ static void snd_virmidi_output_trigger(struct snd_rawmidi_substream *substream,
200201
vmidi->event.type = SNDRV_SEQ_EVENT_NONE;
201202
}
202203
}
204+
if (!check_resched)
205+
continue;
206+
/* do temporary unlock & cond_resched() for avoiding
207+
* CPU soft lockup, which may happen via a write from
208+
* a huge rawmidi buffer
209+
*/
210+
spin_unlock_irqrestore(&substream->runtime->lock, flags);
211+
cond_resched();
212+
spin_lock_irqsave(&substream->runtime->lock, flags);
203213
}
204214
out:
205215
spin_unlock_irqrestore(&substream->runtime->lock, flags);

0 commit comments

Comments
 (0)