You are not logged in.

#1 2023-07-09 00:39:36

Unsecured443
Member
Registered: 2023-07-08
Posts: 20

[SOLVED] 6.4 and higher causes audio distortion

Up until Linux 6.3.9, there was no audio distortion and everything works perfectly. Ever since I 6.4 landed in the main repos and I updated to it, I have been facing audio distortion to the point that nearly nothing is comprehensible. I know it's not a hardware issue, since the audio is fine on 6.1 LTS kernel and also on Windows. Furthermore, the distortion carries through to Bluetooth and wired headphones, further confirming that the audio distortion is not a hardware issue.

The distortion is not immediate. It either occurs automatically after a random amount of time, or when I increase/decrease the volume, or when I skip forward/backward to a section. In order to stop the distortion, I have to either increase/decrease the volume until it stops, or skip forward/backward until it stops, or restarting Pipewire via systemd, however it starts again due to one of the aforementioned reasons.

I just can't figure out why this distortion is occurring. Is anybody else facing this? I am using Pipewire 0.3.73 if that matters.

Here is the hardware information. Taken from the correctly functioning 6.1 LTS kernel:

inxi -A

Audio:
Device-1: Intel Alder Lake PCH-P High Definition Audio
driver: sof-audio-pci-intel-tgl
API: ALSA v: k6.1.38-1-lts status: kernel-api
Server-1: PipeWire v: 0.3.73 status: active

pactl info

Server String: /run/user/1000/pulse/native
Library Protocol Version: 35
Server Protocol Version: 35
Is Local: yes
Client Index: 1091
Tile Size: 65472
User Name: tux
Host Name: NSA-Terminal-4
Server Name: PulseAudio (on PipeWire 0.3.73)
Server Version: 15.0.0
Default Sample Specification: float32le 2ch 48000Hz
Default Channel Map: front-left,front-right
Default Sink: alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__sink
Default Source: alsa_input.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_6__source
Cookie: b9e6:bfc1

pactl list cards

Card #47
Name: alsa_card.pci-0000_00_1f.3-platform-skl_hda_dsp_generic
Driver: alsa
Owner Module: n/a
Properties:
api.acp.auto-port = "false"
api.acp.auto-profile = "false"
api.alsa.card = "0"
api.alsa.card.longname = "LENOVO"
api.alsa.card.name = "sof-hda-dsp"
api.alsa.path = "hw:0"
api.alsa.use-acp = "true"
api.dbus.ReserveDevice1 = "Audio0"
device.api = "alsa"
device.bus = "pci"
device.bus_path = "pci-0000:00:1f.3-platform-skl_hda_dsp_generic"
device.description = "Alder Lake PCH-P High Definition Audio Controller"
device.enum.api = "udev"
device.icon_name = "audio-card-analog-pci"
device.name = "alsa_card.pci-0000_00_1f.3-platform-skl_hda_dsp_generic"
device.nick = "sof-hda-dsp"
device.plugged.usec = "6323069"
device.product.id = "0x51c8"
device.product.name = "Alder Lake PCH-P High Definition Audio Controller"
device.subsystem = "sound"
sysfs.path = "/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0"
device.vendor.id = "0x8086"
device.vendor.name = "Intel Corporation"
media.class = "Audio/Device"
factory.id = "14"
client.id = "34"
object.id = "46"
object.serial = "47"
object.path = "alsa:pcm:0"
alsa.card = "0"
alsa.card_name = "sof-hda-dsp"
alsa.long_card_name = "LENOVO"
alsa.driver_name = "snd_soc_skl_hda_dsp"
device.string = "0"
Profiles:
off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
HiFi: Play HiFi quality Music (sinks: 4, sources: 2, priority: 8000, available: yes)
pro-audio: Pro Audio (sinks: 5, sources: 3, priority: 1, available: yes)
Active Profile: HiFi
Ports:
[Out] HDMI3: HDMI / DisplayPort 3 Output (type: HDMI, priority: 700, latency offset: 0 usec, availability group: HDMI/DP,pcm=5, not available)
Properties:
port.type = "hdmi"
port.availability-group = "HDMI/DP,pcm=5"
device.icon_name = "video-display"
card.profile.port = "0"
Part of profile(s): HiFi
[Out] HDMI2: HDMI / DisplayPort 2 Output (type: HDMI, priority: 600, latency offset: 0 usec, availability group: HDMI/DP,pcm=4, not available)
Properties:
port.type = "hdmi"
port.availability-group = "HDMI/DP,pcm=4"
device.icon_name = "video-display"
card.profile.port = "1"
Part of profile(s): HiFi
[Out] HDMI1: HDMI / DisplayPort 1 Output (type: HDMI, priority: 500, latency offset: 0 usec, availability group: HDMI/DP,pcm=3, not available)
Properties:
port.type = "hdmi"
port.availability-group = "HDMI/DP,pcm=3"
device.icon_name = "video-display"
card.profile.port = "2"
Part of profile(s): HiFi
[Out] Speaker: Speaker (type: Speaker, priority: 100, latency offset: 0 usec, availability unknown)
Properties:
port.type = "speaker"
device.icon_name = "audio-speakers"
card.profile.port = "3"
Part of profile(s): HiFi
[Out] Headphones: Headphones (type: Headphones, priority: 200, latency offset: 0 usec, availability group: Headphone, not available)
Properties:
port.type = "headphones"
port.availability-group = "Headphone"
device.icon_name = "audio-headphones"
card.profile.port = "4"
Part of profile(s): HiFi
[In] Mic2: Headphones Stereo Microphone (type: Mic, priority: 200, latency offset: 0 usec, availability group: Mic, not available)
Properties:
port.type = "mic"
port.availability-group = "Mic"
device.icon_name = "audio-input-microphone"
card.profile.port = "5"
Part of profile(s): HiFi
[In] Mic1: Digital Microphone (type: Mic, priority: 100, latency offset: 0 usec, availability unknown)
Properties:
port.type = "mic"
device.icon_name = "audio-input-microphone"
card.profile.port = "6"
Part of profile(s): HiFi

