Article View: linux.kernel.netdev
Article #21511[PATCH net v5 1/8] ptp: serialize sysfs requests with the ioctl paths
From: Ahmad Byagowi
Date: Tue, 24 Nov 2026 04:42
Date: Tue, 24 Nov 2026 04:42
79 lines
14254 bytes
14254 bytes
The extts_enable, pps_enable and period sysfs stores call the driver's
enable callback without taking pincfg_mux. The corresponding ioctls and
pin configuration changes take that mutex, so sysfs requests can race
with them and with requests through the other sysfs attributes.
On ptp_ocp, PPS and EXTTS channel 5 share pps_req_map and a hardware
source. Concurrent read-modify-write updates can lose a subscription,
and an enable can overlap the register writes and IRQ drain of a
disable. The software subscription state can then disagree with the
hardware state even though both requests succeeded.
Take pincfg_mux around all three sysfs enable callbacks, just as the
ioctl paths do. Keep permission checks and request validation outside
the critical section, propagate callback errors, and return -ERESTARTSYS
if acquiring the mutex is interrupted. A mutex permits callbacks that
sleep, including ptp_ocp's synchronize_irq() on disable.
The Sashiko review identified the EXTTS/sysfs race while reviewing the
timestamp teardown fix. Inspection found the same missing serialization
in pps_enable and period. Codex assisted with the correction, tests and
changelog. Source-derived tests with controlled scheduling reproduce the
reported shared-PPS failure on the previous series and pass with this
fix. Local KUnit tests call the real sysfs stores under mutex contention
in QEMU with KASAN and lockdep. No physical hardware was tested.
Fixes: d94ba80ebbea ("ptp: Added a brand new class driver for ptp clocks.")
Link: https://lore.kernel.org/r/179548551283.3135.17206659598806657887@kernel.org
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
Changes in v5:
- New prerequisite from the runtime-race review of v4 patch 1.
- Serialize EXTTS, PPS and PEROUT sysfs stores, not only EXTTS.
Testing: 100 controlled runtime suites with four interleavings each;
real-store mutex-contention KUnit cases under QEMU KASAN/lockdep; permission,
error and interrupted-lock model cases. Removing each lock independently
causes a runtime assertion failure. No physical hardware was used.
drivers/ptp/ptp_sysfs.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
index 8e0e0aa09981..90fdddc1e6a7 100644
--- a/drivers/ptp/ptp_sysfs.c
+++ b/drivers/ptp/ptp_sysfs.c
@@ -60,7 +60,10 @@ static ssize_t extts_enable_store(struct device *dev,
if (req.extts.index >= ops->n_ext_ts)
goto out;
+ if (mutex_lock_interruptible(&ptp->pincfg_mux))
+ return -ERESTARTSYS;
err = ops->enable(ops, &req, enable ? 1 : 0);
+ mutex_unlock(&ptp->pincfg_mux);
if (err)
goto out;
@@ -130,7 +133,10 @@ static ssize_t period_store(struct device *dev,
goto out;
enable = req.perout.period.sec || req.perout.period.nsec;
+ if (mutex_lock_interruptible(&ptp->pincfg_mux))
+ return -ERESTARTSYS;
err = ops->enable(ops, &req, enable);
+ mutex_unlock(&ptp->pincfg_mux);
if (err)
goto out;
@@ -157,7 +163,10 @@ static ssize_t pps_enable_store(struct device *dev,
if (cnt != 1)
goto out;
+ if (mutex_lock_interruptible(&ptp->pincfg_mux))
+ return -ERESTARTSYS;
err = ops->enable(ops, &req, enable ? 1 : 0);
+ mutex_unlock(&ptp->pincfg_mux);
if (err)
goto out;
Technical Details
Message-ID:
<20261123-timecard-common-v5-d669cfa034-1-ahmadexp@gmail.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370000-linux-kernel-netdev=dewy.ruReferences:
<20261123-timecard-common-v5-d669cfa034-0-ahmadexp@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370000-linux-kernel-netdev=dewy.ru
From: ahmadexp@gmail.com (Ahmad Byagowi)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v5 1/8] ptp: serialize sysfs requests with the ioctl paths
Date: Mon, 23 Nov 2026 20:42:36 -0800
Organization: Usenet Network
Message-ID: <20261123-timecard-common-v5-d669cfa034-1-ahmadexp@gmail.com>
References: <20261123-timecard-common-v5-d669cfa034-0-ahmadexp@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="4052698"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:TEX1D+Ch9xvRT41MVVlANCi7Q8A= sha256:rURzLBzDkEd3f2iV0DbTy4C23w8vuI0oIOHoconCMEQ=
sha1:s/tkRQCW0PQfvr1hOYzAhj3yHL4= sha256:OuJEGcmBFINCQurLd2BX3bSPxnPh7kmnX/Al07nuiF0=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 754FA125DC7; Tue, 24 Nov 2026 07:43:04 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id IpwZKw8_Z24D;
Tue, 24 Nov 2026 07:43:00 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-370000-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 23B0D125DC9; Tue, 24 Nov 2026 07:42:51 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 78F313330C; Tue, 24 Nov 2026 04:42:45 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1795495360;
b=uKEfZx+9LLe+lAVVFKD/aBzWwVAPABDbyXripQVbo/8lU1yU6zjceJWlxnG4f5Ac24Fu
DPUey7Z/IEbBylfw52f01yqelpfOsEV0rElfDfIXSGuz0EJG0KE27BU/Mn/DhTEMaKhyx
RzcAK+ZKEW/2ntSWNqzjZNtGlTxQhkZfmjzUYA8z8JBiwVJw/L9hp+PG0GsKwsaWdW4pB
HuaVN0GB3WpehZO/8BDkufGOiXYgQIkdcmj/o9LRGmY5mkk+w1cZ0YbxlwBw8sYtx0XnM
+ZkkDnNcV4oLtgA4mvupdCY8lD+zbRxiP9xAo/8YLk5MhpEbsNqbT2EgGecNHiWT54g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795495360;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=3LR2pXBU1UF0saUliIwhq7NUmfXvWt7NIINFzWDFrag=;
b=yaCz+dA1tGCm0t6s2X5vhkrZl/hFyuieJujnaRpjtHsg6wVFTYNEa0NDIrCEcSDQvX69
ABYA4I9bY+W0ykh4Vw97CN3UMFdQ/TcrZ9VhpAl0XEfeIIxS4qT+M4qFv4pAqEMJqO8KT
6IGWPR6EpXq3UOZxru3vVIp2uIvx0fE/EFqV9tLzGhbHj05js3GlML3r3VEvIUbCDYpqF
fh8vJqiC6Uk2NCFMtag/CJMjBfJAOJ7gAB8FeVXXpdxnpqsJC6Sn9MFf+Fx8PXDIhbyhm
FzN7pGjbynGxy1POBFLH7GvDWaxIiCUj6wSdkcjEqOj/QcpDm2C7sviqf8lx5VHwRxw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xUNWD6GP;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 61F31606A339;
Tue, 24 Nov 2026 04:42:40 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xUNWD6GP
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.44
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795495359;
b=z8jDzcBejtqEhfoG9Pxrj5+EripzWfl8zV1CjFMDX6ZzgyBGtqiZwD057myzjpRpFlA/
mAFLsbrJkzEJwV/SqDrzM0Yt8hqWMS9HGaXoCqA0Ve1ew0+pDYvo7S1nSFcURfWmmjqh+
1TFbM1nmBHEESSK95a3Rbc5PgRhAirNGb7y67hFAaiHxD5CryuQGdSebmv29q19Gjatrd
aaJ08f2tMVO3wHvNpES5FQOJjRDjhsHz74YcbutSW1Ant0GS9cFok7d/OLp0oa1MIRuen
xanS1+SSWtMIosF9RPAh105JGUQhgkUt1d7Ssci9gtUAikRF2by4TZytjvwZ4LpVfoA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795495359;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-ID:In-Reply-To:References:MIME-Version:
Content-Transfer-Encoding;
bh=3LR2pXBU1UF0saUliIwhq7NUmfXvWt7NIINFzWDFrag=;
b=g6ZnCtLNybCIZOj5F5kSHUxVCyp6o9tid3a59Z2Otsqgf5xrN9VawOyIDoNVRDifkzE6
nW8NI+HreNwGf1hZ0zGLtoV7UjXZ+Y7E3eIldDV3E+rxNGqBHBaB2W2eYgPmlYmxkBS0h
/pWR2QaLK2ld2e3RI9HSI3xEJYLE53Jj71HRzsSew5yrk2dQjRkk3sDnqoDKXhSAXq5FF
cjBeRuCCKxTf8+RluLLfdbXhEC+G43aBlNeW4inmDHK5cXKBZkdUhfyJmDUDY6WCgSXGc
w6E247ncauUTRbeDAEGuqrs7tcCBQzsckBzaBAnKTEICbMvl5w0NgiDq8Ljvk09ZkTQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xUNWD6GP;
arc=none smtp.remote-ip=74.125.82.44
X-Received: from mail-dl1-f44.google.com (mail-dl1-f44.google.com [74.125.82.44])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36560606A333
for <netdev@vger.kernel.org>; Tue, 24 Nov 2026 04:42:39 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 36560606A333
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dl1-f44.google.com with SMTP id a92af1059eb24-1a3c08d6928so5781449c88.0
for <netdev@vger.kernel.org>; Mon, 23 Nov 2026 20:42:39 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1795495358; x=1796100158; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=3LR2pXBU1UF0saUliIwhq7NUmfXvWt7NIINFzWDFrag=;
b=xUNWD6GPmcjKjtaVeqbbPUL4rhsI3ZPkzj8vw1Bv8K4oR2xcifghha1g3L4ksckrHN
jXjtI4p4vTfly0APrpY8hpdaWNC2Jb6o6U5PbhfjcrWKaSr8G6Uhd/p9xUf2K/O3L1A6
ST44sLOxbr2tglyn9HHlZZ5RcbNkVZUlVzN6RyHDaHmjAD62fB4v6pD6TOry51LoAtVw
SIx6npuwVkWoV+l20JlgeEgfVn0tMx3zvudZbFOlIzAW0QwkwPBkOiWMc36kQpTiBc/P
9efZDBdLH9iKSqA2rChiENNCaZk4P5VKDJ1Zgh96F4JhKy55ITo9zfG+RdL7m0kv0+GZ
y8kg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1795495358; x=1796100158;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
:to:cc:subject:date:message-id:reply-to:content-type;
bh=3LR2pXBU1UF0saUliIwhq7NUmfXvWt7NIINFzWDFrag=;
b=0bKnDwBUyoeZZtkzb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DBXutJDY5wNCpGKWT9E5iz3EQZv+Geb8xZZXJVb/lJhgce21cJOnDMj1+UtRz+SQD/QUZrTK/w
BlFOvgR/v1W4YEri5KwaOOiR9NvTfKirpOh+GYcH4lUhUiBx46/AW13YF1yyLKqaH3o/Hdcxm
X-Received: by 2002:a05:7300:c00f:10b0:386:c3ad:dc25 with SMTP id 5a478bee46e88-386c3adde30mr548401eec.34.1795495358333;
Mon, 23 Nov 2026 20:42:38 -0800 (PST)
X-Received: from Mac.localdomain (198-27-228-154.fiber.dynamic.sonic.net. [198.27.228.154])
by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385666e7f59sm43092880eec.6.2026.11.23.20.42.37
(version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
Mon, 23 Nov 2026 20:42:37 -0800 (PST)
X-Cc: andrew@lunn.ch,
arkadiusz.kubalewski@intel.com,
arnd@arndb.de,
davem@davemloft.net,
edumazet@kernel.org,
jiri@resnulli.us,
john.stultz@linaro.org,
jonathan.lemon@gmail.com,
kuba@kernel.org,
linux-kernel@vger.kernel.org,
olteanv@gmail.com,
pabeni@redhat.com,
richardcochran@gmail.com,
rmk+kernel@armlinux.org.uk,
vadim.fedorenko@linux.dev
X-In-Reply-To: <20261123-timecard-common-v5-d669cfa034-0-ahmadexp@gmail.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list