From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.212 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== 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== 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 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 ; Sat, 28 Nov 2026 14:01:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9E047606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev 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-Envelope-To: netdev@vger.kernel.org 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 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 Message-ID: Date: Sat, 28 Nov 2026 14:01:07 +0000 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net v6 1/2] ptp: serialize sysfs enable requests with ioctl paths To: Ahmad Byagowi , netdev@vger.kernel.org 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 References: <20261126-timecard-core-v6-0-ahmadexp@gmail.com> <20261126-timecard-core-v6-1-ahmadexp@gmail.com> Content-Language: en-US From: Vadim Fedorenko In-Reply-To: <20261126-timecard-core-v6-1-ahmadexp@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 26/11/2026 16:41, Ahmad Byagowi wrote: > From: ahmadexp > > 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 > --- > 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; >