Skip to contentSkip to conversation

ASoC: Fix reference to PCM buffer address

PATCH Superseded Takashi Iwai 3 participants 10 messages Jul 28, 2021 – Aug 2, 2021

Subsystems (9)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ASoC: Fix reference to PCM buffer address

Hi,

while updating the memory allocation API for WC pages, I casually stumbled on quite a few drivers dealing with the PCM buffer address wrongly via substream->dma_buffer.addr. This patch series corrects those usages.

Takashi

===

Takashi Iwai (5):
ASoC: amd: Fix reference to PCM buffer address
ASoC: intel: atom: Fix reference to PCM buffer address
ASoC: xilinx: Fix reference to PCM buffer address
ASoC: uniphier: Fix reference to PCM buffer address
ASoC: kirkwood: Fix reference to PCM buffer address

 sound/soc/amd/acp-pcm-dma.c                  |  2 +-
 sound/soc/amd/raven/acp3x-pcm-dma.c          |  2 +-
 sound/soc/amd/renoir/acp3x-pdm-dma.c         |  2 +-
 sound/soc/intel/atom/sst-mfld-platform-pcm.c |  3 +--
 sound/soc/kirkwood/kirkwood-dma.c            | 26 ++++++++++++++------
 sound/soc/uniphier/aio-dma.c                 |  2 +-
 sound/soc/xilinx/xlnx_formatter_pcm.c        |  4 +--
 7 files changed, 25 insertions(+), 16 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/5 ASoC: amd: Fix reference to PCM buffer address

PCM buffers might be allocated dynamically when the buffer preallocation failed or a larger buffer is requested, and it's not guaranteed that substream->dma_buffer points to the actually used buffer. The driver needs to refer to substream->runtime->dma_addr instead for the buffer address.

---
 sound/soc/amd/acp-pcm-dma.c          | 2 +-
 sound/soc/amd/raven/acp3x-pcm-dma.c  | 2 +-
 sound/soc/amd/renoir/acp3x-pdm-dma.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
