All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org, intel-gfx@lists.freedesktop.org
Subject: Re: [alsa-devel] pcm_lock deadlock
Date: Wed, 30 Oct 2019 15:50:09 +0200	[thread overview]
Message-ID: <20191030135009.GJ1208@intel.com> (raw)
In-Reply-To: <s5himo7i89i.wl-tiwai@suse.de>

On Tue, Oct 29, 2019 at 09:52:57PM +0100, Takashi Iwai wrote:
> On Tue, 29 Oct 2019 20:10:50 +0100,
> From: Takashi Iwai <tiwai@suse.de>
> Subject: [PATCH] ALSA: hda - Fix mutex deadlock in HDMI codec driver
> 
> The commit ade49db337a9 ("ALSA: hda/hdmi - Allow audio component for
> AMD/ATI and Nvidia HDMI") introduced the spec->pcm_lock mutex lock to
> the whole generic_hdmi_init() function for avoiding the race with the
> audio component registration.  However, this caused a dead lock when
> the unsolicited event is handled without the audio component, as the
> codec gets runtime-resumed in hdmi_present_sense() which is already
> inside the spec->pcm_lock in its caller.
> 
> For avoiding this deadlock, add a new mutex only for the audio
> component binding that is used in both generic_hdmi_init() and the
> audio notifier registration where the jack callbacks are handled /
> re-registered.
> 
> Fixes: ade49db337a9 ("ALSA: hda/hdmi - Allow audio component for AMD/ATI and Nvidia HDMI")
> Reported-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
>  sound/pci/hda/patch_hdmi.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
> index 795cbda32cbb..d9b5ba361409 100644
> --- a/sound/pci/hda/patch_hdmi.c
> +++ b/sound/pci/hda/patch_hdmi.c
> @@ -145,6 +145,7 @@ struct hdmi_spec {
>  	struct snd_array pins; /* struct hdmi_spec_per_pin */
>  	struct hdmi_pcm pcm_rec[16];
>  	struct mutex pcm_lock;
> +	struct mutex bind_lock; /* for audio component binding */

Missing mutex_init() for this guy.

Tested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

>  	/* pcm_bitmap means which pcms have been assigned to pins*/
>  	unsigned long pcm_bitmap;
>  	int pcm_used;	/* counter of pcm_rec[] */
> @@ -2258,7 +2259,7 @@ static int generic_hdmi_init(struct hda_codec *codec)
>  	struct hdmi_spec *spec = codec->spec;
>  	int pin_idx;
>  
> -	mutex_lock(&spec->pcm_lock);
> +	mutex_lock(&spec->bind_lock);
>  	spec->use_jack_detect = !codec->jackpoll_interval;
>  	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
>  		struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
> @@ -2275,7 +2276,7 @@ static int generic_hdmi_init(struct hda_codec *codec)
>  			snd_hda_jack_detect_enable_callback(codec, pin_nid,
>  							    jack_callback);
>  	}
> -	mutex_unlock(&spec->pcm_lock);
> +	mutex_unlock(&spec->bind_lock);
>  	return 0;
>  }
>  
> @@ -2451,7 +2452,7 @@ static void generic_acomp_notifier_set(struct drm_audio_component *acomp,
>  	int i;
>  
>  	spec = container_of(acomp->audio_ops, struct hdmi_spec, drm_audio_ops);
> -	mutex_lock(&spec->pcm_lock);
> +	mutex_lock(&spec->bind_lock);
>  	spec->use_acomp_notifier = use_acomp;
>  	spec->codec->relaxed_resume = use_acomp;
>  	/* reprogram each jack detection logic depending on the notifier */
> @@ -2461,7 +2462,7 @@ static void generic_acomp_notifier_set(struct drm_audio_component *acomp,
>  					      get_pin(spec, i)->pin_nid,
>  					      use_acomp);
>  	}
> -	mutex_unlock(&spec->pcm_lock);
> +	mutex_unlock(&spec->bind_lock);
>  }
>  
>  /* enable / disable the notifier via master bind / unbind */
> -- 
> 2.16.4

-- 
Ville Syrjälä
Intel
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

WARNING: multiple messages have this Message-ID (diff)
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org, intel-gfx@lists.freedesktop.org
Subject: Re: pcm_lock deadlock
Date: Wed, 30 Oct 2019 15:50:09 +0200	[thread overview]
Message-ID: <20191030135009.GJ1208@intel.com> (raw)
In-Reply-To: <s5himo7i89i.wl-tiwai@suse.de>

