From nobody Sun Dec 14 06:16:11 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 4600B2C2FB9; Tue, 13 May 2025 15:13:39 +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=1747149221; cv=none; b=LiqbL2Bs1JPsRqXp/OoNWA0GVSej937aJ2j73lPGapQjE5sulqQmm2auFMIXKXN+pqTxZCLAGaphlcE2IiIq7N7m3LxpXNyWGFBDgRhBIP2fWgtR6zP4SXVEFCRJqVP+hLCe5doIqQn9EJqfO96hBYFKLbfB2Jx6uMZeodprIDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747149221; c=relaxed/simple; bh=iJJ9ph2Xb8jo5inYrka+dOkNKYSGMVeqGO5dfJupNQc=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=sdgeN+LnHNgIvIhIQx3phPj++1c5uekKsUtSAiqsxnPTiKHb8kDzS1eEATsmWgO3kfw4SuR7uXmnSjBRHrxp8Neh6rDbzINxI/tYb4L4JJBWJBYZX4alhtgCPdyLftEaBa9QLAj/G95bR/SMnRu52dUW2opBGAVBU+zkvZAP7hA= 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=iinsoVwS; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=weCmPHnU; 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="iinsoVwS"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="weCmPHnU" Message-ID: <20250513145138.036707094@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1747149218; 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=sshZ83NzzE8YwIcZ21KwrOb8k7lJw16Y76dziNXGJq4=; b=iinsoVwSSQ4rno6wgH/7CG/WCmCFxpqZZmIKf1CPSZOJgHPIPU59l7aK19zeTxRXQdTBDW Hp+JEG8zFoLX2Q7ty9lx5hjSRvQjr7pc0MH21OdBVHeDa1v/c588FtuEfY0Mt5Hbqv0hzY UXKRDluebUe4ojqFLUe5ZwBtPedG9tRVcH6lSQaKbrmyFAOVQ2DTBJE4tvKN+8GcHxa5lg 5A5eAH99OmjY0fGGGFfHei2Ff7VW+wWHBA9vX3/DocRLkx+1iHK3Yp97Q+uB+gLBZlJ1v2 okQBZo6o3DoCet1APS5tgew2p+9kiEXCCAyVuOFE3emPOK4MK98I77QGTXjnhA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1747149218; 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=sshZ83NzzE8YwIcZ21KwrOb8k7lJw16Y76dziNXGJq4=; b=weCmPHnU4cCjXT4IfsvBFa8s1G9nBz9jDWQZJePA3J01e4Y7JWwktrD+G91tgGoXWJ/eEq 30GlzevJ35SOOxBw== From: Thomas Gleixner To: LKML Cc: netdev@vger.kernel.org, Richard Cochran , Christopher Hall , David Zage , 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 , Alex Gieringer Subject: [patch 23/26] timekeeping: Prepare do_adtimex() for PTP clocks References: <20250513144615.252881431@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Tue, 13 May 2025 17:13:37 +0200 (CEST) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Exclude ADJ_TAI, leap seconds and PPS functionality 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_PTP_CLOCKS +static inline bool tk_get_ptp_ts64(unsigned int tkid, struct timespec64 *t= s) +{ + return ktime_get_ptp_ts64(CLOCK_PTP + tkid - TIMEKEEPER_PTP, ts); +} +#else +static inline bool tk_get_ptp_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 ptp_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 (!ptp_clock) + return 0; + + /* PTP clocks are TAI based 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 ptp_clock; int ret; =20 + ptp_clock =3D IS_ENABLED(CONFIG_POSIX_PTP_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, ptp_clock); if (ret) return ret; add_device_randomness(txc, sizeof(*txc)); =20 - ktime_get_real_ts64(&ts); + if (!ptp_clock) + ktime_get_real_ts64(&ts); + else + tk_get_ptp_ts64(tkd->timekeeper.id, &ts); + add_device_randomness(&ts, sizeof(ts)); =20 guard(raw_spinlock_irqsave)(&tkd->lock);