Commit e918c102 authored by Guilherme G. Piccoli's avatar Guilherme G. Piccoli Committed by Greg Kroah-Hartman

misc/pvpanic: Convert regular spinlock into trylock on panic path

The pvpanic driver relies on panic notifiers to execute a callback
on panic event. Such function is executed in atomic context - the
panic function disables local IRQs, preemption and all other CPUs
that aren't running the panic code.

With that said, it's dangerous to use regular spinlocks in such path,
as introduced by commit b3c0f877 ("misc/pvpanic: probe multiple instances").
This patch fixes that by replacing regular spinlocks with the trylock
safer approach.

It also fixes an old comment (about a long gone framebuffer code) and
the notifier priority - we should execute hypervisor notifiers early,
deferring this way the panic action to the hypervisor, as expected by
the users that are setting up pvpanic.

Fixes: b3c0f877 ("misc/pvpanic: probe multiple instances")
Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Mihai Carabas <mihai.carabas@oracle.com>
Cc: Shile Zhang <shile.zhang@linux.alibaba.com>
Cc: Wang ShaoBo <bobo.shaobowang@huawei.com>
Cc: zhenwei pi <pizhenwei@bytedance.com>
Signed-off-by: default avatarGuilherme G. Piccoli <gpiccoli@igalia.com>
Link: https://lore.kernel.org/r/20220427224924.592546-6-gpiccoli@igalia.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c268c0a8
...@@ -34,7 +34,9 @@ pvpanic_send_event(unsigned int event) ...@@ -34,7 +34,9 @@ pvpanic_send_event(unsigned int event)
{ {
struct pvpanic_instance *pi_cur; struct pvpanic_instance *pi_cur;
spin_lock(&pvpanic_lock); if (!spin_trylock(&pvpanic_lock))
return;
list_for_each_entry(pi_cur, &pvpanic_list, list) { list_for_each_entry(pi_cur, &pvpanic_list, list) {
if (event & pi_cur->capability & pi_cur->events) if (event & pi_cur->capability & pi_cur->events)
iowrite8(event, pi_cur->base); iowrite8(event, pi_cur->base);
...@@ -55,9 +57,13 @@ pvpanic_panic_notify(struct notifier_block *nb, unsigned long code, void *unused ...@@ -55,9 +57,13 @@ pvpanic_panic_notify(struct notifier_block *nb, unsigned long code, void *unused
return NOTIFY_DONE; return NOTIFY_DONE;
} }
/*
* Call our notifier very early on panic, deferring the
* action taken to the hypervisor.
*/
static struct notifier_block pvpanic_panic_nb = { static struct notifier_block pvpanic_panic_nb = {
.notifier_call = pvpanic_panic_notify, .notifier_call = pvpanic_panic_notify,
.priority = 1, /* let this called before broken drm_fb_helper() */ .priority = INT_MAX,
}; };
static void pvpanic_remove(void *param) static void pvpanic_remove(void *param)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment