Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1396119
| From | Matt Fleming <matt@codeblueprint.co.uk> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 1/5] efi/capsule: Make efi_capsule_pending() lockless |
| Date | 2016-05-06 23:40 +0200 |
| Message-ID | <rvVDA-4ib-9@gated-at.bofh.it> (permalink) |
| References | <rvVDA-4ib-11@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Taking a mutex in the reboot path is bogus because we cannot sleep
with interrupts disabled, such as when rebooting due to panic(),
BUG: sleeping function called from invalid context at kernel/locking/mutex.c:97
in_atomic(): 0, irqs_disabled(): 1, pid: 7, name: rcu_sched
Call Trace:
dump_stack+0x63/0x89
___might_sleep+0xd8/0x120
__might_sleep+0x49/0x80
mutex_lock+0x20/0x50
efi_capsule_pending+0x1d/0x60
native_machine_emergency_restart+0x59/0x280
machine_emergency_restart+0x19/0x20
emergency_restart+0x18/0x20
panic+0x1ba/0x217
In this case all other CPUs will have been stopped by the time we
execute the platform reboot code, so 'capsule_pending' cannot change
under our feet. We wouldn't care even if it could since we cannot wait
for it complete.
Also, instead of relying on the external 'system_state' variable just
use a reboot notifier, so we can set 'stop_capsules' while holding
'capsule_mutex', thereby avoiding a race where system_state is updated
while we're in the middle of efi_capsule_update_locked() (since CPUs
won't have been stopped at that point).
Cc: Borislav Petkov <bp@alien8.de>
Cc: Kweh Hock Leong <hock.leong.kweh@intel.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Bryan O'Donoghue <pure.logic@nexus-software.ie>
Cc: joeyli <jlee@suse.com>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
---
drivers/firmware/efi/capsule.c | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)
diff --git a/drivers/firmware/efi/capsule.c b/drivers/firmware/efi/capsule.c
index 0de55944ac0b..4703dc9b8fbd 100644
--- a/drivers/firmware/efi/capsule.c
+++ b/drivers/firmware/efi/capsule.c
@@ -22,11 +22,12 @@ typedef struct {
} efi_capsule_block_desc_t;
static bool capsule_pending;
+static bool stop_capsules;
static int efi_reset_type = -1;
/*
* capsule_mutex serialises access to both capsule_pending and
- * efi_reset_type.
+ * efi_reset_type and stop_capsules.
*/
static DEFINE_MUTEX(capsule_mutex);
@@ -50,18 +51,13 @@ static DEFINE_MUTEX(capsule_mutex);
*/
bool efi_capsule_pending(int *reset_type)
{
- bool rv = false;
-
- mutex_lock(&capsule_mutex);
if (!capsule_pending)
- goto out;
+ return false;
if (reset_type)
*reset_type = efi_reset_type;
- rv = true;
-out:
- mutex_unlock(&capsule_mutex);
- return rv;
+
+ return true;
}
/*
@@ -176,7 +172,7 @@ efi_capsule_update_locked(efi_capsule_header_t *capsule,
* whether to force an EFI reboot), and we're racing against
* that call. Abort in that case.
*/
- if (unlikely(system_state == SYSTEM_RESTART)) {
+ if (unlikely(stop_capsules)) {
pr_warn("Capsule update raced with reboot, aborting.\n");
return -EINVAL;
}
@@ -298,3 +294,23 @@ out:
return rv;
}
EXPORT_SYMBOL_GPL(efi_capsule_update);
+
+static int capsule_reboot_notify(struct notifier_block *nb,
+ unsigned long event, void *cmd)
+{
+ mutex_lock(&capsule_mutex);
+ stop_capsules = true;
+ mutex_unlock(&capsule_mutex);
+
+ return NOTIFY_DONE;
+}
+
+static struct notifier_block capsule_reboot_nb = {
+ .notifier_call = capsule_reboot_notify,
+};
+
+static int __init capsule_reboot_register(void)
+{
+ return register_reboot_notifier(&capsule_reboot_nb);
+}
+core_initcall(capsule_reboot_register);
--
2.7.3
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[GIT PULL 0/5] EFI changes for v4.7 Matt Fleming <matt@codeblueprint.co.uk> - 2016-05-06 23:40 +0200
[PATCH 1/5] efi/capsule: Make efi_capsule_pending() lockless Matt Fleming <matt@codeblueprint.co.uk> - 2016-05-06 23:40 +0200
[tip:efi/core] efi/capsule: Make efi_capsule_pending() lockless tip-bot for Matt Fleming <tipbot@zytor.com> - 2016-05-07 08:40 +0200
[PATCH 5/5] efivarfs: Make efivarfs_file_ioctl static Matt Fleming <matt@codeblueprint.co.uk> - 2016-05-06 23:50 +0200
[tip:efi/core] efivarfs: Make efivarfs_file_ioctl() static tip-bot for Peter Jones <tipbot@zytor.com> - 2016-05-07 08:40 +0200
[PATCH 4/5] efi: Merge boolean flag arguments Matt Fleming <matt@codeblueprint.co.uk> - 2016-05-06 23:50 +0200
[tip:efi/core] efi: Merge boolean flag arguments tip-bot for Julia Lawall <tipbot@zytor.com> - 2016-05-07 08:40 +0200
[PATCH 3/5] efi/capsule: Move 'capsule' to the stack in efi_capsule_supported() Matt Fleming <matt@codeblueprint.co.uk> - 2016-05-06 23:50 +0200
[tip:efi/core] efi/capsule: Move 'capsule' to the stack in efi_capsule_supported() tip-bot for Matt Fleming <tipbot@zytor.com> - 2016-05-07 08:40 +0200
[PATCH 2/5] efibc: Fix excessive stack footprint warning Matt Fleming <matt@codeblueprint.co.uk> - 2016-05-06 23:50 +0200
[tip:efi/core] efibc: Fix excessive stack footprint warning tip-bot for Jeremy Compostella <tipbot@zytor.com> - 2016-05-07 08:40 +0200
RE: [PATCH 2/5] efibc: Fix excessive stack footprint warning "Elliott, Robert (Persistent Memory)" <elliott@hpe.com> - 2016-05-10 01:50 +0200
Re: [PATCH 2/5] efibc: Fix excessive stack footprint warning jeremy.compostella@intel.com (Compostella, Jeremy) - 2016-05-10 10:50 +0200
Re: [PATCH 2/5] efibc: Fix excessive stack footprint warning Matt Fleming <matt@codeblueprint.co.uk> - 2016-05-11 14:50 +0200
Re: [PATCH 2/5] efibc: Fix excessive stack footprint warning jeremy.compostella@intel.com (Compostella, Jeremy) - 2016-05-11 17:20 +0200
csiph-web