All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf/x86/intel: Add cpu_(prepare|starting|dying) for core_pmu
@ 2015-04-21  8:54 Jiri Olsa
  2015-04-21 10:52 ` Ingo Molnar
  2015-04-21 15:12 ` [PATCH] " Peter Zijlstra
  0 siblings, 2 replies; 8+ messages in thread
From: Jiri Olsa @ 2015-04-21  8:54 UTC (permalink / raw)
  To: lkml
  Cc: Andi Kleen, Arnaldo Carvalho de Melo, Ingo Molnar,
	Paul Mackerras, Peter Zijlstra, Stephane Eranian

The core_pmu does not define cpu_* callbacks, which handles
allocation of 'struct cpu_hw_events::shared_regs' data,
initialization of debug store and PMU_FL_EXCL_CNTRS counters.

While this probably won't happen on bare metal, virtual CPU can
define x86_pmu.extra_regs together with PMU version 1 and thus
be using core_pmu -> using shared_regs data without it being
allocated. That could could leave to following panic:

BUG: unable to handle kernel NULL pointer dereference at (null)
IP: [<ffffffff8152cd4f>] _spin_lock_irqsave+0x1f/0x40

SNIP

 [<ffffffff81024bd9>] __intel_shared_reg_get_constraints+0x69/0x1e0
 [<ffffffff81024deb>] intel_get_event_constraints+0x9b/0x180
 [<ffffffff8101e815>] x86_schedule_events+0x75/0x1d0
 [<ffffffff810586dc>] ? check_preempt_curr+0x7c/0x90
 [<ffffffff810649fe>] ? try_to_wake_up+0x24e/0x3e0
 [<ffffffff81064ba2>] ? default_wake_function+0x12/0x20
 [<ffffffff8109eb16>] ? autoremove_wake_function+0x16/0x40
 [<ffffffff810577e9>] ? __wake_up_common+0x59/0x90
 [<ffffffff811a9517>] ? __d_lookup+0xa7/0x150
 [<ffffffff8119db5f>] ? do_lookup+0x9f/0x230
 [<ffffffff811a993a>] ? dput+0x9a/0x150
 [<ffffffff8119c8f5>] ? path_to_nameidata+0x25/0x60
 [<ffffffff8119e90a>] ? __link_path_walk+0x7da/0x1000
 [<ffffffff8101d8f9>] ? x86_pmu_add+0xb9/0x170
 [<ffffffff8101d7a7>] x86_pmu_commit_txn+0x67/0xc0
 [<ffffffff811b07b0>] ? mntput_no_expire+0x30/0x110
 [<ffffffff8119c731>] ? path_put+0x31/0x40
 [<ffffffff8107c297>] ? current_fs_time+0x27/0x30
 [<ffffffff8117d170>] ? mem_cgroup_get_reclaim_stat_from_page+0x20/0x70
 [<ffffffff8111b7aa>] group_sched_in+0x13a/0x170
 [<ffffffff81014a29>] ? sched_clock+0x9/0x10
 [<ffffffff8111bac8>] ctx_sched_in+0x2e8/0x330
 [<ffffffff8111bb7b>] perf_event_sched_in+0x6b/0xb0
 [<ffffffff8111bc36>] perf_event_context_sched_in+0x76/0xc0
 [<ffffffff8111eb3b>] perf_event_comm+0x1bb/0x2e0
 [<ffffffff81195ee9>] set_task_comm+0x69/0x80
 [<ffffffff81195fe1>] setup_new_exec+0xe1/0x2e0
 [<ffffffff811ea68e>] load_elf_binary+0x3ce/0x1ab0

Adding cpu_(prepare|starting|dying) for core_pmu to have shared_regs
data allocated for core_pmu. AFAICS there's no harm to initialize
debug store and PMU_FL_EXCL_CNTRS either for core_pmu.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 arch/x86/kernel/cpu/perf_event_intel.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
index 9da2400c2ec3..0a61a9a021de 100644
--- a/arch/x86/kernel/cpu/perf_event_intel.c
+++ b/arch/x86/kernel/cpu/perf_event_intel.c
@@ -2533,6 +2533,10 @@ ssize_t intel_event_sysfs_show(char *page, u64 config)
 	return x86_event_sysfs_show(page, config, event);
 }
 
+static int  intel_pmu_cpu_prepare(int cpu);
+static void intel_pmu_cpu_starting(int cpu);
+static void intel_pmu_cpu_dying(int cpu);
+
 static __initconst const struct x86_pmu core_pmu = {
 	.name			= "core",
 	.handle_irq		= x86_pmu_handle_irq,
@@ -2559,6 +2563,9 @@ static __initconst const struct x86_pmu core_pmu = {
 	.guest_get_msrs		= core_guest_get_msrs,
 	.format_attrs		= intel_arch_formats_attr,
 	.events_sysfs_show	= intel_event_sysfs_show,
+	.cpu_prepare		= intel_pmu_cpu_prepare,
+	.cpu_starting		= intel_pmu_cpu_starting,
+	.cpu_dying		= intel_pmu_cpu_dying,
 };
 
 struct intel_shared_regs *allocate_shared_regs(int cpu)
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] perf/x86/intel: Add cpu_(prepare|starting|dying) for core_pmu
  2015-04-21  8:54 [PATCH] perf/x86/intel: Add cpu_(prepare|starting|dying) for core_pmu Jiri Olsa
