Netdev List
 help / color / mirror / Atom feed
From: Ahmad Byagowi <ahmadexp@gmail.com>
To: netdev@vger.kernel.org
Cc: richardcochran@gmail.com, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	vladimir.oltean@nxp.com, vadim.fedorenko@linux.dev,
	andrew+netdev@lunn.ch, arnd@arndb.de, john.stultz@linaro.org,
	rmk+kernel@armlinux.org.uk
Subject: [PATCH net v6 1/2] ptp: serialize sysfs enable requests with ioctl paths
Date: Thu, 26 Nov 2026 08:41:21 -0800	[thread overview]
Message-ID: <20261126-timecard-core-v6-1-ahmadexp@gmail.com> (raw)
In-Reply-To: <20261126-timecard-core-v6-0-ahmadexp@gmail.com>

From: ahmadexp <ahmadexp@gmail.com>

EXTTS, PPS and period sysfs stores invoke the clock driver callback without the pincfg_mux mutex. The ioctl paths and pin configuration changes use that mutex, so sysfs can race with those operations and with other sysfs requests.

Take pincfg_mux around each enable callback. Keep validation and permission checks outside the critical section, propagate callback failures, and return -ERESTARTSYS when mutex acquisition is interrupted. The mutex is required because disable callbacks may sleep while draining an IRQ.

A coding assistant helped identify the missing serialization, develop the fix and regression tests, and prepare this changelog. The source-derived tests exercise the actual callbacks with controlled scheduling; KUnit coverage uses the actual stores under lock contention.

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>
---
 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;
 
-- 
2.54.0 (Apple Git-157)


  reply	other threads:[~2026-11-26 16:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 16:41 [PATCH net v6 0/2] ptp: serialize requests and stop unassigned timestamps Ahmad Byagowi
2026-11-26 16:41 ` Ahmad Byagowi [this message]
2026-11-26 16:41 ` [PATCH net v6 2/2] ptp: disable unassigned timestamp channels on unregister 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=20261126-timecard-core-v6-1-ahmadexp@gmail.com \
    --to=ahmadexp@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=arnd@arndb.de \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=john.stultz@linaro.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=vadim.fedorenko@linux.dev \
    --cc=vladimir.oltean@nxp.com \
    /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