linux-stable/sound/soc/sof
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
..
amd ASoC: SOF: amd: Fix locking in ACP IRQ handler 2024-02-11 16:58:50 +00:00
imx ASoC: SOF: imx: Add SNDRV_PCM_INFO_BATCH flag 2023-12-29 02:09:02 +00:00
intel ASoC: Updates for v6.8 2024-01-08 08:18:02 +01:00
mediatek ASoC: SOF: mediatek: mt8186: Revert Add Google Steelix topology compatible 2023-12-06 16:31:09 +00:00
xtensa ASoC: SOF: Xtensa: dump ar registers to restore call stack 2023-09-19 13:48:44 +01:00
compress.c ASoC: SOF: Use no_reply calls for TX 2023-04-20 12:51:45 +01:00
control.c ASoC: SOF: control: Extend the optionality of IPC ops to IPC as well 2022-12-25 23:32:33 +00:00
core.c ASoC: SOF: Move sof_of_machine_select() to core.c from sof-of-dev.c 2023-12-04 17:02:15 +00:00
debug.c ASoC: SOF: debug: conditionally bump runtime_pm counter on exceptions 2023-05-15 10:20:57 +09:00
fw-file-profile.c ASoC: SOF: core: Implement IPC version fallback if firmware files are missing 2023-11-29 13:25:15 +00:00
iomem-utils.c
ipc.c ASoC: SOF: Use generic names for IPC types 2023-09-19 13:49:08 +01:00
ipc3-control.c ASoC: sof: Improve sof_ipc3_bytes_ext_put function 2023-05-23 19:31:14 +01:00
ipc3-dtrace.c ASoC: SOF: icp3-dtrace: Revert "Fix wrong kfree() usage" 2024-01-12 14:13:52 +00:00
ipc3-loader.c ASoC: SOF: Introduce container struct for SOF firmware 2022-10-21 13:04:54 +01:00
ipc3-pcm.c ASoC: SOF: Add support for configuring PDM interface from topology 2023-11-13 00:43:06 +00:00
ipc3-priv.h ASoC: SOF: Refactor rx function for fuzzing 2023-06-09 10:44:39 +01:00
ipc3-topology.c ASoC: SOF: ipc3-topology: Fix pipeline tear down logic 2024-02-08 14:03:24 +00:00
ipc3.c ASoC: SOF: ipc3: Use devm_kmemdup to replace devm_kmalloc + memcpy 2023-08-14 19:44:39 +01:00
ipc4-control.c ASoC: Updates for v6.8 2024-01-08 08:18:02 +01:00
ipc4-fw-reg.h ASoC: SOF: add ipc4_fw_reg header file 2023-02-03 12:03:48 +00:00
ipc4-loader.c ASoC: SOF: ipc4-loader: remove the CPC check warnings 2024-01-15 14:04:52 +00:00
ipc4-mtrace.c ASoC: SOF: ipc4-mtrace: move debug slot related definitions to header.h 2023-09-19 13:48:45 +01:00
ipc4-pcm.c ASoC: SOF: ipc4-pcm: remove log message for LLP 2024-01-15 14:04:51 +00:00
ipc4-priv.h ASoC: SOF: IPC4: query fw_context_save feature from fw 2023-12-15 12:57:56 +00:00
ipc4-telemetry.c ASoC: SOF: ipc4: add definition of telemetry slot for exception handling 2023-09-19 13:48:47 +01:00
ipc4-telemetry.h ASoC: SOF: ipc4: add definition of telemetry slot for exception handling 2023-09-19 13:48:47 +01:00
ipc4-topology.c ASoC: Updates for v6.8 2024-01-08 08:18:02 +01:00
ipc4-topology.h ASoC: SOF: ipc4-topology: Correct data structures for the GAIN module 2023-12-01 14:13:03 +00:00
ipc4.c ASoC: SOF: ipc4: Move window offset configuration earlier 2023-11-29 13:25:26 +00:00
Kconfig ASoC: SOF: core: Implement IPC version fallback if firmware files are missing 2023-11-29 13:25:15 +00:00
loader.c ASoC: SOF: loader: Remove log prefixes for snd_sof_run_firmware 2023-03-07 13:58:16 +00:00
Makefile ASoC: SOF: core: Implement firmware, topology path setup in core 2023-11-29 13:25:09 +00:00
nocodec.c ASoC: sof: convert not to use asoc_xxx() 2023-09-26 17:18:42 +02:00
ops.c
ops.h ASoC: SOF: Make return of remove_late void, too 2023-10-25 08:38:35 +02:00
pcm.c ASoC: sof: convert not to use asoc_xxx() 2023-09-26 17:18:42 +02:00
pm.c ASoC: SOF: pm: Remove duplicated code in sof_suspend 2023-06-16 12:53:53 +01:00
sof-acpi-dev.c ASoC: SOF: sof-acpi-dev: Rely on core to create the file paths 2023-11-29 13:25:10 +00:00
sof-acpi-dev.h ASoC: SOF: Convert to platform remove callback returning void 2023-10-10 19:21:04 +01:00
sof-audio.c ASoC: Updates for v6.8 2024-01-08 08:18:02 +01:00
sof-audio.h ASoC: Updates for v6.8 2024-01-08 08:18:02 +01:00
sof-client-ipc-flood-test.c ASoC: SOF: Use no_reply calls for TX 2023-04-20 12:51:45 +01:00
sof-client-ipc-kernel-injector.c ASoC: SOF: Add IPC3 Kernel Injector 2023-06-09 10:44:40 +01:00
sof-client-ipc-msg-injector.c ASoC: SOF: Use generic names for IPC types 2023-09-19 13:49:08 +01:00
sof-client-probes-ipc3.c ASoC: SOF: Use no_reply calls for TX 2023-04-20 12:51:45 +01:00
sof-client-probes-ipc4.c ASoC: SOF: sof-client-probes-ipc4: add checks to prevent static analysis warnings 2023-07-31 23:22:12 +01:00
sof-client-probes.c ASoC: sof: use snd_soc_dummy_dlc 2023-12-19 13:23:45 +00:00
sof-client-probes.h ASoC: SOF: IPC4: probes: Implement IPC4 ops for probes client device 2022-10-31 13:20:22 +00:00
sof-client.c ASoC: SOF: sof-client: trivial: fix comment typo 2023-11-07 11:10:19 +00:00
sof-client.h ASoC: SOF: Add IPC3 Kernel Injector 2023-06-09 10:44:40 +01:00
sof-of-dev.c ASoC: SOF: Move sof_of_machine_select() to core.c from sof-of-dev.c 2023-12-04 17:02:15 +00:00
sof-of-dev.h ASoC: SOF: Move sof_of_machine_select() to core.c from sof-of-dev.c 2023-12-04 17:02:15 +00:00
sof-pci-dev.c ASoC: SOF: sof-pci-dev: Rely on core to create the file paths 2023-11-29 13:25:12 +00:00
sof-pci-dev.h
sof-priv.h ASoC: SOF: core: Implement firmware, topology path setup in core 2023-11-29 13:25:09 +00:00
sof-utils.c
sof-utils.h
stream-ipc.c ASoC: SOF: Add support for compress API for stream data/offset 2023-01-17 13:37:53 +00:00
topology.c ASoC: Updates for v6.8 2024-01-08 08:18:02 +01:00
trace.c ASoC: SOF: trace: No need to check for op pointer in sof_fw_trace_free() 2022-12-25 23:32:39 +00:00