dpll: do not serialize driver callbacks under global dpll_lock
Subsystems (6)
Ivan Vecera
maintainerv2 cover dpll: do not serialize driver callbacks under global dpll_lock
dpll_lock protects topology and object lifetime, but it also serializes all driver callbacks in the system, so one slow device stalls every other DPLL device, whichever driver it belongs to. mlx5 callbacks issue firmware commands with a 60 s default timeout, and zl3073x callbacks can wait seconds on a driver lock held across ToD writes and phase steps.
Make dpll_lock an rwsem for topology and lifetime and add a mutex per domain for callbacks. A domain is all objects created with one (module, clock_id), in practice one chip or card, so channels of one chip stay serialized as drivers expect, and they still block each other. Device callbacks run under the domain of the device, pin callbacks under the domain of the pin, whichever driver registered them. Only one domain lock is ever held, so domains have no lock order. A lock per device would not work, because pins are N:M with devices and callbacks notify sibling channels.
The driver API does not change, but a callback can now notify only objects of its own domain. Patch 1 changes the one in-tree callback that does not follow this.
Registrations across domains exist in the tree only on E825, where ice registers fwnode pins of an external DPLL with its TXC and TSPLL DPLLs. These callbacks are no longer serialized with TXC and TSPLL, they rely on pf->dplls.lock, and requests about these pins wait while the external DPLL is busy. Intel folks, please check that this is fine.
Each complex of a dual complex E825 has its own DSN and so its own domain, but both use the CGU of complex 0. The lock for the registers they share is in a fix sent to net [1], which this series needs. Without it a test lost updates of them.
Patch 4 is the only patch that lets callbacks run concurrently. Patch 5 adds KUnit tests. I also tested each commit with a mock driver and YNL in QEMU, with lockdep and KASAN, and the tip with lockdep on two systems:
- A board with ZL30732A: every notification the driver sends from a callback, concurrent traffic with PTP, driver reload and rebind.
- GNR-D with dual complex E825 and zl3073x: callbacks of the pins shared by both drivers, TX clock switches, RCLK pins of both complexes, a port going down and up, and both drivers unloaded and loaded in either order under load.
mlx5 is build tested only.
On GNR-D, with ToD writes running on the zl3073x and requests waiting for them, requests to an ice DPLL took 1448 ms in median and 3.9 s at most before this series, 0.2 ms and 0.3 ms with it, the same as when idle. Requests about the pins shared by both drivers still wait for the zl3073x.
Changes in v2:
- Dropped "ice: dpll: serialize changes of the SyncE CGU registers", sent to net with a fix of the SyncE divider [1]
- Addressed the Sashiko review, see the patches for details
- Added Reviewed-by tags from Petr
v1: https://lore.kernel.org/netdev/[email protected]/
[1] https://lore.kernel.org/netdev/[email protected]/
Ivan Vecera (9):
ice: dpll: notify TSPLL lock status from the periodic work only
dpll: add domain object
dpll: take domain locks around driver callbacks
dpll: convert dpll_lock to rwsem
dpll: add KUnit tests for core locking
dpll: reject measured_freq_get for foreign and on-pin registrations
dpll: zl3073x: update locking comments
ice: dpll: update locking comments
dpll: document locking rules
Documentation/driver-api/dpll.rst | 48 + drivers/dpll/.kunitconfig | 5 + drivers/dpll/Kconfig | 13 + drivers/dpll/Makefile | 1 + drivers/dpll/dpll_core.c | 204 ++- drivers/dpll/dpll_core.h | 34 +- drivers/dpll/dpll_core_kunit.c | 1580 +++++++++++++++++++++ drivers/dpll/dpll_netlink.c | 117 +- drivers/dpll/zl3073x/dpll.c | 9 +- drivers/net/ethernet/intel/ice/ice_dpll.c | 24 +- drivers/net/ethernet/intel/ice/ice_dpll.h | 5 + 11 files changed, 1919 insertions(+), 121 deletions(-) create mode 100644 drivers/dpll/.kunitconfig create mode 100644 drivers/dpll/dpll_core_kunit.c
base-commit: 368fbf5d82da9ebce309449c74fc0b128f7d0219
Signature · 1 line
2.56.0
Ivan Vecera
maintainerPATCH v2 1/9 ice: dpll: notify TSPLL lock status from the periodic work only
ice_dpll_tspll_state_on_dpll_set() notifies the TSPLL device from a callback of the TIME_REF pin. This pin belongs to an external DPLL and the DPLL core is going to run its callbacks under a lock of the pin's owner, which does not cover the TSPLL device.
Only update dpll_state in the callback, so a device get reports the new state right away, and leave prev_dpll_state to ice_dpll_periodic_work_e825(), which then sends the notification. It now arrives up to 500 ms later and after the reply to the request.
Refresh dpll_state on every run of the work, as the state written by the callback can be transient and the lock status can return to prev_dpll_state before the next run. No notification is sent in this case.
---
Changes in v2:
- Merged the two comments in ice_dpll_tspll_state_on_dpll_set() (Sashiko)
--- drivers/net/ethernet/intel/ice/ice_dpll.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)
drivers/net/ethernet/intel/ice/ice_dpll.c +6 -14
@@ -2914,7 +2914,6 @@ ice_dpll_tspll_state_on_dpll_set(const struct dpll_pin *pin, void *pin_priv,struct ice_dpll_pin *p = pin_priv;struct ice_pf *pf = p->pf;enum ice_clk_src clk_src; -bool changed = false;struct ice_dpll *tp;int ret;
@@ -2939,23 +2938,16 @@ ice_dpll_tspll_state_on_dpll_set(const struct dpll_pin *pin, void *pin_priv, new_state =ice_dpll_tspll_lock_status_get (pf, false); -/* Sync the cached lock state to what we just observed from HW -* so ice_dpll_periodic_work_e825() (cached path) does not emit -* a spurious UNLOCKED notification between now and the next -* PTP monitor tick. +/* Sync the cached lock state to what we just observed from HW. +* ice_dpll_periodic_work_e825() reads it (cached path), +* compares it with prev_dpll_state and sends the notification. +* dpll_state lets a device get report it right away. */ WRITE_ONCE (pf->ptp.tspll_locked, new_state ==DPLL_LOCK_STATUS_LOCKED ); - -if (tp->prev_dpll_state != new_state) { - tp->dpll_state = new_state; - tp->prev_dpll_state = new_state; - changed = true; - } + tp->dpll_state = new_state; }mutex_unlock (&pf->dplls.lock); -if (changed) -__dpll_device_change_ntf (tp->dpll);/* TSPLL reconfiguration may complete before lock is reacquired. * PTP periodic monitoring tracks and restores the final lock state. */
@@ -3372,8 +3364,8 @@ static void ice_dpll_periodic_work_e825(struct ice_pf *pf)mutex_lock (&pf->dplls.lock); new_state =ice_dpll_tspll_lock_status_get (pf, true); + tp->dpll_state = new_state;if (tp->prev_dpll_state != new_state) { - tp->dpll_state = new_state; tp->prev_dpll_state = new_state; changed = true; }
Signature · 1 line
2.56.0
Ivan Vecera
maintainerPATCH v2 2/9 dpll: add domain object
In reply to Ivan VeceraAll dpll device and pin callbacks are serialized by the global dpll_lock, so a slow device stalls all others, whichever driver they belong to.
Add struct dpll_domain as a preparation for serializing callbacks per driver instance. A domain groups all devices and pins created with the same (module, clock_id) pair, which is in practice one chip or card. The same pair already identifies the owner of a pin in dpll_pin_own_dpll_ref_first(), which now compares the domains instead.
Domains are kept in an xarray, like devices and pins, and they live only as long as their objects.
No functional change.
---
Changes in v2:
- Moved the mutex to the next patch, which first takes it (Sashiko)
- dpll_pin_own_dpll_ref_first() compares the domains
--- drivers/dpll/dpll_core.c | 71 ++++++++++++++++++++++++++++++++++++---- drivers/dpll/dpll_core.h | 21 ++++++++++++ 2 files changed, 85 insertions(+), 7 deletions(-)
drivers/dpll/dpll_core.c +64 -7
@@ -24,6 +24,7 @@ DEFINE_MUTEX(dpll_lock);DEFINE_XARRAY_FLAGS (dpll_device_xa,XA_FLAGS_ALLOC );DEFINE_XARRAY_FLAGS (dpll_pin_xa,XA_FLAGS_ALLOC ); +static DEFINE_XARRAY_FLAGS(dpll_domain_xa, XA_FLAGS_ALLOC);static RAW_NOTIFIER_HEAD (dpll_notifier_chain);static DEFINE_IDA (dpll_pin_idx_ida);
@@ -88,6 +89,47 @@ void dpll_pin_notify(struct dpll_pin *pin, u64 src_clock_id,call_dpll_notifiers (action, &info); } +static struct dpll_domain *dpll_domain_get (u64 clock_id,struct module *module) +{ +struct dpll_domain *domain; +unsigned long i; +int ret; + +lockdep_assert_held (&dpll_lock); + +xa_for_each (&dpll_domain_xa, i, domain) { +if (domain->clock_id == clock_id && domain->module == module) { +refcount_inc (&domain->refcount); +return domain; + } + } + + domain =kzalloc_obj (*domain); +if (!domain) +return ERR_PTR (-ENOMEM ); + domain->clock_id = clock_id; + domain->module = module; +refcount_set (&domain->refcount,1 ); + ret =xa_alloc (&dpll_domain_xa, &domain->id, domain, xa_limit_32b, +GFP_KERNEL ); +if (ret) { +kfree (domain); +return ERR_PTR (ret); + } + +return domain; +} + +static void dpll_domain_put (struct dpll_domain *domain) +{ +lockdep_assert_held (&dpll_lock); + +if (refcount_dec_and_test (&domain->refcount)) { +xa_erase (&dpll_domain_xa, domain->id); +kfree (domain); + } +} +static void dpll_device_tracker_alloc (struct dpll_device *dpll,dpll_tracker *tracker) {
@@ -120,6 +162,7 @@ static void __dpll_device_put(struct dpll_device *dpll, dpll_tracker *tracker)xa_erase (&dpll_device_xa, dpll->id);WARN_ON (!list_empty (&dpll->registration_list));ref_tracker_dir_exit (&dpll->refcnt_tracker); +dpll_domain_put (dpll->domain);kfree (dpll); } }
@@ -159,6 +202,7 @@ static void __dpll_pin_put(struct dpll_pin *pin, dpll_tracker *tracker)fwnode_handle_put (pin->fwnode);dpll_pin_idx_free (pin->pin_idx);ref_tracker_dir_exit (&pin->refcnt_tracker); +dpll_domain_put (pin->domain);kfree_rcu (pin, rcu); } }
@@ -366,6 +410,12 @@ dpll_device_alloc(const u64 clock_id, u32 device_idx, struct module *module) dpll =kzalloc_obj (*dpll);if (!dpll)return ERR_PTR (-ENOMEM ); + dpll->domain =dpll_domain_get (clock_id, module); +if (IS_ERR (dpll->domain)) { + ret =PTR_ERR (dpll->domain); +kfree (dpll); +return ERR_PTR (ret); + }refcount_set (&dpll->refcount,1 );INIT_LIST_HEAD (&dpll->registration_list); dpll->device_idx = device_idx;
@@ -374,6 +424,7 @@ dpll_device_alloc(const u64 clock_id, u32 device_idx, struct module *module) ret =xa_alloc_cyclic (&dpll_device_xa, &dpll->id, dpll, xa_limit_32b, &dpll_device_xa_id,GFP_KERNEL );if (ret <0 ) { +dpll_domain_put (dpll->domain);kfree (dpll);return ERR_PTR (ret); }
@@ -664,6 +715,11 @@ dpll_pin_alloc(u64 clock_id, u32 pin_idx, struct module *module, ret =dpll_pin_prop_dup (prop, &pin->prop);if (ret) goto err_pin_prop; + pin->domain =dpll_domain_get (clock_id, module); +if (IS_ERR (pin->domain)) { + ret =PTR_ERR (pin->domain); + goto err_domain; + }refcount_set (&pin->refcount,1 );xa_init_flags (&pin->dpll_refs,XA_FLAGS_ALLOC );xa_init_flags (&pin->parent_refs,XA_FLAGS_ALLOC );
@@ -678,6 +734,8 @@ dpll_pin_alloc(u64 clock_id, u32 pin_idx, struct module *module,xa_destroy (&pin->dpll_refs);xa_destroy (&pin->parent_refs);xa_destroy (&pin->ref_sync_pins); +dpll_domain_put (pin->domain); +err_domain:dpll_pin_prop_free (&pin->prop); err_pin_prop:kfree (pin);
@@ -1156,11 +1214,11 @@ void *dpll_pin_on_pin_priv(struct dpll_pin *parent,* dpll_pin_own_dpll_ref_first - find the first owner dpll ref of a pin * @pin: pointer to a dpll pin * -* Search pin's dpll_refs for a ref whose dpll matches the pin's -* (module, clock_id) tuple, i.e. the dpll registered by the driver -* that created the pin. This ensures pin-level attributes are -* reported and modified using the owner's ops even when the pin is -* also registered with dplls from other drivers. +* Search pin's dpll_refs for a ref whose dpll belongs to the domain of +* the pin, i.e. the dpll registered by the driver that created the pin. +* This ensures pin-level attributes are reported and modified using the +* owner's ops even when the pin is also registered with dplls from other +* drivers. * * Return: pointer to the owner's dpll_pin_ref, or NULL if no * owner ref is found.
@@ -1171,8 +1229,7 @@ struct dpll_pin_ref *dpll_pin_own_dpll_ref_first(struct dpll_pin *pin)unsigned long i;xa_for_each (&pin->dpll_refs, i, ref) { -if (ref->dpll->module == pin->module && - ref->dpll->clock_id == pin->clock_id) +if (ref->dpll->domain == pin->domain)return ref; }
drivers/dpll/dpll_core.h +21 -0
@@ -15,12 +15,30 @@#define DPLL_REGISTERED XA_MARK_1 +/** +* struct dpll_domain - group of dpll objects +* @id: index of the domain in dpll_domain_xa +* @clock_id: clock_id of the objects in the domain +* @module: module of the objects in the domain +* @refcount: number of dpll devices and pins in the domain +* +* All dpll devices and pins created with the same (module, clock_id) pair +* belong to one domain, in practice to one chip or card. +**/ +struct dpll_domain { +u32 id; +u64 clock_id; +struct module *module; +refcount_t refcount; +}; +/** * struct dpll_device - stores DPLL device internal data * @id: unique id number for device given by dpll subsystem * @device_idx: id given by dev driver * @clock_id: unique identifier (clock_id) of a dpll * @module: module of creator +* @domain: domain the device belongs to * @type: type of a dpll * @pin_refs: stores pins registered within a dpll * @refcount: refcount
@@ -32,6 +50,7 @@ struct dpll_device {u32 device_idx;u64 clock_id;struct module *module; +struct dpll_domain *domain;enum dpll_type type;struct xarray pin_refs;refcount_t refcount;
@@ -46,6 +65,7 @@ struct dpll_device {* @clock_id: clock_id of creator * @module: module of creator * @module_name: module name of creator +* @domain: domain the pin belongs to * @fwnode: optional reference to firmware node * @dpll_refs: hold referencees to dplls pin was registered with * @parent_refs: hold references to parent pins pin was registered with
@@ -61,6 +81,7 @@ struct dpll_pin {u64 clock_id;struct module *module;char module_name[MODULE_NAME_LEN ]; +struct dpll_domain *domain;struct fwnode_handle *fwnode;struct xarray dpll_refs;struct xarray parent_refs;
Signature · 1 line
2.56.0
Ivan Vecera
maintainerPATCH v2 3/9 dpll: take domain locks around driver callbacks
In reply to Ivan VeceraAdd a mutex to struct dpll_domain. Hold the domain lock of the addressed object wherever driver callbacks can run:
- netlink requests addressing a device or a pin, from pre_doit to post_doit
- dumps, for each object
- notifications, while the message is being built and sent
Callbacks of a device run under the domain of the device. Callbacks of a pin run under the domain of the pin, also when another driver registered the pin with its dpll or under its parent pin. All callbacks a message about a pin needs are thus covered by one lock, and only one domain lock is ever held. Domains have no lock order, so registrations can connect them in any way.
A request is atomic against other requests addressing objects of that domain, and messages of one object are sent in the order they were built.
Requests resolving an id run no callbacks, so they do not take the lock.
__dpll_{device,pin}_change_ntf() now also require the domain lock of the object. A callback can therefore only notify objects of the domain it runs under.
Callbacks stay serialized by dpll_lock for now.
---
Changes in v2:
- Added the domain mutex here, moved from the previous patch (Sashiko)
--- drivers/dpll/dpll_core.c | 21 ++++++---- drivers/dpll/dpll_core.h | 12 +++++- drivers/dpll/dpll_netlink.c | 78 ++++++++++++++++++++++++++++--------- 3 files changed, 85 insertions(+), 26 deletions(-)
drivers/dpll/dpll_core.c +14 -7
@@ -110,9 +110,11 @@ static struct dpll_domain *dpll_domain_get(u64 clock_id, struct module *module) domain->clock_id = clock_id; domain->module = module;refcount_set (&domain->refcount,1 ); +mutex_init (&domain->lock); ret =xa_alloc (&dpll_domain_xa, &domain->id, domain, xa_limit_32b,GFP_KERNEL );if (ret) { +mutex_destroy (&domain->lock);kfree (domain);return ERR_PTR (ret); }
@@ -126,6 +128,7 @@ static void dpll_domain_put(struct dpll_domain *domain)if (refcount_dec_and_test (&domain->refcount)) {xa_erase (&dpll_domain_xa, domain->id); +mutex_destroy (&domain->lock);kfree (domain); } }
@@ -517,7 +520,7 @@ dpll_device_registration_find(struct dpll_device *dpll,* * Make dpll device available for user space. * -* Context: Acquires a lock (dpll_lock) +* Context: Acquires dpll_lock and the domain lock of @dpll * Return: * * 0 on success * * negative - error value
@@ -576,7 +579,7 @@ EXPORT_SYMBOL_GPL(dpll_device_register);* * Unregister device, make it unavailable for userspace. * Note: It does not free the memory -* Context: Acquires a lock (dpll_lock) +* Context: Acquires dpll_lock and the domain lock of @dpll */ void dpll_device_unregister (struct dpll_device *dpll,const struct dpll_device_ops *ops,void *priv)
@@ -925,7 +928,7 @@ __dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin,* @ops: ops for a dpll pin ops * @priv: pointer to private information of owner * -* Context: Acquires a lock (dpll_lock) +* Context: Acquires dpll_lock and domain locks * Return: * * 0 on success * * negative - error value
@@ -986,7 +989,9 @@ static void dpll_pin_ref_sync_pair_del(u32 ref_sync_pin_id) ref_sync_pin =xa_load (&pin->ref_sync_pins, ref_sync_pin_id);if (ref_sync_pin) {xa_erase (&pin->ref_sync_pins, ref_sync_pin_id); +mutex_lock (&pin->domain->lock);__dpll_pin_change_ntf (pin); +mutex_unlock (&pin->domain->lock); } } }
@@ -1013,7 +1018,7 @@ __dpll_pin_unregister(struct dpll_device *dpll, struct dpll_pin *pin,* @priv: pointer to private information of owner * * Note: It does not free the memory -* Context: Acquires a lock (dpll_lock) +* Context: Acquires dpll_lock and domain locks */ void dpll_pin_unregister (struct dpll_device *dpll,struct dpll_pin *pin,const struct dpll_pin_ops *ops,void *priv)
@@ -1039,7 +1044,7 @@ EXPORT_SYMBOL_GPL(dpll_pin_unregister);* Register a pin with a parent pin, create references between them and * between newly registered pin and dplls connected with a parent pin. * -* Context: Acquires a lock (dpll_lock) +* Context: Acquires dpll_lock and domain locks * Return: * * 0 on success * * negative - error value
@@ -1096,7 +1101,7 @@ EXPORT_SYMBOL_GPL(dpll_pin_on_pin_register);* @ops: ops for a dpll pin * @priv: pointer to private information of owner * -* Context: Acquires a lock (dpll_lock) +* Context: Acquires dpll_lock and domain locks * Note: It does not free the memory */ void dpll_pin_on_pin_unregister(struct dpll_pin *parent, struct dpll_pin *pin,
@@ -1126,7 +1131,7 @@ EXPORT_SYMBOL_GPL(dpll_pin_on_pin_unregister);* * Once pins are paired, the user-space configuration of reference sync pair * is possible. -* Context: Acquires a lock (dpll_lock) +* Context: Acquires dpll_lock and domain locks * Return: * * 0 on success * * negative - error value
@@ -1139,7 +1144,9 @@ int dpll_pin_ref_sync_pair_add(struct dpll_pin *pin,mutex_lock (&dpll_lock); ret =xa_insert (&pin->ref_sync_pins, ref_sync_pin->id, ref_sync_pin,GFP_KERNEL ); +mutex_lock (&pin->domain->lock);__dpll_pin_change_ntf (pin); +mutex_unlock (&pin->domain->lock);mutex_unlock (&dpll_lock);return ret;
drivers/dpll/dpll_core.h +11 -1
@@ -9,6 +9,7 @@#include <linux/dpll.h> #include <linux/list.h> +#include <linux/mutex.h> #include <linux/refcount.h> #include <linux/ref_tracker.h> #include "dpll_nl.h"
@@ -16,20 +17,29 @@#define DPLL_REGISTERED XA_MARK_1/** -* struct dpll_domain - group of dpll objects +* struct dpll_domain - group of dpll objects sharing a lock * @id: index of the domain in dpll_domain_xa * @clock_id: clock_id of the objects in the domain * @module: module of the objects in the domain * @refcount: number of dpll devices and pins in the domain +* @lock: serializes driver callbacks of the domain * * All dpll devices and pins created with the same (module, clock_id) pair * belong to one domain, in practice to one chip or card. +* +* Callbacks of a device run under the domain of the device and callbacks of a +* pin under the domain of the pin, whichever driver registered them. Only one +* domain lock is held at a time, so domains have no lock order. **/ struct dpll_domain {u32 id;u64 clock_id;struct module *module;refcount_t refcount; +/* Serializes the driver callbacks of all DPLL devices and pins +* that share one (module, clock_id) pair. +*/ +struct mutex lock; };/**
drivers/dpll/dpll_netlink.c +60 -18
204 lines not on this page · raw message
Signature · 1 line
2.56.0
Ivan Vecera
maintainerPATCH v2 4/9 dpll: convert dpll_lock to rwsem
In reply to Ivan VeceraDriver callbacks are now serialized by domain locks, so dpll_lock only has to protect the topology and lifetime of devices and pins.
Convert it to an rwsem. Core functions changing the topology take it for write. Netlink requests, each part of a dump and change notifications take it for read, for their whole duration, so objects found by a lookup stay valid. This is the patch that lets callbacks of different domains run concurrently.
A callback running for long still blocks topology changes, and a waiting writer blocks new readers, so a stuck callback stalls the subsystem while a device is being probed or removed. This is no worse than the global serialization it replaces.
---
Changes in v2:
- lockdep_assert_held_write() in dpll_domain_get() and dpll_domain_put() (Sashiko)
--- drivers/dpll/dpll_core.c | 97 +++++++++++++++++-------------------- drivers/dpll/dpll_core.h | 3 +- drivers/dpll/dpll_netlink.c | 32 ++++++------ 3 files changed, 63 insertions(+), 69 deletions(-)
drivers/dpll/dpll_core.c +45 -52
@@ -19,8 +19,12 @@#include "dpll_core.h" #include "dpll_netlink.h" -/* Mutex lock to protect DPLL subsystem devices and pins */ -DEFINE_MUTEX (dpll_lock); +/* Protects the topology and lifetime of DPLL devices and pins. Taken for write +* to change them and for read for the whole netlink request, part of a dump or +* change notification that uses them. Driver callbacks are serialized by domain +* locks, which are only taken under this lock. +*/ +DECLARE_RWSEM (dpll_lock);DEFINE_XARRAY_FLAGS (dpll_device_xa,XA_FLAGS_ALLOC );DEFINE_XARRAY_FLAGS (dpll_pin_xa,XA_FLAGS_ALLOC );
@@ -95,7 +99,7 @@ static struct dpll_domain *dpll_domain_get(u64 clock_id, struct module *module)unsigned long i;int ret; -lockdep_assert_held (&dpll_lock); +lockdep_assert_held_write (&dpll_lock);xa_for_each (&dpll_domain_xa, i, domain) {if (domain->clock_id == clock_id && domain->module == module) {
@@ -124,7 +128,7 @@ static struct dpll_domain *dpll_domain_get(u64 clock_id, struct module *module)static void dpll_domain_put (struct dpll_domain *domain) { -lockdep_assert_held (&dpll_lock); +lockdep_assert_held_write (&dpll_lock);if (refcount_dec_and_test (&domain->refcount)) {xa_erase (&dpll_domain_xa, domain->id);
@@ -459,7 +463,7 @@ dpll_device_get(u64 clock_id, u32 device_idx, struct module *module,struct dpll_device *dpll, *ret =NULL ;unsigned long index; -mutex_lock (&dpll_lock); +down_write (&dpll_lock);xa_for_each (&dpll_device_xa, index, dpll) { if (dpll->clock_id == clock_id && dpll->device_idx == device_idx &&
@@ -475,7 +479,7 @@ dpll_device_get(u64 clock_id, u32 device_idx, struct module *module,dpll_device_tracker_alloc (ret, tracker); } -mutex_unlock (&dpll_lock); +up_write (&dpll_lock);return ret; }
@@ -492,9 +496,9 @@ EXPORT_SYMBOL_GPL(dpll_device_get);*/ void dpll_device_put (struct dpll_device *dpll,dpll_tracker *tracker) { -mutex_lock (&dpll_lock); +down_write (&dpll_lock);__dpll_device_put (dpll, tracker); -mutex_unlock (&dpll_lock); +up_write (&dpll_lock); }EXPORT_SYMBOL_GPL (dpll_device_put);
@@ -540,16 +544,16 @@ int dpll_device_register(struct dpll_device *dpll, enum dpll_type type,if (WARN_ON (type <DPLL_TYPE_PPS || type >DPLL_TYPE_MAX ))return -EINVAL ; -mutex_lock (&dpll_lock); +down_write (&dpll_lock); reg =dpll_device_registration_find (dpll, ops, priv);if (reg) { -mutex_unlock (&dpll_lock); +up_write (&dpll_lock);return -EEXIST ; } reg =kzalloc_obj (*reg);if (!reg) { -mutex_unlock (&dpll_lock); +up_write (&dpll_lock);return -ENOMEM ; } reg->ops = ops;
@@ -559,13 +563,13 @@ int dpll_device_register(struct dpll_device *dpll, enum dpll_type type, first_registration =list_empty (&dpll->registration_list);list_add_tail (®->list, &dpll->registration_list);if (!first_registration) { -mutex_unlock (&dpll_lock); +up_write (&dpll_lock);return 0 ; }xa_set_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED );dpll_device_create_ntf (dpll); -mutex_unlock (&dpll_lock); +up_write (&dpll_lock);return 0 ; }
@@ -586,12 +590,12 @@ void dpll_device_unregister(struct dpll_device *dpll, {struct dpll_device_registration *reg; -mutex_lock (&dpll_lock); +down_write (&dpll_lock);ASSERT_DPLL_REGISTERED (dpll);dpll_device_delete_ntf (dpll); reg =dpll_device_registration_find (dpll, ops, priv);if (WARN_ON (!reg)) { -mutex_unlock (&dpll_lock); +up_write (&dpll_lock);return ; }list_del (®->list);
@@ -599,11 +603,11 @@ void dpll_device_unregister(struct dpll_device *dpll,kfree (reg);if (!list_empty (&dpll->registration_list)) { -mutex_unlock (&dpll_lock); +up_write (&dpll_lock);return ; }xa_clear_mark (&dpll_device_xa, dpll->id,DPLL_REGISTERED ); -mutex_unlock (&dpll_lock); +up_write (&dpll_lock); }EXPORT_SYMBOL_GPL (dpll_device_unregister);
@@ -771,9 +775,9 @@ int register_dpll_notifier(struct notifier_block *nb) {int ret; -mutex_lock (&dpll_lock); +down_write (&dpll_lock); ret =raw_notifier_chain_register (&dpll_notifier_chain, nb); -mutex_unlock (&dpll_lock); +up_write (&dpll_lock);return ret; }EXPORT_SYMBOL_GPL (register_dpll_notifier);
@@ -782,9 +786,9 @@ int unregister_dpll_notifier(struct notifier_block *nb) {int ret; -mutex_lock (&dpll_lock); +down_write (&dpll_lock); ret =raw_notifier_chain_unregister (&dpll_notifier_chain, nb); -mutex_unlock (&dpll_lock); +up_write (&dpll_lock);return ret; }EXPORT_SYMBOL_GPL (unregister_dpll_notifier);
@@ -812,7 +816,7 @@ dpll_pin_get(u64 clock_id, u32 pin_idx, struct module *module,struct dpll_pin *pos, *ret =NULL ;unsigned long i; -mutex_lock (&dpll_lock); +down_write (&dpll_lock);xa_for_each (&dpll_pin_xa, i, pos) { if (pos->clock_id == clock_id && pos->pin_idx == pin_idx &&
@@ -827,7 +831,7 @@ dpll_pin_get(u64 clock_id, u32 pin_idx, struct module *module,if (!IS_ERR (ret))dpll_pin_tracker_alloc (ret, tracker); } -mutex_unlock (&dpll_lock); +up_write (&dpll_lock);return ret; }
@@ -844,9 +848,9 @@ EXPORT_SYMBOL_GPL(dpll_pin_get);*/ void dpll_pin_put (struct dpll_pin *pin,dpll_tracker *tracker) { -mutex_lock (&dpll_lock); +down_write (&dpll_lock);__dpll_pin_put (pin, tracker); -mutex_unlock (&dpll_lock); +up_write (&dpll_lock); }EXPORT_SYMBOL_GPL (dpll_pin_put);
@@ -859,10 +863,10 @@ EXPORT_SYMBOL_GPL(dpll_pin_put);*/ void dpll_pin_fwnode_set (struct dpll_pin *pin,struct fwnode_handle *fwnode) { -mutex_lock (&dpll_lock); +down_write (&dpll_lock);fwnode_handle_put (pin->fwnode);/* Drop fwnode previously set */ pin->fwnode =fwnode_handle_get (fwnode); -mutex_unlock (&dpll_lock); +up_write (&dpll_lock); }EXPORT_SYMBOL_GPL (dpll_pin_fwnode_set);
@@ -885,7 +889,7 @@ struct dpll_pin *fwnode_dpll_pin_find(struct fwnode_handle *fwnode,struct dpll_pin *pin, *ret =NULL ;unsigned long index; -mutex_lock (&dpll_lock); +down_write (&dpll_lock);xa_for_each (&dpll_pin_xa, index, pin) {if (pin->fwnode == fwnode) {__dpll_pin_hold (pin, tracker);
@@ -893,7 +897,7 @@ struct dpll_pin *fwnode_dpll_pin_find(struct fwnode_handle *fwnode,break ; } } -mutex_unlock (&dpll_lock); +up_write (&dpll_lock);return ret; }
@@ -950,7 +954,7 @@ dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE)))return -EINVAL ; -mutex_lock (&dpll_lock); +down_write (&dpll_lock); dev_ops =dpll_device_ops (dpll); if (WARN_ON(ops->measured_freq_get &&
@@ -974,7 +978,7 @@ dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, ret =__dpll_pin_register (dpll, pin, ops, priv,NULL ); out_unlock: -mutex_unlock (&dpll_lock); +up_write (&dpll_lock);return ret; }
@@ -1028,9 +1032,9 @@ void dpll_pin_unregister(struct dpll_device *dpll, struct dpll_pin *pin,if (WARN_ON (!xa_empty (&pin->parent_refs)))return ; -mutex_lock (&dpll_lock); +down_write (&dpll_lock);__dpll_pin_unregister (dpll, pin, ops, priv,NULL ); -mutex_unlock (&dpll_lock); +up_write (&dpll_lock); }EXPORT_SYMBOL_GPL (dpll_pin_unregister);
@@ -1064,7 +1068,7 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin, WARN_ON(!ops->direction_get))return -EINVAL ; -mutex_lock (&dpll_lock); +down_write (&dpll_lock); ret =dpll_xa_ref_pin_add (&pin->parent_refs, parent, ops, priv, pin);if (ret) goto unlock;
@@ -1076,7 +1080,7 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin, }dpll_pin_create_ntf (pin, parent->clock_id); } -mutex_unlock (&dpll_lock); +up_write (&dpll_lock);return ret;
@@ -1089,7 +1093,7 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin, }dpll_xa_ref_pin_del (&pin->parent_refs, parent, ops, priv, pin); unlock: -mutex_unlock (&dpll_lock); +up_write (&dpll_lock);return ret; }EXPORT_SYMBOL_GPL (dpll_pin_on_pin_register);
@@ -1111,7 +1115,7 @@ void dpll_pin_on_pin_unregister(struct dpll_pin *parent, struct dpll_pin *pin,struct dpll_pin_ref *ref;unsigned long i; -mutex_lock (&dpll_lock); +down_write (&dpll_lock);xa_for_each (&pin->dpll_refs, i, ref) { reg =dpll_pin_registration_find (ref, ops, priv, parent);if (!reg)
@@ -1120,7 +1124,7 @@ void dpll_pin_on_pin_unregister(struct dpll_pin *parent, struct dpll_pin *pin,__dpll_pin_unregister (ref->dpll, pin, ops, priv, parent); }dpll_xa_ref_pin_del (&pin->parent_refs, parent, ops, priv, pin); -mutex_unlock (&dpll_lock); +up_write (&dpll_lock); }EXPORT_SYMBOL_GPL (dpll_pin_on_pin_unregister);
@@ -1141,13 +1145,13 @@ int dpll_pin_ref_sync_pair_add(struct dpll_pin *pin, {int ret; -mutex_lock (&dpll_lock); +down_write (&dpll_lock); ret =xa_insert (&pin->ref_sync_pins, ref_sync_pin->id, ref_sync_pin,GFP_KERNEL );mutex_lock (&pin->domain->lock);__dpll_pin_change_ntf (pin);mutex_unlock (&pin->domain->lock); -mutex_unlock (&dpll_lock); +up_write (&dpll_lock);return ret; }
@@ -1253,23 +1257,12 @@ const struct dpll_pin_ops *dpll_pin_ops(struct dpll_pin_ref *ref)static int __init dpll_init (void ) { -int ret; - - ret =genl_register_family (&dpll_nl_family); -if (ret) - goto error; - -return 0 ; - -error: -mutex_destroy (&dpll_lock); -return ret; +return genl_register_family (&dpll_nl_family); } static void __exit dpll_exit(void) {genl_unregister_family (&dpll_nl_family); -mutex_destroy (&dpll_lock); }subsys_initcall (dpll_init);
drivers/dpll/dpll_core.h +2 -1
@@ -12,6 +12,7 @@#include <linux/mutex.h> #include <linux/refcount.h> #include <linux/ref_tracker.h> +#include <linux/rwsem.h> #include "dpll_nl.h" #define DPLL_REGISTERED XA_MARK_1
@@ -129,7 +130,7 @@ const struct dpll_pin_ops *dpll_pin_ops(struct dpll_pin_ref *ref);struct dpll_pin_ref *dpll_xa_ref_dpll_first (struct xarray *xa_refs);extern struct xarray dpll_device_xa;extern struct xarray dpll_pin_xa; -extern struct mutex dpll_lock; +extern struct rw_semaphore dpll_lock;void dpll_device_notify (struct dpll_device *dpll,unsigned long action); void dpll_pin_notify(struct dpll_pin *pin, u64 src_clock_id,
drivers/dpll/dpll_netlink.c +16 -16
@@ -910,11 +910,11 @@ int dpll_device_change_ntf(struct dpll_device *dpll) {int ret; -mutex_lock (&dpll_lock); +down_read (&dpll_lock);mutex_lock (&dpll->domain->lock); ret =__dpll_device_change_ntf (dpll);mutex_unlock (&dpll->domain->lock); -mutex_unlock (&dpll_lock); +up_read (&dpll_lock);return ret; }
@@ -1004,11 +1004,11 @@ int dpll_pin_change_ntf(struct dpll_pin *pin) {int ret; -mutex_lock (&dpll_lock); +down_read (&dpll_lock);mutex_lock (&pin->domain->lock); ret =__dpll_pin_change_ntf (pin);mutex_unlock (&pin->domain->lock); -mutex_unlock (&dpll_lock); +up_read (&dpll_lock);return ret; }
@@ -1795,7 +1795,7 @@ int dpll_nl_pin_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)unsigned long i;int ret =0 ; -mutex_lock (&dpll_lock); +down_read (&dpll_lock);xa_for_each_marked_start (&dpll_pin_xa, i, pin,DPLL_REGISTERED , ctx->idx) {if (!dpll_pin_available (pin))
@@ -1821,7 +1821,7 @@ int dpll_nl_pin_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) }genlmsg_end (skb, hdr); } -mutex_unlock (&dpll_lock); +up_read (&dpll_lock);if (ret == -EMSGSIZE ) { ctx->idx = i;
@@ -2019,7 +2019,7 @@ int dpll_nl_device_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)unsigned long i;int ret =0 ; -mutex_lock (&dpll_lock); +down_read (&dpll_lock);xa_for_each_marked_start (&dpll_device_xa, i, dpll,DPLL_REGISTERED , ctx->idx) { hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
@@ -2038,7 +2038,7 @@ int dpll_nl_device_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) }genlmsg_end (skb, hdr); } -mutex_unlock (&dpll_lock); +up_read (&dpll_lock);if (ret == -EMSGSIZE ) { ctx->idx = i;
@@ -2056,7 +2056,7 @@ int dpll_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb,if (GENL_REQ_ATTR_CHECK (info,DPLL_A_ID ))return -EINVAL ; -mutex_lock (&dpll_lock); +down_read (&dpll_lock); id =nla_get_u32 (info->attrs[DPLL_A_ID ]); dpll =dpll_device_get_by_id (id);if (!dpll) {
@@ -2067,7 +2067,7 @@ int dpll_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb,mutex_lock (&dpll->domain->lock);return 0 ; unlock: -mutex_unlock (&dpll_lock); +up_read (&dpll_lock);return -ENODEV ; }
@@ -2077,14 +2077,14 @@ void dpll_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb,struct dpll_device *dpll = info->user_ptr[0 ];mutex_unlock (&dpll->domain->lock); -mutex_unlock (&dpll_lock); +up_read (&dpll_lock); }int dpll_lock_doit (const struct genl_split_ops *ops,struct sk_buff *skb,struct genl_info *info) { -mutex_lock (&dpll_lock); +down_read (&dpll_lock);return 0 ; }
@@ -2093,7 +2093,7 @@ void dpll_unlock_doit(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info) { - mutex_unlock(&dpll_lock); + up_read(&dpll_lock); } int dpll_pin_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb,
@@ -2102,7 +2102,7 @@ int dpll_pin_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb,struct dpll_pin *pin;int ret; -mutex_lock (&dpll_lock); +down_read (&dpll_lock);if (GENL_REQ_ATTR_CHECK (info,DPLL_A_PIN_ID )) { ret = -EINVAL ; goto unlock_dev;
@@ -2119,7 +2119,7 @@ int dpll_pin_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb,return 0 ; unlock_dev: -mutex_unlock (&dpll_lock); +up_read (&dpll_lock);return ret; }
@@ -2129,5 +2129,5 @@ void dpll_pin_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb,struct dpll_pin *pin = info->user_ptr[0 ];mutex_unlock (&pin->domain->lock); -mutex_unlock (&dpll_lock); +up_read (&dpll_lock); }
Signature · 1 line
2.56.0
Ivan Vecera
maintainerRe: [PATCH net-next v2 4/9] dpll: convert dpll_lock to rwsem
Sashiko reviewed v2 only on its dashboard [1], with low severity findings, so I am answering them here.
[1] https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111164021.273409-1-ivecera%40redhat.com
Quoted 3 lines
This isn't a bug, but
zl3073x_dpll_input_pin_ref_sync_set()indrivers/dpll/zl3073x/dpll.cstill uses the old global serialization to justify droppingzldpll->lock:
[...]
Quoted 4 lines
Could this comment be updated in this patch, along with the
dpll_lockreference inzl3073x_dpll_changes_check()? The later patch "dpll:
zl3073x: update locking comments" rewrites both. The stale comment only exists between this patch and that one.
Right, both comments are stale between this patch and patch 7, which rewrites them. The code is correct at every commit, because all channels of a chip share one domain. The new comments hold from patch 3 on, so if a respin is needed, I will move patch 7 before this one.
Quoted 3 lines
Pin requests now run with
dpll_lockheld for read andpin->domain->lock. Take a fwnode pin registered on a DPLL from a different domain. Can that DPLL's device callbacks now run without its own domain lock?
[...]
Quoted 2 lines
Would it be better to put that check in before this conversion, or in the same patch, so this gap never exists?
Right, between this patch and patch 6 nothing rejects such a registration. As you note, no in-tree driver registers a pin of another domain with .measured_freq_get, so no commit of the series can hit it with in-tree drivers. If a respin is needed, I will move the check of patch 6 before this patch and keep its tests in the KUnit patch.
Thanks,
Ivan
Ivan Vecera
maintainerPATCH v2 5/9 dpll: add KUnit tests for core locking
In reply to Ivan VeceraAdd KUnit tests using a mock driver with unrelated domains, a pin of one domain registered with a dpll of another and a pin of one domain under a MUX pin of another. They check that:
- objects with the same (module, clock_id) share a refcounted domain
- callbacks of a device run under its domain and callbacks of a pin under the domain of the pin alone, whichever driver registered them
- a callback blocked in one domain does not stop unrelated domains
- callbacks of one domain are serialized, also across its devices
- a stuck callback of a foreign registration stops only the domain of the pin, and a stuck foreign device or domain of the pin does not stop the other side
- a pin and its parent pin of another domain do not block each other
- registrations can connect two domains in both directions
- a topology change waits until running requests finish
- a request setting several attributes of a pin is atomic against other requests about the pin, also when it spans two domains
- notifications from callbacks keep their order, also when a callback fails
Requests that can block run in kthreads, so a test can report a locking bug instead of blocking itself. A real deadlock cannot be undone, the stuck request keeps its locks, so the teardown then hangs until the run times out. The handlers are called directly with a hand-built message, so they are exported for KUnit.
Only lockdep can tell which locks a callback holds. Without it the checks of held locks cannot fail, so the test that checks nothing else is skipped. The tests of what blocks what do not depend on it.
The tests do not cover what needs a netlink socket, for example the order of notifications against the ACK or the content of messages.
Run them with:
tools/testing/kunit/kunit.py run --kunitconfig=drivers/dpll
---
Changes in v2:
- Used kunit_fwnode_create_software_node() (Sashiko)
- Released blocked callbacks in the exit callback of the suite, so a test aborted before its request is set up cannot hang the teardown (Sashiko)
--- drivers/dpll/.kunitconfig | 5 + drivers/dpll/Kconfig | 13 + drivers/dpll/Makefile | 1 + drivers/dpll/dpll_core_kunit.c | 1478 ++++++++++++++++++++++++++++++++ drivers/dpll/dpll_netlink.c | 7 + 5 files changed, 1504 insertions(+) create mode 100644 drivers/dpll/.kunitconfig create mode 100644 drivers/dpll/dpll_core_kunit.c
drivers/dpll/.kunitconfig new file +5 -0
@@ -0,0 +1,5 @@ +CONFIG_KUNIT=y +CONFIG_NET=y +CONFIG_DPLL_KUNIT_TEST=y +CONFIG_DEBUG_KERNEL=y +CONFIG_PROVE_LOCKING=y
drivers/dpll/Kconfig +13 -0
@@ -23,6 +23,19 @@ config DPLL_REFCNT_TRACKER If unsure, say N. +config DPLL_KUNIT_TEST + tristate "KUnit tests for DPLL core" if !KUNIT_ALL_TESTS + depends on KUNIT && NET + select DPLL + default KUNIT_ALL_TESTS + help + KUnit tests for locking in the DPLL core. They use a mock driver + to check that callbacks run under the locks of their domains and + that unrelated domains do not block each other. The checks of held + locks need PROVE_LOCKING. + + If unsure, say N. + source "drivers/dpll/zl3073x/Kconfig" endmenu
drivers/dpll/Makefile +1 -0
@@ -8,4 +8,5 @@ dpll-y += dpll_core.o dpll-y += dpll_netlink.o dpll-y += dpll_nl.o +obj-$(CONFIG_DPLL_KUNIT_TEST) += dpll_core_kunit.o obj-$(CONFIG_ZL3073X) += zl3073x/
drivers/dpll/dpll_core_kunit.c new file +1478 -0
1,478 lines not on this page · raw message
drivers/dpll/dpll_netlink.c +7 -0
@@ -6,6 +6,7 @@* Copyright (c) 2023 Intel and affiliates * */ +#include <kunit/visibility.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/netdevice.h>
@@ -1836,6 +1837,7 @@ int dpll_nl_pin_set_doit(struct sk_buff *skb, struct genl_info *info)return dpll_pin_set_from_nlattr (pin, info); } +EXPORT_SYMBOL_IF_KUNIT (dpll_nl_pin_set_doit);static struct dpll_device * dpll_device_find(u64 clock_id, struct nlattr *mod_name_attr,
@@ -2010,6 +2012,7 @@ int dpll_nl_device_set_doit(struct sk_buff *skb, struct genl_info *info)return dpll_set_from_nlattr (dpll, info); } +EXPORT_SYMBOL_IF_KUNIT (dpll_nl_device_set_doit);int dpll_nl_device_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb) {
@@ -2070,6 +2073,7 @@ int dpll_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb,up_read (&dpll_lock);return -ENODEV ; } +EXPORT_SYMBOL_IF_KUNIT (dpll_pre_doit);void dpll_post_doit (const struct genl_split_ops *ops,struct sk_buff *skb,struct genl_info *info)
@@ -2079,6 +2083,7 @@ void dpll_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb,mutex_unlock (&dpll->domain->lock);up_read (&dpll_lock); } +EXPORT_SYMBOL_IF_KUNIT (dpll_post_doit); int dpll_lock_doit(const struct genl_split_ops *ops, struct sk_buff *skb,
@@ -2122,6 +2127,7 @@ int dpll_pin_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb,up_read (&dpll_lock);return ret; } +EXPORT_SYMBOL_IF_KUNIT (dpll_pin_pre_doit);void dpll_pin_post_doit (const struct genl_split_ops *ops,struct sk_buff *skb,struct genl_info *info)
@@ -2131,3 +2137,4 @@ void dpll_pin_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb,mutex_unlock (&pin->domain->lock);up_read (&dpll_lock); } +EXPORT_SYMBOL_IF_KUNIT (dpll_pin_post_doit);
Signature · 1 line
2.56.0
Ivan Vecera
maintainerPATCH v2 6/9 dpll: reject measured_freq_get for foreign and on-pin registrations
In reply to Ivan VeceraA message about a pin with .measured_freq_get calls .freq_monitor_get of a dpll of the pin. For a pin of another domain, this device callback would run outside the domain of the dpll, so dpll_pin_register() now rejects such ops.
dpll_pin_on_pin_register() checks nothing about them. The message would call .freq_monitor_get with no NULL check, on a dpll of the parent pin that can belong to another driver, so reject them there as well.
No in-tree driver passes such ops. Add KUnit tests: the ops work on a dpll of the domain of the pin, and are rejected on a dpll of another domain and under a parent pin.
---
No changes since v1
--- drivers/dpll/dpll_core.c | 6 +- drivers/dpll/dpll_core_kunit.c | 112 +++++++++++++++++++++++++++++++-- 2 files changed, 111 insertions(+), 7 deletions(-)
drivers/dpll/dpll_core.c +4 -2
@@ -958,7 +958,8 @@ dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin, dev_ops =dpll_device_ops (dpll);if (WARN_ON (ops->measured_freq_get && - (!dev_ops || !dev_ops->freq_monitor_get || + (pin->domain != dpll->domain || !dev_ops || + !dev_ops->freq_monitor_get || !dev_ops->freq_monitor_set))) { ret = -EINVAL ; goto out_unlock;
@@ -1065,7 +1066,8 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent, struct dpll_pin *pin,if (WARN_ON (!ops) ||WARN_ON (!ops->state_on_pin_get) || -WARN_ON (!ops->direction_get)) +WARN_ON (!ops->direction_get) || +WARN_ON (ops->measured_freq_get))return -EINVAL ;down_write (&dpll_lock);
drivers/dpll/dpll_core_kunit.c +107 -5
169 lines not on this page · raw message
Signature · 1 line
2.56.0
Ivan Vecera
maintainerPATCH v2 7/9 dpll: zl3073x: update locking comments
In reply to Ivan VeceraCallbacks are serialized by the DPLL core domain lock instead of dpll_lock. All channels of a chip belong to one domain, so what the comments rely on still holds.
---
No changes since v1
--- drivers/dpll/zl3073x/dpll.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/dpll/zl3073x/dpll.c +5 -4
@@ -349,9 +349,10 @@ zl3073x_dpll_input_pin_ref_sync_set(const struct dpll_pin *dpll_pin,if (rc) goto unlock; -/* All code paths accessing per-channel reference priorities are -* serialized by the subsystem dpll_lock, so it is safe to release -* our lock here before iterating over the other channels. +/* All callbacks accessing per-channel reference priorities are +* serialized by the DPLL core domain lock shared by all channels of +* the chip, so it is safe to release our lock here before iterating +* over the other channels. */ mutex_unlock (&zldpll->lock);
@@ -2401,7 +2402,7 @@ zl3073x_dpll_changes_check(struct zl3073x_dpll *zldpll)mutex_unlock (&zldpll->lock);/* Send notifications outside the lock to avoid ABBA deadlock -* with dpll_lock taken by notification functions. +* with the DPLL core domain lock taken by notification functions. */ if (dev_changed)dpll_device_change_ntf (zldpll->dpll_dev);
Signature · 1 line
2.56.0
Ivan Vecera
maintainerPATCH v2 8/9 ice: dpll: update locking comments
In reply to Ivan VeceraCallbacks run under the DPLL core domain locks instead of dpll_lock. On E825 the TXC DPLL, the TSPLL DPLL and the other objects of a PF are in three domains, and callbacks of pins of an external DPLL run under the domain of that DPLL, so only pf->dplls.lock serializes them with each other.
---
Changes in v2:
- Described the three domains of an E825 PF (Sashiko)
--- drivers/net/ethernet/intel/ice/ice_dpll.c | 4 ++-- drivers/net/ethernet/intel/ice/ice_dpll.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_dpll.c +2 -2
@@ -1178,8 +1178,8 @@ ice_dpll_input_state_get(const struct dpll_pin *pin, void *pin_priv,* peer via dpll netlink learn about the update. * * Context: Called from dpll_pin_ops callbacks after pf->dplls.lock is -* released. Uses __dpll_pin_change_ntf() because dpll_lock is -* still held by the dpll netlink layer. +* released. Uses __dpll_pin_change_ntf() because the domain lock +* is still held by the dpll core. */ static void ice_dpll_sw_pin_notify_peer (struct ice_dplls *d,struct ice_dpll_pin *changed)
drivers/net/ethernet/intel/ice/ice_dpll.h +5 -0
@@ -164,6 +164,11 @@ struct ice_dpll {* tx_refclks usage map), acquire pf->dplls.lock first, then * ctrl_pf->dplls.lock. Skip the second acquire when pf == ctrl_pf * to avoid recursive locking. +* - The DPLL core serializes callbacks per (module, clock_id) domain. On +* E825 the TXC DPLL, the TSPLL DPLL and the other objects of a PF, such +* as the RCLK pin, use three different clock_ids, and callbacks of the +* SYNCE and TIME_REF pins of an external DPLL run under the domain of +* that DPLL, so only @lock serializes all of them with each other. * - @txclk_notify_rwsem is held for read across * ice_txclk_update_and_notify(), including the out-of-lock * dpll_*_change_ntf() calls. ice_dpll_deinit() takes the write side
Signature · 1 line
2.56.0
Ivan Vecera
maintainerRe: [PATCH net-next v2 8/9] ice: dpll: update locking comments
Sashiko reviewed v2 only on its dashboard [1], with a low severity finding, so I am answering it here.
[1] https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111164021.273409-1-ivecera%40redhat.com
Quoted 1 line
Is "use three different
clock_ids" always true on E825?
[...]
Quoted 3 lines
The conclusion that only @lock serializes everything still holds, since fewer domains only add serialization. Could the text say "up to three different
clock_ids" or "may use differentclock_ids" instead?
Right, it is up to three. Only the PF that owns the source timer has the TSPLL DPLL, and without a valid permanent MAC the TXC DPLL uses pf->dplls.clock_id as well. The conclusion holds, as you say. I will change it to "can use different clock_ids" in a respin or a follow-up.
Thanks,
Ivan
Ivan Vecera
maintainerPATCH v2 9/9 dpll: document locking rules
In reply to Ivan VeceraDescribe the lock levels of the subsystem, which domain a callback runs under and the rules device drivers have to follow.
---
Changes in v2:
- Added a rule for reference sync pairs (Sashiko)
- Rules 1 and 3 also forbid waiting for a work item that notifies (Sashiko)
--- Documentation/driver-api/dpll.rst | 48 +++++++++++++++++++++++++++++++ drivers/dpll/dpll_core.c | 13 +++++++++ 2 files changed, 61 insertions(+)
Documentation/driver-api/dpll.rst +48 -0
@@ -675,6 +675,54 @@ In the error path we have to rewind every allocation in the reverse order: More complex example can be found in Intel's ICE driver or nVidia's mlx5 driver. +Locking +======= + +The subsystem uses two levels of locks, always taken in this order: + +- ``dpll_lock`` protects the topology of dpll devices and pins and their + lifetime. Functions changing the topology, for example dpll_pin_register(), + take it for write and send the create and delete notifications under it. + Netlink requests, each part of a dump and change notifications take it for + read for their whole duration. +- A domain lock serializes driver callbacks. All dpll devices and pins created + with the same module and ``clock_id`` belong to one domain, in practice to + one chip or card. + +A netlink request addressing a device or a pin by its ID holds the domain lock +of that object from start to end. A notification holds it while its message is +built and sent, so messages of one object are sent in the order they were +built. Only one domain lock is held at a time, so domains have no lock order, +and callbacks of different domains can run concurrently. + +Callbacks of a dpll device run under the domain of the device. Callbacks of a +pin run under the domain of the pin, whichever driver registered them: + +- A driver registering a pin of another driver with its dpll device has these + callbacks serialized with the driver that created the pin, not with the other + callbacks of its device, so it has to protect the state they share by itself. + A callback stuck in such a registration stops the domain of the pin. +- The parent pin of a pin registered with dpll_pin_on_pin_register() and its + dpll devices can belong to another driver, so the callback must not + dereference their private data. +- The frequency monitor belongs to the dpll device, so only callbacks of a pin + of the same domain registered with dpll_pin_register() can include + ``.measured_freq_get``. +- The reference sync callbacks of a pin get the private data of the other pin + of the pair, so both pins of a pair added by dpll_pin_ref_sync_pair_add() + have to belong to one domain. + +Device drivers have to follow these rules: + +- A callback must not call dpll_device_change_ntf(), dpll_pin_change_ntf() or + any function changing the topology, nor wait for a work item that calls them. +- A callback notifies about objects of the domain it runs under with + __dpll_device_change_ntf() or __dpll_pin_change_ntf(). Other objects have to + be notified from a context that holds no domain lock, for example a work item. +- A driver must not call dpll_device_change_ntf(), dpll_pin_change_ntf() or any + function changing the topology, nor wait for a work item that calls them, + while holding a lock that its callbacks take. + SyncE enablement ================ For SyncE enablement it is required to allow control over dpll device
drivers/dpll/dpll_core.c +13 -0
@@ -932,6 +932,10 @@ __dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin,* @ops: ops for a dpll pin ops * @priv: pointer to private information of owner * +* The callbacks run under the domain of @pin. If @pin belongs to another domain +* than @dpll, they are not serialized with the callbacks of @dpll and @ops must +* not include .measured_freq_get. +* * Context: Acquires dpll_lock and domain locks * Return: * * 0 on success
@@ -1049,6 +1053,11 @@ EXPORT_SYMBOL_GPL(dpll_pin_unregister);* Register a pin with a parent pin, create references between them and * between newly registered pin and dplls connected with a parent pin. * +* The callbacks run under the domain of @pin. The parent pin and its dplls can +* belong to another driver, so @ops must not dereference their private data. +* The frequency monitor belongs to a dpll, so @ops must not include +* .measured_freq_get. +* * Context: Acquires dpll_lock and domain locks * Return: * * 0 on success
@@ -1137,6 +1146,10 @@ EXPORT_SYMBOL_GPL(dpll_pin_on_pin_unregister);* * Once pins are paired, the user-space configuration of reference sync pair * is possible. +* +* The reference sync callbacks of each pin get the private data of the other +* one, so both pins must belong to one domain. +* * Context: Acquires dpll_lock and domain locks * Return: * * 0 on success
Signature · 1 line
2.56.0
Ivan Vecera
maintainerRe: [PATCH net-next v2 9/9] dpll: document locking rules
Sashiko reviewed v2 only on its dashboard [1], with low severity findings, so I am answering them here.
[1] https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111164021.273409-1-ivecera%40redhat.com
Quoted 3 lines
Is this rule broad enough? Several other exported functions in
drivers/dpll/dpll_core.calso takedpll_lockfor write, and most of them do not change the topology:
[...]
Quoted 3 lines
Would it make sense to say that these contexts must not call any exported dpll function that takes
dpll_lock(everything except the __ prefixed notifiers), or to list these functions?
Yes. Every exported dpll function except the __ prefixed notifiers and the netdev pin helpers takes dpll_lock, and rules 1 and 3 should cover all of them. This is not new: on main, a callback calling fwnode_dpll_pin_find() deadlocks on the dpll_lock mutex the same way. I will widen both rules in a follow-up, or in v3 if one is needed.
Quoted 3 lines
Should this section also describe the context of in-kernel notifier callbacks registered with
register_dpll_notifier()? The rules only cover ops callbacks and driver code.
[...]
Quoted 2 lines
Today
ice_dpll_pin_notify()handles this correctly. It only allocates the work and queues it:
[...]
Quoted 2 lines
The dpll calls are then made from
ice_dpll_pin_notify_work(). Could this requirement be stated in the new rules as well?
Yes. Notifier callbacks run under dpll_lock, and with this series also under the domain lock of the notified object, which can belong to another driver. They have to follow the rules of a callback, and a driver must not hold a lock they take while calling a function that takes dpll_lock. I will add both to the same follow-up.
Thanks,
Ivan
Ivan Vecera
maintainerHi Jakub/Paolo,
v2 no longer applies to net-next since net was merged in. It conflicts with 7a3837929d04 ("dpll: notify about a reference sync pair only if it was added") in dpll_pin_ref_sync_pair_add(). Patches 3 and 4 fail on the same lines and the rest applies cleanly. After patch 4 the resolution is:
down_write(&dpll_lock);
ret = xa_insert(&pin->ref_sync_pins, ref_sync_pin->id,
ref_sync_pin, GFP_KERNEL);
if (!ret) {
mutex_lock(&pin->domain->lock);
__dpll_pin_change_ntf(pin);
mutex_unlock(&pin->domain->lock);
}
up_write(&dpll_lock);Patch 3 is the same, with mutex_lock() and mutex_unlock() of dpll_lock. KUnit passes on the result. The SyncE CGU fix that the series needs [1] is in net-next as well.
Sashiko found only low severity issues, I answered them in the replies to patches 4, 8 and 9. Would you resolve the conflict when applying and take the fixes of those issues as a follow-up, or do you prefer a v3 rebased on net-next with them fixed?
Thanks,
Ivan
Jakub Kicinski
maintainerQuoted 5 lines · On Mon, 16 Nov 2026 09:24:39 +0100 Ivan Vecera wrote:
v2 no longer applies to net-next since net was merged in. It conflicts with
7a3837929d04("dpll: notify about a reference sync pair only if it was added") indpll_pin_ref_sync_pair_add(). Patches 3 and 4 fail on the same lines and the rest applies cleanly. After patch 4 the resolution is:
What makes you think we'd rebase your patches for you?
Signature · 1 line
pw-bot: cr
Ivan Vecera
maintainerQuoted 8 lines · Jakub Kicinski
Quoted 5 lines · On Mon, 16 Nov 2026 09:24:39 +0100 Ivan Vecera wrote:
v2 no longer applies to net-next since net was merged in. It conflicts with
7a3837929d04("dpll: notify about a reference sync pair only if it was added") indpll_pin_ref_sync_pair_add(). Patches 3 and 4 fail on the same lines and the rest applies cleanly. After patch 4 the resolution is:What makes you think we'd rebase your patches for you?
Sorry, that came out wrong. I wanted to flag the conflict with the fix from net, not to hand the rebase to you. I will send v3 rebased on net-next once the questions in your other reply are settled.
Thanks,
Ivan
Jakub Kicinski
maintainerQuoted 5 lines · On Wed, 11 Nov 2026 17:40:11 +0100 Ivan Vecera wrote:
dpll_lockprotects topology and object lifetime, but it also serializes all driver callbacks in the system, so one slow device stalls every other DPLL device, whichever driver it belongs to. mlx5 callbacks issue firmware commands with a 60 s default timeout, and zl3073x callbacks can wait seconds on a driver lock held across ToD writes and phase steps.
Can you provide some real life data of how much this actually helps? Real device topology + scenario you hit?
For the cross-domain pins - shouldn't we stretch the domain to cover all interconnected objects on the system instead of hoping people get lock ordering right? You documented some rules in the doc, admittedly, but not sure how enforceable and practical they are.
Ivan Vecera
maintainerQuoted 9 lines · Jakub Kicinski
Quoted 5 lines · On Wed, 11 Nov 2026 17:40:11 +0100 Ivan Vecera wrote:
dpll_lockprotects topology and object lifetime, but it also serializes all driver callbacks in the system, so one slow device stalls every other DPLL device, whichever driver it belongs to. mlx5 callbacks issue firmware commands with a 60 s default timeout, and zl3073x callbacks can wait seconds on a driver lock held across ToD writes and phase steps.Can you provide some real life data of how much this actually helps? Real device topology + scenario you hit?
The system is GNR-D with a dual complex E825 and a ZL30732 on the board. The zl3073x has its own PHC, takes the recovered clocks of the E825 ports and feeds the TX and time reference clocks of the E825. Each ice PF connects to the zl3073x like this:
+------------------------- zl3073x --------------------------+
| EEC DPLL, PPS DPLL |
| |
| input pin output pin |
| (recovered clock of E825) 156M25_NAC0_CLKREF_SYNC |
+-------^---------------------------------|------------------+
| parent pin | registered with
| dpll_pin_on_pin_register() | dpll_pin_register()
+-------|---------------------------------v------------------+
| RCLK pin TXC DPLL |
+------------------------- ice PF ---------------------------+The PF owning the source timer also registers the zl3073x output pin 156M25_NAC0_TIMEREF_SYNC with its TSPLL DPLL.
A step of the zl3073x PHC, which ptp4l and ts2phc do at start and after a large offset, waits for the next 1 PPS edge, up to 1 s, with the channel lock held. A phase step can hold it for up to 3 s while it waits for the previous one. A dpll callback of that channel waits for the lock under dpll_lock, and every other DPLL request and notification in the system waits behind it. With ToD writes running, requests to an ice DPLL took 1448 ms in median and 3.9 s at most. With the series they took 0.2 ms and 0.3 ms, the same as idle.
The bigger reason are zl3073x callbacks we are working on, which have to wait for the hardware themselves:
- a device reset with resync waits for the fast lock, up to 1 s with a 1 PPS input
- a glitchless stop or start of an output completes on an output edge, so it takes up to one period, 1 s for a 1 PPS output
Holding the global dpll_lock for that long would stall every DPLL device in the system. For the output state we tried an asynchronous implementation, but then the callback returns success before it knows the result. A failure can only be reported by a later notification, and the next request gets -EBUSY until the change completes. With a lock per chip the callback can simply wait, and one chip cannot do these operations in parallel anyway.
Quoted 4 lines
For the cross-domain pins - shouldn't we stretch the domain to cover all interconnected objects on the system instead of hoping people get lock ordering right? You documented some rules in the doc, admittedly, but not sure how enforceable and practical they are.
Stretching the domains would not improve anything here. The only in-tree registrations across domains are the ones in the diagram above, and every PF connects to the zl3073x, so the zl3073x and all ice PFs would end up in one domain. The system above would then stall the same way as with the global lock.
There is no lock ordering to get right. Only one domain lock is ever held and all of them share one lockdep class, so any nesting is reported. __dpll_{device,pin}_change_ntf() assert the domain lock of the object, so a callback notifying an object of another domain is reported as well. The rule that a callback must not call functions taking dpll_lock holds on main already. What lockdep cannot check is that a driver registering a pin of another driver protects the state these callbacks share with its own ones. ice is the only such driver and uses pf->dplls.lock for it.
Thanks,
Ivan
Jakub Kicinski
maintainerQuoted 17 lines · On Wed, 18 Nov 2026 16:29:23 +0100 Ivan Vecera wrote:
A step of the zl3073x PHC, which ptp4l and ts2phc do at start and after a large offset, waits for the next 1 PPS edge, up to 1 s, with the channel lock held. A phase step can hold it for up to 3 s while it waits for the previous one. A dpll callback of that channel waits for the lock under
dpll_lock, and every other DPLL request and notification in the system waits behind it. With ToD writes running, requests to an ice DPLL took 1448 ms in median and 3.9 s at most. With the series they took 0.2 ms and 0.3 ms, the same as idle.The bigger reason are zl3073x callbacks we are working on, which have to wait for the hardware themselves:
- a device reset with resync waits for the fast lock, up to 1 s with a 1 PPS input
- a glitchless stop or start of an output completes on an output edge, so it takes up to one period, 1 s for a 1 PPS output
Quoted 4 lines
Holding the global
dpll_lockfor that long would stall every DPLL device in the system. For the output state we tried an asynchronous implementation, but then the callback returns success before it knows the result.
Right, for these level of waiting async seems like the right direction, at least naively/without knowing the HW. Why does the device wait until PPS to apply the step change? Is the programmed time supposed to correspond to the pulse?
Quoted 4 lines
A failure can only be reported by a later notification, and the next request gets
-EBUSYuntil the change completes. With a lock per chip the callback can simply wait, and one chip cannot do these operations in parallel anyway.
Do the failures only happen because of "unforeseen circumstances" / EIO, or there may be more common errors reported? If it's just the former a devlink health reporter could be an option.
Ivan Vecera
maintainerQuoted 23 lines · Jakub Kicinski
Quoted 17 lines · On Wed, 18 Nov 2026 16:29:23 +0100 Ivan Vecera wrote:
A step of the zl3073x PHC, which ptp4l and ts2phc do at start and after a large offset, waits for the next 1 PPS edge, up to 1 s, with the channel lock held. A phase step can hold it for up to 3 s while it waits for the previous one. A dpll callback of that channel waits for the lock under
dpll_lock, and every other DPLL request and notification in the system waits behind it. With ToD writes running, requests to an ice DPLL took 1448 ms in median and 3.9 s at most. With the series they took 0.2 ms and 0.3 ms, the same as idle.The bigger reason are zl3073x callbacks we are working on, which have to wait for the hardware themselves:
- a device reset with resync waits for the fast lock, up to 1 s with a 1 PPS input
- a glitchless stop or start of an output completes on an output edge, so it takes up to one period, 1 s for a 1 PPS outputQuoted 4 lines
Holding the global
dpll_lockfor that long would stall every DPLL device in the system. For the output state we tried an asynchronous implementation, but then the callback returns success before it knows the result.
Quoted 4 lines
Right, for these level of waiting async seems like the right direction, at least naively/without knowing the HW. Why does the device wait until PPS to apply the step change? Is the programmed time supposed to correspond to the pulse?
Yes. The device has no immediate ToD write, it can only write the ToD on the next internal 1 Hz edge, the next input sync edge or the next internal 0.5 Hz edge. The written value is the time at that edge, so the seconds stay aligned with the 1 PPS outputs.
Looking at it again, the zl3073x holds the channel lock while it waits for the edge, although the dpll callbacks do not touch the ToD, TIE or phase step registers, and they already run while the device applies such an operation, because the PTP ops return right after issuing it. I will look at narrowing the lock in the driver.
For the resync, async is not only about reporting the result. Fast lock is a setting of the DPLL, not of a reference, and forcing it makes the DPLL ignore its frequency and phase error monitors. While an asynchronous resync is pending, everything else done to the DPLL runs in forced fast lock. A reference switch, whether from a priority or state change, a manual reference or the device itself in automatic mode, would follow the fast lock phase rate instead of the configured phase slope limit, and the resync would then report success on another reference. A switch to NCO would keep the force bit set until the work clears it. So every request changing the DPLL configuration would have to fail with -EBUSY, cancel the resync, or wait for it. With a lock per chip they simply wait, for at most 1 s.
Quoted 8 lines
Quoted 4 lines
A failure can only be reported by a later notification, and the next request gets
-EBUSYuntil the change completes. With a lock per chip the callback can simply wait, and one chip cannot do these operations in parallel anyway.Do the failures only happen because of "unforeseen circumstances" / EIO, or there may be more common errors reported? If it's just the former a devlink health reporter could be an option.
For the output start and stop, only EIO. The device does not report a stopped output and the driver can only wait for one period, so a health reporter would work there.
For the resync, no. The wait ends with -ETIMEDOUT when the DPLL does not enter fast lock, for example because the selected reference lost its qualification in the meantime. That is a result of the input signal the user needs in the reply, not a device fault.
Beyond the zl3073x, with the global lock any callback that waits for its device, for example an mlx5 firmware command with its 60 s timeout, stalls the DPLL devices of every other driver in the system.
Thanks,
Ivan
Jakub Kicinski
maintainerQuoted 38 lines · On Thu, 19 Nov 2026 13:29:11 +0100 Ivan Vecera wrote:
Quoted 4 lines
Right, for these level of waiting async seems like the right direction, at least naively/without knowing the HW. Why does the device wait until PPS to apply the step change? Is the programmed time supposed to correspond to the pulse?
Yes. The device has no immediate ToD write, it can only write the ToD on the next internal 1 Hz edge, the next input sync edge or the next internal 0.5 Hz edge. The written value is the time at that edge, so the seconds stay aligned with the 1 PPS outputs.
Looking at it again, the zl3073x holds the channel lock while it waits for the edge, although the dpll callbacks do not touch the ToD, TIE or phase step registers, and they already run while the device applies such an operation, because the PTP ops return right after issuing it. I will look at narrowing the lock in the driver.
For the resync, async is not only about reporting the result. Fast lock is a setting of the DPLL, not of a reference, and forcing it makes the DPLL ignore its frequency and phase error monitors. While an asynchronous resync is pending, everything else done to the DPLL runs in forced fast lock. A reference switch, whether from a priority or state change, a manual reference or the device itself in automatic mode, would follow the fast lock phase rate instead of the configured phase slope limit, and the resync would then report success on another reference. A switch to NCO would keep the force bit set until the work clears it. So every request changing the DPLL configuration would have to fail with
-EBUSY, cancel the resync, or wait for it. With a lock per chip they simply wait, for at most 1 s.Quoted 3 lines
Do the failures only happen because of "unforeseen circumstances" / EIO, or there may be more common errors reported? If it's just the former a devlink health reporter could be an option.
For the output start and stop, only EIO. The device does not report a stopped output and the driver can only wait for one period, so a health reporter would work there.
Quoted 8 lines
For the resync, no. The wait ends with
-ETIMEDOUTwhen the DPLL does not enter fast lock, for example because the selected reference lost its qualification in the meantime. That is a result of the input signal the user needs in the reply, not a device fault.Beyond the zl3073x, with the global lock any callback that waits for its device, for example an mlx5 firmware command with its 60 s timeout, stalls the DPLL devices of every other driver in the system.
Well, I'm not convinced. The relations between objects in DPLL are already quite hard to follow, and objects from one driver routinely "plug" into objects from another. The explanation of the locking rules in patch 9 does not look clean or clear. The driver facing API needs to be much more "dummy-proof".
Ivan Vecera
maintainerQuoted 5 lines · Jakub Kicinski
Well, I'm not convinced. The relations between objects in DPLL are already quite hard to follow, and objects from one driver routinely "plug" into objects from another. The explanation of the locking rules in patch 9 does not look clean or clear. The driver facing API needs to be much more "dummy-proof".
Fair enough. The complicated part of the rules comes exactly from
that: a pin registered by another driver, like the zl3073x pins that ice registers with its TXC DPLL or uses as parents of its RCLK pins. A message about such a pin runs callbacks of both drivers. I have prototypes of the first four ways below to lock this, each with KUnit tests, and would like your opinion before going further.
In all of them a domain is the set of objects created with the same module and clock_id, dpll_lock becomes an rwsem for the topology and lifetime, and a mutex per domain serializes the callbacks.
A) Pin's domain (this series)
Callbacks of a pin run under the domain of the pin, whichever driver registered them.
Pros:
* one domain lock at a time, so no lock order
* a request or a message about a pin is atomic
Cons:
* the callbacks of a foreign pin are serialized with the driver that created the pin, not with the other callbacks of the driver that registered it, so that driver has to protect the shared state itself, and lockdep cannot check it
* restrictions for measured_freq_get, reference sync pairs and the private data of a parent pin, which patch 9 has to explain
B) Registrant's domain, deferred notifications
Each callback runs under the domain of the driver that registered it. A message about a pin takes the domain locks one after another, and notifications from callbacks are queued and sent once the domain lock is dropped.
Pros:
* callbacks registered by one driver instance are always serialized with each other
* one domain lock at a time, so no lock order
Cons:
* a request or a message about a pin registered across domains is not atomic
* the most complex core: a notification queue per domain, a lock per object to keep its messages in order, and pin setters split into validation and apply parts
C) Registrant's domain nested under the pin's domain
Pros:
* callbacks registered by one driver instance are serialized with each other and with the driver that created the pin
* a request or a message about a pin is atomic
Cons:
* the lock order comes from the topology, so a pin of A registered with a DPLL of B together with a pin of B registered with a DPLL of A deadlocks, and lockdep sees it only with a lockdep class per domain
* a stuck foreign registrant stops the domain of the pin
D) Merged domains (your suggestion)
Registering a pin with a DPLL or a parent pin of another domain merges both domains. They are not split again.
Pros:
* the rules for drivers stay as they are with the global lock today, and lockdep checks them; the only new one is that state shared between chips not connected by a pin needs a driver lock
* a request or a message is atomic
Cons:
* only hardware not connected by pins runs in parallel; on the GNR-D system the zl3073x and all ice PFs end up in one domain
* a callback that waits for the hardware, like the planned resync for up to 1 s, or for firmware still stalls all DPLL devices in the merged domain
E) Global dpll_lock, slow callbacks asynchronous
Pros:
* no change in the core
Cons:
* the resync problems from my previous mail, and a callback that waits for firmware still stalls all DPLL devices in the system
I wrote before that stretching the domains would not improve anything on that system. That holds for the ToD stall I measured, but the zl3073x does not need to hold its channel lock across the edge waits. Without that, the remaining waits are the planned resync and output state callbacks, and with D they stall only the devices wired to that chip, which depend on it anyway.
So I lean towards D, as it gives drivers nothing new to get right. Would that address your concern, or do you see a better way?
It would be good to hear from the other DPLL maintainers as well. Jiri, Vadim, Arkadiusz, what do you think?
Thanks,
Ivan
Vadim Fedorenko
maintainerQuoted 97 lines · Ivan Vecera
Quoted 5 lines · Jakub Kicinski
Well, I'm not convinced. The relations between objects in DPLL are already quite hard to follow, and objects from one driver routinely "plug" into objects from another. The explanation of the locking rules in patch 9 does not look clean or clear. The driver facing API needs to be much more "dummy-proof".
Fair enough. The complicated part of the rules comes exactly from
that: a pin registered by another driver, like the zl3073x pins that ice registers with its TXC DPLL or uses as parents of its RCLK pins. A message about such a pin runs callbacks of both drivers. I have prototypes of the first four ways below to lock this, each with KUnit tests, and would like your opinion before going further.In all of them a domain is the set of objects created with the same module and
clock_id,dpll_lockbecomes an rwsem for the topology and lifetime, and a mutex per domain serializes the callbacks.A) Pin's domain (this series)
Callbacks of a pin run under the domain of the pin, whichever driver registered them.
Pros:
* one domain lock at a time, so no lock order
* a request or a message about a pin is atomic
Cons:
* the callbacks of a foreign pin are serialized with the driver that created the pin, not with the other callbacks of the driver that registered it, so that driver has to protect the shared state itself, and lockdep cannot check it
* restrictions formeasured_freq_get, reference sync pairs and the private data of a parent pin, which patch 9 has to explainB) Registrant's domain, deferred notifications
Each callback runs under the domain of the driver that registered it. A message about a pin takes the domain locks one after another, and notifications from callbacks are queued and sent once the domain lock is dropped.
Pros:
* callbacks registered by one driver instance are always serialized with each other
* one domain lock at a time, so no lock order
Cons:
* a request or a message about a pin registered across domains is not atomic
* the most complex core: a notification queue per domain, a lock per object to keep its messages in order, and pin setters split into validation and apply partsC) Registrant's domain nested under the pin's domain
Pros:
* callbacks registered by one driver instance are serialized with each other and with the driver that created the pin
* a request or a message about a pin is atomic
Cons:
* the lock order comes from the topology, so a pin of A registered with a DPLL of B together with a pin of B registered with a DPLL of A deadlocks, and lockdep sees it only with a lockdep class per domain
* a stuck foreign registrant stops the domain of the pinD) Merged domains (your suggestion)
Registering a pin with a DPLL or a parent pin of another domain merges both domains. They are not split again.
Pros:
* the rules for drivers stay as they are with the global lock today, and lockdep checks them; the only new one is that state shared between chips not connected by a pin needs a driver lock
* a request or a message is atomic
Cons:
* only hardware not connected by pins runs in parallel; on the GNR-D system the zl3073x and all ice PFs end up in one domain
* a callback that waits for the hardware, like the planned resync for up to 1 s, or for firmware still stalls all DPLL devices in the merged domainE) Global
dpll_lock, slow callbacks asynchronousPros:
* no change in the core
Cons:
* the resync problems from my previous mail, and a callback that waits for firmware still stalls all DPLL devices in the systemI wrote before that stretching the domains would not improve anything on that system. That holds for the ToD stall I measured, but the zl3073x does not need to hold its channel lock across the edge waits. Without that, the remaining waits are the planned resync and output state callbacks, and with D they stall only the devices wired to that chip, which depend on it anyway.
Quoted 5 lines
So I lean towards D, as it gives drivers nothing new to get right. Would that address your concern, or do you see a better way?
It would be good to hear from the other DPLL maintainers as well. Jiri, Vadim, Arkadiusz, what do you think?
I totally agree with Jakub. Current implementation of DPLL subsystem is over complicated, and all these complications came just to completely model what was designed for Intel NICs, basically ice driver. But now we are again back to the discussion how to complicate things further just to fit what was implemented in the new generation of the same hardware.
Maybe it's time to step back and think if we really need all this, or find simpler way to express/model things?
Jiri Pirko
maintainerQuoted 104 lines · Fri, Nov 20, 2026 at 09:00:27PM +0100, [email protected] wrote:
Quoted 97 lines · Ivan Vecera
Quoted 5 lines · Jakub Kicinski
Well, I'm not convinced. The relations between objects in DPLL are already quite hard to follow, and objects from one driver routinely "plug" into objects from another. The explanation of the locking rules in patch 9 does not look clean or clear. The driver facing API needs to be much more "dummy-proof".
Fair enough. The complicated part of the rules comes exactly from
that: a pin registered by another driver, like the zl3073x pins that ice registers with its TXC DPLL or uses as parents of its RCLK pins. A message about such a pin runs callbacks of both drivers. I have prototypes of the first four ways below to lock this, each with KUnit tests, and would like your opinion before going further.In all of them a domain is the set of objects created with the same module and
clock_id,dpll_lockbecomes an rwsem for the topology and lifetime, and a mutex per domain serializes the callbacks.A) Pin's domain (this series)
Callbacks of a pin run under the domain of the pin, whichever driver registered them.
Pros:
* one domain lock at a time, so no lock order
* a request or a message about a pin is atomic
Cons:
* the callbacks of a foreign pin are serialized with the driver that created the pin, not with the other callbacks of the driver that registered it, so that driver has to protect the shared state itself, and lockdep cannot check it
* restrictions formeasured_freq_get, reference sync pairs and the private data of a parent pin, which patch 9 has to explainB) Registrant's domain, deferred notifications
Each callback runs under the domain of the driver that registered it. A message about a pin takes the domain locks one after another, and notifications from callbacks are queued and sent once the domain lock is dropped.
Pros:
* callbacks registered by one driver instance are always serialized with each other
* one domain lock at a time, so no lock order
Cons:
* a request or a message about a pin registered across domains is not atomic
* the most complex core: a notification queue per domain, a lock per object to keep its messages in order, and pin setters split into validation and apply partsC) Registrant's domain nested under the pin's domain
Pros:
* callbacks registered by one driver instance are serialized with each other and with the driver that created the pin
* a request or a message about a pin is atomic
Cons:
* the lock order comes from the topology, so a pin of A registered with a DPLL of B together with a pin of B registered with a DPLL of A deadlocks, and lockdep sees it only with a lockdep class per domain
* a stuck foreign registrant stops the domain of the pinD) Merged domains (your suggestion)
Registering a pin with a DPLL or a parent pin of another domain merges both domains. They are not split again.
Pros:
* the rules for drivers stay as they are with the global lock today, and lockdep checks them; the only new one is that state shared between chips not connected by a pin needs a driver lock
* a request or a message is atomic
Cons:
* only hardware not connected by pins runs in parallel; on the GNR-D system the zl3073x and all ice PFs end up in one domain
* a callback that waits for the hardware, like the planned resync for up to 1 s, or for firmware still stalls all DPLL devices in the merged domainE) Global
dpll_lock, slow callbacks asynchronousPros:
* no change in the core
Cons:
* the resync problems from my previous mail, and a callback that waits for firmware still stalls all DPLL devices in the systemI wrote before that stretching the domains would not improve anything on that system. That holds for the ToD stall I measured, but the zl3073x does not need to hold its channel lock across the edge waits. Without that, the remaining waits are the planned resync and output state callbacks, and with D they stall only the devices wired to that chip, which depend on it anyway.
Quoted 5 lines
So I lean towards D, as it gives drivers nothing new to get right. Would that address your concern, or do you see a better way?
It would be good to hear from the other DPLL maintainers as well. Jiri, Vadim, Arkadiusz, what do you think?
Quoted 8 lines
I totally agree with Jakub. Current implementation of DPLL subsystem is over complicated, and all these complications came just to completely model what was designed for Intel NICs, basically ice driver. But now we are again back to the discussion how to complicate things further just to fit what was implemented in the new generation of the same hardware.
Maybe it's time to step back and think if we really need all this, or find simpler way to express/model things?
Agreed.