Skip to content

Commit

Permalink
x86/tsc: Always unregister clocksource_tsc_early
Browse files Browse the repository at this point in the history
Don't leave the tsc-early clocksource registered if it errors out
early.

This was reported by Diego, who on his Core2 era machine got TSC
invalidated while it was running with tsc-early (due to C-states).
This results in keeping tsc-early with very bad effects.

Reported-and-Tested-by: Diego Viola <diego.viola@gmail.com>
Fixes: aa83c45 ("x86/tsc: Introduce early tsc clocksource")
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: len.brown@intel.com
Cc: rjw@rjwysocki.net
Cc: diego.viola@gmail.com
Cc: rui.zhang@intel.com
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/20180430100344.350507853@infradead.org
  • Loading branch information
Peter Zijlstra authored and Thomas Gleixner committed May 2, 2018
1 parent 6da6c0d commit e9088ad
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions arch/x86/kernel/tsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ static void tsc_refine_calibration_work(struct work_struct *work)

/* Don't bother refining TSC on unstable systems */
if (tsc_unstable)
return;
goto unreg;

/*
* Since the work is started early in boot, we may be
Expand Down Expand Up @@ -1297,11 +1297,12 @@ static void tsc_refine_calibration_work(struct work_struct *work)

out:
if (tsc_unstable)
return;
goto unreg;

if (boot_cpu_has(X86_FEATURE_ART))
art_related_clocksource = &clocksource_tsc;
clocksource_register_khz(&clocksource_tsc, tsc_khz);
unreg:
clocksource_unregister(&clocksource_tsc_early);
}

Expand All @@ -1311,8 +1312,8 @@ static int __init init_tsc_clocksource(void)
if (!boot_cpu_has(X86_FEATURE_TSC) || tsc_disabled > 0 || !tsc_khz)
return 0;

if (check_tsc_unstable())
return 0;
if (tsc_unstable)
goto unreg;

if (tsc_clocksource_reliable)
clocksource_tsc.flags &= ~CLOCK_SOURCE_MUST_VERIFY;
Expand All @@ -1328,6 +1329,7 @@ static int __init init_tsc_clocksource(void)
if (boot_cpu_has(X86_FEATURE_ART))
art_related_clocksource = &clocksource_tsc;
clocksource_register_khz(&clocksource_tsc, tsc_khz);
unreg:
clocksource_unregister(&clocksource_tsc_early);
return 0;
}
Expand Down

0 comments on commit e9088ad

Please sign in to comment.