Skip to content

Commit af8d077

Browse files
tiwaigregkh
authored andcommitted
ALSA: seq: Set upper limit of processed events
[ Upstream commit 6fadb49 ] Currently ALSA sequencer core tries to process the queued events as much as possible when they become dispatchable. If applications try to queue too massive events to be processed at the very same timing, the sequencer core would still try to process such all events, either in the interrupt context or via some notifier; in either away, it might be a cause of RCU stall or such problems. As a potential workaround for those problems, this patch adds the upper limit of the amount of events to be processed. The remaining events are processed in the next batch, so they won't be lost. For the time being, it's limited up to 1000 events per queue, which should be high enough for any normal usages. Reported-by: Zqiang <qiang.zhang1211@gmail.com> Reported-by: syzbot+bb950e68b400ab4f65f8@syzkaller.appspotmail.com Link: https://lore.kernel.org/r/20211102033222.3849-1-qiang.zhang1211@gmail.com Link: https://lore.kernel.org/r/20211207165146.2888-1-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 2972107 commit af8d077

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎sound/core/seq/seq_queue.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,15 @@ struct snd_seq_queue *snd_seq_queue_find_name(char *name)
234234

235235
/* -------------------------------------------------------- */
236236

237+
#define MAX_CELL_PROCESSES_IN_QUEUE 1000
238+
237239
void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop)
238240
{
239241
unsigned long flags;
240242
struct snd_seq_event_cell *cell;
241243
snd_seq_tick_time_t cur_tick;
242244
snd_seq_real_time_t cur_time;
245+
int processed = 0;
243246

244247
if (q == NULL)
245248
return;
@@ -262,6 +265,8 @@ void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop)
262265
if (!cell)
263266
break;
264267
snd_seq_dispatch_event(cell, atomic, hop);
268+
if (++processed >= MAX_CELL_PROCESSES_IN_QUEUE)
269+
goto out; /* the rest processed at the next batch */
265270
}
266271

267272
/* Process time queue... */
@@ -271,14 +276,19 @@ void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop)
271276
if (!cell)
272277
break;
273278
snd_seq_dispatch_event(cell, atomic, hop);
279+
if (++processed >= MAX_CELL_PROCESSES_IN_QUEUE)
280+
goto out; /* the rest processed at the next batch */
274281
}
275282

283+
out:
276284
/* free lock */
277285
spin_lock_irqsave(&q->check_lock, flags);
278286
if (q->check_again) {
279287
q->check_again = 0;
280-
spin_unlock_irqrestore(&q->check_lock, flags);
281-
goto __again;
288+
if (processed < MAX_CELL_PROCESSES_IN_QUEUE) {
289+
spin_unlock_irqrestore(&q->check_lock, flags);
290+
goto __again;
291+
}
282292
}
283293
q->check_blocked = 0;
284294
spin_unlock_irqrestore(&q->check_lock, flags);

0 commit comments

Comments
 (0)