From 1d12d35284b74b7257b84ba0cef1e82a66d73aea Mon Sep 17 00:00:00 2001 From: Maarten Lankhorst Date: Mon, 1 Aug 2011 11:08:59 -0400 Subject: [PATCH 1/2] oprofile, x86: Convert memory allocation to static array On -rt, allocators don't work from atomic context any more, and the maximum size of the array is known at compile time. Call trace on a -rt kernel: oprofile: using NMI interrupt. BUG: sleeping function called from invalid context at kernel/rtmutex.c:645 in_atomic(): 1, irqs_disabled(): 1, pid: 0, name: kworker/0:1 Pid: 0, comm: kworker/0:1 Tainted: G C 3.0.0-rt3-patser+ #39 Call Trace: [] __might_sleep+0xca/0xf0 [] rt_spin_lock+0x24/0x40 [] __kmalloc+0xc7/0x370 [] ? ppro_setup_ctrs+0x215/0x260 [oprofile] [] ? oprofile_cpu_notifier+0x60/0x60 [oprofile] [] ppro_setup_ctrs+0x215/0x260 [oprofile] [] ? oprofile_cpu_notifier+0x60/0x60 [oprofile] [] ? oprofile_cpu_notifier+0x60/0x60 [oprofile] [] nmi_cpu_setup+0xc4/0x110 [oprofile] [] generic_smp_call_function_interrupt+0x95/0x190 [] smp_call_function_interrupt+0x27/0x40 [] call_function_interrupt+0x13/0x20 [] ? plist_check_head+0x54/0xc0 [] ? intel_idle+0xc8/0x120 [] ? intel_idle+0xa7/0x120 [] cpuidle_idle_call+0xb0/0x230 [] cpu_idle+0x8b/0xe0 [] start_secondary+0x1d3/0x1d8 Signed-off-by: Maarten Lankhorst Signed-off-by: Robert Richter --- arch/x86/oprofile/op_model_ppro.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c index 94b745045e4509..608874b70cf46e 100644 --- a/arch/x86/oprofile/op_model_ppro.c +++ b/arch/x86/oprofile/op_model_ppro.c @@ -28,7 +28,7 @@ static int counter_width = 32; #define MSR_PPRO_EVENTSEL_RESERVED ((0xFFFFFFFFULL<<32)|(1ULL<<21)) -static u64 *reset_value; +static u64 reset_value[OP_MAX_COUNTER]; static void ppro_shutdown(struct op_msrs const * const msrs) { @@ -40,10 +40,6 @@ static void ppro_shutdown(struct op_msrs const * const msrs) release_perfctr_nmi(MSR_P6_PERFCTR0 + i); release_evntsel_nmi(MSR_P6_EVNTSEL0 + i); } - if (reset_value) { - kfree(reset_value); - reset_value = NULL; - } } static int ppro_fill_in_addresses(struct op_msrs * const msrs) @@ -79,13 +75,6 @@ static void ppro_setup_ctrs(struct op_x86_model_spec const *model, u64 val; int i; - if (!reset_value) { - reset_value = kzalloc(sizeof(reset_value[0]) * num_counters, - GFP_ATOMIC); - if (!reset_value) - return; - } - if (cpu_has_arch_perfmon) { union cpuid10_eax eax; eax.full = cpuid_eax(0xa); @@ -141,13 +130,6 @@ static int ppro_check_ctrs(struct pt_regs * const regs, u64 val; int i; - /* - * This can happen if perf counters are in use when - * we steal the die notifier NMI. - */ - if (unlikely(!reset_value)) - goto out; - for (i = 0; i < num_counters; ++i) { if (!reset_value[i]) continue; @@ -179,8 +161,6 @@ static void ppro_start(struct op_msrs const * const msrs) u64 val; int i; - if (!reset_value) - return; for (i = 0; i < num_counters; ++i) { if (reset_value[i]) { rdmsrl(msrs->controls[i].addr, val); @@ -196,8 +176,6 @@ static void ppro_stop(struct op_msrs const * const msrs) u64 val; int i; - if (!reset_value) - return; for (i = 0; i < num_counters; ++i) { if (!reset_value[i]) continue; From 298557db42eb2d6efca81669dc369425b46c5be6 Mon Sep 17 00:00:00 2001 From: Robert Richter Date: Tue, 16 Aug 2011 23:39:53 +0200 Subject: [PATCH 2/2] oprofile, x86: Fix overflow and warning (commit 1d12d35) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Following fixes for: 1d12d35 oprofile, x86: Convert memory allocation to static array Fix potential buffer overflow. Fix the following warning: arch/x86/oprofile/op_model_ppro.c: In function ‘ppro_check_ctrs’: arch/x86/oprofile/op_model_ppro.c:143: warning: label ‘out’ defined but not used Cc: Maarten Lankhorst Cc: Andi Kleen Signed-off-by: Robert Richter --- arch/x86/oprofile/op_model_ppro.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c index 608874b70cf46e..d90528ea541206 100644 --- a/arch/x86/oprofile/op_model_ppro.c +++ b/arch/x86/oprofile/op_model_ppro.c @@ -140,7 +140,6 @@ static int ppro_check_ctrs(struct pt_regs * const regs, wrmsrl(msrs->counters[i].addr, -reset_value[i]); } -out: /* Only P6 based Pentium M need to re-unmask the apic vector but it * doesn't hurt other P6 variant */ apic_write(APIC_LVTPC, apic_read(APIC_LVTPC) & ~APIC_LVT_MASKED); @@ -220,7 +219,7 @@ static void arch_perfmon_setup_counters(void) eax.split.bit_width = 40; } - num_counters = eax.split.num_counters; + num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER); op_arch_perfmon_spec.num_counters = num_counters; op_arch_perfmon_spec.num_controls = num_counters;