Skip to contentSkip to conversation

ALSA: hda: intel: Release i915 component when delayed probe fails

PATCH Superseded Kai Vehmanen 3 participants 3 messages Nov 19 Sound

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: hda: intel: Release i915 component when delayed probe fails

Commit fbaccb1b19c7 ("ALSA: hda: intel: Don't free card in the probe work") stopped freeing the card from azx_probe_work() when the delayed probe fails, and only disconnects it, leaving the free to azx_remove(). This avoids the double free, but the resources that were released by the card free via azx_free() are now kept until the PCI device is unbound. In particular the display power reference and the audio component binding to the graphics driver stay held for a controller that will never become operational. This blocks unloading of the i915 driver, which breaks display driver reload.

Release the display power and the i915 audio component in the probe work error path. Both snd_hdac_display_power() and snd_hdac_acomp_exit() are safe to repeat, so the later azx_free() call from azx_remove() is not affected. azx_free() can't be called directly here as it would run before the codec instances are released by the card free.

Fixes fbaccb1b19c7 ("ALSA: hda: intel: Don't free card in the probe work")
---
 sound/hda/controllers/intel.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
sound/hda/controllers/intel.c +13 -1
index 0a62723b3454..73ff42faccb7 100644
@@ -1740,9 +1740,21 @@ static void azx_probe_work(struct work_struct *work)
 	struct hda_intel *hda = container_of(work, struct hda_intel, probe_work.work);
 
 	if (azx_probe_continue(&hda->chip, false) < 0) {
+		struct azx *chip = &hda->chip;
+
 		hda->init_failed = 1;
 		complete_all(&hda->probe_wait);
-		snd_card_disconnect(hda->chip.card);
+		snd_card_disconnect(chip->card);
+
+		/*
+		 * The card itself is left to azx_remove() to free, but the
+		 * graphics driver must not be kept bound to a controller that
+		 * will never become operational; this would e.g. block
+		 * unloading i915. Both calls are safe to repeat from azx_free().
+		 */
+		display_power(chip, false);
+		if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT)
+			snd_hdac_i915_exit(azx_bus(chip));
 	}
 }
 

base-commit: ec925d3740159f4b4bd3b7640be5d0d2b4664106

Signature · 1 line
2.43.0
#1 lore raw
Quoted 16 lines · Kai Vehmanen

Commit fbaccb1b19c7 ("ALSA: hda: intel: Don't free card in the probe work") stopped freeing the card from azx_probe_work() when the delayed probe fails, and only disconnects it, leaving the free to azx_remove(). This avoids the double free, but the resources that were released by the card free via azx_free() are now kept until the PCI device is unbound. In particular the display power reference and the audio component binding to the graphics driver stay held for a controller that will never become operational. This blocks unloading of the i915 driver, which breaks display driver reload.

Release the display power and the i915 audio component in the probe work error path. Both snd_hdac_display_power() and snd_hdac_acomp_exit() are safe to repeat, so the later azx_free() call from azx_remove() is not affected. azx_free() can't be called directly here as it would run before the codec instances are released by the card free.

Quoted 4 lines
Fixes fbaccb1b19c7 ("ALSA: hda: intel: Don't free card in the probe work")

nitpick: s/Tested-by-by:/Tested-by:/

:)

BR,
Michał

Quoted 38 lines
---
 sound/hda/controllers/intel.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
sound/hda/controllers/intel.c +13 -1
index 0a62723b3454..73ff42faccb7 100644
@@ -1740,9 +1740,21 @@ static void azx_probe_work(struct work_struct *work)
 	struct hda_intel *hda = container_of(work, struct hda_intel, probe_work.work);
 
 	if (azx_probe_continue(&hda->chip, false) < 0) {
+		struct azx *chip = &hda->chip;
+
 		hda->init_failed = 1;
 		complete_all(&hda->probe_wait);
-		snd_card_disconnect(hda->chip.card);
+		snd_card_disconnect(chip->card);
+
+		/*
+		 * The card itself is left to azx_remove() to free, but the
+		 * graphics driver must not be kept bound to a controller that
+		 * will never become operational; this would e.g. block
+		 * unloading i915. Both calls are safe to repeat from azx_free().
+		 */
+		display_power(chip, false);
+		if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT)
+			snd_hdac_i915_exit(azx_bus(chip));
 	}
 }
 

