Article View: linux.kernel.netdev
Article #23883Re: [PATCH net v6 1/2] ptp: serialize sysfs enable requests with ioctl paths
From: Vadim Fedorenko
Date: Sat, 28 Nov 2026 14:01
Date: Sat, 28 Nov 2026 14:01
64 lines
11021 bytes
11021 bytes
On 26/11/2026 16:41, Ahmad Byagowi wrote:
> 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.
"The body of the explanation, line wrapped at 75 columns,"
Please, read
https://docs.kernel.org/process/submitting-patches.html#the-canonical-patch-format
before sending patches
>
> Fixes: d94ba80ebbea ("ptp: Added a brand new class driver for ptp clocks.")
no empty lines between tags
> 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;
>
Technical Details
Message-ID:
<b757a1a0-ee68-4ec0-90a5-40556af6ef05@linux.dev>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373143-linux-kernel-netdev=dewy.ruReferences:
<20261126-timecard-core-v6-0-ahmadexp@gmail.com> <20261126-timecard-core-v6-1-ahmadexp@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373143-linux-kernel-netdev=dewy.ru From: vadim.fedorenko@linux.dev (Vadim Fedorenko) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v6 1/2] ptp: serialize sysfs enable requests with ioctl paths Date: Sat, 28 Nov 2026 14:01:07 +0000 Organization: Usenet Network Message-ID: <b757a1a0-ee68-4ec0-90a5-40556af6ef05@linux.dev> References: <20261126-timecard-core-v6-0-ahmadexp@gmail.com> <20261126-timecard-core-v6-1-ahmadexp@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="960958"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:QT9xCYT0Zc839U6xA0n+TsutJ5c= sha256:KZDm31/LiDfuSa9q8YdTHwAWBs/t22m+KgLsVE4i+Qk= sha1:uU9V2W6y7PEZoym7AbVM6ysw5MU= sha256:RtHlyca/PLDXiooCIQ+3xNuYk2rCfrmS16yy8Gp4WNc= Content-Language: en-US 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 87570125F7D; Sat, 28 Nov 2026 17:01:35 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.05 X-Spam-Status: No, score=-3.05 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, 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, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=linux.dev 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 NvkdnkS-z8pm; Sat, 28 Nov 2026 17:01:27 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373143-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 3C993125F76; Sat, 28 Nov 2026 17:01:17 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id F0CC9241CF; Sat, 28 Nov 2026 14:01:12 +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=1795874472; b=rGtFPH/2CvijMLeM91sUXWmdukfMb7s5AE/zW94D/3MfwSDWwFmSxT4Ls6qkWNKllO04 LHs1of8vczcXWSHEBCDl5Lei9HUOd+Vj+jPp8lILQOlCnS4zj2T5nBPDjWofoTrRSExJl 4rzlnZz34J28ux1uLjkyvWkgNv7EGp07twXnN7FxoqGPp1PTF+QXNpdisIoYI5QziRNWj guC6VBN7U4ULG/Jz7g/6y4XI/9v0doxWoEGnc9Bsx79Lp2S4ituHUNLIsf/4JkCW30V+t 0ej2gJSazVO5Slx6K4Odcj1np4P47xLQw+5qhswmWpsBEdovid3lfNZtvUR9+2DbH6w== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795874472; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=XTtxFDBo/rSN1688+PdLLxcrPANByOQiJ+JGT6JoAlw=; b=kwmDwjw5AyExFIL1eCugP8OZ+EYSsOIC2P/2f3ICg9BvAjUXmmF1pWhUlirLnYD4vjDq /muiuNHsYSpaqiqpqsEezv/6CL28uF3Z8qdkAN7ZbAhBg2x8OsSihRR+UOpHH1pauiaFA 93JtLoGbtMvpLXUySDWPEhx9uUb2cHnGKMHbMg4xrMbkoBEFdiIM7A7BKzsLxzlnhwlcW RYGmGdKsFnriEgV5/1IiXIaZ3ghKBGEp8PXwLu0nGvOIGuJmwMpCNVSq5dpKQy6jkp9Sz bu019uZKaA1XumonxhVA80kV189D7NQbaFDsnwxn/OGK8BDHXnnmdXTSjBdtg9ns03g== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=LDbk4uOk; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; 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 886B6606A329; Sat, 28 Nov 2026 14:01:12 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=LDbk4uOk X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.212 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795874471; b=NnWBEKTJd+vQMHtwgb4673F139/ODtSoRfDsMrY/qBi+hYSZxYt9ydCfrtcwykHD3FbO xG8iKzR9g3kfJeSJXiy/ZIs8j4JlyudZOBKmDD63461pOB/vfmBKQHnOu0AqPH8qVYfW/ inudstfCuCBenH9EbInZ3WnS9/2PNmfC3IAiZTJUs8wbnuJ5rQcTLJrZSy48qbLL/IcgG 4bcf4lkWDPQt1fYuvKr3A/xOCDdoEWIUYaPbC8KihQdjfXNgctNr1nGzo9M25+XRtcHXk IudWYRBEXapSTplUy49I7HnLGR6YotDZUtPYAL/SrlBU6T/OdhsAF+akdODrcEYfA4Q== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795874471; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=XTtxFDBo/rSN1688+PdLLxcrPANByOQiJ+JGT6JoAlw=; b=ULI0aZPAsje4DB8ZfC7wH5TerxUAmprhJO5lV4t6yolG2Q/HSHcV/3zMr7Y9LFKjCN2i ul+H1y+GJw404NhBB1KR/Ha4M5EIS2JgGCqgRQO/KGtyVZRkGC8yS7k0n4tbSt4c9lmaK oULIppSUS708/1DBf0VhQtiyGYfIsCsJ7inTFfGObHhan+I5B94yfPr/DIkrcsqq+Qmbj 578YOEEUipnCkjTU46Yro6hNm2g+eF93a3x03HdBEKZUJVKZImf0OvMwbiHmupHHuJRTJ OtkDAa9wPvDnvdbxxxNqsq5GK5d1L9iiQnL4Jdq2sgErKQhmI6hcSPVvZW3kYNUjgFg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=LDbk4uOk; arc=none smtp.remote-ip=95.215.58.212 X-Received: from mta1.migadu.com (out-212.mta1.migadu.com [95.215.58.212]) (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 9E047606A31C for <netdev@vger.kernel.org>; Sat, 28 Nov 2026 14:01:10 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9E047606A31C X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=4Ur4J0mGVkhH1ZXU7aNxHg+8x6EjXxhKy3Fn3lqK7/A=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795874468; v=1; x=1796479268; b=LDbk4uOkJTPrqLshzDZ4oZcSaHzYj9AZXYVg6vxUd0icUw603OUlSeHRyKHSEXDAwHLo3qNB v63/Ev9eMj+q1eeoF1eVRuUPBi9WvayRDvbOj72SF39UvcSzRlH7xlBlJDG97j0s25tdowS/aec wtVqYDuzoCIcDNiHXgA9sPu8= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id 3466a22c282d9a2f; Sat, 28 Nov 2026 14:01:08 +0000 X-Mizu-Trace-ID: 3466a22c282d9a2f X-Migadu-Flow: FLOW_OUT 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 X-User-Agent: Mozilla Thunderbird X-Cc: richardcochran@gmail.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, vladimir.oltean@nxp.com, andrew+netdev@lunn.ch, arnd@arndb.de, john.stultz@linaro.org, rmk+kernel@armlinux.org.uk X-In-Reply-To: <20261126-timecard-core-v6-1-ahmadexp@gmail.com>