2021-02-12 20:22:11

by Mihai Carabas

[permalink] [raw]
Subject: [PATCH v3] add support for pci in the pvpanic driver

This patchset adds support for PCI in the pvpanic driver. The device already
got in qemu [1].

v2:
- mmio -> MMIO, pci -> PCI suggested by Randy Dunlap.
- group pvpanic-common.c and mmio.c in the same module. The intention was to
have only one module and the common code splitted up to be re-used by the
pvpanic-pci module in the next patch.
- add a new patch where add the licenses for the new files (when I moved the
code to mmio.c I preserved the original licenses there)
- properly clean-up PCI device when driver removed.

v3:
- drop patch 3 with licenses and add them when creating files
- create a new patch (2/3) which allowes multiple pvpanic instances

How to test:

Run a VM with latest qemu which has the pvpanic-pci device:
qemu-system-aarch64 -device pvpanic-pci

Generate a panic in the guest:
echo 1 > /proc/sys/kernel/sysrq
echo c > /proc/sysrq-trigger

Observe in the QMP console the panic events received by the device:

{"timestamp": {"seconds": 1613122186, "microseconds": 141729}, "event":
"GUEST_PANICKED", "data": {"action": "pause"}}

{"timestamp": {"seconds": 1613122186, "microseconds": 141833}, "event":
"GUEST_PANICKED", "data": {"action": "poweroff"}}

{"timestamp": {"seconds": 1613122186, "microseconds": 141896}, "event":
"SHUTDOWN", "data": {"guest": true, "reason": "guest-panic"}}


[1] https://github.com/qemu/qemu/commit/9df52f58e76e904fb141b10318362d718f470db2


Mihai Carabas (3):
misc/pvpanic: split-up generic and platform dependent code
misc/pvpanic: probe multiple instances
misc/pvpanic: add PCI driver

drivers/misc/Kconfig | 9 +--
drivers/misc/Makefile | 2 +-
drivers/misc/pvpanic.c | 111 ---------------------------------
drivers/misc/pvpanic/Kconfig | 25 ++++++++
drivers/misc/pvpanic/Makefile | 9 +++
drivers/misc/pvpanic/pvpanic-mmio.c | 82 ++++++++++++++++++++++++
drivers/misc/pvpanic/pvpanic-pci.c | 54 ++++++++++++++++
drivers/misc/pvpanic/pvpanic.c | 120 ++++++++++++++++++++++++++++++++++++
drivers/misc/pvpanic/pvpanic.h | 16 +++++
9 files changed, 308 insertions(+), 120 deletions(-)
delete mode 100644 drivers/misc/pvpanic.c
create mode 100644 drivers/misc/pvpanic/Kconfig
create mode 100644 drivers/misc/pvpanic/Makefile
create mode 100644 drivers/misc/pvpanic/pvpanic-mmio.c
create mode 100644 drivers/misc/pvpanic/pvpanic-pci.c
create mode 100644 drivers/misc/pvpanic/pvpanic.c
create mode 100644 drivers/misc/pvpanic/pvpanic.h

--
1.8.3.1


2021-02-12 20:22:22

by Mihai Carabas

[permalink] [raw]
Subject: [PATCH v3 2/3] misc/pvpanic: probe multiple instances

Create the mecahism that allows multiple pvpanic instances to call
pvpanic_probe and receive panic events. A global list will retain all the
mapped addresses where to write panic events.

Signed-off-by: Mihai Carabas <[email protected]>
---
drivers/misc/pvpanic/pvpanic-mmio.c | 9 ++---
drivers/misc/pvpanic/pvpanic.c | 76 ++++++++++++++++++++++++++++++++-----
drivers/misc/pvpanic/pvpanic.h | 5 +--
3 files changed, 73 insertions(+), 17 deletions(-)

