bianbu-linux-6.6/drivers/platform/x86/intel
Srinivas Pandruvada 17da2d5f93 platform/x86: ISST: Fix possible circular locking dependency detected
As reported:

[  256.104522] ======================================================
[  256.113783] WARNING: possible circular locking dependency detected
[  256.120093] 5.16.0-rc6-yocto-standard+ #99 Not tainted
[  256.125362] ------------------------------------------------------
[  256.131673] intel-speed-sel/844 is trying to acquire lock:
[  256.137290] ffffffffc036f0d0 (punit_misc_dev_lock){+.+.}-{3:3}, at: isst_if_open+0x18/0x90 [isst_if_common]
[  256.147171]
[  256.147171] but task is already holding lock:
[  256.153135] ffffffff8ee7cb50 (misc_mtx){+.+.}-{3:3}, at: misc_open+0x2a/0x170
[  256.160407]
[  256.160407] which lock already depends on the new lock.
[  256.160407]
[  256.168712]
[  256.168712] the existing dependency chain (in reverse order) is:
[  256.176327]
[  256.176327] -> #1 (misc_mtx){+.+.}-{3:3}:
[  256.181946]        lock_acquire+0x1e6/0x330
[  256.186265]        __mutex_lock+0x9b/0x9b0
[  256.190497]        mutex_lock_nested+0x1b/0x20
[  256.195075]        misc_register+0x32/0x1a0
[  256.199390]        isst_if_cdev_register+0x65/0x180 [isst_if_common]
[  256.205878]        isst_if_probe+0x144/0x16e [isst_if_mmio]
...
[  256.241976]
[  256.241976] -> #0 (punit_misc_dev_lock){+.+.}-{3:3}:
[  256.248552]        validate_chain+0xbc6/0x1750
[  256.253131]        __lock_acquire+0x88c/0xc10
[  256.257618]        lock_acquire+0x1e6/0x330
[  256.261933]        __mutex_lock+0x9b/0x9b0
[  256.266165]        mutex_lock_nested+0x1b/0x20
[  256.270739]        isst_if_open+0x18/0x90 [isst_if_common]
[  256.276356]        misc_open+0x100/0x170
[  256.280409]        chrdev_open+0xa5/0x1e0
...

The call sequence suggested that misc_device /dev file can be opened
before misc device is yet to be registered, which is done only once.

Here punit_misc_dev_lock was used as common lock, to protect the
registration by multiple ISST HW drivers, one time setup, prevent
duplicate registry of misc device and prevent load/unload when device
is open.

We can split into locks:
- One which just prevent duplicate call to misc_register() and one
time setup. Also never call again if the misc_register() failed or
required one time setup is failed. This lock is not shared with
any misc device callbacks.

- The other lock protects registry, load and unload of HW drivers.

Sequence in isst_if_cdev_register()
- Register callbacks under punit_misc_dev_open_lock
- Call isst_misc_reg() which registers misc_device on the first
registry which is under punit_misc_dev_reg_lock, which is not
shared with callbacks.

Sequence in isst_if_cdev_unregister
Just opposite of isst_if_cdev_register

Reported-and-tested-by: Liwei Song <liwei.song@windriver.com>
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Link: https://lore.kernel.org/r/20220112022521.54669-1-srinivas.pandruvada@linux.intel.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2022-01-24 10:41:46 +01:00
..
atomisp2 platform/x86: intel_atomisp2: Move to intel sub-directory 2021-08-20 20:11:23 +02:00
int33fe platform/x86: intel_cht_int33fe: Use the new i2c_acpi_client_count() helper 2021-08-12 17:26:37 +02:00
int1092 platform/x86: int1092: Fix non sequential device mode handling 2021-10-11 16:38:32 +02:00
int3472 platform/x86: int3472: Add board data for Surface Go 3 2022-01-08 16:55:21 +01:00
pmc platform/x86: intel_pmc_core: fix memleak on registration failure 2021-12-23 19:30:32 +01:00
pmt platform/x86/intel: Move intel_pmt from MFD to Auxiliary Bus 2021-12-22 13:56:19 +01:00
speed_select_if platform/x86: ISST: Fix possible circular locking dependency detected 2022-01-24 10:41:46 +01:00
telemetry platform/x86: intel_telemetry: Move to intel sub-directory 2021-08-20 20:08:09 +02:00
wmi platform/x86: intel-wmi-thunderbolt: Move to intel sub-directory 2021-08-20 20:11:23 +02:00
bxtwc_tmu.c platform/x86: intel_bxtwc_tmu: Move to intel sub-directory 2021-08-20 20:00:02 +02:00
chtdc_ti_pwrbtn.c platform/x86: intel_chtdc_ti_pwrbtn: Move to intel sub-directory 2021-08-20 20:00:02 +02:00
crystal_cove_charger.c platform/x86: intel_crystal_cove_charger: Fix IRQ masking / unmasking 2022-01-24 10:41:46 +01:00
hid.c platform/x86/intel: hid: add quirk to support Surface Go 3 2021-12-06 22:28:18 +01:00
int0002_vgpio.c platform/x86: intel_int0002_vgpio: Use the new soc_intel_is_byt()/_cht() helpers 2021-10-19 17:31:24 +02:00
ishtp_eclite.c HID: intel-ish-hid: fix module device-id handling 2021-11-11 22:45:40 +01:00
Kconfig driver core changes for 5.17-rc1 2022-01-12 11:11:34 -08:00
Makefile driver core changes for 5.17-rc1 2022-01-12 11:11:34 -08:00
mrfld_pwrbtn.c platform/x86: intel_mrfld_pwrbtn: Move to intel sub-directory 2021-08-20 20:00:02 +02:00
oaktrail.c platform/x86: intel_oaktrail: Move to intel sub-directory 2021-08-20 20:11:23 +02:00
punit_ipc.c platform/x86/intel: punit_ipc: Drop wrong use of ACPI_PTR() 2021-09-13 10:36:52 +02:00
rst.c platform/x86: intel-rst: Move to intel sub-directory 2021-08-20 20:09:43 +02:00
smartconnect.c platform/x86: intel-smartconnect: Move to intel sub-directory 2021-08-20 20:11:12 +02:00
turbo_max_3.c platform/x86: intel_turbo_max_3: Move to intel sub-directory 2021-08-20 20:11:22 +02:00
uncore-frequency.c platform/x86: intel-uncore-frequency: use default_groups in kobj_type 2021-12-30 19:32:24 +01:00
vbtn.c platform/x86: intel-vbtn: Move to intel sub-directory 2021-08-20 20:11:23 +02:00
vsec.c platform/x86/intel: Move intel_pmt from MFD to Auxiliary Bus 2021-12-22 13:56:19 +01:00
vsec.h platform/x86/intel: Move intel_pmt from MFD to Auxiliary Bus 2021-12-22 13:56:19 +01:00