alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* fix GFP_COMP use in noncoherent dma allocators
@ 2022-12-20  8:20 Christoph Hellwig
  2022-12-20  8:20 ` [PATCH 1/2] ALSA: memalloc: don't use GFP_COMP for non-coherent dma allocations Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Christoph Hellwig @ 2022-12-20  8:20 UTC (permalink / raw)
  To: iommu; +Cc: alsa-devel, Robin Murphy, Takashi Iwai, Marek Szyprowski

Hi all,

this series fixe the regression where dma-iommu stopped clearing
GFP_COMP from noncoherent dma allocations by never requesting those
in the sound code and rejecting them in the core DMA API code.

Diffstat:
 kernel/dma/mapping.c  |    4 ++++
 sound/core/memalloc.c |    4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] ALSA: memalloc: don't use GFP_COMP for non-coherent dma allocations
  2022-12-20  8:20 fix GFP_COMP use in noncoherent dma allocators Christoph Hellwig
@ 2022-12-20  8:20 ` Christoph Hellwig
  2022-12-20  8:20 ` [PATCH 2/2] dma-mapping: reject GFP_COMP for noncohernt allocaions Christoph Hellwig
  2022-12-20 12:27 ` fix GFP_COMP use in noncoherent dma allocators Takashi Iwai
  2 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2022-12-20  8:20 UTC (permalink / raw)
  To: iommu
  Cc: alsa-devel, Kai Vehmanen, Takashi Iwai, Mikhail Gavrilov,
	Robin Murphy, Marek Szyprowski

While not quite as bogus as for the dma-coherent allocations that were
fixed earlier, GFP_COMP for these allocations has no benefits for
the dma-direct case, and can't be supported at all by dma dma-iommu
backend which splits up allocations into smaller orders.  Due to an
oversight in ffcb75458460 that flag stopped being cleared for all
dma allocations, but only got rejected for coherent ones.

Start fixing this by not requesting __GFP_COMP in the sound code, which
is the only place that did this.

Fixes: ffcb75458460 ("dma-mapping: reject __GFP_COMP in dma_alloc_attrs")
Reported-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Reported-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 sound/core/memalloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index 3cf5a87d69eaf3..81025f50a54229 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -542,7 +542,7 @@ static void *snd_dma_noncontig_alloc(struct snd_dma_buffer *dmab, size_t size)
 	void *p;
 
 	sgt = dma_alloc_noncontiguous(dmab->dev.dev, size, dmab->dev.dir,
-				      DEFAULT_GFP | __GFP_COMP, 0);
+				      DEFAULT_GFP, 0);
 #ifdef CONFIG_SND_DMA_SGBUF
 	if (!sgt && !get_dma_ops(dmab->dev.dev)) {
 		if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG)
@@ -820,7 +820,7 @@ static void *snd_dma_noncoherent_alloc(struct snd_dma_buffer *dmab, size_t size)
 	void *p;
 
 	p = dma_alloc_noncoherent(dmab->dev.dev, size, &dmab->addr,
-				  dmab->dev.dir, DEFAULT_GFP | __GFP_COMP);
+				  dmab->dev.dir, DEFAULT_GFP);
 	if (p)
 		dmab->dev.need_sync = dma_need_sync(dmab->dev.dev, dmab->addr);
 	return p;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] dma-mapping: reject GFP_COMP for noncohernt allocaions
  2022-12-20  8:20 fix GFP_COMP use in noncoherent dma allocators Christoph Hellwig
  2022-12-20  8:20 ` [PATCH 1/2] ALSA: memalloc: don't use GFP_COMP for non-coherent dma allocations Christoph Hellwig
@ 2022-12-20  8:20 ` Christoph Hellwig
  2022-12-20 14:57   ` Kai Vehmanen
  2022-12-20 12:27 ` fix GFP_COMP use in noncoherent dma allocators Takashi Iwai
  2 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2022-12-20  8:20 UTC (permalink / raw)
  To: iommu
  Cc: alsa-devel, Kai Vehmanen, Takashi Iwai, Mikhail Gavrilov,
	Robin Murphy, Marek Szyprowski

While not quite as bogus as for the dma-coherent allocations that were
fixed earlier, GFP_COMP for these allocations has no benefits for
the dma-direct case, and can't be supported at all by dma dma-iommu
backend which splits up allocations into smaller orders.  Due to an
oversight in ffcb75458460 that flag stopped being cleared for all
dma allocations, but only got rejected for coherent ones, so fix up
these callers to not allow __GFP_COMP as well after the sound code
has been fixed to not ask for it.