diff --git a/drivers/misc/pvpanic/pvpanic-mmio.c b/drivers/misc/pvpanic/pvpanic-mmio.c
index 7454eeb..5425369 100644
--- a/drivers/misc/pvpanic/pvpanic-mmio.c
+++ b/drivers/misc/pvpanic/pvpanic-mmio.c
@@ -22,11 +22,12 @@
MODULE_DESCRIPTION("pvpanic device driver");
MODULE_LICENSE("GPL");

+static void __iomem *base;
+
static int pvpanic_mmio_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct resource *res;
- void __iomem *base;

res = platform_get_mem_or_io(pdev, 0);
if (!res)
@@ -47,15 +48,13 @@ static int pvpanic_mmio_probe(struct platform_device *pdev)
return -EINVAL;
}

- pvpanic_probe(base);
-
- return 0;
+ return pvpanic_probe(base);
}

static int pvpanic_mmio_remove(struct platform_device *pdev)
{

- pvpanic_remove();
+ pvpanic_remove(base);

return 0;
}
diff --git a/drivers/misc/pvpanic/pvpanic.c b/drivers/misc/pvpanic/pvpanic.c
index 652ae01..43b65a3 100644
--- a/drivers/misc/pvpanic/pvpanic.c
+++ b/drivers/misc/pvpanic/pvpanic.c
@@ -14,15 +14,30 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/types.h>
+#include <linux/cdev.h>
+#include <linux/list.h>
+#include <linux/slab.h>

#include <uapi/misc/pvpanic.h>

-static void __iomem *base;
+struct pvpanic_instance {
+ void __iomem *base;
+ struct list_head list;
+};
+
+struct list_head pvpanic_list;
+spinlock_t pvpanic_lock;

static void
pvpanic_send_event(unsigned int event)
{
- iowrite8(event, base);
+ struct pvpanic_instance *pi_cur;
+
+ spin_lock(&pvpanic_lock);
+ list_for_each_entry(pi_cur, &pvpanic_list, list) {
+ iowrite8(event, pi_cur->base);
+ }
+ spin_unlock(&pvpanic_lock);
}

static int
@@ -44,19 +59,62 @@
.priority = 1, /* let this called before broken drm_fb_helper */
};

-void pvpanic_probe(void __iomem *pbase)
+int pvpanic_probe(void __iomem *pbase)
{
- base = pbase;
- atomic_notifier_chain_register(&panic_notifier_list,
- &pvpanic_panic_nb);
+ struct pvpanic_instance *pi;
+
+ if(!pbase)
+ return -EINVAL;
+
+ pi = kmalloc(sizeof(*pi), GFP_ATOMIC);
+ if (!pi)
+ return -ENOMEM;
+
+ pi->base = pbase;
+ spin_lock(&pvpanic_lock);
+ list_add(&pi->list, &pvpanic_list);
+ spin_unlock(&pvpanic_lock);
+
+ return 0;
}
EXPORT_SYMBOL_GPL(pvpanic_probe);

-void pvpanic_remove(void)
+void pvpanic_remove(void __iomem *pbase)
+{
+ struct pvpanic_instance *pi_cur, *pi_next;
+
+ if(!pbase)
+ return -EINVAL;
+
+ spin_lock(&pvpanic_lock);
+ list_for_each_entry_safe(pi_cur, pi_next, &pvpanic_list, list) {
+ if (pi_cur->base == pbase) {
+ list_del(&pi_cur->list);
+ kfree(pi_cur);
+ break;
+ }
+ }
+ spin_unlock(&pvpanic_lock);
+}
+EXPORT_SYMBOL_GPL(pvpanic_remove);
+
+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;
+}
+
+static void pvpanic_exit(void)
+{
atomic_notifier_chain_unregister(&panic_notifier_list,
&pvpanic_panic_nb);
- base = NULL;
+
}
-EXPORT_SYMBOL_GPL(pvpanic_remove);
+
+module_init(pvpanic_init);
+module_exit(pvpanic_exit);
diff --git a/drivers/misc/pvpanic/pvpanic.h b/drivers/misc/pvpanic/pvpanic.h
index 7e75dce..02023d7 100644
--- a/drivers/misc/pvpanic/pvpanic.h
+++ b/drivers/misc/pvpanic/pvpanic.h
@@ -8,10 +8,9 @@
#ifndef PVPANIC_H_
#define PVPANIC_H_