@ 2015-04-21 10:52 ` Ingo Molnar
  2015-04-21 15:14   ` [PATCHv2] " Jiri Olsa
  2015-04-21 15:12 ` [PATCH] " Peter Zijlstra
  1 sibling, 1 reply; 8+ messages in thread
From: Ingo Molnar @ 2015-04-21 10:52 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Andi Kleen, Arnaldo Carvalho de Melo, Paul Mackerras,
	Peter Zijlstra, Stephane Eranian


* Jiri Olsa <jolsa@kernel.org> wrote:

> The core_pmu does not define cpu_* callbacks, which handles
> allocation of 'struct cpu_hw_events::shared_regs' data,
> initialization of debug store and PMU_FL_EXCL_CNTRS counters.
> 
> While this probably won't happen on bare metal, virtual CPU can
> define x86_pmu.extra_regs together with PMU version 1 and thus
> be using core_pmu -> using shared_regs data without it being
> allocated. That could could leave to following panic:
> 
> BUG: unable to handle kernel NULL pointer dereference at (null)
> IP: [<ffffffff8152cd4f>] _spin_lock_irqsave+0x1f/0x40

ok.

> diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
> index 9da2400c2ec3..0a61a9a021de 100644
> --- a/arch/x86/kernel/cpu/perf_event_intel.c
> +++ b/arch/x86/kernel/cpu/perf_event_intel.c
> @@ -2533,6 +2533,10 @@ ssize_t intel_event_sysfs_show(char *page, u64 config)
>  	return x86_event_sysfs_show(page, config, event);
>  }
>  
> +static int  intel_pmu_cpu_prepare(int cpu);
> +static void intel_pmu_cpu_starting(int cpu);
> +static void intel_pmu_cpu_dying(int cpu);
> +
>  static __initconst const struct x86_pmu core_pmu = {
>  	.name			= "core",
>  	.handle_irq		= x86_pmu_handle_irq,
> @@ -2559,6 +2563,9 @@ static __initconst const struct x86_pmu core_pmu = {
>  	.guest_get_msrs		= core_guest_get_msrs,
>  	.format_attrs		= intel_arch_formats_attr,
>  	.events_sysfs_show	= intel_event_sysfs_show,
> +	.cpu_prepare		= intel_pmu_cpu_prepare,
> +	.cpu_starting		= intel_pmu_cpu_starting,
> +	.cpu_dying		= intel_pmu_cpu_dying,
>  };

Instead of adding prototype declarations, please arrange the x86_pmu 
definition's position so that it comes after the required functions - 
so that no prototypes are needed.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] perf/x86/intel: Add cpu_(prepare|starting|dying) for core_pmu
  2015-04-21  8:54 [PATCH] perf/x86/intel: Add cpu_(prepare|starting|dying) for core_pmu Jiri Olsa
  2015-04-21 10:52 ` Ingo Molnar
@ 2015-04-21 15:12 ` Peter Zijlstra
  2015-04-21 15:18   ` Jiri Olsa
  1 sibling, 1 reply; 8+ messages in thread
From: Peter Zijlstra @ 2015-04-21 15:12 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Andi Kleen, Arnaldo Carvalho de Melo, Ingo Molnar,
	Paul Mackerras, Stephane Eranian

On Tue, Apr 21, 2015 at 10:54:25AM +0200, Jiri Olsa wrote:
> @@ -2559,6 +2563,9 @@ static __initconst const struct x86_pmu core_pmu = {
>  	.guest_get_msrs		= core_guest_get_msrs,
>  	.format_attrs		= intel_arch_formats_attr,
>  	.events_sysfs_show	= intel_event_sysfs_show,

Could you also insert a little comment here how these methods are for
'funny' 'hardware' ?

> +	.cpu_prepare		= intel_pmu_cpu_prepare,
> +	.cpu_starting		= intel_pmu_cpu_starting,
> +	.cpu_dying		= intel_pmu_cpu_dying,
>  };
>  
>  struct intel_shared_regs *allocate_shared_regs(int cpu)
> -- 
> 1.9.3
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCHv2] perf/x86/intel: Add cpu_(prepare|starting|dying) for core_pmu
  2015-04-21 10:52 ` Ingo Molnar
@ 2015-04-21 15:14   ` Jiri Olsa
  0 siblings, 0 replies; 8+ messages in thread
From: Jiri Olsa @ 2015-04-21 15:14 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Jiri Olsa, lkml, Andi Kleen, Arnaldo Carvalho de Melo,
	Paul Mackerras, Peter Zijlstra, Stephane Eranian

On Tue, Apr 21, 2015 at 12:52:40PM +0200, Ingo Molnar wrote:
> 
> * Jiri Olsa <jolsa@kernel.org> wrote:

SNIP

