Skip to contentSkip to conversation

ALSA: hda - Fix race between PM ops and HDA init/probe

PATCH In review U. Artie Eoff 2 participants 4 messages Jul 28, 2015 – Jul 29, 2015 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: hda - Fix race between PM ops and HDA init/probe

PM ops could be triggered before HDA is done initializing and cause PM to set HDA controller to D3Hot. This can result in "CORB reset timeout#2, CORBRP = 65535" and "no codecs initialized". Additionally, PM ops can be triggered before azx_probe_continue finishes (async probe). This can result in a NULL deref kernel crash.

To fix this, avoid PM ops if !chip->running.

---
 sound/pci/hda/hda_intel.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sound/pci/hda/hda_intel.c +3 -3
index 735bdcb04ce8..c38c68f57938 100644
@@ -867,7 +867,7 @@ static int azx_suspend(struct device *dev)
 
 	chip = card->private_data;
 	hda = container_of(chip, struct hda_intel, chip);
-	if (chip->disabled || hda->init_failed)
+	if (chip->disabled || hda->init_failed || !chip->running)
 		return 0;
 
 	bus = azx_bus(chip);
@@ -902,7 +902,7 @@ static int azx_resume(struct device *dev)
 
 	chip = card->private_data;
 	hda = container_of(chip, struct hda_intel, chip);
-	if (chip->disabled || hda->init_failed)
+	if (chip->disabled || hda->init_failed || !chip->running)
 		return 0;
 
 	if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL
@@ -1027,7 +1027,7 @@ static int azx_runtime_idle(struct device *dev)
 		return 0;
 
 	if (!power_save_controller || !azx_has_pm_runtime(chip) ||
-	    azx_bus(chip)->codec_powered)
+	    azx_bus(chip)->codec_powered || !chip->running)
 		return -EBUSY;
 
 	return 0;
Signature · 1 line
2.1.0
#1 lore raw
Quoted 20 lines · U. Artie Eoff

PM ops could be triggered before HDA is done initializing and cause PM to set HDA controller to D3Hot. This can result in "CORB reset timeout#2, CORBRP = 65535" and "no codecs initialized". Additionally, PM ops can be triggered before azx_probe_continue finishes (async probe). This can result in a NULL deref kernel crash.

To fix this, avoid PM ops if !chip->running.

---
 sound/pci/hda/hda_intel.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sound/pci/hda/hda_intel.c +0 -0
index 735bdcb04ce8..c38c68f57938 100644

sound/pci/hda/hda_intel.c static int azx_suspend(struct device *dev) · line 870

Quoted 5 lines
sound/pci/hda/hda_intel.c +1 -1
@@ -867,7 +867,7 @@ static int azx_suspend(struct device *dev)
 
 	chip = card->private_data;
 	hda = container_of(chip, struct hda_intel, chip);
-	if (chip->disabled || hda->init_failed)
+	if (chip->disabled || hda->init_failed || !chip->running)

This is superfluous, as azx_runtime_idle() returns -EBUSY.

sound/pci/hda/hda_intel.c static int azx_resume(struct device *dev) · line 905

Quoted 9 lines
sound/pci/hda/hda_intel.c +1 -1
 		return 0;
 
 	bus = azx_bus(chip);
@@ -902,7 +902,7 @@ static int azx_resume(struct device *dev)
 
 	chip = card->private_data;
 	hda = container_of(chip, struct hda_intel, chip);
-	if (chip->disabled || hda->init_failed)
+	if (chip->disabled || hda->init_failed || !chip->running)

Ditto.

Takashi

Quoted 15 lines
sound/pci/hda/hda_intel.c +1 -1
 		return 0;
 
 	if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL
@@ -1027,7 +1027,7 @@ static int azx_runtime_idle(struct device *dev)
 		return 0;
 
 	if (!power_save_controller || !azx_has_pm_runtime(chip) ||
-	    azx_bus(chip)->codec_powered)
+	    azx_bus(chip)->codec_powered || !chip->running)
 		return -EBUSY;
 
 	return 0;
Signature · 1 line
2.1.0
#2 lore raw
Quoted 30 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Wednesday, July 29, 2015 12:03 AM
To: Eoff, Ullysses A
Cc: [email protected]; Lee, Zhuo-hao; Yang, Libin; [email protected]
Subject: Re: [PATCH] ALSA: hda - Fix race between PM ops and HDA init/probe

Quoted 21 lines · U. Artie Eoff

PM ops could be triggered before HDA is done initializing and cause PM to set HDA controller to D3Hot. This can result in "CORB reset timeout#2, CORBRP = 65535" and "no codecs initialized". Additionally, PM ops can be triggered before azx_probe_continue finishes (async probe). This can result in a NULL deref kernel crash.

To fix this, avoid PM ops if !chip->running.

---
 sound/pci/hda/hda_intel.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sound/pci/hda/hda_intel.c +0 -0
