From nobody Sat Oct 24 14:02:53 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792682210; b=GqmN20073ACCkdngBLP3zDDha033bZJHyQ3P2fteD9Du2BHBz40lzRbTLdeqRxe5sWnX Gqm5uhI0GbipUOt4Rig8pWKZdwDcvJVubYUcAvtfCcWGqvU1toMlcp79JWgGLlckOh4rz 36du5uBAAichIZkgsJbIiq2uu10960DhE5A9TBHt3+g2luz5H3Jp9ZHbXAwkI2/hhsBjV 4SwpXCG4HioJHliYONt7pGZdQg4xWCZ+iTQD8q8MnUAmH2bIheLobzJ2/+mIvMawWwcap vxPEF8lPY8gC3BUCVzdKaJSov5kA9eiVplUGH0gb7gLdCDej5jxuo+pGnjH2SRhIwbQ== 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-Forwarded-Encrypted: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=vMlgXJQUUmX+jSWVQHoQJ1yfbl89Qd6NY1F0uBbmMnJ1C/E2Eav5jjhHPa/syt7jvXPo ViwhyKZ8DKF2/23fSubc8f2Y41IqtMdaTyzNFMfDdZQVB/GOah8kI8Jw+ieKralCbY9Ot f1ZcP2KK+uyrvnG3eFIjt7HOixkfEeMIbWtzx//A6HvO8QY7o+HaHRZCU4WMncHhz4ToM w910LENhxD+sEST++vIpBBo/dANje0liC0Uv/wxeXdT6Svisq0rgFWbfwaPTSp+gfULtP 3l3kebsfcEWZVCVhrV/+ZiO9rCAbz/t7wKVtL1fmRUXghW0A9Vihl4Zf71Of1V/xUMg== 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.45 Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (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 ABF6E606B383 for ; Thu, 22 Oct 2026 15:16:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ABF6E606B383 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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 Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-70b875f6f13so9338eaf.0 for ; Thu, 22 Oct 2026 08:16:49 -0700 (PDT) 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=yXeuLusf59L1s3WYiCRzct9X9bXhecesgQzxC+yLV8nd8M4z1ne0dUvsgpSpsiLyak kIHid5xi/CL2GQVV+6gzlecrv4+vl1vkRM/7FVWo/uu7MPPn82wtQNL/hQHmXZy6LZjU HxvoZioBxpYcaaWr6CDSMqpa9Bg/sinfZwdulgHisRASdHQhFi+UUgUbIza6+8bnSAn+ z+PlQ3ZqpkVcVIbtuWqlD1b1douPZYuNhPIebbiTk/tYCI8udXJ154zBWtFQ4F+lsW72 CUCLQiqsrzq+/FPzzvQY0gAWQTW2rQo2qkHuuYh0ocetaLqqq78kRFKGF+DVzBrLHhPl RB2g== X-Forwarded-Encrypted: i=1; AKwUvBxjma2Ul6pu0SYzmarEfhIvwtgky4zsXRMZPAla/tMf7D0rrWCW2FEU5dt8US3Z/uQ+2PAPntR7L8QhsDU=@vger.kernel.org X-Gm-Message-State: AFq9FYKQz2V7eRjxUlrxXZ34Nud4pfw+3ttUTW15utjrKQSWcct3V1Fq yiUiWtCm91nPDSzSKxuQhn2OvSaEOYb4ph2L/8qSot7N0H0fjAJGlgPE X-Gm-Gg: AYBFou2ZkPHwVM5FKYR8zvdeEWlOSq9UfdbNwrMeP6Z1kQxXwwh6nEGqCs8v1zetiyx D6qyoxZIKsSBGYhoWOBYUnCgl2QseWGoW1GYpik//EMCGpX9oxeXaowxOwZq2V70gjVIm7GUwIR 5ZHeLDGv5A5co0BNxJuqHIAW36q4SGPhtuxnBHlqVgoa3sZnz99dCAapJb36f2wXNxsQN0TuEgf c/goi7s+xtods/IRFrp7pTHMaIH0bPgvwk2iY1uCqyskaVLen9uVN4/wMVdxLpoWrMhe0hXyp3a Pr/U5Q49wI56AlvoWodIMXLEjSRWVkw3dCoRJkM0JICYGFh7w9JiVes/c6/rIcKvcO3Zw78DMGD myOuM8IsCyVXG0YnbVjKjCx7jVIbe9sIKoLjtk1vIODGUtqI0JzlaXIQYm/OpdB2UybtH4sOJcV G5Nu4K/17UAxxHLW4HF13cgVmNmoyCu6JgKPyvZrMMH1MtjYCWyowClTxSlzuF+4F6QrVQeJXA8 HTf/Dwn1a6vPnS6RK1Ny5wvDch0SZBR+eQ9IwReJ8xlgLxEK2pcy60/LIL0M8Ni0a5vW3Cnj+X/ CqluubnDpft2mRCFfscgRprqNZehRC0kRMz6i8MLQALgHf6+v9mwemnx1H4lSYsQFgVVMuc4Xxm 5xKUCohJUQ1oc5XWnvp0+6yfvo1MqvlqCjAos0aP+AkPLNi3Qu1GAcEMWXRtiZWQI6x40/BEqH+ c4TRI= 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) 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) From: James Hilliard Date: Thu, 22 Oct 2026 09:16:41 -0600 Subject: [PATCH net v5 1/5] ptp: drain virtual clock sysfs operations before unregistering children X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261022-ptp-vclock-sampling-v5-1-06ceace17bac@gmail.com> References: <20261022-ptp-vclock-sampling-v5-0-06ceace17bac@gmail.com> In-Reply-To: <20261022-ptp-vclock-sampling-v5-0-06ceace17bac@gmail.com> To: netdev@vger.kernel.org, Paolo Abeni , Jakub Kicinski , Richard Cochran , Andrew Lunn , Yangbo Lu , Miroslav Lichvar Cc: Eric Dumazet , "David S. Miller" , linux-kernel@vger.kernel.org, Vadim Fedorenko , James Hilliard X-Mailer: b4 0.15.2 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 phy= sical clock.") Reviewed-by: Vadim Fedorenko Signed-off-by: James Hilliard --- 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) =20 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[]; =20 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); =20 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); =20 +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) { --=20 2.53.0 From nobody Sat Oct 24 14:02:53 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792682215; b=bOQe1eyaTv9+2RWaPGjlwNgFG+IIb2X5G7wBIMHVBc2ZxYQNnwe7LAK81ulipqX7tz+T 1QjzLWrmmCtGGX9xfvWBWuk3eTGOXqajXhUh+AX+3rsvMd8NbEbXejTRBGtmlzMVKggJF nTKNDmzSHBlh419tNbuM2sJc1Ch/8Dy5q/++e2NsKy/FyOJ309HireDFauwIAQ4NvwWjW IU4eC2nypGeYSNYhrvIDuU6nEDO076oNcsA/nrl63kUn4qh1hbNGJmb3FKz6a9cPaoygV 8jXcTybTjz3pjoxzhjW8/ygWBBIwoy2PYlGdzh7ZycuIXrWaqF8G9kn+wmwo35d3ihQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792682215; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=dOGTVagpmg3SkovNg8gY9NJcdR0snicKiJ3IvwwYIZg=; b=vX8Hb9Hvdat0+mZUnaZgpxuX5BjDxHRQvyOBysH8Ddxj0p8oPK/UeFtmV4oe8/h+qCOv fg2Qhs5UfRvsJ0uOMuY4oNtDKe7+ulAXbBmYceXrKQZeX92+5crWvooe6or8KmLtLTlvk yGLX0M3GdKDTZDLHuV9YRRBfOJCx82A0PJ5QvYKRdV1c6x3gQpuhTJoObXd0adRfgvwPb fkdTvjOEw26LEKB/oGkhI2/KXtjMeci1PHrTycruOrwKRr1ThTbnZXLGWTCR67X10TJrZ 9Y9jV5gR0nFANnNcMDBDw9TKRNsVH9VTIEVA8X4egiOB/lGTqIm1TVapJUtuUBD9CkQ== 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=gmBMmMgI; arc=none smtp.remote-ip=209.85.160.44 Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) (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 77B84606B383 for ; Thu, 22 Oct 2026 15:16:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 77B84606B383 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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=gmBMmMgI Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-4932b13c4ccso1007919fac.3 for ; Thu, 22 Oct 2026 08:16:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792682213; x=1793287013; 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=dOGTVagpmg3SkovNg8gY9NJcdR0snicKiJ3IvwwYIZg=; b=gmBMmMgIv4ChXTLyXqT937GGjYbZfczKHrXmdNzdGzgWcCdX672S2Av+RP7IvBbpoW P+oSJBLvyK7sqC/Wj4736VDoy4ySLsvfgnQ5Oo4la5n5Ox/E9GPWxTYc9TfKoBVg/AnS e06cNuJW9GME9Cnb53Imly4VcE9Huc+iC1a0MkyGZSJli0EzifEs1b0yDCDcc1UydBbr 6QEsdEFCVS55JVEDjgO/ZH0M7TYCOw5ZDAQuvwzbKkF4ExYHuJ6ee30qmP/0Vn0eT1mT 3xHAQio+la6q2KCYUDiwb4JwHrlgbgtZN1DEXXafy5A47BcPQM8AHr76vIdtX+CpKS/f z+Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792682213; x=1793287013; 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=dOGTVagpmg3SkovNg8gY9NJcdR0snicKiJ3IvwwYIZg=; b=K2GrMgWDYL+9kPm9nu8enc5c+0yxAUsxcrj4s3ZcORTgGUhTU6awrQ0s9DeJJhhNI/ 4r25TE2U1NzeyHmajYEPL7IfqLTzGtWZDcI/f77xXKb3K2iPCkrgkSeYccIfb4I6FMPD p78TDCOHwZormfUWEkNbufNpQ1Tx81sWec3vS3FMYbOLW2ppeVPlKYXpW7fXq5Iei5EG xfAICEk8UGVbRAFHCktxPu1AijKiJDqXoNTwiSHamufncnJPtD08FguUwx0RE+w1JMcH WxXMqiwDspUjreV11IDQGtuq7RpoXdd80EZZGotzQyFlWLP1+M7fxtAW+vYo9UZCycyx PevA== X-Forwarded-Encrypted: i=1; AKwUvBz5m/plhjAKWSMvvo/7NF1HXeJMLbnR1EJyWWxXtjnOtaje5E5CStEJ4I6fNegPowcJemHV5BV4r7lAvBw=@vger.kernel.org X-Gm-Message-State: AFq9FYLcpjYpN8OnGtx3Y55VPyVB5h1umVI9aSc6XuscSDq/NepbWpF9 aCuJltlHC1I0hdD2NNu84Ayp7nVvGIZnWh/SAL/j5iytx1GpE7JzaD7l X-Gm-Gg: AYBFou06NLfXEXqX5mzEoumwxFS68L4x87xU5v13YQFBm354cqUNhOjWyMbmGMlb3ny Enf6P8RRttVh19ZrHdQv52PTcPvcCOOTE2kLsfr8esfxZIQAtPOmDloMuaw4pLu1BI8HC8WPYqW hZdExcB/B+wIfHMF6zZxvokMh3IrTOacu3hz/+gRuU+d1xmwiGC3ZJP//aIASiXU7qCR5/rHB6e oqPPMuwCvkeND4llKDWZAOMzwWkalbmY4DfOhvDu/8A9yx6JA4h2Al76oNQPdEx/q+MouoSGokm oF/GaWwpkV4e+vt+L8SEFejSE7/xaY0WioEPehnEyyxuVOYq5RTu9SHY86B97Hv2PM2dafm7a7d 5tip4tsXuvVLLNxjDg7wGLbssnTjYm3VkcchSKvxnGgD2lHRzQsLSM3F7+GnHOdfRRPLXX+6NEY hiN4j9Pwk5R47qYARWslcH12ahgzd+6XHhv/uAOM3lFPusK1iORYDvCgPx+0e6oz/vH7t3X+AnE +OFfLmHnbampHXsifxjj3ewFV1G6MK+0U9XoLg1nVFl39VHeDHtctHKnuKzpWUopXbVB1izIMlt QBCA8AhWyCbXg2TsIRUKbNYwRxCJprupk7ymC72Cq/pXWCqwgUXhprO6Rhpf2KZRAgKn3WG0k+B z7Zs9IE1F3bLpefBmnjZreqAqM1egntrYaEasllLQdnH+3g6gTBdCniwTV3B8vox5pN8qdfPzFe FrqQgf X-Received: by 2002:a05:6871:78c:b0:447:1ceb:7cc6 with SMTP id 586e51a60fabf-4a7dc1b02bemr3328201fac.15.1792682213322; Thu, 22 Oct 2026 08:16:53 -0700 (PDT) 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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 08:16:49 -0700 (PDT) From: James Hilliard Date: Thu, 22 Oct 2026 09:16:42 -0600 Subject: [PATCH net v5 2/5] ptp: unwind partially completed virtual clock creation X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261022-ptp-vclock-sampling-v5-2-06ceace17bac@gmail.com> References: <20261022-ptp-vclock-sampling-v5-0-06ceace17bac@gmail.com> In-Reply-To: <20261022-ptp-vclock-sampling-v5-0-06ceace17bac@gmail.com> To: netdev@vger.kernel.org, Paolo Abeni , Jakub Kicinski , Richard Cochran , Andrew Lunn , Yangbo Lu , Miroslav Lichvar Cc: Eric Dumazet , "David S. Miller" , linux-kernel@vger.kernel.org, Vadim Fedorenko , James Hilliard X-Mailer: b4 0.15.2 n_vclocks_store() publishes the new clock count only after every child has been registered. If a later registration fails, it returns without unregistering the children already created by that request. Those clocks are left out of n_vclocks, and a subsequent request can overwrite their index entries without removing them. Unregister the newly created children in reverse order and clear their index entries on failure. Leave the previously installed clocks and their count unchanged. The n_vclocks mutex serializes this rollback with other sysfs changes, and parent removal drains the store before walking the children. This was found by code inspection while adding initial PHC sample error handling to virtual clock registration. Fixes: 73f37068d540 ("ptp: support ptp physical/virtual clocks conversion") Signed-off-by: James Hilliard --- drivers/ptp/ptp_sysfs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c index 53388b123198..fabc1c9b1752 100644 --- a/drivers/ptp/ptp_sysfs.c +++ b/drivers/ptp/ptp_sysfs.c @@ -225,7 +225,7 @@ static ssize_t n_vclocks_store(struct device *dev, for (i =3D 0; i < num - ptp->n_vclocks; i++) { vclock =3D ptp_vclock_register(ptp); if (!vclock) - goto out; + goto err_register; =20 *(ptp->vclock_index + ptp->n_vclocks + i) =3D vclock->clock->index; @@ -257,6 +257,12 @@ static ssize_t n_vclocks_store(struct device *dev, mutex_unlock(&ptp->n_vclocks_mux); =20 return count; +err_register: + num =3D i; + if (num) + device_for_each_child_reverse(dev, &num, unregister_vclock); + for (num =3D 0; num < i; num++) + ptp->vclock_index[ptp->n_vclocks + num] =3D -1; out: mutex_unlock(&ptp->n_vclocks_mux); return err; --=20 2.53.0 From nobody Sat Oct 24 14:02:53 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792682219; b=jMmVYp1Ac/F2DkyTsMhTFxJyaFrNJNjFFGM2zxDwUKPyxXsdPhmyN2HL0/FMIH5LXuZX oYjBSdKfzi/FuxqB3dF9RyYV4Sc8e8jhwJSsGMSwzv4NbOLhS9V+mp3c0DXH1cOhl17t4 qlJTtBReHzHue7heYaLFsmQh1B0hHDeujcfOgIiei4RpOpGZF6G4dgDDiteym6zD5Tz2z pfgQG524r0Ld5kQOZXQU7TqOh6mLEyVc0DsQrHTHN4iepfGmNrTEDwJtdlSEgkrkMK7pM clAauWJ755Y8foUJuOyQrd3UEOpCCENQ47ssZUOyhYOwNRWkMyyDfkNTA6RX5I6qYkg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792682219; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=ArZTwUoXYzov7eHPXGfSS3R5PEo5sgxcCtm/GX7TEww=; b=xZaVJ/sCOpw9sMP156Nbkr7YmJuNCs9WPQU9v4/C8LLC81670Am/Bj2FenZz5iVLr8ps j141oBlOD3iPbsXLAeDDxC36Y5ZJ9ai8PMBcu5w/QuLdEKhZwCVG4IyR5LK10sRClAS7V akq4CDqfDHYSnIcXWdyXm3yRceYk/1uzFu/uu/5TV+p3JrpqE/5OrGR2QwhWLcFIokqFh J2fQD2jkeoZznYEnxrXQthTJ/1p/ZGImUeF1HrowOGw+daVcRdRn/WWyBLw9HAHx6S/b4 wuMZKqxzJtdnIwAw7ZUNLfKgU56apk0o6DAHMxilN+bwsU4tLrF4e/+1uEV2G3j4TTw== 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=pxAnD+jc; arc=none smtp.remote-ip=209.85.160.45 Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) (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 8752E606B3A3 for ; Thu, 22 Oct 2026 15:16:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8752E606B3A3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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=pxAnD+jc Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-49e5f85ce89so797742fac.0 for ; Thu, 22 Oct 2026 08:16:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792682217; x=1793287017; 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=ArZTwUoXYzov7eHPXGfSS3R5PEo5sgxcCtm/GX7TEww=; b=pxAnD+jc1lOVkSXjBuFvtopiKYPsS54zOLQbTxN/OOJM6oBZiH2/s6AOqwjfvltOX3 v57BjOSJk9hYe4bHqvTDMjnEKuN+g9vBhVZ77RRgqa5l4HFRzWNASUW7HMK+9hrNgZeR GcAd3xpxqlSLBLl+hgXOhXzdzZgN0nC+v+iJxt9OHWZ4B2+AtAKl7Q3F6ga7IJJqh0lx HnEYhCnD06A3OmR1Da3DldTC9YbFg9JNLlCVoPsMm+zNcXG5nQZwGaiknf4OV5aeHudo is6kHqdhSjHcQg8PdsJYJNyFmbLzcpomOo51GE3NNh54Iw06Io1kVpNT56q12e8Z3Nbd C2Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792682217; x=1793287017; 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=ArZTwUoXYzov7eHPXGfSS3R5PEo5sgxcCtm/GX7TEww=; b=B+oZ5NPur2A4SMXzKPdK7TK82wo+kBepgi/zVdTGwIR1OQ6UhAl+Nx0X99tuuiOuwV vRcy7ZW5/ettUILWLUCE220uhJGSB5Z41nyEgwkFNT0UfwbYSWvB2ZBOSmCt4SYvNHJc XWZEqsGqyryxz4n9WemP/PfFXMQ6g0ac1q/RAswe/NEv8IgEGUW45DfEWC6aXIw2HvMh fF4X1uptdCEjKujoZ8Ph6mWDFLmPl1+pezqiFszWI4Vc8j2W+Po9iHrNvkZRW9yHMEXp GKAOnG/fjNg5ps/MF8AB1YCWCTyoubzwg9eH1Q2BYzijMofgCOS5e11JnQmXOUuFhnkQ t4Xw== X-Forwarded-Encrypted: i=1; AKwUvBwC+4vyb1/5K4FZvdicCnhN4B2hGBPl3BaNLa7OuRQBlK3uCHrZFM6CkKVbdPrvWVO107y01OD55jpy8JU=@vger.kernel.org X-Gm-Message-State: AFq9FYL6nDhSePYXVXP8fXdEpm0fI0UUNZsfCHAnjygML5Pe19u0DL1e XjT83aGw6b5X/pb80CIFSsZ7wRpybr8ma/xLIrJMS47oGdVAa/LGGNMj X-Gm-Gg: AYBFou33s2fRwKHG18qTc8Br+8SKhh+OBMbieQRYPkHNLX04ncJhvC8nuEVPuWEPXUV O1v+/cZ+g/Ir5gNjT99vrhLEgYKrpkaqCrgSn5Up+zqpMbd6sRBzlAJPgnx8ps8DmrBWiY/LoVa CZsBcQ4wMJLbmkSgMoHEWa/SwMGqAVFTLKGNYlyE8bwtfxT+0X/0Pk01Z+ef8rYbHie8W7ad8X/ LgrHfd0Xl4rvUyCv2jryXRRwFNGy5zTQVCI76mYu9T8hPRZlwmytIVpqQ7qzyfccmaUXK+2qbNE wnN63U3k+Z+iPr1ZsKufG0Ua+H/R96BKv3aH5s9NH1skqY/BiJhm9lNsIylqn6cdrdNZOpwnxqe cJLBspJXwKP3wXzpvhETloQanZfBqS0SSq41bh3oe61Vkpw+c6KJOrkCu09gs3nIUcJuqxoAwHZ fr1ML6e8R3eGK4k7qnpxZMRk8wcNsYUWcnpaUPIEoUX+le0A0tWG0STu7Lvc3XosvZ8vRNurL2S UYx5mf2lqtf8iM1boEbDthOBJHr5pj80N5px+JKifECdIHDcJIjmVlEYSJu2k7RYjLSd+isCLNG YokCoKD/UeRBqppGNw8mVzLYTFcbAH+YI/0kFvaQ+LX80Xcr+qzVMpemAMWAr6hTbEJypl3WEGc W42hnBgcp0REvZWBFF5e60iQ6CFdswdo23Kp/eec6aMwPZEDPVyeuBzPdYO4j4PhOfs5EUrfPGO Ve8aQ= X-Received: by 2002:a05:6870:75cd:b0:48f:e3d4:d45e with SMTP id 586e51a60fabf-4a7dc2bb1aamr4035590fac.61.1792682217381; Thu, 22 Oct 2026 08:16:57 -0700 (PDT) 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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 08:16:54 -0700 (PDT) From: James Hilliard Date: Thu, 22 Oct 2026 09:16:43 -0600 Subject: [PATCH net v5 3/5] ptp: vclock: propagate physical clock sampling errors X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261022-ptp-vclock-sampling-v5-3-06ceace17bac@gmail.com> References: <20261022-ptp-vclock-sampling-v5-0-06ceace17bac@gmail.com> In-Reply-To: <20261022-ptp-vclock-sampling-v5-0-06ceace17bac@gmail.com> To: netdev@vger.kernel.org, Paolo Abeni , Jakub Kicinski , Richard Cochran , Andrew Lunn , Yangbo Lu , Miroslav Lichvar Cc: Eric Dumazet , "David S. Miller" , linux-kernel@vger.kernel.org, Vadim Fedorenko , James Hilliard X-Mailer: b4 0.15.2 The cyclecounter read callback cannot report errors. ptp_vclock_read() ignores the return from the physical clock and consumes its output even if the read failed. A zero sample followed by the real counter can add an extra 32-bit wrap to virtual time. This was found by code inspection of reset-time PHC access and the virtual clock callers. Sample the parent before calling timecounter_read() or timecounter_init() and have the cyclecounter callback return the cached successful sample. On failure, leave the counter and frequency adjustment unchanged and return the PHC error to the caller. Retry the first failed refresh after 10 ms instead of waiting another two seconds. With the existing 32-bit nanosecond mask, timecounter_cyc2time() can interpret a fresh timestamp as being in the past once the last successful refresh is about 2.147 seconds old. An isolated read failure should not deliberately defer the next attempt until that sample is four seconds old. Double the retry delay after consecutive failures, up to the normal two-second refresh interval, and reset it after a successful refresh. Each virtual clock has its own worker, and a failed parent read can involve bus traffic and error logging. Backoff limits that repeated work during a persistent failure while retaining a prompt first retry. Keep the retry state private to each clock's auxiliary worker. Take the initial sample and initialize the counter before publishing the clock. Return an error pointer from registration and propagate its errno through n_vclocks, including when the initial sample fails. Queue the first refresh immediately after registration so registration latency is not followed by another full refresh interval. Keep the existing cyclecounter mask and scaling. These scheduling changes do not guarantee timely samples: prolonged read failures or worker delays can still exceed the half-wrap conversion window, and a gap of about 4.295 seconds between successful samples can lose a full counter wrap. Do not assume that getcycles64() exposes a full-width nanosecond counter. Fixes: 5d43f951b1ac ("ptp: add ptp virtual clock driver framework") Signed-off-by: James Hilliard --- drivers/ptp/ptp_private.h | 4 ++- drivers/ptp/ptp_sysfs.c | 4 ++- drivers/ptp/ptp_vclock.c | 83 +++++++++++++++++++++++++++++++++++--------= ---- 3 files changed, 68 insertions(+), 23 deletions(-) diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h index ec8633126d6b..9c458c2d50de 100644 --- a/drivers/ptp/ptp_private.h +++ b/drivers/ptp/ptp_private.h @@ -81,7 +81,9 @@ struct ptp_vclock { struct hlist_node vclock_hash_node; struct cyclecounter cc; struct timecounter tc; - struct mutex lock; /* protects tc/cc */ + u64 cycles; + struct mutex lock; /* protects tc/cc and the cached sample */ + unsigned long retry_delay; /* owned by the auxiliary worker */ }; =20 /* diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c index fabc1c9b1752..026220b112c2 100644 --- a/drivers/ptp/ptp_sysfs.c +++ b/drivers/ptp/ptp_sysfs.c @@ -224,8 +224,10 @@ static ssize_t n_vclocks_store(struct device *dev, if (num > ptp->n_vclocks) { for (i =3D 0; i < num - ptp->n_vclocks; i++) { vclock =3D ptp_vclock_register(ptp); - if (!vclock) + if (IS_ERR(vclock)) { + err =3D PTR_ERR(vclock); goto err_register; + } =20 *(ptp->vclock_index + ptp->n_vclocks + i) =3D vclock->clock->index; diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c index 84cb527f59cc..c10eba6443f9 100644 --- a/drivers/ptp/ptp_vclock.c +++ b/drivers/ptp/ptp_vclock.c @@ -4,6 +4,7 @@ * * Copyright 2021 NXP */ +#include #include #include #include "ptp_private.h" @@ -13,6 +14,7 @@ #define PTP_VCLOCK_FADJ_SHIFT 9 #define PTP_VCLOCK_FADJ_DENOMINATOR 15625ULL #define PTP_VCLOCK_REFRESH_INTERVAL (HZ * 2) +#define PTP_VCLOCK_RETRY_INTERVAL msecs_to_jiffies(10) =20 /* protects vclock_hash addition/deletion */ static DEFINE_SPINLOCK(vclock_hash_lock); @@ -42,21 +44,39 @@ static void ptp_vclock_hash_del(struct ptp_vclock *vclo= ck) synchronize_srcu(&vclock_srcu); } =20 +/* The caller holds vclock->lock, or has not published the clock yet. */ +static int ptp_vclock_sample(struct ptp_vclock *vclock) +{ + struct ptp_clock *ptp =3D vclock->pclock; + struct timespec64 ts; + int err; + + err =3D ptp->info->getcycles64(ptp->info, &ts); + if (!err) + vclock->cycles =3D timespec64_to_ns(&ts); + + return err; +} + static int ptp_vclock_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) { struct ptp_vclock *vclock =3D info_to_vclock(ptp); s64 adj; + int err; =20 adj =3D (s64)scaled_ppm << PTP_VCLOCK_FADJ_SHIFT; adj =3D div_s64(adj, PTP_VCLOCK_FADJ_DENOMINATOR); =20 if (mutex_lock_interruptible(&vclock->lock)) return -EINTR; - timecounter_read(&vclock->tc); - vclock->cc.mult =3D PTP_VCLOCK_CC_MULT + adj; + err =3D ptp_vclock_sample(vclock); + if (!err) { + timecounter_read(&vclock->tc); + vclock->cc.mult =3D PTP_VCLOCK_CC_MULT + adj; + } mutex_unlock(&vclock->lock); =20 - return 0; + return err; } =20 static int ptp_vclock_adjtime(struct ptp_clock_info *ptp, s64 delta) @@ -75,15 +95,16 @@ static int ptp_vclock_gettime(struct ptp_clock_info *pt= p, struct timespec64 *ts) { struct ptp_vclock *vclock =3D info_to_vclock(ptp); - u64 ns; + int err; =20 if (mutex_lock_interruptible(&vclock->lock)) return -EINTR; - ns =3D timecounter_read(&vclock->tc); + err =3D ptp_vclock_sample(vclock); + if (!err) + *ts =3D ns_to_timespec64(timecounter_read(&vclock->tc)); mutex_unlock(&vclock->lock); - *ts =3D ns_to_timespec64(ns); =20 - return 0; + return err; } =20 static int ptp_vclock_gettimex(struct ptp_clock_info *ptp, @@ -115,13 +136,16 @@ static int ptp_vclock_settime(struct ptp_clock_info *= ptp, { struct ptp_vclock *vclock =3D info_to_vclock(ptp); u64 ns =3D timespec64_to_ns(ts); + int err; =20 if (mutex_lock_interruptible(&vclock->lock)) return -EINTR; - timecounter_init(&vclock->tc, &vclock->cc, ns); + err =3D ptp_vclock_sample(vclock); + if (!err) + timecounter_init(&vclock->tc, &vclock->cc, ns); mutex_unlock(&vclock->lock); =20 - return 0; + return err; } =20 static int ptp_vclock_getcrosststamp(struct ptp_clock_info *ptp, @@ -151,8 +175,18 @@ static long ptp_vclock_refresh(struct ptp_clock_info *= ptp) struct ptp_vclock *vclock =3D info_to_vclock(ptp); struct timespec64 ts; =20 - ptp_vclock_gettime(&vclock->info, &ts); + /* Retry transient failures promptly, but back off during long outages. */ + if (ptp_vclock_gettime(&vclock->info, &ts)) { + if (!vclock->retry_delay) + vclock->retry_delay =3D PTP_VCLOCK_RETRY_INTERVAL; + else + vclock->retry_delay =3D min_t(unsigned long, + vclock->retry_delay * 2, + PTP_VCLOCK_REFRESH_INTERVAL); + return vclock->retry_delay; + } =20 + vclock->retry_delay =3D 0; return PTP_VCLOCK_REFRESH_INTERVAL; } =20 @@ -174,12 +208,9 @@ static const struct ptp_clock_info ptp_vclock_info =3D= { static u64 ptp_vclock_read(struct cyclecounter *cc) { struct ptp_vclock *vclock =3D cc_to_vclock(cc); - struct ptp_clock *ptp =3D vclock->pclock; - struct timespec64 ts =3D {}; - - ptp->info->getcycles64(ptp->info, &ts); =20 - return timespec64_to_ns(&ts); + /* The cyclecounter callback cannot report a failed PHC read. */ + return vclock->cycles; } =20 static const struct cyclecounter ptp_vclock_cc =3D { @@ -192,10 +223,11 @@ static const struct cyclecounter ptp_vclock_cc =3D { struct ptp_vclock *ptp_vclock_register(struct ptp_clock *pclock) { struct ptp_vclock *vclock; + int err; =20 vclock =3D kzalloc_obj(*vclock); if (!vclock) - return NULL; + return ERR_PTR(-ENOMEM); =20 vclock->pclock =3D pclock; vclock->info =3D ptp_vclock_info; @@ -214,20 +246,29 @@ struct ptp_vclock *ptp_vclock_register(struct ptp_clo= ck *pclock) =20 mutex_init(&vclock->lock); =20 + err =3D ptp_vclock_sample(vclock); + if (err) + goto free_vclock; + timecounter_init(&vclock->tc, &vclock->cc, 0); + vclock->clock =3D ptp_clock_register(&vclock->info, &pclock->dev); - if (IS_ERR_OR_NULL(vclock->clock)) { - kfree(vclock); - return NULL; + if (IS_ERR(vclock->clock)) { + err =3D PTR_ERR(vclock->clock); + goto free_vclock; } =20 ptp_vclock_set_subclass(vclock->clock); =20 - timecounter_init(&vclock->tc, &vclock->cc, 0); - ptp_schedule_worker(vclock->clock, PTP_VCLOCK_REFRESH_INTERVAL); + /* The initial sample predates registration; refresh without more delay. = */ + ptp_schedule_worker(vclock->clock, 0); =20 ptp_vclock_hash_add(vclock); =20 return vclock; + +free_vclock: + kfree(vclock); + return ERR_PTR(err); } =20 void ptp_vclock_unregister(struct ptp_vclock *vclock) --=20 2.53.0 From nobody Sat Oct 24 14:02:53 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792682221; b=O1fc7oS1ofDOCb1MNV+w/eT4fkvChzgTy4zZCv4mCXLB/s2iCYm8YqaEoTYkc4y/7Tlt 4IR+tr7cKo50sYknKNX4FSMYAwiA99AI04c2C4nE1up+Yalmg6vwnEa4Us0JddOpL4bkL 6e85dX8lTwXM15GdD+xBXJfSdlEOnZN1SSTq6yzgN7B3GcIG+9VDzAEWzAEbo3iskmuLC tRqA/xuCTXKRaCTsaqSPKyU+exhQbRXPwJu9eqAt4WOyt6puHJsyGQP0O7BeeNePE50jb 0JhexOdkLIdgz8bDjXnmC5w6SeslMCybCs1yuxR9xFf2K0wMpHPGXv2iXkOC3goW7Fg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792682221; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=jDEb6h8puAPE3QoM8kSfzOL4afpqMiINRrdEonSGo6c=; b=rxprxz5ZTALlmwvCcdkZUWI0pmpAJ2s/4rImW3mASRr+ZNGlyTz6ELSEy07ng6SLhenB /ogtEJbkvqZhuymNGrTrJnhMtjet2O/43wfkEiVb/HhMLAsxbvv/Azy6Eu/SVDgMd/rhs rUk18JO+5weuOqY981qphSTEiJUM5JZ660jWgJtnNy8twhSYzaHmcgpHz34bqKhzB8uQI t9rJwCLGOV1EXJnF3AFhdBEyQCxUpTAaVjXCv8Qg9STDgmdffsAazsU1yCbWJXDfDu6bS Z7GZtLIu9pM4qmBXolBiXKJP0VjGNkyjlyUE1TrmorxRX9FuIOmPBjVXFhq9cb643dg== 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=mElLrz1D; arc=none smtp.remote-ip=209.85.161.51 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (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 2975D606B3BE for ; Thu, 22 Oct 2026 15:17:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2975D606B3BE Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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=mElLrz1D Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-6de2f213b7aso847527eaf.0 for ; Thu, 22 Oct 2026 08:17:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792682220; x=1793287020; 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=jDEb6h8puAPE3QoM8kSfzOL4afpqMiINRrdEonSGo6c=; b=mElLrz1D0tMQTj8eeBUtaNFdVWOi1zEYMq1azUxAqmnnAvs5XpTFgfKlUlOZu3shM7 7H1rrFEOlcWGvHPIcnOLZ2RXyKpklWvmFPSnagd+TYKMfurUTzANwrM498DKbbOTRYTz wHLoBqAcx65ETDcEgIBAoR3IlFHGQWanuQ+RF21DTNlCDIbQTu83W8UIms1khS7LZwVQ iRgIrR2Gl3KiEQZLWaMmLV82gZnuGR9zUQjRHCjnOtsM5lsinUpVLjPXVhovcz8AfVbR mH+H+GjNgparOncAnS8FCcT+WKec12jDCysFyzbhhqUM5RUgXSCLYDoSuvugB6STkPZV gBAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792682220; x=1793287020; 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=jDEb6h8puAPE3QoM8kSfzOL4afpqMiINRrdEonSGo6c=; b=qxyHattLQaWGjrj/Ie/fmvjpIXakUIHb1U8nH3mit7agWhkfHRKc3GKAe1TAWuzHNt xIm2cEONha6ueup93ux3ewPpHU+ts1QB1oCdD0sfh8ZFOkMgpmEyTRMPOtGuUyQ0i8Er uMyGiJLvaO19UUeFRzX/Xlq53vfLsq1uFuaWnObH3mC1qY7zMoJBRnhKtxTB0H2bcW8o HY+6wPdcbz0REGiRp61o0JCthm1QYj8UQPZsjmFKA3twosioxQf62QxqM2KLY0qtdr52 /dNgCc4oJMYTBguW5PKsIiGub8KzqsG+R3yUMSCmnEiQ9ADMC2zv0uvNlXim2YBVBoTi Z48Q== X-Forwarded-Encrypted: i=1; AKwUvBy+1LqAVAKL8yFZ+dg7JQmVbquUYnZFqogj1ue5uDHE2rtA5bEtaQkdncUsqtmjvuN47uY4I36tEgmEo3s=@vger.kernel.org X-Gm-Message-State: AFq9FYJHKmRmnX69GZy7h/SVQ5+zpaV/Nsn6lzhzbogVqLvvDa81H0/k Ot+E9VItGNMDJwtv/5auawWuF1GK7gfbufr5655aIF9hMMIkiIH/qhi9 X-Gm-Gg: AYBFou0EWGvLjQfUjXiybQvPTevFPqIjiwvofgmkocoa8mtKGJKLB9D+xHdJn6O2UHW qYGdZ0wsv+80YnvSaD0f1V71L/Gru/ZRPFc/yHuh2vGh0S/RHZzdcLmM5Llbym8x7wkmtCnBHK9 NIOME/bBkEXBWtO1KSODYeI9KgzYm0EHCTQC1xQiXnUonmGbzQswmjlBVuqNnpw2pNCxZJVqdHP 0MbpKa+lWI5g7F2Kn3zQSJW6nEFHBLval85NOvsPmNW/4DaTUnl/QLp/mmle8ocWDAU/fE6BRkc Bv1f8Ng4A8xzbF/4uRwQK/rSetGaGAJuV/BWB251KbkCJppwSRrnCPI/pDKeZX1fq7atX3XDNZi Yqs1XeAU/CAzmr2P5OMwRaxBoMGXMFhi/qrwqS2zYxo063i6TZvzE4Kei3PINJsfaBBQSMq77E4 sbKE7CG5QPEFtYe6nQBgRG/tpLjADHyqz59H4rB4Db9LCCki0wwC5wnnUabFmfm0gWvES0YjpIl vZ515Je/O6hKecZEMPvhEKIV30KlahWMqLpYMXiRVev7KPf8/KbsjNwbx9YhmJ1egtzYpnhHlow PcEfmzhu08pQUhGpvIe7IKeQQAKBjmSrQiJh3p433iqxnK0FIANfX8g4frh5hJefVv6ua6TTM+7 3EsUeg4cmSHl0vYUIo7dSqZIdZVU3rejzBWotJDwI8LiSCtvSGl7Xcfpg3Vzy4Nxn8o8cfl1w7E dExic2UlXI0o4zp27xNGr7LTrr X-Received: by 2002:a05:6820:4b8d:b0:703:27e0:356 with SMTP id 006d021491bc7-7094283046dmr3279957eaf.73.1792682220019; Thu, 22 Oct 2026 08:17:00 -0700 (PDT) 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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 08:16:58 -0700 (PDT) From: James Hilliard Date: Thu, 22 Oct 2026 09:16:44 -0600 Subject: [PATCH net v5 4/5] ptp: vclock: serialize extended samples with counter updates X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261022-ptp-vclock-sampling-v5-4-06ceace17bac@gmail.com> References: <20261022-ptp-vclock-sampling-v5-0-06ceace17bac@gmail.com> In-Reply-To: <20261022-ptp-vclock-sampling-v5-0-06ceace17bac@gmail.com> To: netdev@vger.kernel.org, Paolo Abeni , Jakub Kicinski , Richard Cochran , Andrew Lunn , Yangbo Lu , Miroslav Lichvar Cc: Eric Dumazet , "David S. Miller" , linux-kernel@vger.kernel.org, Vadim Fedorenko , James Hilliard X-Mailer: b4 0.15.2 The extended and cross-timestamp callbacks sample the physical clock before taking the virtual clock mutex. A concurrent frequency adjustment can advance the timecounter and change its multiplier in between, so the older sample is converted using a different frequency than the one in effect when it was taken. Take the mutex before sampling and keep it held through the conversion. Retain timecounter_cyc2time() and its existing conversion window. A PHC sample need not advance the counter: for example, e1000e explicitly allows non-monotonic SYSTIM readings. Treating a slightly older sample as a forward delta would instead advance virtual time by nearly a full counter wrap. This race was found by code inspection of the virtual clock sampling paths. Fixes: f0067ebfc42b ("ptp: add gettimex64() to virtual clocks.") Fixes: 21fad63084c2 ("ptp: add getcrosststamp() to virtual clocks.") Signed-off-by: James Hilliard --- drivers/ptp/ptp_vclock.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c index c10eba6443f9..4e98f119de72 100644 --- a/drivers/ptp/ptp_vclock.c +++ b/drivers/ptp/ptp_vclock.c @@ -115,20 +115,18 @@ static int ptp_vclock_gettimex(struct ptp_clock_info = *ptp, struct ptp_clock *pptp =3D vclock->pclock; struct timespec64 pts; int err; - u64 ns; - - err =3D pptp->info->getcyclesx64(pptp->info, &pts, sts); - if (err) - return err; =20 if (mutex_lock_interruptible(&vclock->lock)) return -EINTR; - ns =3D timecounter_cyc2time(&vclock->tc, timespec64_to_ns(&pts)); - mutex_unlock(&vclock->lock); + err =3D pptp->info->getcyclesx64(pptp->info, &pts, sts); + if (!err) { + u64 ns =3D timecounter_cyc2time(&vclock->tc, timespec64_to_ns(&pts)); =20 - *ts =3D ns_to_timespec64(ns); + *ts =3D ns_to_timespec64(ns); + } + mutex_unlock(&vclock->lock); =20 - return 0; + return err; } =20 static int ptp_vclock_settime(struct ptp_clock_info *ptp, @@ -154,20 +152,18 @@ static int ptp_vclock_getcrosststamp(struct ptp_clock= _info *ptp, struct ptp_vclock *vclock =3D info_to_vclock(ptp); struct ptp_clock *pptp =3D vclock->pclock; int err; - u64 ns; - - err =3D pptp->info->getcrosscycles(pptp->info, xtstamp); - if (err) - return err; =20 if (mutex_lock_interruptible(&vclock->lock)) return -EINTR; - ns =3D timecounter_cyc2time(&vclock->tc, ktime_to_ns(xtstamp->device)); - mutex_unlock(&vclock->lock); + err =3D pptp->info->getcrosscycles(pptp->info, xtstamp); + if (!err) { + u64 ns =3D timecounter_cyc2time(&vclock->tc, ktime_to_ns(xtstamp->device= )); =20 - xtstamp->device =3D ns_to_ktime(ns); + xtstamp->device =3D ns_to_ktime(ns); + } + mutex_unlock(&vclock->lock); =20 - return 0; + return err; } =20 static long ptp_vclock_refresh(struct ptp_clock_info *ptp) --=20 2.53.0 From nobody Sat Oct 24 14:02:53 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792682238; b=lcQyoJvEhSz0klPenP8MGxTF3ME4Vt52ioYSj2+NiY6T49R5n02ZZWC41MnUVWElFtDS QrDizJo134oeYuXTtP5pr8+GH2A5cYXuoU8wrPT9x7M6CNSIaHUCirZxctOgI67Al36Gq gwZAE4o8D6dd2498h8d+o3P0/22SxG38RIgHrX+jhMR2j8/7oCsxf517e6GXQtHSCjia+ XM4mrza4MfNFojIifKDtiOaub5L6KggqvOwPtaODrlx7USZ3olzOyvHr4jLHE5kCSpuM4 mJknN+CHuQ8ZWFpaWXHpMcPL0TnHiBGT42ZDvDYloO2qgltYqesdc3gr4BBZ+FhI0MA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792682238; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=BMS/vcyNjL65g3dFxx4/6BCGx6UhCt4NMD1MWFw7eU4=; b=eYOwxOqm1mHgklhlUJt/OjnW+XvmKYBGv30+SoIg/VgIjdvKaoqhj5u6+4btDQ43X9i8 nmDuyKLDEi+0yjqhosGlKRHaA17lBQ9a4AOuqjVP6dvLC/xbm3Z+ATDBEzYhqBCgOvLse wtTNb6/hIVQLVHPqyRQQxTmCOSxQdWU0PcLCoaWpaZfasZzRzZjmdkkzVmnt2PK7mQVDL 8GmdpRCTbZ31HMLmnnHtT5Gabz1UGQYpI0V/CZSSrzW5HG8JljCbKQ3kUllMjNhezlTzj xdyvsjAsiocMhsYMqyhZU9RsaAcN34k3JdjS1YajW1IndymlIROU0mxVcwKH1raOm6A== 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=Wx1O1+FM; arc=none smtp.remote-ip=209.85.160.41 Received: from mail-oa1-f41.google.com (mail-oa1-f41.google.com [209.85.160.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 A5D23606B3B1 for ; Thu, 22 Oct 2026 15:17:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A5D23606B3B1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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=Wx1O1+FM Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-4a77dcc4ca0so1010291fac.2 for ; Thu, 22 Oct 2026 08:17:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792682236; x=1793287036; 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=BMS/vcyNjL65g3dFxx4/6BCGx6UhCt4NMD1MWFw7eU4=; b=Wx1O1+FMyZDScU8yOmfV1Q9LgiIGBYATJsmvHDSdfQLw9D6zzhLXOL4WRUMvRWCk1N BOUparZ5VbQsgEyxbMXvQUiC9mtbfJwGARxaVpbhYWjSz5CB5eidZ726LXeO5Hk/J48x 5DTFUiVaRM19shYNGeI0PMqotn11D/oes60yH/PrzEUZZpeb9jntHVL7EkrAuuilPJ3x bA7kzxZlBuwnnXjP2clrGR2l8qNs8zCnZd2noylOWLMnNT2sBlqiHTXwyWzEPQd0j66J +T2lGLzOp0FsepD/IPAv4T9zk+JDuDd/kUxqtcZae1+UT0haTHRDw+Yz/tK/NYD5TPP6 6gXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792682236; x=1793287036; 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=BMS/vcyNjL65g3dFxx4/6BCGx6UhCt4NMD1MWFw7eU4=; b=FgZM06nNFSEqRxFTpSvZDdcyn3o2bUPMoQlFvjFEJYoFO1J7XQ0NcE/Cy1V/rDFVXh 266q7+qnC87XcP9aCmw6jMWpSeQe4FEeuntpYWZZEZlcTwNEmGuDrBONRVYzE32ai692 ywd2gCK9vOT36NVpAgTvZdi63T39TiqZzSxS8ywaDUFtvP1D+ztqBMMNtxrLd/vK9XKc 4HAWHPkqjpewAtchpaSgtVGsjv4OvG1qv+eFvuSuWyKGWM+/ETuOJHI48n85K1rJPex2 M1MDEVStYX3ia3HfPIlW2V0NF/FqgB8w81fljLiMCPDgAo/oYtUHSf3bnJyDQjAR6Fbv L+Fw== X-Forwarded-Encrypted: i=1; AKwUvBwP9pVklLZbHzv6s4oOuHWV06HnhxNrwjvDyO+LHqyo/e86Hndx13VbVYIKGudVR0logBMbiQwtQeweOi0=@vger.kernel.org X-Gm-Message-State: AFq9FYK3jSmaQsHqTBTcFWr3FAsCdmUIc7VDoHmge7uEmHQ6Tn3/dAi6 qaQGnF2wN03gImhLzvfY0QK1fhM+EYkWI6KdTTa4Ek0jSqmySoZDqGYX X-Gm-Gg: AYBFou0yOEjw5BqW2QpKiMe2kCqVvjH/OP/83VUU9uaPft18GqfK33zwvdcvaCyDuVu Idd79P7+RJaIykuoXRGbrwBByZx0A2uuAeWCmIVR5KFLOmoo2JiNhihMEFP2Wh11x2cbqUWwDkI XHZAc3SIQuL5s6wLiM0KD67jBG3v8OwdAV7ORvjqyQGjcp5ZmwPMMTpKTDCJe4c63UEI+PXtD29 jc3Aa7QCNbhcezzAFlznxKYmjbApepBQtdIr13PvgfOn8aNQRFwjny2QxDvrxL0pAf4GBaWvbxY /8Wt9WyT1h+ScibRCx0POPQ7p9/hiyKq+M6CE1L9MZr77/7cJih8ZUxFWLQ6VQohpPTg4Oij21e eahgZphWG/d78z6mrTcpMPCgXzUeZM37xeZszteQpysnlWbEFf0Rpps2qMfEfaXtAVC+R4Ok3xU Mz+MLiZJIoRhbvd5fBXotj8K7hjfEtOCLggFmZrAtG+ITcwUUgblum7VLeuIoPu6gQ8Hxh0nRbG Rx9ib1PtRwE1RdB5/4d4aedUys8OO8I6VkSG1N3gClQuJ9JJTEj82/TvY41SShJQ8fgFepJ3HZ1 n5Bnn5OoW8gx1TlPXUKX8gFkrHZOKvqGMmLihTPf2mmYeVBitMlPDRrmYsWfHqBOtYQosi+2ZQn AJ2PKhzhBm2MOsPmeoxgXXdxn4StJ303A7IUJYX3k9aJQFAGqLKheGfSLv+8HSdahOmq1oWG7Gf dehfQCdWOuI61MnohY5UR+Mrft X-Received: by 2002:a05:6870:888d:b0:49e:45d7:f3c with SMTP id 586e51a60fabf-4a7dc214264mr3893477fac.28.1792682236551; Thu, 22 Oct 2026 08:17:16 -0700 (PDT) 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.17.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 08:17:00 -0700 (PDT) From: James Hilliard Date: Thu, 22 Oct 2026 09:16:45 -0600 Subject: [PATCH net v5 5/5] ptp: vclock: preserve missing hardware timestamps X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261022-ptp-vclock-sampling-v5-5-06ceace17bac@gmail.com> References: <20261022-ptp-vclock-sampling-v5-0-06ceace17bac@gmail.com> In-Reply-To: <20261022-ptp-vclock-sampling-v5-0-06ceace17bac@gmail.com> To: netdev@vger.kernel.org, Paolo Abeni , Jakub Kicinski , Richard Cochran , Andrew Lunn , Yangbo Lu , Miroslav Lichvar Cc: Eric Dumazet , "David S. Miller" , linux-kernel@vger.kernel.org, Vadim Fedorenko , James Hilliard X-Mailer: b4 0.15.2 Socket timestamp delivery converts hardware timestamps to a bound virtual clock before checking whether a hardware timestamp is present. A zero timestamp means that the packet has no hardware timestamp, but timecounter_cyc2time() can turn that zero into a nonzero virtual time. The socket then reports a hardware timestamp which was never supplied. Return zero without conversion when the input timestamp is absent. This also covers skb_get_tx_timestamp(), which checks for an absent timestamp after the same conversion. This was identified during review of virtual clock sampling changes. Fixes: d7c088265588 ("net: socket: support hardware timestamp conversion to= PHC bound") Reviewed-by: Vadim Fedorenko Signed-off-by: James Hilliard --- drivers/ptp/ptp_vclock.c | 2 ++ include/linux/ptp_clock_kernel.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c index 4e98f119de72..b863880c0541 100644 --- a/drivers/ptp/ptp_vclock.c +++ b/drivers/ptp/ptp_vclock.c @@ -320,6 +320,8 @@ ktime_t ptp_convert_timestamp(const ktime_t *hwtstamp, = int vclock_index) u64 ns; =20 ns =3D ktime_to_ns(*hwtstamp); + if (!ns) + return 0; =20 srcu_idx =3D srcu_read_lock(&vclock_srcu); =20 diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_ker= nel.h index 36a27a910595..56f6ab1855d3 100644 --- a/include/linux/ptp_clock_kernel.h +++ b/include/linux/ptp_clock_kernel.h @@ -496,7 +496,7 @@ int ptp_get_vclocks_index(int pclock_index, int **vcloc= k_index); * @hwtstamp: timestamp * @vclock_index: phc index of ptp vclock. * - * Returns: converted timestamp, or 0 on error. + * Returns: converted timestamp, or 0 if @hwtstamp is zero or on error. */ ktime_t ptp_convert_timestamp(const ktime_t *hwtstamp, int vclock_index); #else --=20 2.53.0