Skip to content

Commit fac1e24

Browse files
plbossartsmb49
authored andcommitted
soundwire: intel: don't save hw_params for use in prepare
BugLink: https://bugs.launchpad.net/bugs/2025067 [ Upstream commit 0a0d174 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent 0b7f936 commit fac1e24

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
@@ -833,7 +833,6 @@ static int intel_hw_params(struct snd_pcm_substream *substream,
833833
dai_runtime->paused = false;
834834
dai_runtime->suspended = false;
835835
dai_runtime->pdi = pdi;
836-
dai_runtime->hw_params = params;
837836

838837
/* Inform DSP about PDI stream number */
839838
ret = intel_params_stream(sdw, substream->stream, dai, params,
@@ -886,6 +885,11 @@ static int intel_prepare(struct snd_pcm_substream *substream,
886885
}
887886

888887
if (dai_runtime->suspended) {
888+
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
889+
struct snd_pcm_hw_params *hw_params;
890+
891+
hw_params = &rtd->dpcm[substream->stream].hw_params;
892+
889893
dai_runtime->suspended = false;
890894

891895
/*
@@ -897,7 +901,7 @@ static int intel_prepare(struct snd_pcm_substream *substream,
897901
*/
898902

899903
/* configure stream */
900-
ch = params_channels(dai_runtime->hw_params);
904+
ch = params_channels(hw_params);
901905
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
902906
dir = SDW_DATA_DIR_RX;
903907
else
@@ -909,7 +913,7 @@ static int intel_prepare(struct snd_pcm_substream *substream,
909913

910914
/* Inform DSP about PDI stream number */
911915
ret = intel_params_stream(sdw, substream->stream, dai,
912-
dai_runtime->hw_params,
916+
hw_params,
913917
sdw->instance,
914918
dai_runtime->pdi->intel_alh_id);
915919
}
@@ -948,7 +952,6 @@ intel_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
948952
return ret;
949953
}
950954

951-
dai_runtime->hw_params = NULL;
952955
dai_runtime->pdi = NULL;
953956

954957
return 0;

0 commit comments

Comments
 (0)