linux-brain/drivers/base
Junyong Sun 1a5613b54b firmware: fix a double abort case with fw_load_sysfs_fallback
[ Upstream commit bcfbd3523f3c6eea51a74d217a8ebc5463bcb7f4 ]

fw_sysfs_wait_timeout may return err with -ENOENT
at fw_load_sysfs_fallback and firmware is already
in abort status, no need to abort again, so skip it.

This issue is caused by concurrent situation like below:
when thread 1# wait firmware loading, thread 2# may write
-1 to abort loading and wakeup thread 1# before it timeout.
so wait_for_completion_killable_timeout of thread 1# would
return remaining time which is != 0 with fw_st->status
FW_STATUS_ABORTED.And the results would be converted into
err -ENOENT in __fw_state_wait_common and transfered to
fw_load_sysfs_fallback in thread 1#.
The -ENOENT means firmware status is already at ABORTED,
so fw_load_sysfs_fallback no need to get mutex to abort again.
-----------------------------
thread 1#,wait for loading
fw_load_sysfs_fallback
 ->fw_sysfs_wait_timeout
    ->__fw_state_wait_common
       ->wait_for_completion_killable_timeout

in __fw_state_wait_common,
...
93    ret = wait_for_completion_killable_timeout(&fw_st->completion, timeout);
94    if (ret != 0 && fw_st->status == FW_STATUS_ABORTED)
95       return -ENOENT;
96    if (!ret)
97	 return -ETIMEDOUT;
98
99    return ret < 0 ? ret : 0;
-----------------------------
thread 2#, write -1 to abort loading
firmware_loading_store
 ->fw_load_abort
   ->__fw_load_abort
     ->fw_state_aborted
       ->__fw_state_set
         ->complete_all

in __fw_state_set,
...
111    if (status == FW_STATUS_DONE || status == FW_STATUS_ABORTED)
112       complete_all(&fw_st->completion);
-------------------------------------------
BTW,the double abort issue would not cause kernel panic or create an issue,
but slow down it sometimes.The change is just a minor optimization.

Signed-off-by: Junyong Sun <sunjunyong@xiaomi.com>
Acked-by: Luis Chamberlain <mcgrof@kernel.org>
Link: https://lore.kernel.org/r/1583202968-28792-1-git-send-email-sunjunyong@xiaomi.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-04-17 10:48:42 +02:00
..
firmware_loader firmware: fix a double abort case with fw_load_sysfs_fallback 2020-04-17 10:48:42 +02:00
power driver core: Remove device link creation limitation 2020-03-20 11:55:58 +01:00
regmap soundwire: fix regmap dependencies and align with other serial links 2019-10-07 18:57:27 +02:00
test driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
Kconfig firmware_loader: move kconfig FW_LOADER entries to its own file 2018-05-14 16:43:10 +02:00
Makefile dma-mapping: move all DMA mapping code to kernel/dma 2018-06-14 08:50:37 +02:00
arch_topology.c Revert "base: arch_topology: fix section mismatch build warnings" 2018-03-15 14:36:20 +01:00
attribute_container.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
base.h driver core: Establish order of operations for device_add and device_del via bitflag 2019-08-09 17:52:28 +02:00
bus.c kobject: return error code if writing /sys/.../uevent fails 2019-02-12 19:47:06 +01:00
cacheinfo.c drivers: base: cacheinfo: Ensure cpu hotplug work is done before Intel RDT 2019-07-21 09:03:03 +02:00
class.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
component.c component: do not dereference opaque pointer in debugfs 2020-02-01 09:37:03 +00:00
container.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
core.c driver core: Fix creation of device links with PM-runtime flags 2020-03-20 11:55:58 +01:00
cpu.c x86/bugs: Add ITLB_MULTIHIT bug infrastructure 2019-11-12 19:21:36 +01:00
dd.c driver core: Add device link flag DL_FLAG_AUTOPROBE_CONSUMER 2020-03-20 11:55:58 +01:00
devcon.c drivers: base: Unified device connection lookup 2018-03-22 13:10:29 +01:00
devcoredump.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
devres.c devres: Align data[] to ARCH_KMALLOC_MINALIGN 2019-02-12 19:46:56 +01:00
devtmpfs.c kernel: add ksys_unshare() helper; remove in-kernel calls to sys_unshare() 2018-04-02 20:16:06 +02:00
driver.c driver-core: return EINVAL error instead of BUG_ON() 2018-05-25 18:18:45 +02:00
firmware.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
hypervisor.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
init.c base: fix order of OF initialization 2018-07-07 17:54:29 +02:00
isa.c Merge 4.15-rc3 into driver-core-next 2017-12-11 08:50:05 +01:00
map.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
memory.c mm/memory_hotplug: fix try_offline_node() 2020-01-29 16:43:27 +01:00
module.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
node.c drivers/base/node.c: simplify unregister_memory_block_under_nodes() 2020-01-29 16:43:26 +01:00
pinctrl.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
platform-msi.c platform-msi: Free descriptors in platform_msi_domain_free() 2019-01-09 17:38:42 +01:00
platform.c driver core: platform: fix u32 greater or equal to zero comparison 2020-02-24 08:34:50 +01:00
property.c device property: Get rid of union aliasing 2018-05-17 12:47:21 +02:00
soc.c base: soc: Export soc_device_register/unregister APIs 2019-10-05 13:09:37 +02:00
syscore.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
topology.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
transport_class.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00