From patchwork Tue Oct 6 11:30:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Vehmanen X-Patchwork-Id: 291430 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24955C4363D for ; Tue, 6 Oct 2020 11:35:18 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id CF9642083B for ; Tue, 6 Oct 2020 11:35:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="mG/O4O4f" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CF9642083B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 3DD921751; Tue, 6 Oct 2020 13:34:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3DD921751 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1601984115; bh=ariFATIN/9mYSNH7qfw4o4ImbBwnPprJgxa/2183rHU=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=mG/O4O4f25+rdXbOQZEONri1B41YdtuR+5mY283/tkoAeai7xfrVdZ18km0bMf+36 c+jit0N5W8jjjca6B3Ut41F1YSE9hULefHYJ5g8y6nCS88ar0D5bxxxHDCz6x+/a7l +FjBdVRKAV2GLeIq9jXtzlbiDimGtA75xrMnbZJk= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 967D7F80128; Tue, 6 Oct 2020 13:32:52 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 8FADFF80163; Tue, 6 Oct 2020 13:32:49 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 D755CF80129 for ; Tue, 6 Oct 2020 13:32:42 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D755CF80129 IronPort-SDR: 1UoDp1Cwq0eQKMV/5cUbjDi9Q/Vw8etdCDlByaDeVXEMgy5P+PgxHCQZGAsAqofg0P5i9CXu3H HY/EXPZxsp5g== X-IronPort-AV: E=McAfee;i="6000,8403,9765"; a="163682591" X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="163682591" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 04:32:28 -0700 IronPort-SDR: v+0l1sB+6qIY7jurQz62JxRZzbHLLSqNxFBVP7P0MXMBi5tCJhEfLQgkwDUmULUL9O3nbaEQBs t071LAYuqkJA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="460759609" Received: from eliteleevi.tm.intel.com ([10.237.54.20]) by orsmga004.jf.intel.com with ESMTP; 06 Oct 2020 04:32:27 -0700 From: Kai Vehmanen To: alsa-devel@alsa-project.org, tiwai@suse.de Subject: [RFC PATCH 1/2] ALSA: hda - keep track of HDA core bus instance in acomp Date: Tue, 6 Oct 2020 14:30:41 +0300 Message-Id: <20201006113042.471718-2-kai.vehmanen@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201006113042.471718-1-kai.vehmanen@linux.intel.com> References: <20201006113042.471718-1-kai.vehmanen@linux.intel.com> MIME-Version: 1.0 Cc: Kai Vehmanen 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" In current HDA component implementation, HDA controller drivers use snd_hdac_acomp_init() and pass it the HDA bus instance (hdac_bus). When registration to component framework is done, the HDA controller device instance 'hdac_bus->dev' is used. In the component bind/unbind callbacks, only the device handle is passed as context, and it is not possible to look up the HDA bus instance. Fix this gap by adding a separate devres entry for the bus handle. Signed-off-by: Kai Vehmanen --- include/sound/hda_component.h | 5 +++++ sound/hda/hdac_component.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/sound/hda_component.h b/include/sound/hda_component.h index d4804c72d959..476cc4e2083c 100644 --- a/include/sound/hda_component.h +++ b/include/sound/hda_component.h @@ -25,6 +25,7 @@ int snd_hdac_acomp_init(struct hdac_bus *bus, int snd_hdac_acomp_exit(struct hdac_bus *bus); int snd_hdac_acomp_register_notifier(struct hdac_bus *bus, const struct drm_audio_component_audio_ops *ops); +struct hdac_bus *snd_hdac_acomp_get_bus(struct device *dev); #else static inline int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable) { @@ -62,6 +63,10 @@ static inline int snd_hdac_acomp_register_notifier(struct hdac_bus *bus, { return -ENODEV; } +static struct hdac_bus *snd_hdac_acomp_get_bus(struct device *dev) +{ + return NULL; +} #endif #endif /* __SOUND_HDA_COMPONENT_H */ diff --git a/sound/hda/hdac_component.c b/sound/hda/hdac_component.c index 89126c6fd216..d9d2675982f0 100644 --- a/sound/hda/hdac_component.c +++ b/sound/hda/hdac_component.c @@ -19,6 +19,29 @@ static struct drm_audio_component *hdac_get_acomp(struct device *dev) return devres_find(dev, hdac_acomp_release, NULL, NULL); } +static void hdac_acomp_bus_release(struct device *dev, void *res) +{ +} + +/** + * snd_hdac_acomp_get_bus - Get HDA core bus instance + * @dev: device + * + * If audio component registration has been done, this function + * will return the matching HDA core bus. Returns NULL otherwise. + */ +struct hdac_bus *snd_hdac_acomp_get_bus(struct device *dev) +{ + struct drm_audio_component *acomp = hdac_get_acomp(dev); + struct hdac_bus **bus = + devres_find(dev, hdac_acomp_bus_release, NULL, NULL); + if (!acomp || !*bus) + return NULL; + + return *bus; +} +EXPORT_SYMBOL_GPL(snd_hdac_acomp_get_bus); + /** * snd_hdac_set_codec_wakeup - Enable / disable HDMI/DP codec wakeup * @bus: HDA core bus @@ -286,6 +309,7 @@ int snd_hdac_acomp_init(struct hdac_bus *bus, struct component_match *match = NULL; struct device *dev = bus->dev; struct drm_audio_component *acomp; + struct hdac_bus **bus_ptr; int ret; if (WARN_ON(hdac_get_acomp(dev))) @@ -299,6 +323,14 @@ int snd_hdac_acomp_init(struct hdac_bus *bus, bus->audio_component = acomp; devres_add(dev, acomp); + bus_ptr = devres_alloc(hdac_acomp_bus_release, sizeof(*bus_ptr), GFP_KERNEL); + if (!bus_ptr) { + ret = -ENOMEM; + goto out_err_busptr; + } + *bus_ptr = bus; + devres_add(dev, bus_ptr); + component_match_add_typed(dev, &match, match_master, bus); ret = component_master_add_with_match(dev, &hdac_component_master_ops, match); @@ -308,6 +340,8 @@ int snd_hdac_acomp_init(struct hdac_bus *bus, return 0; out_err: + devres_destroy(dev, hdac_acomp_bus_release, NULL, NULL); +out_err_busptr: bus->audio_component = NULL; devres_destroy(dev, hdac_acomp_release, NULL, NULL); dev_info(dev, "failed to add audio component master (%d)\n", ret); From patchwork Tue Oct 6 11:30:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Vehmanen X-Patchwork-Id: 284645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09DBBC4363D for ; Tue, 6 Oct 2020 11:34:33 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id EF051207EA for ; Tue, 6 Oct 2020 11:34:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="anjkdMmP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF051207EA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org 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 045311764; Tue, 6 Oct 2020 13:33:40 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 045311764 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1601984070; bh=6fY0AL8El51jR8+7VKbaRWNL56TXVZB6GvVDJkPsnQM=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=anjkdMmPX3WHi0CyzRAqx0IhYq4M/Zie73TfAteyx9yGkb+H0r9iCofUEgaIws8mY V42cZ7C05SwTDVKKt1riKVR6h5fp59z3UgjO+BEfjKDpKhjPYsTQ0RlT62rqHWoXw/ PtbvJLn9vTmcshzfq/n5E993VlcQBK1yZSur4tlE= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 6CCEEF80129; Tue, 6 Oct 2020 13:32:51 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id B0032F8012B; Tue, 6 Oct 2020 13:32:47 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 C214FF80053 for ; Tue, 6 Oct 2020 13:32:44 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz C214FF80053 IronPort-SDR: M7ckcz4d5PBGGGJa0WtIW5QVSQ+iO3g0eXPeXyEeOtqMMm/GiUjKd0bHyPA5xPEocPaPWvH16p MquyuYojdZog== X-IronPort-AV: E=McAfee;i="6000,8403,9765"; a="163682601" X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="163682601" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 04:32:30 -0700 IronPort-SDR: rTEJ2ByDI1oBACzvtRc7Qs8XmRM9lzWtI2kZBHnyLi5xjIegFL7DjydImp49YeJV2Q+u275Koy MBYU0CJ4NADQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="460759629" Received: from eliteleevi.tm.intel.com ([10.237.54.20]) by orsmga004.jf.intel.com with ESMTP; 06 Oct 2020 04:32:29 -0700 From: Kai Vehmanen To: alsa-devel@alsa-project.org, tiwai@suse.de Subject: [RFC PATCH 2/2] ALSA: hda/i915 - fix list corruption with concurrent probes Date: Tue, 6 Oct 2020 14:30:42 +0300 Message-Id: <20201006113042.471718-3-kai.vehmanen@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201006113042.471718-1-kai.vehmanen@linux.intel.com> References: <20201006113042.471718-1-kai.vehmanen@linux.intel.com> MIME-Version: 1.0 Cc: Kai Vehmanen 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" Current hdac_i915 uses a static completion instance to synchronous communication with i915 driver. This design is not safe if multiple HDA controllers are active and talking to different i915 instances, and can lead to list corruption and failed audio driver probe. Fix the design by storing the completion object to hdac_bus, and signaling completions on a per-bus basis. Signed-off-by: Kai Vehmanen --- include/sound/hdaudio.h | 2 ++ sound/hda/hdac_i915.c | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h index 6eed61e6cf8a..116c89074d79 100644 --- a/include/sound/hdaudio.h +++ b/include/sound/hdaudio.h @@ -6,6 +6,7 @@ #ifndef __SOUND_HDAUDIO_H #define __SOUND_HDAUDIO_H +#include #include #include #include @@ -359,6 +360,7 @@ struct hdac_bus { struct drm_audio_component *audio_component; long display_power_status; unsigned long display_power_active; + struct completion display_bind_complete; /* parameters required for enhanced capabilities */ int num_streams; diff --git a/sound/hda/hdac_i915.c b/sound/hda/hdac_i915.c index 5f0a1aa6ad84..fee3d379d7e0 100644 --- a/sound/hda/hdac_i915.c +++ b/sound/hda/hdac_i915.c @@ -11,8 +11,6 @@ #include #include -static struct completion bind_complete; - #define IS_HSW_CONTROLLER(pci) (((pci)->device == 0x0a0c) || \ ((pci)->device == 0x0c0c) || \ ((pci)->device == 0x0d0c) || \ @@ -133,9 +131,14 @@ static bool i915_gfx_present(void) static int i915_master_bind(struct device *dev, struct drm_audio_component *acomp) { - complete_all(&bind_complete); + struct hdac_bus *bus = snd_hdac_acomp_get_bus(dev); + + if (!bus) + return -EINVAL; + complete_all(&bus->display_bind_complete); /* clear audio_ops here as it was needed only for completion call */ acomp->audio_ops = NULL; + return 0; } @@ -163,8 +166,7 @@ int snd_hdac_i915_init(struct hdac_bus *bus) if (!i915_gfx_present()) return -ENODEV; - init_completion(&bind_complete); - + init_completion(&bus->display_bind_complete); err = snd_hdac_acomp_init(bus, &i915_init_ops, i915_component_master_match, sizeof(struct i915_audio_component) - sizeof(*acomp)); @@ -177,8 +179,8 @@ int snd_hdac_i915_init(struct hdac_bus *bus) if (!IS_ENABLED(CONFIG_MODULES) || !request_module("i915")) { /* 60s timeout */ - wait_for_completion_timeout(&bind_complete, - msecs_to_jiffies(60 * 1000)); + wait_for_completion_timeout(&bus->display_bind_complete, + msecs_to_jiffies(60 * 1000)); } } if (!acomp->ops) {