firmware: efi: add a separate timeout for UpdateCapsule()
PATCH 1/1 firmware: efi: add a separate timeout for UpdateCapsule()
On platforms that allows to update firmware in runtime, UpdateCapsule() may immediately write a firmware image to persistent storage. This operation can take longer than EFI_RTS_TIMEOUT.
Use a separate timeout for the UpdateCapsule() runtime service. By default, wait indefinitely to avoid interrupting an ongoing firmware update. Administrators may configure an appropriate timeout, in seconds, through /sys/firmware/efi/capsule_update_timeout.
--- drivers/firmware/efi/efi.c | 41 +++++++++++++++++++++++++ drivers/firmware/efi/runtime-wrappers.c | 14 +++------ include/linux/efi.h | 10 ++++++ 3 files changed, 55 insertions(+), 10 deletions(-)
drivers/firmware/efi/efi.c +41 -0
@@ -63,6 +63,18 @@ static unsigned long __initdata mem_reserve = EFI_INVALID_TABLE_ADDR;static unsigned long __initdata rt_prop =EFI_INVALID_TABLE_ADDR ;static unsigned long __initdata initrd =EFI_INVALID_TABLE_ADDR ; +/* +* Depending on the platform, UpdateCapsule() may update the firmware +* immediately if the platform allows to update the firmware while in runtime. +* In this case, writing the image to firmware storage may take longer than +* EFI_RTS_TIMEOUT (120 seconds). +* +* To handle this, use a separate timeout for the UpdateCapsule() runtime +* service. Wait indefinitely by default, and allow administrators to set +* an appropriate timeout in seconds through /sys/firmware/efi/capsule_update_timeout. +*/ +unsigned long efi_capsule_update_timeout =MAX_SCHEDULE_TIMEOUT ; +extern unsigned long primary_display_table;struct mm_struct efi_mm = {
@@ -163,15 +175,44 @@ static ssize_t fw_platform_size_show(struct kobject *kobj,return sprintf (buf,"%d\n" ,efi_enabled (EFI_64BIT ) ?64 :32 ); } +static ssize_t capsule_update_timeout_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%lu\n" , efi_capsule_update_timeout /HZ ); +} + +static ssize_t capsule_update_timeout_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t count) +{ +int ret; +unsigned long secs, timeout; + + ret =kstrtoul (buf,0 , &secs); +if (ret) +return ret; +if (check_mul_overflow (secs,HZ , &timeout)) + timeout =MAX_SCHEDULE_TIMEOUT ; +if (timeout <EFI_RTS_TIMEOUT ) + timeout =EFI_RTS_TIMEOUT ; + + efi_capsule_update_timeout = timeout; + +return count; +} +extern __weak struct kobj_attribute efi_attr_fw_vendor;extern __weak struct kobj_attribute efi_attr_runtime;extern __weak struct kobj_attribute efi_attr_config_table;static struct kobj_attribute efi_attr_fw_platform_size =__ATTR_RO (fw_platform_size); +static struct kobj_attribute efi_attr_capsule_update_timeout = +__ATTR_RW_MODE (capsule_update_timeout,0600 );static struct attribute *efi_subsys_attrs[] = { &efi_attr_systab.attr, &efi_attr_fw_platform_size.attr, + &efi_attr_capsule_update_timeout.attr, &efi_attr_fw_vendor.attr, &efi_attr_runtime.attr, &efi_attr_config_table.attr,
drivers/firmware/efi/runtime-wrappers.c +4 -10
@@ -118,14 +118,6 @@ union efi_rts_args {struct efi_runtime_work efi_rts_work; -/* -* Upper bound on how long we wait for a single EFI runtime service -* call to finish before declaring firmware wedged. Chosen to be longer -* than any plausible legitimate call (including UpdateCapsule on slow -* SPI-NOR) while still bounding userspace wait time. -*/ -#define EFI_RTS_TIMEOUT (120 * HZ) -/* * efi_queue_work: Queue EFI runtime service call and wait for completion * @_rts: EFI runtime service function identifier
@@ -347,6 +339,8 @@ static void __nocfi efi_call_rts(struct work_struct *work)static efi_status_t __efi_queue_work (enum efi_rts_ids id,union efi_rts_args *args) { +unsigned long timeout; +if (!efi_enabled (EFI_RUNTIME_SERVICES )) {pr_warn_once ("EFI Runtime Services are disabled!\n" );return EFI_DEVICE_ERROR ;
@@ -369,8 +363,8 @@ static efi_status_t __efi_queue_work(enum efi_rts_ids id, goto exit; } -if (!wait_for_completion_timeout (&efi_rts_work.efi_rts_comp, -EFI_RTS_TIMEOUT )) { + timeout = (id ==EFI_UPDATE_CAPSULE ) ? efi_capsule_update_timeout :EFI_RTS_TIMEOUT ; +if (!wait_for_completion_timeout (&efi_rts_work.efi_rts_comp, timeout)) {pr_err ("EFI runtime service %d wedged in firmware; disabling EFI runtime services\n" , id);clear_bit (EFI_RUNTIME_SERVICES , &efi.flags);
include/linux/efi.h +10 -0
@@ -1345,4 +1345,14 @@ extern struct blocking_notifier_head efivar_ops_nh;void efivars_generic_ops_register (void );void efivars_generic_ops_unregister (void ); +/* +* Upper bound on how long we wait for a single EFI runtime service +* call to finish before declaring firmware wedged. Chosen to be longer +* than any plausible legitimate call (excluding UpdateCapsule() while +* still bounding userspace wait time. +*/ +#define EFI_RTS_TIMEOUT (120 * HZ) + +extern unsigned long efi_capsule_update_timeout; +#endif /* _LINUX_EFI_H */
Signature · 1 line
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}Ard Biesheuvel
maintainerHello Yeoreum Yun,
Quoted 9 lines · Yeoreum Yun
On platforms that allows to update firmware in runtime,
UpdateCapsule()may immediately write a firmware image to persistent storage. This operation can take longer thanEFI_RTS_TIMEOUT.Use a separate timeout for the
UpdateCapsule()runtime service. By default, wait indefinitely to avoid interrupting an ongoing firmware update. Administrators may configure an appropriate timeout, in seconds, through/sys/firmware/efi/capsule_update_timeout.
Quoted 7 lines
Signed-off-by Yeoreum Yun <[email protected]>--- drivers/firmware/efi/efi.c | 41 +++++++++++++++++++++++++ drivers/firmware/efi/runtime-wrappers.c | 14 +++------ include/linux/efi.h | 10 ++++++ 3 files changed, 55 insertions(+), 10 deletions(-)
Given that UpdateCapsule() is rarely used these days at runtime, I wonder if we should just call it synchronously instead of via the EFI workqueue.
I assume that would also solve the timeout issue?
Quoted 139 lines
drivers/firmware/efi/efi.c +3
-0@@ -63,6 +63,18 @@ static unsigned long __initdata mem_reserve =EFI_INVALID_TABLE_ADDR ;static unsigned long __initdata rt_prop =EFI_INVALID_TABLE_ADDR ;static unsigned long __initdata initrd =EFI_INVALID_TABLE_ADDR ; +/* +* Depending on the platform, UpdateCapsule() may update the firmware +* immediately if the platform allows to update the firmware while in runtime.
+ * In this case, writing the image to firmware storage may take longer than
+ *EFI_RTS_TIMEOUT(120 seconds).
+ *
+ * To handle this, use a separate timeout for theUpdateCapsule()runtime
+ * service. Wait indefinitely by default, and allow administrators to set
+ * an appropriate timeout in seconds through/sys/firmware/efi/capsule_update_timeout.
+ */drivers/firmware/efi/efi.c +31
-0+unsigned long efi_capsule_update_timeout =MAX_SCHEDULE_TIMEOUT ; +extern unsigned long primary_display_table;struct mm_struct efi_mm = {@@ -163,15 +175,44 @@ static ssize_t fw_platform_size_show(struct kobject *kobj,return sprintf (buf,"%d\n" ,efi_enabled (EFI_64BIT ) ?64 :32 ); } +static ssize_t capsule_update_timeout_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%lu\n" , efi_capsule_update_timeout /HZ ); +} + +static ssize_t capsule_update_timeout_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t count) +{ +int ret; +unsigned long secs, timeout; + + ret =kstrtoul (buf,0 , &secs); +if (ret) +return ret; +if (check_mul_overflow (secs,HZ , &timeout)) + timeout =MAX_SCHEDULE_TIMEOUT ; +if (timeout <EFI_RTS_TIMEOUT ) + timeout =EFI_RTS_TIMEOUT ; + + efi_capsule_update_timeout = timeout; + +return count; +} +extern __weak struct kobj_attribute efi_attr_fw_vendor;extern __weak struct kobj_attribute efi_attr_runtime;extern __weak struct kobj_attribute efi_attr_config_table;static struct kobj_attribute efi_attr_fw_platform_size =__ATTR_RO (fw_platform_size); +static struct kobj_attribute efi_attr_capsule_update_timeout = +__ATTR_RW_MODE (capsule_update_timeout,0600 );static struct attribute *efi_subsys_attrs[] = { &efi_attr_systab.attr, &efi_attr_fw_platform_size.attr, + &efi_attr_capsule_update_timeout.attr, &efi_attr_fw_vendor.attr, &efi_attr_runtime.attr, &efi_attr_config_table.attr,drivers/firmware/efi/runtime-wrappers.c +4
-10@@ -118,14 +118,6 @@ union efi_rts_args {struct efi_runtime_work efi_rts_work; -/* -* Upper bound on how long we wait for a single EFI runtime service -* call to finish before declaring firmware wedged. Chosen to be longer -* than any plausible legitimate call (including UpdateCapsule on slow -* SPI-NOR) while still bounding userspace wait time. -*/ -#define EFI_RTS_TIMEOUT (120 * HZ) -/* * efi_queue_work: Queue EFI runtime service call and wait for completion * @_rts: EFI runtime service function identifier @@ -347,6 +339,8 @@ static void __nocfi efi_call_rts(struct work_struct *work)static efi_status_t __efi_queue_work (enum efi_rts_ids id,union efi_rts_args *args) { +unsigned long timeout; +if (!efi_enabled (EFI_RUNTIME_SERVICES )) {pr_warn_once ("EFI Runtime Services are disabled!\n" );return EFI_DEVICE_ERROR ;@@ -369,8 +363,8 @@ static efi_status_t __efi_queue_work(enum efi_rts_ids id, goto exit; } -if (!wait_for_completion_timeout (&efi_rts_work.efi_rts_comp, -EFI_RTS_TIMEOUT )) { + timeout = (id ==EFI_UPDATE_CAPSULE ) ? efi_capsule_update_timeout :EFI_RTS_TIMEOUT ; +if (!wait_for_completion_timeout (&efi_rts_work.efi_rts_comp, timeout)) { pr_err("EFI runtime service %d wedged in firmware; disabling EFIruntime services\n",
drivers/firmware/efi/runtime-wrappers.c +0
-0id);clear_bit (EFI_RUNTIME_SERVICES , &efi.flags);include/linux/efi.h +10
-0@@ -1345,4 +1345,14 @@ extern struct blocking_notifier_head efivar_ops_nh;void efivars_generic_ops_register (void );void efivars_generic_ops_unregister (void ); +/* +* Upper bound on how long we wait for a single EFI runtime service +* call to finish before declaring firmware wedged. Chosen to be longer +* than any plausible legitimate call (excluding UpdateCapsule() while +* still bounding userspace wait time. +*/ +#define EFI_RTS_TIMEOUT (120 * HZ) + +extern unsigned long efi_capsule_update_timeout; +#endif /*
_LINUX_EFI_H*/Signature · 1 line
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
Hi Ard,
Quoted 20 lines
Hello Yeoreum Yun,
Quoted 9 lines · Yeoreum Yun
On platforms that allows to update firmware in runtime,
UpdateCapsule()may immediately write a firmware image to persistent storage. This operation can take longer thanEFI_RTS_TIMEOUT.Use a separate timeout for the
UpdateCapsule()runtime service. By default, wait indefinitely to avoid interrupting an ongoing firmware update. Administrators may configure an appropriate timeout, in seconds, through/sys/firmware/efi/capsule_update_timeout.Quoted 7 lines
Signed-off-by Yeoreum Yun <[email protected]>--- drivers/firmware/efi/efi.c | 41 +++++++++++++++++++++++++ drivers/firmware/efi/runtime-wrappers.c | 14 +++------ include/linux/efi.h | 10 ++++++ 3 files changed, 55 insertions(+), 10 deletions(-)
Quoted 5 lines
Given that
UpdateCapsule()is rarely used these days at runtime, I wonder if we should just call it synchronously instead of via the EFI workqueue.I assume that would also solve the timeout issue?
Might be. But it would make *non-preemptible* for UpdateCapsule(). AFAIK the purpose of running runtime service with efi_queue to run it in indepdent context and to be preemtible in case of arm64.
Since most of UpdateCapsule() will be called via capsule-loader's misc device, if UpdateCaspule() is called synchronously, It would be non-preemtible in arm64 platform.
But, some platform could be preemptible while updating firmware so I think it would be better that it would be called via EFI workqueue.
[...]
Thanks!
Signature · 2 lines
Sincerely, Yeoreum Yun
Ard Biesheuvel
maintainerQuoted 26 lines · Yeoreum Yun
Hi Ard,
Quoted 24 lines
Hello Yeoreum Yun,
Quoted 9 lines · Yeoreum Yun
On platforms that allows to update firmware in runtime,
UpdateCapsule()may immediately write a firmware image to persistent storage. This operation can take longer thanEFI_RTS_TIMEOUT.Use a separate timeout for the
UpdateCapsule()runtime service. By default, wait indefinitely to avoid interrupting an ongoing firmware update. Administrators may configure an appropriate timeout, in seconds, through/sys/firmware/efi/capsule_update_timeout.Quoted 7 lines
Signed-off-by Yeoreum Yun <[email protected]>--- drivers/firmware/efi/efi.c | 41 +++++++++++++++++++++++++ drivers/firmware/efi/runtime-wrappers.c | 14 +++------ include/linux/efi.h | 10 ++++++ 3 files changed, 55 insertions(+), 10 deletions(-)Given that
UpdateCapsule()is rarely used these days at runtime, I wonder if we should just call it synchronously instead of via the EFI workqueue.
Quoted 6 lines
Quoted 1 line
I assume that would also solve the timeout issue?
Might be. But it would make *non-preemptible* for
UpdateCapsule(). AFAIK the purpose of running runtime service withefi_queueto run it in indepdent context and to be preemtible in case of arm64.
No.
Quoted 7 lines
Since most of
UpdateCapsule()will be called via capsule-loader's misc device, ifUpdateCaspule()is called synchronously, It would be non-preemtible in arm64 platform.But, some platform could be preemptible while updating firmware so I think it would be better that it would be called via EFI workqueue.
EFI runtime service invocations are preemptible on arm64, so this is not a problem.
Ard Biesheuvel
maintainerQuoted 40 lines · Ard Biesheuvel
Quoted 26 lines · Yeoreum Yun
Hi Ard,
Quoted 24 lines
Hello Yeoreum Yun,
Quoted 9 lines · Yeoreum Yun
On platforms that allows to update firmware in runtime,
UpdateCapsule()may immediately write a firmware image to persistent storage. This operation can take longer thanEFI_RTS_TIMEOUT.Use a separate timeout for the
UpdateCapsule()runtime service. By default, wait indefinitely to avoid interrupting an ongoing firmware update. Administrators may configure an appropriate timeout, in seconds, through/sys/firmware/efi/capsule_update_timeout.Quoted 7 lines
Signed-off-by Yeoreum Yun <[email protected]>--- drivers/firmware/efi/efi.c | 41 +++++++++++++++++++++++++ drivers/firmware/efi/runtime-wrappers.c | 14 +++------ include/linux/efi.h | 10 ++++++ 3 files changed, 55 insertions(+), 10 deletions(-)Given that
UpdateCapsule()is rarely used these days at runtime, I wonder if we should just call it synchronously instead of via the EFI workqueue.Quoted 6 lines
Quoted 1 line
I assume that would also solve the timeout issue?
Might be. But it would make *non-preemptible* for
UpdateCapsule(). AFAIK the purpose of running runtime service withefi_queueto run it in indepdent context and to be preemtible in case of arm64.No.
Quoted 4 lines
Since most of
UpdateCapsule()will be called via capsule-loader's misc device, ifUpdateCaspule()is called synchronously, It would be non-preemtible in arm64 platform.
Quoted 6 lines
Quoted 3 lines
But, some platform could be preemptible while updating firmware so I think it would be better that it would be called via EFI workqueue.
EFI runtime service invocations are preemptible on arm64, so this is not a problem.
Ah wait - you're right, they are only preemptible when invoked from the work queue.
Quoted 45 lines · Ard Biesheuvel
Quoted 44 lines · Yeoreum Yun
Quoted 26 lines
Hi Ard,
Quoted 24 lines
Hello Yeoreum Yun,
Quoted 9 lines · Yeoreum Yun
On platforms that allows to update firmware in runtime,
UpdateCapsule()may immediately write a firmware image to persistent storage. This operation can take longer thanEFI_RTS_TIMEOUT.Use a separate timeout for the
UpdateCapsule()runtime service. By default, wait indefinitely to avoid interrupting an ongoing firmware update. Administrators may configure an appropriate timeout, in seconds, through/sys/firmware/efi/capsule_update_timeout.Quoted 7 lines
Signed-off-by Yeoreum Yun <[email protected]>--- drivers/firmware/efi/efi.c | 41 +++++++++++++++++++++++++ drivers/firmware/efi/runtime-wrappers.c | 14 +++------ include/linux/efi.h | 10 ++++++ 3 files changed, 55 insertions(+), 10 deletions(-)Given that
UpdateCapsule()is rarely used these days at runtime, I wonder if we should just call it synchronously instead of via the EFI workqueue.Quoted 6 lines
Quoted 1 line
I assume that would also solve the timeout issue?
Might be. But it would make *non-preemptible* for
UpdateCapsule(). AFAIK the purpose of running runtime service withefi_queueto run it in indepdent context and to be preemtible in case of arm64.No.
Quoted 7 lines
Since most of
UpdateCapsule()will be called via capsule-loader's misc device, ifUpdateCaspule()is called synchronously, It would be non-preemtible in arm64 platform.But, some platform could be preemptible while updating firmware so I think it would be better that it would be called via EFI workqueue.
Quoted 5 lines
Quoted 2 lines
EFI runtime service invocations are preemptible on arm64, so this is not a problem.
Ah wait - you're right, they are only preemptible when invoked from the work queue.
Yes. That's why I think it would be better to call via EFI workqueue when I see arch_efi_call_virt_setup().
Signature · 2 lines
Sincerely, Yeoreum Yun
Quoted 45 lines
Quoted 45 lines · Ard Biesheuvel
Quoted 44 lines · Yeoreum Yun
Quoted 26 lines
Hi Ard,
Quoted 24 lines
Hello Yeoreum Yun,
Quoted 9 lines · Yeoreum Yun
On platforms that allows to update firmware in runtime,
UpdateCapsule()may immediately write a firmware image to persistent storage. This operation can take longer thanEFI_RTS_TIMEOUT.Use a separate timeout for the
UpdateCapsule()runtime service. By default, wait indefinitely to avoid interrupting an ongoing firmware update. Administrators may configure an appropriate timeout, in seconds, through/sys/firmware/efi/capsule_update_timeout.Quoted 7 lines
Signed-off-by Yeoreum Yun <[email protected]>--- drivers/firmware/efi/efi.c | 41 +++++++++++++++++++++++++ drivers/firmware/efi/runtime-wrappers.c | 14 +++------ include/linux/efi.h | 10 ++++++ 3 files changed, 55 insertions(+), 10 deletions(-)Given that
UpdateCapsule()is rarely used these days at runtime, I wonder if we should just call it synchronously instead of via the EFI workqueue.Quoted 6 lines
Quoted 1 line
I assume that would also solve the timeout issue?
Might be. But it would make *non-preemptible* for
UpdateCapsule(). AFAIK the purpose of running runtime service withefi_queueto run it in indepdent context and to be preemtible in case of arm64.No.
Quoted 7 lines
Since most of
UpdateCapsule()will be called via capsule-loader's misc device, ifUpdateCaspule()is called synchronously, It would be non-preemtible in arm64 platform.But, some platform could be preemptible while updating firmware so I think it would be better that it would be called via EFI workqueue.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
EFI runtime service invocations are preemptible on arm64, so this is not a problem.
Ah wait - you're right, they are only preemptible when invoked from the work queue.
Yes. That's why I think it would be better to call via EFI workqueue when I see
arch_efi_call_virt_setup().
Hi Ard,
Could there be any issues with doing it this way, or would there be a better approach?
Signature · 2 lines
Sincerely, Yeoreum Yun
Ard Biesheuvel
maintainerQuoted 51 lines · Yeoreum Yun
Quoted 51 lines
Quoted 50 lines · Ard Biesheuvel
Quoted 40 lines · Yeoreum Yun
Quoted 26 lines
Hi Ard,
Quoted 24 lines
Hello Yeoreum Yun,
Quoted 9 lines · Yeoreum Yun
On platforms that allows to update firmware in runtime,
UpdateCapsule()may immediately write a firmware image to persistent storage. This operation can take longer thanEFI_RTS_TIMEOUT.Use a separate timeout for the
UpdateCapsule()runtime service. By default, wait indefinitely to avoid interrupting an ongoing firmware update. Administrators may configure an appropriate timeout, in seconds, through/sys/firmware/efi/capsule_update_timeout.Quoted 7 lines
Signed-off-by Yeoreum Yun <[email protected]>--- drivers/firmware/efi/efi.c | 41 +++++++++++++++++++++++++ drivers/firmware/efi/runtime-wrappers.c | 14 +++------ include/linux/efi.h | 10 ++++++ 3 files changed, 55 insertions(+), 10 deletions(-)Given that
UpdateCapsule()is rarely used these days at runtime, I wonder if we should just call it synchronously instead of via the EFI workqueue.Quoted 6 lines
Quoted 1 line
I assume that would also solve the timeout issue?
Might be. But it would make *non-preemptible* for
UpdateCapsule(). AFAIK the purpose of running runtime service withefi_queueto run it in indepdent context and to be preemtible in case of arm64.No.
Quoted 4 lines
Since most of
UpdateCapsule()will be called via capsule-loader's misc device, ifUpdateCaspule()is called synchronously, It would be non-preemtible in arm64 platform.Quoted 6 lines
Quoted 3 lines
But, some platform could be preemptible while updating firmware so I think it would be better that it would be called via EFI workqueue.
EFI runtime service invocations are preemptible on arm64, so this is not a problem.
Ah wait - you're right, they are only preemptible when invoked from the work queue.
Quoted 8 lines
Quoted 2 lines
Yes. That's why I think it would be better to call via EFI workqueue when I see
arch_efi_call_virt_setup().Hi Ard,
Could there be any issues with doing it this way, or would there be a better approach?
Would it make sense to simply have different limits for UpdateCapsule() and for everything else? How much longer than 2 minutes do you need in the typical case?
Hi Ard,
Quoted 58 lines · Yeoreum Yun
Quoted 56 lines
Quoted 45 lines
Quoted 45 lines · Ard Biesheuvel
Quoted 44 lines · Yeoreum Yun
Quoted 26 lines
Hi Ard,
Quoted 24 lines
Hello Yeoreum Yun,
Quoted 9 lines · Yeoreum Yun
On platforms that allows to update firmware in runtime,
UpdateCapsule()may immediately write a firmware image to persistent storage. This operation can take longer thanEFI_RTS_TIMEOUT.Use a separate timeout for the
UpdateCapsule()runtime service. By default, wait indefinitely to avoid interrupting an ongoing firmware update. Administrators may configure an appropriate timeout, in seconds, through/sys/firmware/efi/capsule_update_timeout.Quoted 7 lines
Signed-off-by Yeoreum Yun <[email protected]>--- drivers/firmware/efi/efi.c | 41 +++++++++++++++++++++++++ drivers/firmware/efi/runtime-wrappers.c | 14 +++------ include/linux/efi.h | 10 ++++++ 3 files changed, 55 insertions(+), 10 deletions(-)Given that
UpdateCapsule()is rarely used these days at runtime, I wonder if we should just call it synchronously instead of via the EFI workqueue.Quoted 6 lines
Quoted 1 line
I assume that would also solve the timeout issue?
Might be. But it would make *non-preemptible* for
UpdateCapsule(). AFAIK the purpose of running runtime service withefi_queueto run it in indepdent context and to be preemtible in case of arm64.No.
Quoted 7 lines
Since most of
UpdateCapsule()will be called via capsule-loader's misc device, ifUpdateCaspule()is called synchronously, It would be non-preemtible in arm64 platform.But, some platform could be preemptible while updating firmware so I think it would be better that it would be called via EFI workqueue.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
EFI runtime service invocations are preemptible on arm64, so this is not a problem.
Ah wait - you're right, they are only preemptible when invoked from the work queue.
Yes. That's why I think it would be better to call via EFI workqueue when I see
arch_efi_call_virt_setup().Hi Ard,
Quoted 7 lines
Quoted 3 lines
Could there be any issues with doing it this way, or would there be a better approach?
Would it make sense to simply have different limits for
UpdateCapsule()and for everything else? How much longer than 2 minutes do you need in the typical case?
Although the time required to complete a firmware update depends onthe platform and other factors, such as whether the capsule contains a single firmware image or multiple images, it is generally reasonable to expect the update to complete within 10 minutes.
If, for some reason, an update is expected to take longer than 10 minutes, the sysfs interface for configuring capsule_update_timeout would be useful.
This would allow the timeout to be adjusted as needed, for example to 15 minutes, before capsule update.
Am I missing something?
Signature · 2 lines
Sincerely, Yeoreum Yun
Quoted 73 lines · Yeoreum Yun
Hi Ard,
Quoted 58 lines · Yeoreum Yun
Quoted 56 lines
Quoted 45 lines
Quoted 45 lines · Ard Biesheuvel
Quoted 44 lines · Yeoreum Yun
Quoted 26 lines
Hi Ard,
Quoted 24 lines
Hello Yeoreum Yun,
Quoted 9 lines · Yeoreum Yun
On platforms that allows to update firmware in runtime,
UpdateCapsule()may immediately write a firmware image to persistent storage. This operation can take longer thanEFI_RTS_TIMEOUT.Use a separate timeout for the
UpdateCapsule()runtime service. By default, wait indefinitely to avoid interrupting an ongoing firmware update. Administrators may configure an appropriate timeout, in seconds, through/sys/firmware/efi/capsule_update_timeout.Quoted 7 lines
Signed-off-by Yeoreum Yun <[email protected]>--- drivers/firmware/efi/efi.c | 41 +++++++++++++++++++++++++ drivers/firmware/efi/runtime-wrappers.c | 14 +++------ include/linux/efi.h | 10 ++++++ 3 files changed, 55 insertions(+), 10 deletions(-)Given that
UpdateCapsule()is rarely used these days at runtime, I wonder if we should just call it synchronously instead of via the EFI workqueue.Quoted 6 lines
Quoted 1 line
I assume that would also solve the timeout issue?
Might be. But it would make *non-preemptible* for
UpdateCapsule(). AFAIK the purpose of running runtime service withefi_queueto run it in indepdent context and to be preemtible in case of arm64.No.
Quoted 7 lines
Since most of
UpdateCapsule()will be called via capsule-loader's misc device, ifUpdateCaspule()is called synchronously, It would be non-preemtible in arm64 platform.But, some platform could be preemptible while updating firmware so I think it would be better that it would be called via EFI workqueue.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
EFI runtime service invocations are preemptible on arm64, so this is not a problem.
Ah wait - you're right, they are only preemptible when invoked from the work queue.
Yes. That's why I think it would be better to call via EFI workqueue when I see
arch_efi_call_virt_setup().Hi Ard,
Quoted 7 lines
Quoted 3 lines
Could there be any issues with doing it this way, or would there be a better approach?
Would it make sense to simply have different limits for
UpdateCapsule()and for everything else? How much longer than 2 minutes do you need in the typical case?Although the time required to complete a firmware update depends onthe platform and other factors, such as whether the capsule contains a single firmware image or multiple images, it is generally reasonable to expect the update to complete within 10 minutes.
Quoted 7 lines
If, for some reason, an update is expected to take longer than 10 minutes, the sysfs interface for configuring
capsule_update_timeoutwould be useful.This would allow the timeout to be adjusted as needed, for example to 15 minutes, before capsule update.
Am I missing something?
Gentle ping in case of forgotten.
Signature · 2 lines
Sincerely, Yeoreum Yun
Quoted 13 lines · Yeoreum Yun
Quoted 7 lines
Quoted 3 lines
Could there be any issues with doing it this way, or would there be a better approach?
Would it make sense to simply have different limits for
UpdateCapsule()and for everything else? How much longer than 2 minutes do you need in the typical case?Although the time required to complete a firmware update depends onthe platform and other factors, such as whether the capsule contains a single firmware image or multiple images, it is generally reasonable to expect the update to complete within 10 minutes.
Quoted 5 lines
If, for some reason, an update is expected to take longer than 10 minutes, the sysfs interface for configuring
capsule_update_timeoutwould be useful.This would allow the timeout to be adjusted as needed, for example to 15 minutes, before capsule update.
In this case, if you have a worker that takes 10-15 minutes, will not the workqueue stall kick in ?
Quoted 14 lines · Yeoreum Yun
Quoted 13 lines
Quoted 7 lines
Quoted 3 lines
Could there be any issues with doing it this way, or would there be a better approach?
Would it make sense to simply have different limits for
UpdateCapsule()and for everything else? How much longer than 2 minutes do you need in the typical case?Although the time required to complete a firmware update depends onthe platform and other factors, such as whether the capsule contains a single firmware image or multiple images, it is generally reasonable to expect the update to complete within 10 minutes.
Quoted 8 lines
Quoted 5 lines
If, for some reason, an update is expected to take longer than 10 minutes, the sysfs interface for configuring
capsule_update_timeoutwould be useful.This would allow the timeout to be adjusted as needed, for example to 15 minutes, before capsule update.
In this case, if you have a worker that takes 10-15 minutes, will not the workqueue stall kick in ?
Hi Breno,
Sorry for the late reply. I was on holiday.
If the default value of 30 seconds is used, it would trigger the workqueue stall warning. However, AFAIK, wq_watchdog_thresh is configurable, and platforms where the operation is expected to take longer than 30 seconds should configure it accordingly.
What I want to tell is capsule update timeout should be configurable depending on the use case, rather than hardcoded at least.
Thanks.
Signature · 2 lines
Sincerely, Yeoreum Yun
Quoted 48 lines · Ard Biesheuvel
Quoted 47 lines · Yeoreum Yun
Quoted 47 lines
Quoted 38 lines · Ard Biesheuvel
Quoted 37 lines · Yeoreum Yun
Quoted 21 lines
Hi Ard,
Quoted 19 lines
Hello Yeoreum Yun,
Quoted 16 lines · Yeoreum Yun
On platforms that allows to update firmware in runtime,
UpdateCapsule()may immediately write a firmware image to persistent storage. This operation can take longer thanEFI_RTS_TIMEOUT.Use a separate timeout for the
UpdateCapsule()runtime service. By default, wait indefinitely to avoid interrupting an ongoing firmware update. Administrators may configure an appropriate timeout, in seconds, through/sys/firmware/efi/capsule_update_timeout.Signed-off-by Yeoreum Yun <[email protected]>--- drivers/firmware/efi/efi.c | 41 +++++++++++++++++++++++++ drivers/firmware/efi/runtime-wrappers.c | 14 +++------ include/linux/efi.h | 10 ++++++ 3 files changed, 55 insertions(+), 10 deletions(-)Quoted 9 lines
Quoted 5 lines
Given that
UpdateCapsule()is rarely used these days at runtime, I wonder if we should just call it synchronously instead of via the EFI workqueue.I assume that would also solve the timeout issue?
Might be. But it would make *non-preemptible* for
UpdateCapsule(). AFAIK the purpose of running runtime service withefi_queueto run it in indepdent context and to be preemtible in case of arm64.No.
Quoted 4 lines
Since most of
UpdateCapsule()will be called via capsule-loader's misc device, ifUpdateCaspule()is called synchronously, It would be non-preemtible in arm64 platform.Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
But, some platform could be preemptible while updating firmware so I think it would be better that it would be called via EFI workqueue.
EFI runtime service invocations are preemptible on arm64, so this is not a problem.
Ah wait - you're right, they are only preemptible when invoked from the work queue.
Yes. That's why I think it would be better to call via EFI workqueue when I see
arch_efi_call_virt_setup().
Quoted 10 lines
Quoted 5 lines
Hi Ard,
Could there be any issues with doing it this way, or would there be a better approach?
Would it make sense to simply have different limits for
UpdateCapsule()and for everything else? How much longer than 2 minutes do you need in the typical case?
We are seeing >120 sec timeout for SetVariable as well on Nvidia Grace platforms with AMI firmware.
efi: EFI runtime service 7 wedged in firmware; disabling EFI runtime services
The SetVariable is called as the last step of firmware upgrade process by vthe endor's BIOS update tool (AMI AFU, capsule mode). In this case, the firmware is just slow probably due to some bug in firmware.
But I think kernel should allow the timeout to be configurable with 120 as default. This will allow users to workaround the slow firmware bug by extending the timeout temporarily.