-
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

-void pvpanic_probe(void __iomem *base);
-void pvpanic_remove(void);
+int pvpanic_probe(void __iomem *base);
+void pvpanic_remove(void __iomem *base);

#endif /* PVPANIC_H_ */
--
1.8.3.1

2021-02-12 20:22:22

by Mihai Carabas

[permalink] [raw]
Subject: [PATCH v3 3/3] misc/pvpanic: add PCI driver

Add support for pvpanic PCI device added in qemu [1]. At probe time, obtain the
address where to read/write pvpanic events and pass it to the generic handling
code. Will follow the same logic as pvpanic MMIO device driver. At remove time,
unmap base address and disable PCI device.

[1] https://github.com/qemu/qemu/commit/9df52f58e76e904fb141b10318362d718f470db2

Signed-off-by: Mihai Carabas <[email protected]>
---
drivers/misc/pvpanic/Kconfig | 6 +++++
drivers/misc/pvpanic/Makefile | 1 +
drivers/misc/pvpanic/pvpanic-pci.c | 54 ++++++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+)
create mode 100644 drivers/misc/pvpanic/pvpanic-pci.c

diff --git a/drivers/misc/pvpanic/Kconfig b/drivers/misc/pvpanic/Kconfig
index 454f1ee..9a081ed 100644
--- a/drivers/misc/pvpanic/Kconfig
+++ b/drivers/misc/pvpanic/Kconfig
@@ -17,3 +17,9 @@ config PVPANIC_MMIO
depends on HAS_IOMEM && (ACPI || OF) && PVPANIC
help
This driver provides support for the MMIO pvpanic device.
+
+config PVPANIC_PCI
+ tristate "pvpanic PCI device support"
+ depends on PCI && PVPANIC
+ help
+ This driver provides support for the PCI pvpanic device.
diff --git a/drivers/misc/pvpanic/Makefile b/drivers/misc/pvpanic/Makefile
index 91d816b..b02a95f 100644
--- a/drivers/misc/pvpanic/Makefile
+++ b/drivers/misc/pvpanic/Makefile
@@ -6,3 +6,4 @@
#
obj-$(CONFIG_PVPANIC) += pvpanic.o
obj-$(CONFIG_PVPANIC_MMIO) += pvpanic-mmio.o
+obj-$(CONFIG_PVPANIC_PCI) += pvpanic-pci.o
diff --git a/drivers/misc/pvpanic/pvpanic-pci.c b/drivers/misc/pvpanic/pvpanic-pci.c
new file mode 100644
index 00000000..af94ab8
--- /dev/null
+++ b/drivers/misc/pvpanic/pvpanic-pci.c
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Pvpanic PCI Device Support
+ *
+ * Copyright (C) 2021 Oracle.
+*/
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/types.h>
+#include "pvpanic.h"
+
+#define PCI_VENDOR_ID_REDHAT 0x1b36
+#define PCI_DEVICE_ID_REDHAT_PVPANIC 0x0011
+
+static void __iomem *base;
+static const struct pci_device_id pvpanic_pci_id_tbl[] = {
+ { PCI_DEVICE(PCI_VENDOR_ID_REDHAT, PCI_DEVICE_ID_REDHAT_PVPANIC),},
+ {}
+};
+
+static int pvpanic_pci_probe(struct pci_dev *pdev,
+ const struct pci_device_id *ent)
+{
+ int ret;
+ struct resource res;
+
+ ret = pci_enable_device(pdev);
+ if (ret < 0)
+ return ret;
+
+ base = pci_iomap(pdev, 0, 0);
+ if (IS_ERR(base))
+ return PTR_ERR(base);
+
+ return pvpanic_probe(base);
+}
+
+static void pvpanic_pci_remove(struct pci_dev *pdev)
+{
+ pvpanic_remove(base);
+ iounmap(base);
+ pci_disable_device(pdev);
+}
+
+static struct pci_driver pvpanic_pci_driver = {
+ .name = "pvpanic-pci",
+ .id_table = pvpanic_pci_id_tbl,
+ .probe = pvpanic_pci_probe,
+ .remove = pvpanic_pci_remove,
+};
+
+module_pci_driver(pvpanic_pci_driver);
--
1.8.3.1

