Re: [tip: timers/core] hrtimer: Consolidate reprogramming code

From: Thomas Gleixner
Date: Thu Aug 12 2021 - 10:11:15 EST


On Thu, Aug 12 2021 at 09:19, Mike Galbraith wrote:
> Greetings Peter, may your day get off to a better start than my box's
> did :)
>
> On Tue, 2021-08-10 at 16:02 +0000, tip-bot2 for Peter Zijlstra wrote:
>> The following commit has been merged into the timers/core branch of tip:
>>
>> Commit-ID:     b14bca97c9f5c3e3f133445b01c723e95490d843
>> Gitweb:        https://git.kernel.org/tip/b14bca97c9f5c3e3f133445b01c723e95490d843
>> Author:        Peter Zijlstra <peterz@xxxxxxxxxxxxx>
>> AuthorDate:    Tue, 13 Jul 2021 15:39:47 +02:00
>> Committer:     Thomas Gleixner <tglx@xxxxxxxxxxxxx>
>> CommitterDate: Tue, 10 Aug 2021 17:57:22 +02:00
>>
>> hrtimer: Consolidate reprogramming code
>
> Per git-bisect, this is the tip.today commit that's bricking my box
> early in boot.

Let me stare at that.

> Another inspires the moan below, courtesy of VM, which
> unlike desktop box does not brick immediately thereafter.

> [ 0.556416] rtc_cmos 00:04: RTC can wake from S4
> [ 0.557184] rtc_cmos 00:04: registered as rtc0
> [ 0.557636] BUG: using smp_processor_id() in preemptible [00000000] code: swapper/0/1
> [ 0.558169] caller is debug_smp_processor_id+0x13/0x20
> [ 0.558511] CPU: 3 PID: 1 Comm: swapper/0 Not tainted 5.14.0.g1fd628c-tip #15
> [ 0.558946] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a-rebuilt.opensuse.org 04/01/2014
> [ 0.559623] Call Trace:
> [ 0.559796] dump_stack_lvl+0x62/0x78
> [ 0.560041] dump_stack+0xc/0xd
> [ 0.560263] check_preemption_disabled+0xd3/0xe0
> [ 0.560576] debug_smp_processor_id+0x13/0x20
> [ 0.560954] clock_was_set+0x1c/0x310

My stupidity. Fix for that below.

Thanks,

tglx
---
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -944,10 +944,11 @@ static bool update_needs_ipi(struct hrti
*/
void clock_was_set(unsigned int bases)
{
+ struct hrtimer_cpu_base *cpu_base = raw_cpu_ptr(&hrtimer_bases);
cpumask_var_t mask;
int cpu;

- if (!hrtimer_hres_active() && !tick_nohz_active)
+ if (!__hrtimer_hres_active(cpu_base) && !tick_nohz_active)
goto out_timerfd;

if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) {
@@ -958,9 +959,9 @@ void clock_was_set(unsigned int bases)
/* Avoid interrupting CPUs if possible */
cpus_read_lock();
for_each_online_cpu(cpu) {
- struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
unsigned long flags;

+ cpu_base = &per_cpu(hrtimer_bases, cpu);
raw_spin_lock_irqsave(&cpu_base->lock, flags);

if (update_needs_ipi(cpu_base, bases))