From patchwork Fri Aug 25 10:04:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 9921647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 687F76022E for ; Fri, 25 Aug 2017 10:12:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24D4327D4A for ; Fri, 25 Aug 2017 10:12:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19AE727E5A; Fri, 25 Aug 2017 10:12:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EFCD27DA4 for ; Fri, 25 Aug 2017 10:12:05 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 85EB82673A4; Fri, 25 Aug 2017 12:04:17 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 6C4FB2673A6; Fri, 25 Aug 2017 12:04:16 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 4772B266EA7 for ; Fri, 25 Aug 2017 12:04:12 +0200 (CEST) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9A4D3AE60; Fri, 25 Aug 2017 10:04:12 +0000 (UTC) From: Takashi Iwai To: Mark Brown Date: Fri, 25 Aug 2017 12:04:07 +0200 Message-Id: <20170825100407.5640-1-tiwai@suse.de> X-Mailer: git-send-email 2.14.0 Cc: alsa-devel@alsa-project.org, Kuninori Morimoto Subject: [alsa-devel] [PATCH] ASoC: pcm: Sync delayed work before releasing resources X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP When ASoC driver is unbound dynamically during its operation (i.e. a kind of hot-unplug), we may hit Oops due to the resource access after the release by a delayed work, something like: Unable to handle kernel paging request at virtual address dead000000000220 .... PC is at soc_dapm_dai_stream_event.isra.14+0x20/0xd0 LR is at snd_soc_dapm_stream_event+0x74/0xa8 .... [] soc_dapm_dai_stream_event.isra.14+0x20/0xd0 [] snd_soc_dapm_stream_event+0x74/0xa8 [] close_delayed_work+0x3c/0x50 [] process_one_work+0x1ac/0x318 [] worker_thread+0x48/0x420 [] kthread+0xfc/0x128 [] ret_from_fork+0x10/0x18 For fixing the race, this patch adds a sync-point in pcm private_free callback to finish the delayed work before actually releasing the resources. Reported-by: Hiep Cao Minh Reported-by: Kuninori Morimoto Tested-by: Kuninori Morimoto Signed-off-by: Takashi Iwai --- sound/soc/soc-pcm.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 94b88b897c3b..c0f0b09cb433 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -2632,6 +2632,17 @@ static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream) return ret; } +static void soc_pcm_private_free(struct snd_pcm *pcm) +{ + struct snd_soc_pcm_runtime *rtd = pcm->private_data; + struct snd_soc_platform *platform = rtd->platform; + + /* need to sync the delayed work before releasing resources */ + flush_delayed_work(&rtd->delayed_work); + if (platform->driver->pcm_free) + platform->driver->pcm_free(pcm); +} + /* create a new pcm */ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) { @@ -2757,7 +2768,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) } } - pcm->private_free = platform->driver->pcm_free; + pcm->private_free = soc_pcm_private_free; out: dev_info(rtd->card->dev, "%s <-> %s mapping ok\n", (rtd->num_codecs > 1) ? "multicodec" : rtd->codec_dai->name,