From: YE Chengfeng <cyeaa@connect.ust.hk>
To: "perex@perex.cz" <perex@perex.cz>,
"tiwai@suse.com" <tiwai@suse.com>,
"yunjunlee@chromium.org" <yunjunlee@chromium.org>
Cc: "alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH] ALSA: dummy: Fix &dpcm->lock deadlock issues
Date: Sun, 25 Jun 2023 15:35:48 +0000 [thread overview]
Message-ID: <TYCP286MB1188FEE149369A32D90DCE288A21A@TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM> (raw)
The timer dummy_systimer_callback is executed under softirq
context, thus other process context code requiring the same lock
should disable interrupt. Otherwise there would be potential
deadlock issues when the code executing under process context
(i.e., dummy_systimer_pointer, dummy_systimer_start,
dummy_systimer_stop) is preempted by the timer while holding
the lock.
Deadlock scenario:
dummy_systimer_pointer
-> spin_lock(&dpcm->lock);
<timer interrupt>
-> dummy_systimer_callback
-> spin_lock_irqsave(&dpcm->lock, flags);
Fix the potential deadlock by using spin_lock_irqsave.
Signed-off-by: Chengfeng Ye <cyeaa@connect.ust.hk>
---
sound/drivers/dummy.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
index 9c17b49a2ae1..04fb4f17e05c 100644
--- a/sound/drivers/dummy.c
+++ b/sound/drivers/dummy.c
@@ -268,19 +268,23 @@ static void dummy_systimer_update(struct dummy_systimer_pcm *dpcm)
static int dummy_systimer_start(struct snd_pcm_substream *substream)
{
struct dummy_systimer_pcm *dpcm = substream->runtime->private_data;
- spin_lock(&dpcm->lock);
+ unsigned long flags;
+
+ spin_lock_irqsave(&dpcm->lock, flags);
dpcm->base_time = jiffies;
dummy_systimer_rearm(dpcm);
- spin_unlock(&dpcm->lock);
+ spin_unlock_irqrestore(&dpcm->lock, flags);
return 0;
}
static int dummy_systimer_stop(struct snd_pcm_substream *substream)
{
struct dummy_systimer_pcm *dpcm = substream->runtime->private_data;
- spin_lock(&dpcm->lock);
+ unsigned long flags;
+
+ spin_lock_irqsave(&dpcm->lock, flags);
del_timer(&dpcm->timer);
- spin_unlock(&dpcm->lock);
+ spin_unlock_irqrestore(&dpcm->lock, flags);
return 0;
}
@@ -320,11 +324,12 @@ dummy_systimer_pointer(struct snd_pcm_substream *substream)
{
struct dummy_systimer_pcm *dpcm = substream->runtime->private_data;
snd_pcm_uframes_t pos;
+ unsigned long flags;
- spin_lock(&dpcm->lock);
+ spin_lock_irqsave(&dpcm->lock, flags);
dummy_systimer_update(dpcm);
pos = dpcm->frac_pos / HZ;
- spin_unlock(&dpcm->lock);
+ spin_unlock_irqrestore(&dpcm->lock, flags);
return pos;
}
--
2.17.1
next reply other threads:[~2023-06-25 15:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-25 15:35 YE Chengfeng [this message]
2023-06-25 18:13 ` Takashi Iwai
[not found] ` <TYCP286MB1188D860B56B9FF1FCAA79148A26A@TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM>
2023-09-17 17:26 ` 回复: " YE Chengfeng
2023-09-18 15:53 ` Takashi Iwai
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=TYCP286MB1188FEE149369A32D90DCE288A21A@TYCP286MB1188.JPNP286.PROD.OUTLOOK.COM \
--to=cyeaa@connect.ust.hk \
--cc=alsa-devel@alsa-project.org \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
--cc=yunjunlee@chromium.org \
/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
all inboxes | Powered by JetHome®