> -----Original Message----- > From: Jacob Keller <[email protected]> > Sent: Friday, September 25, 2026 4:57 PM > To: Intel Wired LAN <[email protected]>; Machnikowski, Maciej > <[email protected]>; Keller, Jacob E <[email protected]>; > Korba, Przemyslaw <[email protected]>; Nguyen, Anthony L > <[email protected]>; Nitka, Grzegorz <[email protected]>; > Kubalewski, Arkadiusz <[email protected]> > Cc: Keller, Jacob E <[email protected]>; Machnikowski, Maciej > <[email protected]> > Subject: [PATCH iwl-net v3 02/15] ice: use reference counting and SRCU for > PTP port access > > The ice adapter structure maintains a list of ports associated with the > adapter. This is used for supporting PTP, where the clock owner must handle > many operations that require access to the PTP port structures of the > associated PFs. > > This is implemented using a linked list and a mutex. This sort of works, but > a few places within the code do not acquire the mutex when iterating the > list. This includes ice_ptp_flush_all_tx_tracker(), > ice_ptp_restart_all_phy(), and ice_ptp_prepare_rebuild_sec(). > > Fixing this is tricky, especially since it is not clear if we can simply > acquire the lock around the complete iterations. > > The pattern of use for the port list is read-mostly with modifications only > happening during PF initialization when elements are inserted. This typically > only happens during early boot, though a PF could in principle be removed or > loaded at arbitrary times via bind and unbind operations. > > The use of a mutex does mean the driver can sleep while holding it, but it > still creates complicates with lock ordering and prevents iterating the list > in any code path that *can't* sleep. > > Instead, use SRCU primitives for the port linked list, along with a reference > count on the port. The kref reference counter ensures that a PF will have a > valid lifetime and not be removed until the reference is released. Note that > this change focuses solely on the port list and does not make an effort to > resolve access to ctrl_pf, which is currently being investigated by another > developer. > > Use of sleepable RCU is required because we often iterate the PTP port list > and perform operations that might sleep. Attempts at implementing regular RCU > have thus far not proven to be acceptable. > > The remove path first removes the port from the list, and we use > kref_get_unless_zero to ensure that such ports are skipped when iterating the > list. This ensures that once a port starts removing we will drop references > and no longer be able to acquire new ones. This avoids loop iterations > chaining together to indefinitely block removal. > > The ice_ptp_release_port_srcu() function is used as the release function for > the kref_put() call. This uses wake_up_var() to wake the removing thread. > The waiting thread will block until the final reference has been removed, > then it will use synchronize_srcu() to ensure any outstanding SRCU critical > sections have had the necessary grace period. > > This flow ensures that accesses to ports via the adapter port list will > remain valid until both the SRCU critical sections have ended and all the > references to the ports have been dropped. Strictly speaking, SRCU alone > might be sufficient for existing code paths, but the reference count allows > the option for passing a pointer to the port on to other functions if > necessary in the future. > > Fixes: e800654e85b5 ("ice: Use ice_adapter for PTP shared data instead of > auxdev") > Reviewed-by: Maciek Machnikowski <[email protected]> > Signed-off-by: Jacob Keller <[email protected]> > --- > drivers/net/ethernet/intel/ice/ice_adapter.h | 16 ++-- > drivers/net/ethernet/intel/ice/ice_ptp.h | 4 + > drivers/net/ethernet/intel/ice/ice_adapter.c | 17 +++- > drivers/net/ethernet/intel/ice/ice_ptp.c | 121 > ++++++++++++++++++++------- > 4 files changed, 116 insertions(+), 42 deletions(-)
Tested-by: Alexander Nowlin <[email protected]>