2021-02-12 20:26:02

by Mihai Carabas

[permalink] [raw]
Subject: [PATCH v3 1/3] misc/pvpanic: split-up generic and platform dependent code

Split-up generic and platform dependent code in order to be able to re-use
generic event handling code in pvpanic PCI device driver in the next patches.

The code from pvpanic.c was split in two new files:
- pvpanic.c: generic code that handles pvpanic events
- pvpanic-mmio.c: platform/bus dependent code

Signed-off-by: Mihai Carabas <[email protected]>
---
drivers/misc/Kconfig | 9 +--
drivers/misc/Makefile | 2 +-
drivers/misc/pvpanic.c | 111 ------------------------------------
drivers/misc/pvpanic/Kconfig | 19 ++++++
drivers/misc/pvpanic/Makefile | 8 +++
drivers/misc/pvpanic/pvpanic-mmio.c | 83 +++++++++++++++++++++++++++
drivers/misc/pvpanic/pvpanic.c | 62 ++++++++++++++++++++
drivers/misc/pvpanic/pvpanic.h | 17 ++++++
8 files changed, 191 insertions(+), 120 deletions(-)
delete mode 100644 drivers/misc/pvpanic.c
create mode 100644 drivers/misc/pvpanic/Kconfig
create mode 100644 drivers/misc/pvpanic/Makefile
create mode 100644 drivers/misc/pvpanic/pvpanic-mmio.c
create mode 100644 drivers/misc/pvpanic/pvpanic.c
create mode 100644 drivers/misc/pvpanic/pvpanic.h

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index fafa8b0..0273ecb 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -448,14 +448,6 @@ config MISC_RTSX
tristate
default MISC_RTSX_PCI || MISC_RTSX_USB

