Skip to content

Commit

Permalink
perf, x86: Avoid kfree() in CPU_STARTING
Browse files Browse the repository at this point in the history
On -rt kfree() can schedule, but CPU_STARTING is before the CPU is
fully up and running. These are contradictory, so avoid it. Instead
push the kfree() to CPU_ONLINE where we're free to schedule.

Reported-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-kwd4j6ayld5thrscvaxgjquv@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Aug 14, 2011
1 parent bdc2209 commit 7fdba1c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions arch/x86/kernel/cpu/perf_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ struct cpu_hw_events {
* AMD specific bits
*/
struct amd_nb *amd_nb;

void *kfree_on_online;
};

#define __EVENT_CONSTRAINT(c, n, m, w) {\
Expand Down Expand Up @@ -1466,10 +1468,12 @@ static int __cpuinit
x86_pmu_notifier(struct notifier_block *self, unsigned long action, void *hcpu)
{
unsigned int cpu = (long)hcpu;
struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
int ret = NOTIFY_OK;

switch (action & ~CPU_TASKS_FROZEN) {
case CPU_UP_PREPARE:
cpuc->kfree_on_online = NULL;
if (x86_pmu.cpu_prepare)
ret = x86_pmu.cpu_prepare(cpu);
break;
Expand All @@ -1479,6 +1483,10 @@ x86_pmu_notifier(struct notifier_block *self, unsigned long action, void *hcpu)
x86_pmu.cpu_starting(cpu);
break;

case CPU_ONLINE:
kfree(cpuc->kfree_on_online);
break;

case CPU_DYING:
if (x86_pmu.cpu_dying)
x86_pmu.cpu_dying(cpu);
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpu/perf_event_amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ static void amd_pmu_cpu_starting(int cpu)
continue;

if (nb->nb_id == nb_id) {
kfree(cpuc->amd_nb);
cpuc->kfree_on_online = cpuc->amd_nb;
cpuc->amd_nb = nb;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpu/perf_event_intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ static void intel_pmu_cpu_starting(int cpu)

pc = per_cpu(cpu_hw_events, i).shared_regs;
if (pc && pc->core_id == core_id) {
kfree(cpuc->shared_regs);
cpuc->kfree_on_online = cpuc->shared_regs;
cpuc->shared_regs = pc;
break;
}
Expand Down

0 comments on commit 7fdba1c

Please sign in to comment.