ASoC: SOF: fix uninitialised "work" with VirtIO
Subsystems (3)
PATCH 1/1 ASoC: SOF: fix uninitialised "work" with VirtIO
In the VirtIO case the sof_pcm_open() function isn't called on the host during guest streaming, which then leaves "work" structures uninitialised. However it is then used to handle position update messages from the DSP. Move their initialisation to immediately after allocation of the containing structure.
---
This is a re-send of "[PATCH 08/14] ASoC: SOF: fix uninitialised "work" with VirtIO" as suggested by Mark, also taking into account a comment from Ranjani - thanks. Note: I haven't sent patches before from mutt, hope this will work, if not - will have to re-send.
sound/soc/sof/pcm.c | 4 +--- sound/soc/sof/sof-audio.h | 3 +++ sound/soc/sof/topology.c | 17 ++++++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-)
sound/soc/sof/pcm.c +1 -3
@@ -57,7 +57,7 @@ static int sof_pcm_dsp_params(struct snd_sof_pcm *spcm, struct snd_pcm_substream/* * sof pcm period elapse work */ -static void sof_pcm_period_elapsed_work (struct work_struct *work) +void snd_sof_pcm_period_elapsed_work (struct work_struct *work) {struct snd_sof_pcm_stream *sps = container_of(work, struct snd_sof_pcm_stream,
@@ -475,8 +475,6 @@ static int sof_pcm_open(struct snd_soc_component *component,dev_dbg (component->dev,"pcm: open stream %d dir %d\n" , spcm->pcm.pcm_id, substream->stream); -INIT_WORK (&spcm->stream[substream->stream].period_elapsed_work, - sof_pcm_period_elapsed_work); caps = &spcm->pcm.caps[substream->stream];
sound/soc/sof/sof-audio.h +3 -0
@@ -11,6 +11,8 @@#ifndef __SOUND_SOC_SOF_AUDIO_H#define __SOUND_SOC_SOF_AUDIO_H +#include <linux/workqueue.h> +#include <sound/soc.h> #include <sound/control.h> #include <sound/sof/stream.h> /* needs to be included before control.h */
@@ -189,6 +191,7 @@ struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,struct snd_sof_pcm *snd_sof_find_spcm_pcm_id (struct snd_soc_component *scomp,unsigned int pcm_id);void snd_sof_pcm_period_elapsed (struct snd_pcm_substream *substream); +void snd_sof_pcm_period_elapsed_work (struct work_struct *work);/* * Mixer IPC
sound/soc/sof/topology.c +12 -5
@@ -9,6 +9,7 @@// #include <linux/firmware.h> +#include <linux/workqueue.h> #include <sound/tlv.h> #include <sound/pcm_params.h> #include <uapi/sound/sof/tokens.h>
@@ -2448,7 +2449,7 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index,struct snd_soc_tplg_stream_caps *caps;struct snd_soc_tplg_private *private = &pcm->priv;struct snd_sof_pcm *spcm; -int stream =SNDRV_PCM_STREAM_PLAYBACK ; +int stream;int ret =0 ;/* nothing to do for BEs atm */
@@ -2460,8 +2461,12 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index,return -ENOMEM ; spcm->scomp = scomp; - spcm->stream[SNDRV_PCM_STREAM_PLAYBACK ].comp_id =COMP_ID_UNASSIGNED ; - spcm->stream[SNDRV_PCM_STREAM_CAPTURE ].comp_id =COMP_ID_UNASSIGNED ; + +for_each_pcm_streams (stream) { + spcm->stream[stream].comp_id =COMP_ID_UNASSIGNED ; +INIT_WORK (&spcm->stream[stream].period_elapsed_work, + snd_sof_pcm_period_elapsed_work); + } spcm->pcm = *pcm;dev_dbg (scomp->dev,"tplg: load pcm %s\n" , pcm->dai_name);
@@ -2482,8 +2487,10 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index,if (!spcm->pcm.playback) goto capture; + stream =SNDRV_PCM_STREAM_PLAYBACK ; +dev_vdbg (scomp->dev,"tplg: pcm %s stream tokens: playback d0i3:%d\n" , - spcm->pcm.pcm_name, spcm->stream[0 ].d0i3_compatible); + spcm->pcm.pcm_name, spcm->stream[stream].d0i3_compatible); caps = &spcm->pcm.caps[stream];
@@ -2513,7 +2520,7 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index,return ret;dev_vdbg (scomp->dev,"tplg: pcm %s stream tokens: capture d0i3:%d\n" , - spcm->pcm.pcm_name, spcm->stream[1 ].d0i3_compatible); + spcm->pcm.pcm_name, spcm->stream[stream].d0i3_compatible); caps = &spcm->pcm.caps[stream];
Signature · 1 line
1.9.3
Quoted 109 lines · Guennadi Liakhovetski
In the VirtIO case the
sof_pcm_open()function isn't called on the host during guest streaming, which then leaves "work" structures uninitialised. However it is then used to handle position update messages from the DSP. Move their initialisation to immediately after allocation of the containing structure.Signed-off-by: Guennadi Liakhovetski <
[email protected]>
---This is a re-send of "[PATCH 08/14] ASoC: SOF: fix uninitialised "work" with VirtIO" as suggested by Mark, also taking into account a comment from Ranjani - thanks. Note: I haven't sent patches before from mutt, hope this will work, if not - will have to re-send.
sound/soc/sof/pcm.c | 4 +--- sound/soc/sof/sof-audio.h | 3 +++ sound/soc/sof/topology.c | 17 ++++++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-)sound/soc/sof/pcm.c +0
-0@@ -57,7 +57,7 @@ static int sof_pcm_dsp_params(struct snd_sof_pcm *spcm,struct
snd_pcm_substream
/*
* sof pcm period elapse work
*/sound/soc/sof/pcm.c +1
-3-static void sof_pcm_period_elapsed_work (struct work_struct *work) +void snd_sof_pcm_period_elapsed_work (struct work_struct *work) {struct snd_sof_pcm_stream *sps = container_of(work, struct snd_sof_pcm_stream,@@ -475,8 +475,6 @@ static int sof_pcm_open(struct snd_soc_component *component,dev_dbg (component->dev,"pcm: open stream %d dir %d\n" , spcm->pcm.pcm_id, substream->stream); -INIT_WORK (&spcm->stream[substream->stream].period_elapsed_work, - sof_pcm_period_elapsed_work); caps = &spcm->pcm.caps[substream->stream];sound/soc/sof/sof-audio.h +3
-0@@ -11,6 +11,8 @@#ifndef __SOUND_SOC_SOF_AUDIO_H#define __SOUND_SOC_SOF_AUDIO_H +#include <linux/workqueue.h> +#include <sound/soc.h> #include <sound/control.h> #include <sound/sof/stream.h> /* needs to be included before control.h */ @@ -189,6 +191,7 @@ struct snd_sof_pcm *snd_sof_find_spcm_comp(structsnd_soc_component *scomp, struct snd_sof_pcm *snd_sof_find_spcm_pcm_id(struct snd_soc_component *scomp,unsigned int pcm_id);void snd_sof_pcm_period_elapsed (struct snd_pcm_substream *substream); +void snd_sof_pcm_period_elapsed_work (struct work_struct *work);/*
* Mixer IPCsound/soc/sof/topology.c +2
-1@@ -9,6 +9,7 @@// #include <linux/firmware.h> +#include <linux/workqueue.h> #include <sound/tlv.h> #include <sound/pcm_params.h> #include <uapi/sound/sof/tokens.h> @@ -2448,7 +2449,7 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index, struct snd_soc_tplg_stream_caps *caps;struct snd_soc_tplg_private *private = &pcm->priv;struct snd_sof_pcm *spcm; -int stream =SNDRV_PCM_STREAM_PLAYBACK ; +int stream;int ret =0 ;/* nothing to do for BEs atm */sound/soc/sof/topology.c +6
-2@@ -2460,8 +2461,12 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index, return -ENOMEM ; spcm->scomp = scomp; - spcm->stream[SNDRV_PCM_STREAM_PLAYBACK ].comp_id =COMP_ID_UNASSIGNED ; - spcm->stream[SNDRV_PCM_STREAM_CAPTURE ].comp_id =COMP_ID_UNASSIGNED ; + +for_each_pcm_streams (stream) { + spcm->stream[stream].comp_id =COMP_ID_UNASSIGNED ; +INIT_WORK (&spcm->stream[stream].period_elapsed_work, + snd_sof_pcm_period_elapsed_work); + }spcm->pcm = *pcm; dev_dbg(scomp->dev, "tplg: load pcm %s\n", pcm->dai_name);sound/soc/sof/topology.c +0
-0@@ -2482,8 +2487,10 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index,
sound/soc/sof/topology.c static int sof_dai_load(struct snd_soc_component · line 2496
Quoted 10 lines
sound/soc/sof/topology.c +3
-1if (!spcm->pcm.playback) goto capture; + stream =SNDRV_PCM_STREAM_PLAYBACK ; +dev_vdbg (scomp->dev,"tplg: pcm %s stream tokens: playback d0i3:%d\n", - spcm->pcm.pcm_name, spcm->stream[0 ].d0i3_compatible); + spcm->pcm.pcm_name, spcm->stream[stream].d0i3_compatible);
Hi Guennadi,
This cleanup is unrelated to the commit message (and the one below)? Should it be a separate patch?
Thanks,
Ranjani
Hi Ranjani,
Quoted 124 lines · Ranjani
Quoted 109 lines · Guennadi Liakhovetski
In the VirtIO case the
sof_pcm_open()function isn't called on the host during guest streaming, which then leaves "work" structures uninitialised. However it is then used to handle position update messages from the DSP. Move their initialisation to immediately after allocation of the containing structure.Signed-off-by: Guennadi Liakhovetski <
[email protected]>
---This is a re-send of "[PATCH 08/14] ASoC: SOF: fix uninitialised "work" with VirtIO" as suggested by Mark, also taking into account a comment from Ranjani - thanks. Note: I haven't sent patches before from mutt, hope this will work, if not - will have to re-send.
sound/soc/sof/pcm.c | 4 +--- sound/soc/sof/sof-audio.h | 3 +++ sound/soc/sof/topology.c | 17 ++++++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-)sound/soc/sof/pcm.c +0
-0@@ -57,7 +57,7 @@ static int sof_pcm_dsp_params(struct snd_sof_pcm *spcm,struct
snd_pcm_substream
/*
* sof pcm period elapse work
*/sound/soc/sof/pcm.c +1
-3-static void sof_pcm_period_elapsed_work (struct work_struct *work) +void snd_sof_pcm_period_elapsed_work (struct work_struct *work) {struct snd_sof_pcm_stream *sps = container_of(work, struct snd_sof_pcm_stream,@@ -475,8 +475,6 @@ static int sof_pcm_open(struct snd_soc_component *component,dev_dbg (component->dev,"pcm: open stream %d dir %d\n" , spcm->pcm.pcm_id, substream->stream); -INIT_WORK (&spcm->stream[substream->stream].period_elapsed_work, - sof_pcm_period_elapsed_work); caps = &spcm->pcm.caps[substream->stream];sound/soc/sof/sof-audio.h +3
-0@@ -11,6 +11,8 @@#ifndef __SOUND_SOC_SOF_AUDIO_H#define __SOUND_SOC_SOF_AUDIO_H +#include <linux/workqueue.h> +#include <sound/soc.h> #include <sound/control.h> #include <sound/sof/stream.h> /* needs to be included before control.h */ @@ -189,6 +191,7 @@ struct snd_sof_pcm *snd_sof_find_spcm_comp(structsnd_soc_component *scomp, struct snd_sof_pcm *snd_sof_find_spcm_pcm_id(struct snd_soc_component *scomp,unsigned int pcm_id);void snd_sof_pcm_period_elapsed (struct snd_pcm_substream *substream); +void snd_sof_pcm_period_elapsed_work (struct work_struct *work);/*
* Mixer IPCsound/soc/sof/topology.c +2
-1@@ -9,6 +9,7 @@// #include <linux/firmware.h> +#include <linux/workqueue.h> #include <sound/tlv.h> #include <sound/pcm_params.h> #include <uapi/sound/sof/tokens.h> @@ -2448,7 +2449,7 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index, struct snd_soc_tplg_stream_caps *caps;struct snd_soc_tplg_private *private = &pcm->priv;struct snd_sof_pcm *spcm; -int stream =SNDRV_PCM_STREAM_PLAYBACK ; +int stream;int ret =0 ;/* nothing to do for BEs atm */sound/soc/sof/topology.c +6
-2@@ -2460,8 +2461,12 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index, return -ENOMEM ; spcm->scomp = scomp; - spcm->stream[SNDRV_PCM_STREAM_PLAYBACK ].comp_id =COMP_ID_UNASSIGNED ; - spcm->stream[SNDRV_PCM_STREAM_CAPTURE ].comp_id =COMP_ID_UNASSIGNED ; + +for_each_pcm_streams (stream) { + spcm->stream[stream].comp_id =COMP_ID_UNASSIGNED ; +INIT_WORK (&spcm->stream[stream].period_elapsed_work, + snd_sof_pcm_period_elapsed_work); + }spcm->pcm = *pcm; dev_dbg(scomp->dev, "tplg: load pcm %s\n", pcm->dai_name);sound/soc/sof/topology.c +0
-0@@ -2482,8 +2487,10 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index,sound/soc/sof/topology.c static int sof_dai_load(struct snd_soc_component · line 2496
Quoted 10 lines
sound/soc/sof/topology.c +3
-1if (!spcm->pcm.playback) goto capture; + stream =SNDRV_PCM_STREAM_PLAYBACK ; +dev_vdbg (scomp->dev,"tplg: pcm %s stream tokens: playback d0i3:%d\n", - spcm->pcm.pcm_name, spcm->stream[0 ].d0i3_compatible); + spcm->pcm.pcm_name, spcm->stream[stream].d0i3_compatible);Hi Guennadi,
Quoted 2 lines
This cleanup is unrelated to the commit message (and the one below)? Should it be a separate patch?
I think it is a matter of judgement. It was your request to use for_each_pcm_streams() which I did. While transitioning to it I noticed a couple of related inconsistencies which I then aso fixed. So IMHO the change is minor, obvious and related. But I agree that this now makes the patch a bit controversial.
Thanks
Guennadi
Quoted 2 lines
Thanks,
Ranjani
Quoted 131 lines · Guennadi Liakhovetski
Hi Ranjani,
Quoted 23 lines · Ranjani
Quoted 20 lines · Guennadi Liakhovetski
In the VirtIO case the
sof_pcm_open()function isn't called on the host during guest streaming, which then leaves "work" structures uninitialised. However it is then used to handle position update messages from the DSP. Move their initialisation to immediately after allocation of the containing structure.Signed-off-by: Guennadi Liakhovetski <
[email protected]>
---This is a re-send of "[PATCH 08/14] ASoC: SOF: fix uninitialised "work" with VirtIO" as suggested by Mark, also taking into account a comment from Ranjani - thanks. Note: I haven't sent patches before from mutt, hope this will work, if not - will have to re-send.
sound/soc/sof/pcm.c | 4 +--- sound/soc/sof/sof-audio.h | 3 +++ sound/soc/sof/topology.c | 17 ++++++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-)Quoted 5 lines
sound/soc/sof/pcm.c static int sof_pcm_dsp_params(struct snd_sof_pcm
Quoted 5 lines
sound/soc/sof/pcm.c +0
-0@@ -57,7 +57,7 @@ static int sof_pcm_dsp_params(struct snd_sof_pcm*spcm,
Quoted 27 lines
Quoted 27 lines
struct
snd_pcm_substream
/*
* sof pcm period elapse work
*/sound/soc/sof/pcm.c +1
-3-static void sof_pcm_period_elapsed_work (struct work_struct *work) +void snd_sof_pcm_period_elapsed_work (struct work_struct *work) {struct snd_sof_pcm_stream *sps = container_of(work, struct snd_sof_pcm_stream,@@ -475,8 +475,6 @@ static int sof_pcm_open(struct snd_soc_component *component,dev_dbg (component->dev,"pcm: open stream %d dir %d\n" , spcm->pcm.pcm_id, substream->stream); -INIT_WORK (&spcm->stream[substream->stream].period_elapsed_work, - sof_pcm_period_elapsed_work); caps = &spcm->pcm.caps[substream->stream];sound/soc/sof/sof-audio.h +0
-0@@ -11,6 +11,8 @@#ifndef __SOUND_SOC_SOF_AUDIO_H#define __SOUND_SOC_SOF_AUDIO_HQuoted 5 lines
sound/soc/sof/sof-audio.h
Quoted 5 lines
sound/soc/sof/sof-audio.h +2
-0+#include <linux/workqueue.h> +#include <sound/soc.h> #include <sound/control.h> #include <sound/sof/stream.h> /* needs to be included before
control.h*/Quoted 55 lines
Quoted 55 lines
sound/soc/sof/sof-audio.h +1
-0@@ -189,6 +191,7 @@ struct snd_sof_pcm *snd_sof_find_spcm_comp(structsnd_soc_component *scomp, struct snd_sof_pcm *snd_sof_find_spcm_pcm_id(struct snd_soc_component *scomp,unsigned int pcm_id);void snd_sof_pcm_period_elapsed (struct snd_pcm_substream *substream); +void snd_sof_pcm_period_elapsed_work (struct work_struct *work);/*
* Mixer IPCsound/soc/sof/topology.c +2
-1@@ -9,6 +9,7 @@// #include <linux/firmware.h> +#include <linux/workqueue.h> #include <sound/tlv.h> #include <sound/pcm_params.h> #include <uapi/sound/sof/tokens.h> @@ -2448,7 +2449,7 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index, struct snd_soc_tplg_stream_caps *caps;struct snd_soc_tplg_private *private = &pcm->priv;struct snd_sof_pcm *spcm; -int stream =SNDRV_PCM_STREAM_PLAYBACK ; +int stream;int ret =0 ;/* nothing to do for BEs atm */sound/soc/sof/topology.c +6
-2@@ -2460,8 +2461,12 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index, return -ENOMEM ; spcm->scomp = scomp; - spcm->stream[SNDRV_PCM_STREAM_PLAYBACK ].comp_id =COMP_ID_UNASSIGNED ; - spcm->stream[SNDRV_PCM_STREAM_CAPTURE ].comp_id =COMP_ID_UNASSIGNED ; + +for_each_pcm_streams (stream) { + spcm->stream[stream].comp_id =COMP_ID_UNASSIGNED ; +INIT_WORK (&spcm->stream[stream].period_elapsed_work, + snd_sof_pcm_period_elapsed_work); + }spcm->pcm = *pcm; dev_dbg(scomp->dev, "tplg: load pcm %s\n", pcm->dai_name);sound/soc/sof/topology.c +0
-0@@ -2482,8 +2487,10 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index, if (!spcm->pcm.playback) goto capture;Quoted 6 lines
sound/soc/sof/topology.c static int sof_dai_load(struct snd_soc_component *scomp, int index,
Quoted 6 lines
sound/soc/sof/topology.c +3
-1+ stream =SNDRV_PCM_STREAM_PLAYBACK ; + dev_vdbg(scomp->dev, "tplg: pcm %s stream tokens: playback d0i3:%d\n", - spcm->pcm.pcm_name, spcm->stream[0 ].d0i3_compatible); + spcm->pcm.pcm_name,spcm->stream[stream].d0i3_compatible);
Quoted 4 lines
Quoted 1 line
Hi Guennadi,
This cleanup is unrelated to the commit message (and the one below)?
Quoted 8 lines
Should
Quoted 1 line
it be a separate patch?
I think it is a matter of judgement. It was your request to use
for_each_pcm_streams()which I did. While transitioning to it I noticed a couple of related inconsistencies which I then aso fixed. So IMHO the change is minor, obvious and related. But I agree that this now makes the patch a bit controversial.
Hi Guennadi,
May I suggest to break it up into 2 patches: First, to move to using the new for_each_pcm_stream_macro() and the second to add the add the work init. That way there would be no confusion.
Thanks,
Ranjani