All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: hda: Check snd_hda_power_pm construct error before executing verb
@ 2026-07-13  2:04 songxiebing
  2026-07-13 10:13 ` Takashi Iwai
  2026-07-14  2:13 ` songxiebing
  0 siblings, 2 replies; 5+ messages in thread
From: songxiebing @ 2026-07-13  2:04 UTC (permalink / raw)
  To: tiwai, perex; +Cc: linux-sound, linux-kernel, songxiebing

From: Bob Song <songxiebing@kylinos.cn>

When userspace writes 1 to /sys/bus/pci/devices/XX/remove to remove HDA PCI device,
the codec device enters runtime suspended state early. The snd_hda_power_pm RAII
constructor fails to wake up codec, but the original code ignores pm.err and continues
to execute hda verb commands. After pci driver remove callback completes, devres
automatically iounmap the BAR virtual address bus->remap_addr, resulting in access
to invalid unmapped MMIO address and triggering page fault BUG.

Add error check for snd_hda_power_pm constructor result:
1. Detect pm construction failure when HDA core device is suspended;
2. Print warning log with command and error code for debug;
3. Return early to skip subsequent hardware register access, avoid page fault crash.

Signed-off-by: Bob Song <songxiebing@kylinos.cn>
---
 sound/hda/common/codec.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sound/hda/common/codec.c b/sound/hda/common/codec.c
index ef533770179b..69ddd153509c 100644
--- a/sound/hda/common/codec.c
+++ b/sound/hda/common/codec.c
@@ -39,6 +39,12 @@ static int call_exec_verb(struct hda_bus *bus, struct hda_codec *codec,
 	int err;
 
 	CLASS(snd_hda_power_pm, pm)(codec);
+	if (pm.err < 0 && pm_runtime_status_suspended(bus->core.dev)) {
+		codec_warn(codec,
+			   "Failed to send cmd 0x%x ret=[%d], hda control device is suspended\n",
+			   cmd, pm.err);
+		return pm.err;
+	}
 	guard(mutex)(&bus->core.cmd_mutex);
 	if (flags & HDA_RW_NO_RESPONSE_FALLBACK)
 		bus->no_response_fallback = 1;
-- 
2.25.1


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

* Re: [PATCH] ALSA: hda: Check snd_hda_power_pm construct error before executing verb
  2026-07-13  2:04 [PATCH] ALSA: hda: Check snd_hda_power_pm construct error before executing verb songxiebing
@ 2026-07-13 10:13 ` Takashi Iwai
  2026-07-14  2:13 ` songxiebing
  1 sibling, 0 replies; 5+ messages in thread
From: Takashi Iwai @ 2026-07-13 10:13 UTC (permalink / raw)
  To: songxiebing; +Cc: tiwai, perex, linux-sound, linux-kernel

On Mon, 13 Jul 2026 04:04:27 +0200,
songxiebing wrote:
> 
> From: Bob Song <songxiebing@kylinos.cn>
> 
> When userspace writes 1 to /sys/bus/pci/devices/XX/remove to remove HDA PCI device,
> the codec device enters runtime suspended state early. The snd_hda_power_pm RAII
> constructor fails to wake up codec, but the original code ignores pm.err and continues
> to execute hda verb commands. After pci driver remove callback completes, devres
> automatically iounmap the BAR virtual address bus->remap_addr, resulting in access
> to invalid unmapped MMIO address and triggering page fault BUG.
> 
> Add error check for snd_hda_power_pm constructor result:
> 1. Detect pm construction failure when HDA core device is suspended;
> 2. Print warning log with command and error code for debug;
> 3. Return early to skip subsequent hardware register access, avoid page fault crash.
> 
> Signed-off-by: Bob Song <songxiebing@kylinos.cn>

Applied to for-next branch.  Thanks.


Takashi

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

* Re: [PATCH] ALSA: hda: Check snd_hda_power_pm construct error before executing verb
@ 2026-07-14  2:07 songxiebing
  0 siblings, 0 replies; 5+ messages in thread
From: songxiebing @ 2026-07-14  2:07 UTC (permalink / raw)
  To: tiwai, perex; +Cc: linux-sound, linux-kernel, songxiebing

Hi Takashi,

At present, this patch may cause misjudgment for some platform devices.
If rpm is not enabled on the platform device, the default runtime_status is suspended,
which will result in the inability to write commands properly.

Could you please drop this patch? Sorry for the trouble.

>On Mon, 13 Jul 2026 04:04:27 +0200,
>songxiebing wrote:
>> 
>> From: Bob Song <songxiebing@kylinos.cn>
>> 
>> When userspace writes 1 to /sys/bus/pci/devices/XX/remove to remove HDA PCI device,
>> the codec device enters runtime suspended state early. The snd_hda_power_pm RAII
>> constructor fails to wake up codec, but the original code ignores pm.err and continues
>> to execute hda verb commands. After pci driver remove callback completes, devres
>> automatically iounmap the BAR virtual address bus->remap_addr, resulting in access
>> to invalid unmapped MMIO address and triggering page fault BUG.
>> 
>> Add error check for snd_hda_power_pm constructor result:
>> 1. Detect pm construction failure when HDA core device is suspended;
>> 2. Print warning log with command and error code for debug;
>> 3. Return early to skip subsequent hardware register access, avoid page fault crash.
>> 
>> Signed-off-by: Bob Song <songxiebing@kylinos.cn>
>
>Applied to for-next branch.  Thanks.
>
>
>Takashi

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

* Re: [PATCH] ALSA: hda: Check snd_hda_power_pm construct error before executing verb
  2026-07-13  2:04 [PATCH] ALSA: hda: Check snd_hda_power_pm construct error before executing verb songxiebing
  2026-07-13 10:13 ` Takashi Iwai
@ 2026-07-14  2:13 ` songxiebing
  2026-07-14  5:26   ` Takashi Iwai
  1 sibling, 1 reply; 5+ messages in thread
From: songxiebing @ 2026-07-14  2:13 UTC (permalink / raw)
  To: tiwai, perex; +Cc: linux-sound, linux-kernel, songxiebing

Hi Takashi,

At present, this patch may cause misjudgment for some platform devices.
If rpm is not enabled on the platform device, the default runtime_status is suspended,
which will result in the inability to write commands properly.

Could you please drop this patch? Sorry for the trouble.

>On Mon, 13 Jul 2026 04:04:27 +0200,
>songxiebing wrote:
>> 
>> From: Bob Song <songxiebing@kylinos.cn>
>> 
>> When userspace writes 1 to /sys/bus/pci/devices/XX/remove to remove HDA PCI device,
>> the codec device enters runtime suspended state early. The snd_hda_power_pm RAII
>> constructor fails to wake up codec, but the original code ignores pm.err and continues
>> to execute hda verb commands. After pci driver remove callback completes, devres
>> automatically iounmap the BAR virtual address bus->remap_addr, resulting in access
>> to invalid unmapped MMIO address and triggering page fault BUG.
>> 
>> Add error check for snd_hda_power_pm constructor result:
>> 1. Detect pm construction failure when HDA core device is suspended;
>> 2. Print warning log with command and error code for debug;
>> 3. Return early to skip subsequent hardware register access, avoid page fault crash.
>> 
>> Signed-off-by: Bob Song <songxiebing@kylinos.cn>
>
>Applied to for-next branch.  Thanks.
>
>
>Takashi

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

* Re: [PATCH] ALSA: hda: Check snd_hda_power_pm construct error before executing verb
  2026-07-14  2:13 ` songxiebing
@ 2026-07-14  5:26   ` Takashi Iwai
  0 siblings, 0 replies; 5+ messages in thread
From: Takashi Iwai @ 2026-07-14  5:26 UTC (permalink / raw)
  To: songxiebing; +Cc: tiwai, perex, linux-sound, linux-kernel

On Tue, 14 Jul 2026 04:13:51 +0200,
songxiebing wrote:
> 
> Hi Takashi,
> 
> At present, this patch may cause misjudgment for some platform devices.
> If rpm is not enabled on the platform device, the default runtime_status is suspended,
> which will result in the inability to write commands properly.
> 
> Could you please drop this patch? Sorry for the trouble.

OK, dropped now.


thanks,

Takashi

> >On Mon, 13 Jul 2026 04:04:27 +0200,
> >songxiebing wrote:
> >> 
> >> From: Bob Song <songxiebing@kylinos.cn>
> >> 
> >> When userspace writes 1 to /sys/bus/pci/devices/XX/remove to remove HDA PCI device,
> >> the codec device enters runtime suspended state early. The snd_hda_power_pm RAII
> >> constructor fails to wake up codec, but the original code ignores pm.err and continues
> >> to execute hda verb commands. After pci driver remove callback completes, devres
> >> automatically iounmap the BAR virtual address bus->remap_addr, resulting in access
> >> to invalid unmapped MMIO address and triggering page fault BUG.
> >> 
> >> Add error check for snd_hda_power_pm constructor result:
> >> 1. Detect pm construction failure when HDA core device is suspended;
> >> 2. Print warning log with command and error code for debug;
> >> 3. Return early to skip subsequent hardware register access, avoid page fault crash.
> >> 
> >> Signed-off-by: Bob Song <songxiebing@kylinos.cn>
> >
> >Applied to for-next branch.  Thanks.
> >
> >
> >Takashi

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

end of thread, other threads:[~2026-07-14  5:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-13  2:04 [PATCH] ALSA: hda: Check snd_hda_power_pm construct error before executing verb songxiebing
2026-07-13 10:13 ` Takashi Iwai
2026-07-14  2:13 ` songxiebing
2026-07-14  5:26   ` Takashi Iwai
  -- strict thread matches above, loose matches on Subject: below --
2026-07-14  2:07 songxiebing

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.