On Tue, Oct 29, 2019 at 09:52:57PM +0100, Takashi Iwai wrote:
> On Tue, 29 Oct 2019 20:10:50 +0100,
> From: Takashi Iwai <tiwai@suse.de>
> Subject: [PATCH] ALSA: hda - Fix mutex deadlock in HDMI codec driver
> 
> The commit ade49db337a9 ("ALSA: hda/hdmi - Allow audio component for
> AMD/ATI and Nvidia HDMI") introduced the spec->pcm_lock mutex lock to
> the whole generic_hdmi_init() function for avoiding the race with the
> audio component registration.  However, this caused a dead lock when
> the unsolicited event is handled without the audio component, as the
> codec gets runtime-resumed in hdmi_present_sense() which is already
> inside the spec->pcm_lock in its caller.
> 
> For avoiding this deadlock, add a new mutex only for the audio
> component binding that is used in both generic_hdmi_init() and the
> audio notifier registration where the jack callbacks are handled /
> re-registered.
> 
> Fixes: ade49db337a9 ("ALSA: hda/hdmi - Allow audio component for AMD/ATI and Nvidia HDMI")
> Reported-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
>  sound/pci/hda/patch_hdmi.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
> index 795cbda32cbb..d9b5ba361409 100644
> --- a/sound/pci/hda/patch_hdmi.c
> +++ b/sound/pci/hda/patch_hdmi.c
> @@ -145,6 +145,7 @@ struct hdmi_spec {
>  	struct snd_array pins; /* struct hdmi_spec_per_pin */
>  	struct hdmi_pcm pcm_rec[16];
>  	struct mutex pcm_lock;
> +	struct mutex bind_lock; /* for audio component binding */

Missing mutex_init() for this guy.

Tested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

>  	/* pcm_bitmap means which pcms have been assigned to pins*/
>  	unsigned long pcm_bitmap;
>  	int pcm_used;	/* counter of pcm_rec[] */
> @@ -2258,7 +2259,7 @@ static int generic_hdmi_init(struct hda_codec *codec)
>  	struct hdmi_spec *spec = codec->spec;
>  	int pin_idx;
>  
> -	mutex_lock(&spec->pcm_lock);
> +	mutex_lock(&spec->bind_lock);
>  	spec->use_jack_detect = !codec->jackpoll_interval;
>  	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
>  		struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
> @@ -2275,7 +2276,7 @@ static int generic_hdmi_init(struct hda_codec *codec)
>  			snd_hda_jack_detect_enable_callback(codec, pin_nid,
>  							    jack_callback);
>  	}
> -	mutex_unlock(&spec->pcm_lock);
> +	mutex_unlock(&spec->bind_lock);
>  	return 0;
>  }
>  
> @@ -2451,7 +2452,7 @@ static void generic_acomp_notifier_set(struct drm_audio_component *acomp,
>  	int i;
>  
>  	spec = container_of(acomp->audio_ops, struct hdmi_spec, drm_audio_ops);
> -	mutex_lock(&spec->pcm_lock);
> +	mutex_lock(&spec->bind_lock);
>  	spec->use_acomp_notifier = use_acomp;
>  	spec->codec->relaxed_resume = use_acomp;
>  	/* reprogram each jack detection logic depending on the notifier */
> @@ -2461,7 +2462,7 @@ static void generic_acomp_notifier_set(struct drm_audio_component *acomp,
>  					      get_pin(spec, i)->pin_nid,
>  					      use_acomp);
>  	}
> -	mutex_unlock(&spec->pcm_lock);
> +	mutex_unlock(&spec->bind_lock);
>  }
>  
>  /* enable / disable the notifier via master bind / unbind */
> -- 
> 2.16.4

-- 
Ville Syrjälä
Intel
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

WARNING: multiple messages have this Message-ID (diff)
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org, intel-gfx@lists.freedesktop.org
Subject: Re: [Intel-gfx] pcm_lock deadlock
Date: Wed, 30 Oct 2019 15:50:09 +0200	[thread overview]
Message-ID: <20191030135009.GJ1208@intel.com> (raw)
Message-ID: <20191030135009.Zji4YUqi1TdPuSZoINvmAoyM8LyIa6OwEaYJsHO5nj0@z> (raw)
In-Reply-To: <s5himo7i89i.wl-tiwai@suse.de>

