Skip to contentSkip to conversation

ALSA: hda - Fix race condition between HDA driver and runtime PM

PATCH In review U. Artie Eoff 2 participants 6 messages Jul 28, 2015 Sound

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ALSA: hda - Fix race condition between HDA driver and runtime PM

Don't execute runtime suspend if HDA is not finished initializing. Otherwise, the following errors can occur in hda:

snd_hda_intel 0000:00:1b.0: CORB reset timeout#2, CORBRP = 65535 snd_hda_intel 0000:00:1b.0: no codecs initialized

Debugged and root-cause found by [email protected]

v2: remove unnecessary extra check for chip init (libin)

---
 sound/pci/hda/hda_intel.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
sound/pci/hda/hda_intel.c +3 -1
index b729b25a6ad6..15d4e28fc64e 100644
@@ -1017,17 +1017,19 @@ static int azx_runtime_idle(struct device *dev)
 	struct snd_card *card = dev_get_drvdata(dev);
 	struct azx *chip;
 	struct hda_intel *hda;
+	struct hdac_bus *bus;
 
 	if (!card)
 		return 0;
 
 	chip = card->private_data;
 	hda = container_of(chip, struct hda_intel, chip);
+	bus = azx_bus(chip);
 	if (chip->disabled || hda->init_failed || !chip->running)
 		return 0;
 
 	if (!power_save_controller || !azx_has_pm_runtime(chip) ||
-	    azx_bus(chip)->codec_powered)
+	    bus->codec_powered || !bus->chip_init)
 		return -EBUSY;
 
 	return 0;
Signature · 1 line
1.9.3
#1 lore raw

Hi Ullysses,

Quoted 31 lines

-----Original Message-----
From: Eoff, Ullysses A
Sent: Tuesday, July 28, 2015 12:20 PM
To: [email protected]; [email protected]
Cc: Lee, Zhuo-hao; Yang, Libin; Eoff, Ullysses A
Subject: [PATCH v2] ALSA: hda - Fix race condition between HDA driver and runtime PM

Don't execute runtime suspend if HDA is not finished initializing. Otherwise, the following errors can occur in hda:

snd_hda_intel 0000:00:1b.0: CORB reset timeout#2, CORBRP = 65535 snd_hda_intel 0000:00:1b.0: no codecs initialized

Debugged and root-cause found by [email protected]

v2: remove unnecessary extra check for chip init (libin)

---
 sound/pci/hda/hda_intel.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
sound/pci/hda/hda_intel.c +0 -0
index b729b25a6ad6..15d4e28fc64e 100644
@@ -1017,17 +1017,19 @@ static int azx_runtime_idle(struct device
 *dev)
 	struct snd_card *card = dev_get_drvdata(dev);
 	struct azx *chip;

sound/pci/hda/hda_intel.c static int azx_runtime_idle(struct device · line 1029

Quoted 10 lines
sound/pci/hda/hda_intel.c +2 -0
 	struct hda_intel *hda;
+	struct hdac_bus *bus;
 
 	if (!card)
 		return 0;
 
 	chip = card->private_data;
 	hda = container_of(chip, struct hda_intel, chip);
+	bus = azx_bus(chip);
 	if (chip->disabled || hda->init_failed || !chip->running)

I mean we don't need '!chip->running' either. Otherwise, initialization may be interrupted.

Quoted 10 lines
sound/pci/hda/hda_intel.c +1 -1
 		return 0;
 
 	if (!power_save_controller || !azx_has_pm_runtime(chip) ||
-	    azx_bus(chip)->codec_powered)
+	    bus->codec_powered || !bus->chip_init)
 		return -EBUSY;
 

return 0;
--
1.9.3

#2 lore raw
Quoted 48 lines

-----Original Message-----
From: Yang, Libin
Sent: Monday, July 27, 2015 10:20 PM
To: Eoff, Ullysses A; [email protected]; [email protected]
Cc: Lee, Zhuo-hao
Subject: RE: [PATCH v2] ALSA: hda - Fix race condition between HDA driver and runtime PM

Hi Ullysses,

Quoted 37 lines