If you need any more information, please ask. Thanks!

Edit 1: Removed Bluetooth, since after extensive testing, it doesn't yet appear to affect Bluetooth devices. At first, it probably occurred to me due to bad DSP configuration. Sorry about that hmm

Last edited by Unsecured443 (2023-08-18 23:29:34)

Offline

#2 2023-07-10 20:38:37

Mrestof
Member
Registered: 2022-05-06
Posts: 3

Re: [SOLVED] 6.4 and higher causes audio distortion

Hello, I am having the same problem here. Rolled back to LTS kernel for the time being. Also I have my sound card clock rate set not to a default value in pipewire.conf, but to 192000. I am providing all the useful info below. Ask for more if needed.

inxi -A

Audio:
  Device-1: Intel Tiger Lake-LP Smart Sound Audio
    driver: sof-audio-pci-intel-tgl
  API: ALSA v: k6.4.2-arch1-1 status: kernel-api
  Server-1: PipeWire v: 0.3.73 status: active

pactl info

Server String: /run/user/1000/pulse/native
Library Protocol Version: 35
Server Protocol Version: 35
Is Local: yes
Client Index: 98
Tile Size: 65472
User Name: mrestof
Host Name: mars
Server Name: PulseAudio (on PipeWire 0.3.73)
Server Version: 15.0.0
Default Sample Specification: float32le 2ch 192000Hz
Default Channel Map: front-left,front-right
Default Sink: alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__sink
Default Source: alsa_input.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_6__source
Cookie: c991:5182

pactl list cards