Fixes: ffcb75458460 ("dma-mapping: reject __GFP_COMP in dma_alloc_attrs")
Reported-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Reported-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 kernel/dma/mapping.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index c026a5a5e0466e..68106e3791f6c3 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -560,6 +560,8 @@ static struct page *__dma_alloc_pages(struct device *dev, size_t size,
 		return NULL;
 	if (WARN_ON_ONCE(gfp & (__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM)))
 		return NULL;
+	if (WARN_ON_ONCE(gfp & __GFP_COMP))
+		return NULL;
 
 	size = PAGE_ALIGN(size);
 	if (dma_alloc_direct(dev, ops))
@@ -645,6 +647,8 @@ struct sg_table *dma_alloc_noncontiguous(struct device *dev, size_t size,
 
 	if (WARN_ON_ONCE(attrs & ~DMA_ATTR_ALLOC_SINGLE_PAGES))
 		return NULL;
+	if (WARN_ON_ONCE(gfp & __GFP_COMP))
+		return NULL;
 
 	if (ops && ops->alloc_noncontiguous)
 		sgt = ops->alloc_noncontiguous(dev, size, dir, gfp, attrs);
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: fix GFP_COMP use in noncoherent dma allocators
  2022-12-20  8:20 fix GFP_COMP use in noncoherent dma allocators Christoph Hellwig
  2022-12-20  8:20 ` [PATCH 1/2] ALSA: memalloc: don't use GFP_COMP for non-coherent dma allocations Christoph Hellwig
  2022-12-20  8:20 ` [PATCH 2/2] dma-mapping: reject GFP_COMP for noncohernt allocaions Christoph Hellwig
@ 2022-12-20 12:27 ` Takashi Iwai
  2 siblings, 0 replies; 7+ messages in thread
From: Takashi Iwai @ 2022-12-20 12:27 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: alsa-devel, Takashi Iwai, iommu, Robin Murphy, Marek Szyprowski

On Tue, 20 Dec 2022 09:20:07 +0100,
Christoph Hellwig wrote:
> 
> Hi all,
> 
> this series fixe the regression where dma-iommu stopped clearing
> GFP_COMP from noncoherent dma allocations by never requesting those
> in the sound code and rejecting them in the core DMA API code.
> 
> Diffstat:
>  kernel/dma/mapping.c  |    4 ++++
>  sound/core/memalloc.c |    4 ++--
>  2 files changed, 6 insertions(+), 2 deletions(-)

Thank you Christoph for taking care of this mess, and apologies for my
delayed reaction, as I've been (still) on vacation since the last
week.

FWIW, feel free to take my ack for the sound part:

Acked-by: Takashi Iwai <tiwai@suse.de>


Takashi

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] dma-mapping: reject GFP_COMP for noncohernt allocaions
  2022-12-20  8:20 ` [PATCH 2/2] dma-mapping: reject GFP_COMP for noncohernt allocaions Christoph Hellwig
@ 2022-12-20 14:57   ` Kai Vehmanen
  2022-12-21  6:57     ` Mikhail Gavrilov
  2022-12-21  7:46     ` Christoph Hellwig
  0 siblings, 2 replies; 7+ messages in thread
From: Kai Vehmanen @ 2022-12-20 14:57 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: alsa-devel, Kai Vehmanen, Takashi Iwai, iommu, Mikhail Gavrilov,
	Robin Murphy, Marek Szyprowski

Hey,

On Tue, 20 Dec 2022, Christoph Hellwig wrote:

> While not quite as bogus as for the dma-coherent allocations that were
> fixed earlier, GFP_COMP for these allocations has no benefits for
> the dma-direct case, and can't be supported at all by dma dma-iommu

tested the series and this fixes the issue:
Tested-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>

Minor nit, typo "noncohernt allocaions" in subject of this second patch.

Br, Kai

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] dma-mapping: reject GFP_COMP for noncohernt allocaions
  2022-12-20 14:57   ` Kai Vehmanen
@ 2022-12-21  6:57     ` Mikhail Gavrilov
  2022-12-21  7:46     ` Christoph Hellwig
  1 sibling, 0 replies; 7+ messages in thread
From: Mikhail Gavrilov @ 2022-12-21  6:57 UTC (permalink / raw)
  To: Kai Vehmanen
  Cc: alsa-devel, Takashi Iwai, iommu, Robin Murphy, Christoph Hellwig,
	Marek Szyprowski

On Tue, Dec 20, 2022 at 7:58 PM Kai Vehmanen
<kai.vehmanen@linux.intel.com> wrote:
>
> Hey,
>
> On Tue, 20 Dec 2022, Christoph Hellwig wrote:
>
> > While not quite as bogus as for the dma-coherent allocations that were
> > fixed earlier, GFP_COMP for these allocations has no benefits for
> > the dma-direct case, and can't be supported at all by dma dma-iommu
>
> tested the series and this fixes the issue:
> Tested-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
>
> Minor nit, typo "noncohernt allocaions" in subject of this second patch.
>
> Br, Kai

I also confirm that after applying this patch series issue was gone.

Tested-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>

Thanks.

-- 
Best Regards,
Mike Gavrilov.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] dma-mapping: reject GFP_COMP for noncohernt allocaions
  2022-12-20 14:57   ` Kai Vehmanen
  2022-12-21  6:57     ` Mikhail Gavrilov
@ 2022-12-21  7:46     ` Christoph Hellwig
  1 sibling, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2022-12-21  7:46 UTC (permalink / raw)
  To: Kai Vehmanen
  Cc: alsa-devel, Takashi Iwai, iommu, Mikhail Gavrilov, Robin Murphy,
	Christoph Hellwig, Marek Szyprowski

On Tue, Dec 20, 2022 at 04:57:25PM +0200, Kai Vehmanen wrote:
> Minor nit, typo "noncohernt allocaions" in subject of this second patch.

Thanks,

I've fixed this and queued up the series.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-12-21  7:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-20  8:20 fix GFP_COMP use in noncoherent dma allocators Christoph Hellwig
2022-12-20  8:20 ` [PATCH 1/2] ALSA: memalloc: don't use GFP_COMP for non-coherent dma allocations Christoph Hellwig
2022-12-20  8:20 ` [PATCH 2/2] dma-mapping: reject GFP_COMP for noncohernt allocaions Christoph Hellwig
2022-12-20 14:57   ` Kai Vehmanen
2022-12-21  6:57     ` Mikhail Gavrilov
2022-12-21  7:46     ` Christoph Hellwig
2022-12-20 12:27 ` fix GFP_COMP use in noncoherent dma allocators Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).