perf,p4 series for -tip
Subsystems (2)
cover perf,p4 series for -tip
Hi,
please review and test if possible. Any complains
are quite welcome! Thanks!
Cyrill
PATCH 1/4 x86,perf: P4 PMU -- configurate predefined events
If an event is not RAW we should exit p4_hw_config early but call x86_setup_perfctr as well.
---
Robert, if only I'm not missing something this is
a side effect of commit 9d0fcba67e47ff398a6fa86476d4884d472dc98a, wonders why don't we hit it earlier. Am I wrong?
arch/x86/kernel/cpu/perf_event_p4.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
arch/x86/kernel/cpu/perf_event_p4.c +14 -15
@@ -439,21 +439,20 @@ static int p4_hw_config(struct perf_evenif (p4_ht_active () &&p4_ht_thread (cpu)) event->hw.config =p4_set_ht_bit (event->hw.config); -if (event->attr.type !=PERF_TYPE_RAW ) -return 0 ; - -/* -* We don't control raw events so it's up to the caller -* to pass sane values (and we don't count the thread number -* on HT machine but allow HT-compatible specifics to be -* passed on) -* -* XXX: HT wide things should check perf_paranoid_cpu() && -* CAP_SYS_ADMIN -*/ - event->hw.config |= event->attr.config & - (p4_config_pack_escr (P4_ESCR_MASK_HT ) | -p4_config_pack_cccr (P4_CCCR_MASK_HT )); +if (event->attr.type ==PERF_TYPE_RAW ) { +/* +* We don't control raw events so it's up to the caller +* to pass sane values (and we don't count the thread number +* on HT machine but allow HT-compatible specifics to be +* passed on) +* +* XXX: HT wide things should check perf_paranoid_cpu() && +* CAP_SYS_ADMIN +*/ + event->hw.config |= event->attr.config & + (p4_config_pack_escr (P4_ESCR_MASK_HT ) | +p4_config_pack_cccr (P4_CCCR_MASK_HT )); + }return x86_setup_perfctr (event); }
Re: [patch 1/4] x86,perf: P4 PMU -- configurate predefined events
Quoted 3 lines · Cyrill Gorcunov
If an event is not RAW we should exit
p4_hw_configearly but callx86_setup_perfctras well.
Actually i meant "should not"
Quoted 57 lines
CC Peter Zijlstra <[email protected]>CC Ingo Molnar <[email protected]>CC Frederic Weisbecker <[email protected]>CC Lin Ming <[email protected]>CC Robert Richter <[email protected]>Signed-off-by Cyrill Gorcunov <[email protected]>---
Robert, if only I'm not missing something this is
a side effect of commit9d0fcba67e47ff398a6fa86476d4884d472dc98a, wonders why don't we hit it earlier. Am I wrong?arch/x86/kernel/cpu/perf_event_p4.c | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)Index:
linux-2.6.git/arch/x86/kernel/cpu/perf_event_p4.c
=====================================================================arch/x86/kernel/cpu/perf_event_p4.c +14
-15@@ -439,21 +439,20 @@ static int p4_hw_config(struct perf_even if (p4_ht_active() && p4_ht_thread(cpu)) event->hw.config = p4_set_ht_bit(event->hw.config); - if (event->attr.type != PERF_TYPE_RAW) - return 0; - - /* - * We don't control raw events so it's up to the caller - * to pass sane values (and we don't count the thread number - * on HT machine but allow HT-compatible specifics to be - * passed on) - * - * XXX: HT wide things should check perf_paranoid_cpu() && - * CAP_SYS_ADMIN - */ - event->hw.config |= event->attr.config & - (p4_config_pack_escr(P4_ESCR_MASK_HT) | - p4_config_pack_cccr(P4_CCCR_MASK_HT)); + if (event->attr.type == PERF_TYPE_RAW) { + /* + * We don't control raw events so it's up to the caller + * to pass sane values (and we don't count the thread number + * on HT machine but allow HT-compatible specifics to be + * passed on) + * + * XXX: HT wide things should check perf_paranoid_cpu() && + * CAP_SYS_ADMIN + */ + event->hw.config |= event->attr.config & + (p4_config_pack_escr(P4_ESCR_MASK_HT) | + p4_config_pack_cccr(P4_CCCR_MASK_HT)); + } return x86_setup_perfctr(event); }
Re: [patch 1/4] x86,perf: P4 PMU -- configurate predefined events
In reply to Cyrill GorcunovQuoted 9 lines · Cyrill Gorcunov
If an event is not RAW we should exit
p4_hw_configearly but callx86_setup_perfctras well.CC Peter Zijlstra <[email protected]>CC Ingo Molnar <[email protected]>CC Frederic Weisbecker <[email protected]>CC Lin Ming <[email protected]>CC Robert Richter <[email protected]>Signed-off-by Cyrill Gorcunov <[email protected]>
Quoted 5 lines
---
Robert, if only I'm not missing something this is
a side effect of commit9d0fcba67e47ff398a6fa86476d4884d472dc98a, wonders why don't we hit it earlier. Am I wrong?
Yes, that's true, the function had have two exit points. Thanks for the fix.
-Robert
Signature · 3 lines
Advanced Micro Devices, Inc. Operating System Research Center email: [email protected]
PATCH 2/4 x86,perf: P4 PMU -- protect sensible procedures from preemption
In reply to Cyrill GorcunovSteven reported
| | I'm getting: | | Pid: 3477, comm: perf Not tainted 2.6.34-rc6 #2727 | Call Trace: | [<ffffffff811c7565>] debug_smp_processor_id+0xd5/0xf0 | [<ffffffff81019874>] p4_hw_config+0x2b/0x15c | [<ffffffff8107acbc>] ? trace_hardirqs_on_caller+0x12b/0x14f | [<ffffffff81019143>] hw_perf_event_init+0x468/0x7be | [<ffffffff810782fd>] ? debug_mutex_init+0x31/0x3c | [<ffffffff810c68b2>] T.850+0x273/0x42e | [<ffffffff810c6cab>] sys_perf_event_open+0x23e/0x3f1 | [<ffffffff81009e6a>] ? sysret_check+0x2e/0x69 | [<ffffffff81009e32>] system_call_fastpath+0x16/0x1b | | When running perf record in latest tip/perf/core |
Due to the fact that p4 counters are shared between HT threads we synthetically divide the whole set of counters into two non-intersected subsets. And while we're "borrowing" counters from these subsets we should not be preempted (well, strictly speaking in p4_hw_config we just pre-set reference to the subset which allow to save some cycles in schedule routine if it happens on the same cpu). So use get_cpu/put_cpu pair.
Also p4_pmu_schedule_events should use smp_processor_id rather than raw_ version. This allow us to catch up preemption issue (if there will ever be).
---
Note: I've removed Steven's Tested-by tag, since due to commit 9d0fcba67e47ff398a6fa86476d4884d472dc98a the former patch Steven were testing is not applicable anymore.
arch/x86/kernel/cpu/perf_event_p4.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event_p4.c +6 -2
@@ -421,7 +421,8 @@ static u64 p4_pmu_event_map(int hw_eventstatic int p4_hw_config (struct perf_event *event) { -int cpu =raw_smp_processor_id (); +int cpu =get_cpu (); +int rc =0 ;u32 escr, cccr;/*
@@ -454,7 +455,10 @@ static int p4_hw_config(struct perf_even p4_config_pack_cccr(P4_CCCR_MASK_HT)); } -return x86_setup_perfctr (event); + rc =x86_setup_perfctr (event); +put_cpu (); + +return rc; }static inline void p4_pmu_clear_cccr_ovf (struct hw_perf_event *hwc)
[tip:perf/core] x86, perf: P4 PMU -- protect sensible procedures from preemption
Commit-ID: 137351e0feeb9f25d99488ee1afc1c79f5499a9a Gitweb: http://git.kernel.org/tip/137351e0feeb9f25d99488ee1afc1c79f5499a9a Author: Cyrill Gorcunov <[email protected]> AuthorDate: Sat, 8 May 2010 15:25:52 +0400 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 8 May 2010 14:17:53 +0200
x86, perf: P4 PMU -- protect sensible procedures from preemption
Steven reported:
| | I'm getting: | | Pid: 3477, comm: perf Not tainted 2.6.34-rc6 #2727 | Call Trace: | [<ffffffff811c7565>] debug_smp_processor_id+0xd5/0xf0 | [<ffffffff81019874>] p4_hw_config+0x2b/0x15c | [<ffffffff8107acbc>] ? trace_hardirqs_on_caller+0x12b/0x14f | [<ffffffff81019143>] hw_perf_event_init+0x468/0x7be | [<ffffffff810782fd>] ? debug_mutex_init+0x31/0x3c | [<ffffffff810c68b2>] T.850+0x273/0x42e | [<ffffffff810c6cab>] sys_perf_event_open+0x23e/0x3f1 | [<ffffffff81009e6a>] ? sysret_check+0x2e/0x69 | [<ffffffff81009e32>] system_call_fastpath+0x16/0x1b | | When running perf record in latest tip/perf/core |
Due to the fact that p4 counters are shared between HT threads we synthetically divide the whole set of counters into two non-intersected subsets. And while we're "borrowing" counters from these subsets we should not be preempted (well, strictly speaking in p4_hw_config we just pre-set reference to the subset which allow to save some cycles in schedule routine if it happens on the same cpu). So use get_cpu/put_cpu pair.
Also p4_pmu_schedule_events should use smp_processor_id rather than raw_ version. This allow us to catch up preemption issue (if there will ever be).
LKML-Reference: <[email protected]>
--- arch/x86/kernel/cpu/perf_event_p4.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event_p4.c +6 -2
@@ -421,7 +421,8 @@ static u64 p4_pmu_event_map(int hw_event)static int p4_hw_config (struct perf_event *event) { -int cpu =raw_smp_processor_id (); +int cpu =get_cpu (); +int rc =0 ;u32 escr, cccr;/*
@@ -454,7 +455,10 @@ static int p4_hw_config(struct perf_event *event) p4_config_pack_cccr(P4_CCCR_MASK_HT)); } -return x86_setup_perfctr (event); + rc =x86_setup_perfctr (event); +put_cpu (); + +return rc; }static inline void p4_pmu_clear_cccr_ovf (struct hw_perf_event *hwc)
PATCH 3/4 x86,perf: P4 PMU -- Get rid of redundant check for array index
In reply to Cyrill GorcunovThe caller already has done such a check.
And it was wrong anyway, it had to be '>=' rather then '>'
--- arch/x86/kernel/cpu/perf_event_p4.c | 5 ----- 1 file changed, 5 deletions(-)
arch/x86/kernel/cpu/perf_event_p4.c +0 -5
@@ -406,11 +406,6 @@ static u64 p4_pmu_event_map(int hw_eventunsigned int esel;u64 config; -if (hw_event >ARRAY_SIZE (p4_general_events)) { -printk_once (KERN_ERR "P4 PMU: Bad index: %i\n" , hw_event); -return 0 ; - } - config = p4_general_events[hw_event]; bind =p4_config_get_bind (config); esel =P4_OPCODE_ESEL (bind->opcode);
[tip:perf/core] x86, perf: P4 PMU -- Get rid of redundant check for array index
Commit-ID: 3f51b7119d052827dbb0e40c966acdf2bdc6f47f Gitweb: http://git.kernel.org/tip/3f51b7119d052827dbb0e40c966acdf2bdc6f47f Author: Cyrill Gorcunov <[email protected]> AuthorDate: Sat, 8 May 2010 15:25:53 +0400 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 8 May 2010 14:17:53 +0200
x86, perf: P4 PMU -- Get rid of redundant check for array index
The caller already has done such a check.
And it was wrong anyway, it had to be '>=' rather than '>'
LKML-Reference: <[email protected]>
--- arch/x86/kernel/cpu/perf_event_p4.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/perf_event_p4.c +0 -5
@@ -406,11 +406,6 @@ static u64 p4_pmu_event_map(int hw_event)unsigned int esel;u64 config; -if (hw_event >ARRAY_SIZE (p4_general_events)) { -printk_once (KERN_ERR "P4 PMU: Bad index: %i\n" , hw_event); -return 0 ; - } - config = p4_general_events[hw_event]; bind =p4_config_get_bind (config); esel =P4_OPCODE_ESEL (bind->opcode);
PATCH 4/4 x86,perf: P4 PMU -- check for proper event index in RAW events
In reply to Cyrill GorcunovRAW events are special and we should be ready for user passing insane event index.
--- arch/x86/kernel/cpu/perf_event_p4.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/perf_event_p4.c +10 -1
@@ -418,6 +418,7 @@ static int p4_hw_config(struct perf_even {int cpu =get_cpu ();int rc =0 ; +unsigned int evnt;u32 escr, cccr;/*
@@ -436,6 +437,14 @@ static int p4_hw_config(struct perf_even event->hw.config =p4_set_ht_bit (event->hw.config);if (event->attr.type ==PERF_TYPE_RAW ) { + +/* user data may have out-of-bound event index */ + evnt =p4_config_unpack_event (event->attr.config); +if (evnt >=ARRAY_SIZE (p4_event_bind_map)) { + rc = -EINVAL ; + goto out; + } +/* * We don't control raw events so it's up to the caller * to pass sane values (and we don't count the thread number
@@ -451,8 +460,8 @@ static int p4_hw_config(struct perf_even } rc =x86_setup_perfctr (event); +out:put_cpu (); -return rc; }
[tip:perf/core] x86, perf: P4 PMU -- check for proper event index in RAW events
Commit-ID: c7993165ef0c1d636ca05f4787739f8414584e6d Gitweb: http://git.kernel.org/tip/c7993165ef0c1d636ca05f4787739f8414584e6d Author: Cyrill Gorcunov <[email protected]> AuthorDate: Sat, 8 May 2010 15:25:54 +0400 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 8 May 2010 14:17:53 +0200
x86, perf: P4 PMU -- check for proper event index in RAW events
RAW events are special and we should be ready for user passing in insane event index values.
LKML-Reference: <[email protected]>
--- arch/x86/kernel/cpu/perf_event_p4.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/perf_event_p4.c +10 -1
@@ -418,6 +418,7 @@ static int p4_hw_config(struct perf_event *event) {int cpu =get_cpu ();int rc =0 ; +unsigned int evnt;u32 escr, cccr;/*
@@ -436,6 +437,14 @@ static int p4_hw_config(struct perf_event *event) event->hw.config =p4_set_ht_bit (event->hw.config);if (event->attr.type ==PERF_TYPE_RAW ) { + +/* user data may have out-of-bound event index */ + evnt =p4_config_unpack_event (event->attr.config); +if (evnt >=ARRAY_SIZE (p4_event_bind_map)) { + rc = -EINVAL ; + goto out; + } +/* * We don't control raw events so it's up to the caller * to pass sane values (and we don't count the thread number
@@ -451,8 +460,8 @@ static int p4_hw_config(struct perf_event *event) } rc =x86_setup_perfctr (event); +out:put_cpu (); -return rc; }