-config PVPANIC
- tristate "pvpanic device support"
- depends on HAS_IOMEM && (ACPI || OF)
- help
- This driver provides support for the pvpanic device. pvpanic is
- a paravirtualized device provided by QEMU; it lets a virtual machine
- (guest) communicate panic events to the host.
-
config HISI_HIKEY_USB
tristate "USB GPIO Hub on HiSilicon Hikey 960/970 Platform"
depends on (OF && GPIOLIB) || COMPILE_TEST
@@ -481,4 +473,5 @@ source "drivers/misc/ocxl/Kconfig"
source "drivers/misc/cardreader/Kconfig"
source "drivers/misc/habanalabs/Kconfig"
source "drivers/misc/uacce/Kconfig"
+source "drivers/misc/pvpanic/Kconfig"
endmenu
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index d23231e..9f411b8 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -52,7 +52,7 @@ obj-$(CONFIG_CXL_BASE) += cxl/
obj-$(CONFIG_PCI_ENDPOINT_TEST) += pci_endpoint_test.o
obj-$(CONFIG_OCXL) += ocxl/
obj-y += cardreader/
-obj-$(CONFIG_PVPANIC) += pvpanic.o
+obj-$(CONFIG_PVPANIC) += pvpanic/
obj-$(CONFIG_HABANA_AI) += habanalabs/
obj-$(CONFIG_UACCE) += uacce/
obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o
diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c
deleted file mode 100644
index 41cab29..00000000
--- a/drivers/misc/pvpanic.c
+++ /dev/null
@@ -1,111 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Pvpanic Device Support
- *
- * Copyright (C) 2013 Fujitsu.
- * Copyright (C) 2018 ZTE.
- */
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#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/types.h>
-
-#include <uapi/misc/pvpanic.h>
-
-static void __iomem *base;
-
-MODULE_AUTHOR("Hu Tao <[email protected]>");
-MODULE_DESCRIPTION("pvpanic device driver");
-MODULE_LICENSE("GPL");
-
-static void
-pvpanic_send_event(unsigned int event)
-{
- iowrite8(event, base);
-}
-
-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;
-}
-
-static struct notifier_block pvpanic_panic_nb = {
- .notifier_call = pvpanic_panic_notify,
- .priority = 1, /* let this called before broken drm_fb_helper */
-};
-
-static int pvpanic_mmio_probe(struct platform_device *pdev)
-{
- struct device *dev = &pdev->dev;
- struct resource *res;
-
- res = platform_get_mem_or_io(pdev, 0);
- if (!res)
- return -EINVAL;
-
- switch (resource_type(res)) {
- case IORESOURCE_IO:
- base = devm_ioport_map(dev, res->start, resource_size(res));
- if (!base)
- return -ENOMEM;
- break;
- case IORESOURCE_MEM:
- base = devm_ioremap_resource(dev, res);
- if (IS_ERR(base))
- return PTR_ERR(base);
- break;
- default:
- return -EINVAL;
- }
-
- atomic_notifier_chain_register(&panic_notifier_list,
- &pvpanic_panic_nb);
-
- return 0;
-}
-
-static int pvpanic_mmio_remove(struct platform_device *pdev)
-{
-
- atomic_notifier_chain_unregister(&panic_notifier_list,
- &pvpanic_panic_nb);
-
- return 0;
-}
-
-static const struct of_device_id pvpanic_mmio_match[] = {
- { .compatible = "qemu,pvpanic-mmio", },
- {}
-};
-
-static const struct acpi_device_id pvpanic_device_ids[] = {
- { "QEMU0001", 0 },
- { "", 0 }
-};
-MODULE_DEVICE_TABLE(acpi, pvpanic_device_ids);
-
-static struct platform_driver pvpanic_mmio_driver = {
- .driver = {
- .name = "pvpanic-mmio",
- .of_match_table = pvpanic_mmio_match,
- .acpi_match_table = pvpanic_device_ids,
- },
- .probe = pvpanic_mmio_probe,
- .remove = pvpanic_mmio_remove,
-};
-module_platform_driver(pvpanic_mmio_driver);
diff --git a/drivers/misc/pvpanic/Kconfig b/drivers/misc/pvpanic/Kconfig
new file mode 100644
index 00000000..454f1ee
--- /dev/null
+++ b/drivers/misc/pvpanic/Kconfig
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Pvpanic Kconfig
+#
+# Copyright (C) 2021 Oracle.
+#
+
+config PVPANIC
+ bool "pvpanic device support"
+ help
+ This option allows to select a specific pvpanic device driver.
+ pvpanic is a paravirtualized device provided by QEMU; it lets
+ a virtual machine (guest) communicate panic events to the host.
+
+config PVPANIC_MMIO
+ tristate "pvpanic MMIO device support"
+ depends on HAS_IOMEM && (ACPI || OF) && PVPANIC
+ help
+ This driver provides support for the MMIO pvpanic device.
diff --git a/drivers/misc/pvpanic/Makefile b/drivers/misc/pvpanic/Makefile
new file mode 100644
index 00000000..91d816b
--- /dev/null
+++ b/drivers/misc/pvpanic/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Pvpanic Makefile
+#
+# Copyright (C) 2021 Oracle.
+#
+obj-$(CONFIG_PVPANIC) += pvpanic.o
+obj-$(CONFIG_PVPANIC_MMIO) += pvpanic-mmio.o
diff --git a/drivers/misc/pvpanic/pvpanic-mmio.c b/drivers/misc/pvpanic/pvpanic-mmio.c
new file mode 100644
index 00000000..7454eeb
--- /dev/null
+++ b/drivers/misc/pvpanic/pvpanic-mmio.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Pvpanic MMIO 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/types.h>
+
+#include <uapi/misc/pvpanic.h>
+#include "pvpanic.h"
+
+MODULE_AUTHOR("Hu Tao <[email protected]>");
+MODULE_DESCRIPTION("pvpanic device driver");
+MODULE_LICENSE("GPL");
+
+static int pvpanic_mmio_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct resource *res;
+ void __iomem *base;
+
+ res = platform_get_mem_or_io(pdev, 0);
+ if (!res)
+ return -EINVAL;
+
+ switch (resource_type(res)) {
+ case IORESOURCE_IO:
+ base = devm_ioport_map(dev, res->start, resource_size(res));
+ if (!base)
+ return -ENOMEM;
+ break;
+ case IORESOURCE_MEM:
+ base = devm_ioremap_resource(dev, res);
+ if (IS_ERR(base))
+ return PTR_ERR(base);
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ pvpanic_probe(base);
+
+ return 0;
+}
+
+static int pvpanic_mmio_remove(struct platform_device *pdev)
+{
+
+ pvpanic_remove();
+
+ return 0;
+}
+
+static const struct of_device_id pvpanic_mmio_match[] = {
+ { .compatible = "qemu,pvpanic-mmio", },
+ {}
+};
+
+static const struct acpi_device_id pvpanic_device_ids[] = {
+ { "QEMU0001", 0 },
+ { "", 0 }
+};
+MODULE_DEVICE_TABLE(acpi, pvpanic_device_ids);
+
+static struct platform_driver pvpanic_mmio_driver = {
+ .driver = {
+ .name = "pvpanic-mmio",
+ .of_match_table = pvpanic_mmio_match,
+ .acpi_match_table = pvpanic_device_ids,
+ },
+ .probe = pvpanic_mmio_probe,
+ .remove = pvpanic_mmio_remove,
+};
+module_platform_driver(pvpanic_mmio_driver);
diff --git a/drivers/misc/pvpanic/pvpanic.c b/drivers/misc/pvpanic/pvpanic.c
new file mode 100644
index 00000000..652ae01
--- /dev/null
+++ b/drivers/misc/pvpanic/pvpanic.c
@@ -0,0 +1,62 @@
+// 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/types.h>
+
+#include <uapi/misc/pvpanic.h>
+
+static void __iomem *base;
+
+static void
+pvpanic_send_event(unsigned int event)
+{
+ iowrite8(event, base);
+}
+
+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;
+}
+
+static struct notifier_block pvpanic_panic_nb = {
+ .notifier_call = pvpanic_panic_notify,
+ .priority = 1, /* let this called before broken drm_fb_helper */
+};
+
+void pvpanic_probe(void __iomem *pbase)
+{
+ base = pbase;
+ atomic_notifier_chain_register(&panic_notifier_list,
+ &pvpanic_panic_nb);
+}
+EXPORT_SYMBOL_GPL(pvpanic_probe);
+
+void pvpanic_remove(void)
+{
+
+ atomic_notifier_chain_unregister(&panic_notifier_list,
+ &pvpanic_panic_nb);
+ base = NULL;
+}
+EXPORT_SYMBOL_GPL(pvpanic_remove);
diff --git a/drivers/misc/pvpanic/pvpanic.h b/drivers/misc/pvpanic/pvpanic.h
new file mode 100644
index 00000000..7e75dce
--- /dev/null
+++ b/drivers/misc/pvpanic/pvpanic.h
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Pvpanic Device Support
+ *
+ * Copyright (C) 2021 Oracle.
+*/
+
+#ifndef PVPANIC_H_
+#define PVPANIC_H_
+
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+void pvpanic_probe(void __iomem *base);
+void pvpanic_remove(void);
+
+#endif /* PVPANIC_H_ */
--
1.8.3.1

