mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-02-13 16:33:57 -05:00
timekeeping: Make do_adjtimex() reusable
Split out the actual functionality of adjtimex() and make do_adjtimex() a wrapper which feeds the core timekeeper into it and handles the result including audit at the call site. This allows to reuse the actual functionality for auxiliary clocks. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: John Stultz <jstultz@google.com> Link: https://lore.kernel.org/all/20250625183758.187322876@linutronix.de
This commit is contained in:
@@ -2585,17 +2585,18 @@ unsigned long random_get_entropy_fallback(void)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(random_get_entropy_fallback);
|
EXPORT_SYMBOL_GPL(random_get_entropy_fallback);
|
||||||
|
|
||||||
/**
|
struct adjtimex_result {
|
||||||
* do_adjtimex() - Accessor function to NTP __do_adjtimex function
|
struct audit_ntp_data ad;
|
||||||
* @txc: Pointer to kernel_timex structure containing NTP parameters
|
struct timespec64 delta;
|
||||||
*/
|
bool clock_set;
|
||||||
int do_adjtimex(struct __kernel_timex *txc)
|
};
|
||||||
|
|
||||||
|
static int __do_adjtimex(struct tk_data *tkd, struct __kernel_timex *txc,
|
||||||
|
struct adjtimex_result *result)
|
||||||
{
|
{
|
||||||
struct tk_data *tkd = &tk_core;
|
struct timekeeper *tks = &tkd->shadow_timekeeper;
|
||||||
struct timespec64 delta, ts;
|
struct timespec64 ts;
|
||||||
struct audit_ntp_data ad;
|
s32 orig_tai, tai;
|
||||||
bool offset_set = false;
|
|
||||||
bool clock_set = false;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Validate the data before disabling interrupts */
|
/* Validate the data before disabling interrupts */
|
||||||
@@ -2604,56 +2605,65 @@ int do_adjtimex(struct __kernel_timex *txc)
|
|||||||
return ret;
|
return ret;
|
||||||
add_device_randomness(txc, sizeof(*txc));
|
add_device_randomness(txc, sizeof(*txc));
|
||||||
|
|
||||||
audit_ntp_init(&ad);
|
|
||||||
|
|
||||||
ktime_get_real_ts64(&ts);
|
ktime_get_real_ts64(&ts);
|
||||||
add_device_randomness(&ts, sizeof(ts));
|
add_device_randomness(&ts, sizeof(ts));
|
||||||
|
|
||||||
scoped_guard (raw_spinlock_irqsave, &tkd->lock) {
|
guard(raw_spinlock_irqsave)(&tkd->lock);
|
||||||
struct timekeeper *tks = &tkd->shadow_timekeeper;
|
|
||||||
s32 orig_tai, tai;
|
|
||||||
|
|
||||||
if (!tks->clock_valid)
|
if (!tks->clock_valid)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
if (txc->modes & ADJ_SETOFFSET) {
|
if (txc->modes & ADJ_SETOFFSET) {
|
||||||
delta.tv_sec = txc->time.tv_sec;
|
result->delta.tv_sec = txc->time.tv_sec;
|
||||||
delta.tv_nsec = txc->time.tv_usec;
|
result->delta.tv_nsec = txc->time.tv_usec;
|
||||||
if (!(txc->modes & ADJ_NANO))
|
if (!(txc->modes & ADJ_NANO))
|
||||||
delta.tv_nsec *= 1000;
|
result->delta.tv_nsec *= 1000;
|
||||||
ret = __timekeeping_inject_offset(tkd, &delta);
|
ret = __timekeeping_inject_offset(tkd, &result->delta);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
result->clock_set = true;
|
||||||
offset_set = delta.tv_sec != 0;
|
|
||||||
clock_set = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
orig_tai = tai = tks->tai_offset;
|
|
||||||
ret = ntp_adjtimex(tks->id, txc, &ts, &tai, &ad);
|
|
||||||
|
|
||||||
if (tai != orig_tai) {
|
|
||||||
__timekeeping_set_tai_offset(tks, tai);
|
|
||||||
timekeeping_update_from_shadow(tkd, TK_CLOCK_WAS_SET);
|
|
||||||
clock_set = true;
|
|
||||||
} else {
|
|
||||||
tk_update_leap_state_all(&tk_core);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update the multiplier immediately if frequency was set directly */
|
|
||||||
if (txc->modes & (ADJ_FREQUENCY | ADJ_TICK))
|
|
||||||
clock_set |= __timekeeping_advance(tkd, TK_ADV_FREQ);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
orig_tai = tai = tks->tai_offset;
|
||||||
|
ret = ntp_adjtimex(tks->id, txc, &ts, &tai, &result->ad);
|
||||||
|
|
||||||
|
if (tai != orig_tai) {
|
||||||
|
__timekeeping_set_tai_offset(tks, tai);
|
||||||
|
timekeeping_update_from_shadow(tkd, TK_CLOCK_WAS_SET);
|
||||||
|
result->clock_set = true;
|
||||||
|
} else {
|
||||||
|
tk_update_leap_state_all(&tk_core);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update the multiplier immediately if frequency was set directly */
|
||||||
|
if (txc->modes & (ADJ_FREQUENCY | ADJ_TICK))
|
||||||
|
result->clock_set |= __timekeeping_advance(tkd, TK_ADV_FREQ);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* do_adjtimex() - Accessor function to NTP __do_adjtimex function
|
||||||
|
* @txc: Pointer to kernel_timex structure containing NTP parameters
|
||||||
|
*/
|
||||||
|
int do_adjtimex(struct __kernel_timex *txc)
|
||||||
|
{
|
||||||
|
struct adjtimex_result result = { };
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = __do_adjtimex(&tk_core, txc, &result);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
if (txc->modes & ADJ_SETOFFSET)
|
if (txc->modes & ADJ_SETOFFSET)
|
||||||
audit_tk_injoffset(delta);
|
audit_tk_injoffset(result.delta);
|
||||||
|
|
||||||
audit_ntp_log(&ad);
|
audit_ntp_log(&result.ad);
|
||||||
|
|
||||||
if (clock_set)
|
if (result.clock_set)
|
||||||
clock_was_set(CLOCK_SET_WALL);
|
clock_was_set(CLOCK_SET_WALL);
|
||||||
|
|
||||||
ntp_notify_cmos_timer(offset_set);
|
ntp_notify_cmos_timer(result.delta.tv_sec != 0);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user