Card #48
  Name: alsa_card.pci-0000_00_1f.3-platform-skl_hda_dsp_generic
  Driver: alsa
  Owner Module: n/a
  Properties:
    api.acp.auto-port = "false"
    api.acp.auto-profile = "false"
    api.alsa.card = "0"
    api.alsa.card.longname = "LENOVO-20TD0003RA-ThinkPadE15Gen2"
    api.alsa.card.name = "sof-hda-dsp"
    api.alsa.path = "hw:0"
    api.alsa.use-acp = "true"
    api.dbus.ReserveDevice1 = "Audio0"
    device.api = "alsa"
    device.bus = "pci"
    device.bus_path = "pci-0000:00:1f.3-platform-skl_hda_dsp_generic"
    device.description = "Tiger Lake-LP Smart Sound Technology Audio Controller"
    device.enum.api = "udev"
    device.icon_name = "audio-card-analog-pci"
    device.name = "alsa_card.pci-0000_00_1f.3-platform-skl_hda_dsp_generic"
    device.nick = "sof-hda-dsp"
    device.plugged.usec = "3213331"
    device.product.id = "0xa0c8"
    device.product.name = "Tiger Lake-LP Smart Sound Technology Audio Controller"
    device.subsystem = "sound"
    sysfs.path = "/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0"
    device.vendor.id = "0x8086"
    device.vendor.name = "Intel Corporation"
    media.class = "Audio/Device"
    factory.id = "14"
    client.id = "34"
    object.id = "46"
    object.serial = "48"
    object.path = "alsa:pcm:0"
    alsa.card = "0"
    alsa.card_name = "sof-hda-dsp"
    alsa.long_card_name = "LENOVO-20TD0003RA-ThinkPadE15Gen2"
    alsa.driver_name = "snd_soc_skl_hda_dsp"
    device.string = "0"
  Profiles:
    off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
    HiFi: Play HiFi quality Music (sinks: 4, sources: 2, priority: 8000, available: yes)
    pro-audio: Pro Audio (sinks: 5, sources: 3, priority: 1, available: yes)
  Active Profile: HiFi
  Ports:
    [Out] HDMI3: HDMI / DisplayPort 3 Output (type: HDMI, priority: 700, latency offset: 0 usec, availability group: HDMI/DP,pcm=5, not available)
      Properties:
        port.type = "hdmi"
        port.availability-group = "HDMI/DP,pcm=5"
        device.icon_name = "video-display"
        card.profile.port = "0"
      Part of profile(s): HiFi
    [Out] HDMI2: HDMI / DisplayPort 2 Output (type: HDMI, priority: 600, latency offset: 0 usec, availability group: HDMI/DP,pcm=4, not available)
      Properties:
        port.type = "hdmi"
        port.availability-group = "HDMI/DP,pcm=4"
        device.icon_name = "video-display"
        card.profile.port = "1"
      Part of profile(s): HiFi
    [Out] HDMI1: HDMI / DisplayPort 1 Output (type: HDMI, priority: 500, latency offset: 0 usec, availability group: HDMI/DP,pcm=3, not available)
      Properties:
        port.type = "hdmi"
        port.availability-group = "HDMI/DP,pcm=3"
        device.icon_name = "video-display"
        card.profile.port = "2"
      Part of profile(s): HiFi
    [Out] Speaker: Speaker (type: Speaker, priority: 100, latency offset: 0 usec, availability unknown)
      Properties:
        port.type = "speaker"
        device.icon_name = "audio-speakers"
        card.profile.port = "3"
      Part of profile(s): HiFi
    [Out] Headphones: Headphones (type: Headphones, priority: 200, latency offset: 0 usec, availability group: Headphone, available)
      Properties:
        port.type = "headphones"
        port.availability-group = "Headphone"
        device.icon_name = "audio-headphones"
        card.profile.port = "4"
      Part of profile(s): HiFi
    [In] Mic2: Headphones Stereo Microphone (type: Mic, priority: 200, latency offset: 0 usec, availability group: Mic, not available)
      Properties:
        port.type = "mic"
        port.availability-group = "Mic"
        device.icon_name = "audio-input-microphone"
        card.profile.port = "5"
      Part of profile(s): HiFi
    [In] Mic1: Digital Microphone (type: Mic, priority: 100, latency offset: 0 usec, availability unknown)
      Properties:
        port.type = "mic"
        device.icon_name = "audio-input-microphone"
        card.profile.port = "6"
      Part of profile(s): HiFi

Offline

#3 2023-07-12 16:35:37

bertzi
Member
Registered: 2011-10-02
Posts: 8

Re: [SOLVED] 6.4 and higher causes audio distortion

I have the same issue for 6.4.*-lqx kernels, and I also tried the default kernel 6.4.2. (It reminded me to Half life 2 soldiers voice). I had to downgrade to 6.3.11-lqx.

Offline

#4 2023-07-12 23:25:11

Unsecured443
Member
Registered: 2023-07-08
Posts: 20

