linux-stable/drivers/firmware
Pierre Gondois 59842a9ba2 firmware: arm_sdei: Fix sleep from invalid context BUG
[ Upstream commit d2c48b2387 ]

Running a preempt-rt (v6.2-rc3-rt1) based kernel on an Ampere Altra
triggers:

  BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:46
  in_atomic(): 0, irqs_disabled(): 128, non_block: 0, pid: 24, name: cpuhp/0
  preempt_count: 0, expected: 0
  RCU nest depth: 0, expected: 0
  3 locks held by cpuhp/0/24:
    #0: ffffda30217c70d0 (cpu_hotplug_lock){++++}-{0:0}, at: cpuhp_thread_fun+0x5c/0x248
    #1: ffffda30217c7120 (cpuhp_state-up){+.+.}-{0:0}, at: cpuhp_thread_fun+0x5c/0x248
    #2: ffffda3021c711f0 (sdei_list_lock){....}-{3:3}, at: sdei_cpuhp_up+0x3c/0x130
  irq event stamp: 36
  hardirqs last  enabled at (35): [<ffffda301e85b7bc>] finish_task_switch+0xb4/0x2b0
  hardirqs last disabled at (36): [<ffffda301e812fec>] cpuhp_thread_fun+0x21c/0x248
  softirqs last  enabled at (0): [<ffffda301e80b184>] copy_process+0x63c/0x1ac0
  softirqs last disabled at (0): [<0000000000000000>] 0x0
  CPU: 0 PID: 24 Comm: cpuhp/0 Not tainted 5.19.0-rc3-rt5-[...]
  Hardware name: WIWYNN Mt.Jade Server [...]
  Call trace:
    dump_backtrace+0x114/0x120
    show_stack+0x20/0x70
    dump_stack_lvl+0x9c/0xd8
    dump_stack+0x18/0x34
    __might_resched+0x188/0x228
    rt_spin_lock+0x70/0x120
    sdei_cpuhp_up+0x3c/0x130
    cpuhp_invoke_callback+0x250/0xf08
    cpuhp_thread_fun+0x120/0x248
    smpboot_thread_fn+0x280/0x320
    kthread+0x130/0x140
    ret_from_fork+0x10/0x20

sdei_cpuhp_up() is called in the STARTING hotplug section,
which runs with interrupts disabled. Use a CPUHP_AP_ONLINE_DYN entry
instead to execute the cpuhp cb later, with preemption enabled.

SDEI originally got its own cpuhp slot to allow interacting
with perf. It got superseded by pNMI and this early slot is not
relevant anymore. [1]

Some SDEI calls (e.g. SDEI_1_0_FN_SDEI_PE_MASK) take actions on the
calling CPU. It is checked that preemption is disabled for them.
_ONLINE cpuhp cb are executed in the 'per CPU hotplug thread'.
Preemption is enabled in those threads, but their cpumask is limited
to 1 CPU.
Move 'WARN_ON_ONCE(preemptible())' statements so that SDEI cpuhp cb
don't trigger them.

Also add a check for the SDEI_1_0_FN_SDEI_PRIVATE_RESET SDEI call
which acts on the calling CPU.

[1]:
https://lore.kernel.org/all/5813b8c5-ae3e-87fd-fccc-94c9cd08816d@arm.com/

Suggested-by: James Morse <james.morse@arm.com>
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: James Morse <james.morse@arm.com>
Link: https://lore.kernel.org/r/20230216084920.144064-1-pierre.gondois@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-05-30 12:42:08 +01:00
..
arm_scmi firmware: arm_scmi: Fix device node validation for mailbox transport 2023-04-05 11:15:42 +02:00
broadcom
efi efi: Accept version 2 of memory attributes table 2023-02-22 12:47:15 +01:00
google firmware: coreboot: framebuffer: Ignore reserved pixel color bits 2023-03-11 16:31:48 +01:00
meson
tegra
arm_scpi.c firmware: arm_scpi: Ensure scpi_info is not assigned if the probe fails 2022-08-25 11:15:33 +02:00
arm_sdei.c firmware: arm_sdei: Fix sleep from invalid context BUG 2023-05-30 12:42:08 +01:00
dcdbas.c
dcdbas.h
dell_rbu.c firmware: dell_rbu: Make payload memory uncachable 2019-11-20 18:47:41 +01:00
dmi-id.c
dmi-sysfs.c firmware: dmi-sysfs: Fix memory leak in dmi_sysfs_register_handle 2022-06-14 16:59:33 +02:00
dmi_scan.c firmware: dmi: Fix unlikely out-of-bounds read in save_mem_devices 2020-01-27 14:51:19 +01:00
edd.c
iscsi_ibft.c iscsi_ibft: make ISCSI_IBFT dependson ACPI instead of ISCSI_IBFT_FIND 2019-08-16 10:12:45 +02:00
iscsi_ibft_find.c
Kconfig firmware: qcom-scm: Fix QCOM_SCM configuration 2021-05-22 10:59:32 +02:00
Makefile
memmap.c
pcdp.c
pcdp.h
psci.c arm/arm64: smccc/psci: add arm_smccc_1_1_get_conduit() 2022-03-11 10:15:11 +01:00
psci_checker.c firmware/psci: fix application of sizeof to pointer 2021-11-26 11:35:57 +01:00
qcom_scm-32.c
qcom_scm-64.c firmware: qcom: scm: Ensure 'a0' status code is treated as signed 2019-12-17 20:35:42 +01:00
qcom_scm.c firmware: qcom_scm: Clear download bit during reboot 2023-05-17 11:13:09 +02:00
qcom_scm.h
qemu_fw_cfg.c firmware: qemu_fw_cfg: fix kobject leak in probe error path 2022-01-27 09:04:14 +01:00
raspberrypi.c firmware: raspberrypi: Fix firmware calls with large buffers 2019-12-13 08:51:26 +01:00
scpi_pm_domain.c firmware: arm_scpi: Fix string overflow in SCPI genpd driver 2021-12-22 09:19:04 +01:00
ti_sci.c firmware: ti_sci: Always request response from firmware 2019-09-19 09:09:39 +02:00
ti_sci.h