On Tue, Oct 29, 2019 at 09:52:57PM +0100, Takashi Iwai wrote:
> On Tue, 29 Oct 2019 20:10:50 +0100,
> From: Takashi Iwai <tiwai@suse.de>
> Subject: [PATCH] ALSA: hda - Fix mutex deadlock in HDMI codec driver
> 
> The commit ade49db337a9 ("ALSA: hda/hdmi - Allow audio component for
> AMD/ATI and Nvidia HDMI") introduced the spec->pcm_lock mutex lock to
> the whole generic_hdmi_init() function for avoiding the race with the
> audio component registration.  However, this caused a dead lock when
> the unsolicited event is handled without the audio component, as the
> codec gets runtime-resumed in hdmi_present_sense() which is already
> inside the spec->pcm_lock in its caller.
> 
> For avoiding this deadlock, add a new mutex only for the audio
> component binding that is used in both generic_hdmi_init() and the
> audio notifier registration where the jack callbacks are handled /
> re-registered.
> 
> Fixes: ade49db337a9 ("ALSA: hda/hdmi - Allow audio component for AMD/ATI and Nvidia HDMI")
> Reported-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
>  sound/pci/hda/patch_hdmi.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
> index 795cbda32cbb..d9b5ba361409 100644
> --- a/sound/pci/hda/patch_hdmi.c
> +++ b/sound/pci/hda/patch_hdmi.c
> @@ -145,6 +145,7 @@ struct hdmi_spec {
>  	struct snd_array pins; /* struct hdmi_spec_per_pin */
>  	struct hdmi_pcm pcm_rec[16];
>  	struct mutex pcm_lock;
> +	struct mutex bind_lock; /* for audio component binding */

Missing mutex_init() for this guy.

Tested-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

>  	/* pcm_bitmap means which pcms have been assigned to pins*/
>  	unsigned long pcm_bitmap;
>  	int pcm_used;	/* counter of pcm_rec[] */
> @@ -2258,7 +2259,7 @@ static int generic_hdmi_init(struct hda_codec *codec)
>  	struct hdmi_spec *spec = codec->spec;
>  	int pin_idx;
>  
> -	mutex_lock(&spec->pcm_lock);
> +	mutex_lock(&spec->bind_lock);
>  	spec->use_jack_detect = !codec->jackpoll_interval;
>  	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
>  		struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
> @@ -2275,7 +2276,7 @@ static int generic_hdmi_init(struct hda_codec *codec)
>  			snd_hda_jack_detect_enable_callback(codec, pin_nid,
>  							    jack_callback);
>  	}
> -	mutex_unlock(&spec->pcm_lock);
> +	mutex_unlock(&spec->bind_lock);
>  	return 0;
>  }
>  
> @@ -2451,7 +2452,7 @@ static void generic_acomp_notifier_set(struct drm_audio_component *acomp,
>  	int i;
>  
>  	spec = container_of(acomp->audio_ops, struct hdmi_spec, drm_audio_ops);
> -	mutex_lock(&spec->pcm_lock);
> +	mutex_lock(&spec->bind_lock);
>  	spec->use_acomp_notifier = use_acomp;
>  	spec->codec->relaxed_resume = use_acomp;
>  	/* reprogram each jack detection logic depending on the notifier */
> @@ -2461,7 +2462,7 @@ static void generic_acomp_notifier_set(struct drm_audio_component *acomp,
>  					      get_pin(spec, i)->pin_nid,
>  					      use_acomp);
>  	}
> -	mutex_unlock(&spec->pcm_lock);
> +	mutex_unlock(&spec->bind_lock);
>  }
>  
>  /* enable / disable the notifier via master bind / unbind */
> -- 
> 2.16.4

-- 
Ville Syrjälä
Intel
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2019-10-30 13:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-29 19:10 [alsa-devel] pcm_lock deadlock Ville Syrjälä
2019-10-29 19:10 ` [Intel-gfx] " Ville Syrjälä
2019-10-29 19:10 ` Ville Syrjälä
2019-10-29 20:52 ` [alsa-devel] " Takashi Iwai
2019-10-29 20:52   ` [Intel-gfx] " Takashi Iwai
2019-10-29 20:52   ` Takashi Iwai
2019-10-30 13:50   ` Ville Syrjälä [this message]
2019-10-30 13:50     ` [Intel-gfx] " Ville Syrjälä
2019-10-30 13:50     ` Ville Syrjälä
2019-10-30 14:36     ` [alsa-devel] " Takashi Iwai
2019-10-30 14:36       ` [Intel-gfx] " Takashi Iwai
2019-10-30 14:36       ` Takashi Iwai
2019-10-30  2:36 ` ✗ Fi.CI.CHECKPATCH: warning for " Patchwork
2019-10-30  2:36   ` [Intel-gfx] " Patchwork
2019-10-30  2:52 ` ✗ Fi.CI.BAT: failure " Patchwork
2019-10-30  2:52   ` [Intel-gfx] " Patchwork

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=20191030135009.GJ1208@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=intel-gfx@lists.freedesktop.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.