2021-02-12 20:30:49

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH v3 1/3] misc/pvpanic: split-up generic and platform dependent code

On Fri, Feb 12, 2021 at 8:32 PM Mihai Carabas <[email protected]> wrote:
>
> Split-up generic and platform dependent code in order to be able to re-use
> generic event handling code in pvpanic PCI device driver in the next patches.
>
> The code from pvpanic.c was split in two new files:
> - pvpanic.c: generic code that handles pvpanic events
> - pvpanic-mmio.c: platform/bus dependent code
>
> Signed-off-by: Mihai Carabas <[email protected]>

> ---
> drivers/misc/Kconfig | 9 +--
> drivers/misc/Makefile | 2 +-
> drivers/misc/pvpanic.c | 111 ------------------------------------
> drivers/misc/pvpanic/Kconfig | 19 ++++++
> drivers/misc/pvpanic/Makefile | 8 +++
> drivers/misc/pvpanic/pvpanic-mmio.c | 83 +++++++++++++++++++++++++++
> drivers/misc/pvpanic/pvpanic.c | 62 ++++++++++++++++++++
> drivers/misc/pvpanic/pvpanic.h | 17 ++++++


As mentioned, please use 'git format-patch -M' to make it easier to review

> +
> +config PVPANIC
> + bool "pvpanic device support"
> + help
> + This option allows to select a specific pvpanic device driver.
> + pvpanic is a paravirtualized device provided by QEMU; it lets
> + a virtual machine (guest) communicate panic events to the host.
> +
> +config PVPANIC_MMIO
> + tristate "pvpanic MMIO device support"
> + depends on HAS_IOMEM && (ACPI || OF) && PVPANIC
> + help
> + This driver provides support for the MMIO pvpanic device.
...
> +#
> +obj-$(CONFIG_PVPANIC) += pvpanic.o
> +obj-$(CONFIG_PVPANIC_MMIO) += pvpanic-mmio.o