> >  	.guest_get_msrs		= core_guest_get_msrs,
> >  	.format_attrs		= intel_arch_formats_attr,
> >  	.events_sysfs_show	= intel_event_sysfs_show,
> > +	.cpu_prepare		= intel_pmu_cpu_prepare,
> > +	.cpu_starting		= intel_pmu_cpu_starting,
> > +	.cpu_dying		= intel_pmu_cpu_dying,
> >  };
> 
> Instead of adding prototype declarations, please arrange the x86_pmu 
> definition's position so that it comes after the required functions - 
> so that no prototypes are needed.

ok, v2 is attached

thanks,
jirka


---
The core_pmu does not define cpu_* callbacks, which handles
allocation of 'struct cpu_hw_events::shared_regs' data,
initialization of debug store and PMU_FL_EXCL_CNTRS counters.

While this probably won't happen on bare metal, virtual CPU can
define x86_pmu.extra_regs together with PMU version 1 and thus
be using core_pmu -> using shared_regs data without it being
allocated. That could could leave to following panic:

BUG: unable to handle kernel NULL pointer dereference at (null)
IP: [<ffffffff8152cd4f>] _spin_lock_irqsave+0x1f/0x40

SNIP

 [<ffffffff81024bd9>] __intel_shared_reg_get_constraints+0x69/0x1e0
 [<ffffffff81024deb>] intel_get_event_constraints+0x9b/0x180
 [<ffffffff8101e815>] x86_schedule_events+0x75/0x1d0
 [<ffffffff810586dc>] ? check_preempt_curr+0x7c/0x90
 [<ffffffff810649fe>] ? try_to_wake_up+0x24e/0x3e0
 [<ffffffff81064ba2>] ? default_wake_function+0x12/0x20
 [<ffffffff8109eb16>] ? autoremove_wake_function+0x16/0x40
 [<ffffffff810577e9>] ? __wake_up_common+0x59/0x90
 [<ffffffff811a9517>] ? __d_lookup+0xa7/0x150
 [<ffffffff8119db5f>] ? do_lookup+0x9f/0x230
 [<ffffffff811a993a>] ? dput+0x9a/0x150
 [<ffffffff8119c8f5>] ? path_to_nameidata+0x25/0x60
 [<ffffffff8119e90a>] ? __link_path_walk+0x7da/0x1000
 [<ffffffff8101d8f9>] ? x86_pmu_add+0xb9/0x170
 [<ffffffff8101d7a7>] x86_pmu_commit_txn+0x67/0xc0
 [<ffffffff811b07b0>] ? mntput_no_expire+0x30/0x110
 [<ffffffff8119c731>] ? path_put+0x31/0x40
 [<ffffffff8107c297>] ? current_fs_time+0x27/0x30
 [<ffffffff8117d170>] ? mem_cgroup_get_reclaim_stat_from_page+0x20/0x70
 [<ffffffff8111b7aa>] group_sched_in+0x13a/0x170
 [<ffffffff81014a29>] ? sched_clock+0x9/0x10
 [<ffffffff8111bac8>] ctx_sched_in+0x2e8/0x330
 [<ffffffff8111bb7b>] perf_event_sched_in+0x6b/0xb0
 [<ffffffff8111bc36>] perf_event_context_sched_in+0x76/0xc0
 [<ffffffff8111eb3b>] perf_event_comm+0x1bb/0x2e0
 [<ffffffff81195ee9>] set_task_comm+0x69/0x80
 [<ffffffff81195fe1>] setup_new_exec+0xe1/0x2e0
 [<ffffffff811ea68e>] load_elf_binary+0x3ce/0x1ab0

Adding cpu_(prepare|starting|dying) for core_pmu to have shared_regs
data allocated for core_pmu. AFAICS there's no harm to initialize
debug store and PMU_FL_EXCL_CNTRS either for core_pmu.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 arch/x86/kernel/cpu/perf_event_intel.c | 59 ++++++++++++++++++----------------
 1 file changed, 31 insertions(+), 28 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
index 9da2400c2ec3..973abdc796fb 100644
--- a/arch/x86/kernel/cpu/perf_event_intel.c
+++ b/arch/x86/kernel/cpu/perf_event_intel.c
@@ -2533,34 +2533,6 @@ ssize_t intel_event_sysfs_show(char *page, u64 config)
 	return x86_event_sysfs_show(page, config, event);
 }
 
