Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e59310ad authored by Seiji Aguchi's avatar Seiji Aguchi Committed by Tony Luck
Browse files

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: default avatarSeiji Aguchi <seiji.aguchi@hds.com>
Acked-by: default avatarDon Zickus <dzickus@redhat.com>
Signed-off-by: default avatarTony Luck <tony.luck@intel.com>
parent 9f244e9c
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -1209,6 +1209,15 @@ static int efi_pstore_write(enum pstore_type_id type,
	u64 storage_space, remaining_space, max_variable_size;
	efi_status_t status = EFI_NOT_FOUND;

	if (pstore_cannot_block_path(reason)) {
		/*
		 * If the lock is taken by another cpu in non-blocking path,
		 * this driver returns without entering firmware to avoid
		 * hanging up.
		 */
		if (!spin_trylock(&efivars->lock))
			return -EBUSY;
	} else
		spin_lock(&efivars->lock);

	/*