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 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 C0D97C77B60 for ; Wed, 26 Apr 2023 08:15:38 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 472FE1089; Wed, 26 Apr 2023 10:14:45 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 472FE1089 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1682496935; bh=U933/FLakViy7ZABOQOnGMtwkcGSEMKMBSU6rLupXTI=; h=Date:From:To:Subject:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=LNHu7+dF6eJHxIDYqiK7TBHfHiNe11uzXBWI641ffMm3tgwSkYIS7tlqN1luYY4Rs uzqK2nv2OmtSHrkUPg7CPeskKKgJCJtwJZ0r944NQXbaSewtn4wXJSjSpWJRDhQdNq MqBDHG/UwGeIwGZ59ARhnmCnXcioWeU5zX1la9xo= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 357A8F80236; Wed, 26 Apr 2023 10:14:21 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id B0928F80236; Wed, 26 Apr 2023 10:14:17 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 6318AF80137 for ; Wed, 26 Apr 2023 10:14:14 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 6318AF80137 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=FrGexklZ; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=J8Jlz6bE Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B2B9521A0C; Wed, 26 Apr 2023 08:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1682496853; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=M1G4S3FK1yY2QyDvXyKj5CqNV7wvs8bTdK4+2pu9qQw=; b=FrGexklZXUKD1AveKLSowcb78cfdPMtA3xNiQJ3UsbRe09CRcFYNpGHZMX1aGUq2INfCVg yvJIFC99oRIc2ewYzbG6nschyvbmNsrUYe2EugRCENu2GF6y/u2LWlwfUldfcr5sBDA2V5 Up87MO+wakF+SXqZ/TC2VOz5y3VNJlU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1682496853; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=M1G4S3FK1yY2QyDvXyKj5CqNV7wvs8bTdK4+2pu9qQw=; b=J8Jlz6bEQEpMzJrot5tTUrEdomfsvz/127koz4BXYjXWI1ermlbwJIbRTlOND9MJt+Hzkp bpzTGwmMTRrQrkCg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 93AB513421; Wed, 26 Apr 2023 08:14:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Q6uVI1XdSGTBEAAAMHmgww (envelope-from ); Wed, 26 Apr 2023 08:14:13 +0000 Date: Wed, 26 Apr 2023 10:14:13 +0200 Message-ID: <87leifjc16.wl-tiwai@suse.de> From: Takashi Iwai To: Jaroslav Kysela Subject: Re: USB sound card freezes USB after resume from suspend In-Reply-To: <7645c6c8-a21c-23d7-5c19-cd2892b98481@perex.cz> References: <20230425111924.05cf8b13@kernel.org> <87pm7rtdul.wl-tiwai@suse.de> <7645c6c8-a21c-23d7-5c19-cd2892b98481@perex.cz> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Message-ID-Hash: 57LX6MFGFTQZCJ7RVUOK3TG7ERHZW2II X-Message-ID-Hash: 57LX6MFGFTQZCJ7RVUOK3TG7ERHZW2II X-MailFrom: tiwai@suse.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Jakub Kicinski , Takashi Iwai , alsa-devel@alsa-project.org, linux-usb@vger.kernel.org, Greg Kroah-Hartman , regressions@lists.linux.dev X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Wed, 26 Apr 2023 10:01:11 +0200, Jaroslav Kysela wrote: > > On 26. 04. 23 7:24, Takashi Iwai wrote: > > On Tue, 25 Apr 2023 20:19:24 +0200, > > Jakub Kicinski wrote: > >> > >> Hi! > >> > >> For a few weeks now I can't use any USB devices if I suspend my laptop > >> with my USB sound card active and resuming it without it connected. > >> > >> USB worker threads seems to be sitting in: > >> > >> [<0>] snd_pcm_dev_disconnect+0x1e8/0x280 [snd_pcm] > >> [<0>] snd_device_disconnect_all+0x42/0x80 [snd] > >> [<0>] snd_card_disconnect+0x128/0x290 [snd] > >> [<0>] usb_audio_disconnect+0x11a/0x2c0 [snd_usb_audio] > >> [<0>] usb_unbind_interface+0x8c/0x270 > >> [<0>] device_release_driver_internal+0x1b2/0x230 > >> [<0>] bus_remove_device+0xd8/0x150 > >> [<0>] device_del+0x18b/0x410 > >> [<0>] usb_disable_device+0xc6/0x1e0 > >> [<0>] usb_disconnect+0xda/0x2c0 > >> [<0>] usb_disconnect+0xbf/0x2c0 > >> [<0>] usb_disconnect+0xbf/0x2c0 > >> [<0>] usb_disconnect+0xbf/0x2c0 > >> [<0>] hub_event+0xf01/0x1cd0 > >> [<0>] process_one_work+0x1c4/0x3d0 > >> [<0>] worker_thread+0x4d/0x380 > >> [<0>] kthread+0xe6/0x110 > >> [<0>] ret_from_fork+0x29/0x50 > >> > >> Which is: > >> > >> snd_pcm_dev_disconnect (/usr/src/debug/kernel-6.2.12/linux-6.2.12-300.fc38.x86_64/sound/core/pcm.c:818 /usr/src/debug/kernel-6.2.12/linux-6.2.12-300.fc38.x86_64/sound/core/pcm.c:812 /usr/src/debug/kernel-6.2.12/linux-6.2.12-300.fc38.x86_64/sound/core/pcm.c:1129) snd_pcm > >> > >> It happens on Fedora 37 and Fedora 38, it seems to have coincided with > >> the 6.2 kernel but I'm not 100% sure. > >> > >> The USB devices come back after half an hour or so, silently. > >> There's nothing of note in dmesg. > > > > AFAIK, there has been no similar report, so far. > > > > Is it a regression? If yes, could you figure out which kernel version > > starts showing the problem (or at best bisection)? > > It seems that it may be related to free_chmap(): > > (gdb) l *(snd_pcm_dev_disconnect+0x1e8) > 0xef0 is in snd_pcm_dev_disconnect (sound/core/pcm.c:817). > 812 static void free_chmap(struct snd_pcm_str *pstr) > 813 { > 814 if (pstr->chmap_kctl) { > 815 struct snd_card *card = pstr->pcm->card; > 816 > 817 down_write(&card->controls_rwsem); > 818 snd_ctl_remove(card, pstr->chmap_kctl); > 819 up_write(&card->controls_rwsem); > 820 pstr->chmap_kctl = NULL; > 821 } > > I think that the chmap should be freed only in snd_pcm_free_stream() > to avoid possible nested mutex locks. This operation does not belong > to disconnect. A good point, it'll be a patch like below. But we still need to figure out what's actually happening there. > But I cannot reproduce this lock here. Here too. Could be tied with the config or the device? thanks, Takashi -- 8< -- --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -1126,7 +1126,6 @@ static int snd_pcm_dev_disconnect(struct snd_device *device) pcm_call_notify(pcm, n_disconnect); for (cidx = 0; cidx < 2; cidx++) { snd_unregister_device(&pcm->streams[cidx].dev); - free_chmap(&pcm->streams[cidx]); } mutex_unlock(&pcm->open_mutex); mutex_unlock(®ister_mutex);