Re: [PATCH] tick/broadcast: Do not set oneshot_mask except was_periodic was true

From: Victor Hassan
Date: Fri Apr 07 2023 - 02:51:31 EST




On 4/4/2023 8:21 PM, Frederic Weisbecker wrote:
On Tue, Apr 04, 2023 at 07:37:06PM +0800, Victor Hassan wrote:

Leading to such race:

* CPU 1 stop its tick, next event is in one hour
* CPU 0 registers new broadcast and sets CPU 1 in tick_broadcast_oneshot_mask
* CPU 1 runs into cpuidle_enter_state(), and tick_broadcast_enter() is ignored because
the CPU is already in tick_broadcast_oneshot_mask

Yes.

* CPU 1 goes to sleep
* CPU 0 runs the broadcast callback, sees that the next timer for CPU 1
is in one hour, program the broadcast to that deadline
* CPU 1 gets an interrupt that enqueues a new timer expiring in the next jiffy
* CPU 1 don't call tick_broadcast_exit and thus don't remove itself from
tick_broadcast_oneshot_mask

I'm not sure about this... Actually, I believe CPU 1 *will* call
tick_broadcast_exit in this condition because I cannot find a limitation on
this execution path.

You're right, what I wrote doesn't make sense. Let me try again:

* CPU 1 stop its tick, next event is in one hour. It calls
tick_broadcast_enter() and goes to sleep.
* CPU 1 gets an interrupt that enqueues a new timer expiring in the next jiffy
(note it's not yet actually programmed in the tick device)
* CPU 1 call tick_broadcast_exit().

* CPU 0 registers new broadcast device and sets CPU 1 in tick_broadcast_oneshot_mask

* CPU 0 runs the broadcast callback, sees that the next timer for CPU 1
is in one hour (because the recently enqueued timer for CPU 1 hasn't been programmed
yet), so it programs the broadcast to that 1 hour deadline.

* CPU 1 runs tick_nohz_idle_stop_tick() which eventually writes and program
dev->next_event to next jiffy
* CPU 1 runs into cpuidle_enter_state(), and tick_broadcast_enter() is ignored because
the CPU is already in tick_broadcast_oneshot_mask, so the dev->next_event
change isn't propagated to broadcast.

* CPU 1 goes to sleep for 1 hour.

Hi Frederic,
Yes, I think that make sense :)



Does it make more sense? There might be more simple scenario of course.

Thanks.