[RFC v4 21/22] clockevents: make setting of ->mult and ->mult_adjusted atomic

From: Nicolai Stange
Date: Mon Aug 22 2016 - 19:34:34 EST


In order to avoid races between setting a struct clock_event_device's
->mult_adjusted in clockevents_update_freq() and yet to be implemented
updates triggered from the timekeeping core, the setting of ->mult and
->mult_adjusted should be made atomic.

Protect the update in clockevents_update_freq() by locking the
clockevents_lock spinlock. Frequency updates are expected to be done
seldomly and thus, taking this subsystem lock should not have any impact
on performance.

Note that the call to tick_broadcast_update_freq() is also protected
by this clockevents_lock and thus, this patch introduces the locking
dependency clockevents_lock -> tick_broadcast_lock.

Signed-off-by: Nicolai Stange <nicstange@xxxxxxxxx>
---
kernel/time/clockevents.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c
index 8a89b8a..ee7cd40 100644
--- a/kernel/time/clockevents.c
+++ b/kernel/time/clockevents.c
@@ -592,11 +592,11 @@ int clockevents_update_freq(struct clock_event_device *dev, u32 freq)
unsigned long flags;
int ret;

- local_irq_save(flags);
+ raw_spin_lock_irqsave(&clockevents_lock, flags);
ret = tick_broadcast_update_freq(dev, freq);
if (ret == -ENODEV)
ret = __clockevents_update_freq(dev, freq);
- local_irq_restore(flags);
+ raw_spin_unlock_irqrestore(&clockevents_lock, flags);
return ret;
}

--
2.9.2