Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4146465pxb; Mon, 21 Feb 2022 13:16:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJwfQTTHv6HjU/c28nUHjaHOnq9ar37HL4U5Z6LQVD4MibYFBd1G3NbOkUdbw1QeYNYTtGZt X-Received: by 2002:aa7:cc12:0:b0:410:cb7b:a9ba with SMTP id q18-20020aa7cc12000000b00410cb7ba9bamr22862459edt.196.1645478181050; Mon, 21 Feb 2022 13:16:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645478181; cv=none; d=google.com; s=arc-20160816; b=D6/fg/xevMaN4aTalNKlFuk4VjMbhpLDJcvJhKYFSyf1zIoXWpVM3UD829lrnO8bhk 7QljD0eiv2vQTLJHSmdVrGx7zcdrT87nbI11311c4U7lcUD50S5OR2YxzS8a5LcWxvNs gEgCatw+fKGLBEvghX54AjPG1kcm3xGIDjM1rrxgp1dI/43B8uvIXs33qbWhUC58u/jJ tdNv+R/vG5Mu1jdMfbEaymIpE/wPKxYtQ7bq7T4sV6afWbL7swsZCrQOg3de/RHx+fU2 dNG9iW7RbVm2gyAhniKPHda3MuRBTdpXNVJL7JpfauP/iMMXpxiqsMogr951D3QWfd0k gM1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nbiHUo5bIkLPt2U0spcn2Q84xWnXDAyQTcCmzvwC0ZA=; b=f4le+KwaehFirhBSTDM4jufizRnr9PyLXQyQvSTqATyu7BWCmIcmy/cR43qYQNY1os vL/2HJp1hy7jO4KK7kkeUgfkcN4PXRpfZOTgblU5ibKijhua4f3p7ngBknTbTAzb0rll XcICJeGJ86lM1raMYwgxRjBafldtzaq8nffzmKxPl9ky1Cwn2FeOJHUQcNixQBgseRzC hLBxaeYHra5TfMNUz8Deg2ONGaxo+kd+XRnwCDogzHzJN4rpQx4Vbi89mnto06WQuXy9 l7PGcTTe/LDEnDZG/z9QiVYXU7uGVnzADSs0bmsARPjeu4j+eq/HYllJ6VkZRkBaJ721 fuZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LbFUfA5C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cr2si10387874ejc.571.2022.02.21.13.15.58; Mon, 21 Feb 2022 13:16:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LbFUfA5C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229917AbiBUJ7a (ORCPT + 99 others); Mon, 21 Feb 2022 04:59:30 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351482AbiBUJwG (ORCPT ); Mon, 21 Feb 2022 04:52:06 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C17521C11E; Mon, 21 Feb 2022 01:22:57 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 1D307CE0E95; Mon, 21 Feb 2022 09:22:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0106EC340F8; Mon, 21 Feb 2022 09:22:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435374; bh=CvA19KV9FG1Gjf9m0b3HLPFaZC9yM084E9lwfwyuGhQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LbFUfA5CF0Q9/vf1afLC1WFFzh4W+PyVuey3xDp7iMS2lN6lZ9Hdxnn8ou3jfPecq vX9N9/2teoWSwHstiLIG3qkG+eHt75KrqiAfWUOqx1014snV0hp3js5Q1LPympljiv 1LRh2/zJ8KzntS4Nh75bkV2AYSq/PnHpZaXY07eg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , Julian Wollrath Subject: [PATCH 5.16 140/227] ALSA: hda/realtek: Fix deadlock by COEF mutex Date: Mon, 21 Feb 2022 09:49:19 +0100 Message-Id: <20220221084939.495721883@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084934.836145070@linuxfoundation.org> References: <20220221084934.836145070@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai commit 2a845837e3d0ddaed493b4c5c4643d7f0542804d upstream. The recently introduced coef_mutex for Realtek codec seems causing a deadlock when the relevant code is invoked from the power-off state; then the HD-audio core tries to power-up internally, and this kicks off the codec runtime PM code that tries to take the same coef_mutex. In order to avoid the deadlock, do the temporary power up/down around the coef_mutex acquisition and release. This assures that the power-up sequence runs before the mutex, hence no re-entrance will happen. Fixes: b837a9f5ab3b ("ALSA: hda: realtek: Fix race at concurrent COEF updates") Reported-and-tested-by: Julian Wollrath Cc: Link: https://lore.kernel.org/r/20220214132838.4db10fca@schienar Link: https://lore.kernel.org/r/20220214130410.21230-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/pci/hda/patch_realtek.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -133,6 +133,22 @@ struct alc_spec { * COEF access helper functions */ +static void coef_mutex_lock(struct hda_codec *codec) +{ + struct alc_spec *spec = codec->spec; + + snd_hda_power_up_pm(codec); + mutex_lock(&spec->coef_mutex); +} + +static void coef_mutex_unlock(struct hda_codec *codec) +{ + struct alc_spec *spec = codec->spec; + + mutex_unlock(&spec->coef_mutex); + snd_hda_power_down_pm(codec); +} + static int __alc_read_coefex_idx(struct hda_codec *codec, hda_nid_t nid, unsigned int coef_idx) { @@ -146,12 +162,11 @@ static int __alc_read_coefex_idx(struct static int alc_read_coefex_idx(struct hda_codec *codec, hda_nid_t nid, unsigned int coef_idx) { - struct alc_spec *spec = codec->spec; unsigned int val; - mutex_lock(&spec->coef_mutex); + coef_mutex_lock(codec); val = __alc_read_coefex_idx(codec, nid, coef_idx); - mutex_unlock(&spec->coef_mutex); + coef_mutex_unlock(codec); return val; } @@ -168,11 +183,9 @@ static void __alc_write_coefex_idx(struc static void alc_write_coefex_idx(struct hda_codec *codec, hda_nid_t nid, unsigned int coef_idx, unsigned int coef_val) { - struct alc_spec *spec = codec->spec; - - mutex_lock(&spec->coef_mutex); + coef_mutex_lock(codec); __alc_write_coefex_idx(codec, nid, coef_idx, coef_val); - mutex_unlock(&spec->coef_mutex); + coef_mutex_unlock(codec); } #define alc_write_coef_idx(codec, coef_idx, coef_val) \ @@ -193,11 +206,9 @@ static void alc_update_coefex_idx(struct unsigned int coef_idx, unsigned int mask, unsigned int bits_set) { - struct alc_spec *spec = codec->spec; - - mutex_lock(&spec->coef_mutex); + coef_mutex_lock(codec); __alc_update_coefex_idx(codec, nid, coef_idx, mask, bits_set); - mutex_unlock(&spec->coef_mutex); + coef_mutex_unlock(codec); } #define alc_update_coef_idx(codec, coef_idx, mask, bits_set) \ @@ -230,9 +241,7 @@ struct coef_fw { static void alc_process_coef_fw(struct hda_codec *codec, const struct coef_fw *fw) { - struct alc_spec *spec = codec->spec; - - mutex_lock(&spec->coef_mutex); + coef_mutex_lock(codec); for (; fw->nid; fw++) { if (fw->mask == (unsigned short)-1) __alc_write_coefex_idx(codec, fw->nid, fw->idx, fw->val); @@ -240,7 +249,7 @@ static void alc_process_coef_fw(struct h __alc_update_coefex_idx(codec, fw->nid, fw->idx, fw->mask, fw->val); } - mutex_unlock(&spec->coef_mutex); + coef_mutex_unlock(codec); } /*