-----Original Message-----
From: Eoff, Ullysses A
Sent: Tuesday, July 28, 2015 12:20 PM
To: [email protected]; [email protected]
Cc: Lee, Zhuo-hao; Yang, Libin; Eoff, Ullysses A
Subject: [PATCH v2] ALSA: hda - Fix race condition between HDA driver and runtime PM

Don't execute runtime suspend if HDA is not finished initializing. Otherwise, the following errors can occur in hda:

snd_hda_intel 0000:00:1b.0: CORB reset timeout#2, CORBRP = 65535 snd_hda_intel 0000:00:1b.0: no codecs initialized

Debugged and root-cause found by [email protected]

v2: remove unnecessary extra check for chip init (libin)

---
 sound/pci/hda/hda_intel.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
sound/pci/hda/hda_intel.c +1 -0
index b729b25a6ad6..15d4e28fc64e 100644
@@ -1017,17 +1017,19 @@ static int azx_runtime_idle(struct device
 *dev)
 	struct snd_card *card = dev_get_drvdata(dev);
 	struct azx *chip;
 	struct hda_intel *hda;
+	struct hdac_bus *bus;
 
 	if (!card)
 		return 0;
 
Quoted 7 lines

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

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

I mean we don't need '!chip->running' either. Otherwise, initialization may be interrupted.

!chip->running condition comes from patch 1/2 and is needed to avoid race with async probe. Are you saying we don't need patch 1/2?

Quoted 11 lines
Quoted 11 lines
sound/pci/hda/hda_intel.c +1 -1
 		return 0;
 
 	if (!power_save_controller || !azx_has_pm_runtime(chip) ||
-	    azx_bus(chip)->codec_powered)
+	    bus->codec_powered || !bus->chip_init)
 		return -EBUSY;
 

return 0;
--
1.9.3

#3 lore raw

Hi Ullysses,

Quoted 68 lines

-----Original Message-----
From: Eoff, Ullysses A
Sent: Tuesday, July 28, 2015 1:27 PM
To: Yang, Libin; [email protected]; [email protected]
Cc: Lee, Zhuo-hao
Subject: RE: [PATCH v2] ALSA: hda - Fix race condition between HDA driver and runtime PM

Quoted 6 lines

-----Original Message-----
From: Yang, Libin
Sent: Monday, July 27, 2015 10:20 PM
To: Eoff, Ullysses A; [email protected]; [email protected]
Cc: Lee, Zhuo-hao
Subject: RE: [PATCH v2] ALSA: hda - Fix race condition between HDA

driver and runtime PM

Quoted 10 lines

Hi Ullysses,

Quoted 6 lines

-----Original Message-----
From: Eoff, Ullysses A
Sent: Tuesday, July 28, 2015 12:20 PM
To: [email protected]; [email protected]
Cc: Lee, Zhuo-hao; Yang, Libin; Eoff, Ullysses A
Subject: [PATCH v2] ALSA: hda - Fix race condition between HDA

driver

Quoted 6 lines
Quoted 6 lines

and runtime PM

Don't execute runtime suspend if HDA is not finished initializing. Otherwise, the following errors can occur in hda:

snd_hda_intel 0000:00:1b.0: CORB reset timeout#2, CORBRP =

65535

Quoted 11 lines
Quoted 11 lines

snd_hda_intel 0000:00:1b.0: no codecs initialized

Debugged and root-cause found by [email protected]

v2: remove unnecessary extra check for chip init (libin)

---
 sound/pci/hda/hda_intel.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 5 lines

sound/pci/hda/hda_intel.c static int azx_runtime_idle(struct

Quoted 5 lines
sound/pci/hda/hda_intel.c +0 -0
index b729b25a6ad6..15d4e28fc64e 100644
@@ -1017,17 +1017,19 @@ static int azx_runtime_idle(struct

device

Quoted 9 lines
Quoted 9 lines
sound/pci/hda/hda_intel.c +1 -0
 *dev)
 	struct snd_card *card = dev_get_drvdata(dev);
 	struct azx *chip;
 	struct hda_intel *hda;
+	struct hdac_bus *bus;
 
 	if (!card)
 		return 0;
 
Quoted 7 lines

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

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

I mean we don't need '!chip->running' either. Otherwise, initialization may be interrupted.

Quoted 3 lines

!chip->running condition comes from patch 1/2 and is needed to avoid race with async probe. Are you saying we don't need patch 1/2?

Do you mean removing patch 1/2 will cause race?

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
sound/pci/hda/hda_intel.c +1 -1
 		return 0;
 
 	if (!power_save_controller || !azx_has_pm_runtime(chip) ||
-	    azx_bus(chip)->codec_powered)
+	    bus->codec_powered || !bus->chip_init)
 		return -EBUSY;
 

return 0;
--
1.9.3

#4 lore raw
Quoted 77 lines

-----Original Message-----
From: Yang, Libin
Sent: Monday, July 27, 2015 10:30 PM
To: Eoff, Ullysses A; [email protected]; [email protected]
Cc: Lee, Zhuo-hao
Subject: RE: [PATCH v2] ALSA: hda - Fix race condition between HDA driver and runtime PM

Hi Ullysses,

Quoted 68 lines

-----Original Message-----
From: Eoff, Ullysses A
Sent: Tuesday, July 28, 2015 1:27 PM
To: Yang, Libin; [email protected]; [email protected]
Cc: Lee, Zhuo-hao
Subject: RE: [PATCH v2] ALSA: hda - Fix race condition between HDA driver and runtime PM

Quoted 6 lines

-----Original Message-----
From: Yang, Libin
Sent: Monday, July 27, 2015 10:20 PM
To: Eoff, Ullysses A; [email protected]; [email protected]
Cc: Lee, Zhuo-hao
Subject: RE: [PATCH v2] ALSA: hda - Fix race condition between HDA

driver and runtime PM

Quoted 10 lines

Hi Ullysses,

Quoted 6 lines

-----Original Message-----
From: Eoff, Ullysses A
Sent: Tuesday, July 28, 2015 12:20 PM
To: [email protected]; [email protected]
Cc: Lee, Zhuo-hao; Yang, Libin; Eoff, Ullysses A
Subject: [PATCH v2] ALSA: hda - Fix race condition between HDA

driver

Quoted 6 lines
Quoted 6 lines

and runtime PM

Don't execute runtime suspend if HDA is not finished initializing. Otherwise, the following errors can occur in hda:

snd_hda_intel 0000:00:1b.0: CORB reset timeout#2, CORBRP =

65535

Quoted 11 lines
Quoted 11 lines

snd_hda_intel 0000:00:1b.0: no codecs initialized

Debugged and root-cause found by [email protected]

v2: remove unnecessary extra check for chip init (libin)

---
 sound/pci/hda/hda_intel.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 5 lines

sound/pci/hda/hda_intel.c static int azx_runtime_idle(struct

Quoted 5 lines
sound/pci/hda/hda_intel.c +0 -0
index b729b25a6ad6..15d4e28fc64e 100644
@@ -1017,17 +1017,19 @@ static int azx_runtime_idle(struct

device

Quoted 16 lines

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

Quoted 13 lines
sound/pci/hda/hda_intel.c +2 -0
 *dev)
 	struct snd_card *card = dev_get_drvdata(dev);
 	struct azx *chip;
 	struct hda_intel *hda;
+	struct hdac_bus *bus;
 
 	if (!card)
 		return 0;
 
 	chip = card->private_data;
 	hda = container_of(chip, struct hda_intel, chip);
+	bus = azx_bus(chip);
 	if (chip->disabled || hda->init_failed || !chip->running)

I mean we don't need '!chip->running' either. Otherwise, initialization may be interrupted.

Quoted 5 lines
Quoted 3 lines

!chip->running condition comes from patch 1/2 and is needed to avoid race with async probe. Are you saying we don't need patch 1/2?

Do you mean removing patch 1/2 will cause race?

Yes. PM ops could trigger before azx_probe_continue finishes which results in a NULL deref kernel crash.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
sound/pci/hda/hda_intel.c +1 -1
 		return 0;
 
 	if (!power_save_controller || !azx_has_pm_runtime(chip) ||
-	    azx_bus(chip)->codec_powered)
+	    bus->codec_powered || !bus->chip_init)
 		return -EBUSY;
 

return 0;
--
1.9.3

#5 lore raw
Quoted 90 lines

-----Original Message-----
From: Eoff, Ullysses A
Sent: Tuesday, July 28, 2015 1:38 PM
To: Yang, Libin; [email protected]; [email protected]
Cc: Lee, Zhuo-hao
Subject: RE: [PATCH v2] ALSA: hda - Fix race condition between HDA driver and runtime PM