This solves the problem that Greg pointed out, but now the core pvpanic
driver is always built-in even when it is only used from loadable modules.

The easiest way to express what you actually want is with a Makefile
trick:

obj-$(CONFIG_PVPANIC) += pvpanic.o pvpanic-pci.o
obj-$(CONFIG_PVPANIC_MMIO) += pvpanic.o pvpanic-mmio.o

When you do this, pvpanic.o is built-in when at least one of its
users is built-in, and otherwise it a loadable module when there
is at least one user, but it will not be built twice or with the wrong
flags.

Arnd

2021-02-12 23:05:51

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v3 1/3] misc/pvpanic: split-up generic and platform dependent code

Hi Mihai,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linux/master]
[also build test WARNING on soc/for-next linus/master v5.11-rc7]
[cannot apply to char-misc/char-misc-testing next-20210211]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Mihai-Carabas/misc-pvpanic-split-up-generic-and-platform-dependent-code/20210213-043307
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2ab38c17aac10bf55ab3efde4c4db3893d8691d2
config: x86_64-randconfig-r012-20210209 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project c9439ca36342fb6013187d0a69aef92736951476)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/e69d90da4864766e3dc173d0940c05c4ec59278b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mihai-Carabas/misc-pvpanic-split-up-generic-and-platform-dependent-code/20210213-043307
git checkout e69d90da4864766e3dc173d0940c05c4ec59278b
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

>> drivers/misc/pvpanic/pvpanic.c:47:6: warning: no previous prototype for function 'pvpanic_probe' [-Wmissing-prototypes]
void pvpanic_probe(void __iomem *pbase)
^
drivers/misc/pvpanic/pvpanic.c:47:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void pvpanic_probe(void __iomem *pbase)
^
static
>> drivers/misc/pvpanic/pvpanic.c:55:6: warning: no previous prototype for function 'pvpanic_remove' [-Wmissing-prototypes]
void pvpanic_remove(void)
^
drivers/misc/pvpanic/pvpanic.c:55:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void pvpanic_remove(void)
^
static
2 warnings generated.


