From: Ahmad Byagowi <ahmadexp@gmail.com>
To: netdev@vger.kernel.org
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
Subject: [PATCH net v5 1/8] ptp: serialize sysfs requests with the ioctl paths
Date: Mon, 23 Nov 2026 20:42:36 -0800 [thread overview]
Message-ID: <20261123-timecard-common-v5-d669cfa034-1-ahmadexp@gmail.com> (raw)
In-Reply-To: <20261123-timecard-common-v5-d669cfa034-0-ahmadexp@gmail.com>
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;
next prev parent reply other threads:[~2026-11-24 4:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 4:42 [PATCH net v5 0/8] ptp: fix request serialization, teardown and SMA reporting Ahmad Byagowi
2026-11-24 4:42 ` Ahmad Byagowi [this message]
2026-11-24 4:42 ` [PATCH net v5 2/8] net: dsa: sja1105: leave the pin function unchanged on EXTTS disable Ahmad Byagowi
2026-11-24 4:42 ` [PATCH net v5 3/8] ptp: disable all timestamp channels after removing the user interfaces Ahmad Byagowi
2026-11-24 4:42 ` [PATCH net v5 4/8] ptp: ocp: handle hardware selectors and combined DPLL input routes Ahmad Byagowi
2026-11-24 4:42 ` [PATCH net v5 5/8] ptp: ocp: recover disabled SMA inputs when binding the driver Ahmad Byagowi
2026-11-24 4:42 ` [PATCH net v5 6/8] ptp: ocp: report zero frequency for disabled SMA inputs Ahmad Byagowi
2026-11-24 4:42 ` [PATCH net v5 7/8] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
2026-11-24 4:42 ` [PATCH net v5 8/8] ptp: ocp: correct the ART 10 MHz input frequency Ahmad Byagowi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123-timecard-common-v5-d669cfa034-1-ahmadexp@gmail.com \
--to=ahmadexp@gmail.com \
--cc=andrew@lunn.ch \
--cc=arkadiusz.kubalewski@intel.com \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=jiri@resnulli.us \
--cc=john.stultz@linaro.org \
--cc=jonathan.lemon@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=rmk+kernel@armlinux.org.uk \
--cc=vadim.fedorenko@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®