* [PATCH v4 1/2] firmware_loader: Refactor kill_pending_fw_fallback_reqs()
@ 2023-10-26 14:27 Mukesh Ojha
2023-10-26 14:27 ` [PATCH v4 2/2] firmware_loader: Abort all upcoming firmware load request once reboot triggered Mukesh Ojha
2023-10-26 21:18 ` [PATCH v4 1/2] firmware_loader: Refactor kill_pending_fw_fallback_reqs() Luis Chamberlain
0 siblings, 2 replies; 4+ messages in thread
From: Mukesh Ojha @ 2023-10-26 14:27 UTC (permalink / raw)
To: Luis Chamberlain, Russ Weight, Greg Kroah-Hartman
Cc: Rafael J. Wysocki, linux-kernel, Mukesh Ojha
Rename 'only_kill_custom' and refactor logic related to it
to be more meaningful.
Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
---
Changes in v4:
- New patch, no past revision.
drivers/base/firmware_loader/fallback.c | 4 ++--
drivers/base/firmware_loader/fallback.h | 4 ++--
drivers/base/firmware_loader/main.c | 8 ++++----
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/base/firmware_loader/fallback.c b/drivers/base/firmware_loader/fallback.c
index bf68e3947814..b3ce07160281 100644
--- a/drivers/base/firmware_loader/fallback.c
+++ b/drivers/base/firmware_loader/fallback.c
@@ -46,7 +46,7 @@ static inline int fw_sysfs_wait_timeout(struct fw_priv *fw_priv, long timeout)
static LIST_HEAD(pending_fw_head);
-void kill_pending_fw_fallback_reqs(bool only_kill_custom)
+void kill_pending_fw_fallback_reqs(bool kill_all)
{
struct fw_priv *fw_priv;
struct fw_priv *next;
@@ -54,7 +54,7 @@ void kill_pending_fw_fallback_reqs(bool only_kill_custom)
mutex_lock(&fw_lock);
list_for_each_entry_safe(fw_priv, next, &pending_fw_head,
pending_list) {
- if (!fw_priv->need_uevent || !only_kill_custom)
+ if (kill_all || !fw_priv->need_uevent)
__fw_load_abort(fw_priv);
}
mutex_unlock(&fw_lock);
diff --git a/drivers/base/firmware_loader/fallback.h b/drivers/base/firmware_loader/fallback.h
index 144148595660..ccf912bef6ca 100644
--- a/drivers/base/firmware_loader/fallback.h
+++ b/drivers/base/firmware_loader/fallback.h
@@ -13,7 +13,7 @@ int firmware_fallback_sysfs(struct firmware *fw, const char *name,
struct device *device,
u32 opt_flags,
int ret);
-void kill_pending_fw_fallback_reqs(bool only_kill_custom);
+void kill_pending_fw_fallback_reqs(bool kill_all);
void fw_fallback_set_cache_timeout(void);
void fw_fallback_set_default_timeout(void);
@@ -28,7 +28,7 @@ static inline int firmware_fallback_sysfs(struct firmware *fw, const char *name,
return ret;
}
-static inline void kill_pending_fw_fallback_reqs(bool only_kill_custom) { }
+static inline void kill_pending_fw_fallback_reqs(bool kill_all) { }
static inline void fw_fallback_set_cache_timeout(void) { }
static inline void fw_fallback_set_default_timeout(void) { }
#endif /* CONFIG_FW_LOADER_USER_HELPER */
diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c
index b58c42f1b1ce..522ccee781b4 100644
--- a/drivers/base/firmware_loader/main.c
+++ b/drivers/base/firmware_loader/main.c
@@ -1524,10 +1524,10 @@ static int fw_pm_notify(struct notifier_block *notify_block,
case PM_SUSPEND_PREPARE:
case PM_RESTORE_PREPARE:
/*
- * kill pending fallback requests with a custom fallback
- * to avoid stalling suspend.
+ * Here, kill pending fallback requests will only kill
+ * non-uevent firmware request to avoid stalling suspend.
*/
- kill_pending_fw_fallback_reqs(true);
+ kill_pending_fw_fallback_reqs(false);
device_cache_fw_images();
break;
@@ -1612,7 +1612,7 @@ static int fw_shutdown_notify(struct notifier_block *unused1,
* Kill all pending fallback requests to avoid both stalling shutdown,
* and avoid a deadlock with the usermode_lock.
*/
- kill_pending_fw_fallback_reqs(false);
+ kill_pending_fw_fallback_reqs(true);
return NOTIFY_DONE;
}
--
2.7.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v4 2/2] firmware_loader: Abort all upcoming firmware load request once reboot triggered
2023-10-26 14:27 [PATCH v4 1/2] firmware_loader: Refactor kill_pending_fw_fallback_reqs() Mukesh Ojha
@ 2023-10-26 14:27 ` Mukesh Ojha
2023-10-26 21:17 ` Luis Chamberlain
2023-10-26 21:18 ` [PATCH v4 1/2] firmware_loader: Refactor kill_pending_fw_fallback_reqs() Luis Chamberlain
1 sibling, 1 reply; 4+ messages in thread
From: Mukesh Ojha @ 2023-10-26 14:27 UTC (permalink / raw)
To: Luis Chamberlain, Russ Weight, Greg Kroah-Hartman
Cc: Rafael J. Wysocki, linux-kernel, Mukesh Ojha
There could be following scenario where there is a ongoing reboot
is going from processA which tries to call all the reboot notifier
callback and one of them is firmware reboot call which tries to
abort all the ongoing firmware userspace request under fw_lock but
there could be another processB which tries to do request firmware,
which came just after abort done from ProcessA and ask for userspace
to load the firmware and this can stop the ongoing reboot ProcessA
to stall for next 60s(default timeout) which may not be expected
behaviour everyone like to see, instead we should abort any firmware
load request which came once firmware knows about the reboot through
notification.
ProcessA ProcessB
kernel_restart_prepare
blocking_notifier_call_chain
fw_shutdown_notify
kill_pending_fw_fallback_reqs
__fw_load_abort
fw_state_aborted request_firmware
__fw_state_set firmware_fallback_sysfs
... fw_load_from_user_helper
.. ...
. ..
usermodehelper_read_trylock
fw_load_sysfs_fallback
fw_sysfs_wait_timeout
usermodehelper_disable
__usermodehelper_disable
down_write()
Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
---
Changes from v3: https://lore.kernel.org/lkml/1696482420-1329-1-git-send-email-quic_mojha@quicinc.com/
- Again renamed variable name to be more meaningful after 1/2.
Changes from v2: https://lore.kernel.org/lkml/1696431327-7369-1-git-send-email-quic_mojha@quicinc.com/
- Renamed the flag to fw_abort_load.
Changes from v1: https://lore.kernel.org/lkml/1694773288-15755-1-git-send-email-quic_mojha@quicinc.com/
- Renamed the flag to fw_load_abort.
- Kept the flag under fw_lock.
- Repharsed commit text.
drivers/base/firmware_loader/fallback.c | 6 +++++-
drivers/base/firmware_loader/firmware.h | 1 +
drivers/base/firmware_loader/main.c | 1 +
3 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/base/firmware_loader/fallback.c b/drivers/base/firmware_loader/fallback.c
index b3ce07160281..3ef0b312ae71 100644
--- a/drivers/base/firmware_loader/fallback.c
+++ b/drivers/base/firmware_loader/fallback.c
@@ -57,6 +57,10 @@ void kill_pending_fw_fallback_reqs(bool kill_all)
if (kill_all || !fw_priv->need_uevent)
__fw_load_abort(fw_priv);
}
+
+ if (kill_all)
+ fw_load_abort_all = true;
+
mutex_unlock(&fw_lock);
}
@@ -86,7 +90,7 @@ static int fw_load_sysfs_fallback(struct fw_sysfs *fw_sysfs, long timeout)
}
mutex_lock(&fw_lock);
- if (fw_state_is_aborted(fw_priv)) {
+ if (fw_load_abort_all || fw_state_is_aborted(fw_priv)) {
mutex_unlock(&fw_lock);
retval = -EINTR;
goto out;
diff --git a/drivers/base/firmware_loader/firmware.h b/drivers/base/firmware_loader/firmware.h
index bf549d6500d7..e891742ba264 100644
--- a/drivers/base/firmware_loader/firmware.h
+++ b/drivers/base/firmware_loader/firmware.h
@@ -86,6 +86,7 @@ struct fw_priv {
extern struct mutex fw_lock;
extern struct firmware_cache fw_cache;
+extern bool fw_load_abort_all;
static inline bool __fw_state_check(struct fw_priv *fw_priv,
enum fw_status status)
diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c
index 522ccee781b4..ea28102d421e 100644
--- a/drivers/base/firmware_loader/main.c
+++ b/drivers/base/firmware_loader/main.c
@@ -93,6 +93,7 @@ static inline struct fw_priv *to_fw_priv(struct kref *ref)
DEFINE_MUTEX(fw_lock);
struct firmware_cache fw_cache;
+bool fw_load_abort_all;
void fw_state_init(struct fw_priv *fw_priv)
{
--
2.7.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v4 2/2] firmware_loader: Abort all upcoming firmware load request once reboot triggered
2023-10-26 14:27 ` [PATCH v4 2/2] firmware_loader: Abort all upcoming firmware load request once reboot triggered Mukesh Ojha
@ 2023-10-26 21:17 ` Luis Chamberlain
0 siblings, 0 replies; 4+ messages in thread
From: Luis Chamberlain @ 2023-10-26 21:17 UTC (permalink / raw)
To: Mukesh Ojha
Cc: Russ Weight, Greg Kroah-Hartman, Rafael J. Wysocki, linux-kernel
On Thu, Oct 26, 2023 at 07:57:39PM +0530, Mukesh Ojha wrote:
> There could be following scenario where there is a ongoing reboot
> is going from processA which tries to call all the reboot notifier
> callback and one of them is firmware reboot call which tries to
> abort all the ongoing firmware userspace request under fw_lock but
> there could be another processB which tries to do request firmware,
> which came just after abort done from ProcessA and ask for userspace
> to load the firmware and this can stop the ongoing reboot ProcessA
> to stall for next 60s(default timeout) which may not be expected
> behaviour everyone like to see, instead we should abort any firmware
> load request which came once firmware knows about the reboot through
> notification.
>
> ProcessA ProcessB
>
> kernel_restart_prepare
> blocking_notifier_call_chain
> fw_shutdown_notify
> kill_pending_fw_fallback_reqs
> __fw_load_abort
> fw_state_aborted request_firmware
> __fw_state_set firmware_fallback_sysfs
> ... fw_load_from_user_helper
> .. ...
> . ..
> usermodehelper_read_trylock
> fw_load_sysfs_fallback
> fw_sysfs_wait_timeout
> usermodehelper_disable
> __usermodehelper_disable
> down_write()
>
> Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
> ---
Acked-by: Luis Chamberlain <mcgrof@kernel.org>
Luis
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v4 1/2] firmware_loader: Refactor kill_pending_fw_fallback_reqs()
2023-10-26 14:27 [PATCH v4 1/2] firmware_loader: Refactor kill_pending_fw_fallback_reqs() Mukesh Ojha
2023-10-26 14:27 ` [PATCH v4 2/2] firmware_loader: Abort all upcoming firmware load request once reboot triggered Mukesh Ojha
@ 2023-10-26 21:18 ` Luis Chamberlain
1 sibling, 0 replies; 4+ messages in thread
From: Luis Chamberlain @ 2023-10-26 21:18 UTC (permalink / raw)
To: Mukesh Ojha
Cc: Russ Weight, Greg Kroah-Hartman, Rafael J. Wysocki, linux-kernel
On Thu, Oct 26, 2023 at 07:57:38PM +0530, Mukesh Ojha wrote:
> Rename 'only_kill_custom' and refactor logic related to it
> to be more meaningful.
>
> Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
Acked-by: Luis Chamberlain <mcgrof@kernel.org>
Luis
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-10-26 21:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-26 14:27 [PATCH v4 1/2] firmware_loader: Refactor kill_pending_fw_fallback_reqs() Mukesh Ojha
2023-10-26 14:27 ` [PATCH v4 2/2] firmware_loader: Abort all upcoming firmware load request once reboot triggered Mukesh Ojha
2023-10-26 21:17 ` Luis Chamberlain
2023-10-26 21:18 ` [PATCH v4 1/2] firmware_loader: Refactor kill_pending_fw_fallback_reqs() Luis Chamberlain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®