All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org, Harald Arnesen <harald@skogtun.org>,
	Alex Xu <alex_y_xu@yahoo.ca>
Subject: Re: Intel HD Audio: sound stops working in Xen PV dom0 in >=5.17
Date: Fri, 20 Jan 2023 02:10:37 +0100	[thread overview]
Message-ID: <Y8nqIBJISq9Vm710@mail-itl> (raw)
In-Reply-To: <87fsc8t3s3.wl-tiwai@suse.de>

[-- Attachment #1: Type: text/plain, Size: 9284 bytes --]

On Wed, Jan 18, 2023 at 01:39:56PM +0100, Takashi Iwai wrote:
> On Wed, 18 Jan 2023 11:39:18 +0100,
> Marek Marczykowski-Górecki wrote:
> > 
> > On Wed, Jan 18, 2023 at 09:59:26AM +0100, Takashi Iwai wrote:
> > > On Tue, 17 Jan 2023 21:34:11 +0100,
> > > Marek Marczykowski-Górecki wrote:
> > > > 
> > > > On Tue, Jan 17, 2023 at 05:52:25PM +0100, Takashi Iwai wrote:
> > > > > On Tue, 17 Jan 2023 17:49:28 +0100,
> > > > > Marek Marczykowski-Górecki wrote:
> > > > > > 
> > > > > > On Tue, Jan 17, 2023 at 03:33:42PM +0100, Takashi Iwai wrote:
> > > > > > > On Tue, 17 Jan 2023 15:21:23 +0100,
> > > > > > > Marek Marczykowski-Górecki wrote:
> > > > > > > > 
> > > > > > > > On Tue, Jan 17, 2023 at 12:36:28PM +0100, Marek Marczykowski-Górecki wrote:
> > > > > > > > > On Tue, Jan 17, 2023 at 08:58:57AM +0100, Takashi Iwai wrote:
> > > > > > > > > > On Mon, 16 Jan 2023 16:55:11 +0100,
> > > > > > > > > > Takashi Iwai wrote:
> > > > > > > > > > > 
> > > > > > > > > > > On Tue, 27 Dec 2022 16:26:54 +0100,
> > > > > > > > > > > Marek Marczykowski-Górecki wrote:
> > > > > > > > > > > > 
> > > > > > > > > > > > On Thu, Dec 22, 2022 at 09:09:15AM +0100, Takashi Iwai wrote:
> > > > > > > > > > > > > On Sat, 10 Dec 2022 17:17:42 +0100,
> > > > > > > > > > > > > Marek Marczykowski-Górecki wrote:
> > > > > > > > > > > > > > 
> > > > > > > > > > > > > > On Sat, Dec 10, 2022 at 02:00:06AM +0100, Marek Marczykowski-Górecki wrote:
> > > > > > > > > > > > > > > On Fri, Dec 09, 2022 at 01:40:15PM +0100, Marek Marczykowski-Górecki wrote:
> > > > > > > > > > > > > > > > On Fri, Dec 09, 2022 at 09:10:19AM +0100, Takashi Iwai wrote:
> > > > > > > > > > > > > > > > > On Fri, 09 Dec 2022 02:27:30 +0100,
> > > > > > > > > > > > > > > > > Marek Marczykowski-Górecki wrote:
> > > > > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > > > Hi,
> > > > > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > > > Under Xen PV dom0, with Linux >= 5.17, sound stops working after few
> > > > > > > > > > > > > > > > > > hours. pavucontrol still shows meter bars moving, but the speakers
> > > > > > > > > > > > > > > > > > remain silent. At least on some occasions I see the following message in
> > > > > > > > > > > > > > > > > > dmesg:
> > > > > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > > >   [ 2142.484553] snd_hda_intel 0000:00:1f.3: Unstable LPIB (18144 >= 6396); disabling LPIB delay counting
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > Hit the issue again, this message did not appear in the log (or at least
> > > > > > > > > > > > > > > not yet).
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > (...)
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > > In anyway, please check the behavior with 6.1-rc8 + the commit
> > > > > > > > > > > > > > > > > cc26516374065a34e10c9a8bf3e940e42cd96e2a
> > > > > > > > > > > > > > > > >     ALSA: memalloc: Allocate more contiguous pages for fallback case
> > > > > > > > > > > > > > > > > from for-next of my sound git tree (which will be in 6.2-rc1).
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > This did not helped.
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > Looking at the mentioned commits, there is one specific aspect of Xen PV
> > > > > > > > > > > > > > > > that may be relevant. It configures PAT differently than native Linux.
> > > > > > > > > > > > > > > > Theoretically Linux adapts automatically and using proper API (like
> > > > > > > > > > > > > > > > set_memory_wc()) should just work, but at least for i915 driver it
> > > > > > > > > > > > > > > > causes issues (not fully tracked down yet). Details about that bug
> > > > > > > > > > > > > > > > report include some more background:
> > > > > > > > > > > > > > > > https://lore.kernel.org/intel-gfx/Y5Hst0bCxQDTN7lK@mail-itl/
> > > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > Anyway, I have tested it on a Xen modified to setup PAT the same way as
> > > > > > > > > > > > > > > > native Linux and the audio issue is still there.
> > > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > > If the problem persists, another thing to check is the hack below
> > > > > > > > > > > > > > > > > works.
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > Trying this one now.
> > > > > > > > > > > > > > 
> > > > > > > > > > > > > > And this one didn't either :/
> > > > > > > > > > > > > 
> > > > > > > > > > > > > (Sorry for the late reply, as I've been off in the last weeks.)
> > > > > > > > > > > > > 
> > > > > > > > > > > > > I think the hack doesn't influence on the PCM buffer pages, but only
> > > > > > > > > > > > > about BDL pages.  Could you check the patch below instead?
> > > > > > > > > > > > > It'll disable the SG-buffer handling on x86 completely. 
> > > > > > > > > > > > 
> > > > > > > > > > > > This seems to "fix" the issue, thanks!
> > > > > > > > > > > > I guess I'll run it this way for now, but a proper solution would be
> > > > > > > > > > > > nice. Let me know if I can collect any more info that would help with
> > > > > > > > > > > > that.
> > > > > > > > > > > 
> > > > > > > > > > > Then we seem to go back again with the coherent memory allocation for
> > > > > > > > > > > the fallback sg cases.  It was changed because the use of
> > > > > > > > > > > dma_alloc_coherent() caused a problem with IOMMU case for retrieving
> > > > > > > > > > > the page addresses, but since the commit 9736a325137b, we essentially
> > > > > > > > > > > avoid the fallback when IOMMU is used, so it should be fine again.
> > > > > > > > > > > 
> > > > > > > > > > > Let me know if the patch like below works for you instead of the
> > > > > > > > > > > previous hack to disable SG-buffer (note: totally untested!)
> > > > > > > > > > 
> > > > > > > > > > Gah, there was an obvious typo, scratch that.
> > > > > > > > > > 
> > > > > > > > > > Below is a proper patch.  Please try this one instead.
> > > > > > > > > 
> > > > > > > > > Thanks, I'll give it a try.
> > > > > > > > 
> > > > > > > > Unfortunately, it doesn't help, it stopped working again, after about 3h
> > > > > > > > uptime.
> > > > > > > 
> > > > > > > Aha, then it might be rather other way round;
> > > > > > > dma_alloc_noncontiguous() doesn't work on Xen properly.
> > > > > > > 
> > > > > > > Could you try the one below instead of the previous?
> > > > > > 
> > > > > > Unfortunately, this one doesn't fix it either :/
> > > > > 
> > > > > Hmm.  Then how about applying both of the last two patches?  The last
> > > > > one to enforce the fallback allocation and the previous one to use
> > > > > dma_alloc_coherent().  It should be essentially reverting to the old
> > > > > way.
> > > > 
> > > > Oh, I noticed only now: the last patch made it fail to initialize.
> > > 
> > > The "last patch" means the patch to enforce the fallback allocation?
> > 
> > Yes, the one about dma_alloc_noncontiguous().
> > 
> > > > I
> > > > don't see obvious errors in dmesg, but when trying aplay, I get:
> > > > 
> > > >     ALSA lib pcm_direct.c:1284:(snd1_pcm_direct_initialize_slave) unable to install hw params
> > > >     ALSA lib pcm_dmix.c:1087:(snd_pcm_dmix_open) unable to initialize slave
> > > >     aplay: main:830: audio open error: Cannot allocate memory
> > > 
> > > It's -ENOMEM, so it must be from there.  Does it appear always?  If
> > > yes, your system is with IOMMU, and the patch made return always NULL
> > > intentionally.
> > 
> > While the system do have IOMMU, it isn't configured by Linux, but by
> > Xen. And it maps all the memory that Linux see.
> > 
> > > If that's the case, the problem is that IOMMU doesn't handle the
> > > coherent memory on Xen.
> > > 
> > > Please check more explicitly, whether get_dma_ops(dmab->dev.dev) call
> > > in snd_dma_noncontig_alloc() returns NULL or not.
> > 
> > Will do.
> 
> If get_dma_ops() is non-NULL, 

Yes, it's non-NULL.

> it means we need some Xen-specific
> workaround not to use dma_alloc_noncontiguous().
> What's the best way to see whether the driver is running on Xen PV?

Usually it's this: cpu_feature_enabled(X86_FEATURE_XENPV)

> Meanwhile, it's helpful if you can try the combo of my last two
> patches, too.  It should work, and if it doesn't, it implies that
> we're looking at a wrong place.

It doesn't because the last of them causes "Cannot allocate memory".
I'm trying now with this on top:

---8<---
diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index 97d7b8106869..e927d18d1ebb 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -545,7 +545,7 @@ static void *snd_dma_noncontig_alloc(struct snd_dma_buffer *dmab, size_t size)
 	// sgt = dma_alloc_noncontiguous(dmab->dev.dev, size, dmab->dev.dir,
 	//	      DEFAULT_GFP, 0);
 #ifdef CONFIG_SND_DMA_SGBUF
-	if (!sgt && !get_dma_ops(dmab->dev.dev)) {
+	if (!sgt) { // && !get_dma_ops(dmab->dev.dev)) {
 		if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG)
 			dmab->dev.type = SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK;
 		else
---8<---


-- 
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2023-01-20  1:12 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Y5KPAs6f7S2dEoxR@mail-itl>
2022-12-09  8:10 ` Intel HD Audio: sound stops working in Xen PV dom0 in >=5.17 Takashi Iwai
2022-12-09 12:40   ` Marek Marczykowski-Górecki
2022-12-10  1:00     ` Marek Marczykowski-Górecki
2022-12-10 16:17       ` Marek Marczykowski-Górecki
2022-12-20  4:43         ` Marek Marczykowski-Górecki
2022-12-22  8:09         ` Takashi Iwai
2022-12-27 15:26           ` Marek Marczykowski-Górecki
2023-01-16 15:55             ` Takashi Iwai
2023-01-17  7:58               ` Takashi Iwai
2023-01-17 11:36                 ` Marek Marczykowski-Górecki
2023-01-17 14:21                   ` Marek Marczykowski-Górecki
2023-01-17 14:33                     ` Takashi Iwai
2023-01-17 16:49                       ` Marek Marczykowski-Górecki
2023-01-17 16:52                         ` Takashi Iwai
2023-01-17 20:34                           ` Marek Marczykowski-Górecki
2023-01-18  8:59                             ` Takashi Iwai
2023-01-18 10:39                               ` Marek Marczykowski-Górecki
2023-01-18 12:39                                 ` Takashi Iwai
2023-01-20  1:10                                   ` Marek Marczykowski-Górecki [this message]
2023-01-20  2:24                                     ` Marek Marczykowski-Górecki
2023-01-20  7:26                                       ` Takashi Iwai
2023-01-20 12:11                                         ` Marek Marczykowski-Górecki
2023-01-20 13:19                                           ` Takashi Iwai
2023-01-23 21:31                                             ` Marek Marczykowski-Górecki
2023-01-24  9:24                                               ` Takashi Iwai

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=Y8nqIBJISq9Vm710@mail-itl \
    --to=marmarek@invisiblethingslab.com \
    --cc=alex_y_xu@yahoo.ca \
    --cc=alsa-devel@alsa-project.org \
    --cc=harald@skogtun.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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.