index 735bdcb04ce8..c38c68f57938 100644
@@ -867,7 +867,7 @@ static int azx_suspend(struct device *dev)
 
Quoted 7 lines

sound/pci/hda/hda_intel.c static int azx_suspend(struct device *dev) · line 870

Quoted 4 lines
sound/pci/hda/hda_intel.c +1 -1
 	chip = card->private_data;
 	hda = container_of(chip, struct hda_intel, chip);
-	if (chip->disabled || hda->init_failed)
+	if (chip->disabled || hda->init_failed || !chip->running)

This is superfluous, as azx_runtime_idle() returns -EBUSY.

This is the sleep suspend, not runtime. Runtime idle result does not influence sleep pm ops.

Quoted 5 lines
Quoted 5 lines
sound/pci/hda/hda_intel.c +0 -0
 		return 0;
 
 	bus = azx_bus(chip);
@@ -902,7 +902,7 @@ static int azx_resume(struct device *dev)
 
Quoted 7 lines

sound/pci/hda/hda_intel.c static int azx_suspend(struct device *dev) · line 870

Quoted 4 lines
sound/pci/hda/hda_intel.c +1 -1
 	chip = card->private_data;
 	hda = container_of(chip, struct hda_intel, chip);
-	if (chip->disabled || hda->init_failed)
+	if (chip->disabled || hda->init_failed || !chip->running)

Ditto.

Similar here... not runtime.

Quoted 18 lines

Takashi

Quoted 15 lines
sound/pci/hda/hda_intel.c +1 -2
 		return 0;
 
 	if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL
@@ -1027,7 +1027,7 @@ static int azx_runtime_idle(struct device *dev)
 		return 0;
 
 	if (!power_save_controller || !azx_has_pm_runtime(chip) ||
-	    azx_bus(chip)->codec_powered)
+	    azx_bus(chip)->codec_powered || !chip->running)
 		return -EBUSY;
 
 	return 0;
--

2.1.0

#3 lore raw
Quoted 39 lines · Ullysses A
Quoted 31 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Wednesday, July 29, 2015 12:03 AM
To: Eoff, Ullysses A
Cc: [email protected]; Lee, Zhuo-hao; Yang, Libin; [email protected]
Subject: Re: [PATCH] ALSA: hda - Fix race between PM ops and HDA init/probe

Quoted 21 lines · U. Artie Eoff

PM ops could be triggered before HDA is done initializing and cause PM to set HDA controller to D3Hot. This can result in "CORB reset timeout#2, CORBRP = 65535" and "no codecs initialized". Additionally, PM ops can be triggered before azx_probe_continue finishes (async probe). This can result in a NULL deref kernel crash.

To fix this, avoid PM ops if !chip->running.

---
 sound/pci/hda/hda_intel.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sound/pci/hda/hda_intel.c +0 -0
index 735bdcb04ce8..c38c68f57938 100644
@@ -867,7 +867,7 @@ static int azx_suspend(struct device *dev)
 
Quoted 7 lines

sound/pci/hda/hda_intel.c static int azx_suspend(struct device *dev) · line 870

Quoted 4 lines
sound/pci/hda/hda_intel.c +1 -1
 	chip = card->private_data;
 	hda = container_of(chip, struct hda_intel, chip);
-	if (chip->disabled || hda->init_failed)
+	if (chip->disabled || hda->init_failed || !chip->running)

This is superfluous, as azx_runtime_idle() returns -EBUSY.

Quoted 2 lines

This is the sleep suspend, not runtime. Runtime idle result does not influence sleep pm ops.

Fair enough, I applied the patch now.

thanks,

Takashi

Quoted 35 lines
Quoted 6 lines
Quoted 6 lines
sound/pci/hda/hda_intel.c +0 -0
 		return 0;
 
 	bus = azx_bus(chip);
@@ -902,7 +902,7 @@ static int azx_resume(struct device *dev)
 
Quoted 7 lines

sound/pci/hda/hda_intel.c static int azx_suspend(struct device *dev) · line 870

Quoted 4 lines
sound/pci/hda/hda_intel.c +1 -1
 	chip = card->private_data;
 	hda = container_of(chip, struct hda_intel, chip);
-	if (chip->disabled || hda->init_failed)
+	if (chip->disabled || hda->init_failed || !chip->running)

Ditto.

Similar here... not runtime.

Quoted 18 lines

Takashi

Quoted 15 lines
sound/pci/hda/hda_intel.c +1 -2
 		return 0;
 
 	if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL
@@ -1027,7 +1027,7 @@ static int azx_runtime_idle(struct device *dev)
 		return 0;
 
 	if (!power_save_controller || !azx_has_pm_runtime(chip) ||
-	    azx_bus(chip)->codec_powered)
+	    azx_bus(chip)->codec_powered || !chip->running)
 		return -EBUSY;
 
 	return 0;
--

2.1.0