From patchwork Wed Jul 6 12:02:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cezary Rojewski X-Patchwork-Id: 587765 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 990F5C433EF for ; Wed, 6 Jul 2022 11:53:35 +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 78C5F169C; Wed, 6 Jul 2022 13:52:43 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 78C5F169C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1657108413; bh=BHmWG6c0VB2XxZFlHPPmiVu4GAR7HgrBVzWFqZOxawc=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=uZGMdhPLHe4JhQdmoODdc4F4xQ6z+qZA4vpwOGV7IecKbtYFxI56wBYYZmrKsqlmj KfA7KBB42+DZEw7FW01DL3e7xfMoKrf6A73Cope6n9aDC/f7OJmSLJUh/VmUfCljlL oGo/5m4kz7DPVeNx3yuWT6JDLtItlRWaWYKcxkKU= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 12755F804B4; Wed, 6 Jul 2022 13:52:43 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 51792F804B4; Wed, 6 Jul 2022 13:52:41 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 976FCF8012A for ; Wed, 6 Jul 2022 13:52:38 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 976FCF8012A Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RGTmDp8B" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657108359; x=1688644359; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BHmWG6c0VB2XxZFlHPPmiVu4GAR7HgrBVzWFqZOxawc=; b=RGTmDp8BYOIKJg0mbVu9I0uDeHykj/ppALz7j5r6aFmAhHuhgj1gj9ec gMQTUrHI+xkYz+4aMx2KevZkbh/qGI3gE5NnhVhwr4ogtj22CDcEOa6dx YW6MIpLUUQE8ZFA469hE3NjlahVJVd6KXfz6ftG8UmVy3Eg4xL9xebHI8 Mgq2aOyX3/51vhwXbVE+ma37O2JSBOVzVaIIhpUipNPipmwda8Nt9uDpK M/vVg0Ys8CopYlC8jyiqb9dpFUZUQPifqUaLKOWvJ2gViXnUXMPbno/Cy Dr3fsSmZBIv45w7SnLIZzNYZpYryB81N/6shyiFRlK3iTQsbLSSssgYtj A==; X-IronPort-AV: E=McAfee;i="6400,9594,10399"; a="370042598" X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="370042598" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2022 04:52:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="920136253" Received: from crojewsk-ctrl.igk.intel.com ([10.102.9.28]) by fmsmga005.fm.intel.com with ESMTP; 06 Jul 2022 04:52:34 -0700 From: Cezary Rojewski To: alsa-devel@alsa-project.org, tiwai@suse.com Subject: [PATCH 1/9] ALSA: hda: Do not unset preset when cleaning up codec Date: Wed, 6 Jul 2022 14:02:22 +0200 Message-Id: <20220706120230.427296-2-cezary.rojewski@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220706120230.427296-1-cezary.rojewski@intel.com> References: <20220706120230.427296-1-cezary.rojewski@intel.com> MIME-Version: 1.0 Cc: Cezary Rojewski , pierre-louis.bossart@linux.intel.com, hdegoede@redhat.com, broonie@kernel.org, amadeuszx.slawinski@linux.intel.com 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" snd_hda_codec_cleanup_for_unbind() unsets preset what interferes with module unloading and triggers null-ptr-deref. Preset is assigned only once, during device/driver matching whereas module reload and unload follow completely different path and may occur several times during runtime. Fixes: 9a6246ff78ac ("ALSA: hda - Implement unbind more safely") Signed-off-by: Cezary Rojewski --- sound/pci/hda/hda_codec.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 7579a6982f47..9ceb642ac819 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -795,7 +795,6 @@ void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) snd_array_free(&codec->cvt_setups); snd_array_free(&codec->spdif_out); snd_array_free(&codec->verbs); - codec->preset = NULL; codec->follower_dig_outs = NULL; codec->spdif_status_reset = 0; snd_array_free(&codec->mixers); From patchwork Wed Jul 6 12:02:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cezary Rojewski X-Patchwork-Id: 587764 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 BF15BC43334 for ; Wed, 6 Jul 2022 11:54:25 +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 2232B16B8; Wed, 6 Jul 2022 13:53:34 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 2232B16B8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1657108464; bh=amzOSwAOX4foyC+9TNzVuqyMV+SNxwJmMBmYPdPI7oI=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=JP9pXEdN1IfzgE+pmMBsrTcuUWig5bYq6ZsG9JGhPkb5SO0+NTi2M8KgfEEjsvRqJ MY3Yem8j0mifDp1rk6DdwjW0KtnxmkHck1yhn/d6qrUIsTZoMVEpsOb6Zhwt6rM426 vOR9cFKk7MWu3nbDS2LnYXuaN+xx9DSmOmWPk7CU= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 5777FF80538; Wed, 6 Jul 2022 13:52:47 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1A4C2F804ED; Wed, 6 Jul 2022 13:52:45 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 3D68DF8023A for ; Wed, 6 Jul 2022 13:52:39 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 3D68DF8023A Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="LKGEL3LR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657108363; x=1688644363; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=amzOSwAOX4foyC+9TNzVuqyMV+SNxwJmMBmYPdPI7oI=; b=LKGEL3LRtzJJSB0e8dwTlpmnx19slUI1Euuq3dHP3EGbzehXy2nzHpSq VBth3OHlnhSrUa1I3VVJrmsUciM4zTsww8TsW5a2CRi2mo0DjPeNQc7Wk TLErshxYSJAG62KAf6zVaxk+eXBrJ21YP5kraEIfnP2CVWuIZiq5KYs/i ti7wYKUIbhaofz8oNdj3B0R9uR65ABM1gC6rh6CFAKYQ2rSCOp6cd2My+ 8jVsfn5klvAZPprXvWbXlYnC4pnCvMXNNwgdUrc3pHvJMvl4Dt95RfyJq AKrqIDm9Q7F95FIzSIdiFyjCJ7IWi5APGz2+LvTrusoBWJyfP54RFl1vj w==; X-IronPort-AV: E=McAfee;i="6400,9594,10399"; a="370042620" X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="370042620" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2022 04:52:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="920136268" Received: from crojewsk-ctrl.igk.intel.com ([10.102.9.28]) by fmsmga005.fm.intel.com with ESMTP; 06 Jul 2022 04:52:37 -0700 From: Cezary Rojewski To: alsa-devel@alsa-project.org, tiwai@suse.com Subject: [PATCH 3/9] ALSA: hda: Make device usage_count consistent across subsequent probing Date: Wed, 6 Jul 2022 14:02:24 +0200 Message-Id: <20220706120230.427296-4-cezary.rojewski@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220706120230.427296-1-cezary.rojewski@intel.com> References: <20220706120230.427296-1-cezary.rojewski@intel.com> MIME-Version: 1.0 Cc: Cezary Rojewski , pierre-louis.bossart@linux.intel.com, hdegoede@redhat.com, broonie@kernel.org, amadeuszx.slawinski@linux.intel.com 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" AVS HDAudio bus driver does not tie with codec drivers tighly and snd_hda_codec_device_new() can be called after codec's module reload. In such case, rpm is forbidden and invoking pm_runtime_forbid() unconditionally causes device's usage_count to become unbalanced. This is later caught by WARN_ON() found in sound/soc/hda.c. Detect such circumstance and bump the usage_count instead. Signed-off-by: Cezary Rojewski --- sound/pci/hda/hda_codec.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 9ceb642ac819..83d954ab056f 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -1044,8 +1044,14 @@ int snd_hda_codec_device_new(struct hda_bus *bus, struct snd_card *card, goto error; } +#ifdef CONFIG_PM /* PM runtime needs to be enabled later after binding codec */ - pm_runtime_forbid(&codec->core.dev); + if (codec->core.dev.power.runtime_auto) + pm_runtime_forbid(&codec->core.dev); + else + /* Keep the usage_count consistent across subsequent probing */ + pm_runtime_get_noresume(&codec->core.dev); +#endif return 0; From patchwork Wed Jul 6 12:02:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cezary Rojewski X-Patchwork-Id: 587761 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 2915FCCA473 for ; Wed, 6 Jul 2022 11:55:58 +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 6A9DF16D5; Wed, 6 Jul 2022 13:55:06 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6A9DF16D5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1657108556; bh=0QRNt+1qf6ahxvwm4IA9D0yF6GEVpZjS+dnXOeTslDg=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=J+kjiRfUjDh9C5ePjTAjmxoV0ODjonAXJKDf4Rto2YfLPIx/peB8SYySIL+CbKody +EoCi28Z/CJPwVbf4SDkCUk5Knl2Z08zwbszi+bOSRGYEyFciY0p7FaK1RJC6Fa1Sb 2/dAqpFBjHFeqMrXjQRuucugI2mwkyhNQEhrFgns= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 53B20F80567; Wed, 6 Jul 2022 13:52:57 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 60F8CF80557; Wed, 6 Jul 2022 13:52:54 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 86381F8053A for ; Wed, 6 Jul 2022 13:52:46 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 86381F8053A Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="mFP/GQDk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657108369; x=1688644369; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0QRNt+1qf6ahxvwm4IA9D0yF6GEVpZjS+dnXOeTslDg=; b=mFP/GQDk5ArrATTH9YRwmAffOi/kRGn+wum9ygVnLILdQG45JeqfdGGN WEacB/tct7cFXneLtSjf1EG2cw6df48q7+2MCf6sElxaN9450Kw+i/op7 oS71ryPaoFZz36GZDRpwPxQkny6LJZi7ilzHMXj+xqLT27HH5x4HUX6zb +eOkj2qZKP8jG+37S0Cq2lL7FbsItcUPSpRQrjmi8dXRYHe+r5K4UlcTS VyWmIMKFBpvWjh8CA/zQbR8MYfrRYR5HlxwAGUJXwjEAGKiX73nO8q0WB Hqnhcdo/DZYFmLMLkbUVhWudCItYXbrixgoUpnRlB1O3dOFPlCHOjSiCy A==; X-IronPort-AV: E=McAfee;i="6400,9594,10399"; a="370042626" X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="370042626" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2022 04:52:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="920136275" Received: from crojewsk-ctrl.igk.intel.com ([10.102.9.28]) by fmsmga005.fm.intel.com with ESMTP; 06 Jul 2022 04:52:39 -0700 From: Cezary Rojewski To: alsa-devel@alsa-project.org, tiwai@suse.com Subject: [PATCH 4/9] ALSA: hda: Fix put_device() inconsistency in error path Date: Wed, 6 Jul 2022 14:02:25 +0200 Message-Id: <20220706120230.427296-5-cezary.rojewski@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220706120230.427296-1-cezary.rojewski@intel.com> References: <20220706120230.427296-1-cezary.rojewski@intel.com> MIME-Version: 1.0 Cc: Cezary Rojewski , pierre-louis.bossart@linux.intel.com, hdegoede@redhat.com, broonie@kernel.org, amadeuszx.slawinski@linux.intel.com 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" AVS HDAudio bus driver does not tie with codec drivers tighly. Codec device and its respective driver cleanup procedures are split and may not occur one after the other. Device cleanup is performed only on snd_hdac_ext_bus_device_remove() i.e. it's the bus driver's responsibility. If codec component probing fails, put_device() found in snd_hda_codec_device_new() may lead to page fault. Relocate it to snd_hda_codec_new() to address the problem on ASoC side while keeping status quo for snd_hda_intel. Signed-off-by: Cezary Rojewski --- sound/pci/hda/hda_codec.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 83d954ab056f..2381aced492f 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -949,6 +949,7 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, unsigned int codec_addr, struct hda_codec **codecp) { struct hda_codec *codec; + int ret; codec = snd_hda_codec_device_init(bus, codec_addr, "hdaudioC%dD%d", card->number, codec_addr); @@ -956,7 +957,11 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, return PTR_ERR(codec); *codecp = codec; - return snd_hda_codec_device_new(bus, card, codec_addr, *codecp, true); + ret = snd_hda_codec_device_new(bus, card, codec_addr, *codecp, true); + if (ret) + put_device(hda_codec_dev(*codecp)); + + return ret; } EXPORT_SYMBOL_GPL(snd_hda_codec_new); @@ -1011,19 +1016,17 @@ int snd_hda_codec_device_new(struct hda_bus *bus, struct snd_card *card, if (codec->bus->modelname) { codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); - if (!codec->modelname) { - err = -ENOMEM; - goto error; - } + if (!codec->modelname) + return -ENOMEM; } fg = codec->core.afg ? codec->core.afg : codec->core.mfg; err = read_widget_caps(codec, fg); if (err < 0) - goto error; + return err; err = read_pin_defaults(codec); if (err < 0) - goto error; + return err; /* power-up all before initialization */ hda_set_power_state(codec, AC_PWRST_D0); @@ -1041,7 +1044,7 @@ int snd_hda_codec_device_new(struct hda_bus *bus, struct snd_card *card, /* ASoC features component management instead */ err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops); if (err < 0) - goto error; + return err; } #ifdef CONFIG_PM @@ -1054,10 +1057,6 @@ int snd_hda_codec_device_new(struct hda_bus *bus, struct snd_card *card, #endif return 0; - - error: - put_device(hda_codec_dev(codec)); - return err; } EXPORT_SYMBOL_GPL(snd_hda_codec_device_new); From patchwork Wed Jul 6 12:02:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cezary Rojewski X-Patchwork-Id: 587763 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 14053C433EF for ; Wed, 6 Jul 2022 11:54:53 +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 4EA0016F9; Wed, 6 Jul 2022 13:54:01 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 4EA0016F9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1657108491; bh=V/NEJiSKyl2dZbJEEGzCFIniY3CIOqOoa980IyjNtQc=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=mIkQJ0mIcjebbsSKjsiFzYIeUpnPB9vgxXVFZke7jUs2XP29pwFi7g8WSF0lticHa daaTXXiu1VZwCVhQmiTqMVCdFJQ0EhuxhNo9FKMiVU90nu1M+pSeAk61Lxwuc0nQqI KeL8HsTm+ZEktbwMWcBrJGHK+Gi6UK3P4mjqvbYo= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id D341EF80104; Wed, 6 Jul 2022 13:52:52 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3811CF80558; Wed, 6 Jul 2022 13:52:51 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 5B6A2F80104 for ; Wed, 6 Jul 2022 13:52:44 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 5B6A2F80104 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DaISjZa0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657108365; x=1688644365; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V/NEJiSKyl2dZbJEEGzCFIniY3CIOqOoa980IyjNtQc=; b=DaISjZa01sqoEMqUyeZpee+ka05Io4L2VP/HP3pww3OtKGs9Dzroa4fc a2QWNq/DO777OjOv4kq3B+PbX0Albp6cSHV6EoVKM/PNy4jgpmGTL1pkR vwKitA6u6BGNoR4RYinXsRK2wRR9pNYU1qpcrXoumimeRQjD3MxsfgDq3 uvOEFVnH+FzOjfONyqwOkNbfQj3eXfHaAwRPagbaDXZJlRZWOJwzNY8Xc xDtEPKZTf6TKM6pAyCKCTNjSag2qqJpSe2OvE8hdJxx2I3wVdrYEY0KHV KtdOuR37owu1uskLZOkqSQ5waBjEBZwSJaCwJnxmu7MqqB0r3ixhBXj5C A==; X-IronPort-AV: E=McAfee;i="6400,9594,10399"; a="370042630" X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="370042630" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2022 04:52:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="920136284" Received: from crojewsk-ctrl.igk.intel.com ([10.102.9.28]) by fmsmga005.fm.intel.com with ESMTP; 06 Jul 2022 04:52:41 -0700 From: Cezary Rojewski To: alsa-devel@alsa-project.org, tiwai@suse.com Subject: [PATCH 5/9] ALSA: hda: Skip event processing for unregistered codecs Date: Wed, 6 Jul 2022 14:02:26 +0200 Message-Id: <20220706120230.427296-6-cezary.rojewski@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220706120230.427296-1-cezary.rojewski@intel.com> References: <20220706120230.427296-1-cezary.rojewski@intel.com> MIME-Version: 1.0 Cc: Cezary Rojewski , pierre-louis.bossart@linux.intel.com, hdegoede@redhat.com, broonie@kernel.org, amadeuszx.slawinski@linux.intel.com 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" When codec is unbound but not yet removed, in the eyes of snd_hdac_bus_process_unsol_events() it is still a valid target to delegate work to. Such behaviour may lead to use-after-free errors. Address by verifying if codec is actually registered. Signed-off-by: Cezary Rojewski --- include/sound/hda_codec.h | 1 - include/sound/hdaudio.h | 1 + sound/hda/hdac_bus.c | 2 +- sound/pci/hda/hda_codec.c | 10 +++++----- sound/soc/codecs/hda.c | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/sound/hda_codec.h b/include/sound/hda_codec.h index b7be300b6b18..6d3c82c4b6ac 100644 --- a/include/sound/hda_codec.h +++ b/include/sound/hda_codec.h @@ -231,7 +231,6 @@ struct hda_codec { /* misc flags */ unsigned int configured:1; /* codec was configured */ unsigned int in_freeing:1; /* being released */ - unsigned int registered:1; /* codec was registered */ unsigned int display_power_control:1; /* needs display power */ unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each * status change diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h index 15f15075238d..797bf67a164d 100644 --- a/include/sound/hdaudio.h +++ b/include/sound/hdaudio.h @@ -93,6 +93,7 @@ struct hdac_device { bool lazy_cache:1; /* don't wake up for writes */ bool caps_overwriting:1; /* caps overwrite being in process */ bool cache_coef:1; /* cache COEF read/write too */ + unsigned int registered:1; /* codec was registered */ }; /* device/driver type used for matching */ diff --git a/sound/hda/hdac_bus.c b/sound/hda/hdac_bus.c index 71db8592b33d..d497414a5538 100644 --- a/sound/hda/hdac_bus.c +++ b/sound/hda/hdac_bus.c @@ -183,7 +183,7 @@ static void snd_hdac_bus_process_unsol_events(struct work_struct *work) if (!(caddr & (1 << 4))) /* no unsolicited event? */ continue; codec = bus->caddr_tbl[caddr & 0x0f]; - if (!codec || !codec->dev.driver) + if (!codec || !codec->registered) continue; spin_unlock_irq(&bus->reg_lock); drv = drv_to_hdac_driver(codec->dev.driver); diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 2381aced492f..75e85bf58681 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -772,11 +772,11 @@ static void codec_release_pcms(struct hda_codec *codec) */ void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) { - if (codec->registered) { + if (codec->core.registered) { /* pm_runtime_put() is called in snd_hdac_device_exit() */ pm_runtime_get_noresume(hda_codec_dev(codec)); pm_runtime_disable(hda_codec_dev(codec)); - codec->registered = 0; + codec->core.registered = 0; } snd_hda_codec_disconnect_pcms(codec); @@ -824,14 +824,14 @@ void snd_hda_codec_display_power(struct hda_codec *codec, bool enable) */ void snd_hda_codec_register(struct hda_codec *codec) { - if (codec->registered) + if (codec->core.registered) return; if (device_is_registered(hda_codec_dev(codec))) { snd_hda_codec_display_power(codec, true); pm_runtime_enable(hda_codec_dev(codec)); /* it was powered up in snd_hda_codec_new(), now all done */ snd_hda_power_down(codec); - codec->registered = 1; + codec->core.registered = 1; } } EXPORT_SYMBOL_GPL(snd_hda_codec_register); @@ -3047,7 +3047,7 @@ void snd_hda_codec_shutdown(struct hda_codec *codec) struct hda_pcm *cpcm; /* Skip the shutdown if codec is not registered */ - if (!codec->registered) + if (!codec->core.registered) return; cancel_delayed_work_sync(&codec->jackpoll_work); diff --git a/sound/soc/codecs/hda.c b/sound/soc/codecs/hda.c index edcb8bc6806b..ad20a3dff9b7 100644 --- a/sound/soc/codecs/hda.c +++ b/sound/soc/codecs/hda.c @@ -274,7 +274,7 @@ static void hda_codec_remove(struct snd_soc_component *component) struct hdac_device *hdev = &codec->core; struct hdac_bus *bus = hdev->bus; struct hdac_ext_link *hlink; - bool was_registered = codec->registered; + bool was_registered = codec->core.registered; /* Don't allow any more runtime suspends */ pm_runtime_forbid(&hdev->dev); @@ -376,7 +376,7 @@ static int hda_hdev_detach(struct hdac_device *hdev) { struct hda_codec *codec = dev_to_hda_codec(&hdev->dev); - if (codec->registered) + if (codec->core.registered) cancel_delayed_work_sync(&codec->jackpoll_work); snd_soc_unregister_component(&hdev->dev); From patchwork Wed Jul 6 12:02:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cezary Rojewski X-Patchwork-Id: 587762 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 20956C43334 for ; Wed, 6 Jul 2022 11:55:28 +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 6E87D1696; Wed, 6 Jul 2022 13:54:36 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6E87D1696 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1657108526; bh=SEjS9Eii0++oY3C8utx4IDlU6UrCPdIH13zix8eJYhE=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=iZjaZ6HbiZjR5+L1i6qPqDb6oD/KHHhv+rWC8+igAYVUHfelM+Phi+UGKqBAm5sR+ LXv1PTO3hOIy8vpFXAP2gTdK0dv6QVJtNGL5axcUEB1AHtLemrWxAgzX1YyU5Pyd0I HoWmYqc1J6BoxA01YIAj/+nxQKFhkI6KeNA9gTEs= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 37C2AF8055B; Wed, 6 Jul 2022 13:52:56 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 11A59F80552; Wed, 6 Jul 2022 13:52:52 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 033D9F80551 for ; Wed, 6 Jul 2022 13:52:46 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 033D9F80551 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Xim0cUxf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657108370; x=1688644370; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SEjS9Eii0++oY3C8utx4IDlU6UrCPdIH13zix8eJYhE=; b=Xim0cUxfMvnLjV0+a/C5Dl3/4rSq7v2fZwhFsTCLu/mM9yd+rzDSGWXY AuJGUaAzb8HPojgdbXGdtO9zBmCBgh8eyo/P4uh5HW1rXpZlGvAB6UbU1 qS1ZiA+5RQ7cTmNtWUDww3SfvJkjY7Mu8HpLmichF4iaXEOy0S0h1BU5y 0A1x7nYzUmX8ekDKHzmKYcrNLK7BpiTTzX/++CyYCqhFOqjzNeJ4EIsL9 9zB2nZIkIe4+6hp7VTUHKkHPIP1fWhWlaXZEmIIMKFLSG8Zny6igL6VW4 3BfDGw0qPA30EUuiRAK5b3pLlla/TetIWToCzpaGTUUdO3pNB1UxbQAzu g==; X-IronPort-AV: E=McAfee;i="6400,9594,10399"; a="370042645" X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="370042645" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2022 04:52:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="920136299" Received: from crojewsk-ctrl.igk.intel.com ([10.102.9.28]) by fmsmga005.fm.intel.com with ESMTP; 06 Jul 2022 04:52:43 -0700 From: Cezary Rojewski To: alsa-devel@alsa-project.org, tiwai@suse.com Subject: [PATCH 6/9] ALSA: hda: Fix page fault in snd_hda_codec_shutdown() Date: Wed, 6 Jul 2022 14:02:27 +0200 Message-Id: <20220706120230.427296-7-cezary.rojewski@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220706120230.427296-1-cezary.rojewski@intel.com> References: <20220706120230.427296-1-cezary.rojewski@intel.com> MIME-Version: 1.0 Cc: Cezary Rojewski , pierre-louis.bossart@linux.intel.com, hdegoede@redhat.com, broonie@kernel.org, amadeuszx.slawinski@linux.intel.com 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" If early probe of HDAudio bus driver fails e.g.: due to missing firmware file, snd_hda_codec_shutdown() ends in manipulating uninitialized codec->pcm_list_head causing page fault. Iinitialization of HDAudio codec in ASoC is split in two: - snd_hda_codec_device_init() - snd_hda_codec_device_new() snd_hda_codec_device_init() is called during probe_codecs() by HDAudio bus driver while snd_hda_codec_device_new() is called by codec-component's ->probe(). The second call will not happen until all components required by related sound card are present within the ASoC framework. With firmware failing to load during the PCI's deferred initialization i.e.: probe_work(), no platform components are ever registered. HDAudio codec enumeration is done at that point though, so the codec components became registered to ASoC framework, calling snd_hda_codec_device_init() in the process. Now, during platform reboot snd_hda_codec_shutdown() is called for every codec found on the HDAudio bus causing oops if any of them has not completed both of their initialization steps. Relocating field initialization fixes the issue. Signed-off-by: Cezary Rojewski --- sound/pci/hda/hda_codec.c | 41 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 75e85bf58681..677d0a78f19c 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -930,8 +930,28 @@ snd_hda_codec_device_init(struct hda_bus *bus, unsigned int codec_addr, } codec->bus = bus; + codec->depop_delay = -1; + codec->fixup_id = HDA_FIXUP_ID_NOT_SET; + codec->core.dev.release = snd_hda_codec_dev_release; + codec->core.exec_verb = codec_exec_verb; codec->core.type = HDA_DEV_LEGACY; + mutex_init(&codec->spdif_mutex); + mutex_init(&codec->control_mutex); + snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); + snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); + snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); + snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); + snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); + snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16); + snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16); + snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8); + INIT_LIST_HEAD(&codec->conn_list); + INIT_LIST_HEAD(&codec->pcm_list_head); + INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); + refcount_set(&codec->pcm_ref, 1); + init_waitqueue_head(&codec->remove_sleep); + return codec; } EXPORT_SYMBOL_GPL(snd_hda_codec_device_init); @@ -984,29 +1004,8 @@ int snd_hda_codec_device_new(struct hda_bus *bus, struct snd_card *card, if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS)) return -EINVAL; - codec->core.dev.release = snd_hda_codec_dev_release; - codec->core.exec_verb = codec_exec_verb; - codec->card = card; codec->addr = codec_addr; - mutex_init(&codec->spdif_mutex); - mutex_init(&codec->control_mutex); - snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32); - snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32); - snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16); - snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16); - snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8); - snd_array_init(&codec->spdif_out, sizeof(struct hda_spdif_out), 16); - snd_array_init(&codec->jacktbl, sizeof(struct hda_jack_tbl), 16); - snd_array_init(&codec->verbs, sizeof(struct hda_verb *), 8); - INIT_LIST_HEAD(&codec->conn_list); - INIT_LIST_HEAD(&codec->pcm_list_head); - refcount_set(&codec->pcm_ref, 1); - init_waitqueue_head(&codec->remove_sleep); - - INIT_DELAYED_WORK(&codec->jackpoll_work, hda_jackpoll_work); - codec->depop_delay = -1; - codec->fixup_id = HDA_FIXUP_ID_NOT_SET; #ifdef CONFIG_PM codec->power_jiffies = jiffies;