Re: [SOLVED] 6.4 and higher causes audio distortion

I have opened a bug report on the Arch Bug Reporting platform. It would be great if you guys can go there, vote for the issue, and post your device information and circumstances as well. Here's the bug report: FS#79081 - [linux linux-zen] >= 6.4 causes audio distortion

Last edited by Unsecured443 (2023-07-12 23:32:57)

Offline

#5 2023-07-14 22:53:54

Unsecured443
Member
Registered: 2023-07-08
Posts: 20

Re: [SOLVED] 6.4 and higher causes audio distortion

I have filed a bug report to upstream here: Bug 217673 - 6.4 and higher causes audio distortion. Please go there and also put the circumstances under which you all are facing this issue.

Offline

#6 2023-07-19 06:36:16

Unsecured443
Member
Registered: 2023-07-08
Posts: 20

Re: [SOLVED] 6.4 and higher causes audio distortion

This same issue is reported here by another person: https://lore.kernel.org/all/875080d0-87 … @gmail.com

A bug report referencing the faulty kernel commit is located on the SOF project's Github project: [BUG] [Regression] Intel hda-dai doesn't recover gracefully from underruns; audio distortion

This indeed does looks like a kernel regression introduced with this commit/patchset: PATCH 1/3 - ASoC: SOF: Intel: hda-dai: Do not perform DMA cleanup during stop

Offline

#7 2023-07-19 13:20:46

darose
Member
Registered: 2004-04-13
Posts: 158

Re: [SOLVED] 6.4 and higher causes audio distortion

Thanks much for posting. That's very helpful.

So does this mean the issue is a problem in the sof-firmware package?  It looks like that got upgraded from 2.2.5-1 -> 2.2.6-1 in early July.

Offline

#8 2023-07-19 20:06:20

Unsecured443
Member
Registered: 2023-07-08
Posts: 20

Re: [SOLVED] 6.4 and higher causes audio distortion

darose wrote:

Thanks much for posting. That's very helpful.

So does this mean the issue is a problem in the sof-firmware package?  It looks like that got upgraded from 2.2.5-1 -> 2.2.6-1 in early July.

No, the issue is not in the sof-firmware package, but rather in the kernel itself. The latest 2.2.6-1 sof-firmware package works fine on the 6.1 LTS and also on the 6.3.x kernel series. The patchset that I referred to earlier is what's causing the issue, both according to the person I referred to and my own testing with the "git bisect" command.

So until that regression is either reversed or patched otherwise in the mainline upstream kernel by the kernel devs, or by the Arch kernel distributors' own decisions, the audio distortion issue will persist.

Edit 1: Added more clarity in regard to sof-firmware.

Last edited by Unsecured443 (2023-07-19 20:10:01)

Offline

#9 2023-07-19 20:17:01

loqs
Member
Registered: 2014-03-06
Posts: 17,450

Re: [SOLVED] 6.4 and higher causes audio distortion

Have you reported the bug to regzbot so it is tracked on https://linux-regtracking.leemhuis.info/regzbot/all/

Offline

#10 2023-07-19 20:28:18

Unsecured443
Member
Registered: 2023-07-08
Posts: 20

Re: [SOLVED] 6.4 and higher causes audio distortion

loqs wrote:

Have you reported the bug to regzbot so it is tracked on https://linux-regtracking.leemhuis.info/regzbot/all/

It's on that website under this title: "PipeWire + Wireplumber audio distortion on Lenovo ThinkPad X1 Yoga Gen 7"

I didn't know I had to do that, but a kind person named Bagas Sanjaya did when I initially reported the bug to upstream.

Offline

#11 2023-07-19 20:45:56

loqs
Member
Registered: 2014-03-06
Posts: 17,450

Re: [SOLVED] 6.4 and higher causes audio distortion

Unsecured443 wrote:
loqs wrote:

Have you reported the bug to regzbot so it is tracked on https://linux-regtracking.leemhuis.info/regzbot/all/

It's on that website under this title: "PipeWire + Wireplumber audio distortion on Lenovo ThinkPad X1 Yoga Gen 7"

I didn't know I had to do that, but a kind person named Bagas Sanjaya did when I initially reported the bug to upstream.

