stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Takashi Iwai <tiwai@suse.de>, Zqiang <qiang.zhang1211@gmail.com>,
	syzbot+bb950e68b400ab4f65f8@syzkaller.appspotmail.com,
	Sasha Levin <sashal@kernel.org>,
	perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org
Subject: [PATCH AUTOSEL 5.4 15/21] ALSA: seq: Set upper limit of processed events
Date: Mon, 17 Jan 2022 12:04:47 -0500	[thread overview]
Message-ID: <20220117170454.1472347-15-sashal@kernel.org> (raw)
In-Reply-To: <20220117170454.1472347-1-sashal@kernel.org>

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 71a6ea62c3be7..4ff0b927230c2 100644
--- a/sound/core/seq/seq_queue.c
+++ b/sound/core/seq/seq_queue.c
@@ -234,12 +234,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;
@@ -262,6 +265,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... */
@@ -271,14 +276,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


  parent reply	other threads:[~2022-01-17 17:07 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17 17:04 [PATCH AUTOSEL 5.4 01/21] clk: imx: Use div64_ul instead of do_div Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 02/21] powerpc/6xx: add missing of_node_put Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 03/21] powerpc/powernv: " Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 04/21] powerpc/cell: " Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 05/21] powerpc/btext: " Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 06/21] powerpc/watchdog: Fix missed watchdog reset due to memory ordering race Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 07/21] i2c: i801: Don't silently correct invalid transfer size Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 08/21] powerpc/smp: Move setup_profiling_timer() under CONFIG_PROFILING Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 09/21] i2c: mpc: Correct I2C reset procedure Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 10/21] clk: meson: gxbb: Fix the SDM_EN bit for MPLL0 on GXBB Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 11/21] powerpc/powermac: Add missing lockdep_register_key() Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 12/21] KVM: PPC: Book3S: Suppress failed alloc warning in H_COPY_TOFROM_GUEST Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 13/21] w1: Misuse of get_user()/put_user() reported by sparse Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 14/21] scsi: lpfc: Trigger SLI4 firmware dump before doing driver cleanup Sasha Levin
2022-01-17 17:04 ` Sasha Levin [this message]
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 16/21] powerpc: handle kdump appropriately with crash_kexec_post_notifiers option Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 17/21] MIPS: OCTEON: add put_device() after of_find_device_by_node() Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 18/21] i2c: designware-pci: Fix to change data types of hcnt and lcnt parameters Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 19/21] MIPS: Octeon: Fix build errors using clang Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 20/21] scsi: sr: Don't use GFP_DMA Sasha Levin
2022-01-17 17:04 ` [PATCH AUTOSEL 5.4 21/21] ASoC: mediatek: mt8173: fix device_node leak Sasha Levin

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=20220117170454.1472347-15-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=qiang.zhang1211@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+bb950e68b400ab4f65f8@syzkaller.appspotmail.com \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).