vim +/pvpanic_probe +47 drivers/misc/pvpanic/pvpanic.c

46
> 47 void pvpanic_probe(void __iomem *pbase)
48 {
49 base = pbase;
50 atomic_notifier_chain_register(&panic_notifier_list,
51 &pvpanic_panic_nb);
52 }
53 EXPORT_SYMBOL_GPL(pvpanic_probe);
54
> 55 void pvpanic_remove(void)

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (2.96 kB)
.config.gz (31.56 kB)
Download all attachments

2021-02-13 02:04:50

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v3 2/3] misc/pvpanic: probe multiple instances

Hi Mihai,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linux/master]
[also build test ERROR on soc/for-next linus/master v5.11-rc7]
[cannot apply to char-misc/char-misc-testing next-20210211]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Mihai-Carabas/misc-pvpanic-split-up-generic-and-platform-dependent-code/20210213-043307
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2ab38c17aac10bf55ab3efde4c4db3893d8691d2
config: x86_64-randconfig-r012-20210209 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project c9439ca36342fb6013187d0a69aef92736951476)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/70eed71fbb1f23b28a401213c2dac3c27fcae323
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mihai-Carabas/misc-pvpanic-split-up-generic-and-platform-dependent-code/20210213-043307
git checkout 70eed71fbb1f23b28a401213c2dac3c27fcae323
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

drivers/misc/pvpanic/pvpanic.c:62:5: warning: no previous prototype for function 'pvpanic_probe' [-Wmissing-prototypes]
int pvpanic_probe(void __iomem *pbase)
^
drivers/misc/pvpanic/pvpanic.c:62:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
int pvpanic_probe(void __iomem *pbase)
^
static
>> drivers/misc/pvpanic/pvpanic.c:87:3: error: void function 'pvpanic_remove' should not return a value [-Wreturn-type]
return -EINVAL;
^ ~~~~~~~
drivers/misc/pvpanic/pvpanic.c:82:6: warning: no previous prototype for function 'pvpanic_remove' [-Wmissing-prototypes]
void pvpanic_remove(void __iomem *pbase)
^
drivers/misc/pvpanic/pvpanic.c:82:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
void pvpanic_remove(void __iomem *pbase)
^
static
2 warnings and 1 error generated.


vim +/pvpanic_remove +87 drivers/misc/pvpanic/pvpanic.c

61
> 62 int pvpanic_probe(void __iomem *pbase)
63 {
64 struct pvpanic_instance *pi;
65
66 if(!pbase)
67 return -EINVAL;
68
69 pi = kmalloc(sizeof(*pi), GFP_ATOMIC);
70 if (!pi)
71 return -ENOMEM;
72
73 pi->base = pbase;
74 spin_lock(&pvpanic_lock);
75 list_add(&pi->list, &pvpanic_list);
76 spin_unlock(&pvpanic_lock);
77
78 return 0;
79 }
80 EXPORT_SYMBOL_GPL(pvpanic_probe);
81
82 void pvpanic_remove(void __iomem *pbase)
83 {
84 struct pvpanic_instance *pi_cur, *pi_next;
85
86 if(!pbase)
> 87 return -EINVAL;
88
89 spin_lock(&pvpanic_lock);
90 list_for_each_entry_safe(pi_cur, pi_next, &pvpanic_list, list) {
91 if (pi_cur->base == pbase) {
92 list_del(&pi_cur->list);
93 kfree(pi_cur);
94 break;
95 }
96 }
97 spin_unlock(&pvpanic_lock);
98 }
99 EXPORT_SYMBOL_GPL(pvpanic_remove);
100

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (3.90 kB)
.config.gz (31.56 kB)
Download all attachments