Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3975578pxb; Tue, 25 Jan 2022 00:25:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJyDtK+Sx7WvyT+4j6X5T/AwlzL3F8xqs4yXVt8waNXsyVGw1Fz3KsjxnqtK6d9o5Q2ahHXK X-Received: by 2002:a17:90b:1c02:: with SMTP id oc2mr2334020pjb.33.1643099132787; Tue, 25 Jan 2022 00:25:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643099132; cv=none; d=google.com; s=arc-20160816; b=xaHTHeE1d/pt1penEBpGeoldCIqRRVQ54yi2xBwdAaLhrKxmNCkvE0jvUruvDllvGv XAVpqUNc/d0DFnngLxvTMfx93vz9foa9MzruUGn1SS9K9zRu9wkd4O8pMiLPF/5TtTO4 Sf9/hft3sYm1ydQ2ZiUNwhQ/DD/Q482wAZULSPYqeiqKWX02m1/4U5gTl/gapfA4xFZ3 3Np6uhSTWup+UmeNtctJZlIBIkYKNnCOAEayv8vM8D7h5fEEP392HWgsMZPglTw+xnNR qOj2KvovczcdAXDsxsd8578b2DTO/vZmWAAK/qWbTLfLyUmI2ux8y/HHShqg+dde5IxC d9Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dM0A+EjoLdq9Ukz9/1Sf/uWDov11cvdP6D2oYC7pANw=; b=fPdm3tz1B9aVW//dlCkbYiL8Zj4bLU58ZdgIeby3e1uIVquZffG073zyAYeEkLH6mE QC5eOHJ194530gr4C1oe5ohZbmmLntm18NJhOlP+K7YE9omThGT5gUbZ5bXma0PCmCsf HGb4rPJTJ1GIbM0yV42b1bUWrLpNI6YvW8zx4TI6gajcWrTrXY5i4lZEBYZSRJoujK1r 8VOB9+wJrDkBwD/ef4BMg92w8rVIDkONJHpOfjcrPoAYYRv2wbVYhK579vvrvvkydXlJ IzzUf8u7TCm1C3cOgOKGvLDJTuRVsIjEtmjDsThUPgEfnOWMwpun0CtsfEcbBMShHbmD w7NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y3ndXdzC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u6si13485388plq.479.2022.01.25.00.25.18; Tue, 25 Jan 2022 00:25:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y3ndXdzC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S3420925AbiAYCZu (ORCPT + 99 others); Mon, 24 Jan 2022 21:25:50 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:49702 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344886AbiAXTVd (ORCPT ); Mon, 24 Jan 2022 14:21:33 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8814A60917; Mon, 24 Jan 2022 19:21:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A2DEC340E8; Mon, 24 Jan 2022 19:21:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052092; bh=8dtuI81vH2nEg04/VDZ3p6Ngyx8DAV+nwowjYqyLxQs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y3ndXdzCiKxuOi0jKmNBFnnevJmLWTf5MJOE9w+izIReQPBzUsGs0mbRFf+glA9mx nlRkM30bM5bIjDN42KLBjoRth8j+ewStZXV6hQmCeQ3vMJ29A4dY5Y110HxwsC1uMM oW2GQ0CY8Wd9yi4x8lI0VHeP4B8nnxCvTz0Dq7ps= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zqiang , syzbot+bb950e68b400ab4f65f8@syzkaller.appspotmail.com, Takashi Iwai , Sasha Levin Subject: [PATCH 4.19 187/239] ALSA: seq: Set upper limit of processed events Date: Mon, 24 Jan 2022 19:43:45 +0100 Message-Id: <20220124183949.046047461@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183943.102762895@linuxfoundation.org> References: <20220124183943.102762895@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai [ 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 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 Signed-off-by: Sasha Levin --- 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 28b4dd45b8d1d..a23ba648db845 100644 --- a/sound/core/seq/seq_queue.c +++ b/sound/core/seq/seq_queue.c @@ -247,12 +247,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; @@ -275,6 +278,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... */ @@ -284,14 +289,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