Skip to content

Commit 287e82c

Browse files
James-A-ClarkSuzuki K Poulose
authored andcommitted
coresight: Fix crash when Perf and sysfs modes are used concurrently
Partially revert the change in commit 6148652 ("coresight: Enable and disable helper devices adjacent to the path") which changed the bare call from source_ops(csdev)->enable() to coresight_enable_source() for Perf sessions. It was missed that coresight_enable_source() is specifically for the sysfs interface, rather than being a generic call. This interferes with the sysfs reference counting to cause the following crash: $ perf record -e cs_etm/@tmc_etr0/ -C 0 & $ echo 1 > /sys/bus/coresight/devices/tmc_etr0/enable_sink $ echo 1 > /sys/bus/coresight/devices/etm0/enable_source $ echo 0 > /sys/bus/coresight/devices/etm0/enable_source Unable to handle kernel NULL pointer dereference at virtual address 00000000000001d0 Internal error: Oops: 0000000096000004 [#1] PREEMPT SMP ... Call trace: etm4_disable+0x54/0x150 [coresight_etm4x] coresight_disable_source+0x6c/0x98 [coresight] coresight_disable+0x74/0x1c0 [coresight] enable_source_store+0x88/0xa0 [coresight] dev_attr_store+0x20/0x40 sysfs_kf_write+0x4c/0x68 kernfs_fop_write_iter+0x120/0x1b8 vfs_write+0x2dc/0x3b0 ksys_write+0x70/0x108 __arm64_sys_write+0x24/0x38 invoke_syscall+0x50/0x128 el0_svc_common.constprop.0+0x104/0x130 do_el0_svc+0x40/0xb8 el0_svc+0x2c/0xb8 el0t_64_sync_handler+0xc0/0xc8 el0t_64_sync+0x1a4/0x1a8 Code: d53cd042 91002000 b9402a81 b8626800 (f940ead5) ---[ end trace 0000000000000000 ]--- This commit linked below also fixes the issue, but has unlocked updates to the mode which could potentially race. So until we come up with a more complete solution that takes all locking and interaction between both modes into account, just revert back to the old behavior for Perf. Reported-by: Junhao He <[email protected]> Closes: https://lore.kernel.org/linux-arm-kernel/[email protected]/ Fixes: 6148652 ("coresight: Enable and disable helper devices adjacent to the path") Tested-by: Junhao He <[email protected]> Signed-off-by: James Clark <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 348ddab commit 287e82c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/hwtracing/coresight/coresight-etm-perf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ static void etm_event_start(struct perf_event *event, int flags)
493493
goto fail_end_stop;
494494

495495
/* Finally enable the tracer */
496-
if (coresight_enable_source(csdev, CS_MODE_PERF, event))
496+
if (source_ops(csdev)->enable(csdev, event, CS_MODE_PERF))
497497
goto fail_disable_path;
498498

499499
/*
@@ -587,7 +587,7 @@ static void etm_event_stop(struct perf_event *event, int mode)
587587
return;
588588

589589
/* stop tracer */
590-
coresight_disable_source(csdev, event);
590+
source_ops(csdev)->disable(csdev, event);
591591

592592
/* tell the core */
593593
event->hw.state = PERF_HES_STOPPED;

0 commit comments

Comments
 (0)