sound/soc/amd/acp-pcm-dma.c +1 -1
index 143155a840ac..cc1ce6f22caa 100644
@@ -969,7 +969,7 @@ static int acp_dma_hw_params(struct snd_soc_component *component,
 
 	acp_set_sram_bank_state(rtd->acp_mmio, 0, true);
 	/* Save for runtime private data */
-	rtd->dma_addr = substream->dma_buffer.addr;
+	rtd->dma_addr = runtime->dma_addr;
 	rtd->order = get_order(size);
 
 	/* Fill the page table entries in ACP SRAM */
sound/soc/amd/raven/acp3x-pcm-dma.c +1 -1
index 8148b0d22e88..597d7c4b2a6b 100644
@@ -286,7 +286,7 @@ static int acp3x_dma_hw_params(struct snd_soc_component *component,
 		pr_err("pinfo failed\n");
 	}
 	size = params_buffer_bytes(params);
-	rtd->dma_addr = substream->dma_buffer.addr;
+	rtd->dma_addr = substream->runtime->dma_addr;
 	rtd->num_pages = (PAGE_ALIGN(size) >> PAGE_SHIFT);
 	config_acp3x_dma(rtd, substream->stream);
 	return 0;
sound/soc/amd/renoir/acp3x-pdm-dma.c +1 -1
index bd20622b0933..11bd22f4fef5 100644
@@ -242,7 +242,7 @@ static int acp_pdm_dma_hw_params(struct snd_soc_component *component,
 		return -EINVAL;
 	size = params_buffer_bytes(params);
 	period_bytes = params_period_bytes(params);
-	rtd->dma_addr = substream->dma_buffer.addr;
+	rtd->dma_addr = runtime->dma_addr;
 	rtd->num_pages = (PAGE_ALIGN(size) >> PAGE_SHIFT);
 	config_acp_dma(rtd, substream->stream);
 	init_pdm_ring_buffer(MEM_WINDOW_START, size, period_bytes,
Signature · 1 line
2.26.2
maintainer
#2 lore raw

Re: [PATCH 1/5] ASoC: amd: Fix reference to PCM buffer address

Quoted 5 lines · Takashi Iwai

PCM buffers might be allocated dynamically when the buffer preallocation failed or a larger buffer is requested, and it's not guaranteed that substream->dma_buffer points to the actually used buffer. The driver needs to refer to substream->runtime->dma_addr instead for the buffer address.

This breaks the build for me on an x86-64 allmodconfig:

/mnt/kernel/sound/soc/amd/renoir/acp3x-pdm-dma.c: In function 'acp_pdm_dma_hw_params':
/mnt/kernel/sound/soc/amd/renoir/acp3x-pdm-dma.c:245:18: error: 'runtime' undeclared (first use in this function); did you mean 'vtime'?

  rtd->dma_addr = runtime->dma_addr;
                  ^~~~~~~
                  vtime
#3 lore raw

Re: [PATCH 1/5] ASoC: amd: Fix reference to PCM buffer address

Quoted 8 lines · Mark Brown
Quoted 5 lines · Takashi Iwai

PCM buffers might be allocated dynamically when the buffer preallocation failed or a larger buffer is requested, and it's not guaranteed that substream->dma_buffer points to the actually used buffer. The driver needs to refer to substream->runtime->dma_addr instead for the buffer address.

Quoted 7 lines

This breaks the build for me on an x86-64 allmodconfig:

/mnt/kernel/sound/soc/amd/renoir/acp3x-pdm-dma.c: In function 'acp_pdm_dma_hw_params':
/mnt/kernel/sound/soc/amd/renoir/acp3x-pdm-dma.c:245:18: error: 'runtime' undeclared (first use in this function); did you mean 'vtime'?

  rtd->dma_addr = runtime->dma_addr;
                  ^~~~~~~
                  vtime

Oops, will resubmit the fixed patch set.

thanks,

Takashi

maintainer
#4 lore raw

Re: [PATCH 1/5] ASoC: amd: Fix reference to PCM buffer address

In reply to Takashi Iwai
Quoted 5 lines · Takashi Iwai

PCM buffers might be allocated dynamically when the buffer preallocation failed or a larger buffer is requested, and it's not guaranteed that substream->dma_buffer points to the actually used buffer. The driver needs to refer to substream->runtime->dma_addr instead for the buffer address.

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/5] ASoC: amd: Fix reference to PCM buffer address
(no commit info)
[2/5] ASoC: intel: atom: Fix reference to PCM buffer address

      commit: 2e6b836312a477d647a7920b56810a5a25f6c856
[3/5] ASoC: xilinx: Fix reference to PCM buffer address
      commit: 42bc62c9f1d3d4880bdc27acb5ab4784209bb0b0
[4/5] ASoC: uniphier: Fix reference to PCM buffer address
      commit: 827f3164aaa579eee6fd50c6654861d54f282a11
[5/5] ASoC: kirkwood: Fix reference to PCM buffer address
      commit: bb6a40fc5a830cae45ddd5cd6cfa151b008522ed

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

#5 lore raw

PATCH 2/5 ASoC: intel: atom: Fix reference to PCM buffer address

In reply to Takashi Iwai

PCM buffers might be allocated dynamically when the buffer preallocation failed or a larger buffer is requested, and it's not guaranteed that substream->dma_buffer points to the actually used buffer. The address should be retrieved from runtime->dma_addr, instead of substream->dma_buffer (and shouldn't use virt_to_phys).

Also, remove the line overriding runtime->dma_area superfluously, which was already set up at the PCM buffer allocation.

Cc Cezary Rojewski <[email protected]>
Cc Pierre-Louis Bossart <[email protected]>
---
 sound/soc/intel/atom/sst-mfld-platform-pcm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/intel/atom/sst-mfld-platform-pcm.c +1 -2
index 4124aa2fc247..5db2f4865bbb 100644
@@ -127,7 +127,7 @@ static void sst_fill_alloc_params(struct snd_pcm_substream *substream,
 	snd_pcm_uframes_t period_size;
 	ssize_t periodbytes;
 	ssize_t buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
-	u32 buffer_addr = virt_to_phys(substream->dma_buffer.area);
+	u32 buffer_addr = substream->runtime->dma_addr;
 
 	channels = substream->runtime->channels;
 	period_size = substream->runtime->period_size;
@@ -233,7 +233,6 @@ static int sst_platform_alloc_stream(struct snd_pcm_substream *substream,
 	/* set codec params and inform SST driver the same */
 	sst_fill_pcm_params(substream, &param);
 	sst_fill_alloc_params(substream, &alloc_params);
-	substream->runtime->dma_area = substream->dma_buffer.area;
 	str_params.sparams = param;
 	str_params.aparams = alloc_params;
 	str_params.codec = SST_CODEC_TYPE_PCM;
Signature · 1 line
2.26.2
maintainer Reviewed-by on v1 2/5
#6 lore raw

Re: [PATCH 2/5] ASoC: intel: atom: Fix reference to PCM buffer address

Quoted 32 lines · Takashi Iwai

PCM buffers might be allocated dynamically when the buffer preallocation failed or a larger buffer is requested, and it's not guaranteed that substream->dma_buffer points to the actually used buffer. The address should be retrieved from runtime->dma_addr, instead of substream->dma_buffer (and shouldn't use virt_to_phys).

Also, remove the line overriding runtime->dma_area superfluously, which was already set up at the PCM buffer allocation.

Cc Cezary Rojewski <[email protected]>
Cc Pierre-Louis Bossart <[email protected]>
---
  sound/soc/intel/atom/sst-mfld-platform-pcm.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/intel/atom/sst-mfld-platform-pcm.c +1 -1
index 4124aa2fc247..5db2f4865bbb 100644
@@ -127,7 +127,7 @@ static void sst_fill_alloc_params(struct snd_pcm_substream *substream,
  	snd_pcm_uframes_t period_size;
  	ssize_t periodbytes;
  	ssize_t buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
-	u32 buffer_addr = virt_to_phys(substream->dma_buffer.area);
+	u32 buffer_addr = substream->runtime->dma_addr;
 
  	channels = substream->runtime->channels;
  	period_size = substream->runtime->period_size;

sound/soc/intel/atom/sst-mfld-platform-pcm.c static int sst_platform_alloc_stream(struct snd_pcm_substream *substream, · line 238

Quoted 7 lines
sound/soc/intel/atom/sst-mfld-platform-pcm.c +0 -1
@@ -233,7 +233,6 @@ static int sst_platform_alloc_stream(struct snd_pcm_substream *substream,
  	/* set codec params and inform SST driver the same */
  	sst_fill_pcm_params(substream, &param);
  	sst_fill_alloc_params(substream, &alloc_params);
-	substream->runtime->dma_area = substream->dma_buffer.area;
  	str_params.sparams = param;
  	str_params.aparams = alloc_params;
  	str_params.codec = SST_CODEC_TYPE_PCM;

Hello,

Changes look good. Can't verify these due to lack of test vehicles, unfortunately.

#7 lore raw

PATCH 3/5 ASoC: xilinx: Fix reference to PCM buffer address

In reply to Takashi Iwai

PCM buffers might be allocated dynamically when the buffer preallocation failed or a larger buffer is requested, and it's not guaranteed that substream->dma_buffer points to the actually used buffer. The driver needs to refer to substream->runtime->dma_addr instead for the buffer address.

---
 sound/soc/xilinx/xlnx_formatter_pcm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/xilinx/xlnx_formatter_pcm.c +2 -2
index 1d59fb668c77..91afea9d5de6 100644
@@ -452,8 +452,8 @@ static int xlnx_formatter_pcm_hw_params(struct snd_soc_component *component,
 
 	stream_data->buffer_size = size;
 
-	low = lower_32_bits(substream->dma_buffer.addr);
-	high = upper_32_bits(substream->dma_buffer.addr);
+	low = lower_32_bits(runtime->dma_addr);
+	high = upper_32_bits(runtime->dma_addr);
 	writel(low, stream_data->mmio + XLNX_AUD_BUFF_ADDR_LSB);
 	writel(high, stream_data->mmio + XLNX_AUD_BUFF_ADDR_MSB);
 
Signature · 1 line
2.26.2
#8 lore raw

PATCH 4/5 ASoC: uniphier: Fix reference to PCM buffer address

In reply to Takashi Iwai

Along with the transition to the managed PCM buffers, the driver now accepts the dynamically allocated buffer, while it still kept the reference to the old preallocated buffer address. This patch corrects to the right reference via runtime->dma_addr.

(Although this might have been already buggy before the cleanup with the managed buffer, let's put Fixes tag to point that; it's a corner case, after all.)

Fixes d55894bc2763 ("ASoC: uniphier: Use managed buffer allocation")
---
 sound/soc/uniphier/aio-dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/uniphier/aio-dma.c +1 -1
index 3c1628a3a1ac..3d9736e7381f 100644
@@ -198,7 +198,7 @@ static int uniphier_aiodma_mmap(struct snd_soc_component *component,
 	vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
 
 	return remap_pfn_range(vma, vma->vm_start,
-			       substream->dma_buffer.addr >> PAGE_SHIFT,
+			       substream->runtime->dma_addr >> PAGE_SHIFT,
 			       vma->vm_end - vma->vm_start, vma->vm_page_prot);
 }
 
Signature · 1 line
2.26.2
#9 lore raw

PATCH 5/5 ASoC: kirkwood: Fix reference to PCM buffer address

In reply to Takashi Iwai

The transition to the managed PCM buffers allowed the dynamically buffer allocation, while the driver code still assumes the fixed preallocation buffer and sets up the DMA stuff at the open call. This needs to be moved to hw_params after the buffer allocation and setup. Also, the reference to the buffer address has to be corrected to runtime->dma_addr.

Fixes b3c0ae75f5d3 ("ASoC: kirkwood: Use managed DMA buffer allocation")
Cc Lars-Peter Clausen <[email protected]>
---
 sound/soc/kirkwood/kirkwood-dma.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
sound/soc/kirkwood/kirkwood-dma.c +18 -8
index c2a5933bfcfc..700a18561a94 100644
@@ -104,8 +104,6 @@ static int kirkwood_dma_open(struct snd_soc_component *component,
 	int err;
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct kirkwood_dma_data *priv = kirkwood_priv(substream);
-	const struct mbus_dram_target_info *dram;
-	unsigned long addr;
 
 	snd_soc_set_runtime_hwparams(substream, &kirkwood_dma_snd_hw);
 
@@ -142,20 +140,14 @@ static int kirkwood_dma_open(struct snd_soc_component *component,
 		writel((unsigned int)-1, priv->io + KIRKWOOD_ERR_MASK);
 	}
 
-	dram = mv_mbus_dram_info();
-	addr = substream->dma_buffer.addr;
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
 		if (priv->substream_play)
 			return -EBUSY;
 		priv->substream_play = substream;
-		kirkwood_dma_conf_mbus_windows(priv->io,
-			KIRKWOOD_PLAYBACK_WIN, addr, dram);
 	} else {
 		if (priv->substream_rec)
 			return -EBUSY;
 		priv->substream_rec = substream;
-		kirkwood_dma_conf_mbus_windows(priv->io,
-			KIRKWOOD_RECORD_WIN, addr, dram);
 	}
 
 	return 0;
@@ -182,6 +174,23 @@ static int kirkwood_dma_close(struct snd_soc_component *component,
 	return 0;
 }
 
+static int kirkwood_dma_hw_params(struct snd_soc_component *component,
+				  struct snd_pcm_substream *substream,
+				  struct snd_pcm_hw_params *params)
+{
+	struct kirkwood_dma_data *priv = kirkwood_priv(substream);
+	const struct mbus_dram_target_info *dram = mv_mbus_dram_info();
+	unsigned long addr = substream->runtime->dma_addr;
+
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		kirkwood_dma_conf_mbus_windows(priv->io,
+			KIRKWOOD_PLAYBACK_WIN, addr, dram);
+	else
+		kirkwood_dma_conf_mbus_windows(priv->io,
+			KIRKWOOD_RECORD_WIN, addr, dram);
+	return 0;
+}
+
 static int kirkwood_dma_prepare(struct snd_soc_component *component,
 				struct snd_pcm_substream *substream)
 {
@@ -246,6 +255,7 @@ const struct snd_soc_component_driver kirkwood_soc_component = {
 	.name		= DRV_NAME,
 	.open		= kirkwood_dma_open,
 	.close		= kirkwood_dma_close,
+	.hw_params	= kirkwood_dma_hw_params,
 	.prepare	= kirkwood_dma_prepare,
 	.pointer	= kirkwood_dma_pointer,
 	.pcm_construct	= kirkwood_dma_new,
Signature · 1 line
2.26.2