mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: ivecera@redhat.com
Cc: netdev@vger.kernel.org, vadim.fedorenko@linux.dev,
	arkadiusz.kubalewski@intel.com, jiri@resnulli.us, corbet@lwn.net,
	skhan@linuxfoundation.org, rdunlap@infradead.org,
	min.li@microchip.com, anthony.l.nguyen@intel.com,
	przemyslaw.kitszel@intel.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, richardcochran@gmail.com,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	intel-wired-lan@lists.osuosl.org, grzegorz.nitka@intel.com,
	karol.kolacinski@intel.com, saeedm@nvidia.com, tariqt@nvidia.com,
	poros@redhat.com
Subject: Re: [PATCH net-next 10/10] dpll: document locking rules
Date: Tue, 10 Nov 2026 17:53:30 +0000	[thread overview]
Message-ID: <179433321053.994134.15233379643090486121@kernel.org> (raw)
In-Reply-To: <20261106121005.1327603-11-ivecera@redhat.com>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The new Locking section in Documentation/driver-api/dpll.rst
  covers three cases where a pin callback reaches private data owned by…
- [Low] The new driver rule in Documentation/driver-api/dpll.rst (lines
  716-718) says notifications for objects outside the callback's domain…

--

dpll: document locking rules

This commit adds a Locking section to the dpll driver API documentation.
The section describes the dpll_lock and per-domain lock levels, the domain
each driver callback runs under, and the rules drivers have to follow. It
also adds matching notes to the kernel-doc of dpll_pin_register() and
dpll_pin_on_pin_register().

> diff --git a/Documentation/driver-api/dpll.rst b/Documentation/driver-api/dpll.rst
> index 7c117ae37cc1b..40d5037ff3bb0 100644
> --- a/Documentation/driver-api/dpll.rst
> +++ b/Documentation/driver-api/dpll.rst
> @@ -675,6 +675,50 @@ In the error path we have to rewind every allocation in the reverse order:

[ ... ]

> +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``.

[Severity: Low]
Should reference-sync pairs be in this list too?

dpll_pin_ref_sync_pair_add() only does an xa_insert() into
pin->ref_sync_pins. It never checks that pin->domain matches
ref_sync_pin->domain, so a pair can span two domains.

When the ref-sync callbacks run, only the domain lock of the pin is held,
but they get the private data of the paired pin:

drivers/dpll/dpll_netlink.c:dpll_msg_add_pin_ref_sync() {
    ...
	ref_sync_pin_priv = dpll_pin_on_dpll_priv(dpll, ref_sync_pin);
    ...
	ret = ops->ref_sync_get(pin, pin_priv, ref_sync_pin,
				ref_sync_pin_priv, &state, extack);
    ...
}

dpll_pin_ref_sync_state_set() does the same for ref_sync_get() and
ref_sync_set(). It then calls __dpll_pin_change_ntf() only for the pin, not
for ref_sync_pin.

Under the rules above, the callbacks from ref_sync_pin's own registration
run under ref_sync_pin's domain. If the two domains differ, nothing
serializes these two sets of callbacks.

The in-tree implementers zl3073x_dpll_input_pin_ref_sync_get() and
zl3073x_dpll_input_pin_ref_sync_set() do dereference this data:

	struct zl3073x_dpll_pin *sync_pin = ref_sync_pin_priv;

No in-tree driver creates a cross-domain pair today, since zl3073x
registers only its own chip's pins. The first bullet partly covers the case
where one driver registered both pins. It does not cover pins that
different drivers registered on one dpll.

Could the documentation say whether a ref-sync pair may cross domains, and
whether ref_sync_pin_priv may be dereferenced? The parent pin case in the
dpll_pin_on_pin_register() bullet already has an explicit rule like this.

> +
> +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.
> +- 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 while holding a lock that its callbacks take.

[Severity: Low]
Can a driver follow the work item suggestion safely without two more rules?

The first rule is about waiting on the work. The deferred work ends up in
dpll_pin_change_ntf() or dpll_device_change_ntf(). Both take dpll_lock for
read and then the domain mutex:

drivers/dpll/dpll_netlink.c:dpll_pin_change_ntf() {
    ...
	down_read(&dpll_lock);
	mutex_lock(&pin->domain->lock);
	ret = __dpll_pin_change_ntf(pin);
    ...
}

