Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 b3c0f8774668 ("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: b3c0f8774668 ("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: Guilherme G. Piccoli <gpiccoli@igalia.com>
Link: https://lore.kernel.org/r/20220427224924.592546-6-gpiccoli@igalia.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Guilherme G. Piccoli and committed by
Greg Kroah-Hartman
e918c102 c268c0a8

+8 -2
+8 -2
drivers/misc/pvpanic/pvpanic.c
··· 34 34 { 35 35 struct pvpanic_instance *pi_cur; 36 36 37 - spin_lock(&pvpanic_lock); 37 + if (!spin_trylock(&pvpanic_lock)) 38 + return; 39 + 38 40 list_for_each_entry(pi_cur, &pvpanic_list, list) { 39 41 if (event & pi_cur->capability & pi_cur->events) 40 42 iowrite8(event, pi_cur->base); ··· 57 55 return NOTIFY_DONE; 58 56 } 59 57 58 + /* 59 + * Call our notifier very early on panic, deferring the 60 + * action taken to the hypervisor. 61 + */ 60 62 static struct notifier_block pvpanic_panic_nb = { 61 63 .notifier_call = pvpanic_panic_notify, 62 - .priority = 1, /* let this called before broken drm_fb_helper() */ 64 + .priority = INT_MAX, 63 65 }; 64 66 65 67 static void pvpanic_remove(void *param)