All of
 help / color / mirror / Atom feed
From: Takashi Iwai <>
Cc: "Marek Marczykowski-Górecki" <>
Subject: [PATCH 1/2] ALSA: memalloc: Explicit SG-allocations for Xen PV and non-IOMMU systems
Date: Tue, 24 Jan 2023 10:27:43 +0100	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

For non-IOMMU systems, it makes little sense (or even buggy) to use
dma_alloc_noncontiguous() as an x86 SG-buffer allocation, as it always
results in the big continuous pages instead of SG buffer.  Also, for
Xen PV, this seems also not working well as the pages allocated there
aren't guaranteed to be coherent.

This patch is a first step to address those problems.  It changes the
memalloc helper to go for the explicit SG-page allocations via the
existing fallback allocation primarily for such a platform instead of

Fixes: a8d302a0b770 ("ALSA: memalloc: Revive x86-specific WC page allocations again")
Fixes: 9736a325137b ("ALSA: memalloc: Don't fall back for SG-buffer with IOMMU")
Reported-and-tested-by: Marek Marczykowski-Górecki <>
Signed-off-by: Takashi Iwai <>
 sound/core/memalloc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index 81025f50a542..30c9ad192986 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -541,10 +541,9 @@ static void *snd_dma_noncontig_alloc(struct snd_dma_buffer *dmab, size_t size)
 	struct sg_table *sgt;
 	void *p;
-	sgt = dma_alloc_noncontiguous(dmab->, size, dmab->dev.dir,
-				      DEFAULT_GFP, 0);
-	if (!sgt && !get_dma_ops(dmab-> {
+	if (cpu_feature_enabled(X86_FEATURE_XENPV) ||
+	    !get_dma_ops(dmab-> {
 		if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG)
 			dmab->dev.type = SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK;
@@ -552,6 +551,8 @@ static void *snd_dma_noncontig_alloc(struct snd_dma_buffer *dmab, size_t size)
 		return snd_dma_sg_fallback_alloc(dmab, size);
+	sgt = dma_alloc_noncontiguous(dmab->, size, dmab->dev.dir,
+				      DEFAULT_GFP, 0);
 	if (!sgt)
 		return NULL;

  reply	other threads:[~2023-01-24  9:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-24  9:27 [PATCH 0/2] ALSA: memalloc: Fix for Xen PV and non-IOMMU systems Takashi Iwai
2023-01-24  9:27 ` Takashi Iwai [this message]
2023-01-24  9:27 ` [PATCH 2/2] ALSA: memalloc: Use coherent DMA allocation for fallback again Takashi Iwai
2023-01-25 15:29 ` [PATCH 0/2] ALSA: memalloc: Fix for Xen PV and non-IOMMU systems Takashi Iwai
2023-01-25 15:33   ` Marek Marczykowski-Górecki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.