netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/2] ptp: safely cleanup when unregistering a PTP clock
@ 2025-09-16 21:35 Russell King (Oracle)
  2025-09-16 21:35 ` [PATCH net-next v2 1/2] ptp: describe the two disables in ptp_set_pinfunc() Russell King (Oracle)
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Russell King (Oracle) @ 2025-09-16 21:35 UTC (permalink / raw)
  To: Richard Cochran
  Cc: Ajay Kaher, Alexey Makhalov, Andrew Lunn,
	Broadcom internal kernel review list, Clark Wang, David S. Miller,
	David Woodhouse, Eric Dumazet, imx, Jakub Kicinski,
	Jonathan Lemon, netdev, Nick Shi, Paolo Abeni, Sven Schnelle,
	Vadim Fedorenko, Vladimir Oltean, Wei Fang, Yangbo Lu

(I'm assuming drivers/ptp/ patches go via net-next as there is no
git tree against the "PTP HARDWARE CLOCK SUPPORT" maintainers entry.)

The standard rule in the kernel for unregistering user visible devices
is to unpublish the userspace API before doing any shutdown of the
resources necessary for the operation of the device.

PTP has several issues in this area:

1. ptp_clock_unregister() cancells and destroys work while the PTP
   chardev is still published, which gives the opportunity for a
   precisely timed user API call to cause a driver to attempt to
   queue the aux work.

2. PTP pins are not cleaned up - if userspace has enabled PTP pins,
   e.g. for extts, drivers are forced to do cleanup before calling
   ptp_clock_unregister() to stop events being forwarded into the
   PTP layer. E.g mv88e6xxx cancells its internal tai_event_work
   to avoid calling into the PTP clock code with a stale ptp_clock
   pointer, but a badly timed userspace EXTTS enable will re-schedule
   the tai_event_work.

Simplify the process by ensuring that:

1. we take a referene on the PTP struct device to stop the
   ptp_clock structure going away underneath us when we call
   posix_clock_unregister().

2. call posix_clock_unregister() to remove the /dev/ptp* device.

3. add additional functionality to disable any PTP EXTTS pins and
   PPS event generation that have been configured on this device.
   This should shutdown all events coming from PTP clock drivers.

4. cancel the delayed aux_work and destroy the kthread.

5. remove the PPS source.

6. drop the reference on the PTP struct device to allow the
   ptp_clock structure to be released.

This is difficult for me to test beyond build testing - on the
Clearfog platform with Marvell PHY PTP, the ethernet PHY is the
primary connectivity, so removing the PHY driver for an in-use
network interface isn't possible.

On the ZII rev B platform, where the DSA switches have the TAI
hardware and where root NFS is used, removal of the DSA switch
module somehow forces the FEC interface _not_ connected to the DSA
switch to lose link, causing the machine to become unresponsive
as its root filesystem vanishes.

---
v2:
- add r-b's to patch 1
- only disable EXTTS pins
- disable PPS event generation

 drivers/ptp/ptp_chardev.c | 28 +++++++++++++++++++++++++++-
 drivers/ptp/ptp_clock.c   | 15 ++++++++++++++-
 drivers/ptp/ptp_private.h |  2 ++
 3 files changed, 43 insertions(+), 2 deletions(-)

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-09-17 22:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-16 21:35 [PATCH net-next v2 0/2] ptp: safely cleanup when unregistering a PTP clock Russell King (Oracle)
2025-09-16 21:35 ` [PATCH net-next v2 1/2] ptp: describe the two disables in ptp_set_pinfunc() Russell King (Oracle)
2025-09-16 21:36 ` [PATCH net-next v2 2/2] ptp: rework ptp_clock_unregister() to disable events Russell King (Oracle)
2025-09-17  8:38   ` Vladimir Oltean
2025-09-17 10:47   ` Vadim Fedorenko
2025-09-17 14:47 ` [PATCH net-next v2 0/2] ptp: safely cleanup when unregistering a PTP clock Richard Cochran
2025-09-17 22:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).