Ah I missed it as I was looking for the commit you bisected the issue to but regzbot has not been updated since the initial report that put the issue in the range v6.3..v6.4.

Last edited by loqs (2023-07-19 20:46:13)

Offline

#12 2023-07-20 02:14:15

Fijxu
Member
Registered: 2021-08-11
Posts: 44

Re: [SOLVED] 6.4 and higher causes audio distortion

Hello, I also have this problem on my PC WITHOUT sof-firmware installed (not a laptop) and I tried installing linux-lts with no luck, the audio distortion persists and it occurs more often if there is high CPU usage or two programs are outputting audio (Like a game + music).

I also have a Thinkpad P1 Gen 4 with sof-firmware installed and something like this happens sometimes (The video is not mine since I am not able to reproduce this issue, but is an HP laptop with sof-firmware installed): Audio Distortion – https://i.ayaya.beauty/gMcy.mp4

I don't have any custom configurations on PipeWire and Wireplumber, just the defaults.

Right now I'm using these Pipewire packages on my PC and Laptop:

local/lib32-libpipewire 1:0.3.74-1
    Low-latency audio/video router and processor - 32-bit - client library
local/lib32-pipewire 1:0.3.74-1
    Low-latency audio/video router and processor - 32-bit
local/lib32-pipewire-jack 1:0.3.74-1
    Low-latency audio/video router and processor - 32-bit - JACK support
local/libpipewire 1:0.3.74-1
    Low-latency audio/video router and processor - client library
local/libwireplumber 0.4.14-1.1
    Session / policy manager implementation for PipeWire - client library
local/pipewire 1:0.3.74-1
    Low-latency audio/video router and processor
local/pipewire-alsa 1:0.3.74-1
    Low-latency audio/video router and processor - ALSA configuration
local/pipewire-audio 1:0.3.74-1
    Low-latency audio/video router and processor - Audio support
local/pipewire-jack 1:0.3.74-1
    Low-latency audio/video router and processor - JACK support
local/pipewire-pulse 1:0.3.74-1
    Low-latency audio/video router and processor - PulseAudio replacement
local/wireplumber 0.4.14-1.1
    Session / policy manager implementation for PipeWire

All the pipewire packages come from the official Arch Linux repositories. CachyOS mantainers don't provide custom builds of Pipewire so it should make a big difference

Since i use Arch Linux with "CachyOS" repositories i opened a different thread on their forums because just using linux-lts (From the Official Arch Linux) repositories didn't solve the problem for me: Random audio distortion using Pipewire + Wireplumber with Intel PCH

CachyOS is just an Arch Linux based distro that builds the packages for different CPU Micro-architecture levels with LTO

If i need to provide more information, just ask for it, this problem is very annoying...

Offline

#13 2023-07-20 02:18:24

Unsecured443
Member
Registered: 2023-07-08
Posts: 20

Re: [SOLVED] 6.4 and higher causes audio distortion

loqs wrote:
Unsecured443 wrote:
loqs wrote:

Have you reported the bug to regzbot so it is tracked on https://linux-regtracking.leemhuis.info/regzbot/all/

It's on that website under this title: "PipeWire + Wireplumber audio distortion on Lenovo ThinkPad X1 Yoga Gen 7"

I didn't know I had to do that, but a kind person named Bagas Sanjaya did when I initially reported the bug to upstream.

Ah I missed it as I was looking for the commit you bisected the issue to but regzbot has not been updated since the initial report that put the issue in the range v6.3..v6.4.

I just sent out a mail to the mailing list updating the regzbot status. I hope I did that right since this is the first time that I am replying to a mailing list and updating the status of regzbot.

Offline

#14 2023-07-20 06:13:10

Fijxu
Member
Registered: 2021-08-11
Posts: 44

Re: [SOLVED] 6.4 and higher causes audio distortion

I just noticed that there is 2 different problems at the same time occurring right now about Audio artifacts.

This one that happens on Laptops (It also happens to me on my laptop): https://i.ayaya.beauty/gMcy.mp4

And this one that happens on PC (When Write error: -32,Broken pipe happens the artifact can be heard): https://i.ayaya.beauty/gSLz.mp4 . This one is independent of the Kernel used, i tried lts, 6.3 and the lastest one, everyone has this problem.

