Skip to content

Commit 0a0d174

Browse files
plbossartvinodkoul
authored andcommitted
soundwire: intel: don't save hw_params for use in prepare
The existing code copies the hw_params pointer and reuses it later in .prepare, specifically to re-initialize the ALH DMA channel information that's lost in suspend-resume cycles. This is not needed, we can directly access the information from the substream/rtd - as done for the HDAudio DAIs in sound/soc/sof/intel/hda-dai.c In addition, using the saved pointer causes the suspend-resume test cases to fail on specific platforms, depending on which version of GCC is used. Péter Ujfalusi and I have spent long hours to root-cause this problem that was reported by the Intel CI first with 6.2-rc1 and again v6.3-rc1. In the latter case we were lucky that the problem was 100% reproducible on local test devices, and found out that adding a dev_dbg() or adding a call to usleep_range() just before accessing the saved pointer "fixed" the issue. With errors appearing just by changing the compiler version or minor changes in the code generated, clearly we have a memory management Heisenbug. The root-cause seems to be that the hw_params pointer is not persistent. The soc-pcm code allocates the hw_params structure on the stack, and passes it to the BE dailink hw_params and DAIs hw_params. Saving such a pointer and reusing it later during the .prepare stage cannot possibly work reliably, it's broken-by-design since v5.10. It's astonishing that the problem was not seen earlier. This simple fix will have to be back-ported to -stable, due to changes to avoid the use of the get/set_dmadata routines this patch will only apply on kernels older than v6.1. Fixes: a5a0239 ("soundwire: intel: reinitialize IP+DSP in .prepare(), but only when resuming") Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com> Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com> Link: https://lore.kernel.org/r/20230321022642.1426611-1-yung-chuan.liao@linux.intel.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent d005ea7 commit 0a0d174

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

drivers/soundwire/cadence_master.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ struct sdw_cdns_stream_config {
8484
* @bus: Bus handle
8585
* @stream_type: Stream type
8686
* @link_id: Master link id
87-
* @hw_params: hw_params to be applied in .prepare step
8887
* @suspended: status set when suspended, to be used in .prepare
8988
* @paused: status set in .trigger, to be used in suspend
9089
* @direction: stream direction
@@ -96,7 +95,6 @@ struct sdw_cdns_dai_runtime {
9695
struct sdw_bus *bus;
9796
enum sdw_stream_type stream_type;
9897
int link_id;
99-
struct snd_pcm_hw_params *hw_params;
10098
bool suspended;
10199
bool paused;
102100
int direction;

drivers/soundwire/intel.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,6 @@ static int intel_hw_params(struct snd_pcm_substream *substream,
725725
dai_runtime->paused = false;
726726
dai_runtime->suspended = false;
727727
dai_runtime->pdi = pdi;
728-
dai_runtime->hw_params = params;
729728

730729
/* Inform DSP about PDI stream number */
731730
ret = intel_params_stream(sdw, substream->stream, dai, params,
@@ -778,6 +777,11 @@ static int intel_prepare(struct snd_pcm_substream *substream,
778777
}
779778

780779
if (dai_runtime->suspended) {
780+
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
781+
struct snd_pcm_hw_params *hw_params;
782+
783+
hw_params = &rtd->dpcm[substream->stream].hw_params;
784+
781785
dai_runtime->suspended = false;
782786

783787
/*
@@ -789,7 +793,7 @@ static int intel_prepare(struct snd_pcm_substream *substream,
789793
*/
790794

791795
/* configure stream */
792-
ch = params_channels(dai_runtime->hw_params);
796+
ch = params_channels(hw_params);
793797
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
794798
dir = SDW_DATA_DIR_RX;
795799
else
@@ -801,7 +805,7 @@ static int intel_prepare(struct snd_pcm_substream *substream,
801805

802806
/* Inform DSP about PDI stream number */
803807
ret = intel_params_stream(sdw, substream->stream, dai,
804-
dai_runtime->hw_params,
808+
hw_params,
805809
sdw->instance,
806810
dai_runtime->pdi->intel_alh_id);
807811
}
@@ -840,7 +844,6 @@ intel_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
840844
return ret;
841845
}
842846

843-
dai_runtime->hw_params = NULL;
844847
dai_runtime->pdi = NULL;
845848

846849
return 0;

0 commit comments

Comments
 (0)