mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 05:24:39 +01:00
timekeeping: Prepare do_adtimex() for auxiliary clocks
Exclude ADJ_TAI, leap seconds and PPS functionality as they make no sense in the context of auxiliary clocks and provide a time stamp based on the actual clock. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: John Stultz <jstultz@google.com> Link: https://lore.kernel.org/all/20250625183758.253203783@linutronix.de
This commit is contained in:
parent
775f71ebed
commit
4eca49d0b6
1 changed files with 33 additions and 3 deletions
|
|
@ -58,6 +58,17 @@ static struct tk_data timekeeper_data[TIMEKEEPERS_MAX];
|
|||
/* The core timekeeper */
|
||||
#define tk_core (timekeeper_data[TIMEKEEPER_CORE])
|
||||
|
||||
#ifdef CONFIG_POSIX_AUX_CLOCKS
|
||||
static inline bool tk_get_aux_ts64(unsigned int tkid, struct timespec64 *ts)
|
||||
{
|
||||
return ktime_get_aux_ts64(CLOCK_AUX + tkid - TIMEKEEPER_AUX_FIRST, ts);
|
||||
}
|
||||
#else
|
||||
static inline bool tk_get_aux_ts64(unsigned int tkid, struct timespec64 *ts)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* flag for if timekeeping is suspended */
|
||||
int __read_mostly timekeeping_suspended;
|
||||
|
|
@ -2508,7 +2519,7 @@ ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, ktime_t *offs_real,
|
|||
/*
|
||||
* timekeeping_validate_timex - Ensures the timex is ok for use in do_adjtimex
|
||||
*/
|
||||
static int timekeeping_validate_timex(const struct __kernel_timex *txc)
|
||||
static int timekeeping_validate_timex(const struct __kernel_timex *txc, bool aux_clock)
|
||||
{
|
||||
if (txc->modes & ADJ_ADJTIME) {
|
||||
/* singleshot must not be used with any other mode bits */
|
||||
|
|
@ -2567,6 +2578,20 @@ static int timekeeping_validate_timex(const struct __kernel_timex *txc)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (aux_clock) {
|
||||
/* Auxiliary clocks are similar to TAI and do not have leap seconds */
|
||||
if (txc->status & (STA_INS | STA_DEL))
|
||||
return -EINVAL;
|
||||
|
||||
/* No TAI offset setting */
|
||||
if (txc->modes & ADJ_TAI)
|
||||
return -EINVAL;
|
||||
|
||||
/* No PPS support either */
|
||||
if (txc->status & (STA_PPSFREQ | STA_PPSTIME))
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -2595,17 +2620,22 @@ static int __do_adjtimex(struct tk_data *tkd, struct __kernel_timex *txc,
|
|||
struct adjtimex_result *result)
|
||||
{
|
||||
struct timekeeper *tks = &tkd->shadow_timekeeper;
|
||||
bool aux_clock = !timekeeper_is_core_tk(tks);
|
||||
struct timespec64 ts;
|
||||
s32 orig_tai, tai;
|
||||
int ret;
|
||||
|
||||
/* Validate the data before disabling interrupts */
|
||||
ret = timekeeping_validate_timex(txc);
|
||||
ret = timekeeping_validate_timex(txc, aux_clock);
|
||||
if (ret)
|
||||
return ret;
|
||||
add_device_randomness(txc, sizeof(*txc));
|
||||
|
||||
ktime_get_real_ts64(&ts);
|
||||
if (!aux_clock)
|
||||
ktime_get_real_ts64(&ts);
|
||||
else
|
||||
tk_get_aux_ts64(tkd->timekeeper.id, &ts);
|
||||
|
||||
add_device_randomness(&ts, sizeof(ts));
|
||||
|
||||
guard(raw_spinlock_irqsave)(&tkd->lock);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue