Skip to contentSkip to conversation

ALSA: hda/i915 - avoid hung task timeout in i915 wait

PATCH Superseded Kai Vehmanen 4 participants 4 messages Mar 8, 2022 Sound

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: hda/i915 - avoid hung task timeout in i915 wait

If kernel is built with hung task detection enabled and CONFIG_DEFAULT_HUNG_TASK_TIMEOUT set to less than 60 seconds, snd_hdac_i915_init() will trigger the hung task timeout in case i915 is not available and taint the kernel.

Split the 60sec wait into a loop of smaller waits to avoid this.

---
 sound/hda/hdac_i915.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
sound/hda/hdac_i915.c +6 -4
index 454474ac5716..6219de739b56 100644
@@ -143,7 +143,8 @@ static bool i915_gfx_present(void)
 int snd_hdac_i915_init(struct hdac_bus *bus)
 {
 	struct drm_audio_component *acomp;
-	int err;
+	unsigned long wait = 0;
+	int err, i;
 
 	if (!i915_gfx_present())
 		return -ENODEV;
@@ -159,9 +160,10 @@ int snd_hdac_i915_init(struct hdac_bus *bus)
 	if (!acomp->ops) {
 		if (!IS_ENABLED(CONFIG_MODULES) ||
 		    !request_module("i915")) {
-			/* 60s timeout */
-			wait_for_completion_timeout(&acomp->master_bind_complete,
-						    msecs_to_jiffies(60 * 1000));
+			/* max 60s timeout */
+			for (i = 0; !wait && i < 60; i++)
+				wait = wait_for_completion_timeout(&acomp->master_bind_complete,
+								   msecs_to_jiffies(1000));
 		}
 	}
 	if (!acomp->ops) {

base-commit: fd7698cf0858f8c5e659b655109cd93c2f15cdd3

Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Kai Vehmanen

If kernel is built with hung task detection enabled and CONFIG_DEFAULT_HUNG_TASK_TIMEOUT set to less than 60 seconds, snd_hdac_i915_init() will trigger the hung task timeout in case i915 is not available and taint the kernel.

Split the 60sec wait into a loop of smaller waits to avoid this.

thanks
Lucas De Marchi

#2 lore raw
In reply to Kai Vehmanen
Quoted 20 lines · Kai Vehmanen

If kernel is built with hung task detection enabled and CONFIG_DEFAULT_HUNG_TASK_TIMEOUT set to less than 60 seconds, snd_hdac_i915_init() will trigger the hung task timeout in case i915 is not available and taint the kernel.

Split the 60sec wait into a loop of smaller waits to avoid this.

---
  sound/hda/hdac_i915.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
sound/hda/hdac_i915.c +0 -0
index 454474ac5716..6219de739b56 100644

sound/hda/hdac_i915.c static bool i915_gfx_present(void) · line 146

Quoted 5 lines
sound/hda/hdac_i915.c +1 -1
@@ -143,7 +143,8 @@ static bool i915_gfx_present(void)
  int snd_hdac_i915_init(struct hdac_bus *bus)
  {
  	struct drm_audio_component *acomp;
-	int err;
+	unsigned long wait = 0;

I'm not sure if it is best name for variable that is set to 0 ("false"), maybe done would be better? Especially looking at condition in the following for loop.

Quoted 20 lines
sound/hda/hdac_i915.c +5 -3
+	int err, i;
 
  	if (!i915_gfx_present())
  		return -ENODEV;
@@ -159,9 +160,10 @@ int snd_hdac_i915_init(struct hdac_bus *bus)
  	if (!acomp->ops) {
  		if (!IS_ENABLED(CONFIG_MODULES) ||
  		    !request_module("i915")) {
-			/* 60s timeout */
-			wait_for_completion_timeout(&acomp->master_bind_complete,
-						    msecs_to_jiffies(60 * 1000));
+			/* max 60s timeout */
+			for (i = 0; !wait && i < 60; i++)
+				wait = wait_for_completion_timeout(&acomp->master_bind_complete,
+								   msecs_to_jiffies(1000));
  		}
  	}
  	if (!acomp->ops) {

base-commit: fd7698cf0858f8c5e659b655109cd93c2f15cdd3

#3 lore raw
Quoted 17 lines · On Tue, 08 Mar 2022 17:29:21 +0100, Amadeusz SX2awiX4ski wrote:
Quoted 15 lines · Kai Vehmanen

If kernel is built with hung task detection enabled and CONFIG_DEFAULT_HUNG_TASK_TIMEOUT set to less than 60 seconds, snd_hdac_i915_init() will trigger the hung task timeout in case i915 is not available and taint the kernel.

Split the 60sec wait into a loop of smaller waits to avoid this.

---
  sound/hda/hdac_i915.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
Quoted 14 lines

sound/hda/hdac_i915.c static bool i915_gfx_present(void) · line 146

Quoted 10 lines
sound/hda/hdac_i915.c +1 -1
index 454474ac5716..6219de739b56 100644
@@ -143,7 +143,8 @@ static bool i915_gfx_present(void)
  int snd_hdac_i915_init(struct hdac_bus *bus)
  {
  	struct drm_audio_component *acomp;
-	int err;
+	unsigned long wait = 0;

I'm not sure if it is best name for variable that is set to 0 ("false"), maybe done would be better? Especially looking at condition in the following for loop.

Or, more simply some thing like

			/* max 60s timeout */
			for (i = 0; i < 60; i++) {
				if (wait_for_completion_timeout(&acomp->master_bind_complete,
								   msecs_to_jiffies(1000)))
					break;
			}

Takashi