mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-24 03:24:55 +08:00
e918c10265
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 commitb3c0f87746
("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:b3c0f87746
("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>
116 lines
2.4 KiB
C
116 lines
2.4 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Pvpanic Device Support
|
|
*
|
|
* Copyright (C) 2013 Fujitsu.
|
|
* Copyright (C) 2018 ZTE.
|
|
* Copyright (C) 2021 Oracle.
|
|
*/
|
|
|
|
#include <linux/io.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/kexec.h>
|
|
#include <linux/mod_devicetable.h>
|
|
#include <linux/module.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/panic_notifier.h>
|
|
#include <linux/types.h>
|
|
#include <linux/cdev.h>
|
|
#include <linux/list.h>
|
|
|
|
#include <uapi/misc/pvpanic.h>
|
|
|
|
#include "pvpanic.h"
|
|
|
|
MODULE_AUTHOR("Mihai Carabas <mihai.carabas@oracle.com>");
|
|
MODULE_DESCRIPTION("pvpanic device driver");
|
|
MODULE_LICENSE("GPL");
|
|
|
|
static struct list_head pvpanic_list;
|
|
static spinlock_t pvpanic_lock;
|
|
|
|
static void
|
|
pvpanic_send_event(unsigned int event)
|
|
{
|
|
struct pvpanic_instance *pi_cur;
|
|
|
|
if (!spin_trylock(&pvpanic_lock))
|
|
return;
|
|
|
|
list_for_each_entry(pi_cur, &pvpanic_list, list) {
|
|
if (event & pi_cur->capability & pi_cur->events)
|
|
iowrite8(event, pi_cur->base);
|
|
}
|
|
spin_unlock(&pvpanic_lock);
|
|
}
|
|
|
|
static int
|
|
pvpanic_panic_notify(struct notifier_block *nb, unsigned long code, void *unused)
|
|
{
|
|
unsigned int event = PVPANIC_PANICKED;
|
|
|
|
if (kexec_crash_loaded())
|
|
event = PVPANIC_CRASH_LOADED;
|
|
|
|
pvpanic_send_event(event);
|
|
|
|
return NOTIFY_DONE;
|
|
}
|
|
|
|
/*
|
|
* Call our notifier very early on panic, deferring the
|
|
* action taken to the hypervisor.
|
|
*/
|
|
static struct notifier_block pvpanic_panic_nb = {
|
|
.notifier_call = pvpanic_panic_notify,
|
|
.priority = INT_MAX,
|
|
};
|
|
|
|
static void pvpanic_remove(void *param)
|
|
{
|
|
struct pvpanic_instance *pi_cur, *pi_next;
|
|
struct pvpanic_instance *pi = param;
|
|
|
|
spin_lock(&pvpanic_lock);
|
|
list_for_each_entry_safe(pi_cur, pi_next, &pvpanic_list, list) {
|
|
if (pi_cur == pi) {
|
|
list_del(&pi_cur->list);
|
|
break;
|
|
}
|
|
}
|
|
spin_unlock(&pvpanic_lock);
|
|
}
|
|
|
|
int devm_pvpanic_probe(struct device *dev, struct pvpanic_instance *pi)
|
|
{
|
|
if (!pi || !pi->base)
|
|
return -EINVAL;
|
|
|
|
spin_lock(&pvpanic_lock);
|
|
list_add(&pi->list, &pvpanic_list);
|
|
spin_unlock(&pvpanic_lock);
|
|
|
|
dev_set_drvdata(dev, pi);
|
|
|
|
return devm_add_action_or_reset(dev, pvpanic_remove, pi);
|
|
}
|
|
EXPORT_SYMBOL_GPL(devm_pvpanic_probe);
|
|
|
|
static int pvpanic_init(void)
|
|
{
|
|
INIT_LIST_HEAD(&pvpanic_list);
|
|
spin_lock_init(&pvpanic_lock);
|
|
|
|
atomic_notifier_chain_register(&panic_notifier_list, &pvpanic_panic_nb);
|
|
|
|
return 0;
|
|
}
|
|
module_init(pvpanic_init);
|
|
|
|
static void pvpanic_exit(void)
|
|
{
|
|
atomic_notifier_chain_unregister(&panic_notifier_list, &pvpanic_panic_nb);
|
|
|
|
}
|
|
module_exit(pvpanic_exit);
|