linux-stable/sound/soc/sof/amd
Cristian Ciocaltea c4b603c6e2
ASoC: SOF: amd: Fix locking in ACP IRQ handler
A recent change in acp_irq_thread() was meant to address a potential race
condition while trying to acquire the hardware semaphore responsible for
the synchronization between firmware and host IPC interrupts.

This resulted in an improper use of the IPC spinlock, causing normal
kernel memory allocations (which may sleep) inside atomic contexts:

1707255557.133976 kernel: BUG: sleeping function called from invalid context at include/linux/sched/mm.h:315

...

1707255557.134757 kernel:  sof_ipc3_rx_msg+0x70/0x130 [snd_sof]
1707255557.134793 kernel:  acp_sof_ipc_irq_thread+0x1e0/0x550 [snd_sof_amd_acp]
1707255557.134855 kernel:  acp_irq_thread+0xa3/0x130 [snd_sof_amd_acp]
1707255557.134904 kernel:  ? irq_thread+0xb5/0x1e0
1707255557.134947 kernel:  ? __pfx_irq_thread_fn+0x10/0x10
1707255557.134985 kernel:  irq_thread_fn+0x23/0x60

Moreover, there are attempts to lock a mutex from the same atomic
context:

1707255557.136357 kernel: =============================
1707255557.136393 kernel: [ BUG: Invalid wait context ]
1707255557.136413 kernel: 6.8.0-rc3-next-20240206-audio-next #9 Tainted: G        W
1707255557.136432 kernel: -----------------------------
1707255557.136451 kernel: irq/66-AudioDSP/502 is trying to lock:
1707255557.136470 kernel: ffff965152f26af8 (&sb->s_type->i_mutex_key#2){+.+.}-{3:3}, at: start_creating.part.0+0x5f/0x180

...

1707255557.137429 kernel:  start_creating.part.0+0x5f/0x180
1707255557.137457 kernel:  __debugfs_create_file+0x61/0x210
1707255557.137475 kernel:  snd_sof_debugfs_io_item+0x75/0xc0 [snd_sof]
1707255557.137494 kernel:  sof_ipc3_do_rx_work+0x7cf/0x9f0 [snd_sof]
1707255557.137513 kernel:  sof_ipc3_rx_msg+0xb3/0x130 [snd_sof]
1707255557.137532 kernel:  acp_sof_ipc_irq_thread+0x1e0/0x550 [snd_sof_amd_acp]
1707255557.137551 kernel:  acp_irq_thread+0xa3/0x130 [snd_sof_amd_acp]

Fix the issues by reducing the lock scope in acp_irq_thread(), so that
it guards only the hardware semaphore acquiring attempt.  Additionally,
restore the initial locking in acp_sof_ipc_irq_thread() to synchronize
the handling of immediate replies from DSP core.

Fixes: 802134c8c2 ("ASoC: SOF: amd: Refactor spinlock_irq(&sdev->ipc_lock) sequence in irq_handler")
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
Link: https://lore.kernel.org/r/20240208234315.2182048-1-cristian.ciocaltea@collabora.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2024-02-11 16:58:50 +00:00
..
acp-common.c ASoC: SOF: amd: remove duplicated including 2023-12-15 12:58:07 +00:00
acp-dsp-offset.h ASoC: SOF: amd: Add support for signed fw image loading 2023-08-21 16:05:48 +01:00
acp-ipc.c ASoC: SOF: amd: Fix locking in ACP IRQ handler 2024-02-11 16:58:50 +00:00
acp-loader.c ASoC: SOF: amd: add option to use sram for data bin loading 2023-10-23 13:29:56 +01:00
acp-pcm.c ASoC: sof: amd: convert not to use asoc_xxx() 2023-09-25 14:16:44 +02:00
acp-probes.c ASoC: SOF: amd: Add Probe functionality support for amd platforms. 2023-07-17 06:15:35 +01:00
acp-stream.c ASoC: SOF: amd: increase SRAM inbox and outbox size to 1024 2022-09-20 19:38:04 +01:00
acp-trace.c ASoC: SOF: Modify the host trace_init parameter list to include dmab 2022-05-19 16:44:17 +01:00
acp.c ASoC: SOF: amd: Fix locking in ACP IRQ handler 2024-02-11 16:58:50 +00:00
acp.h ASoC: SOF: amd: Add acp-psp mailbox interface for iram-dram fence register modification 2023-12-19 14:02:49 +00:00
acp63.c ASoC: SOF: amd: add support for acp6.3 based platform 2023-10-23 13:29:54 +01:00
Kconfig ASoC: SOF: amd: add support for acp6.3 based platform 2023-10-23 13:29:54 +01:00
Makefile ASoC: SOF: amd: add support for acp6.3 based platform 2023-10-23 13:29:54 +01:00
pci-acp63.c ASoC: SOF: amd: add support for acp6.3 based platform 2023-10-23 13:29:54 +01:00
pci-rmb.c ASoC: Merge fixes for consistent cs42l43 schema 2023-10-10 17:07:17 +01:00
pci-rn.c ASoC: SOF: amd: Use generic names for IPC types 2023-09-19 13:49:09 +01:00
pci-vangogh.c ASoC: SOF: amd: Use generic names for IPC types 2023-09-19 13:49:09 +01:00
rembrandt.c ASoC: SOF: amd: remove acp_dai_probe() function 2023-04-03 12:15:32 +01:00
renoir.c ASoC: SOF: amd: remove acp_dai_probe() function 2023-04-03 12:15:32 +01:00
vangogh.c ASoC: SOF: amd: Enable signed firmware image loading for Vangogh platform 2023-08-21 16:05:49 +01:00