Quoted 6 lines

-----Original Message-----
From: Yang, Libin
Sent: Monday, July 27, 2015 10:30 PM
To: Eoff, Ullysses A; [email protected]; [email protected]
Cc: Lee, Zhuo-hao
Subject: RE: [PATCH v2] ALSA: hda - Fix race condition between HDA

driver and runtime PM

Quoted 9 lines

Hi Ullysses,

Quoted 6 lines

-----Original Message-----
From: Eoff, Ullysses A
Sent: Tuesday, July 28, 2015 1:27 PM
To: Yang, Libin; [email protected]; [email protected]
Cc: Lee, Zhuo-hao
Subject: RE: [PATCH v2] ALSA: hda - Fix race condition between

HDA

Quoted 9 lines
Quoted 9 lines

driver and runtime PM

Quoted 6 lines

-----Original Message-----
From: Yang, Libin
Sent: Monday, July 27, 2015 10:20 PM
To: Eoff, Ullysses A; [email protected]; [email protected]
Cc: Lee, Zhuo-hao
Subject: RE: [PATCH v2] ALSA: hda - Fix race condition between

HDA

Quoted 11 lines
Quoted 11 lines

driver and runtime PM

Quoted 10 lines

Hi Ullysses,

Quoted 6 lines

-----Original Message-----
From: Eoff, Ullysses A
Sent: Tuesday, July 28, 2015 12:20 PM
To: [email protected]; [email protected]
Cc: Lee, Zhuo-hao; Yang, Libin; Eoff, Ullysses A
Subject: [PATCH v2] ALSA: hda - Fix race condition between

HDA

Quoted 12 lines
Quoted 12 lines

driver

Quoted 6 lines
Quoted 6 lines

and runtime PM

Don't execute runtime suspend if HDA is not finished initializing. Otherwise, the following errors can occur in hda:

snd_hda_intel 0000:00:1b.0: CORB reset timeout#2, CORBRP =

65535

Quoted 4 lines
Quoted 4 lines

snd_hda_intel 0000:00:1b.0: no codecs initialized

Debugged and root-cause found by [email protected]

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines

v2: remove unnecessary extra check for chip init (libin)

---
 sound/pci/hda/hda_intel.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/sound/pci/hda/hda_intel.c

Quoted 22 lines
Quoted 22 lines
Quoted 4 lines

sound/pci/hda/hda_intel.c static int azx_runtime_idle(struct

Quoted 4 lines

index b729b25a6ad6..15d4e28fc64e 100644

sound/pci/hda/hda_intel.c +0 -0
@@ -1017,17 +1017,19 @@ static int azx_runtime_idle(struct

device

Quoted 16 lines

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

Quoted 13 lines
sound/pci/hda/hda_intel.c +2 -0
 *dev)
 	struct snd_card *card = dev_get_drvdata(dev);
 	struct azx *chip;
 	struct hda_intel *hda;
+	struct hdac_bus *bus;
 
 	if (!card)
 		return 0;
 
 	chip = card->private_data;
 	hda = container_of(chip, struct hda_intel, chip);
+	bus = azx_bus(chip);
 	if (chip->disabled || hda->init_failed || !chip->running)

I mean we don't need '!chip->running' either. Otherwise, initialization may be interrupted.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

!chip->running condition comes from patch 1/2 and is needed to avoid race with async probe. Are you saying we don't need patch 1/2?

Do you mean removing patch 1/2 will cause race?

Yes. PM ops could trigger before azx_probe_continue finishes which results in a NULL deref kernel crash.

If so, agree with Takashi's comment's on the first patch, we can return -EBUSY for this case.

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

sound/pci/hda/hda_intel.c static int azx_runtime_idle(struct device *dev)

Quoted 7 lines
sound/pci/hda/hda_intel.c +0 -0
 		return 0;
 
 	if (!power_save_controller
|| !azx_has_pm_runtime(chip) ||
> > > > -	    azx_bus(chip)->codec_powered)
> > > > +	    bus->codec_powered || !bus->chip_init)
> > > >  		return -EBUSY;
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
sound/pci/hda/hda_intel.c +0 -1
 	return 0;
--

1.9.3