Skip to content

Commit 06c017f

Browse files
timekeeping: Hold timekeepering locks in do_adjtimex and hardpps
In moving the NTP state to be protected by the timekeeping locks, be sure to acquire the timekeeping locks prior to calling ntp functions. Cc: Thomas Gleixner <[email protected]> Cc: Richard Cochran <[email protected]> Cc: Prarit Bhargava <[email protected]> Signed-off-by: John Stultz <[email protected]>
1 parent cef9037 commit 06c017f

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

kernel/time/timekeeping.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,10 @@ void __init timekeeping_init(void)
787787
boot.tv_nsec = 0;
788788
}
789789

790-
ntp_init();
791-
792790
raw_spin_lock_irqsave(&timekeeper_lock, flags);
793791
write_seqcount_begin(&timekeeper_seq);
792+
ntp_init();
793+
794794
clock = clocksource_default_clock();
795795
if (clock->enable)
796796
clock->enable(clock);
@@ -1618,6 +1618,7 @@ EXPORT_SYMBOL_GPL(ktime_get_monotonic_offset);
16181618
*/
16191619
int do_adjtimex(struct timex *txc)
16201620
{
1621+
unsigned long flags;
16211622
struct timespec ts;
16221623
s32 tai, orig_tai;
16231624
int ret;
@@ -1641,8 +1642,14 @@ int do_adjtimex(struct timex *txc)
16411642
getnstimeofday(&ts);
16421643
orig_tai = tai = timekeeping_get_tai_offset();
16431644

1645+
raw_spin_lock_irqsave(&timekeeper_lock, flags);
1646+
write_seqcount_begin(&timekeeper_seq);
1647+
16441648
ret = __do_adjtimex(txc, &ts, &tai);
16451649

1650+
write_seqcount_end(&timekeeper_seq);
1651+
raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
1652+
16461653
if (tai != orig_tai)
16471654
timekeeping_set_tai_offset(tai);
16481655

@@ -1655,7 +1662,15 @@ int do_adjtimex(struct timex *txc)
16551662
*/
16561663
void hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts)
16571664
{
1665+
unsigned long flags;
1666+
1667+
raw_spin_lock_irqsave(&timekeeper_lock, flags);
1668+
write_seqcount_begin(&timekeeper_seq);
1669+
16581670
__hardpps(phase_ts, raw_ts);
1671+
1672+
write_seqcount_end(&timekeeper_seq);
1673+
raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
16591674
}
16601675
EXPORT_SYMBOL(hardpps);
16611676
#endif

0 commit comments

Comments
 (0)