Hi James,
-----Original Message----- From: James Clark james.clark@arm.com Sent: Thursday, August 17, 2023 7:21 PM To: Linu Cherian lcherian@marvell.com; suzuki.poulose@arm.com; mike.leach@linaro.org; mathieu.poirier@linaro.org Cc: coresight@lists.linaro.org; Anil Kumar Reddy H areddy3@marvell.com; Tanmay Jagdale tanmay@marvell.com; George Cherian gcherian@marvell.com Subject: [EXT] Re: [RFC PATCH v2 3/7] coresight: core: Add provision for panic callbacks
External Email
On 13/07/2023 14:47, Linu Cherian wrote:
Panic callback handlers allows coresight device drivers to sync relevant trace data and trace metadata to reserved memory regions so that they can be retrieved later in the subsequent boot or in the crashdump kernel.
Signed-off-by: Linu Cherian lcherian@marvell.com
drivers/hwtracing/coresight/coresight-core.c | 30
++++++++++++++++++++
include/linux/coresight.h | 11 +++++++ 2 files changed, 41 insertions(+)
diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c index d3bf82c0de1d..aa29a7d18518 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -19,6 +19,7 @@ #include <linux/of_platform.h> #include <linux/delay.h> #include <linux/pm_runtime.h> +#include <linux/panic_notifier.h>
#include "coresight-etm-perf.h" #include "coresight-priv.h" @@ -1765,6 +1766,31 @@ struct bus_type coresight_bustype = { .name = "coresight", };
+static int coresight_panic_sync(struct device *dev, void *data) {
- struct coresight_device *csdev = container_of(dev, struct
+coresight_device, dev);
- /* Run through panic sync handlers for all enabled devices */
- if (csdev->enable && panic_ops(csdev))
panic_ops(csdev)->sync(csdev);
- return 0;
+}
+static int coresight_panic_cb(struct notifier_block *self,
unsigned long v, void *p)
+{
- bus_for_each_dev(&coresight_bustype, NULL, NULL,
coresight_panic_sync);
- return 0;
+}
+static struct notifier_block coresight_notifier = {
- .notifier_call = coresight_panic_cb, };
static int __init coresight_init(void) { int ret; @@ -1777,6 +1803,10 @@ static int __init coresight_init(void) if (ret) goto exit_bus_unregister;
- /* Register function to be called for panic */
- ret = atomic_notifier_chain_register(&panic_notifier_list,
&coresight_notifier);
I think this needs to be unregistered on unload, or not done on every load, otherwise doing rmmod and then insmod gives you an error:
[ 3273.744765] ------------[ cut here ]------------ [ 3273.744775] notifier callback coresight_panic_cb [coresight] already registered [ 3273.744846] WARNING: CPU: 3 PID: 4282 at kernel/notifier.c:32 notifier_chain_register+0x140/0x248 [ 3273.744862] Modules linked in: coresight(+) dm_mod xt_CHECKSUM xt_MASQUERADE xt_conntrack ipt_REJECT nf_reject_ipv4 xt_tcpudp ip6table_mangle ip6table_nat iptable_mangle iptable_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 libcrc32c ip6table_filter ip6_tables iptable_filter bridge stp llc arm_spe_pmu ip_tables x_tables ipv6 xhci_pci xhci_pci_renesas r8169 [last unloaded: coresight] [ 3273.744954] CPU: 3 PID: 4282 Comm: modprobe Not tainted 6.5.0-rc3+ #145 [ 3273.744962] pstate: 604000c9 (nZCv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 3273.744970] pc : notifier_chain_register+0x140/0x248 [ 3273.744977] lr : notifier_chain_register+0x13c/0x248 [ 3273.744984] sp : ffff8000893e7780 [ 3273.744988] x29: ffff8000893e7780 x28: ffff800085d2c273 x27: 0000000000000009 [ 3273.745000] x26: ffff80007bdc4040 x25: ffff80007bdb22d8 x24: 0000000000000000 [ 3273.745012] x23: ffff80007bdadde0 x22: ffff80007bdaddf0 x21: 0000000000000000 [ 3273.745024] x20: ffff800082a1f848 x19: ffff80007bdadde0 x18: ffff00837dff7400 [ 3273.745036] x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000001 [ 3273.745048] x14: 1fffe0105dad2022 x13: 0000000000000000 x12: 0000000000000000 [ 3273.745060] x11: ffff60105dad2023 x10: 1fffe01008a07001 x9 : 9df4d03567f7fe00 [ 3273.745072] x8 : 9df4d03567f7fe00 x7 : 0000000000000001 x6 : 0000000000000001 [ 3273.745084] x5 : ffff8000893e7478 x4 : ffff80008241eac0 x3 : ffff8000803322fc [ 3273.745096] x2 : 0000000000000001 x1 : 0000000000000004 x0 : 00000000ffffffef [ 3273.745107] Call trace: [ 3273.745111] notifier_chain_register+0x140/0x248 [ 3273.745118] atomic_notifier_chain_register+0x40/0x70 [ 3273.745125] init_module+0x74/0x90 [coresight] [ 3273.745184] do_one_initcall+0x11c/0x470 [ 3273.745191] do_init_module+0x114/0x338 [ 3273.745198] load_module+0x2248/0x2478 [ 3273.745206] __arm64_sys_finit_module+0x2b8/0x3d8 [ 3273.745213] invoke_syscall+0x60/0x188 [ 3273.745221] el0_svc_common+0x110/0x158 [ 3273.745228] do_el0_svc+0x4c/0xe0 [ 3273.745235] el0_svc+0x44/0xb8 [ 3273.745242] el0t_64_sync_handler+0x84/0x100 [ 3273.745248] el0t_64_sync+0x190/0x198 [ 3273.745254] irq event stamp: 0 [ 3273.745257] hardirqs last enabled at (0): [<0000000000000000>] 0x0 [ 3273.745265] hardirqs last disabled at (0): [<ffff8000800ca374>] copy_process+0x994/0x18f0 [ 3273.745272] softirqs last enabled at (0): [<ffff8000800ca38c>] copy_process+0x9ac/0x18f0 [ 3273.745279] softirqs last disabled at (0): [<0000000000000000>] 0x0 [ 3273.745284] ---[ end trace 0000000000000000 ]---
Ack. Will fix.
/* initialise the coresight syscfg API */ ret = cscfg_init(); if (!ret) diff --git a/include/linux/coresight.h b/include/linux/coresight.h index f19a47b9bb5a..8831df24733a 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -277,6 +277,7 @@ static struct coresight_dev_list (var) = {
\
#define link_ops(csdev) csdev->ops->link_ops #define helper_ops(csdev) csdev->ops->helper_ops #define ect_ops(csdev) csdev->ops->ect_ops +#define panic_ops(csdev) csdev->ops->panic_ops
/**
- struct coresight_ops_sink - basic operations for a sink @@ -351,12
+352,22 @@ struct coresight_ops_ect { int (*disable)(struct coresight_device *csdev); };
+/**
- struct coresight_ops_panic - Generic device ops for panic handing
- @sync : Sync the device register state/trace data
- */
+struct coresight_ops_panic {
- int (*sync)(struct coresight_device *csdev); };
struct coresight_ops { const struct coresight_ops_sink *sink_ops; const struct coresight_ops_link *link_ops; const struct coresight_ops_source *source_ops; const struct coresight_ops_helper *helper_ops; const struct coresight_ops_ect *ect_ops;
- const struct coresight_ops_panic *panic_ops;
};
#if IS_ENABLED(CONFIG_CORESIGHT)