From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71037C433EF for ; Wed, 29 Sep 2021 05:50:41 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6C8A0613C8 for ; Wed, 29 Sep 2021 05:50:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6C8A0613C8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=samsung.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id A750D1689; Wed, 29 Sep 2021 07:49:48 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz A750D1689 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1632894638; bh=v9OKzkiV9I9SfVzRsaoqPA49bUFJBUP6XSdkoZ4u08Q=; h=From:To:In-Reply-To:Subject:Date:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=NmcuBwL5h99M+5UOEGbJ6wzxbENvwWOfHB0NG2GinWqOjOYw6dqLnIz+9QZJdhjbv giSoz82xAscT/KR+jEb5iwSh9MtPnJggLhNXS1cL2/3BKgpdOge/QJurvu5Wg20c7X cTRSf+0oet4Ihl08kIjuRAxzLBJxL/N+Vo+u0qKM= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 407E1F801F7; Wed, 29 Sep 2021 07:49:48 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 5C84BF80227; Wed, 29 Sep 2021 07:49:46 +0200 (CEST) Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id E2BA4F80105 for ; Wed, 29 Sep 2021 07:49:38 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E2BA4F80105 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="YMFeGzLa" Received: from epcas2p4.samsung.com (unknown [182.195.41.56]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20210929054932epoutp0332f4a0f697ccadcd08d6a1fb27b3ca9e~pNPZxWaSW0891008910epoutp033 for ; Wed, 29 Sep 2021 05:49:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20210929054932epoutp0332f4a0f697ccadcd08d6a1fb27b3ca9e~pNPZxWaSW0891008910epoutp033 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1632894573; bh=ebXDZjnjfx5PMA0E9dVI+5JrhVFNjHxLzCeUiOcb7Zk=; h=From:To:Cc:In-Reply-To:Subject:Date:References:From; b=YMFeGzLalWHDIEwvNh+w6UvT3qITOdfCmsuvP/clf4r6juPXR67JwzFWmtjSIYU79 Bxzf+KhChCZyBaReF8HZStzNqEdKyoQx7mKqyi7atB1qnbAqoMWk7pbsPiXHjJrxRW VPF7lBnDArMyh/PIf92pkbxc9qqI6SkMwDXhorZI= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas2p4.samsung.com (KnoxPortal) with ESMTP id 20210929054932epcas2p4a530f13c6c88e72b30bfbf83062fa3fc~pNPZHG65s1157711577epcas2p4y; Wed, 29 Sep 2021 05:49:32 +0000 (GMT) Received: from epsmges2p2.samsung.com (unknown [182.195.36.92]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4HK56Z6S1Yz4x9Q2; Wed, 29 Sep 2021 05:49:26 +0000 (GMT) Received: from epcas2p4.samsung.com ( [182.195.41.56]) by epsmges2p2.samsung.com (Symantec Messaging Gateway) with SMTP id 81.92.09816.26EF3516; Wed, 29 Sep 2021 14:49:22 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas2p2.samsung.com (KnoxPortal) with ESMTPA id 20210929054921epcas2p2fbe35a6262405e064aac3bd92b22b1aa~pNPPPbRzT1077810778epcas2p2F; Wed, 29 Sep 2021 05:49:21 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20210929054921epsmtrp10c3a24954d2f325ae2a0a2e775846b9d~pNPPOrZZ62592725927epsmtrp1J; Wed, 29 Sep 2021 05:49:21 +0000 (GMT) X-AuditID: b6c32a46-63bff70000002658-0d-6153fe62ad32 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id BF.C2.09091.16EF3516; Wed, 29 Sep 2021 14:49:21 +0900 (KST) Received: from KORDO025540 (unknown [12.36.182.130]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20210929054921epsmtip2c0003f42b8b1260ba035ce21e2f4e0a9~pNPPEHFqU2307723077epsmtip2d; Wed, 29 Sep 2021 05:49:21 +0000 (GMT) From: "Gyeongtaek Lee" To: "'Takashi Iwai'" In-Reply-To: Subject: [PATCH] ASoC: dpcm: fix race condition to dpcm links in dpcm_be_dai_trigger Date: Wed, 29 Sep 2021 14:49:21 +0900 Message-ID: <002f01d7b4f5$c030f4a0$4092dde0$@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 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Bcf92VNV9PVJzXWs5QY+85qXxmsYa5u9Ka4OMn5B5/Xsp/6VJUPcf5v/pvSzgO3Ak4 KM/ZysyZE7aOk1Ml01t7q2rAYgEe1W6+a5dXnZ+7KPniGf2ldV5ZadJ2z7k2Xz3x9tQlNT17 /aTNPqr333QzXj3lEffvreR51sNbT7x+6DRTiaU4I9FQi7moOBEA19l9ohsDAAA= X-CMS-MailID: 20210929054921epcas2p2fbe35a6262405e064aac3bd92b22b1aa X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20210929054921epcas2p2fbe35a6262405e064aac3bd92b22b1aa References: Cc: alsa-devel@alsa-project.org, kimty@samsung.com, lgirdwood@gmail.com, senius.park@samsung.com, donggyun.ko@samsung.com, hmseo@samsung.com, seungbin.lee@samsung.com, s47.kang@samsung.com, pilsun.jang@samsung.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" If routing change and underrun stop is run at the same time, data abort can be occurred by the following sequence. CPU0: Processing underrun CPU1: Processing routing change dpcm_be_dai_trigger(): dpcm_be_disconnect(): for_each_dpcm_be(fe, stream, dpcm) { spin_lock_irqsave(&fe->card->dpcm_lock, flags); list_del(&dpcm->list_be); list_del(&dpcm->list_fe); spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); kfree(dpcm); struct snd_soc_pcm_runtime *be = dpcm->be; <-- Accessing freed memory To prevent this situation, dpcm_lock is needed during accessing the lists for dpcm links. Signed-off-by: Gyeongtaek Lee Cc: stable@vger.kernel.org --- sound/soc/soc-pcm.c | 53 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 48f71bb81a2f..df2cd4c0dabe 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -1993,17 +1993,63 @@ static int dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream, return ret; } +struct dpcm_be_list { + unsigned int num; + struct snd_soc_pcm_runtime *be[]; +}; + +static int dpcm_create_be_list(struct snd_soc_pcm_runtime *fe, int stream, + struct dpcm_be_list **be_list) +{ + struct snd_soc_dpcm *dpcm; + struct dpcm_be_list *be; + int size = 0; + int ret = 0; + unsigned long flags; + + spin_lock_irqsave(&fe->card->dpcm_lock, flags); + + for_each_dpcm_be(fe, stream, dpcm) + size++; + + be = kzalloc(struct_size(be, be, size), GFP_ATOMIC); + if (!be) { + ret = -ENOMEM; + } else { + unsigned int i = 0; + + for_each_dpcm_be(fe, stream, dpcm) + be->be[i++] = dpcm->be; + + *be_list = be; + } + + spin_unlock_irqrestore(&fe->card->dpcm_lock, flags); + + return ret; +} + +static void dpcm_free_be_list(struct dpcm_be_list *be_list) +{ + kfree(be_list); +} + int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, int cmd) { struct snd_soc_pcm_runtime *be; - struct snd_soc_dpcm *dpcm; + struct dpcm_be_list *be_list; int ret = 0; + int i; - for_each_dpcm_be(fe, stream, dpcm) { + ret = dpcm_create_be_list(fe, stream, &be_list); + if (ret < 0) + return ret; + + for(i = 0; i < be_list->num; i++) { struct snd_pcm_substream *be_substream; - be = dpcm->be; + be = be_list->be[i]; be_substream = snd_soc_dpcm_get_substream(be, stream); /* is this op for this BE ? */ @@ -2092,6 +2138,7 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, if (ret < 0) dev_err(fe->dev, "ASoC: %s() failed at %s (%d)\n", __func__, be->dai_link->name, ret); + dpcm_free_be_list(be_list); return ret; } EXPORT_SYMBOL_GPL(dpcm_be_dai_trigger); base-commit: 4ac6d90867a4de2e12117e755dbd76e08d88697f -- 2.21.0