From nobody Fri Dec 19 17:18:02 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0669E2741D0; Mon, 19 May 2025 08:33:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747643625; cv=none; b=CqTXxjnkR7nCVPYUsdEDWG6Lwjth+lTmeSGm7fvwAcdh9HutaV1yzegdH6OCEF6QOddM53xWdkIvWEd5aussW8Rmhnu8PMtCbe2v7RUmbZGi+FFvNqtcRdITAf5QoN4cys/ABGZn8lGx5VEgqSUhE+xMEma9zg+dEOaa3V+Ox/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747643625; c=relaxed/simple; bh=GRP0gjAGrn/citbYtuiPWdcwsdlss+TGtUZ0SDP84BM=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=JMtZvYTb4nvOKsW3q7OT/nA7cNQbpUNFbR5nCxcfnpTKcsssgNwPGfevZ4LbXQM9Jhgm9W8VJDMblChoSembcFBkWSQC+0+zW5tJxuiRMJB6W/Vv/DLiIv6GDuPyyUkllnZlgRWH+KyWv9gnAwRsYom4xDn0AiWgNo3DDcX/O5c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=uYH33D9d; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rxKLUGFY; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uYH33D9d"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rxKLUGFY" Message-ID: <20250519083027.023158795@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1747643622; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=QHFCCWtgxJo9J0DtoRfT+72OmxVX42D6q0paXfZdXuM=; b=uYH33D9daUwl2TGXRYuCv9UO6a8r5qge1T7r5kOXptL/hiIPfeE/m+gklzEq+ii8SIwDcp DUIY+InFOiuQV7cIXjIQsgotKEV0MShNAPyfPZRmqvYg+jfZRSTSqgtD/PhhKsFgReuyiA IN6q8DhLFmBtfWUc2bWNmarVKh9TxIGN/laKnEZYZpVZc7XBnM7CEn6upewf7NZMUHEESD CcjHfAkrjCgnD8K0oMK0eAVdJDDaLReWrgXzsqUOGMG7uP3ZT4RtF4rno5ZvK3nY1IwQEX nasM9rOHUGaxS0Y+pqOZF1dJcLDgFP/PcVGIhwMtDGyCru7sLDEwjMb8iQ6CuA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1747643622; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=QHFCCWtgxJo9J0DtoRfT+72OmxVX42D6q0paXfZdXuM=; b=rxKLUGFYd7nDDOrLYUzoC4+xAqIgZlJ6OpHemWQiZ1zoc3x0RVwgAeKElRBjDAVG0mz50t Rju/Cq2aBs/aOdAA== From: Thomas Gleixner To: LKML Cc: netdev@vger.kernel.org, Richard Cochran , Christopher Hall , John Stultz , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Kurt Kanzenbach , Nam Cao , Antoine Tenart Subject: [patch V2 23/26] timekeeping: Prepare do_adtimex() for auxiliary clocks References: <20250519082042.742926976@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Mon, 19 May 2025 10:33:42 +0200 (CEST) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- kernel/time/timekeeping.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) --- --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -58,6 +58,17 @@ static struct tk_data timekeeper_data[TI /* The core timekeeper */ #define tk_core (timekeeper_data[TIMEKEEPER_CORE]) =20 +#ifdef CONFIG_POSIX_AUX_CLOCKS +static inline bool tk_get_aux_ts64(unsigned int tkid, struct timespec64 *t= s) +{ + return ktime_get_aux_ts64(CLOCK_AUX + tkid - TIMEKEEPER_AUX, ts); +} +#else +static inline bool tk_get_aux_ts64(unsigned int tkid, struct timespec64 *t= s) +{ + return false; +} +#endif =20 /* flag for if timekeeping is suspended */ int __read_mostly timekeeping_suspended; @@ -2503,7 +2514,7 @@ ktime_t ktime_get_update_offsets_now(uns /* * timekeeping_validate_timex - Ensures the timex is ok for use in do_adjt= imex */ -static int timekeeping_validate_timex(const struct __kernel_timex *txc) +static int timekeeping_validate_timex(const struct __kernel_timex *txc, bo= ol aux_clock) { if (txc->modes & ADJ_ADJTIME) { /* singleshot must not be used with any other mode bits */ @@ -2562,6 +2573,21 @@ static int timekeeping_validate_timex(co return -EINVAL; } =20 + if (!aux_clock) + return 0; + + /* 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; } =20 @@ -2592,15 +2618,22 @@ static int __do_adjtimex(struct tk_data struct timekeeper *tks =3D &tkd->shadow_timekeeper; struct timespec64 ts; s32 orig_tai, tai; + bool aux_clock; int ret; =20 + aux_clock =3D IS_ENABLED(CONFIG_POSIX_AUX_CLOCKS) && tkd->timekeeper.id != =3D TIMEKEEPER_CORE; + /* Validate the data before disabling interrupts */ - ret =3D timekeeping_validate_timex(txc); + ret =3D timekeeping_validate_timex(txc, aux_clock); if (ret) return ret; add_device_randomness(txc, sizeof(*txc)); =20 - 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)); =20 guard(raw_spinlock_irqsave)(&tkd->lock);