From nobody Tue Feb 10 00:03:01 2026 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 3E7EB2E7196; Thu, 26 Jun 2025 13:27:37 +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=1750944459; cv=none; b=lCijEpVzESiqk+EyghwJkpW7wu9Y9J4/vqLBrqwCl8/g5xSd0zfvQrWCKHpSCf52eF1XotzkeoUT2AKGczZ4917wS666KShIgCI6yeqAmaiWsq83UqMIcSluRSYlDk8uJrHFkQ5MWTuWewZvS1nQnV0IRFjbebD/TLUDiYX752Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750944459; c=relaxed/simple; bh=LQCtlrijMtzrLcCN//EaLeGrkvgwl9q1RRfITmiG/B8=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=p6Yx9oF3KghzFbojxKkle3pmO0uyLyaroGkMD0ltuzONuiDhkSWUu5raqUXPBAZVXkkoM5cui42tTCdR7huhgRCQL2n+BGohEAGFngtFcCDmtgMYktBYdXYGKGrLhRy8s8830M8C4SEaAqxInt0T5ZselKxHHQfqgO0IoMpv5wk= 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=YRmchcvM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=pvzwNVKE; 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="YRmchcvM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="pvzwNVKE" Message-ID: <20250626131708.544227586@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750944455; 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=+23L/t+gK242K9oPEMEakcO6Zj9GwQnHSFFMgTm1G8c=; b=YRmchcvMjps2ADVLc2TaFrDyPuu15ZB7cri1Wsf7hDlY0q1PORGhE60Q6zjou10sHU2rsr Iww9aBaZtelcPeYTtB5egj1FczH0VkkoUXe/fOPOQhc46z7EqTnlyUujo/YXp+Hsi4UUpB t6JIxxGnYtGRMjseJfM4X0pUidBK4X7Bj4L0hZVTq7srSL3HCARk8RfDiTUk3fOng3Louk ZFDD29CxKE3kCWDXLdXVvLdvJvoc2Mah2durEecNxcZ7kO5Q1hZP7MzucqQeUXb6DrSzU/ /yKRToHAhIeERxoO5XcBCwRFoTrE6sAB+UH2Zkhm2ks1OQaVPb5mlcrwezHodQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750944455; 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=+23L/t+gK242K9oPEMEakcO6Zj9GwQnHSFFMgTm1G8c=; b=pvzwNVKEmDQDkK1zRoegaqYZWFHX7QzZppx2NTRNgkaJN0s8RZe1oNRYByTSrhq1L0hKBo g5F5fjvstS0ANoDw== 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 3/3] ptp: Enable auxiliary clocks for PTP_SYS_OFFSET_EXTENDED References: <20250626124327.667087805@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 26 Jun 2025 15:27:34 +0200 (CEST) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow ioctl(PTP_SYS_OFFSET_EXTENDED*) to select CLOCK_AUX clock ids for generating the pre and post hardware readout timestamps. Aside of adding these clocks to the clock ID validation, this also requires to check the timestamp to be valid, i.e. the seconds value being greater than or equal zero. This is necessary because AUX clocks can be asynchronously enabled or disabled, so there is no way to validate the availability upfront. The same could have been achieved by handing the return value of ktime_get_aux_ts64() all the way down to the IOCTL call site, but that'd require to modify all existing ptp::gettimex64() callbacks and their inner call chains. The timestamp check achieves the same with less churn and less complicated code all over the place. Signed-off-by: Thomas Gleixner Reviewed-by: Vadim Fedorenko --- drivers/ptp/ptp_chardev.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) --- a/drivers/ptp/ptp_chardev.c +++ b/drivers/ptp/ptp_chardev.c @@ -325,13 +325,19 @@ static long ptp_sys_offset_extended(stru if (IS_ERR(extoff)) return PTR_ERR(extoff); =20 - if (extoff->n_samples > PTP_MAX_SAMPLES || - extoff->rsv[0] || extoff->rsv[1] || - (extoff->clockid !=3D CLOCK_REALTIME && - extoff->clockid !=3D CLOCK_MONOTONIC && - extoff->clockid !=3D CLOCK_MONOTONIC_RAW)) + if (extoff->n_samples > PTP_MAX_SAMPLES || extoff->rsv[0] || extoff->rsv[= 1]) return -EINVAL; =20 + switch (extoff->clockid) { + case CLOCK_REALTIME: + case CLOCK_MONOTONIC: + case CLOCK_MONOTONIC_RAW: + case CLOCK_AUX ... CLOCK_AUX_LAST: + break; + default: + return -EINVAL; + } + sts.clockid =3D extoff->clockid; for (unsigned int i =3D 0; i < extoff->n_samples; i++) { struct timespec64 ts; @@ -340,6 +346,11 @@ static long ptp_sys_offset_extended(stru err =3D ptp->info->gettimex64(ptp->info, &ts, &sts); if (err) return err; + + /* Filter out disabled or unavailable clocks */ + if (sts.pre_ts.tv_sec < 0 || sts.post_ts.tv_sec < 0) + return -EINVAL; + extoff->ts[i][0].sec =3D sts.pre_ts.tv_sec; extoff->ts[i][0].nsec =3D sts.pre_ts.tv_nsec; extoff->ts[i][1].sec =3D ts.tv_sec;