I guess this thread is about the first video right? If I'm wrong, tell me please.

Offline

#15 2023-07-20 19:22:26

Unsecured443
Member
Registered: 2023-07-08
Posts: 20

Re: [SOLVED] 6.4 and higher causes audio distortion

Fijxu wrote:

I just noticed that there is 2 different problems at the same time occurring right now about Audio artifacts.

This one that happens on Laptops (It also happens to me on my laptop): https://i.ayaya.beauty/gMcy.mp4

And this one that happens on PC (When Write error: -32,Broken pipe happens the artifact can be heard): https://i.ayaya.beauty/gSLz.mp4 . This one is independent of the Kernel used, i tried lts, 6.3 and the lastest one, everyone has this problem.

I guess this thread is about the first video right? If I'm wrong, tell me please.

Yes, this thread is about the first video with the laptop.

Offline

#16 2023-07-22 22:13:49

loqs
Member
Registered: 2014-03-06
Posts: 17,450

Re: [SOLVED] 6.4 and higher causes audio distortion

Is the issue fixed by https://github.com/thesofproject/linux/pull/4484 which is applied to the kernel linked below (with manual adjustments so it applies to 6.4.4):

https://drive.google.com/file/d/1jHArIx … sp=sharing linux-6.4.4.arch1-1.2-x86_64.pkg.tar.zst
https://drive.google.com/file/d/17f8lry … sp=sharing linux-headers-6.4.4.arch1-1.2-x86_64.pkg.tar.zst
Edit:
Applied to 6.5-rc3 without requiring adjustments
https://drive.google.com/file/d/1_htN7u … sp=sharing linux-6.5rc3-1.1-x86_64.pkg.tar.zst
https://drive.google.com/file/d/1HcuzLX … sp=sharing linux-headers-6.5rc3-1.1-x86_64.pkg.tar.zst

Last edited by loqs (2023-07-24 10:30:01)

Offline

#17 2023-07-24 21:59:17

Unsecured443
Member
Registered: 2023-07-08
Posts: 20

Re: [SOLVED] 6.4 and higher causes audio distortion

loqs wrote:

Is the issue fixed by https://github.com/thesofproject/linux/pull/4484 which is applied to the kernel linked below (with manual adjustments so it applies to 6.4.4):

https://drive.google.com/file/d/1jHArIx … sp=sharing linux-6.4.4.arch1-1.2-x86_64.pkg.tar.zst
https://drive.google.com/file/d/17f8lry … sp=sharing linux-headers-6.4.4.arch1-1.2-x86_64.pkg.tar.zst
Edit:
Applied to 6.5-rc3 without requiring adjustments
https://drive.google.com/file/d/1_htN7u … sp=sharing linux-6.5rc3-1.1-x86_64.pkg.tar.zst
https://drive.google.com/file/d/1HcuzLX … sp=sharing linux-headers-6.5rc3-1.1-x86_64.pkg.tar.zst

Sorry for the late reply. The issue is indeed fixed with that patch applied to the kernel.

Edit:
It appears the patch was updated to apply as-is against 6.4.x kernels, unlike earlier where manual adjustments were needed.

Last edited by Unsecured443 (2023-07-24 22:04:43)

Offline

#18 2023-07-24 22:13:21

loqs
Member
Registered: 2014-03-06
Posts: 17,450

Re: [SOLVED] 6.4 and higher causes audio distortion

Unsecured443 wrote:

It appears the patch was updated to apply as-is against 6.4.x kernels, unlike earlier where manual adjustments were needed.

The updated patch https://github.com/thesofproject/linux/ … 478e1b43c5 still does not apply for the reason you stated in https://github.com/thesofproject/linux/ … 1646281090
The update did not change the use of hda_link_dma_cleanup which takes 3 parameters in 6.5 but the extra codec_dai in 6.4.
Edit:
Updated version of the patch for 6.4 is it similar to what you are using?

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Date: Fri, 21 Jul 2023 14:20:04 -0700
Subject: [PATCH] ASoC: SOF: intel: hda: Clean up link DMA for IPC3 during stop

With IPC3, we reset hw_params during the stop trigger, so we should also
clean up the link DMA during the stop trigger.