-static __initconst const struct x86_pmu core_pmu = {
-	.name			= "core",
-	.handle_irq		= x86_pmu_handle_irq,
-	.disable_all		= x86_pmu_disable_all,
-	.enable_all		= core_pmu_enable_all,
-	.enable			= core_pmu_enable_event,
-	.disable		= x86_pmu_disable_event,
-	.hw_config		= x86_pmu_hw_config,
-	.schedule_events	= x86_schedule_events,
-	.eventsel		= MSR_ARCH_PERFMON_EVENTSEL0,
-	.perfctr		= MSR_ARCH_PERFMON_PERFCTR0,
-	.event_map		= intel_pmu_event_map,
-	.max_events		= ARRAY_SIZE(intel_perfmon_event_map),
-	.apic			= 1,
-	/*
-	 * Intel PMCs cannot be accessed sanely above 32 bit width,
-	 * so we install an artificial 1<<31 period regardless of
-	 * the generic event period:
-	 */
-	.max_period		= (1ULL << 31) - 1,
-	.get_event_constraints	= intel_get_event_constraints,
-	.put_event_constraints	= intel_put_event_constraints,
-	.event_constraints	= intel_core_event_constraints,
-	.guest_get_msrs		= core_guest_get_msrs,
-	.format_attrs		= intel_arch_formats_attr,
-	.events_sysfs_show	= intel_event_sysfs_show,
-};
-
 struct intel_shared_regs *allocate_shared_regs(int cpu)
 {
 	struct intel_shared_regs *regs;
@@ -2743,6 +2715,37 @@ static struct attribute *intel_arch3_formats_attr[] = {
 	NULL,
 };
 
+static __initconst const struct x86_pmu core_pmu = {
+	.name			= "core",
+	.handle_irq		= x86_pmu_handle_irq,
+	.disable_all		= x86_pmu_disable_all,
+	.enable_all		= core_pmu_enable_all,
+	.enable			= core_pmu_enable_event,
+	.disable		= x86_pmu_disable_event,
+	.hw_config		= x86_pmu_hw_config,
+	.schedule_events	= x86_schedule_events,
+	.eventsel		= MSR_ARCH_PERFMON_EVENTSEL0,
+	.perfctr		= MSR_ARCH_PERFMON_PERFCTR0,
+	.event_map		= intel_pmu_event_map,
+	.max_events		= ARRAY_SIZE(intel_perfmon_event_map),
+	.apic			= 1,
+	/*
+	 * Intel PMCs cannot be accessed sanely above 32 bit width,
+	 * so we install an artificial 1<<31 period regardless of
+	 * the generic event period:
+	 */
+	.max_period		= (1ULL << 31) - 1,
+	.get_event_constraints	= intel_get_event_constraints,
+	.put_event_constraints	= intel_put_event_constraints,
+	.event_constraints	= intel_core_event_constraints,
+	.guest_get_msrs		= core_guest_get_msrs,
+	.format_attrs		= intel_arch_formats_attr,
+	.events_sysfs_show	= intel_event_sysfs_show,
+	.cpu_prepare		= intel_pmu_cpu_prepare,
+	.cpu_starting		= intel_pmu_cpu_starting,
+	.cpu_dying		= intel_pmu_cpu_dying,
+};
+
 static __initconst const struct x86_pmu intel_pmu = {
 	.name			= "Intel",
 	.handle_irq		= intel_pmu_handle_irq,
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] perf/x86/intel: Add cpu_(prepare|starting|dying) for core_pmu
  2015-04-21 15:12 ` [PATCH] " Peter Zijlstra
@ 2015-04-21 15:18   ` Jiri Olsa
  2015-04-21 15:26     ` [PATCHv3] " Jiri Olsa
  0 siblings, 1 reply; 8+ messages in thread
From: Jiri Olsa @ 2015-04-21 15:18 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Jiri Olsa, lkml, Andi Kleen, Arnaldo Carvalho de Melo,
	Ingo Molnar, Paul Mackerras, Stephane Eranian

On Tue, Apr 21, 2015 at 05:12:16PM +0200, Peter Zijlstra wrote:
> On Tue, Apr 21, 2015 at 10:54:25AM +0200, Jiri Olsa wrote:
> > @@ -2559,6 +2563,9 @@ static __initconst const struct x86_pmu core_pmu = {
> >  	.guest_get_msrs		= core_guest_get_msrs,
> >  	.format_attrs		= intel_arch_formats_attr,
> >  	.events_sysfs_show	= intel_event_sysfs_show,
> 
> Could you also insert a little comment here how these methods are for
> 'funny' 'hardware' ?

ook, will do v3

jirka

> 
> > +	.cpu_prepare		= intel_pmu_cpu_prepare,
> > +	.cpu_starting		= intel_pmu_cpu_starting,
> > +	.cpu_dying		= intel_pmu_cpu_dying,
> >  };
> >  
> >  struct intel_shared_regs *allocate_shared_regs(int cpu)
> > -- 
> > 1.9.3
> > 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCHv3] perf/x86/intel: Add cpu_(prepare|starting|dying) for core_pmu
  2015-04-21 15:18   ` Jiri Olsa
@ 2015-04-21 15:26     ` Jiri Olsa
  2015-04-21 21:00       ` Peter Zijlstra
  2015-04-22 14:10       ` [tip:perf/urgent] perf/x86/intel: Add cpu_(prepare|starting|dying ) " tip-bot for Jiri Olsa
  0 siblings, 2 replies; 8+ messages in thread
From: Jiri Olsa @ 2015-04-21 15:26 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Jiri Olsa, lkml, Andi Kleen, Arnaldo Carvalho de Melo,
	Ingo Molnar, Paul Mackerras, Stephane Eranian

On Tue, Apr 21, 2015 at 05:18:27PM +0200, Jiri Olsa wrote:
> On Tue, Apr 21, 2015 at 05:12:16PM +0200, Peter Zijlstra wrote:
> > On Tue, Apr 21, 2015 at 10:54:25AM +0200, Jiri Olsa wrote:
> > > @@ -2559,6 +2563,9 @@ static __initconst const struct x86_pmu core_pmu = {
> > >  	.guest_get_msrs		= core_guest_get_msrs,
> > >  	.format_attrs		= intel_arch_formats_attr,
> > >  	.events_sysfs_show	= intel_event_sysfs_show,
> > 
> > Could you also insert a little comment here how these methods are for
> > 'funny' 'hardware' ?
> 
> ook, will do v3

attached,
jirka


---
The core_pmu does not define cpu_* callbacks, which handles
allocation of 'struct cpu_hw_events::shared_regs' data,
initialization of debug store and PMU_FL_EXCL_CNTRS counters.

While this probably won't happen on bare metal, virtual CPU can
define x86_pmu.extra_regs together with PMU version 1 and thus
be using core_pmu -> using shared_regs data without it being
allocated. That could could leave to following panic:

BUG: unable to handle kernel NULL pointer dereference at (null)
IP: [<ffffffff8152cd4f>] _spin_lock_irqsave+0x1f/0x40

SNIP

 [<ffffffff81024bd9>] __intel_shared_reg_get_constraints+0x69/0x1e0
 [<ffffffff81024deb>] intel_get_event_constraints+0x9b/0x180
 [<ffffffff8101e815>] x86_schedule_events+0x75/0x1d0
 [<ffffffff810586dc>] ? check_preempt_curr+0x7c/0x90
 [<ffffffff810649fe>] ? try_to_wake_up+0x24e/0x3e0
 [<ffffffff81064ba2>] ? default_wake_function+0x12/0x20
 [<ffffffff8109eb16>] ? autoremove_wake_function+0x16/0x40
 [<ffffffff810577e9>] ? __wake_up_common+0x59/0x90
 [<ffffffff811a9517>] ? __d_lookup+0xa7/0x150
 [<ffffffff8119db5f>] ? do_lookup+0x9f/0x230
 [<ffffffff811a993a>] ? dput+0x9a/0x150
 [<ffffffff8119c8f5>] ? path_to_nameidata+0x25/0x60
 [<ffffffff8119e90a>] ? __link_path_walk+0x7da/0x1000
 [<ffffffff8101d8f9>] ? x86_pmu_add+0xb9/0x170
 [<ffffffff8101d7a7>] x86_pmu_commit_txn+0x67/0xc0
 [<ffffffff811b07b0>] ? mntput_no_expire+0x30/0x110
 [<ffffffff8119c731>] ? path_put+0x31/0x40
 [<ffffffff8107c297>] ? current_fs_time+0x27/0x30
 [<ffffffff8117d170>] ? mem_cgroup_get_reclaim_stat_from_page+0x20/0x70
 [<ffffffff8111b7aa>] group_sched_in+0x13a/0x170
 [<ffffffff81014a29>] ? sched_clock+0x9/0x10
 [<ffffffff8111bac8>] ctx_sched_in+0x2e8/0x330
 [<ffffffff8111bb7b>] perf_event_sched_in+0x6b/0xb0
 [<ffffffff8111bc36>] perf_event_context_sched_in+0x76/0xc0
 [<ffffffff8111eb3b>] perf_event_comm+0x1bb/0x2e0
 [<ffffffff81195ee9>] set_task_comm+0x69/0x80
 [<ffffffff81195fe1>] setup_new_exec+0xe1/0x2e0
 [<ffffffff811ea68e>] load_elf_binary+0x3ce/0x1ab0

Adding cpu_(prepare|starting|dying) for core_pmu to have shared_regs
data allocated for core_pmu. AFAICS there's no harm to initialize
debug store and PMU_FL_EXCL_CNTRS either for core_pmu.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 arch/x86/kernel/cpu/perf_event_intel.c | 66 +++++++++++++++++++---------------
 1 file changed, 38 insertions(+), 28 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
index 9da2400c2ec3..8a4e21eb2087 100644
--- a/arch/x86/kernel/cpu/perf_event_intel.c
+++ b/arch/x86/kernel/cpu/perf_event_intel.c
@@ -2533,34 +2533,6 @@ ssize_t intel_event_sysfs_show(char *page, u64 config)
 	return x86_event_sysfs_show(page, config, event);
 }
 
-static __initconst const struct x86_pmu core_pmu = {
-	.name			= "core",
-	.handle_irq		= x86_pmu_handle_irq,
-	.disable_all		= x86_pmu_disable_all,
-	.enable_all		= core_pmu_enable_all,
-	.enable			= core_pmu_enable_event,
-	.disable		= x86_pmu_disable_event,
-	.hw_config		= x86_pmu_hw_config,
-	.schedule_events	= x86_schedule_events,
-	.eventsel		= MSR_ARCH_PERFMON_EVENTSEL0,
-	.perfctr		= MSR_ARCH_PERFMON_PERFCTR0,
-	.event_map		= intel_pmu_event_map,
-	.max_events		= ARRAY_SIZE(intel_perfmon_event_map),
-	.apic			= 1,
-	/*
-	 * Intel PMCs cannot be accessed sanely above 32 bit width,
-	 * so we install an artificial 1<<31 period regardless of
-	 * the generic event period:
-	 */
-	.max_period		= (1ULL << 31) - 1,
-	.get_event_constraints	= intel_get_event_constraints,
-	.put_event_constraints	= intel_put_event_constraints,
-	.event_constraints	= intel_core_event_constraints,
-	.guest_get_msrs		= core_guest_get_msrs,
-	.format_attrs		= intel_arch_formats_attr,
-	.events_sysfs_show	= intel_event_sysfs_show,
-};
-
 struct intel_shared_regs *allocate_shared_regs(int cpu)
 {
 	struct intel_shared_regs *regs;
@@ -2743,6 +2715,44 @@ static struct attribute *intel_arch3_formats_attr[] = {
 	NULL,
 };
 
+static __initconst const struct x86_pmu core_pmu = {
+	.name			= "core",
+	.handle_irq		= x86_pmu_handle_irq,
+	.disable_all		= x86_pmu_disable_all,
+	.enable_all		= core_pmu_enable_all,
+	.enable			= core_pmu_enable_event,
+	.disable		= x86_pmu_disable_event,
+	.hw_config		= x86_pmu_hw_config,
+	.schedule_events	= x86_schedule_events,
+	.eventsel		= MSR_ARCH_PERFMON_EVENTSEL0,
+	.perfctr		= MSR_ARCH_PERFMON_PERFCTR0,
+	.event_map		= intel_pmu_event_map,
+	.max_events		= ARRAY_SIZE(intel_perfmon_event_map),
+	.apic			= 1,
+	/*
+	 * Intel PMCs cannot be accessed sanely above 32 bit width,
+	 * so we install an artificial 1<<31 period regardless of
+	 * the generic event period:
+	 */
+	.max_period		= (1ULL << 31) - 1,
+	.get_event_constraints	= intel_get_event_constraints,
+	.put_event_constraints	= intel_put_event_constraints,
+	.event_constraints	= intel_core_event_constraints,
+	.guest_get_msrs		= core_guest_get_msrs,
+	.format_attrs		= intel_arch_formats_attr,
+	.events_sysfs_show	= intel_event_sysfs_show,
+
+	/*
+	 * Virtual (or funny metal) CPU can define x86_pmu.extra_regs
+	 * together with PMU version 1 and thus be using core_pmu with
+	 * shared_regs. We need following callbacks here to allocate
+	 * it properly.
+	 */
+	.cpu_prepare		= intel_pmu_cpu_prepare,
+	.cpu_starting		= intel_pmu_cpu_starting,
+	.cpu_dying		= intel_pmu_cpu_dying,
+};
+
 static __initconst const struct x86_pmu intel_pmu = {
 	.name			= "Intel",
 	.handle_irq		= intel_pmu_handle_irq,
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCHv3] perf/x86/intel: Add cpu_(prepare|starting|dying) for core_pmu
  2015-04-21 15:26     ` [PATCHv3] " Jiri Olsa
@ 2015-04-21 21:00       ` Peter Zijlstra
  2015-04-22 14:10       ` [tip:perf/urgent] perf/x86/intel: Add cpu_(prepare|starting|dying ) " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 8+ messages in thread
From: Peter Zijlstra @ 2015-04-21 21:00 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Jiri Olsa, lkml, Andi Kleen, Arnaldo Carvalho de Melo,
	Ingo Molnar, Paul Mackerras, Stephane Eranian

On Tue, Apr 21, 2015 at 05:26:23PM +0200, Jiri Olsa wrote:
> The core_pmu does not define cpu_* callbacks, which handles
> allocation of 'struct cpu_hw_events::shared_regs' data,
> initialization of debug store and PMU_FL_EXCL_CNTRS counters.
> 
> While this probably won't happen on bare metal, virtual CPU can
> define x86_pmu.extra_regs together with PMU version 1 and thus
> be using core_pmu -> using shared_regs data without it being
> allocated. That could could leave to following panic:
> 
> BUG: unable to handle kernel NULL pointer dereference at (null)
> IP: [<ffffffff8152cd4f>] _spin_lock_irqsave+0x1f/0x40
> 
> SNIP
> 
>  [<ffffffff81024bd9>] __intel_shared_reg_get_constraints+0x69/0x1e0
>  [<ffffffff81024deb>] intel_get_event_constraints+0x9b/0x180
>  [<ffffffff8101e815>] x86_schedule_events+0x75/0x1d0
>  [<ffffffff810586dc>] ? check_preempt_curr+0x7c/0x90
>  [<ffffffff810649fe>] ? try_to_wake_up+0x24e/0x3e0
>  [<ffffffff81064ba2>] ? default_wake_function+0x12/0x20
>  [<ffffffff8109eb16>] ? autoremove_wake_function+0x16/0x40
>  [<ffffffff810577e9>] ? __wake_up_common+0x59/0x90
>  [<ffffffff811a9517>] ? __d_lookup+0xa7/0x150
>  [<ffffffff8119db5f>] ? do_lookup+0x9f/0x230
>  [<ffffffff811a993a>] ? dput+0x9a/0x150
>  [<ffffffff8119c8f5>] ? path_to_nameidata+0x25/0x60
>  [<ffffffff8119e90a>] ? __link_path_walk+0x7da/0x1000
>  [<ffffffff8101d8f9>] ? x86_pmu_add+0xb9/0x170
>  [<ffffffff8101d7a7>] x86_pmu_commit_txn+0x67/0xc0
>  [<ffffffff811b07b0>] ? mntput_no_expire+0x30/0x110
>  [<ffffffff8119c731>] ? path_put+0x31/0x40
>  [<ffffffff8107c297>] ? current_fs_time+0x27/0x30
>  [<ffffffff8117d170>] ? mem_cgroup_get_reclaim_stat_from_page+0x20/0x70
>  [<ffffffff8111b7aa>] group_sched_in+0x13a/0x170
>  [<ffffffff81014a29>] ? sched_clock+0x9/0x10
>  [<ffffffff8111bac8>] ctx_sched_in+0x2e8/0x330
>  [<ffffffff8111bb7b>] perf_event_sched_in+0x6b/0xb0
>  [<ffffffff8111bc36>] perf_event_context_sched_in+0x76/0xc0
>  [<ffffffff8111eb3b>] perf_event_comm+0x1bb/0x2e0
>  [<ffffffff81195ee9>] set_task_comm+0x69/0x80
>  [<ffffffff81195fe1>] setup_new_exec+0xe1/0x2e0
>  [<ffffffff811ea68e>] load_elf_binary+0x3ce/0x1ab0
> 
> Adding cpu_(prepare|starting|dying) for core_pmu to have shared_regs
> data allocated for core_pmu. AFAICS there's no harm to initialize
> debug store and PMU_FL_EXCL_CNTRS either for core_pmu.
> 
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tip:perf/urgent] perf/x86/intel: Add cpu_(prepare|starting|dying ) for core_pmu
  2015-04-21 15:26     ` [PATCHv3] " Jiri Olsa
  2015-04-21 21:00       ` Peter Zijlstra
