Article View: linux.kernel.netdev
Article #6494[PATCH net v5 1/5] ptp: drain virtual clock sysfs operations before unregistering children
From: James Hilliard
Date: Thu, 22 Oct 2026 15:16
Date: Thu, 22 Oct 2026 15:16
73 lines
13742 bytes
13742 bytes
Parent clock removal walks its virtual clocks before removing the
n_vclocks sysfs attribute. The mutex taken by ptp_vclock_in_use() is
released before that walk, so a concurrent sysfs deletion can pick the
same child and unregister and free its ptp_vclock a second time. A
reference held by the device iterator does not protect that separately
allocated virtual clock.
Remove n_vclocks before walking the children. Removing the attribute
prevents new stores and drains stores already running, without holding
n_vclocks_mux across a callback that needs that mutex. Skip virtual
clocks, which do not have this attribute.
This race was found by code inspection of virtual-clock registration
failure cleanup and parent removal.
Fixes: bfcbb76b0f59 ("ptp: unregister virtual clocks when unregistering physical clock.")
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
drivers/ptp/ptp_clock.c | 5 +++++
drivers/ptp/ptp_private.h | 1 +
drivers/ptp/ptp_sysfs.c | 6 ++++++
3 files changed, 12 insertions(+)
diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index 4111342d64f0..47ffc773065a 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -508,6 +508,11 @@ static int unregister_vclock(struct device *dev, void *data)
int ptp_clock_unregister(struct ptp_clock *ptp)
{
+ /*
+ * Stop and drain virtual-clock creation and deletion before walking the
+ * children. Do not hold n_vclocks_mux while waiting for sysfs callbacks.
+ */
+ ptp_vclock_remove_sysfs(ptp);
if (ptp_vclock_in_use(ptp)) {
device_for_each_child(&ptp->dev, NULL, unregister_vclock);
}
diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
index db4039d642b4..ec8633126d6b 100644
--- a/drivers/ptp/ptp_private.h
+++ b/drivers/ptp/ptp_private.h
@@ -169,6 +169,7 @@ extern const struct attribute_group *ptp_groups[];
int ptp_populate_pin_groups(struct ptp_clock *ptp);
void ptp_cleanup_pin_groups(struct ptp_clock *ptp);
+void ptp_vclock_remove_sysfs(struct ptp_clock *ptp);
struct ptp_vclock *ptp_vclock_register(struct ptp_clock *pclock);
void ptp_vclock_unregister(struct ptp_vclock *vclock);
diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
index dc398c6b7528..53388b123198 100644
--- a/drivers/ptp/ptp_sysfs.c
+++ b/drivers/ptp/ptp_sysfs.c
@@ -263,6 +263,12 @@ static ssize_t n_vclocks_store(struct device *dev,
}
static DEVICE_ATTR_RW(n_vclocks);
+void ptp_vclock_remove_sysfs(struct ptp_clock *ptp)
+{
+ if (!ptp->is_virtual_clock)
+ device_remove_file(&ptp->dev, &dev_attr_n_vclocks);
+}
+
static ssize_t max_vclocks_show(struct device *dev,
struct device_attribute *attr, char *page)
{
--
2.53.0
Technical Details
Message-ID:
<20261022-ptp-vclock-sampling-v5-1-06ceace17bac@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-350648-linux-kernel-netdev=dewy.ruReferences:
<20261022-ptp-vclock-sampling-v5-0-06ceace17bac@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-350648-linux-kernel-netdev=dewy.ru
From: james.hilliard1@gmail.com (James Hilliard)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v5 1/5] ptp: drain virtual clock sysfs operations
before unregistering children
Date: Thu, 22 Oct 2026 09:16:41 -0600
Organization: Usenet Network
Message-ID: <20261022-ptp-vclock-sampling-v5-1-06ceace17bac@gmail.com>
References: <20261022-ptp-vclock-sampling-v5-0-06ceace17bac@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
logging-data="242179"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:KWNookMP8hc7bSWJxvD+uMwc+Fk= sha256:U8vOGRUlYfdYNIS1IdNYgwVQRJjWG9KAn8qvu8+1qhc=
sha1:GNwEJT9O+yRL5D2lTodBqPxJrJ0= sha256:qhXT+hTcll9mEguNfl96bsozX7wBQTpKreasEgsh3ho=
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 8A3A51112CF; Thu, 22 Oct 2026 18:18:05 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 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.25,
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 RWpdo7toZjbr;
Thu, 22 Oct 2026 18:18:01 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-350648-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 0C6221112CB; Thu, 22 Oct 2026 18:17:53 +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 162A437270; Thu, 22 Oct 2026 15:16:51 +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=1792682210;
b=Mk/mdhTRDzERz84TqZ1TDSRmZpy/c/y43WgsdXdUX7rEVgyGosJnRSYgRw9yMcxUGYPp
HqsnHlhYtYSo1ZMKtgOZKNstFyxMQHffkM7xisZkVxx17WN9E1S2ZdQcJlyFr51lamorW
Wytctv3vdoktsNcxs0UNao+kGyNH8K9cGvKvslUrwW9r6tPgBLWThB768j0vNeuQvOGf4
wQFDU58nxpC68kg+4KvvHQtnA7Pz+z7v4m8fwAD03pBsfEmfHHYVQkq250bIHr82YPpk0
Ljsw8kwtI/KdgZnudukOIyhRCqGADAubA3yuwz6pBpi1FwYzL1HElF2W7hwUaT+BDiA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792682210;
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:Date:Subject:X-Mailing-List:List-Id:List-Post:List-Help:
List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Type:Content-Transfer-Encoding:Message-Id:References:
In-Reply-To:To:Cc:X-Mailer;
bh=DOHXnXj9H0hCXUUYqqbghfjLZTExI37IMuLDbNTswLI=;
b=tDHhDZ4eWEIANviU7nIxzZCwxBR72gF/CFSQG5gY9BN0ERU8boe/fRPaJRwnDxkeeSf+
qd8tQK5hbICQMrL++Cq4YNvkjF2isi05+OXZPDrfHQIk6UUFQnEC2vFO7hudc+unB0bmI
iWiVMo9+1ZHlDlIre2HSwett0Uy9nN46MoutyltPjzN3MSGZMy3nOSE9bM1MB5gwFQbnt
P1il//Sp1btx2L18P5DdbDYQ8NZmxZOTbfJZuNeGfx7F5NsQDt55vtAU9PPvjMybQwol8
/kVmyHH84jLtw6eL7OY1bsfyfSfQYWzGGVDfPbj175A7Os2oUOjUQhsFGAS+S3HSQCQ==
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=20251104 header.b=d4iKLn02;
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 D97DD606B38D;
Thu, 22 Oct 2026 15:16:50 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=d4iKLn02
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.41
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1792682210;
b=urJIdprs3wYKiY9RRheaAULlFq0v7h9Wn1JXrYH1vK45vUJp/KB7/A9LycSFQijvfN26
CWfpzgazo4HDzhdAnagYP3YrJgBGZl+n50Ep7kTa2O7w+PNg6+7tthPU5Oy4EgVw8s0ad
AK0fJbLedXhLDkzLEF/E2yyxWIqriSgH2guWY4TyAhoI5CBiIFrSrzK8Gd3T5kuPmSoB1
hUrvEKd4dRQrz9K3mMQOonsDVN8dRbJLnGznaAq7ByxhDhXK3ek8ofHXf+skyIE53kt0y
ZR0hhXdEt6G9WWobztMeLoyZ4OX0UYc3wWNtdKNnxJy7UJni+KuMY6nbFZa2zy8acdw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792682210;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:Date:Subject:
MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:
References:In-Reply-To:To:Cc:X-Mailer;
bh=DOHXnXj9H0hCXUUYqqbghfjLZTExI37IMuLDbNTswLI=;
b=HwwaOwcFCjBudDKruGHCefpKql9tMwDul5UEj8n0M1RayedbxDhWIZruYKIkKMD/RzRb
f8QoFZq0AiI/pXkm8mGaCUF5S14tusRd3Dn7O0tLCu7NMvVB+g1rDCkYvXEw97gNr0FKP
+YjHUwsjiTMBOe8Nmof4diNuw6gMYk/sBvwrHOhQD3Q3votBEztlDmDJN3KXWCsFwBMi3
O0MYpyIv0oOT0JVTyJQuHOlEmGwW3RdOQjZEcfvQbHPe5+zSX20XthKncHx8JHNYv3UsH
wQVNCIOURtZ7pjLoNE3J2EQwVo+sPTQCi8vqvLiQVXEC/OgttKzbUs6lG4Dkc0UaqmQ==
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=20251104 header.b=d4iKLn02;
arc=none smtp.remote-ip=209.85.161.41
X-Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41])
(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 AD268606B384
for <netdev@vger.kernel.org>; Thu, 22 Oct 2026 15:16:49 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AD268606B384
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-oo1-f41.google.com with SMTP id 006d021491bc7-6df5e315bd1so1204189eaf.2
for <netdev@vger.kernel.org>; Thu, 22 Oct 2026 08:16:49 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792682208; x=1793287008; darn=vger.kernel.org;
h=cc:to:in-reply-to:references:message-id:content-transfer-encoding
:content-type:mime-version:subject:date:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=DOHXnXj9H0hCXUUYqqbghfjLZTExI37IMuLDbNTswLI=;
b=d4iKLn02OTqL+KMfhrnOAAthWUA2hmMU3XVU59+ctqrRUNPLQABODb8zadkrhFSRxE
otlH/r1nXGDgqIRTySVkbFTiQZVHJ8G+sPnbxU5NxbyvujYUud+GBL4hFdEv5u3MfYEj
hqwhE2MM2lnsTkZZti76o+DGtR+F/jYCGWowrZ2Qyqonne+KHcWV6GljpEfboGurQ/iv
H/xELW09uua04J3nm2O1Ksf5pgGptGI5q+2I5dvCORCv+r0XhDeQ7J+rw6CfTHytzQx2
Xx6ImduwR9A7Wrkcw/BsQuep3JMXoUOugOhxufy6I9aARJDj68LwOs+7sfSN56aL5LJO
1Y2A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792682208; x=1793287008;
h=cc:to:in-reply-to:references:message-id:content-transfer-encoding
:content-type:mime-version:subject:date:from:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=DOHXnXj9H0hCXUUYqqbghfjLZTExI37IMuLDbNTswLI=;
b=p3EHpY+gVJE5yYxb5yBItIN4W3YC57QZlIi4hYXFGYJLbOE73XcKZiCo99hq8oWqV/
E/bSaWC302EFcJgo/1r13exEwKLS68N7thpr6lep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VQLpPK4fgWLvtvlq+1zbS4tppJFgw+8Y9TleCZ6Nfj+R/
hHGPw=
X-Received: by 2002:a05:6820:997:b0:6dd:4f30:258f with SMTP id 006d021491bc7-70940d5b3f2mr3229186eaf.56.1792682208643;
Thu, 22 Oct 2026 08:16:48 -0700 (PDT)
X-Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49])
by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4a7d5eb8fc0sm4685631fac.1.2026.10.22.08.16.46
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 22 Oct 2026 08:16:47 -0700 (PDT)
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-In-Reply-To: <20261022-ptp-vclock-sampling-v5-0-06ceace17bac@gmail.com>
X-Cc: Eric Dumazet <edumazet@kernel.org>,
"David S. Miller" <davem@davemloft.net>, linux-kernel@vger.kernel.org,
Vadim Fedorenko <vadim.fedorenko@linux.dev>,
James Hilliard <james.hilliard1@gmail.com>
X-Mailer: b4 0.15.2