Fixes: 1bf83fa6654c ("ASoC: SOF: Intel: hda-dai: Do not perform DMA cleanup during stop")
Closes: https://github.com/thesofproject/linux/issues/4455
Closes: https://github.com/thesofproject/linux/issues/4482
Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
---
 sound/soc/sof/intel/hda-dai-ops.c | 16 +++++++++++++++-
 sound/soc/sof/intel/hda-dai.c     |  2 +-
 sound/soc/sof/intel/hda.h         |  2 ++
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/sound/soc/sof/intel/hda-dai-ops.c b/sound/soc/sof/intel/hda-dai-ops.c
index 4b39cecacd68..30d57be05f10 100644
--- a/sound/soc/sof/intel/hda-dai-ops.c
+++ b/sound/soc/sof/intel/hda-dai-ops.c
@@ -289,16 +289,30 @@ static const struct hda_dai_widget_dma_ops hda_ipc4_chain_dma_ops = {
 static int hda_ipc3_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
 				 struct snd_pcm_substream *substream, int cmd)
 {
+	struct hdac_ext_stream *hext_stream = hda_get_hext_stream(sdev, cpu_dai, substream);
 	struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(cpu_dai, substream->stream);
+	struct snd_soc_pcm_runtime *rtd;
+	struct snd_soc_dai *codec_dai;
+
+	rtd = asoc_substream_to_rtd(substream);
+	codec_dai = asoc_rtd_to_codec(rtd, 0);
 
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_SUSPEND:
 	case SNDRV_PCM_TRIGGER_STOP:
 	{
 		struct snd_sof_dai_config_data data = { 0 };
+		int ret;
 
 		data.dai_data = DMA_CHAN_INVALID;
-		return hda_dai_config(w, SOF_DAI_CONFIG_FLAGS_HW_FREE, &data);
+		ret = hda_dai_config(w, SOF_DAI_CONFIG_FLAGS_HW_FREE, &data);
+		if (ret < 0)
+			return ret;
+
+		if (cmd == SNDRV_PCM_TRIGGER_STOP)
+			return hda_link_dma_cleanup(substream, hext_stream, cpu_dai, codec_dai);
+
+		break;
 	}
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
 		return hda_dai_config(w, SOF_DAI_CONFIG_FLAGS_PAUSE, NULL);
diff --git a/sound/soc/sof/intel/hda-dai.c b/sound/soc/sof/intel/hda-dai.c
index 44a5d94c5050..1a373a0fcd52 100644
--- a/sound/soc/sof/intel/hda-dai.c
+++ b/sound/soc/sof/intel/hda-dai.c
@@ -91,7 +91,7 @@ hda_dai_get_ops(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai
 	return sdai->platform_private;
 }
 
-static int hda_link_dma_cleanup(struct snd_pcm_substream *substream,
+int hda_link_dma_cleanup(struct snd_pcm_substream *substream,
 				struct hdac_ext_stream *hext_stream,
 				struct snd_soc_dai *cpu_dai,
 				struct snd_soc_dai *codec_dai)
diff --git a/sound/soc/sof/intel/hda.h b/sound/soc/sof/intel/hda.h
index c4befacde23e..94c738eae751 100644
--- a/sound/soc/sof/intel/hda.h
+++ b/sound/soc/sof/intel/hda.h
@@ -942,5 +942,7 @@ const struct hda_dai_widget_dma_ops *
 hda_select_dai_widget_ops(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget);
 int hda_dai_config(struct snd_soc_dapm_widget *w, unsigned int flags,
 		   struct snd_sof_dai_config_data *data);
+int hda_link_dma_cleanup(struct snd_pcm_substream *substream, struct hdac_ext_stream *hext_stream,
+			 struct snd_soc_dai *cpu_dai, struct snd_soc_dai *codec_dai);
 
 #endif

Last edited by loqs (2023-07-24 22:23:51)

Offline

#19 2023-07-25 00:00:35

darose
Member
Registered: 2004-04-13
Posts: 158

Re: [SOLVED] 6.4 and higher causes audio distortion

I'm assuming this fix is *not* included in the 6.4.5 kernel that just appeared in the Arch repos?  (It looks like the PR for the fix hasn't gotten merged yet.)

Offline

#20 2023-07-25 00:32:10

Unsecured443
Member
Registered: 2023-07-08
Posts: 20

Re: [SOLVED] 6.4 and higher causes audio distortion

loqs wrote:

The updated patch https://github.com/thesofproject/linux/ … 478e1b43c5 still does not apply for the reason you stated in https://github.com/thesofproject/linux/ … 1646281090

I think there's some confusion. The CFSworks guy in the Github issue report is not me. He is some other person.

loqs wrote:

Updated version of the patch for 6.4 is it similar to what you are using?

Yes. I had to add the additional parameter for 6.4. 6.5 seems fine without it.

And yes, you are correct. The updated patch still doesn't work as-is with 6.4 and requires the addition of the additional *codec_dai parameter. I overlooked that. My bad hmm

Offline

#21 2023-07-25 00:39:04

Unsecured443
Member
Registered: 2023-07-08
Posts: 20

Re: [SOLVED] 6.4 and higher causes audio distortion

darose wrote:

I'm assuming this fix is *not* included in the 6.4.5 kernel that just appeared in the Arch repos?  (It looks like the PR for the fix hasn't gotten merged yet.)

