lkml.org 
[lkml]   [2022]   [Jan]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.16 0756/1039] ALSA: seq: Set upper limit of processed events
    Date
    From: Takashi Iwai <tiwai@suse.de>

    [ Upstream commit 6fadb494a638d8b8a55864ecc6ac58194f03f327 ]

    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>
    ---
    sound/core/seq/seq_queue.c | 14 ++++++++++++--
    1 file changed, 12 insertions(+), 2 deletions(-)

    diff --git a/sound/core/seq/seq_queue.c b/sound/core/seq/seq_queue.c
    index d6c02dea976c8..bc933104c3eea 100644
    --- a/sound/core/seq/seq_queue.c
    +++ b/sound/core/seq/seq_queue.c
    @@ -235,12 +235,15 @@ struct snd_seq_queue *snd_seq_queue_find_name(char *name)

    /* -------------------------------------------------------- */

    +#define MAX_CELL_PROCESSES_IN_QUEUE 1000
    +
    void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop)
    {
    unsigned long flags;
    struct snd_seq_event_cell *cell;
    snd_seq_tick_time_t cur_tick;
    snd_seq_real_time_t cur_time;
    + int processed = 0;

    if (q == NULL)
    return;
    @@ -263,6 +266,8 @@ void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop)
    if (!cell)
    break;
    snd_seq_dispatch_event(cell, atomic, hop);
    + if (++processed >= MAX_CELL_PROCESSES_IN_QUEUE)
    + goto out; /* the rest processed at the next batch */
    }

    /* Process time queue... */
    @@ -272,14 +277,19 @@ void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop)
    if (!cell)
    break;
    snd_seq_dispatch_event(cell, atomic, hop);
    + if (++processed >= MAX_CELL_PROCESSES_IN_QUEUE)
    + goto out; /* the rest processed at the next batch */
    }

    + out:
    /* free lock */
    spin_lock_irqsave(&q->check_lock, flags);
    if (q->check_again) {
    q->check_again = 0;
    - spin_unlock_irqrestore(&q->check_lock, flags);
    - goto __again;
    + if (processed < MAX_CELL_PROCESSES_IN_QUEUE) {
    + spin_unlock_irqrestore(&q->check_lock, flags);
    + goto __again;
    + }
    }
    q->check_blocked = 0;
    spin_unlock_irqrestore(&q->check_lock, flags);
    --
    2.34.1


    \
     
     \ /
      Last update: 2022-09-17 16:14    [W:4.016 / U:0.968 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site