@ 2015-04-22 14:10       ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 8+ messages in thread
From: tip-bot for Jiri Olsa @ 2015-04-22 14:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, jolsa, jolsa, acme, mingo, linux-kernel, hpa, eranian,
	tglx, paulus

Commit-ID:  3b6e042188994466ec257b71296b5f85b894dcd9
Gitweb:     http://git.kernel.org/tip/3b6e042188994466ec257b71296b5f85b894dcd9
Author:     Jiri Olsa <jolsa@redhat.com>
AuthorDate: Tue, 21 Apr 2015 17:26:23 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 22 Apr 2015 08:24:33 +0200

perf/x86/intel: Add cpu_(prepare|starting|dying) for core_pmu

The core_pmu does not define cpu_* callbacks, which handles
allocation of 'struct cpu_hw_events::shared_regs' data,
initialization of debug store and PMU_FL_EXCL_CNTRS counters.

While this probably won't happen on bare metal, virtual CPU can
define x86_pmu.extra_regs together with PMU version 1 and thus
be using core_pmu -> using shared_regs data without it being
allocated. That could could leave to following panic:

	BUG: unable to handle kernel NULL pointer dereference at (null)
	IP: [<ffffffff8152cd4f>] _spin_lock_irqsave+0x1f/0x40

	SNIP

	 [<ffffffff81024bd9>] __intel_shared_reg_get_constraints+0x69/0x1e0
	 [<ffffffff81024deb>] intel_get_event_constraints+0x9b/0x180
	 [<ffffffff8101e815>] x86_schedule_events+0x75/0x1d0
	 [<ffffffff810586dc>] ? check_preempt_curr+0x7c/0x90
	 [<ffffffff810649fe>] ? try_to_wake_up+0x24e/0x3e0
	 [<ffffffff81064ba2>] ? default_wake_function+0x12/0x20
	 [<ffffffff8109eb16>] ? autoremove_wake_function+0x16/0x40
	 [<ffffffff810577e9>] ? __wake_up_common+0x59/0x90
	 [<ffffffff811a9517>] ? __d_lookup+0xa7/0x150
	 [<ffffffff8119db5f>] ? do_lookup+0x9f/0x230
	 [<ffffffff811a993a>] ? dput+0x9a/0x150
	 [<ffffffff8119c8f5>] ? path_to_nameidata+0x25/0x60
	 [<ffffffff8119e90a>] ? __link_path_walk+0x7da/0x1000
	 [<ffffffff8101d8f9>] ? x86_pmu_add+0xb9/0x170
	 [<ffffffff8101d7a7>] x86_pmu_commit_txn+0x67/0xc0
	 [<ffffffff811b07b0>] ? mntput_no_expire+0x30/0x110
	 [<ffffffff8119c731>] ? path_put+0x31/0x40
	 [<ffffffff8107c297>] ? current_fs_time+0x27/0x30
	 [<ffffffff8117d170>] ? mem_cgroup_get_reclaim_stat_from_page+0x20/0x70
	 [<ffffffff8111b7aa>] group_sched_in+0x13a/0x170
	 [<ffffffff81014a29>] ? sched_clock+0x9/0x10
	 [<ffffffff8111bac8>] ctx_sched_in+0x2e8/0x330
	 [<ffffffff8111bb7b>] perf_event_sched_in+0x6b/0xb0
	 [<ffffffff8111bc36>] perf_event_context_sched_in+0x76/0xc0
	 [<ffffffff8111eb3b>] perf_event_comm+0x1bb/0x2e0
	 [<ffffffff81195ee9>] set_task_comm+0x69/0x80
	 [<ffffffff81195fe1>] setup_new_exec+0xe1/0x2e0
	 [<ffffffff811ea68e>] load_elf_binary+0x3ce/0x1ab0