6.4.5 doesn't patch this issue. The changelog for the release doesn't list it. At the moment, you have to manually patch and build the kernel to use 6.4 without this issue.

Offline

#22 2023-08-03 16:13:27

loqs
Member
Registered: 2014-03-06
Posts: 17,450

Re: [SOLVED] 6.4 and higher causes audio distortion

@Unsecured443 Arch did not pick up the patch locally for 6.4.8-arch1 do you know if thesofproject intends to do a pull for this issue before the 6.6 merge window?

Offline

#23 2023-08-03 23:31:40

Unsecured443
Member
Registered: 2023-07-08
Posts: 20

Re: [SOLVED] 6.4 and higher causes audio distortion

loqs wrote:

@Unsecured443 Arch did not pick up the patch locally for 6.4.8-arch1 do you know if thesofproject intends to do a pull for this issue before the 6.6 merge window?

No, unfortunately, I am not sure when they will issue the PR for the patch. I hope they pick up the patch in an upcoming RC for 6.5

Offline

#24 2023-08-10 03:26:54

Unsecured443
Member
Registered: 2023-07-08
Posts: 20

Re: [SOLVED] 6.4 and higher causes audio distortion

Good news everyone! The patch for this issue has been merged into the linux-next branch!

The patch picked up in the linux-next branch will not work for 6.4.x mainline kernels since the additional parameter discussed before in this thread is not present in the patch. So, the patch will only work for 6.5 and above. It's **extremely unlikely** that the patch will be backported to work with 6.4.x mainline. The patch has been backported to 6.4 stable series and will be landing in 6.4.12. Thanks to @loqs for pointing that out!

As such, from what I understand, 6.4.x kernels will only have this issue fixed if:
1. You manually compile the kernel with the patch applied with the additional parameter.
2. Arch kernel maintainers manually apply the patch with the additional parameter to the kernels they distribute.

Hopefully, the patch will be picked up in the next RC for 6.5, or at least before 6.5 is promoted to stable. Otherwise, from what I understand, the patch will only be merged during the 6.6 merge window.

Here's the mailing list notice for anyone interested: LKML

Last edited by Unsecured443 (2023-08-22 23:04:10)

Offline

#25 2023-08-10 05:00:49

loqs
Member
Registered: 2014-03-06
Posts: 17,450

Re: [SOLVED] 6.4 and higher causes audio distortion

You could try the linux-regressions mailing list again.  Instead of trying to update regzbot just state the issue has been bisected to 1bf83fa6654c ("ASoC: SOF: Intel: hda-dai: Do not perform DMA cleanup during stop") and a fix is available and could it please be applied before 6.5 is released.
regressions@leemhuis.info was in the mails CC so that has already been covered and was already being followed up https://lore.kernel.org/regressions/474 … 4abd70cf33

https://lore.kernel.org/all/16915174269 … ernel.org/ confirms as a fix it should be pulled before the merge window and it is in the for-linus branch https://git.kernel.org/pub/scm/linux/ke … =for-linus

Last edited by loqs (2023-08-10 06:12:10)

Offline

Board footer

Powered by FluxBB