All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kai Vehmanen <kai.vehmanen@linux.intel.com>
To: alsa-devel@alsa-project.org, tiwai@suse.de
Cc: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Subject: [RFC PATCH 2/2] ALSA: hda/i915 - fix list corruption with concurrent probes
Date: Tue,  6 Oct 2020 14:30:42 +0300	[thread overview]
Message-ID: <20201006113042.471718-3-kai.vehmanen@linux.intel.com> (raw)
In-Reply-To: <20201006113042.471718-1-kai.vehmanen@linux.intel.com>

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 <kai.vehmanen@linux.intel.com>
---
 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 <linux/completion.h>
 #include <linux/device.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
@@ -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 <sound/hda_i915.h>
 #include <sound/hda_register.h>
 
-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) {
-- 
2.28.0


  parent reply	other threads:[~2020-10-06 11:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-06 11:30 [RFC PATCH 0/2] ALSA: hda - acomp probe fix for i915 Kai Vehmanen
2020-10-06 11:30 ` [RFC PATCH 1/2] ALSA: hda - keep track of HDA core bus instance in acomp Kai Vehmanen
2020-10-06 11:30 ` Kai Vehmanen [this message]
2020-10-06 12:13 ` [RFC PATCH 0/2] ALSA: hda - acomp probe fix for i915 Takashi Iwai
2020-10-06 12:45   ` Takashi Iwai
2020-10-06 14:16     ` Kai Vehmanen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201006113042.471718-3-kai.vehmanen@linux.intel.com \
    --to=kai.vehmanen@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.