Callbacks already run with dpll_lock held for read, for example from
dpll_pin_pre_doit() or dpll_pre_doit(). A callback, or code holding a lock
the callbacks take, might wait for the work with flush_work() or
cancel_work_sync() while a writer is queued on dpll_lock. Could that
deadlock?

callback                  writer                  work
down_read(&dpll_lock)
                          dpll_pin_register()
                            down_write(&dpll_lock)
                                                  dpll_pin_change_ntf()
                                                    down_read(&dpll_lock)
flush_work()

Here the writer waits for the callback's read hold. The work's down_read()
blocks behind the queued writer, and the callback waits for the work.

The last rule above only bans direct calls to dpll_device_change_ntf() and
dpll_pin_change_ntf() while holding such a lock. It does not cover waiting
for a work item that makes those calls.

The second rule is about lifetime. The text does not say that the work has
to be cancelled or flushed before the target pin or device is unregistered
and released with dpll_pin_put() or dpll_device_put(). __dpll_device_put()
ends in kfree(dpll). A work item that keeps a struct dpll_device or struct
dpll_pin pointer and runs after the final put would touch freed memory.

Would it make sense to add both rules next to the work item suggestion?

> +
>  SyncE enablement
>  ================
>  For SyncE enablement it is required to allow control over dpll device

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106121005.1327603-1-ivecera%40redhat.com

      parent reply	other threads:[~2026-11-10 17:53 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 12:09 [PATCH net-next 00/10] dpll: do not serialize driver callbacks under global dpll_lock Ivan Vecera
2026-11-06 12:09 ` [PATCH net-next 01/10] ice: dpll: notify TSPLL lock status from the periodic work only Ivan Vecera
2026-11-10 12:20   ` Petr Oros
2026-11-10 17:53   ` netdev-bot+sashiko
2026-11-06 12:09 ` [PATCH net-next 02/10] ice: dpll: serialize changes of the SyncE CGU registers Ivan Vecera
2026-11-10 17:53   ` netdev-bot+sashiko
2026-11-06 12:09 ` [PATCH net-next 03/10] dpll: add domain object Ivan Vecera
2026-11-10 12:23   ` Petr Oros
2026-11-10 17:53   ` netdev-bot+sashiko
2026-11-06 12:09 ` [PATCH net-next 04/10] dpll: take domain locks around driver callbacks Ivan Vecera
2026-11-10 12:23   ` Petr Oros
2026-11-06 12:10 ` [PATCH net-next 05/10] dpll: convert dpll_lock to rwsem Ivan Vecera
2026-11-10 12:24   ` Petr Oros
2026-11-10 17:53   ` netdev-bot+sashiko
2026-11-06 12:10 ` [PATCH net-next 06/10] dpll: add KUnit tests for core locking Ivan Vecera
2026-11-10 12:24   ` Petr Oros
2026-11-10 17:53   ` netdev-bot+sashiko
2026-11-06 12:10 ` [PATCH net-next 07/10] dpll: reject measured_freq_get for foreign and on-pin registrations Ivan Vecera
2026-11-10 12:24   ` Petr Oros
2026-11-06 12:10 ` [PATCH net-next 08/10] dpll: zl3073x: update locking comments Ivan Vecera
2026-11-10 12:24   ` Petr Oros
2026-11-06 12:10 ` [PATCH net-next 09/10] ice: dpll: " Ivan Vecera
2026-11-10 15:31   ` Petr Oros
2026-11-10 17:53   ` netdev-bot+sashiko
2026-11-06 12:10 ` [PATCH net-next 10/10] dpll: document locking rules Ivan Vecera
2026-11-10 12:25   ` Petr Oros
2026-11-10 17:53   ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179433321053.994134.15233379643090486121@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=arkadiusz.kubalewski@intel.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=grzegorz.nitka@intel.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=ivecera@redhat.com \
    --cc=jiri@resnulli.us \
    --cc=karol.kolacinski@intel.com \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=min.li@microchip.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=poros@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=rdunlap@infradead.org \
    --cc=richardcochran@gmail.com \
    --cc=saeedm@nvidia.com \
    --cc=skhan@linuxfoundation.org \
    --cc=tariqt@nvidia.com \
    --cc=vadim.fedorenko@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®