Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2134144pxv; Fri, 2 Jul 2021 23:43:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJJw8/vGanvDHzh+sZwCuItcRxMfr3QhpW4is07kQli+3gP1rKeuwkJ3dGUtRop1kgM9dO X-Received: by 2002:aa7:d9cc:: with SMTP id v12mr3651920eds.224.1625294628543; Fri, 02 Jul 2021 23:43:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625294628; cv=none; d=google.com; s=arc-20160816; b=U+AAGHvlM83HCuBGT5i1p56un8xXSb7/UDW71wqWejMcYIueASXFAX7xcDB8x5TtsQ 6E0hyUNweiSctHncDPhseUyUci+f3VEHsJwlg7tmiFAcXK5Cb0SHp4xqwiSVhblFQD3t qcdt2nI+d0TZdeI5C41BJND88/wRvS/gOFEH2CpU1w4gE9YgsO5HjO458L8xoJEww+su VFqLMhhbK8CjqIcb0pI7FxLKWmB33CnnVIWDTeNqkaVH7p2Qt9e3GpGVtb5z2ypKJral A+gbvhAWxPlKoteItu6BxvWe3jXtY4MBz3JuD6I2xpaQN7zWUZAN/5Wu6Vniw2N1YGQI W8zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature:dkim-signature; bh=UOVQzo5peU9hwquiGwR5ViUp2k9ewftmmdtIsg9qScw=; b=xrPxRpk9pyPknmYFdcCIjDX0e/rFRksOpZV5aCLb0x7nJmoj5plmzmboHD6S5oKYsW CJJVJAFs6h+sfJJwSlVF0bX0Rt7VbBZaLTHN3IX5EzTJziTKq5EOBaUpfd4Gm5I3M+IW Ttpg5qdywOJIQPeXtMv8zTpEX3TB8CgwzFJN6eeX1F8bGoqaVLOs43o4EhIvvgUTfRFu UvDsGRqJ9hcMqn2VOiR4VE4Lye5dJIUF50HeYa5SWAA5soQDDB9E5CDYB/lCWJcwtw63 sFv+QGHv90AtE6BebEE4yudYO3sgbu/mC47gECXkokTr1eHdqJdxj5lVU4wWqQK8r1Hd 1Mtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm2 header.b=QcN1SRQR; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=U+3NTxvx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b9si5167635eds.501.2021.07.02.23.43.24; Fri, 02 Jul 2021 23:43:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@sakamocchi.jp header.s=fm2 header.b=QcN1SRQR; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=U+3NTxvx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229898AbhGCGl2 (ORCPT + 99 others); Sat, 3 Jul 2021 02:41:28 -0400 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:46381 "EHLO wout4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbhGCGl2 (ORCPT ); Sat, 3 Jul 2021 02:41:28 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 5E95C32003AC; Sat, 3 Jul 2021 02:38:54 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Sat, 03 Jul 2021 02:38:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=UOVQzo5peU9hwquiGwR5ViUp2k9 ewftmmdtIsg9qScw=; b=QcN1SRQRNScvREtQ7Qz078kAsUVQiueobP2eBHB07CJ xwvV1WHaxoEY6nzC0YcjuctiR5FEcSsNbD+s32qMrNuPmzxUwVj9ghIfXh4nqaSM WC/v+r4rzVw82nBvS/78kp1bVOOJJZ9QQRI/y8TOPB2ydVKrXawz788qNr3H86Bc 28I6PILaFfC+uVsaCA4td6v8hnFw2IhlTyZ83Qd/m7EuqYlBVasHqevCsQhJ396j rEsnUuocF9/epLbF8CwhR6f309HoULJP+pXfHrqh+alJ7042bJOSOJ64VUuety+3 1zB91WT9C7SzzxorNpkWPxPtEgmeJQLbWmTk1BItT4A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=UOVQzo 5peU9hwquiGwR5ViUp2k9ewftmmdtIsg9qScw=; b=U+3NTxvxx71BQXB7CERqUF T6gVnr2fbpR29q0jpu0xj2zmNE5zsKKTsAfSQAyvROCwbCwZCwtL89/WUqpqh4fY jC9GUCPFQLwTpxmEJ6dmeU6GMLIn6GWsgaCj17gidqXK1JCi4hsO8cjQtHQYk8rn QTWB1LqXfz+bSb38pT1Y9FTdRam1xELzPWijhywW0ZYb+56AyrSpjoEzkBdEvk0g mXwHaMPjfGzyVyK2wl84D5EcS0CMdT6p5LZfwciTsMT/ncDDvpToXTdzY/4Rdy5p /GCbOL4F+W/jjB75e3F3G7LTznJaDSiFA5ot1P66kwyUrYUj0RvIA0raZci1bLRA == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeeiledguddtvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepvfgrkhgr shhhihcuufgrkhgrmhhothhouceoohdqthgrkhgrshhhihesshgrkhgrmhhotggthhhird hjpheqnecuggftrfgrthhtvghrnheplefhueegvdejgfejgfdukeefudetvddtuddtueei vedttdegteejkedvfeegfefhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepohdqthgrkhgrshhhihesshgrkhgrmhhotggthhhirdhjph X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 3 Jul 2021 02:38:51 -0400 (EDT) Date: Sat, 3 Jul 2021 15:38:48 +0900 From: Takashi Sakamoto To: Linus Torvalds Cc: Takashi Iwai , alsa-devel@alsa-project.org, Mark Brown , Liam Girdwood , Linux Kernel Mailing List , marcan@marcan.st Subject: Re: [GIT PULL] sound updates for 5.14-rc1 Message-ID: Mail-Followup-To: Linus Torvalds , Takashi Iwai , alsa-devel@alsa-project.org, Mark Brown , Liam Girdwood , Linux Kernel Mailing List , marcan@marcan.st References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Fri, Jul 02, 2021 at 10:19:46PM -0700, Linus Torvalds wrote: > On Fri, Jul 2, 2021 at 9:37 PM Linus Torvalds > wrote: > > > > But I thought I'd report this as a likely candidate. > > Confirmed. The watchdog hang bisects right down to commit 9ce650a75a3b > ("ALSA: usb-audio: Reduce latency at playback start"). > > And reverting it on top of my tree also fixes the hang, so it's not > some bisection fluke. > > I have no idea what is actually wrong with that commit, but it most > definitely is the problem, and I have reverted it in my tree so that I > can continue merging stuff tomorrow. The cause seems to be the attempt to lock PCM substream recursively introduced by the issued commit. Would I ask you to test with below patch? I apologize that the patch is still untested in my side since at present I have no preparation to debug USB stuffs instantly (I'm just a maintainer for ALSA firewire stack...), so I'm glad if getting your cooperation for the issue. ======== 8< -------- From f7ab449f10152635ad7083aa73d80e3fb1adabb4 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Sat, 3 Jul 2021 15:23:25 +0900 Subject: [PATCH] ALSA: usb-audio: fix recursive lock of PCM substream when starting playback PCM substream A commit 9ce650a75a3b ("ALSA: usb-audio: Reduce latency at playback start") unfortunately introduced the call of snd_pcm_period_elapsed() under acquired lock of PCM substream. This causes recursive lock and results in dead-lock. ->ioctl(2) (sound/core/pcm_native.c) ->snd_pcm_stream_lock_irqsave() <- ... ->struct snd_pcm_ops.trigger() (sound/usb/pcm.c) = snd_usb_substream_playback_trigger() ->start_endpoints() (sound/usb/endpoint.c) ->snd_usb_endpoint_start() ->prepare_outbound_urb() ->struct snd_usb_endpoint.prepare_data_urb() (sound/usb/pcm.c) = prepare_playback_urb() (sound/core/pcm_lib.c) ->snd_pcm_period_elapsed() (sound/core/pcm_native.c) ->snd_pcm_stream_lock_irqsave() <- This commit fixes the issue to use newly added function; snd_pcm_period_elapsed_under_stream_lock() with condition to check running context. Reported-by: Hector Martin Fixes: 9ce650a75a3b ("ALSA: usb-audio: Reduce latency at playback start") Signed-off-by: Takashi Sakamoto --- sound/usb/pcm.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index c66831ee15f9..235070f0236a 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -1395,8 +1395,16 @@ static void prepare_playback_urb(struct snd_usb_substream *subs, spin_unlock_irqrestore(&subs->lock, flags); urb->transfer_buffer_length = bytes; - if (period_elapsed) - snd_pcm_period_elapsed(subs->pcm_substream); + if (period_elapsed) { + // The callback of struct snd_pcm_ops.trigger with SNDRV_PCM_TRIGGER_START command + // can reach here, under acquired lock of PCM substream. To avoid dead-lock, check + // current context and call corresponding function. + if (in_softirq()) { + snd_pcm_period_elapsed(subs->pcm_substream); + } else { + snd_pcm_period_elapsed_under_stream_lock(subs->pcm_substream); + } + } } /* -- 2.30.2 ======== 8< -------- Thanks Takashi (not subsystem maintainer) Sakamoto