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 AD7D9ECAAA1 for ; Fri, 9 Sep 2022 16:00:45 +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 BB2041651; Fri, 9 Sep 2022 17:59:53 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz BB2041651 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1662739243; bh=IPegQaVJ5BcrY5za71KUf86GJrRbfbHlQtA1b92b33c=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=XRRm/w6rnLrlXo7dVqUZwLh/CSfKVqHiMWuvBNsSNTJOhVQRVfZbbnFr+fQxygi8h 1vWZ6xqHsc+v3Fgt+dxJJiLw/ZKN6f/zgQjhOqoJp45eV78tZKos36sMtbuq1dsi+O ZvqjHwq7Qlh3QV2wKyo4HXEOYdxiPBOOpe7IVJ44= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 3AB02F8016C; Fri, 9 Sep 2022 17:59:53 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id F02B5F8023A; Fri, 9 Sep 2022 17:59:51 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (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 9F3A9F8016C for ; Fri, 9 Sep 2022 17:59:48 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 9F3A9F8016C Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="O6BHXY5a"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Bld3I7H+" 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 0724822CE8; Fri, 9 Sep 2022 15:59:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1662739188; 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=pRLas43sjox7U3pbQ+WeY9MwwBLpYupEDL3u9GS1D2Y=; b=O6BHXY5aJIlMjCTXh/4pfWdu4N3CvOOylNEcvZXLcdk6yBIczhSW4Pa2EgSaCm/a0i6aBQ XkdXw/Ea76YwK09Rb6uz9JCClPaNIiLaYVCZ7Q/86as1E7ZR4gQWO9IUf+RRwC9kpYZRO5 w/lGlGQlD3ZKz1R41HCi2K+29gy6wbI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1662739188; 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=pRLas43sjox7U3pbQ+WeY9MwwBLpYupEDL3u9GS1D2Y=; b=Bld3I7H+60UUHX+C5HP4Av+RYtzfM9vI+58QLY3rN9GwVL+xa8xATdtj0OnJOE8VCZNWC1 PQ+c7Dx/izihWpCg== 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 DF70F139D5; Fri, 9 Sep 2022 15:59:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6wjMNfNiG2OVewAAMHmgww (envelope-from ); Fri, 09 Sep 2022 15:59:47 +0000 Date: Fri, 09 Sep 2022 17:59:47 +0200 Message-ID: <87fsh0czd8.wl-tiwai@suse.de> From: Takashi Iwai To: Ville =?ISO-8859-1?Q?Syrj=E4l=E4?= Subject: Re: hda codec unbind refcount hang In-Reply-To: References: 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=ISO-8859-1 Content-Transfer-Encoding: 8bit Cc: alsa-devel@alsa-project.org 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 Fri, 09 Sep 2022 17:45:25 +0200, Ville Syrjälä wrote: > > Hi Takashi, > > commit 7206998f578d ("ALSA: hda: Fix potential deadlock at codec > unbinding") introduced a problem on at least one of my older machines. > > The problem happens when hda_codec_driver_remove() encounters a > codec without any pcms (and thus the refcount is 1) and tries to > call refcount_dec(). Turns out refcount_dec() doesn't like to be > used for dropping the refcount to 0, and instead if spews a warning > and does its saturate thing. The subsequent wait_event() is then > permanently stuck waiting on the saturated refcount. > > I've definitely seen the same kind of pattern used elsewhere > in the kernel as well, so the fact that refcount_t can't be used > to implement it is a bit of surprise to me. I guess most other > places still use atomic_t instead. Does the patch below work around it? It seem to be a subtle difference between refcount_dec() and refcount_dec_and_test(). thanks, Takashi -- 8< -- --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c @@ -157,10 +157,11 @@ static int hda_codec_driver_remove(struct device *dev) return codec->bus->core.ext_ops->hdev_detach(&codec->core); } - refcount_dec(&codec->pcm_ref); - snd_hda_codec_disconnect_pcms(codec); - snd_hda_jack_tbl_disconnect(codec); - wait_event(codec->remove_sleep, !refcount_read(&codec->pcm_ref)); + if (!refcount_dec_and_test(&codec->pcm_ref)) { + snd_hda_codec_disconnect_pcms(codec); + snd_hda_jack_tbl_disconnect(codec); + wait_event(codec->remove_sleep, !refcount_read(&codec->pcm_ref)); + } snd_power_sync_ref(codec->bus->card); if (codec->patch_ops.free)