linux/drivers/perf
Qi Liu bdc5c744c7 drivers/perf: Fix kernel panic when rmmod PMU modules during perf sampling
When users try to remove PMU modules during perf sampling, kernel panic
will happen because the pmu->read() is a NULL pointer here.

INFO on HiSilicon hip08 platform as follow:
pc : hisi_uncore_pmu_event_update+0x30/0xa4 [hisi_uncore_pmu]
lr : hisi_uncore_pmu_read+0x20/0x2c [hisi_uncore_pmu]
sp : ffff800010103e90
x29: ffff800010103e90 x28: ffff0027db0c0e40
x27: ffffa29a76f129d8 x26: ffffa29a77ceb000
x25: ffffa29a773a5000 x24: ffffa29a77392000
x23: ffffddffe5943f08 x22: ffff002784285960
x21: ffff002784285800 x20: ffff0027d2e76c80
x19: ffff0027842859e0 x18: ffff80003498bcc8
x17: ffffa29a76afe910 x16: ffffa29a7583f530
x15: 16151a1512061a1e x14: 0000000000000000
x13: ffffa29a76f1e238 x12: 0000000000000001
x11: 0000000000000400 x10: 00000000000009f0
x9 : ffff8000107b3e70 x8 : ffff0027db0c1890
x7 : ffffa29a773a7000 x6 : 00000007f5131013
x5 : 00000007f5131013 x4 : 09f257d417c00000
x3 : 00000002187bd7ce x2 : ffffa29a38f0f0d8
x1 : ffffa29a38eae268 x0 : ffff0027d2e76c80
Call trace:
hisi_uncore_pmu_event_update+0x30/0xa4 [hisi_uncore_pmu]
hisi_uncore_pmu_read+0x20/0x2c [hisi_uncore_pmu]
__perf_event_read+0x1a0/0x1f8
flush_smp_call_function_queue+0xa0/0x160
generic_smp_call_function_single_interrupt+0x18/0x20
handle_IPI+0x31c/0x4dc
gic_handle_irq+0x2c8/0x310
el1_irq+0xcc/0x180
arch_cpu_idle+0x4c/0x20c
default_idle_call+0x20/0x30
do_idle+0x1b4/0x270
cpu_startup_entry+0x28/0x30
secondary_start_kernel+0x1a4/0x1fc

To solve the above issue, current module should be registered to kernel,
so that try_module_get() can be invoked when perf sampling starts. This
adds the reference counting of module and could prevent users from removing
modules during sampling.

Reported-by: Haifeng Wang <wang.wanghaifeng@huawei.com>
Signed-off-by: Qi Liu <liuqi115@huawei.com>
Reviewed-by: John Garry <john.garry@huawei.com>
Link: https://lore.kernel.org/r/1594891165-8228-1-git-send-email-liuqi115@huawei.com
Signed-off-by: Will Deacon <will@kernel.org>
2020-07-16 11:35:24 +01:00
..
hisilicon drivers/perf: Fix kernel panic when rmmod PMU modules during perf sampling 2020-07-16 11:35:24 +01:00
arm_dsu_pmu.c drivers/perf: arm_dsu_pmu: Avoid duplicate printouts 2020-04-30 21:48:10 +01:00
arm_pmu_acpi.c drivers/perf: arm_pmu_acpi: Fix incorrect checking of gicc pointer 2020-03-02 12:07:35 +00:00
arm_pmu_platform.c perf: Convert to using %pOFn instead of device_node.name 2018-10-01 11:33:17 +01:00
arm_pmu.c drivers/perf: arm_pmu: Fix failure path in PM notifier 2019-07-29 11:43:48 +01:00
arm_smmuv3_pmu.c drivers/perf: Fix kernel panic when rmmod PMU modules during perf sampling 2020-07-16 11:35:24 +01:00
arm_spe_pmu.c arm64 updates for 5.8 2020-06-01 15:18:27 -07:00
arm-cci.c perf/arm-cci: use devm_platform_ioremap_resource() to simplify code 2019-10-01 12:28:47 +01:00
arm-ccn.c perf: arm-ccn: Use scnprintf() for robustness 2020-03-17 22:45:56 +00:00
fsl_imx8_ddr_perf.c drivers/perf: Fix kernel panic when rmmod PMU modules during perf sampling 2020-07-16 11:35:24 +01:00
Kconfig drivers/perf: hisi: Permit modular builds of HiSilicon uncore drivers 2020-05-18 18:18:39 +01:00
Makefile drivers/perf: imx_ddr: Add DDR performance counter support to perf 2019-06-13 11:07:57 +01:00
qcom_l2_pmu.c perf: Remove dev_err() usage after platform_get_irq() 2019-07-31 17:15:20 +01:00
qcom_l3_pmu.c docs: perf: move to the admin-guide 2019-07-15 09:20:27 -03:00
thunderx2_pmu.c drivers/perf: Add CCPI2 PMU support in ThunderX2 UNCORE driver. 2019-10-29 10:08:46 +00:00
xgene_pmu.c perf: xgene: use devm_platform_ioremap_resource() to simplify code 2019-10-01 12:28:46 +01:00