Adding cpu_(prepare|starting|dying) for core_pmu to have
shared_regs data allocated for core_pmu. AFAICS there's no harm
to initialize debug store and PMU_FL_EXCL_CNTRS either for
core_pmu.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20150421152623.GC13169@krava.redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/cpu/perf_event_intel.c | 66 +++++++++++++++++++---------------
 1 file changed, 38 insertions(+), 28 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
index 219d3fb..960e85d 100644
--- a/arch/x86/kernel/cpu/perf_event_intel.c
+++ b/arch/x86/kernel/cpu/perf_event_intel.c
@@ -2533,34 +2533,6 @@ ssize_t intel_event_sysfs_show(char *page, u64 config)
 	return x86_event_sysfs_show(page, config, event);
 }
 
-static __initconst const struct x86_pmu core_pmu = {
-	.name			= "core",
-	.handle_irq		= x86_pmu_handle_irq,
-	.disable_all		= x86_pmu_disable_all,
-	.enable_all		= core_pmu_enable_all,
-	.enable			= core_pmu_enable_event,
-	.disable		= x86_pmu_disable_event,
-	.hw_config		= x86_pmu_hw_config,
-	.schedule_events	= x86_schedule_events,
-	.eventsel		= MSR_ARCH_PERFMON_EVENTSEL0,
-	.perfctr		= MSR_ARCH_PERFMON_PERFCTR0,
-	.event_map		= intel_pmu_event_map,
-	.max_events		= ARRAY_SIZE(intel_perfmon_event_map),
-	.apic			= 1,
-	/*
-	 * Intel PMCs cannot be accessed sanely above 32 bit width,
-	 * so we install an artificial 1<<31 period regardless of
-	 * the generic event period:
-	 */
-	.max_period		= (1ULL << 31) - 1,
-	.get_event_constraints	= intel_get_event_constraints,
-	.put_event_constraints	= intel_put_event_constraints,
-	.event_constraints	= intel_core_event_constraints,
-	.guest_get_msrs		= core_guest_get_msrs,
-	.format_attrs		= intel_arch_formats_attr,
-	.events_sysfs_show	= intel_event_sysfs_show,
-};
-
 struct intel_shared_regs *allocate_shared_regs(int cpu)
 {
 	struct intel_shared_regs *regs;
@@ -2743,6 +2715,44 @@ static struct attribute *intel_arch3_formats_attr[] = {
 	NULL,
 };
 
+static __initconst const struct x86_pmu core_pmu = {
+	.name			= "core",
+	.handle_irq		= x86_pmu_handle_irq,
+	.disable_all		= x86_pmu_disable_all,
+	.enable_all		= core_pmu_enable_all,
+	.enable			= core_pmu_enable_event,
+	.disable		= x86_pmu_disable_event,
+	.hw_config		= x86_pmu_hw_config,
+	.schedule_events	= x86_schedule_events,
+	.eventsel		= MSR_ARCH_PERFMON_EVENTSEL0,
+	.perfctr		= MSR_ARCH_PERFMON_PERFCTR0,
+	.event_map		= intel_pmu_event_map,
+	.max_events		= ARRAY_SIZE(intel_perfmon_event_map),
+	.apic			= 1,
+	/*
+	 * Intel PMCs cannot be accessed sanely above 32-bit width,
+	 * so we install an artificial 1<<31 period regardless of
+	 * the generic event period:
+	 */
+	.max_period		= (1ULL<<31) - 1,
+	.get_event_constraints	= intel_get_event_constraints,
+	.put_event_constraints	= intel_put_event_constraints,
+	.event_constraints	= intel_core_event_constraints,
+	.guest_get_msrs		= core_guest_get_msrs,
+	.format_attrs		= intel_arch_formats_attr,
+	.events_sysfs_show	= intel_event_sysfs_show,
+
+	/*
+	 * Virtual (or funny metal) CPU can define x86_pmu.extra_regs
+	 * together with PMU version 1 and thus be using core_pmu with
+	 * shared_regs. We need following callbacks here to allocate
+	 * it properly.
+	 */
+	.cpu_prepare		= intel_pmu_cpu_prepare,
+	.cpu_starting		= intel_pmu_cpu_starting,
+	.cpu_dying		= intel_pmu_cpu_dying,
+};
+
 static __initconst const struct x86_pmu intel_pmu = {
 	.name			= "Intel",
 	.handle_irq		= intel_pmu_handle_irq,

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-04-22 14:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-21  8:54 [PATCH] perf/x86/intel: Add cpu_(prepare|starting|dying) for core_pmu Jiri Olsa
2015-04-21 10:52 ` Ingo Molnar
2015-04-21 15:14   ` [PATCHv2] " Jiri Olsa
2015-04-21 15:12 ` [PATCH] " Peter Zijlstra
2015-04-21 15:18   ` Jiri Olsa
2015-04-21 15:26     ` [PATCHv3] " Jiri Olsa
2015-04-21 21:00       ` Peter Zijlstra
2015-04-22 14:10       ` [tip:perf/urgent] perf/x86/intel: Add cpu_(prepare|starting|dying ) " tip-bot for Jiri Olsa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.