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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A8B6CC433F5 for ; Thu, 13 Jan 2022 16:13:15 +0000 (UTC) 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 107881F83; Thu, 13 Jan 2022 17:12:23 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 107881F83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1642090393; bh=rAbS0ibmRI7QIfh1yKc8CRsA1HULjEF9GcCLKv+bDp4=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=gF8SUOMhzaRfwJln/5kJEbJKk7RCFYHp7hL5gjcR8QFGSSYYxhkehSwoO19VWfLd6 YU+XZBxRejpfRiRyWZpy5R76sDGGEzO9P7kZCzVD2Yz30/eK2ik3jV6m7G4CgIxTGX qCM5fqMIuQwGA+rCOVJfUQbsjpkxndd8fbAIGGmA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 9117FF8010B; Thu, 13 Jan 2022 17:12:22 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 93FA0F8013F; Thu, 13 Jan 2022 17:12:21 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 83A9FF80088 for ; Thu, 13 Jan 2022 17:12:13 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 83A9FF80088 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="f/P4HyFr"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="mQaBkR2l" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id E51CD1F3BA; Thu, 13 Jan 2022 16:12:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1642090332; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yAdFeGuSrg6CdcZrhVcPF9lmz3MLRx4AGnEN8Y0bTCc=; b=f/P4HyFrpqHqb07LXIGWRtApvbQf+jJNf7HouPCVulWMILxW4P8tgkPZcpg/Zgp6kqC5NT tqRGLFsHx5/hiWSmFvHFI4KUwhcQeCGkdxUDdTyZEvtEGbbJM1Pi/+8qshuw9zp7WJYspi NU/sxgl4Mz942yVhnTeQIyI9S1lSp2w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1642090332; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yAdFeGuSrg6CdcZrhVcPF9lmz3MLRx4AGnEN8Y0bTCc=; b=mQaBkR2lsxvjYYPz2MFkE5mlMluCW8kTkLPanCnlJXYr7SWNQkPb7LCPD3ZrR5txzd1/wN tqxkM9VxHX8GFwCA== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id C744AA3B88; Thu, 13 Jan 2022 16:12:12 +0000 (UTC) Date: Thu, 13 Jan 2022 17:12:12 +0100 Message-ID: From: Takashi Iwai To: Marek Szyprowski Subject: Re: [PATCH] ASoC: soc-pcm: Fix DPCM lockdep warning due to nested stream locks In-Reply-To: <91d7a1df-9e90-7c07-f15c-7ca1dad0b4ef@samsung.com> References: <20220113141858.10904-1-tiwai@suse.de> <91d7a1df-9e90-7c07-f15c-7ca1dad0b4ef@samsung.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Hans de Goede , alsa-devel@alsa-project.org, Mark Brown , Pierre-Louis Bossart 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" On Thu, 13 Jan 2022 15:59:31 +0100, Marek Szyprowski wrote: > > On 13.01.2022 15:18, Takashi Iwai wrote: > > The recent change for DPCM locking caused spurious lockdep warnings. > > Actually the warnings are false-positive, as those are triggered due > > to the nested stream locks for FE and BE. Since both locks belong to > > the same lock class, lockdep sees it as if a deadlock. > > > > For fixing this, we need take PCM stream locks for BE with the nested > > lock primitives. Since currently snd_pcm_stream_lock*() helper > > assumes only the top-level single locking, a new helper function > > snd_pcm_stream_lock_irqsave_nested() is defined for a single-depth > > nested lock, which is now used in the BE DAI trigger that is always > > performed inside a FE stream lock. > > > > Fixes: b7898396f4bb ("ASoC: soc-pcm: Fix and cleanup DPCM locking") > > Reported-and-tested-by: Hans de Goede > > Reported-by: Marek Szyprowski > > Link: https://lore.kernel.org/r/73018f3c-9769-72ea-0325-b3f8e2381e30@redhat.com > > Link: https://lore.kernel.org/alsa-devel/9a0abddd-49e9-872d-2f00-a1697340f786@samsung.com > > Signed-off-by: Takashi Iwai > > Thanks for the fix! It helps a bit, but I still get a warning (a > different one now): Thanks for the quick testing. Actually we do have multiple issues. > root@target:~# speaker-test -l1 > > speaker-test 1.1.8 > > Playback device is default > Stream parameters are 48000Hz, S16_LE, 1 channels > Using 16 octaves of pink noise > Rate set to 48000Hz (requested 48000Hz) > Buffer size range from 128 to 131072 > Period size range from 64 to 65536 > Using max buffer size 131072 > Periods = 4 > was set period_size = 32768 > was set buffer_size = 131072 >  0 - Front Left > Time per period = 0.022199 > max98090 1-0010: PLL unlocked > > ===================================================== > WARNING: SOFTIRQ-safe -> SOFTIRQ-unsafe lock order detected > 5.16.0-next-20220113-00001-g3967460dbcf4 #11212 Not tainted > ----------------------------------------------------- > speaker-test/1319 [HC0[0]:SC0[0]:HE0:SE1] is trying to acquire: > c1296410 (pin_fs_lock){+.+.}-{2:2}, at: simple_pin_fs+0x1c/0xac > > and this task is already holding: > c2fe6ea4 (&group->lock){..-.}-{2:2}, at: dpcm_be_disconnect+0x3c/0x348 > which would create a new lock dependency: >  (&group->lock){..-.}-{2:2} -> (pin_fs_lock){+.+.}-{2:2} So that's the problem: we call debugfs_remove_recursive() in the spinlocked context. Could you try the patch below? It's a bit hackish, but let's check whether that's the real cause or not. Takashi --- --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -1268,6 +1268,7 @@ static void dpcm_be_reparent(struct snd_soc_pcm_runtime *fe, void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream) { struct snd_soc_dpcm *dpcm, *d; + LIST_HEAD(deleted_dpcms); snd_soc_dpcm_mutex_assert_held(fe); @@ -1287,13 +1288,18 @@ void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream) /* BEs still alive need new FE */ dpcm_be_reparent(fe, dpcm->be, stream); - dpcm_remove_debugfs_state(dpcm); - list_del(&dpcm->list_be); + list_move(&dpcm->list_fe, &deleted_dpcms); + } + snd_soc_dpcm_stream_unlock_irq(fe, stream); + + while (!list_empty(&deleted_dpcms)) { + dpcm = list_first_entry(&deleted_dpcms, struct snd_soc_dpcm, + list_fe); list_del(&dpcm->list_fe); + dpcm_remove_debugfs_state(dpcm); kfree(dpcm); } - snd_soc_dpcm_stream_unlock_irq(fe, stream); } /* get BE for DAI widget and stream */