base-commit: ec925d3740159f4b4bd3b7640be5d0d2b4664106

Signature · 1 line
2.43.0
#2 lore raw
In reply to Kai Vehmanen
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] ALSA: hda: intel: azx_probe_work() drops display power before stopping chip - [Medium] ALSA: hda…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] ALSA: hda: intel: azx_probe_work() drops display power before stopping chip
- [Medium] ALSA: hda: intel: azx_probe_work() exits i915 while codecs remain registered
--

commit 8668fbf5bb132662ae06081f1c3f17768cfd79c9
Author: Kai Vehmanen <[email protected]>

ALSA: hda: intel: Release i915 component when delayed probe fails

This commit releases display power and exits the i915 audio component in azx_probe_work() when azx_probe_continue() fails, so the graphics driver is not kept bound until azx_remove() frees the card.

Quoted 14 lines
sound/hda/controllers/intel.c +3 -1
index 0a62723b34549..73ff42faccb77 100644
@@ -1740,9 +1740,21 @@ static void azx_probe_work(struct work_struct *work)
 	struct hda_intel *hda = container_of(work, struct hda_intel, probe_work.work);
 
 	if (azx_probe_continue(&hda->chip, false) < 0) {
+		struct azx *chip = &hda->chip;
+
 		hda->init_failed = 1;
 		complete_all(&hda->probe_wait);
-		snd_card_disconnect(hda->chip.card);
+		snd_card_disconnect(chip->card);

sound/hda/controllers/intel.c static void azx_probe_work(struct work_struct *work) · line 1757

Quoted 10 lines
sound/hda/controllers/intel.c +10 -0
+
+		/*
+		 * The card itself is left to azx_remove() to free, but the
+		 * graphics driver must not be kept bound to a controller that
+		 * will never become operational; this would e.g. block
+		 * unloading i915. Both calls are safe to repeat from azx_free().
+		 */
+		display_power(chip, false);
+		if (chip->driver_caps & AZX_DCAPS_I915_COMPONENT)
+			snd_hdac_i915_exit(azx_bus(chip));

[Severity: Medium]
Should the controller be stopped before dropping display power and exiting the i915 component?

When azx_probe_continue() fails after azx_first_init() (for example in azx_probe_codecs() or azx_codec_configure()), hda_intel_init_chip() has already started CORB/RIRB DMA, enabled controller interrupts, and set bus->chip_init = true. Unlike __azx_shutdown_chip() and azx_free(), this path releases display power while the controller is still running.

On platforms where the HDA controller sits in the GPU display power domain (hda->need_i915_power), powering down the domain with DMA active leaves bus->chip_init set, so when azx_remove() later runs azx_free(), it accesses and polls controller MMIO registers after display power and the i915 component have already been released:

sound/hda/controllers/intel.c:azx_free() {
	...
	if (bus->chip_init) {
		azx_clear_irq_pending(chip);
		azx_stop_all_streams(chip);
		azx_stop_chip(chip);
	}
	...
}

[Severity: Medium]
Can exiting the i915 component here trigger WARN_ON(bus->display_power_active) or leave codec devices registered on the bus without an audio component?

snd_card_disconnect() does not unregister or free SNDRV_DEV_CODEC devices. If azx_probe_continue() fails in snd_hda_card_register() after snd_hda_codec_register() has enabled per-codec display power via snd_hda_codec_display_power(codec, true), display_power(chip, false) only clears HDA_CODEC_IDX_CONTROLLER in bus->display_power_status. The codec's bit remains set until snd_card_free() runs in azx_remove(), so snd_hdac_i915_exit() -> snd_hdac_acomp_exit() hits WARN_ON(bus->display_power_active).

In addition, when azx_codec_configure() fails for all codecs (success == 0), codec->core.dev stays registered on snd_hda_bus_type and in sysfs after bus->audio_component is torn down, allowing late codec driver binding or sysfs reconfig_codec() to run against a controller with no display power or audio component.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1