ALSA: memalloc: Fixes for sync check and SG helper
cover ALSA: memalloc: Fixes for sync check and SG helper
The recent changes and additions in ALSA core memalloc helpers had incorrect usages of dma_need_sync() and the order of SG page invalidation. This patch corrects those.
Takashi
===
Takashi Iwai (2):
ALSA: memalloc: Fix dma_need_sync() checks
ALSA: memalloc: invalidate SG pages before sync
sound/core/memalloc.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/2 ALSA: memalloc: Fix dma_need_sync() checks
dma_need_sync() checks each DMA address. Fix the incorrect usages for non-contiguous and non-coherent page allocations. Fortunately, there are no actual call sites that need manual syncs yet.
--- sound/core/memalloc.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
sound/core/memalloc.c +9 -4
@@ -511,7 +511,8 @@ static void *snd_dma_noncontig_alloc(struct snd_dma_buffer *dmab, size_t size) DEFAULT_GFP, 0);if (!sgt)return NULL ; - dmab->dev.need_sync =dma_need_sync (dmab->dev.dev, dmab->dev.dir); + dmab->dev.need_sync =dma_need_sync (dmab->dev.dev, +sg_dma_address (sgt->sgl)); p =dma_vmap_noncontiguous (dmab->dev.dev, size, sgt);if (p) dmab->private_data = sgt;
@@ -671,9 +672,13 @@ static const struct snd_malloc_ops snd_dma_sg_wc_ops = {*/ static void *snd_dma_noncoherent_alloc (struct snd_dma_buffer *dmab,size_t size) { - dmab->dev.need_sync =dma_need_sync (dmab->dev.dev, dmab->dev.dir); -return dma_alloc_noncoherent (dmab->dev.dev, size, &dmab->addr, - dmab->dev.dir,DEFAULT_GFP ); +void *p; + + p =dma_alloc_noncoherent (dmab->dev.dev, size, &dmab->addr, + dmab->dev.dir,DEFAULT_GFP ); +if (p) + dmab->dev.need_sync =dma_need_sync (dmab->dev.dev, dmab->addr); +return p; }static void snd_dma_noncoherent_free (struct snd_dma_buffer *dmab)
Signature · 1 line
2.31.1
PATCH 2/2 ALSA: memalloc: invalidate SG pages before sync
In reply to Takashi IwaiIt seems that calling invalidate_kernel_vmap_range() is more correct to be called before dma_sync_*(), judging from the other thread:
https://lore.kernel.org/all/[email protected]/
Although this won't matter much in practice, let's fix the call order for consistency.
--- sound/core/memalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/memalloc.c +1 -1
@@ -541,9 +541,9 @@ static void snd_dma_noncontig_sync(struct snd_dma_buffer *dmab,if (mode ==SNDRV_DMA_SYNC_CPU ) {if (dmab->dev.dir ==DMA_TO_DEVICE )return ; +invalidate_kernel_vmap_range (dmab->area, dmab->bytes);dma_sync_sgtable_for_cpu (dmab->dev.dev, dmab->private_data, dmab->dev.dir); -invalidate_kernel_vmap_range (dmab->area, dmab->bytes); }else {if (dmab->dev.dir ==DMA_FROM_DEVICE )return ;
Signature · 1 line
2.31.1