Re: [PATCH v1 ] ALSA: core: memalloc: add page alignment for iram

From: Takashi Iwai
Date: Thu Dec 17 2020 - 11:29:47 EST


On Thu, 17 Dec 2020 16:38:22 +0100,
Lars-Peter Clausen wrote:
>
> >> Maybe what we need is a check that runtime->dma_area is page aligned
> >> and runtime->dma_bytes is a multiple of PAGE_SIZE. With a warning at
> >> first and then turn this into a error a year later or so.
> > OK, how about the following instead?
> > Just check SNDRV_PCM_INFO_MMAP in runtime->info; if this is set, the
> > buffer size must be aligned with the page size, and we are safe to
> > extend the size to clear.
> >
> > So the revised fix is much simpler, something like below.
>
> I think this will work for the leaking data issue.
>
> But it will not help with the original issue that
> gen_pool_dma_alloc_align() does not reserve the remainder of the page
> and could give it out to other allocations. We'd need a separate patch
> for that.

That can be fixed by the pcm_memory.c change in the previous patch.
Recited below.

Of course it won't cover the non-standard allocation case, but then
it's rather the responsibility of such driver.


Takashi

---
--- a/sound/core/pcm_memory.c
+++ b/sound/core/pcm_memory.c
@@ -36,6 +36,7 @@ static int do_alloc_pages(struct snd_card *card, int type, struct device *dev,
{
int err;

+ size = PAGE_ALIGN(size)
if (max_alloc_per_card &&
card->total_pcm_alloc_bytes + size > max_alloc_per_card)
return -ENOMEM;
@@ -187,7 +188,7 @@ static void snd_pcm_lib_preallocate_proc_write(struct snd_info_entry *entry,
buffer->error = -ENOMEM;
return;
}
- substream->buffer_bytes_max = size;
+ substream->buffer_bytes_max = new_dmab.bytes;
} else {
substream->buffer_bytes_max = UINT_MAX;
}