Commit b899142ce21d53b496fe7d1534ba7ca62538ca37

Authored by David Carrillo-Cisneros
Committed by Greg Kroah-Hartman
1 parent efa225254a

perf/x86: Set pmu->module in Intel PMU modules

[ Upstream commit 74545f63890e38520eb4d1dbedcadaa9c0dbc824 ]

The conversion of Intel PMU drivers into modules did not include reference
counting. The machine will crash when attempting to  access deleted code
if an event from a module PMU is started and the module removed before the
event is destroyed.

i.e. this crashes the machine:

	$ insmod intel-rapl-perf.ko
	$ perf stat -e power/energy-cores/ -C 0 &
	$ rmmod intel-rapl-perf.ko

Set THIS_MODULE to pmu->module in Intel module PMUs so that generic code
can handle reference counting and deny rmmod while an event still exists.

Signed-off-by: David Carrillo-Cisneros <davidcc@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Turner <pjt@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1482455860-116269-1-git-send-email-davidcc@google.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 3 changed files with 4 additions and 0 deletions Side-by-side Diff

arch/x86/events/intel/cstate.c
... ... @@ -434,6 +434,7 @@
434 434 .stop = cstate_pmu_event_stop,
435 435 .read = cstate_pmu_event_update,
436 436 .capabilities = PERF_PMU_CAP_NO_INTERRUPT,
  437 + .module = THIS_MODULE,
437 438 };
438 439  
439 440 static struct pmu cstate_pkg_pmu = {
... ... @@ -447,6 +448,7 @@
447 448 .stop = cstate_pmu_event_stop,
448 449 .read = cstate_pmu_event_update,
449 450 .capabilities = PERF_PMU_CAP_NO_INTERRUPT,
  451 + .module = THIS_MODULE,
450 452 };
451 453  
452 454 static const struct cstate_model nhm_cstates __initconst = {
arch/x86/events/intel/rapl.c
... ... @@ -697,6 +697,7 @@
697 697 rapl_pmus->pmu.start = rapl_pmu_event_start;
698 698 rapl_pmus->pmu.stop = rapl_pmu_event_stop;
699 699 rapl_pmus->pmu.read = rapl_pmu_event_read;
  700 + rapl_pmus->pmu.module = THIS_MODULE;
700 701 return 0;
701 702 }
702 703  
arch/x86/events/intel/uncore.c
... ... @@ -733,6 +733,7 @@
733 733 .start = uncore_pmu_event_start,
734 734 .stop = uncore_pmu_event_stop,
735 735 .read = uncore_pmu_event_read,
  736 + .module = THIS_MODULE,
736 737 };
737 738 } else {
738 739 pmu->pmu = *pmu->type->pmu;