Skip to content

Commit e59310a

Browse files
Seiji Aguchiaegl
authored andcommitted
efi_pstore: Avoid deadlock in non-blocking paths
[Issue] There is a scenario which efi_pstore may hang up: - cpuA grabs efivars->lock - cpuB panics and calls smp_send_stop - smp_send_stop sends IRQ to cpuA - after 1 second, cpuB gives up on cpuA and sends an NMI instead - cpuA is now in an NMI handler while still holding efivars->lock - cpuB is deadlocked This case may happen if a firmware has a bug and cpuA is stuck talking with it. [Solution] This patch changes a spin_lock to a spin_trylock in non-blocking paths. and if the spin_lock has already taken by another cpu, it returns without accessing to a firmware to avoid the deadlock. Signed-off-by: Seiji Aguchi <seiji.aguchi@hds.com> Acked-by: Don Zickus <dzickus@redhat.com> Signed-off-by: Tony Luck <tony.luck@intel.com>
1 parent 9f244e9 commit e59310a

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎drivers/firmware/efivars.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,16 @@ static int efi_pstore_write(enum pstore_type_id type,
12091209
u64 storage_space, remaining_space, max_variable_size;
12101210
efi_status_t status = EFI_NOT_FOUND;
12111211

1212-
spin_lock(&efivars->lock);
1212+
if (pstore_cannot_block_path(reason)) {
1213+
/*
1214+
* If the lock is taken by another cpu in non-blocking path,
1215+
* this driver returns without entering firmware to avoid
1216+
* hanging up.
1217+
*/
1218+
if (!spin_trylock(&efivars->lock))
1219+
return -EBUSY;
1220+
} else
1221+
spin_lock(&efivars->lock);
12131222

12141223
/*
12151224
* Check if there is a space enough to log.

0 commit comments

Comments
 (0)