Skip to contentSkip to conversation

x86: Use for_each_possible_cpu to allocate msrs (was [PATCH] x86: fix oprofile double free (was Re: Multiple free during oprofile unload))

PATCH In review Arnaldo Carvalho de Melo 2 participants 2 messages May 31, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: Use for_each_possible_cpu to allocate msrs (was [PATCH] x86: fix oprofile double free (was Re: Multiple free during oprofile unload))

The fix for the fix needed a fix: allocate_msrs() was using for_each_online_cpu(), but nmi_setup uses for_each_possible_cpu(), and in my test machine, a Dell Poweredge 1950 I have 2 dual core Xeons, which makes for 4 possible cores, but wait, they are HT capable, so...

[acme@mica linux-2.6.21.3.orig]$ dmesg | grep Allowing
SMP: Allowing 8 CPUs, 4 hotplug CPUs [acme@mica linux-2.6.21.3.orig]$

We have 8 possible CPUs, but only 4 online, b00m. Fix it by making allocate_msrs agree with nmi_setup, i.e. make both use for_each_possible_cpu().

---

arch/i386/oprofile/nmi_int.c +1 -1
diff -uNrp linux-2.6.21.3.orig/arch/i386/oprofile/nmi_int.c linux-2.6.21.3.new/arch/i386/oprofile/nmi_int.c
@@ -154,7 +154,7 @@ static int allocate_msrs(void)
 	size_t counters_size = sizeof(struct op_msr) * model->num_counters;
 
 	int i;
-	for_each_online_cpu(i) {
+	for_each_possible_cpu(i) {
 		cpu_msrs[i].counters = kmalloc(counters_size, GFP_KERNEL);
 		if (!cpu_msrs[i].counters) {
 			success = 0;
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · * Arnaldo Carvalho de Melo ([email protected]) wrote:

The fix for the fix needed a fix: allocate_msrs() was using for_each_online_cpu(), but nmi_setup uses for_each_possible_cpu(), and in my test machine, a Dell Poweredge 1950 I have 2 dual core Xeons, which makes for 4 possible cores, but wait, they are HT capable, so...

[acme@mica linux-2.6.21.3.orig]$ dmesg | grep Allowing
SMP: Allowing 8 CPUs, 4 hotplug CPUs [acme@mica linux-2.6.21.3.orig]$

Quoted 5 lines

We have 8 possible CPUs, but only 4 online, b00m. Fix it by making allocate_msrs agree with nmi_setup, i.e. make both use for_each_possible_cpu().

Thanks Arnaldo. I noticed this earlier, but mistakenly didn't consider it an issue aside of code needing to be cleaned up and for hotplug (which I thought was already broken for other reasons). And the Opteron I tested on has possible == online. I tested this addition on both the AMD box, as well as an Intel box with possible > online. All looks good.

thanks,
-chris