All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org, broonie@kernel.org,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Subject: Re: [PATCH 08/12] ASoC: SOF: ipc: fix a race, leading to IPC timeouts
Date: Mon, 20 May 2019 09:15:48 +0200	[thread overview]
Message-ID: <20190520071547.godyxigamihl5gav@debian.ka.intel.com> (raw)
In-Reply-To: <s5hftpaewq0.wl-tiwai@suse.de>

Hi Takashi,

On Sun, May 19, 2019 at 09:20:55AM +0200, Takashi Iwai wrote:
> On Sat, 18 May 2019 22:27:00 +0200,
> Pierre-Louis Bossart wrote:
> > 
> > From: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
> > 
> > Currently on all supported platforms the IPC IRQ thread first signals
> > the sender when an IPC response is received from the DSP, then
> > unmasks the IPC interrupt. Those actions are performed without
> > holding any locks, so the thread can be interrupted between them. IPC
> > timeouts have been observed in such scenarios: if the sender is woken
> > up and it proceeds with sending the next message without unmasking
> > the IPC interrupt, it can miss the next response. This patch takes a
> > spin-lock to prevent the IRQ thread from being preempted at that
> > point. It also makes sure, that the next IPC transmission by the host
> > cannot take place before the IRQ thread has finished updating all the
> > required IPC registers.
> > 
> > Fixes: 53e0c72d98b ("ASoC: SOF: Add support for IPC IO between DSP and Host")
> > Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
> > Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
> > ---
> >  sound/soc/sof/intel/bdw.c     | 11 ++++++-----
> >  sound/soc/sof/intel/byt.c     | 12 +++++++-----
> >  sound/soc/sof/intel/cnl.c     |  6 ++++++
> >  sound/soc/sof/intel/hda-ipc.c | 19 ++++++++++++++++---
> >  sound/soc/sof/ipc.c           | 13 -------------
> >  5 files changed, 35 insertions(+), 26 deletions(-)
> > 
> > diff --git a/sound/soc/sof/intel/bdw.c b/sound/soc/sof/intel/bdw.c
> > index 065cb868bdfa..9dfdc02192b7 100644
> > --- a/sound/soc/sof/intel/bdw.c
> > +++ b/sound/soc/sof/intel/bdw.c
> > @@ -278,11 +278,15 @@ static irqreturn_t bdw_irq_thread(int irq, void *context)
> >  	/* reply message from DSP */
> >  	if (ipcx & SHIM_IPCX_DONE &&
> >  	    !(imrx & SHIM_IMRX_DONE)) {
> > +		unsigned long flags;
> > +
> >  		/* Mask Done interrupt before return */
> >  		snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR,
> >  						 SHIM_IMRX, SHIM_IMRX_DONE,
> >  						 SHIM_IMRX_DONE);
> > +		spin_lock_irqsave(&sdev->ipc_lock, flags);
> 
> Here is an threaded irq handler, so the irqflag is superfluous.
> You can use spin_lock_irq() and spin_unlock_irq().

Oh, sure, thanks for catching this! That was a blind moving of the
spin-lock from lower-level functions. I'll send an updated version to
Pierre, unless you want to apply it immediately, in which case I can
send it to you now.

> > diff --git a/sound/soc/sof/intel/byt.c b/sound/soc/sof/intel/byt.c
> > index 7bf9143d3106..5a11a104110b 100644
> > --- a/sound/soc/sof/intel/byt.c
> > +++ b/sound/soc/sof/intel/byt.c
> > @@ -324,11 +324,16 @@ static irqreturn_t byt_irq_thread(int irq, void *context)
> >  	/* reply message from DSP */
> >  	if (ipcx & SHIM_BYT_IPCX_DONE &&
> >  	    !(imrx & SHIM_IMRX_DONE)) {
> > +		unsigned long flags;
> > +
> >  		/* Mask Done interrupt before first */
> >  		snd_sof_dsp_update_bits64_unlocked(sdev, BYT_DSP_BAR,
> >  						   SHIM_IMRX,
> >  						   SHIM_IMRX_DONE,
> >  						   SHIM_IMRX_DONE);
> 
> BTW, is this usage of _unlocked() version safe?  The previous one also
> contained that, and I wonder why _unlocked variant must be used here.

Some of those uses seem rather fragile to me too, but it looks like they
*should* be safe in normal cases. There seem to be a potential problem
on Broadwell, where an ISR is first configured, which uses *_unlocked()
to access the SHIM_IMRX register, and then bdw_set_dsp_D0() is called,
which also touches that register. So, it's relying on the fact, that no
IPC interrupts will occur until probing is completed. This should also
normally be the case, but if for some reason such an interrupt does
trigger at that time, access to that register can be messed up. This
should be reviewed and possibly refined separately.

Thanks
Guennadi


> thanks,
> 
> Takashi

  reply	other threads:[~2019-05-20  7:16 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-18 20:26 [PATCH 00/12] ASoC: SOF: stability fixes Pierre-Louis Bossart
2019-05-18 20:26 ` [PATCH 01/12] ASoC: SOF: core: remove DSP after unregistering machine driver Pierre-Louis Bossart
2019-05-18 20:26 ` [PATCH 02/12] ASoC: SOF: core: remove snd_soc_unregister_component in case of error Pierre-Louis Bossart
2019-05-18 20:26 ` [PATCH 03/12] ASoC: SOF: core: fix error handling with the probe workqueue Pierre-Louis Bossart
2019-05-18 20:26 ` [PATCH 04/12] ASoC: SOF: pcm: remove runtime PM calls during pcm open/close Pierre-Louis Bossart
2019-05-18 20:26 ` [PATCH 05/12] ASoC: SOF: pcm: clear hw_params_upon_resume flag correctly Pierre-Louis Bossart
2019-05-18 20:26 ` [PATCH 06/12] ASoC: SOF: pcm: remove warning - initialize workqueue on open Pierre-Louis Bossart
2019-05-18 20:26 ` [PATCH 07/12] ASoC: SOF: control: correct the copy size for bytes kcontrol put Pierre-Louis Bossart
2019-05-18 20:27 ` [PATCH 08/12] ASoC: SOF: ipc: fix a race, leading to IPC timeouts Pierre-Louis Bossart
2019-05-19  7:20   ` Takashi Iwai
2019-05-20  7:15     ` Guennadi Liakhovetski [this message]
2019-05-20 13:36       ` Pierre-Louis Bossart
2019-05-18 20:27 ` [PATCH 09/12] ASoC: SOF: Intel: hda: fix the hda init chip Pierre-Louis Bossart
2019-05-18 20:27 ` [PATCH 10/12] ASoC: SOF: Intel: hda: use the defined ppcap functions Pierre-Louis Bossart
2019-05-18 20:27 ` [PATCH 11/12] ALSA: hdac: fix memory release for SST and SOF drivers Pierre-Louis Bossart
2019-05-19  7:30   ` Takashi Iwai
2019-05-19  7:37     ` Takashi Iwai
2019-05-18 20:27 ` [PATCH 12/12] ASoC: SOF: Intel: hda-codec: fix memory allocation Pierre-Louis Bossart
2019-05-19  7:39 ` [PATCH 00/12] ASoC: SOF: stability fixes Takashi Iwai

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=20190520071547.godyxigamihl5gav@debian.ka.intel.com \
    --to=guennadi.liakhovetski@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=pierre-louis.bossart@linux.intel.com \
    --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.