Skip to contentSkip to conversation

dpll: add a simulated DPLL device driver

PATCH Superseded Petr Oros 2 participants 23 messages Nov 12 – Nov 16

Subsystems (5)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Petr Oros

author
#0 lore raw

v4 cover dpll: add a simulated DPLL device driver

The DPLL subsystem has no in-tree driver that can run without real hardware, so core changes and userspace tooling are hard to exercise in CI, and the pin-on-pin and reference sync paths see almost no coverage outside the vendors' labs. This series adds dpllsim, a simulated DPLL device driver, together with selftests that run against it.

The driver is controlled through configfs, following gpio-sim. Writing a clock ID into a device directory and setting "live" to 1 registers a DPLL device with the core. Pins are directories under pins/ with their type, frequency, direction and priority as attributes, and all of them are registered when the device goes live. The split between creating the configuration and going live keeps the register and unregister paths reachable from userspace, so they can be exercised repeatedly without reloading the module.

The patches follow the shape of the zl3073x introduction. The driver starts with the device alone, then gains pins and the static pin operations one at a time (state, priority, frequency, phase adjustment), and every feature patch is followed by the selftest that covers it. The last two patches add concurrency stress tests and reference tracker leak tests for the lifecycle paths.

The simulation loop (lock state machine, phase and frequency measurements, monitoring features), the topology features (MUX pin hierarchies, reference sync, media failure injection), netdevsim integration and device mode setting follow in two further series once this one is in, to stay within the 15 patch limit.

The driver and the selftests were developed with an LLM coding assistant (Claude Code) working under my direction. I chose the configfs design, the split into one feature per patch and the test scenarios, and I reviewed every line. The assistant wrote most of the code and the first drafts of the changelogs, and it found and fixed bugs by running the suite on the lab host. The series then went through several rounds of an LLM based patch reviewer whose findings were fixed, and through a mutation test in which deliberately broken driver and core code was caught by the tests.

The selftests live in tools/testing/selftests/drivers/dpll and run with "make -C tools/testing/selftests TARGETS=drivers/dpll run_tests". By default they create dpllsim devices; with DPLL_DEV_ID=<id> the basic and feature scripts run against an existing device instead, so the same suite exercises real hardware, and DPLL_DRIVER=<module name> picks the first device of that driver, dpllsim for a simulated one. The whole suite was run through the kselftest runner in a KVM guest and on an ice E810 host with CONFIG_KASAN, CONFIG_PROVE_LOCKING and CONFIG_DPLL_REFCNT_TRACKER enabled, against the simulator and, with DPLL_DRIVER=ice, against the ice DPLL, where the tests that need a simulator skip and the pin state and priorities of the hardware are left as they were. All pass with no warnings in dmesg.

---
v4:
- address the findings of the netdev AI review of v3
- dpllsim: keep the priority and the frequency set over netlink apart from the configured values, so that every live transition starts from what configfs holds and the attributes keep showing it
- dpllsim: document the pin limit, the frequencies per pin type, the errors of the live write and what happens to values set over netlink; correct the comments on what the subsystem mutex covers
- selftests: tell a failed device or pin dump from a system without devices or pins, and fail instead of skipping when the simulated device cannot be created
- selftests: pick the spare input pin by all its parent devices, bail out before touching a pin whose current priority, frequency or phase adjust could not be written back, restore the reference after the test pin in manual mode, do not let a refusal hide an earlier failure
- selftests: signal only workers that are still children of the script, never delete a device named by the environment or one that existed before, record the mounts before mounting
- selftests: keep the files of freed objects out of the reference tracker snapshot, fail when the tracker is built in but records nothing, skip the final leak check when a device was left behind
- selftests: log deferred restores that fail, tell failed pin queries from missing attributes in the remaining places, fail a stress worker that a signal interrupted, enable CONFIG_IKCONFIG_PROC for the tracker probe
- drop the claim that configfs implies no stable ABI
- add the Reviewed-by given to patches 2, 5, 6 and 14 of v3 (Ivan Vecera) and keep the other tags, except on patches 7 and 9, where the behaviour of the driver changed and which ask for a new look

v3:
- move the selftests from tools/testing/selftests/drivers/net/dpll to tools/testing/selftests/drivers/dpll, with the shared library as a TEST_FILES entry of that directory, so that the tests sit where the drivers do
- let dpllsim refuse pin states that are not valid in the device mode:
connected is refused in automatic mode, which the simulator runs in, as Documentation/driver-api/dpll.rst reserves it for manual mode (Ivan Vecera)
- make the pin state test follow the mode of the device under test and check on the simulator that connected is refused in automatic mode; cycle the stress tests through the states of automatic mode only
- add DPLL_DRIVER to pick the device of a given driver, or the simulator with DPLL_DRIVER=dpllsim, on a system that has hardware DPLL devices
- describe what the leak check waits for instead of a concurrent dump holding references, which nothing does (Ivan Vecera)
- carry the Reviewed-by and the set Acked-by of v2 over to the patches whose code did not change or only moved; patches 2, 5 and 6 changed and ask for a new look

v2:
- sort tools/testing/selftests/drivers/net/dpll/config alphabetically and make the scripts clean under the shellcheck run of the netdev CI (quoted exit and return values, shellcheck directives for the globals shared between the library and the scripts and for the optional argument of dpllsim_setup_standard_device())

v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
---

Petr Oros (14):
dpll: dpllsim: Add simulated DPLL device driver
selftests: dpll: add test library and device lifecycle tests
dpll: dpllsim: Add configurable pins
selftests: dpll: add pin enumeration and property tests
dpll: dpllsim: Add support to set input pin state
selftests: dpll: add pin state tests
dpll: dpllsim: Add support to get/set priority on input pins
selftests: dpll: add pin priority test
dpll: dpllsim: Add support to set frequency on pins
selftests: dpll: add pin frequency test
dpll: dpllsim: Add support to adjust phase
selftests: dpll: add pin phase adjust test
selftests: dpll: add concurrency stress tests
selftests: dpll: add reference leak tests

 Documentation/driver-api/dpllsim.rst          |  95 ++
 Documentation/driver-api/index.rst            |   1 +
 MAINTAINERS                                   |   8 +
 drivers/dpll/Kconfig                          |   1 +
 drivers/dpll/Makefile                         |   1 +
 drivers/dpll/dpllsim/Kconfig                  |  16 +
 drivers/dpll/dpllsim/Makefile                 |   4 +
 drivers/dpll/dpllsim/core.c                   | 480 +++++++++
 drivers/dpll/dpllsim/dpll.c                   | 500 +++++++++
 drivers/dpll/dpllsim/dpllsim.h                | 101 ++
 tools/testing/selftests/Makefile              |   1 +
 tools/testing/selftests/drivers/dpll/Makefile |  17 +
 tools/testing/selftests/drivers/dpll/config   |   8 +
 .../selftests/drivers/dpll/dpll_basic.sh      | 242 +++++
 .../selftests/drivers/dpll/dpll_features.sh   | 605 +++++++++++
 .../selftests/drivers/dpll/dpll_lib.sh        | 989 ++++++++++++++++++
 .../selftests/drivers/dpll/dpll_reftrack.sh   | 190 ++++
 .../selftests/drivers/dpll/dpll_stress.sh     | 610 +++++++++++
 tools/testing/selftests/drivers/dpll/settings |   1 +
 19 files changed, 3870 insertions(+)
 create mode 100644 Documentation/driver-api/dpllsim.rst
 create mode 100644 drivers/dpll/dpllsim/Kconfig
 create mode 100644 drivers/dpll/dpllsim/Makefile
 create mode 100644 drivers/dpll/dpllsim/core.c
 create mode 100644 drivers/dpll/dpllsim/dpll.c
 create mode 100644 drivers/dpll/dpllsim/dpllsim.h
 create mode 100644 tools/testing/selftests/drivers/dpll/Makefile
 create mode 100644 tools/testing/selftests/drivers/dpll/config
 create mode 100755 tools/testing/selftests/drivers/dpll/dpll_basic.sh
 create mode 100755 tools/testing/selftests/drivers/dpll/dpll_features.sh
 create mode 100644 tools/testing/selftests/drivers/dpll/dpll_lib.sh
 create mode 100755 tools/testing/selftests/drivers/dpll/dpll_reftrack.sh
 create mode 100755 tools/testing/selftests/drivers/dpll/dpll_stress.sh
 create mode 100644 tools/testing/selftests/drivers/dpll/settings
Signature · 1 line
2.56.0
author
#1 lore raw

PATCH v4 1/14 dpll: dpllsim: Add simulated DPLL device driver

Add dpllsim, a driver providing simulated DPLL devices for testing the DPLL subsystem and its userspace tooling without real hardware, in the same spirit as netdevsim for network devices. The DPLL core identifies a device by clock ID, index and module only, so the driver needs no bus and no struct device at all.

Instances are created and configured at runtime through configfs, following the gpio-sim precedent for objects that userspace creates on demand. Creating a directory under /sys/kernel/config/dpllsim/ allocates an instance, its clock_id attribute selects the clock ID, writing 1 to live registers the DPLL device with the core and writing 0 unregisters it again. Removing the directory tears a live instance down implicitly. Keeping registration separate from creation lets a test register and unregister the same device repeatedly, which is where the core bugs the driver is meant to catch tend to live, and it allows the structural attributes to be refused with EBUSY while the device is visible to userspace.

Reading live reports whether the device is registered with the DPLL subsystem, it turns 1 only once the whole live transition succeeded and 0 again as the first step of the teardown. The configuration is frozen earlier, from the moment the transition obtains the device handle, so that a configuration write racing with the transition is refused rather than lost.

The device registers as a PPS type DPLL with the two mandatory callbacks only. mode_get reports automatic mode and lock_status_get reports unlocked with no error. Pins come with the following patches and the simulation of lock acquisition with a later series.

Document the configfs layout under Documentation/driver-api and add a MAINTAINERS entry.

---
v4:
- drop the claim that configfs implies no stable ABI from the changelog, no code change

v3: https://lore.kernel.org/all/[email protected]/

---
 Documentation/driver-api/dpllsim.rst |  41 +++++
 Documentation/driver-api/index.rst   |   1 +
 MAINTAINERS                          |   7 +
 drivers/dpll/Kconfig                 |   1 +
 drivers/dpll/Makefile                |   1 +
 drivers/dpll/dpllsim/Kconfig         |  16 ++
 drivers/dpll/dpllsim/Makefile        |   4 +
 drivers/dpll/dpllsim/core.c          | 221 +++++++++++++++++++++++++++
 drivers/dpll/dpllsim/dpll.c          |  84 ++++++++++
 drivers/dpll/dpllsim/dpllsim.h       |  58 +++++++
 10 files changed, 434 insertions(+)
 create mode 100644 Documentation/driver-api/dpllsim.rst
 create mode 100644 drivers/dpll/dpllsim/Kconfig
 create mode 100644 drivers/dpll/dpllsim/Makefile
 create mode 100644 drivers/dpll/dpllsim/core.c
 create mode 100644 drivers/dpll/dpllsim/dpll.c
 create mode 100644 drivers/dpll/dpllsim/dpllsim.h
Documentation/driver-api/dpllsim.rst new file +41 -0
new file mode 100644
index 00000000000000..86a5d523534055
@@ -0,0 +1,41 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==========================
+DPLL simulator (dpllsim)
+==========================
+
+The dpllsim driver provides simulated DPLL devices for testing the DPLL
+subsystem and its userspace tooling without real hardware, similar to
+what netdevsim provides for network devices.
+
+Configuration interface
+=======================
+
+Devices are described in configfs under ``/sys/kernel/config/dpllsim/``.
+A directory created there is a device instance. Attributes are written
+while the instance is not live, then ``live`` is set to 1 to register
+the device with the DPLL subsystem. Writing 0 unregisters it again.
+Structural attributes return ``EBUSY`` while the instance is live.
+
+Device directory ``/sys/kernel/config/dpllsim/<dev>/``:
+
+=======================  =====================================================
+``clock_id``             Clock ID of the DPLL device, must be nonzero and
+                         unique among live instances
+``live``                 1 registers the device, 0 unregisters it
+=======================  =====================================================
+
+Example
+=======
+
+Create a device and make it live::
+
+    cd /sys/kernel/config/dpllsim
+    mkdir dev0 && cd dev0
+    echo 100 > clock_id
+    echo 1 > live
+
+    dpll device show
+
+To remove the device, write 0 to ``live`` and remove the device
+directory.
Documentation/driver-api/index.rst +1 -0
index aaf5d76ed074ed..e2271889e33400 100644
@@ -87,6 +87,7 @@ Subsystem-specific APIs
    crypto/index
    dmaengine/index
    dpll
+   dpllsim
    edac
    extcon
    firmware/index
MAINTAINERS +7 -0
index fe23913b1e4329..0c8c36e90537f4 100644
@@ -8099,6 +8099,13 @@ F:	Documentation/networking/device_drivers/ethernet/freescale/dpaa2/switch-drive
 F:	drivers/net/ethernet/freescale/dpaa2/dpaa2-switch*
 F:	drivers/net/ethernet/freescale/dpaa2/dpsw*
 
+DPLL SIMULATOR DRIVER (dpllsim)
+M:	Petr Oros <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/driver-api/dpllsim.rst
+F:	drivers/dpll/dpllsim/
+
 DPLL SUBSYSTEM
 M:	Vadim Fedorenko <[email protected]>
 M:	Arkadiusz Kubalewski <[email protected]>
drivers/dpll/Kconfig +1 -0
index be98969f040ab6..c6bd5392ce8753 100644
@@ -24,5 +24,6 @@ config DPLL_REFCNT_TRACKER
 	  If unsure, say N.
 
 source "drivers/dpll/zl3073x/Kconfig"
+source "drivers/dpll/dpllsim/Kconfig"
 
 endmenu
drivers/dpll/Makefile +1 -0
index 9e7a3a3e592e81..1ee1daa3a46cc7 100644
@@ -9,3 +9,4 @@ dpll-y                  += dpll_netlink.o
 dpll-y                  += dpll_nl.o
 
 obj-$(CONFIG_ZL3073X)	+= zl3073x/
+obj-$(CONFIG_DPLLSIM)	+= dpllsim/
drivers/dpll/dpllsim/Kconfig new file +16 -0
new file mode 100644
index 00000000000000..45ed93ba3dee5a
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config DPLLSIM
+	tristate "DPLL simulator driver"
+	depends on NET
+	select DPLL
+	select CONFIGFS_FS
+	help
+	  This driver provides simulated DPLL devices for testing and
+	  development of the DPLL subsystem and its userspace tooling
+	  without real hardware. Devices with arbitrary pin topologies
+	  are created and configured at runtime through configfs,
+	  similar to what gpio-sim provides for GPIO.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called dpllsim.
drivers/dpll/dpllsim/Makefile new file +4 -0
new file mode 100644
index 00000000000000..905df2ee00874f
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-$(CONFIG_DPLLSIM) += dpllsim.o
+dpllsim-y := core.o dpll.o
drivers/dpll/dpllsim/core.c new file +221 -0

221 lines not on this page · raw message

drivers/dpll/dpllsim/dpll.c new file +84 -0

84 lines not on this page · raw message

drivers/dpll/dpllsim/dpllsim.h new file +58 -0

58 lines not on this page · raw message

Signature · 1 line
2.56.0
author
#2 lore raw

PATCH v4 2/14 selftests: dpll: add test library and device lifecycle tests

In reply to Petr Oros

Add a shell library for DPLL selftests with wrappers around the iproute2 dpll tool and around the dpllsim configfs interface, and the first two test scripts built on it. The library resolves devices by the clock ID chosen at creation time, since netlink ids depend on what else exists on the system, and the dpllsim helpers restrict the lookup to their module, so that a device of another driver with the same clock ID is never picked up. Every query runs the tool first and jq on what it printed, so that a failed query is told apart from a missing attribute. That includes the device dump the device selection reads. A dump that fails is a failure, not a system without a device, unless the simulator is missing as well, which is what a kernel without the DPLL subsystem looks like and a skip. The library loads the dpllsim module and mounts configfs when nothing else did, and the exit trap of each script undoes the mount, removes the devices the script created and runs on INT and TERM as well, so that a timeout imposed by the harness still cleans up. The module stays loaded.

Two runs of scripts that create dpllsim devices would share the one dpllsim directory and could draw the same clock IDs, so every such script takes a lock before it mounts or creates anything and skips when another run holds it. The lock file lives under /run rather than in /tmp, since the scripts run as root and open the file for writing, and a symlink planted in the world-writable /tmp would redirect that open.

dpll_basic.sh checks that a device reports the mandatory attributes over netlink. It runs against the device named by DPLL_DEV_ID, the first device of the driver named by DPLL_DRIVER, or the first device that is not a dpllsim one, and creates a dpllsim device when there is none or when DPLL_DRIVER asks for dpllsim, so the same script serves the simulator and real drivers and picks one of several drivers on a host. A simulated device that cannot be created, registered or found on netlink is a failure, only a missing module is a skip. dpll_stress.sh is simulator only and exercises the lifecycle paths of the core by creating and deleting devices in a loop and by cycling one device through repeated register and unregister transitions. The dpllsim MAINTAINERS entry covers the new directory.

---
v4:
- tell a failed device dump from a system without a device, the dump is a failure unless the simulator is missing as well
- fail instead of skipping when the simulated device cannot be created, registered or found on netlink
- initialize DPLLSIM_CREATED_NAME, so that a value inherited from the environment cannot make a cleanup handler delete a device, and never record a directory that existed before as a device of the run
- record the configfs mount before mounting, so that a signal handled right after the mount still unmounts it
- correct the comments on the side effects of the library and on how it is used, drop the shellcheck directive of a function without arguments
- add the Reviewed-by given to v3 (Ivan Vecera)

v3:
- move the selftests to tools/testing/selftests/drivers/dpll, next to where the drivers live, with the library in that directory as a TEST_FILES entry; the TARGETS and MAINTAINERS entries follow
- add DPLL_DRIVER, which picks the first device of the named driver or, as dpllsim, a created simulated device on a system that has hardware DPLL devices
- the Reviewed-by and Acked-by of v2 are not carried over, the device selection changed

v2:
- sort the config file alphabetically (netdev CI check_selftest)
- quote the ksft_skip and ret expansions and add shellcheck directives for the globals read by the scripts, for ksft_skip, which comes from net/lib.sh, and for the optional argument of dpllsim_setup_standard_device() (netdev CI shellcheck)

v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

---
 MAINTAINERS                                   |   1 +
 tools/testing/selftests/Makefile              |   1 +
 tools/testing/selftests/drivers/dpll/Makefile |  15 +
 tools/testing/selftests/drivers/dpll/config   |   3 +
 .../selftests/drivers/dpll/dpll_basic.sh      |  98 +++++
 .../selftests/drivers/dpll/dpll_lib.sh        | 381 ++++++++++++++++++
 .../selftests/drivers/dpll/dpll_stress.sh     | 164 ++++++++
 tools/testing/selftests/drivers/dpll/settings |   1 +
 8 files changed, 664 insertions(+)
 create mode 100644 tools/testing/selftests/drivers/dpll/Makefile
 create mode 100644 tools/testing/selftests/drivers/dpll/config
 create mode 100755 tools/testing/selftests/drivers/dpll/dpll_basic.sh
 create mode 100644 tools/testing/selftests/drivers/dpll/dpll_lib.sh
 create mode 100755 tools/testing/selftests/drivers/dpll/dpll_stress.sh
 create mode 100644 tools/testing/selftests/drivers/dpll/settings
MAINTAINERS +1 -0
index 0c8c36e90537f4..c2998bb1d136af 100644
@@ -8105,6 +8105,7 @@ L:	[email protected]
 S:	Maintained
 F:	Documentation/driver-api/dpllsim.rst
 F:	drivers/dpll/dpllsim/
+F:	tools/testing/selftests/drivers/dpll/
 
 DPLL SUBSYSTEM
 M:	Vadim Fedorenko <[email protected]>
tools/testing/selftests/Makefile +1 -0
index 07c3719f8b04bf..9f07446a4e8c51 100644
@@ -20,6 +20,7 @@ TARGETS += devices/error_logs
 TARGETS += devices/probe
 TARGETS += dmabuf-heaps
 TARGETS += drivers/dma-buf
+TARGETS += drivers/dpll
 TARGETS += drivers/ntsync
 TARGETS += drivers/s390x/uvdevice
 TARGETS += drivers/net
tools/testing/selftests/drivers/dpll/Makefile new file +15 -0
new file mode 100644
index 00000000000000..7e839ae71cd22f
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0
+
+TEST_INCLUDES := \
+	$(wildcard ../../net/lib/sh/*.sh) \
+	../../net/lib.sh \
+# end of TEST_INCLUDES
+
+TEST_FILES := dpll_lib.sh
+
+TEST_PROGS := \
+	dpll_basic.sh \
+	dpll_stress.sh \
+# end of TEST_PROGS
+
+include ../../lib.mk
tools/testing/selftests/drivers/dpll/config new file +3 -0
new file mode 100644
index 00000000000000..e2c90b6970bd43
@@ -0,0 +1,3 @@
+CONFIG_CONFIGFS_FS=y
+CONFIG_DPLL=y
+CONFIG_DPLLSIM=m
tools/testing/selftests/drivers/dpll/dpll_basic.sh new file +98 -0

98 lines not on this page · raw message

tools/testing/selftests/drivers/dpll/dpll_lib.sh new file +381 -0

381 lines not on this page · raw message

tools/testing/selftests/drivers/dpll/dpll_stress.sh new file +164 -0

164 lines not on this page · raw message

tools/testing/selftests/drivers/dpll/settings new file +1 -0
new file mode 100644
index 00000000000000..a62d2fa1275c6b
@@ -0,0 +1 @@
+timeout=600
Signature · 1 line
2.56.0
#3 lore raw

Re: [PATCH net-next v4 02/14] selftests: dpll: add test library and device lifecycle tests

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] When dpllsim is built in (CONFIG_DPLLSIM=y), the selftests cannot find their own devices and report a hard FAIL where they should…
- [Low] A second signal can still abort the exit-trap teardown, despite the comment in cleanup().

--

selftests: dpll: add test library and device lifecycle tests

This adds a shell library for the DPLL selftests. It wraps the iproute2 dpll tool and the dpllsim configfs interface, and the patch also adds dpll_basic.sh and dpll_stress.sh. The library finds simulated devices by clock ID and module name, and each script takes a lock, mounts configfs when needed and cleans up from an exit trap.

Quoted 5 lines
tools/testing/selftests/drivers/dpll/dpll_lib.sh new file +0 -0
new file mode 100644
index 0000000000000..9fe7f2f62dd46

[ ... ]

Quoted 4 lines
tools/testing/selftests/drivers/dpll/dpll_lib.sh new file +4 -0
+# $1: clock-id, $2: module name (optional)
+dpll_device_get_id_by_clock_id()
+{
+	local clock_id=$1

tools/testing/selftests/drivers/dpll/dpll_lib.sh line 199

Quoted 10 lines
tools/testing/selftests/drivers/dpll/dpll_lib.sh new file +10 -0
+	local module=${2:-}
+	local out
+
+	out=$(dpll device show -j 2>/dev/null) || return 1
+	jq -r --arg cid "$clock_id" --arg mod "$module" \
+	   '[.device[]? |
+	     select((.["clock-id"] | tostring) == $cid and
+		    ($mod == "" or .["module-name"] == $mod))
+	    ][0].id // empty' <<< "$out"
+}

[Severity: Medium]
Does this module-name match work when dpllsim is built in?

DPLLSIM is a tristate. With CONFIG_DPLLSIM=y, THIS_MODULE is NULL, and dpllsim registers its device with:

drivers/dpll/dpllsim/dpll.c:dpllsim_dev_deploy() {
    ...
	dpll = dpll_device_get(sim->clock_id, 0, THIS_MODULE, &sim->tracker);
    ...
}

The netlink reply then carries:

drivers/dpll/dpll_netlink.c:dpll_device_get_one() {
    ...
	if (nla_put_string(msg, DPLL_A_MODULE_NAME, module_name(dpll->module)))
    ...
}

module_name() returns "kernel" for a NULL module. With mod=dpllsim, the select above never matches a device the script created.

dpllsim_available() still counts a built-in simulator as available. Once /sys/kernel/config/dpllsim exists it returns 0, and it ignores the modprobe result:

	[ -d "$DPLLSIM_CFG" ] && return 0

So the scripts create and deploy a device that their own lookup cannot find:

In dpll_basic.sh, dpllsim_setup_standard_device() calls dpll_device_wait_by_clock_id "$clock_id" dpllsim. busywait runs until BUSYWAIT_TIMEOUT, and the script then prints "FAIL: cannot create dpllsim device" and exits with ksft_fail.

In dpll_stress.sh, test_deploy_cycle() fails on its first iteration with "device not on netlink".

The default branch of dpll_lib_init() has a related problem:

	select(.["module-name"] != "dpllsim")

This does not exclude a leftover built-in dpllsim device, so that device would be tested as if it were hardware.

The later patches in the series (the pin flooding and many-devices tests) still use the same module-name filter, so they do not fix this.

Could the lookups handle a built-in dpllsim, or should the scripts skip when dpllsim is not a module?

Quoted 5 lines
tools/testing/selftests/drivers/dpll/dpll_stress.sh new file +0 -0
new file mode 100755
index 0000000000000..01d57ab0172b0

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_stress.sh line 46

Quoted 6 lines
tools/testing/selftests/drivers/dpll/dpll_stress.sh new file +6 -0
+cleanup()
+{
+	local dev
+
+	# A second signal must not abort the teardown half way.
+	trap '' INT TERM

[Severity: Low]
Can a second signal still abort the teardown here? The script sets up its traps like this:

trap cleanup EXIT
trap 'exit 1' INT TERM

The INT/TERM handler stays "exit 1" until cleanup() itself runs trap '' INT TERM, and here "local dev" runs before that.

If another INT or TERM is handled at that command boundary, exit 1 runs inside the EXIT trap. bash does not run the EXIT trap a second time, so the shell exits without running:

- the CREATED_DEVICES loop
- the DPLLSIM_CREATED_NAME delete
- dpll_lib_cleanup()

The simulated devices and the configfs mount from this run would then be left behind.

dpll_basic.sh uses the same trap pattern. Its cleanup() runs the ignore first, which makes the window smaller but does not remove it.

The window is still there at the end of the series. There, cleanup() in dpll_stress.sh runs "local pid dev base" and "local pids=() shell_jobs=()" before the ignore.

Would it be better to ignore the signals in the handler itself? For example:

trap 'trap "" INT TERM; exit 1' INT TERM

Or at least make the ignore the first statement of every cleanup()?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112130359.840795-1-poros%40redhat.com
author
#4 lore raw

PATCH v4 3/14 dpll: dpllsim: Add configurable pins

In reply to Petr Oros

Pins are the unit of most DPLL netlink interaction, so let a device instance carry a set of up to 128 of them. Each directory created under the pins/ group of an instance is one pin with type, frequency and direction attributes. The type takes the names of the DPLL pin type enum as iproute2 prints them, the direction is input or output and the frequency must be one of the frequencies the driver advertises as supported for the type. The pin directory name becomes the board label of the pin, which gives tests a stable handle to find a pin by. The attributes are writable only while the instance is not live and return EBUSY otherwise.

At live=1 the pins are ordered as created and each pin records its index in that order, which is the pin index it is registered under. Their frequencies are validated against the per type tables, a MUX pin configured as output is rejected since a MUX pin stands for an input selector, and all pin handles are obtained up front, so that a failure leaves nothing half visible. The device is registered first and the pins after it, so that every pin registration event reaches userspace with a valid device, and a failure unwinds exactly what was registered in reverse order. While the instance is live the pin items are held with configfs_depend_item_unlocked(), which makes rmdir of a pin fail with EBUSY until the instance is taken down. configfs calls make_item and drop_item under the subsystem mutex but links and unlinks the pin directory outside of it, so a live transition racing with a pin mkdir or rmdir can find a pin it cannot hold and fails with ENOENT then.

The pins register with the mandatory callbacks only, direction_get and state_on_dpll_get, plus frequency_get since the frequency is known from the configuration. The input and output ops tables are identical here and diverge when input pins gain their setters in the next patches. The state is always reported as disconnected for now, the settable pin features follow in separate patches.

---
v4:
- document the limit of 128 pins, that pins cannot be added to a live instance, the frequencies each pin type supports and the errors of the live write
- correct the comments on what the subsystem mutex covers, a live write racing with a pin mkdir or rmdir fails with ENOENT

v3: https://lore.kernel.org/all/[email protected]/

---
 Documentation/driver-api/dpllsim.rst |  57 +++++-
 drivers/dpll/dpllsim/core.c          | 234 +++++++++++++++++++++-
 drivers/dpll/dpllsim/dpll.c          | 280 ++++++++++++++++++++++++++-
 drivers/dpll/dpllsim/dpllsim.h       |  32 +++
 4 files changed, 591 insertions(+), 12 deletions(-)
Documentation/driver-api/dpllsim.rst +50 -7
index 86a5d523534055..a0e5ea44d2c6d3 100644
@@ -12,10 +12,13 @@ Configuration interface
 =======================
 
 Devices are described in configfs under ``/sys/kernel/config/dpllsim/``.
-A directory created there is a device instance. Attributes are written
-while the instance is not live, then ``live`` is set to 1 to register
-the device with the DPLL subsystem. Writing 0 unregisters it again.
-Structural attributes return ``EBUSY`` while the instance is live.
+A directory created there is a device instance, a directory created in
+its ``pins/`` subdirectory is a pin. Attributes are written while the
+instance is not live, then ``live`` is set to 1 to register the device
+and its pins with the DPLL subsystem. Writing 0 unregisters everything
+again. Structural attributes return ``EBUSY`` while the instance is live
+and pins of a live instance can neither be added nor removed. An
+instance holds up to 128 pins, creating one more fails with ``ENOSPC``.
 
 Device directory ``/sys/kernel/config/dpllsim/<dev>/``:
 
@@ -25,17 +28,57 @@ Device directory ``/sys/kernel/config/dpllsim/<dev>/``:
 ``live``                 1 registers the device, 0 unregisters it
 =======================  =====================================================
 
+Pin directory ``/sys/kernel/config/dpllsim/<dev>/pins/<pin>/``:
+
+=============  ===============================================================
+``type``       ``gnss``, ``int-oscillator``, ``ext``, ``synce-eth-port`` or
+               ``mux`` (default ``ext``)
+``frequency``  Frequency in Hz, must be supported by the pin type
+               (default 0, which is rejected)
+``direction``  ``input`` or ``output`` (default ``input``), a ``mux`` pin
+               must be an input
+=============  ===============================================================
+
+The pin directory name becomes the board label of the pin. Pins are
+registered in the order the directories were created.
+
+The frequencies a pin type supports:
+
+==================  ==========================================================
+``gnss``            1 Hz
+``int-oscillator``  25 MHz
+``synce-eth-port``  1.544 MHz, 2.048 MHz, 10 MHz and 25 MHz
+``mux``             same as ``synce-eth-port``
+``ext``             1 Hz, 10 MHz, 19.44 MHz, 25 MHz, 77.76 MHz, 125 MHz and
+                    156.25 MHz
+==================  ==========================================================
+
+The pin configuration is checked when 1 is written to ``live``. The
+write fails with ``EINVAL`` when a pin has a frequency its type does not
+support or when a ``mux`` pin is an output, and with ``ENOENT`` when a
+pin directory is being created or removed at the same time.
+
 Example
 =======
 
-Create a device and make it live::
+Create a device with a GNSS input, an external input and an external
+output, then make it live::
 
     cd /sys/kernel/config/dpllsim
     mkdir dev0 && cd dev0
     echo 100 > clock_id
+    mkdir pins/gnss0
+    echo gnss > pins/gnss0/type
+    echo 1 > pins/gnss0/frequency
+    mkdir pins/ext0
+    echo 10000000 > pins/ext0/frequency
+    mkdir pins/out0
+    echo 10000000 > pins/out0/frequency
+    echo output > pins/out0/direction
     echo 1 > live
 
     dpll device show
+    dpll pin show
 
-To remove the device, write 0 to ``live`` and remove the device
-directory.
+To remove the device, write 0 to ``live``, remove the pin directories
+and finally the device directory.
drivers/dpll/dpllsim/core.c +231 -3

285 lines not on this page · raw message

drivers/dpll/dpllsim/dpll.c +278 -2

325 lines not on this page · raw message

drivers/dpll/dpllsim/dpllsim.h +32 -0
index 5667f8827c98c1..73b846b66f79c7 100644
@@ -9,10 +9,39 @@
 
 #include <linux/configfs.h>
 #include <linux/dpll.h>
+#include <linux/list.h>
 #include <linux/mutex.h>
 
+#define DPLLSIM_MAX_PINS			128
+
+struct dpllsim_dev;
+
+struct dpllsim_pin {
+	struct config_item item;
+	struct list_head list;
+	struct dpllsim_dev *dev;
+
+	/* Configuration, writable only until dpllsim_dev_frozen() */
+	enum dpll_pin_type type;
+	enum dpll_pin_direction direction;
+	u64 frequency;
+
+	/* Resolved at live=1 */
+	int idx;
+	struct dpll_pin *dpll_pin;
+	const struct dpll_pin_ops *ops;
+	dpll_tracker tracker;
+	bool registered;
+
+	/* Simulated state, guarded by dev->lock */
+	enum dpll_pin_state state;
+};
+
 struct dpllsim_dev {
 	struct config_group group;
+	struct config_group pins_group;
+	/* Pin items, guarded by the configfs subsystem mutex */
+	struct list_head pin_list;
 
 	/*
 	 * Set from the start of a live transition until the device is
@@ -27,6 +56,9 @@ struct dpllsim_dev {
 	 * the live attribute reports, see dpllsim_dev_live().
 	 */
 	bool registered;
+	/* Pins in registration order, valid while @dpll is set */
+	struct dpllsim_pin **pins;
+	int num_pins;
 
 	/* Guarded by the subsystem mutex */
 	u64 clock_id;
Signature · 1 line
2.56.0
author
#5 lore raw

PATCH v4 4/14 selftests: dpll: add pin enumeration and property tests

In reply to Petr Oros

Extend the library with pin queries. Pins of a device are collected from the full pin dump with jq, since older iproute2 lacks the device filter of "pin show", and the fields that live in the parent-device nest are read through a helper that selects the nest of the device under test. The helpers that work on the full dump normalize its shape the same way the id-based ones do, so that a tool printing a flat object instead of the dump wrapper works with all of them. Like the device queries, every pin query runs the tool first and jq on what it printed, so that a query which fails returns the status of the tool instead of the empty output a missing attribute produces too. The prerequisite check now also requires a tool that knows "pin show", so that a tool too old for the pin queries is a skip up front rather than a failed query in every test. The dpllsim helpers gain dpllsim_add_pin, which creates a pin directory and writes its type, frequency and direction, and the standard device grows a GNSS input, an external input and an external output.

The helpers that print a list of pin ids are read through dpll_pin_ids_read, which keeps their status where a process substitution or a pipeline would drop it, so that a pin dump that fails is reported as a failure rather than as a device without pins.

dpll_basic.sh checks that the enumeration yields a numeric id for every pin of the device, the ids are taken from the dump as they are and jq prints null for a pin without one, that every pin has an id and a type and carries the direction in the parent-device nest, and that an input pin reports a valid state. The property test does not go on to query pins by an id that is not one, and reports a pin it cannot query at all as one failure rather than as one per attribute. The frequency is not required, a pin without a frequency callback does not report one. The device the script created has the standard pins, so an empty pin list or a missing input pin on it means a failed query or broken tooling rather than a pinless device. The library gains dpll_log_test_skip_or_fail for such conditions, which fails on the device the script created, recorded in DPLL_CREATED_DEVICE next to DPLL_DEV_ID, and skips on a device the user provided. The stress script creates its devices with a random set of pins of every type and both directions, MUX pins always as inputs, and the deploy cycle test runs with the standard pin set.

---
v4:
- read the pin lists through dpll_pin_ids_read, which keeps the status of the dump, so that a failed dump is a failure and not a device without pins
- correct the comment on pins without a parent-device nest

v3:
- follow the move of the selftests to
tools/testing/selftests/drivers/dpll

v2:
- quote the ksft_skip and ret expansions (netdev CI shellcheck)

v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

---
 .../selftests/drivers/dpll/dpll_basic.sh      | 164 +++++++++++++-
 .../selftests/drivers/dpll/dpll_lib.sh        | 205 +++++++++++++++++-
 .../selftests/drivers/dpll/dpll_stress.sh     |  46 +++-
 3 files changed, 390 insertions(+), 25 deletions(-)
tools/testing/selftests/drivers/dpll/dpll_basic.sh +154 -10
index 2f9a4370088a79..c6b223d1368c4a 100755
@@ -1,11 +1,12 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 #
-# Basic DPLL subsystem test. Read-only validation of the device properties
-# exposed over netlink. Runs against a hardware DPLL device when one is
-# present (or when DPLL_DEV_ID is set), otherwise against a freshly
-# created dpllsim device. DPLL_DRIVER names the driver to take the
-# device from, dpllsim for a created one although hardware is present.
+# Basic DPLL subsystem test. Read-only validation of device and pin
+# enumeration and of the properties exposed over netlink. Runs against a
+# hardware DPLL device when one is present (or when DPLL_DEV_ID is set),
+# otherwise against a freshly created dpllsim device. DPLL_DRIVER names
+# the driver to take the device from, dpllsim for a created one although
+# hardware is present.
 #
 # Copyright (c) 2026 Red Hat, Inc.
 
@@ -16,8 +17,29 @@ source "$SCRIPTDIR/dpll_lib.sh"
 
 ALL_TESTS="
 	test_device_properties
+	test_pin_enumeration
+	test_pin_properties
+	test_pin_state
 "
 
+# Fail on every entry of a pin id list that is not a number. The ids are
+# taken from the dump as they are, so a pin without one shows up as the
+# "null" jq prints for a missing field, not as an empty line. Return 1
+# when any entry is invalid.
+check_pin_ids()
+{
+	local id ret=0
+
+	for id in "$@"; do
+		if ! [[ "$id" =~ ^[0-9]+$ ]]; then
+			check_err 1 "invalid pin id '$id'"
+			ret=1
+		fi
+	done
+
+	return "$ret"
+}
+
 test_device_properties()
 {
 	local json
@@ -43,6 +65,129 @@ test_device_properties()
 	log_test "DPLL device properties"
 }
 
+test_pin_enumeration()
+{
+	local pin_ids
+
+	RET=0
+
+	# A dump that failed is not a device without pins.
+	if ! dpll_pin_ids_read pin_ids dpll_pin_get_ids "$DPLL_DEV_ID"; then
+		check_err 1 "pin dump failed"
+		log_test "DPLL pin enumeration"
+		return
+	fi
+	if [ "${#pin_ids[@]}" -eq 0 ]; then
+		dpll_log_test_skip_or_fail "DPLL pin enumeration" \
+		    "no pins found"
+		return
+	fi
+	check_pin_ids "${pin_ids[@]}"
+
+	log_test "DPLL pin enumeration (${#pin_ids[@]} pins)"
+}
+
+check_pin_properties()
+{
+	local pin_id=$1
+	local json field
+
+	# A pin that cannot be queried at all would be reported as one
+	# that misses every attribute, so bail out on that first.
+	if ! json=$(dpll_pin_json "$pin_id") || [ -z "$json" ]; then
+		check_err 1 "pin $pin_id query failed"
+		return
+	fi
+
+	# Frequency is optional, a pin without a frequency callback such
+	# as a recovered clock pin does not report it.
+	for field in '.id' '.type'; do
+		if ! jq -e "$field" <<< "$json" &> /dev/null; then
+			check_err 1 \
+			    "pin $pin_id is missing the $field attribute"
+		fi
+	done
+
+	# A pin registered on a parent pin has no parent-device nest, but
+	# when the device under test is in it, that entry must carry the
+	# direction. A pin can be registered on more than one device, so
+	# match on parent-id instead of taking the first entry.
+	if jq -e --argjson dev "$DPLL_DEV_ID" \
+		'[.["parent-device"][]? | select(.["parent-id"] == $dev)] |
+		 length > 0' <<< "$json" &> /dev/null; then
+		if ! jq -e --argjson dev "$DPLL_DEV_ID" \
+			'.["parent-device"][]? |
+			 select(.["parent-id"] == $dev) | .direction' \
+			<<< "$json" &> /dev/null; then
+			check_err 1 \
+			    "pin $pin_id parent-device is missing direction"
+		fi
+	fi
+}
+
+test_pin_properties()
+{
+	local pin_ids pin_id
+
+	RET=0
+
+	if ! dpll_pin_ids_read pin_ids dpll_pin_get_ids "$DPLL_DEV_ID"; then
+		check_err 1 "pin dump failed"
+		log_test "DPLL pin properties"
+		return
+	fi
+	if [ "${#pin_ids[@]}" -eq 0 ]; then
+		dpll_log_test_skip_or_fail "DPLL pin properties" "no pins found"
+		return
+	fi
+	if ! check_pin_ids "${pin_ids[@]}"; then
+		log_test "DPLL pin properties"
+		return
+	fi
+
+	for pin_id in "${pin_ids[@]}"; do
+		check_pin_properties "$pin_id"
+	done
+
+	log_test "DPLL pin properties (${#pin_ids[@]} pins)"
+}
+
+test_pin_state()
+{
+	local pin_ids pin_id state
+
+	RET=0
+
+	if ! dpll_pin_ids_read pin_ids dpll_pin_find_by_direction \
+			       "$DPLL_DEV_ID" input; then
+		check_err 1 "pin dump failed"
+		log_test "DPLL pin state"
+		return
+	fi
+	pin_id=${pin_ids[0]:-}
+	if [ -z "$pin_id" ]; then
+		dpll_log_test_skip_or_fail "DPLL pin state" "no input pin"
+		return
+	fi
+
+	# The pin was found through its parent-device nest for this device
+	# and the state is mandatory there, so an empty value is a failed
+	# query rather than a state.
+	state=$(dpll_pin_get_state "$DPLL_DEV_ID" "$pin_id")
+	case "$state" in
+	"")
+		check_err 1 "cannot read the state of pin $pin_id"
+		;;
+	connected|disconnected|selectable)
+		;;
+	*)
+		check_err 1 "pin $pin_id reports invalid state '$state'"
+		;;
+	esac
+
+	log_test "DPLL pin state"
+}
+
 ##############################################################################
 
 cleanup()
@@ -50,9 +195,9 @@ cleanup()
 	# A second signal must not abort the teardown half way.
 	trap '' INT TERM
 
-	if [ -n "$CREATED_DEVICE" ]; then
-		dpllsim_delete_device "$CREATED_DEVICE" ||
-			log_info "cannot delete device $CREATED_DEVICE"
+	if [ -n "$DPLL_CREATED_DEVICE" ]; then
+		dpllsim_delete_device "$DPLL_CREATED_DEVICE" ||
+			log_info "cannot delete device $DPLL_CREATED_DEVICE"
 	fi
 	# The device whose creation a signal interrupted is recorded by the
 	# library alone, a double delete of a tracked one is harmless.
@@ -68,7 +213,6 @@ dpll_lib_check_prereqs
 # lock in the library.
 dpll_lib_lock
 
-CREATED_DEVICE=""
 # The device selection and the module check may mount configfs, so the
 # exit trap that unmounts it again has to be in place before. INT and
 # TERM exit through it as well, so that a timeout imposed by the harness
@@ -86,8 +230,8 @@ if [ -z "$DPLL_DEV_ID" ]; then
 		echo "FAIL: cannot create dpllsim device"
 		exit "$ksft_fail"
 	fi
-	CREATED_DEVICE=$DPLLSIM_CREATED_NAME
 	DPLL_DEV_ID=$DPLLSIM_DEV_ID
+	DPLL_CREATED_DEVICE=$DPLLSIM_CREATED_NAME
 	DPLL_MODULE_NAME="dpllsim"
 fi
 
tools/testing/selftests/drivers/dpll/dpll_lib.sh +193 -12

262 lines not on this page · raw message

tools/testing/selftests/drivers/dpll/dpll_stress.sh +43 -3

71 lines not on this page · raw message

Signature · 1 line
2.56.0
author
#6 lore raw

PATCH v4 5/14 dpll: dpllsim: Add support to set input pin state

In reply to Petr Oros

Add support for setting the state of input pins on the device. Implement the state_on_dpll_set callback for input pins and advertise the state-can-change capability for them, so that userspace can move a pin between the states valid for the device mode. The core checks the capability only, the states a mode allows are up to the driver: in automatic mode a pin is selectable or disconnected, in manual mode connected or disconnected, as Documentation/driver-api/dpll.rst describes them. The device reports automatic mode, so connected is refused with -EINVAL and an extack message. The check is written for both modes already, so that manual mode has nothing to add to it when it arrives. The driver stores the requested state and reports it back unchanged, it does not act on it yet. Output pins keep reporting their state only.

---
v4:
- no change, add the Reviewed-by given to v3 (Ivan Vecera)

v3:
- refuse pin states that are not valid in the device mode, so that connected is refused in automatic mode, the mode the device reports, with an extack message (Ivan Vecera)
- the Acked-by of v2 is not carried over, the callback changed

v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

---
 drivers/dpll/dpllsim/dpll.c | 42 +++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
drivers/dpll/dpllsim/dpll.c +42 -0
index a1d5921fb8d017..794020d0c112e8 100644
@@ -104,10 +104,46 @@ static int dpllsim_pin_state_get(const struct dpll_pin *pin, void *pin_priv,
 	return 0;
 }
 
+/*
+ * The states a user may request depend on the device mode: connected and
+ * disconnected select and deselect the reference in manual mode, selectable
+ * and disconnected offer a pin to or withdraw it from the automatic
+ * selection. The core checks the state-can-change capability only.
+ */
+static bool dpllsim_pin_state_valid(const struct dpllsim_dev *sim,
+				    enum dpll_pin_state state)
+{
+	if (state == DPLL_PIN_STATE_DISCONNECTED)
+		return true;
+	if (sim->mode == DPLL_MODE_MANUAL)
+		return state == DPLL_PIN_STATE_CONNECTED;
+	return state == DPLL_PIN_STATE_SELECTABLE;
+}
+
+static int dpllsim_pin_state_set(const struct dpll_pin *pin, void *pin_priv,
+				 const struct dpll_device *dpll,
+				 void *dpll_priv, enum dpll_pin_state state,
+				 struct netlink_ext_ack *extack)
+{
+	struct dpllsim_pin *sim_pin = pin_priv;
+	struct dpllsim_dev *sim = sim_pin->dev;
+
+	guard(mutex)(&sim->lock);
+	if (!dpllsim_pin_state_valid(sim, state)) {
+		NL_SET_ERR_MSG_FMT(extack, "Pin state not valid in %s mode",
+				   sim->mode == DPLL_MODE_MANUAL ?
+				   "manual" : "automatic");
+		return -EINVAL;
+	}
+	sim_pin->state = state;
+	return 0;
+}
+
 static const struct dpll_pin_ops dpllsim_input_pin_ops = {
 	.frequency_get = dpllsim_pin_frequency_get,
 	.direction_get = dpllsim_pin_direction_get,
 	.state_on_dpll_get = dpllsim_pin_state_get,
+	.state_on_dpll_set = dpllsim_pin_state_set,
 };
 
 static const struct dpll_pin_ops dpllsim_output_pin_ops = {
@@ -149,6 +185,12 @@ static void dpllsim_pin_props(struct dpllsim_pin *pin,
 		prop->freq_supported_num = ARRAY_SIZE(dpllsim_freq_ext);
 		break;
 	}
+
+	/* Capabilities follow the ops the pin is served by */
+	if (dpllsim_pin_select_ops(pin) == &dpllsim_input_pin_ops)
+		prop->capabilities = DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE;
+	else
+		prop->capabilities = 0;
 }
 
 static bool dpllsim_pin_frequency_valid(struct dpllsim_pin *pin)
Signature · 1 line
2.56.0
author
#7 lore raw

PATCH v4 6/14 selftests: dpll: add pin state tests

In reply to Petr Oros

Add dpll_features.sh, a script that exercises individual device and pin callbacks with get/set roundtrips over netlink. It creates a dpllsim device with the standard pin layout by default or runs against the device named by DPLL_DEV_ID or the first device of the driver named by DPLL_DRIVER, and picks the pin to reconfigure up front, so that no test touches the reference the device is locked to. The pin is an input that is disconnected or selectable on the device and that none of its parent devices reports as connected or, where the tool prints the operational state, as active, since a pin can be registered on several devices. When the first input pin and another one both qualify the other one is taken, drivers tend to list their primary reference first. On hardware a spare pin with a valid signal can still be selected while a test reconfigures it, which the header of the script points out.

The first test moves that pin through the states of the device mode, as Documentation/driver-api/dpll.rst defines them, reads the state back after each step and restores the original state at the end. In automatic mode these are disconnected and selectable, and on the device the script created the test then checks that connected is refused. Hardware drivers are not held to that, ice accepts connected in automatic mode, and a pin with the state-connected-override capability would take over the reference. In manual mode connected and disconnected
are the states, connecting the pin makes it the reference, so the test finds the pin connected before, connects it back at the end and checks that it is the reference again.

A driver may refuse a state the capability promises, for a constraint the interface does not tell. That is a skip on a device provided by the user, with the reason the tool reported, and a failure on the device the script created, whose simulator accepts both states of its mode. A refusal that follows a failed readback leaves the test failed, dpll_log_test_skip_or_fail no longer turns a recorded failure into a skip. The restores are deferred right after the original states are read, the reconnect of the reference first, since deferred commands run last in first out and the test pin has to be disconnected again before the reference is connected back. The cleanup handler of every script that defers runs the pending restores before it removes the devices the script created, so that an interrupted run puts the device back as well. defer drops the status of what it runs, so the restores go through dpll_restore, which logs one that fails. A pin that cannot be queried is a failure, not a pin that is in use or lacks a capability.

The stress script gains a test that floods one input pin of a fresh device with changes between the states of automatic mode and ends on selectable, the state a fresh pin is not in, so that the readback after the flood catches a setter that stores nothing. The library gains the state setter both use, which keeps the extack line of the tool in DPLL_LAST_ERR so that a test can tell a refusal from a failure, the device mode getter, and a check whether the pin set usage of the tool knows a keyword, so that a test skips on a tool too old for it rather than every script requiring a newer tool.

---
v4:
- defer the reconnect of the reference before the restore of the test pin, deferred commands run last in first out
- do not let a refusal turn a test that already failed into a skip
- pick the spare pin by all its parent devices and by the operational state where the tool prints it, and leave it alone when the automatic selection took it in the meantime
- accept connected when a pin was set selectable in automatic mode, the device may pick the pin it was offered as its reference, also when the restore makes it selectable again
- end the state flood on selectable, so that the readback catches a setter that stores nothing
- fail when the pin dump fails or the simulated device cannot be created
- say in the header what the tests change on a device the user provided
- log a deferred restore that fails, defer drops the status of what it runs
- tell a pin that could not be queried from one that is in use or lacks a capability, and log the reason of a refusal that follows a failure
- take the number of state changes of the flood from one variable
- add the Reviewed-by given to v3 (Ivan Vecera)

v3:
- follow the mode of the device under test: disconnected and selectable in automatic mode, where the simulator is checked to refuse connected, connected and disconnected in manual mode, where the pin connected before is connected back at the end
- cycle the state flooding test through the states of automatic mode
- add the device mode getter to the library
- honor DPLL_DRIVER like dpll_basic.sh does
- follow the move of the selftests to tools/testing/selftests/drivers/dpll
- the Reviewed-by and Acked-by of v2 are not carried over, the state test changed

v2:
- quote the ksft_skip expansion (netdev CI shellcheck)

v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

---
 tools/testing/selftests/drivers/dpll/Makefile |   1 +
 .../selftests/drivers/dpll/dpll_features.sh   | 339 ++++++++++++++++++
 .../selftests/drivers/dpll/dpll_lib.sh        | 102 +++++-
 .../selftests/drivers/dpll/dpll_stress.sh     |  73 ++++
 4 files changed, 513 insertions(+), 2 deletions(-)
 create mode 100755 tools/testing/selftests/drivers/dpll/dpll_features.sh
tools/testing/selftests/drivers/dpll/Makefile +1 -0
index 7e839ae71cd22f..1349d078fa2660 100644
@@ -9,6 +9,7 @@ TEST_FILES := dpll_lib.sh
 
 TEST_PROGS := \
 	dpll_basic.sh \
+	dpll_features.sh \
 	dpll_stress.sh \
 # end of TEST_PROGS
 
tools/testing/selftests/drivers/dpll/dpll_features.sh new file +339 -0

339 lines not on this page · raw message

tools/testing/selftests/drivers/dpll/dpll_lib.sh +100 -2

138 lines not on this page · raw message

tools/testing/selftests/drivers/dpll/dpll_stress.sh +73 -0

91 lines not on this page · raw message

Signature · 1 line
2.56.0
#8 lore raw

Re: [PATCH net-next v4 06/14] selftests: dpll: add pin state tests

Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 4 · Low: 5

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] In test_pin_state_transitions, the guard against touching a pin that automatic selection has since locked onto only checks the…
- [Medium] In manual mode, test_pin_state_transitions finds the reference to restore with find_connected_pin(), which only searches input_pins.
- [Medium] pin_is_spare() and pick_tune_pin() never check the pin type, so zl3073x's internal NCO pseudo-input can be chosen as PIN_TUNE_ID.
- [Medium] test_pin_state_transitions assumes that 'manual' means one connected reference, and that reconnecting it restores the device.
- [Low] The commit message and the script header say the reference is never touched, but in manual mode the test takes the reference over on…
- [Low] Both state tests accept 'connected' as the readback after 'selectable' was set in automatic mode, even on dpllsim devices the…
- [Low] In dpll_lib.sh, the comment on dpll_pin_set_supports says the keyword 'must stand on its own between blanks or brackets'.
- [Low] test_pin_state_transitions ignores the exit status of mode=$(dpll_device_get_mode ...) (line 98) and of…
- [Low] In manual mode, the deferred restore of PIN_TUNE_ID to before (line 144) still runs after the test body has already restored…

--

selftests: dpll: add pin state tests

This adds dpll_features.sh. Its test moves a spare input pin through the states of the device mode and then restores it. It runs on a dpllsim device it creates, or on a device the user names. It also adds a state flooding test to dpll_stress.sh, plus library helpers for the pin state setter, the device mode getter, deferred restores and a dpll tool keyword check.

Quoted 8 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh new file +2 -0
new file mode 100755
index 0000000000000..0a00a18bded2c
@@ -0,0 +1,339 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_features.sh line 16

Quoted 5 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh new file +5 -0
+# The tests reconfigure a spare input pin of the device and restore it
+# afterwards, see pick_tune_pin. A pin the device uses as its reference
+# is never picked, but on hardware a spare pin that carries a valid
+# signal can still be selected while a test reconfigures it, so do not
+# point the script at a device whose reference must not be disturbed.

[Severity: Low]
The header says a pin used as the reference is never picked. The commit message says the pin is picked up front:

"so that no test touches the reference the device is locked to"

Does that hold in manual mode? test_pin_state_transitions() uses:

manual)
states="connected disconnected"

Connecting PIN_TUNE_ID makes it the reference in place of the locked one. Disconnecting it then leaves the device with no reference until ref_pin is connected back. This happens on every manual mode run, whether or not the spare pin carries a valid signal.

A later paragraph of the commit message says as much ("connecting the pin makes it the reference ... connects it back at the end"), which contradicts the earlier claim.

Could the header and the commit message say that manual mode switches the reference away and back on purpose?

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_features.sh line 48

Quoted 12 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh new file +12 -0
+find_connected_pin()
+{
+	local pin_id
+
+	for pin_id in "${input_pins[@]}"; do
+		if [ "$(dpll_pin_get_state "$DPLL_DEV_ID" "$pin_id")" = \
+		     connected ]; then
+			echo "$pin_id"
+			return
+		fi
+	done
+}

[Severity: Medium]
Can this miss the manual mode reference? input_pins comes from dpll_pin_find_by_direction(), which drops mux-typed pins:

	   '(.pin? // [.])[] | select(.type != "mux") |

This loop also ignores the exit status of dpll_pin_get_state(), so a failed query looks like a pin that is not connected.

zl3073x supports manual mode, and zl3073x_pin_props_get() can give input pins DPLL_PIN_TYPE_MUX from firmware properties. ice registers mux-typed direct inputs as well.

If the reference is such a pin, or its state query fails, ref_pin stays empty in test_pin_state_transitions():

		ref_pin=$(find_connected_pin)
		if [ -n "$ref_pin" ]; then
			defer dpll_restore dpll_pin_set_state "$DPLL_DEV_ID" \
			      "$ref_pin" connected
		fi

Then neither the deferred reconnect nor the one at the end of the test runs. The loop still connects PIN_TUNE_ID, which displaces the real reference, and then disconnects it. Only PIN_TUNE_ID goes back to $before.

Would the device be left without its reference while the test reports a pass?

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_features.sh line 105

Quoted 8 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh new file +8 -0
+	mode=$(dpll_device_get_mode "$DPLL_DEV_ID")
+	case "$mode" in
+	automatic)
+		states="disconnected selectable"
+		;;
+	manual)
+		states="connected disconnected"
+		;;

[Severity: Medium]
Does a mode of manual always mean one connected reference that can simply be reconnected? zl3073x_dpll_mode_get() reports DPLL_MODE_MANUAL for the freerun, holdover, NCO and reflock refsel modes.

In freerun or holdover every ref reads disconnected, so find_connected_pin() returns nothing and ref_pin is empty. The connected step then makes zl3073x_dpll_input_pin_state_on_dpll_set() select PIN_TUNE_ID and switch to reflock:

	case ZL_DPLL_MODE_REFSEL_MODE_FREERUN:
	case ZL_DPLL_MODE_REFSEL_MODE_HOLDOVER:
		if (state == DPLL_PIN_STATE_CONNECTED) {
			/* Choose the pin as new selected reference */
			zl3073x_chan_ref_set(&chan, ref);
			/* Switch to reflock mode */

The disconnected step then picks holdover or freerun from the cached lock_status. A channel that started in holdover can end in freerun, or in a holdover that is now based on PIN_TUNE_ID.

The original refsel mode is never saved or restored. Every pin reads disconnected again, so the test passes.

In NCO mode the NCO pin is the connected input and becomes ref_pin. Connecting PIN_TUNE_ID leaves NCO mode, which steps the ToD and clears the PPS TIE. Reconnecting the NCO pin re-enters NCO mode, and nco_auto_read captures the current tracking offset, not the offset userspace had programmed.

Should the test skip in manual mode when no regular input is connected, or save and restore the refsel mode?

tools/testing/selftests/drivers/dpll/dpll_features.sh line 118

Quoted 13 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh new file +13 -0
+	*)
+		dpll_log_test_skip_or_fail "DPLL pin state transitions" \
+		    "device mode '$mode' not handled"
+		return
+		;;
+	esac
+
+	before=$(dpll_pin_get_state "$DPLL_DEV_ID" "$PIN_TUNE_ID")
+	if [ -z "$before" ]; then
+		dpll_log_test_skip_or_fail "DPLL pin state transitions" \
+		    "state not reported"
+		return
+	fi

[Severity: Low]
__dpll_device_field() and __dpll_pin_dev_field() return 1 when the dpll tool fails. The status of the mode= and before= assignments is dropped here, though. On a device the user provided, a failed query is then logged as a skip, with "device mode '' not handled" or "state not reported".

The commit message says "A pin that cannot be queried is a failure, not a pin that is in use or lacks a capability". pin_is_spare() and dpll_pin_has_capability() return 2 for exactly that case.

Should these two queries be reported as failures as well?

tools/testing/selftests/drivers/dpll/dpll_features.sh line 125

Quoted 7 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh new file +7 -0
+	# The automatic selection may have taken the pin since it was
+	# picked, it is the reference then and not to be touched.
+	if [ "$mode" = automatic ] && [ "$before" = connected ]; then
+		dpll_log_test_skip_or_fail "DPLL pin state transitions" \
+		    "spare input pin became the reference"
+		return
+	fi

[Severity: Medium]
Is the admin state enough to tell that the automatic selection took this pin? Documentation/driver-api/dpll.rst says the pin state reflects the administrative intent, while the operstate reflects what the hardware actually does with the pin.

In automatic mode, zl3073x_dpll_input_pin_state_on_dpll_get() reports selectable for the active ref too:

	case ZL_DPLL_MODE_REFSEL_MODE_AUTO:
		if (zl3073x_chan_ref_is_selectable(chan, ref))
			*state = DPLL_PIN_STATE_SELECTABLE;

pin_is_spare() already rejects .operstate == "active", but this check does not. Suppose PIN_TUNE_ID becomes the active reference after pick_tune_pin() ran. On zl3073x this check passes, and the loop sets the pin to disconnected, which withdraws the reference the device is locked to.

The loop comment ("the pin reports connected then") seems to rest on the same assumption.

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_features.sh line 145

Quoted 3 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh new file +3 -0
+	# Restore the original state even when the test aborts half way.
+	defer dpll_restore dpll_pin_set_state "$DPLL_DEV_ID" "$PIN_TUNE_ID" \
+	      "$before"

[Severity: Low]
In manual mode, does this restore run a second time after the test body has already put both pins back? On a successful run, the end of the test sets PIN_TUNE_ID to $before and reconnects ref_pin:

	if [ -n "$ref_pin" ]; then
		dpll_pin_set_state "$DPLL_DEV_ID" "$ref_pin" connected

The deferred commands then run last in first out. PIN_TUNE_ID is set to disconnected again while the channel is locked to ref_pin, and only after that is ref_pin connected.

In zl3073x_dpll_input_pin_state_on_dpll_set(), DPLL_PIN_STATE_DISCONNECTED in reflock mode switches the channel to holdover or freerun. It does not check whether the pin is the selected ref:

		} else if (state == DPLL_PIN_STATE_DISCONNECTED) {
			/* Choose new mode based on lock status */
			switch (zldpll->lock_status) {

So the device loses its reference a second time. If the deferred reconnect then fails, dpll_restore() only logs it, and the device stays in holdover or freerun.

[ ... ]

Quoted 13 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh new file +13 -0
+pin_is_spare()
+{
+	local out
+
+	out=$(dpll pin show id "$2" -j 2>/dev/null) || return 2
+	jq -e --argjson dev "$1" '
+		(.pin[0]? // .) | [.["parent-device"][]?] |
+		any(.[]; .["parent-id"] == $dev and
+			 (.state == "disconnected" or
+			  .state == "selectable")) and
+		all(.[]; .state != "connected" and .operstate != "active")' \
+		<<< "$out" &> /dev/null || return 1
+}

[ ... ]

Quoted 7 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh new file +7 -0
+pick_tune_pin()
+{
+	local pin_id
+
+	PIN_TUNE_ID=""
+	for pin_id in "${input_pins[@]}"; do
+		pin_is_spare "$DPLL_DEV_ID" "$pin_id"

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_features.sh line 327

Quoted 4 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh new file +4 -0
+		PIN_TUNE_ID=$pin_id
+		[ "$pin_id" != "${input_pins[0]}" ] && return
+	done
+}

[Severity: Medium]
Can this pick the zl3073x NCO pseudo-input as PIN_TUNE_ID?

zl3073x_dpll_nco_pin_register() registers that pin with DPLL_PIN_DIRECTION_INPUT, DPLL_PIN_TYPE_INT_NCO and DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE, after all the ref pins. Outside NCO mode it reports disconnected and standby, so pin_is_spare() accepts it.

The NCO pin is dumped last. So when input_pins[0] is spare and no other ref qualifies, pick_tune_pin() takes the NCO pin over the real spare input.

In manual mode the test then connects the NCO pin, which enters NCO mode with the nco_auto_read, tod_step_reset and tie_clear settings programmed at registration. Disconnecting it makes zl3073x_dpll_nco_pin_state_on_dpll_set() force freerun:

		/* Switch to freerun - holdover averaging was not
		 * updated during NCO mode.
		 */
		zl3073x_chan_mode_set(&chan,
				      ZL_DPLL_MODE_REFSEL_MODE_FREERUN);

In automatic mode, setting selectable on the NCO pin returns -EINVAL, so on a user device the test skips and no real input gets exercised.

Should pin_is_spare() leave out pins of type int-nco? Later tests that reuse PIN_TUNE_ID would inherit the same choice.

Quoted 4 lines
tools/testing/selftests/drivers/dpll/dpll_lib.sh +0 -0
index 2da8cbe8a883e..783db2a4dbc18 100644

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_lib.sh dpll_lib_lock() · line 127

Quoted 13 lines
tools/testing/selftests/drivers/dpll/dpll_lib.sh +13 -0
+# Return 0 when the dpll tool knows the given "pin set" keyword, such as
+# state or frequency. A test that sets something checks its keyword
+# first and skips on a tool that is too old for it. Only the "pin set"
+# usage is searched, a keyword that only "pin show" knows must not
+# count, and the keyword must stand on its own between blanks or
+# brackets, a hyphenated compound that contains it does not count.
+dpll_pin_set_supports()
+{
+	local usage
+
+	usage=$(__dpll_usage_block pin set) || return 1
+	grep -qE "(^|[[:space:][])$1([[:space:]]|$)" <<< "$usage"
+}

[Severity: Low]
This isn't a bug, but the comment says the keyword must stand between blanks or brackets. The regex accepts an opening bracket before the keyword, but only a blank or the end of the line after it, so "state]" would not match.

Every pin set keyword takes an argument, so this works in practice. Should the trailing group also accept ], or should the comment be adjusted?

[ ... ]

Quoted 4 lines
tools/testing/selftests/drivers/dpll/dpll_stress.sh +0 -0
index b21325d8368fb..396d44c7bbe35 100755

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_stress.sh test_rapid_create_delete() · line 191

Quoted 7 lines
tools/testing/selftests/drivers/dpll/dpll_stress.sh +7 -0
+			# A device in automatic mode may pick the pin it
+			# was offered as its reference, the pin reports
+			# connected then.
+			state=$(dpll_pin_get_state "$dev_id" "$pin_id")
+			case "$state" in
+			selectable|connected)
+				;;

[Severity: Low]
Does accepting connected here hide a wrong readback on the simulator?

test_pin_state_flooding() only runs on a fresh dpllsim device. dpllsim_pin_state_set() stores exactly the requested state, after dpllsim_pin_state_valid() has refused connected in automatic mode. Nothing in drivers/dpll/dpllsim/ writes DPLL_PIN_STATE_CONNECTED.

So a regression that stores connected when selectable was requested would pass this test. test_pin_state_transitions() applies the same automatic/selectable/connected exemption, even when DPLL_CREATED_DEVICE is set.

Could this exemption apply only to devices the user provided?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112130359.840795-1-poros%40redhat.com
author
#9 lore raw

PATCH v4 7/14 dpll: dpllsim: Add support to get/set priority on input pins

In reply to Petr Oros

Add support for getting and setting the priority of input pins. Implement the prio_get and prio_set callbacks and advertise the priority-can-change capability for input pins, which includes the MUX type pins since those are always inputs.

The initial priority of a pin is configured through a new prio attribute of the pin directory, which takes a value between 0 and 255 and defaults to 128, so that a test can lay out the reference order before the device goes live. Like the other pin attributes it is writable only while the device is not live. Priority changes made over netlink are stored and reported back, the driver does not select a reference by them. They are kept apart from the configured value, so that every live transition starts from what configfs holds, like the pin state does, and the attribute keeps showing what was configured. The setter rejects a value above 255 with EINVAL and an extack message. A priority is meaningful for input pins only, so live fails with EINVAL when an output pin was given a priority other than the default, next to the frequency validation.

---
v4:
- keep the priority set over netlink apart from the configured one, every live transition starts from the configured value and the attribute keeps showing it
- document that, and that the driver only stores the priority
- the Reviewed-by and Acked-by of v3 are not carried over, the behaviour of the driver changed

v3: https://lore.kernel.org/all/[email protected]/

---
 Documentation/driver-api/dpllsim.rst | 15 +++++++--
 drivers/dpll/dpllsim/core.c          | 31 +++++++++++++++++++
 drivers/dpll/dpllsim/dpll.c          | 46 ++++++++++++++++++++++++++--
 drivers/dpll/dpllsim/dpllsim.h       |  6 ++++
 4 files changed, 94 insertions(+), 4 deletions(-)
Documentation/driver-api/dpllsim.rst +13 -2
index a0e5ea44d2c6d3..27cfc4b2c71518 100644
@@ -37,6 +37,8 @@ Pin directory ``/sys/kernel/config/dpllsim/<dev>/pins/<pin>/``:
                (default 0, which is rejected)
 ``direction``  ``input`` or ``output`` (default ``input``), a ``mux`` pin
                must be an input
+``prio``       Initial priority 0-255 of an input pin, output pins must
+               keep the default (default 128)
 =============  ===============================================================
 
 The pin directory name becomes the board label of the pin. Pins are
@@ -55,8 +57,15 @@ The frequencies a pin type supports:
 
 The pin configuration is checked when 1 is written to ``live``. The
 write fails with ``EINVAL`` when a pin has a frequency its type does not
-support or when a ``mux`` pin is an output, and with ``ENOENT`` when a
-pin directory is being created or removed at the same time.
+support, when a ``mux`` pin is an output or when an output pin has a
+priority other than the default, and with ``ENOENT`` when a pin
+directory is being created or removed at the same time.
+
+Every live transition starts from the configured values. A priority set
+over netlink while the instance is live is reported back over netlink,
+it is not written to the ``prio`` attribute and is gone once the
+instance is taken down. The driver stores the priority, it does not
+select a reference by it.
 
 Example
 =======
@@ -70,8 +79,10 @@ output, then make it live::
     mkdir pins/gnss0
     echo gnss > pins/gnss0/type
     echo 1 > pins/gnss0/frequency
+    echo 0 > pins/gnss0/prio
     mkdir pins/ext0
     echo 10000000 > pins/ext0/frequency
+    echo 1 > pins/ext0/prio
     mkdir pins/out0
     echo 10000000 > pins/out0/frequency
     echo output > pins/out0/direction
drivers/dpll/dpllsim/core.c +31 -0
index 21c56aa4ecf5ac..fca16ec0976684 100644
@@ -132,10 +132,40 @@ static ssize_t dpllsim_pin_frequency_store(struct config_item *item,
 }
 CONFIGFS_ATTR(dpllsim_pin_, frequency);
 
+static ssize_t dpllsim_pin_prio_show(struct config_item *item, char *page)
+{
+	struct dpllsim_pin *pin = to_dpllsim_pin(item);
+
+	guard(mutex)(&pin->dev->lock);
+	return sysfs_emit(page, "%u\n", pin->cfg_prio);
+}
+
+static ssize_t dpllsim_pin_prio_store(struct config_item *item,
+				      const char *page, size_t count)
+{
+	struct dpllsim_pin *pin = to_dpllsim_pin(item);
+	u32 val;
+	int err;
+
+	err = kstrtou32(page, 10, &val);
+	if (err)
+		return err;
+	if (val > DPLLSIM_PIN_PRIO_MAX)
+		return -EINVAL;
+
+	guard(mutex)(&pin->dev->lock);
+	if (dpllsim_dev_frozen(pin->dev))
+		return -EBUSY;
+	pin->cfg_prio = val;
+	return count;
+}
+CONFIGFS_ATTR(dpllsim_pin_, prio);
+
 static struct configfs_attribute *dpllsim_pin_attrs[] = {
 	&dpllsim_pin_attr_type,
 	&dpllsim_pin_attr_direction,
 	&dpllsim_pin_attr_frequency,
+	&dpllsim_pin_attr_prio,
 	NULL,
 };
 
@@ -178,6 +208,7 @@ static struct config_item *dpllsim_pins_make_item(struct config_group *group,
 	pin->dev = sim;
 	pin->type = DPLL_PIN_TYPE_EXT;
 	pin->direction = DPLL_PIN_DIRECTION_INPUT;
+	pin->cfg_prio = DPLLSIM_DEFAULT_PIN_PRIO;
 	list_add_tail(&pin->list, &sim->pin_list);
 
 	return &pin->item;
drivers/dpll/dpllsim/dpll.c +44 -2

79 lines not on this page · raw message

drivers/dpll/dpllsim/dpllsim.h +6 -0
index 73b846b66f79c7..54f4f1636f64e4 100644
@@ -12,6 +12,9 @@
 #include <linux/list.h>
 #include <linux/mutex.h>
 
+#define DPLLSIM_DEFAULT_PIN_PRIO		128
+#define DPLLSIM_PIN_PRIO_MAX			255
+
 #define DPLLSIM_MAX_PINS			128
 
 struct dpllsim_dev;
@@ -25,6 +28,7 @@ struct dpllsim_pin {
 	enum dpll_pin_type type;
 	enum dpll_pin_direction direction;
 	u64 frequency;
+	u32 cfg_prio;
 
 	/* Resolved at live=1 */
 	int idx;
@@ -35,6 +39,8 @@ struct dpllsim_pin {
 
 	/* Simulated state, guarded by dev->lock */
 	enum dpll_pin_state state;
+	/* Starts from cfg_prio at live=1, changed by the netlink setter */
+	u32 prio;
 };
 
 struct dpllsim_dev {
Signature · 1 line
2.56.0
author
#10 lore raw

PATCH v4 8/14 selftests: dpll: add pin priority test

In reply to Petr Oros

Add a test that sets a new priority on an input pin, reads it back and restores the original value. The range of priorities a device accepts is not advertised over netlink, so the test tries one below the current value and then the small values every driver accepts, since a large current value may mark an unused pin outside the settable range, as the ice driver does with 255. A driver may still refuse all of them for a constraint the interface does not tell, so that is a skip on a device provided by the user, with the reason the tool reported, and a failure on the device the script created, whose simulator accepts every value the test tries. A current value the device does not take back could not be restored, so the test writes it back once before it touches the pin, which changes nothing, and ends there when that is refused. The test skips when the dpll tool lacks the prio keyword of pin set, and the restore is deferred right after that write so that an interrupted run restores the value too. A pin that does not advertise the priority-can-change capability or does not report a priority is a skip on a device provided by the user and a failure on the device the script created, whose pins have both.

The dpllsim_add_pin helper gains an optional priority argument, which is written only when it is given, so that a pin without one keeps the default of the simulator. A priority is accepted for input pins only, so the callers pass one for those alone.

The standard device lays its inputs out as gnss0 with priority 0 and ext0 with priority 1, and the stress devices get random priorities on their input pins.

---
v4:
- write the current priority back before the pin is touched and end the test when the device refuses it, the pin could not be restored
- say that the simulator accepts every value the test tries, not every priority, and drop "active reference" from the layout comment
- tell a failed capability query from a missing capability and log a deferred restore that fails

v3:
- follow the move of the selftests to
tools/testing/selftests/drivers/dpll

v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

---
 .../selftests/drivers/dpll/dpll_features.sh   | 74 +++++++++++++++++++
 .../selftests/drivers/dpll/dpll_lib.sh        | 32 ++++++--
 .../selftests/drivers/dpll/dpll_stress.sh     | 15 ++--
 3 files changed, 109 insertions(+), 12 deletions(-)
tools/testing/selftests/drivers/dpll/dpll_features.sh +74 -0
index 0a00a18bded2c5..f7340bd89602fe 100755
@@ -27,6 +27,7 @@ input_pins=()
 
 ALL_TESTS="
 	test_pin_state_transitions
+	test_pin_priority_get_set
 "
 
 ##############################################################################
@@ -70,6 +71,79 @@ pin_tune_capable()
 	return 1
 }
 
+test_pin_priority_get_set()
+{
+	local before target after reason candidate
+
+	RET=0
+
+	if [ -z "$PIN_TUNE_ID" ]; then
+		dpll_log_test_skip_or_fail "DPLL pin priority set/get" \
+		    "no spare input pin"
+		return
+	fi
+	if ! dpll_pin_set_supports prio; then
+		log_test_skip "DPLL pin priority set/get" \
+		    "dpll tool lacks pin set prio"
+		return
+	fi
+	pin_tune_capable priority-can-change "DPLL pin priority set/get" \
+			 "priority cannot change" || return
+
+	before=$(dpll_pin_get_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID")
+	if [ -z "$before" ]; then
+		dpll_log_test_skip_or_fail "DPLL pin priority set/get" \
+		    "prio not reported"
+		return
+	fi
+	# A device may report a priority it does not accept back, one that
+	# marks an unused pin for instance, and the pin could not be
+	# restored then. Writing the current value changes nothing, so
+	# that is tried before the pin is touched.
+	if ! dpll_pin_set_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID" "$before"; then
+		reason=${DPLL_LAST_ERR%%$'\n'*}
+		dpll_log_test_skip_or_fail "DPLL pin priority set/get" \
+		    "cannot write the current prio back${reason:+, $reason}"
+		return
+	fi
+	defer dpll_restore dpll_pin_set_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID" \
+	      "$before"
+
+	# The accepted range is not advertised, so try one below the current
+	# value and then small values, a refusal of all of them is a skip on
+	# a device the user provided, the simulator accepts every value
+	# tried here.
+	target=""
+	for candidate in $((before - 1)) 1 7; do
+		[ "$candidate" -ge 0 ] && [ "$candidate" != "$before" ] ||
+			continue
+		if dpll_pin_set_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID" \
+				     "$candidate"; then
+			target=$candidate
+			break
+		fi
+		reason=${DPLL_LAST_ERR%%$'\n'*}
+	done
+	if [ -z "$target" ]; then
+		dpll_log_test_skip_or_fail "DPLL pin priority set/get" \
+		    "cannot set a new prio${reason:+, $reason}"
+		return
+	fi
+	after=$(dpll_pin_get_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID")
+	if [ "$after" != "$target" ]; then
+		check_err 1 "priority expected $target, got '$after'"
+	fi
+
+	dpll_pin_set_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID" "$before"
+	check_err $? "cannot restore pin priority"
+	after=$(dpll_pin_get_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID")
+	if [ "$after" != "$before" ]; then
+		check_err 1 "priority not restored, got '$after'"
+	fi
+
+	log_test "DPLL pin priority set/get"
+}
+
 test_pin_state_transitions()
 {
 	local mode before state after reason ref_pin
tools/testing/selftests/drivers/dpll/dpll_lib.sh +26 -6
index 783db2a4dbc180..b8f4375a4f76a7 100644
@@ -437,6 +437,11 @@ dpll_pin_has_capability()
 	   <<< "$out" &> /dev/null || return 1
 }
 
+dpll_pin_get_prio()
+{
+	__dpll_pin_dev_field "$1" "$2" '.prio'
+}
+
 ##############################################################################
 # Pin setters
 #
@@ -471,6 +476,16 @@ dpll_pin_set_state()
 			     state "$state" 2>&1 >/dev/null)
 }
 
+dpll_pin_set_prio()
+{
+	local dev_id=$1
+	local pin_id=$2
+	local prio=$3
+
+	DPLL_LAST_ERR=$(dpll pin set id "$pin_id" parent-device "$dev_id" \
+			     prio "$prio" 2>&1 >/dev/null)
+}
+
 ##############################################################################
 # dpllsim configfs interface
 #
@@ -567,7 +582,9 @@ dpllsim_create_device()
 
 # $1: device name, $2: pin name (becomes the board-label), $3: type (gnss,
 # int-oscillator, ext, synce-eth-port, mux), $4: frequency in Hz,
-# $5: direction (input/output)
+# $5: direction (input/output), $6: prio (optional, input pins only).
+# The priority is written only when one is given, so a pin without one
+# keeps the default of the simulator.
 dpllsim_add_pin()
 {
 	local dev=$1
@@ -575,13 +592,16 @@ dpllsim_add_pin()
 	local type=$3
 	local frequency=$4
 	local direction=$5
+	local prio=${6:-}
 	local pin_path="$DPLLSIM_CFG/$dev/pins/$pin"
 
 	mkdir "$pin_path" 2>/dev/null || return 1
 
 	if ! echo "$type" 2>/dev/null > "$pin_path/type" ||
 	   ! echo "$frequency" 2>/dev/null > "$pin_path/frequency" ||
-	   ! echo "$direction" 2>/dev/null > "$pin_path/direction"; then
+	   ! echo "$direction" 2>/dev/null > "$pin_path/direction" ||
+	   { [ -n "$prio" ] &&
+	     ! echo "$prio" 2>/dev/null > "$pin_path/prio"; }; then
 		rmdir "$pin_path" 2>/dev/null
 		return 1
 	fi
@@ -628,8 +648,8 @@ dpllsim_alloc_clock_id()
 # Create a device with the standard 3-pin layout, deploy it and resolve
 # the netlink device id. Sets DPLLSIM_CREATED_NAME, DPLLSIM_CLOCK_ID and
 # DPLLSIM_DEV_ID.
-#   gnss0: GNSS, 1 Hz, input
-#   ext0: EXT, 10 MHz, input
+#   gnss0: GNSS, 1 Hz, input, prio 0
+#   ext0: EXT, 10 MHz, input, prio 1
 #   out0: EXT, 10 MHz, output
 dpllsim_setup_standard_device()
 {
@@ -640,8 +660,8 @@ dpllsim_setup_standard_device()
 	name="std$clock_id"
 	dpllsim_create_device "$name" "$clock_id" || return 1
 
-	if ! dpllsim_add_pin "$name" gnss0 gnss 1 input ||
-	   ! dpllsim_add_pin "$name" ext0 ext 10000000 input ||
+	if ! dpllsim_add_pin "$name" gnss0 gnss 1 input 0 ||
+	   ! dpllsim_add_pin "$name" ext0 ext 10000000 input 1 ||
 	   ! dpllsim_add_pin "$name" out0 ext 10000000 output; then
 		dpllsim_delete_device "$name"
 		return 1
tools/testing/selftests/drivers/dpll/dpll_stress.sh +9 -6
index 396d44c7bbe351..1745643955da16 100755
@@ -77,13 +77,13 @@ create_stress_device()
 	local clock_id=$1
 	local num_pins=$2
 	local name="st$clock_id"
-	local i type freq dir
+	local i type freq dir prio
 	local dirs=(input output)
 
 	dpllsim_create_device "$name" "$clock_id" || return 1
 
 	# Always have at least one plain input pin, then random ones
-	if ! dpllsim_add_pin "$name" ext0 ext 10000000 input; then
+	if ! dpllsim_add_pin "$name" ext0 ext 10000000 input 1; then
 		dpllsim_delete_device "$name"
 		return 1
 	fi
@@ -94,8 +94,11 @@ create_stress_device()
 		# output one
 		dir=${dirs[RANDOM % 2]}
 		[ "$type" = mux ] && dir=input
-		if ! dpllsim_add_pin "$name" "pin$i" "$type" "$freq" \
-				     "$dir"; then
+		# Only input pins accept a priority
+		prio=""
+		[ "$dir" = input ] && prio=$((RANDOM % 128))
+		if ! dpllsim_add_pin "$name" "pin$i" "$type" "$freq" "$dir" \
+				     "$prio"; then
 			dpllsim_delete_device "$name"
 			return 1
 		fi
@@ -221,8 +224,8 @@ test_deploy_cycle()
 	fi
 	track_device "$name"
 
-	if ! dpllsim_add_pin "$name" gnss0 gnss 1 input ||
-	   ! dpllsim_add_pin "$name" ext0 ext 10000000 input ||
+	if ! dpllsim_add_pin "$name" gnss0 gnss 1 input 0 ||
+	   ! dpllsim_add_pin "$name" ext0 ext 10000000 input 1 ||
 	   ! dpllsim_add_pin "$name" out0 ext 10000000 output; then
 		check_err 1 "cannot add pins"
 		log_test "DPLL deploy/undeploy cycling"
Signature · 1 line
2.56.0
#11 lore raw

Re: [PATCH net-next v4 08/14] selftests: dpll: add pin priority test

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] In test_pin_priority_get_set (tools/testing/selftests/drivers/dpll/dpll_features.sh), the candidate…
- [Low] test_pin_priority_get_set (dpll_features.sh, line 93) ignores the exit status of dpll_pin_get_prio: `before=$(dpll_pin_get_prio…
- [Low] Part of the commit message rationale is out of date after v4.

--

selftests: dpll: add pin priority test

This adds test_pin_priority_get_set() to dpll_features.sh. The test writes the current priority of a spare input pin back, sets a new priority from a list of candidates, reads it back and restores the original. The dpllsim_add_pin helper gains an optional priority argument, and the standard and stress simulator devices now set priorities on their input pins.

Quoted 5 lines

The range of priorities a device accepts is
not advertised over netlink, so the test tries one below the current value and then the small values every driver accepts, since a large current value may mark an unused pin outside the settable range, as the ice driver does with 255. A driver may still refuse all of them for a

[Severity: Low]
Is this rationale still accurate after the v4 change? In v4, test_pin_priority_get_set() first writes the current value back, and returns if the device refuses it:

    if ! dpll_pin_set_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID" "$before"; then
        ...
        return
    fi

So a current value outside the settable range, such as 255 on ice, ends the test before the candidate loop runs. The fallback to 1 and 7 now matters only when before is 0, or when the device accepts its current value back but refuses before - 1.

Also, "the small values every driver accepts" is followed by "A driver may still refuse all of them". These two statements contradict each other.

Quoted 3 lines

The standard device lays its inputs out as gnss0 with priority 0 and ext0 with priority 1, and the stress devices get random priorities on their input pins.

create_stress_device() gives ext0 a fixed priority of 1, and test_deploy_cycle() uses the fixed values 0 and 1. Could the message say that only the extra input pins of the stress device get random priorities?

Quoted 4 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh +0 -0
index 0a00a18bded2c..f7340bd89602f 100755

[ ... ]

Quoted 6 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh +2 -0
@@ -70,6 +71,79 @@ pin_tune_capable()
 	return 1
 }
 
+test_pin_priority_get_set()
+{

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_features.sh pin_tune_capable() · line 98

Quoted 9 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh +9 -0
+	pin_tune_capable priority-can-change "DPLL pin priority set/get" \
+			 "priority cannot change" || return
+
+	before=$(dpll_pin_get_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID")
+	if [ -z "$before" ]; then
+		dpll_log_test_skip_or_fail "DPLL pin priority set/get" \
+		    "prio not reported"
+		return
+	fi

[Severity: Low]
Should the exit status of dpll_pin_get_prio() be checked here? When the dpll tool fails, __dpll_pin_dev_field() returns 1 with empty output:

    out=$(dpll pin show id "$pin_id" -j 2>/dev/null) || return 1

So a failed query and a pin with no prio in its parent-device nest both end up as "prio not reported". On a device provided by the user, that is logged as a skip, not a failure.

pin_tune_capable(), just above, already tells a failed query apart from a missing capability. The later frequency and phase adjust tests in the series also make that distinction for their getters.

Quoted 4 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh +4 -0
+	# A device may report a priority it does not accept back, one that
+	# marks an unused pin for instance, and the pin could not be
+	# restored then. Writing the current value changes nothing, so
+	# that is tried before the pin is touched.

[ ... ]

Quoted 14 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh +14 -0
+	# The accepted range is not advertised, so try one below the current
+	# value and then small values, a refusal of all of them is a skip on
+	# a device the user provided, the simulator accepts every value
+	# tried here.
+	target=""
+	for candidate in $((before - 1)) 1 7; do
+		[ "$candidate" -ge 0 ] && [ "$candidate" != "$before" ] ||
+			continue
+		if dpll_pin_set_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID" \
+				     "$candidate"; then
+			target=$candidate
+			break
+		fi
+		reason=${DPLL_LAST_ERR%%$'\n'*}

tools/testing/selftests/drivers/dpll/dpll_features.sh pin_tune_capable() · line 135

Quoted 10 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh +10 -0
+	done
+	if [ -z "$target" ]; then
+		dpll_log_test_skip_or_fail "DPLL pin priority set/get" \
+		    "cannot set a new prio${reason:+, $reason}"
+		return
+	fi
+	after=$(dpll_pin_get_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID")
+	if [ "$after" != "$target" ]; then
+		check_err 1 "priority expected $target, got '$after'"
+	fi

[Severity: Medium]
Can this candidate order make the device switch its reference in automatic mode? pin_is_spare() accepts a pin whose state is selectable:

    (.state == "disconnected" or
     .state == "selectable")) and

A lower number means a higher priority. Both before - 1 and then 1 move the spare pin toward or above the current reference.

For example, take a reference at prio 2 and a spare pin at prio 3. Then before - 1 ties with the reference, and 1 puts the spare pin above it.

Candidate 7 is tried whenever before is not 7. So when before < 7, it lowers the priority instead.

After the set, only the prio is read back and the pin state is not checked. A reference switch on hardware (ice, or zl3073x when the ref is selectable) would go unnoticed.

On a non-revertive device, the switch can remain after the deferred restore, and the restore still reports success.

There is also no re-check like the one in test_pin_state_transitions():

    if [ "$mode" = automatic ] && [ "$before" = connected ]; then
        dpll_log_test_skip_or_fail "DPLL pin state transitions" \
            "spare input pin became the reference"
        return
    fi

test_pin_state_transitions() runs first. Through its automatic/selectable/connected exception, it accepts the pin being left connected.

Could test_pin_priority_get_set() then change the priority of what is now the device's reference? When before < 7, it would lower that priority with 7.

The script header warns that a spare pin with a valid signal can still be selected. Would it make sense to try values that lower the priority first, or to check the pin state before and after the set?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112130359.840795-1-poros%40redhat.com
author
#12 lore raw

PATCH v4 9/14 dpll: dpllsim: Add support to set frequency on pins

In reply to Petr Oros

Add support to set the frequency of input and output pins. The DPLL core validates the requested value against the supported frequency list the pin advertises, so the frequency_set callback only has to store it. The same per type tables that validate the configured frequency at live time serve as the supported list. The configfs attribute is rejected with EBUSY while the device is live, so only the netlink setter changes the frequency of a registered pin and the two cannot race. The frequency set over netlink is kept apart from the configured one, like the priority, so the attribute keeps showing what was configured and every live transition starts from it.

---
v4:
- keep the frequency set over netlink apart from the configured one, like the priority
- document that values set over netlink are not written back to the attributes
- the Reviewed-by and Acked-by of v3 are not carried over, the behaviour of the driver changed

v3: https://lore.kernel.org/all/[email protected]/

---
 Documentation/driver-api/dpllsim.rst | 10 +++++-----
 drivers/dpll/dpllsim/core.c          |  4 ++--
 drivers/dpll/dpllsim/dpll.c          | 20 ++++++++++++++++++--
 drivers/dpll/dpllsim/dpllsim.h       |  8 ++++++--
 4 files changed, 31 insertions(+), 11 deletions(-)
Documentation/driver-api/dpllsim.rst +5 -5
index 27cfc4b2c71518..9c717b81a9473c 100644
@@ -61,11 +61,11 @@ support, when a ``mux`` pin is an output or when an output pin has a
 priority other than the default, and with ``ENOENT`` when a pin
 directory is being created or removed at the same time.
 
-Every live transition starts from the configured values. A priority set
-over netlink while the instance is live is reported back over netlink,
-it is not written to the ``prio`` attribute and is gone once the
-instance is taken down. The driver stores the priority, it does not
-select a reference by it.
+Every live transition starts from the configured values. A frequency or
+a priority set over netlink while the instance is live is reported back
+over netlink, it is not written to the ``frequency`` or ``prio``
+attribute and is gone once the instance is taken down. The driver
+stores the priority, it does not select a reference by it.
 
 Example
 =======
drivers/dpll/dpllsim/core.c +2 -2
index fca16ec0976684..caf161221fe410 100644
@@ -110,7 +110,7 @@ static ssize_t dpllsim_pin_frequency_show(struct config_item *item, char *page)
 	struct dpllsim_pin *pin = to_dpllsim_pin(item);
 
 	guard(mutex)(&pin->dev->lock);
-	return sysfs_emit(page, "%llu\n", pin->frequency);
+	return sysfs_emit(page, "%llu\n", pin->cfg_frequency);
 }
 
 static ssize_t dpllsim_pin_frequency_store(struct config_item *item,
@@ -127,7 +127,7 @@ static ssize_t dpllsim_pin_frequency_store(struct config_item *item,
 	guard(mutex)(&pin->dev->lock);
 	if (dpllsim_dev_frozen(pin->dev))
 		return -EBUSY;
-	pin->frequency = val;
+	pin->cfg_frequency = val;
 	return count;
 }
 CONFIGFS_ATTR(dpllsim_pin_, frequency);
drivers/dpll/dpllsim/dpll.c +18 -2
index 9fdb5dbeba4400..0cce8fef232cd3 100644
@@ -79,6 +79,19 @@ static int dpllsim_pin_frequency_get(const struct dpll_pin *pin,
 	return 0;
 }
 
+static int dpllsim_pin_frequency_set(const struct dpll_pin *pin,
+				     void *pin_priv,
+				     const struct dpll_device *dpll,
+				     void *dpll_priv, u64 frequency,
+				     struct netlink_ext_ack *extack)
+{
+	struct dpllsim_pin *sim_pin = pin_priv;
+
+	guard(mutex)(&sim_pin->dev->lock);
+	sim_pin->frequency = frequency;
+	return 0;
+}
+
 static int dpllsim_pin_direction_get(const struct dpll_pin *pin,
 				     void *pin_priv,
 				     const struct dpll_device *dpll,
@@ -171,6 +184,7 @@ static int dpllsim_pin_prio_set(const struct dpll_pin *pin, void *pin_priv,
 
 static const struct dpll_pin_ops dpllsim_input_pin_ops = {
 	.frequency_get = dpllsim_pin_frequency_get,
+	.frequency_set = dpllsim_pin_frequency_set,
 	.direction_get = dpllsim_pin_direction_get,
 	.state_on_dpll_get = dpllsim_pin_state_get,
 	.state_on_dpll_set = dpllsim_pin_state_set,
@@ -180,6 +194,7 @@ static const struct dpll_pin_ops dpllsim_input_pin_ops = {
 
 static const struct dpll_pin_ops dpllsim_output_pin_ops = {
 	.frequency_get = dpllsim_pin_frequency_get,
+	.frequency_set = dpllsim_pin_frequency_set,
 	.direction_get = dpllsim_pin_direction_get,
 	.state_on_dpll_get = dpllsim_pin_state_get,
 };
@@ -233,8 +248,8 @@ static bool dpllsim_pin_frequency_valid(struct dpllsim_pin *pin)
 
 	dpllsim_pin_props(pin, &prop);
 	for (i = 0; i < prop.freq_supported_num; i++)
-		if (pin->frequency >= prop.freq_supported[i].min &&
-		    pin->frequency <= prop.freq_supported[i].max)
+		if (pin->cfg_frequency >= prop.freq_supported[i].min &&
+		    pin->cfg_frequency <= prop.freq_supported[i].max)
 			return true;
 
 	return false;
@@ -258,6 +273,7 @@ static void dpllsim_pin_reset(struct dpllsim_pin *pin)
 {
 	pin->ops = dpllsim_pin_select_ops(pin);
 	pin->state = DPLL_PIN_STATE_DISCONNECTED;
+	pin->frequency = pin->cfg_frequency;
 	pin->prio = pin->cfg_prio;
 }
 
drivers/dpll/dpllsim/dpllsim.h +6 -2
index 54f4f1636f64e4..cd99227f1e4e1d 100644
@@ -27,7 +27,7 @@ struct dpllsim_pin {
 	/* Configuration, writable only until dpllsim_dev_frozen() */
 	enum dpll_pin_type type;
 	enum dpll_pin_direction direction;
-	u64 frequency;
+	u64 cfg_frequency;
 	u32 cfg_prio;
 
 	/* Resolved at live=1 */
@@ -39,7 +39,11 @@ struct dpllsim_pin {
 
 	/* Simulated state, guarded by dev->lock */
 	enum dpll_pin_state state;
-	/* Starts from cfg_prio at live=1, changed by the netlink setter */
+	/*
+	 * Start from cfg_frequency and cfg_prio at live=1, changed by the
+	 * netlink setters
+	 */
+	u64 frequency;
 	u32 prio;
 };
 
Signature · 1 line
2.56.0
author
#13 lore raw

PATCH v4 10/14 selftests: dpll: add pin frequency test

In reply to Petr Oros

Add a test that picks a supported frequency other than the current one from the frequency-supported list of an input pin, sets it, reads it back and restores the original value. Both ends of every advertised range are candidates, so that a pin advertising a single range wider than one value still has one. It skips when the dpll tool lacks the frequency keyword of pin set, and the restore is deferred right after the original value is read so that an interrupted run restores it too. The core refuses a frequency outside the supported ranges, so a pin whose current frequency is not in them could not be put back, zl3073x reports a sub-Hz reference as 0 Hz and does not offer that. The test bails out on such a pin before it touches it. The frequency belongs to the pin and not to one of its parent devices, which is why the pin the script picks must not be the reference of any of them.
A pin that reports no frequency or advertises a single frequency only is a skip on a device provided by the user and a failure on the device the script created, whose pins advertise several.

The driver may refuse the candidate. A driver without a frequency setter refuses every value with EOPNOTSUPP, and a driver with constraints of its own refuses values the advertised ranges allow, zl3073x for instance wants the frequencies of an output pair to divide each other. On a device provided by the user a refused set is a skip that names the reason the tool reported, which the setter keeps in DPLL_LAST_ERR, on the created device the simulator accepts every advertised value and the refusal is a failure. Once the set went through, a refused restore is a failure on either.

---
v4:
- bail out before touching a pin whose current frequency is not among the supported ones, it could not be restored
- tell a failed query from a pin without a frequency, check that the value is a number and log a deferred restore that fails
- name the arguments of dpll_pin_set_frequency like the other setters

v3:
- follow the move of the selftests to
tools/testing/selftests/drivers/dpll

v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

---
 .../selftests/drivers/dpll/dpll_features.sh   | 90 +++++++++++++++++++
 .../selftests/drivers/dpll/dpll_lib.sh        | 10 +++
 2 files changed, 100 insertions(+)
tools/testing/selftests/drivers/dpll/dpll_features.sh +90 -0
index f7340bd89602fe..ebb52c85262016 100755
@@ -28,6 +28,7 @@ input_pins=()
 ALL_TESTS="
 	test_pin_state_transitions
 	test_pin_priority_get_set
+	test_pin_frequency_set_get
 "
 
 ##############################################################################
@@ -297,6 +298,95 @@ test_pin_state_transitions()
 	log_test "DPLL pin state transitions"
 }
 
+test_pin_frequency_set_get()
+{
+	local before target after reason json
+
+	RET=0
+
+	if [ -z "$PIN_TUNE_ID" ]; then
+		dpll_log_test_skip_or_fail "DPLL pin frequency set/get" \
+		    "no spare input pin"
+		return
+	fi
+	if ! dpll_pin_set_supports frequency; then
+		log_test_skip "DPLL pin frequency set/get" \
+		    "dpll tool lacks pin set frequency"
+		return
+	fi
+
+	# A query that failed is not a pin without a frequency.
+	if ! before=$(dpll_pin_get_frequency "$PIN_TUNE_ID"); then
+		check_err 1 "pin $PIN_TUNE_ID query failed"
+		log_test "DPLL pin frequency set/get"
+		return
+	fi
+	if [ -z "$before" ]; then
+		dpll_log_test_skip_or_fail "DPLL pin frequency set/get" \
+		    "frequency not reported"
+		return
+	fi
+	if ! [[ "$before" =~ ^[0-9]+$ ]]; then
+		check_err 1 "frequency '$before' is not a number"
+		log_test "DPLL pin frequency set/get"
+		return
+	fi
+	if ! json=$(dpll_pin_json "$PIN_TUNE_ID"); then
+		check_err 1 "pin $PIN_TUNE_ID query failed"
+		log_test "DPLL pin frequency set/get"
+		return
+	fi
+	# The core refuses a frequency outside the supported ranges, the
+	# current one included, and a driver may report one it does not
+	# offer, zl3073x reads a sub-Hz reference back as 0 Hz. Such a pin
+	# could not be restored, so bail out before it is touched.
+	if ! jq -e --argjson cur "$before" \
+		'any(.["frequency-supported"][]?;
+		     .["frequency-min"] <= $cur and
+		     .["frequency-max"] >= $cur)' <<< "$json" &> /dev/null; then
+		dpll_log_test_skip_or_fail "DPLL pin frequency set/get" \
+		    "current frequency is not a supported one"
+		return
+	fi
+	defer dpll_restore dpll_pin_set_frequency "$PIN_TUNE_ID" "$before"
+
+	# Pick a supported frequency different from the current one. Both
+	# ends of every supported range are candidates, so a pin with a
+	# single range still has an alternative unless it is one value wide.
+	target=$(jq -r --argjson cur "$before" \
+		    '[.["frequency-supported"][]? |
+		      .["frequency-min"], .["frequency-max"] |
+		      numbers | select(. != $cur)][0] // empty' <<< "$json")
+	if [ -z "$target" ]; then
+		dpll_log_test_skip_or_fail "DPLL pin frequency set/get" \
+		    "no alternative supported frequency"
+		return
+	fi
+
+	# A driver without a frequency setter or with constraints of its own
+	# may refuse the candidate, a skip on a device the user provided, the
+	# simulator accepts every advertised value.
+	if ! dpll_pin_set_frequency "$PIN_TUNE_ID" "$target"; then
+		reason=${DPLL_LAST_ERR%%$'\n'*}
+		dpll_log_test_skip_or_fail "DPLL pin frequency set/get" \
+		    "cannot set frequency=$target${reason:+, $reason}"
+		return
+	fi
+	after=$(dpll_pin_get_frequency "$PIN_TUNE_ID")
+	if [ "$after" != "$target" ]; then
+		check_err 1 "frequency expected $target, got '$after'"
+	fi
+
+	dpll_pin_set_frequency "$PIN_TUNE_ID" "$before"
+	check_err $? "cannot restore frequency"
+	after=$(dpll_pin_get_frequency "$PIN_TUNE_ID")
+	if [ "$after" != "$before" ]; then
+		check_err 1 "frequency not restored, got '$after'"
+	fi
+
+	log_test "DPLL pin frequency set/get"
+}
+
 ##############################################################################
 
 cleanup()
tools/testing/selftests/drivers/dpll/dpll_lib.sh +10 -0
index b8f4375a4f76a7..fa1895ab17f518 100644
@@ -486,6 +486,16 @@ dpll_pin_set_prio()
 			     prio "$prio" 2>&1 >/dev/null)
 }
 
+# $2: frequency in Hz
+dpll_pin_set_frequency()
+{
+	local pin_id=$1
+	local frequency=$2
+
+	DPLL_LAST_ERR=$(dpll pin set id "$pin_id" frequency "$frequency" \
+			     2>&1 >/dev/null)
+}
+
 ##############################################################################
 # dpllsim configfs interface
 #
Signature · 1 line
2.56.0
#14 lore raw

Re: [PATCH net-next v4 10/14] selftests: dpll: add pin frequency test

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 3

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] test_pin_frequency_set_get (tools/testing/selftests/drivers/dpll/dpll_features.sh) only re-checks…
- [Low] test_pin_frequency_set_get registers defer dpll_restore dpll_pin_set_frequency "$PIN_TUNE_ID" "$before" before any frequency…
- [Low] pin_is_spare/pick_tune_pin do not look at reference-sync pairing.
- [Low] Two statements in the commit message do not match the code.

--

selftests: dpll: add pin frequency test

This adds test_pin_frequency_set_get() to dpll_features.sh. The test picks a supported frequency of the spare input pin other than the current one, sets it, reads it back and restores the original value. A new dpll_pin_set_frequency() helper in dpll_lib.sh keeps the error output of the tool in DPLL_LAST_ERR.

Quoted 3 lines

constraints of its own refuses values the advertised ranges allow, zl3073x for instance wants the frequencies of an output pair to divide each other.

[Severity: Low]
Does this example apply to this test? The divisibility check is only in zl3073x_dpll_output_pin_frequency_set():

"OUT%uN freq must divide OUT%uP freq",

This test only changes PIN_TUNE_ID, which is taken from the input pins.

Quoted 3 lines

A pin that reports no frequency or advertises a single frequency only is a skip on a device provided by the user and a failure on the device the script created, whose pins advertise several.

Is this accurate for the gnss pins of the created device? dpllsim_pin_props() gives gnss pins a single 1 Hz range:

static struct dpll_pin_frequency dpllsim_freq_1pps[] = {
	DPLL_PIN_FREQUENCY_RANGE(1, 1),
};

dpllsim_setup_standard_device() creates gnss0 before ext0. The test passes on the created device only because pick_tune_pin() ends up choosing ext0. If that choice changed, the created device would fail with "no alternative supported frequency".

Quoted 10 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh +1 -0
index f7340bd89602f..ebb52c8526201 100755
@@ -28,6 +28,7 @@ input_pins=()
 ALL_TESTS="
 	test_pin_state_transitions
 	test_pin_priority_get_set
+	test_pin_frequency_set_get
 "

[ ... ]

Quoted 10 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh +6 -0
@@ -297,6 +298,95 @@ test_pin_state_transitions()
 	log_test "DPLL pin state transitions"
 }
 
+test_pin_frequency_set_get()
+{
+	local before target after reason json
+
+	RET=0
+

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_features.sh test_pin_state_transitions() · line 351

Quoted 13 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh +13 -0
+	# The core refuses a frequency outside the supported ranges, the
+	# current one included, and a driver may report one it does not
+	# offer, zl3073x reads a sub-Hz reference back as 0 Hz. Such a pin
+	# could not be restored, so bail out before it is touched.
+	if ! jq -e --argjson cur "$before" \
+		'any(.["frequency-supported"][]?;
+		     .["frequency-min"] <= $cur and
+		     .["frequency-max"] >= $cur)' <<< "$json" &> /dev/null; then
+		dpll_log_test_skip_or_fail "DPLL pin frequency set/get" \
+		    "current frequency is not a supported one"
+		return
+	fi
+	defer dpll_restore dpll_pin_set_frequency "$PIN_TUNE_ID" "$before"

[Severity: Low]
The restore is deferred here, before any frequency write has worked. The commit message covers "A driver without a frequency setter refuses every value with EOPNOTSUPP". On such a driver the target set below fails, the test skips and returns, and then the deferred restore runs.

In dpll_pin_freq_set() the ops check comes before the no-op shortcut:

drivers/dpll/dpll_netlink.c:dpll_pin_freq_set() {
    ...
	if (!ops->frequency_set || !ops->frequency_get) {
		NL_SET_ERR_MSG(extack,
			       "frequency set not supported by the device");
		return -EOPNOTSUPP;
	}
    ...
	if (freq == old_freq)
		return 0;
    ...
}

So writing back the unchanged value fails as well. dpll_restore() then logs "restore failed: dpll_pin_set_frequency ..." with the "frequency set not supported by the device" reason, for a pin that was never changed.

All in-tree drivers currently pair frequency_get with frequency_set, so this needs a driver that implements only frequency_get.

Could this do what test_pin_priority_get_set() does? That test writes the current value back first and defers the restore only after that write succeeds.

Quoted 4 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh +4 -0
+
+	# Pick a supported frequency different from the current one. Both
+	# ends of every supported range are candidates, so a pin with a
+	# single range still has an alternative unless it is one value wide.

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_features.sh test_pin_state_transitions() · line 369

Quoted 4 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh +4 -0
+	# A driver without a frequency setter or with constraints of its own
+	# may refuse the candidate, a skip on a device the user provided, the
+	# simulator accepts every advertised value.
+	if ! dpll_pin_set_frequency "$PIN_TUNE_ID" "$target"; then

[Severity: Medium]
Can PIN_TUNE_ID have become the reference by the time this runs?

test_pin_priority_get_set() runs just before this test and gives the pin a better priority (before - 1, 1 or 7). A qualified input with that priority can win the automatic selection. A non-revertive device can stay on it after the priority is put back.

test_pin_state_transitions() checks for exactly this:

# The automatic selection may have taken the pin since it was # picked, it is the reference then and not to be touched. if [ "$mode" = automatic ] && [ "$before" = connected ]; then
dpll_log_test_skip_or_fail "DPLL pin state transitions" \
"spare input pin became the reference"

This test only relies on the pin_is_spare() check that pick_tune_pin() does once when the script starts.

On zl3073x, zl3073x_dpll_input_pin_frequency_set() writes the new frequency with zl3073x_ref_state_set(). That configuration is shared by every channel the reference feeds, so a locked channel could lose lock or go into holdover until the restore runs.

The commit message says "the pin the script picks must not be the reference of any of them". Should the pin's state on each parent device be checked again before this set, as test_pin_state_transitions() does?

[Severity: Low]
Could PIN_TUNE_ID be the reference-sync partner of the active reference?

On zl3073x, zl3073x_dpll_input_pin_ref_sync_set() checks the pair rules only when the pair is enabled:

		if (sync_freq > 8000) {
			NL_SET_ERR_MSG(extack,
				       "sync frequency must be 8 kHz or less");

It also sets the priority of the sync partner to none on every channel. In automatic mode that partner then reports disconnected. pin_is_spare() only looks at state and operstate on the parent devices, so it treats the partner as spare.

zl3073x_dpll_input_pin_frequency_set() and dpll_pin_freq_set() do not check the ref-sync rules again. The test could therefore set the sync input to an advertised endpoint above 8 kHz, for example 10 MHz instead of 1 Hz. It would stay paired with the locked reference until the restore runs.

Should pin_is_spare() also treat a pin as not spare when it has a connected reference-sync entry in the output of dpll pin show -j?

Quoted 5 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh +5 -0
+		reason=${DPLL_LAST_ERR%%$'\n'*}
+		dpll_log_test_skip_or_fail "DPLL pin frequency set/get" \
+		    "cannot set frequency=$target${reason:+, $reason}"
+		return
+	fi

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112130359.840795-1-poros%40redhat.com
author
#15 lore raw

PATCH v4 11/14 dpll: dpllsim: Add support to adjust phase

In reply to Petr Oros

Add support to get and set the phase adjustment of input and output pins. The pins advertise a granularity of 100 ps and a symmetric range whose ends are the largest multiples of the granularity that fit a 32-bit signed value, so that the advertised ends themselves are settable, the core validates the requested value against both and the driver stores it. The adjustment is reset to zero every time the device goes live, so that repeated deploy cycles start from a known state. It becomes the baseline of the simulated phase offset measurements once those exist.

---
 drivers/dpll/dpllsim/dpll.c    | 40 ++++++++++++++++++++++++++++++++++
 drivers/dpll/dpllsim/dpllsim.h |  1 +
 2 files changed, 41 insertions(+)
drivers/dpll/dpllsim/dpll.c +40 -0
index 0cce8fef232cd3..0260bffd157000 100644
@@ -12,6 +12,11 @@
 
 #include "dpllsim.h"
 
+#define DPLLSIM_PHASE_ADJUST_GRAN		100	/* ps */
+/* Largest multiple of the granularity, so the range ends are settable */
+#define DPLLSIM_PHASE_ADJUST_MAX \
+	(S32_MAX - S32_MAX % DPLLSIM_PHASE_ADJUST_GRAN)
+
 static struct dpll_pin_frequency dpllsim_freq_1pps[] = {
 	DPLL_PIN_FREQUENCY_RANGE(1, 1),
 };
@@ -182,6 +187,33 @@ static int dpllsim_pin_prio_set(const struct dpll_pin *pin, void *pin_priv,
 	return 0;
 }
 
+static int dpllsim_pin_phase_adjust_get(const struct dpll_pin *pin,
+					void *pin_priv,
+					const struct dpll_device *dpll,
+					void *dpll_priv, s32 *phase_adjust,
+					struct netlink_ext_ack *extack)
+{
+	struct dpllsim_pin *sim_pin = pin_priv;
+
+	guard(mutex)(&sim_pin->dev->lock);
+	*phase_adjust = sim_pin->phase_adjust;
+	return 0;
+}
+
+static int dpllsim_pin_phase_adjust_set(const struct dpll_pin *pin,
+					void *pin_priv,
+					const struct dpll_device *dpll,
+					void *dpll_priv,
+					const s32 phase_adjust,
+					struct netlink_ext_ack *extack)
+{
+	struct dpllsim_pin *sim_pin = pin_priv;
+
+	guard(mutex)(&sim_pin->dev->lock);
+	sim_pin->phase_adjust = phase_adjust;
+	return 0;
+}
+
 static const struct dpll_pin_ops dpllsim_input_pin_ops = {
 	.frequency_get = dpllsim_pin_frequency_get,
 	.frequency_set = dpllsim_pin_frequency_set,
@@ -190,6 +222,8 @@ static const struct dpll_pin_ops dpllsim_input_pin_ops = {
 	.state_on_dpll_set = dpllsim_pin_state_set,
 	.prio_get = dpllsim_pin_prio_get,
 	.prio_set = dpllsim_pin_prio_set,
+	.phase_adjust_get = dpllsim_pin_phase_adjust_get,
+	.phase_adjust_set = dpllsim_pin_phase_adjust_set,
 };
 
 static const struct dpll_pin_ops dpllsim_output_pin_ops = {
@@ -197,6 +231,8 @@ static const struct dpll_pin_ops dpllsim_output_pin_ops = {
 	.frequency_set = dpllsim_pin_frequency_set,
 	.direction_get = dpllsim_pin_direction_get,
 	.state_on_dpll_get = dpllsim_pin_state_get,
+	.phase_adjust_get = dpllsim_pin_phase_adjust_get,
+	.phase_adjust_set = dpllsim_pin_phase_adjust_set,
 };
 
 static const struct dpll_pin_ops *
@@ -212,6 +248,9 @@ static void dpllsim_pin_props(struct dpllsim_pin *pin,
 {
 	prop->type = pin->type;
 	prop->board_label = config_item_name(&pin->item);
+	prop->phase_range.min = -DPLLSIM_PHASE_ADJUST_MAX;
+	prop->phase_range.max = DPLLSIM_PHASE_ADJUST_MAX;
+	prop->phase_gran = DPLLSIM_PHASE_ADJUST_GRAN;
 
 	switch (pin->type) {
 	case DPLL_PIN_TYPE_GNSS:
@@ -275,6 +314,7 @@ static void dpllsim_pin_reset(struct dpllsim_pin *pin)
 	pin->state = DPLL_PIN_STATE_DISCONNECTED;
 	pin->frequency = pin->cfg_frequency;
 	pin->prio = pin->cfg_prio;
+	pin->phase_adjust = 0;
 }
 
 /* Build sim->pins in registration order, the order the pins were created */
drivers/dpll/dpllsim/dpllsim.h +1 -0
index cd99227f1e4e1d..94383e71d7fcec 100644
@@ -45,6 +45,7 @@ struct dpllsim_pin {
 	 */
 	u64 frequency;
 	u32 prio;
+	s32 phase_adjust;
 };
 
 struct dpllsim_dev {
Signature · 1 line
2.56.0
#16 lore raw

Re: [PATCH net-next v4 11/14] dpll: dpllsim: Add support to adjust phase

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…

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] Documentation/driver-api/dpllsim.rst is not updated for the new phase-adjust feature, and the series never updates it later.

--

dpll: dpllsim: Add support to adjust phase

This adds phase adjust get and set callbacks to the dpllsim input and output pin ops. Each pin advertises a 100 ps granularity and a symmetric range that fits a 32-bit signed value. The stored value is reset to zero on every live transition.

Quoted 4 lines
drivers/dpll/dpllsim/dpll.c +0 -0
index 0cce8fef232cd..0260bffd15700 100644

[ ... ]

Quoted 20 lines
drivers/dpll/dpllsim/dpll.c +5 -0
@@ -197,6 +231,8 @@ static const struct dpll_pin_ops dpllsim_output_pin_ops = {
 	.frequency_set = dpllsim_pin_frequency_set,
 	.direction_get = dpllsim_pin_direction_get,
 	.state_on_dpll_get = dpllsim_pin_state_get,
+	.phase_adjust_get = dpllsim_pin_phase_adjust_get,
+	.phase_adjust_set = dpllsim_pin_phase_adjust_set,
 };
 
 static const struct dpll_pin_ops *
@@ -212,6 +248,9 @@ static void dpllsim_pin_props(struct dpllsim_pin *pin,
 {
 	prop->type = pin->type;
 	prop->board_label = config_item_name(&pin->item);
+	prop->phase_range.min = -DPLLSIM_PHASE_ADJUST_MAX;
+	prop->phase_range.max = DPLLSIM_PHASE_ADJUST_MAX;
+	prop->phase_gran = DPLLSIM_PHASE_ADJUST_GRAN;
 
 	switch (pin->type) {
 	case DPLL_PIN_TYPE_GNSS:

drivers/dpll/dpllsim/dpll.c static void dpllsim_pin_reset(struct dpllsim_pin *pin) · line 318

Quoted 5 lines
drivers/dpll/dpllsim/dpll.c +1 -0
@@ -275,6 +314,7 @@ static void dpllsim_pin_reset(struct dpllsim_pin *pin)
 	pin->state = DPLL_PIN_STATE_DISCONNECTED;
 	pin->frequency = pin->cfg_frequency;
 	pin->prio = pin->cfg_prio;
+	pin->phase_adjust = 0;
 }

[Severity: Low]
This isn't a bug, but should Documentation/driver-api/dpllsim.rst be updated for phase adjust? The later patches in the series don't touch it either.

The doc paragraph about netlink-settable state only covers frequency and priority:

Every live transition starts from the configured values. A frequency or a priority set over netlink while the instance is live is reported back over netlink, it is not written to the ``frequency`` or ``prio`` attribute and is gone once the instance is taken down.

Phase adjust has no configfs attribute, so it has no configured value. dpllsim_pin_reset() always sets it back to 0.

The doc also lists the prio range and the frequency table for each pin type. It doesn't mention any of these:

- the advertised phase adjust range of -2147483600..2147483600 ps
- the 100 ps granularity
- the reset to 0 on each live transition
- output pins accept phase adjust as well as input pins

Would a sentence or two covering these help users of the simulator?

The input pin state setter added earlier in the series is also missing from that paragraph.

Quoted 2 lines
drivers/dpll/dpllsim/dpll.c +0 -0
 /* Build sim->pins in registration order, the order the pins were created */

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112130359.840795-1-poros%40redhat.com
author
#17 lore raw

PATCH v4 12/14 selftests: dpll: add pin phase adjust test

In reply to Petr Oros

Add a test that reads the phase adjustment range and granularity a pin advertises, picks the largest multiple of the granularity inside the range, or the smallest one when that is already the current value, sets it, reads it back and restores the original value. It skips when the dpll tool lacks the phase-adjust keyword of pin set and when the range is too narrow to pick a different value. A pin that reports no phase adjustment or no range is a skip on a device provided by the user and a failure on the device the script created, whose pins report both.

The core refuses a value outside the advertised range and one that is not a multiple of the granularity a driver reports, the current value included, so a pin that sits at such a value could not be put back. The test bails out on either before it schedules the restore, which is deferred right after so that an interrupted run restores the value too.

The granularity is only reported by drivers that have the core enforce one. Without it the target is computed with a granularity of 1, and a driver may refuse it for a granularity of its own or for any other constraint the interface does not advertise. A refused set is therefore a skip on a device provided by the user, with the reason the tool reported, and a failure on the device the script created, whose simulator accepts every value its range and granularity allow. The test ends there, a value that was not set has nothing to read back.

---
v4:
- bail out when the current value lies outside the advertised range, it could not be restored
- tell a failed query from a pin without a phase adjust or a range and log a deferred restore that fails

v3:
- follow the move of the selftests to
tools/testing/selftests/drivers/dpll

v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

---
 .../selftests/drivers/dpll/dpll_features.sh   | 102 ++++++++++++++++++
 .../selftests/drivers/dpll/dpll_lib.sh        |  15 +++
 2 files changed, 117 insertions(+)
tools/testing/selftests/drivers/dpll/dpll_features.sh +102 -0
index ebb52c85262016..7b7e077073db58 100755
@@ -29,6 +29,7 @@ ALL_TESTS="
 	test_pin_state_transitions
 	test_pin_priority_get_set
 	test_pin_frequency_set_get
+	test_pin_phase_adjust_set_get
 "
 
 ##############################################################################
@@ -298,6 +299,107 @@ test_pin_state_transitions()
 	log_test "DPLL pin state transitions"
 }
 
+test_pin_phase_adjust_set_get()
+{
+	local before target after json min max gran reason
+
+	RET=0
+
+	if [ -z "$PIN_TUNE_ID" ]; then
+		dpll_log_test_skip_or_fail "DPLL pin phase-adjust set/get" \
+		    "no spare input pin"
+		return
+	fi
+	if ! dpll_pin_set_supports phase-adjust; then
+		log_test_skip "DPLL pin phase-adjust set/get" \
+		    "dpll tool lacks pin set phase-adjust"
+		return
+	fi
+
+	# A query that failed is not a pin without a phase adjust.
+	if ! before=$(dpll_pin_get_phase_adjust "$PIN_TUNE_ID") ||
+	   ! json=$(dpll_pin_json "$PIN_TUNE_ID"); then
+		check_err 1 "pin $PIN_TUNE_ID query failed"
+		log_test "DPLL pin phase-adjust set/get"
+		return
+	fi
+	if [ -z "$before" ]; then
+		dpll_log_test_skip_or_fail "DPLL pin phase-adjust set/get" \
+		    "phase adjust not reported"
+		return
+	fi
+	if ! [[ "$before" =~ ^-?[0-9]+$ ]]; then
+		check_err 1 "phase adjust '$before' is not a number"
+		log_test "DPLL pin phase-adjust set/get"
+		return
+	fi
+
+	# Pick a target inside the advertised range different from the
+	# current value, a multiple of the granularity, which is taken as 1
+	# when the driver reports none.
+	min=$(jq -r '.["phase-adjust-min"] // empty' <<< "$json")
+	max=$(jq -r '.["phase-adjust-max"] // empty' <<< "$json")
+	gran=$(jq -r '.["phase-adjust-gran"] // empty' <<< "$json")
+	if [ -z "$min" ] || [ -z "$max" ]; then
+		dpll_log_test_skip_or_fail "DPLL pin phase-adjust set/get" \
+		    "no adjust range"
+		return
+	fi
+	# The core refuses a value outside the range or off the
+	# granularity, the current one included. A pin that sits at such a
+	# value could not be put back, so bail out before the restore is
+	# scheduled.
+	if [ "$before" -lt "$min" ] || [ "$before" -gt "$max" ]; then
+		dpll_log_test_skip_or_fail "DPLL pin phase-adjust set/get" \
+		    "current phase adjust outside the adjust range"
+		return
+	fi
+	if [ -n "$gran" ] && [ $((before % gran)) -ne 0 ]; then
+		dpll_log_test_skip_or_fail "DPLL pin phase-adjust set/get" \
+		    "current phase adjust not a granularity multiple"
+		return
+	fi
+	[ -n "$gran" ] || gran=1
+	defer dpll_restore dpll_pin_set_phase_adjust "$PIN_TUNE_ID" "$before"
+
+	# Shell division truncates towards zero, so round the bounds towards
+	# the inside of the range explicitly, which matters for negative ones.
+	target=$((max / gran * gran))
+	[ "$target" -gt "$max" ] && target=$((target - gran))
+	if [ "$target" = "$before" ]; then
+		target=$((min / gran * gran))
+		[ "$target" -lt "$min" ] && target=$((target + gran))
+	fi
+	if [ "$target" = "$before" ] || [ "$target" -gt "$max" ] ||
+	   [ "$target" -lt "$min" ]; then
+		log_test_skip "DPLL pin phase-adjust set/get" "range too narrow"
+		return
+	fi
+
+	# A driver may enforce a granularity it does not report or another
+	# constraint, a skip on a device the user provided, the simulator
+	# accepts every value its range and granularity allow.
+	if ! dpll_pin_set_phase_adjust "$PIN_TUNE_ID" "$target"; then
+		reason=${DPLL_LAST_ERR%%$'\n'*}
+		dpll_log_test_skip_or_fail "DPLL pin phase-adjust set/get" \
+		    "cannot set phase-adjust=$target${reason:+, $reason}"
+		return
+	fi
+	after=$(dpll_pin_get_phase_adjust "$PIN_TUNE_ID")
+	if [ "$after" != "$target" ]; then
+		check_err 1 "phase-adjust expected $target, got '$after'"
+	fi
+
+	dpll_pin_set_phase_adjust "$PIN_TUNE_ID" "$before"
+	check_err $? "cannot restore phase-adjust"
+	after=$(dpll_pin_get_phase_adjust "$PIN_TUNE_ID")
+	if [ "$after" != "$before" ]; then
+		check_err 1 "phase-adjust not restored, got '$after'"
+	fi
+
+	log_test "DPLL pin phase-adjust set/get"
+}
+
 test_pin_frequency_set_get()
 {
 	local before target after reason json
tools/testing/selftests/drivers/dpll/dpll_lib.sh +15 -0
index fa1895ab17f518..6b99dae5a4f379 100644
@@ -442,6 +442,11 @@ dpll_pin_get_prio()
 	__dpll_pin_dev_field "$1" "$2" '.prio'
 }
 
+dpll_pin_get_phase_adjust()
+{
+	__dpll_pin_field "$1" '.["phase-adjust"]'
+}
+
 ##############################################################################
 # Pin setters
 #
@@ -496,6 +501,16 @@ dpll_pin_set_frequency()
 			     2>&1 >/dev/null)
 }
 
+# $2: phase adjust in ps
+dpll_pin_set_phase_adjust()
+{
+	local pin_id=$1
+	local phase_adjust=$2
+
+	DPLL_LAST_ERR=$(dpll pin set id "$pin_id" phase-adjust \
+			     "$phase_adjust" 2>&1 >/dev/null)
+}
+
 ##############################################################################
 # dpllsim configfs interface
 #
Signature · 1 line
2.56.0
#18 lore raw

Re: [PATCH net-next v4 12/14] selftests: dpll: add pin phase adjust test

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…

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 phase-adjust round-trip test test_pin_phase_adjust_set_get (tools/testing/selftests/drivers/dpll/dpll_features.sh) only needs…

--

selftests: dpll: add pin phase adjust test

This adds test_pin_phase_adjust_set_get() to dpll_features.sh. The test reads the phase adjust range and granularity a pin reports. It sets the largest granularity multiple inside the range, or the smallest one if the largest is already the current value, reads it back and restores the original value.

Quoted 4 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh +0 -0
index ebb52c8526201..7b7e077073db5 100755

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_features.sh test_pin_state_transitions() · line 372

Quoted 11 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh +11 -0
+	[ -n "$gran" ] || gran=1
+	defer dpll_restore dpll_pin_set_phase_adjust "$PIN_TUNE_ID" "$before"
+
+	# Shell division truncates towards zero, so round the bounds towards
+	# the inside of the range explicitly, which matters for negative ones.
+	target=$((max / gran * gran))
+	[ "$target" -gt "$max" ] && target=$((target - gran))
+	if [ "$target" = "$before" ]; then
+		target=$((min / gran * gran))
+		[ "$target" -lt "$min" ] && target=$((target + gran))
+	fi

[Severity: Low]
Does the round trip need the end of the advertised range here? Any value one granularity step away from before would test the same set/get path.

On zl3073x, zl3073x_pin_props_get() reports the full s32 range for every pin, but sets a granularity only for output pins:

drivers/dpll/zl3073x/prop.c:zl3073x_pin_props_get() {
    ...
	props->dpll_props.phase_range.min = S32_MIN;
	props->dpll_props.phase_range.max = S32_MAX;
    ...
}

So on a zl3073x input pin the test uses gran=1 and target=2147483647 ps. zl3073x_dpll_input_pin_phase_adjust_set() then writes about 2.1 ms of compensation into the reference's phase offset register. ice behaves the same way with its firmware maximum, through ice_dpll_phase_range_set().

PIN_TUNE_ID comes from pin_is_spare(), which also accepts a pin in the selectable state:

	any(.[]; .["parent-id"] == $dev and
		 (.state == "disconnected" or
		  .state == "selectable")) and
	all(.[]; .state != "connected" and .operstate != "active")

In automatic mode the DPLL can switch to that reference by itself while the test runs, for example on failover or a revertive switch. The PTP or SyncE outputs would then be offset by milliseconds until the deferred restore runs.

The script header already warns against pointing it at a device whose reference must not be disturbed, and the value is restored right away.

Would a small step such as before + gran or before - gran, clamped to [min, max], be enough here?

Quoted 5 lines
tools/testing/selftests/drivers/dpll/dpll_features.sh +5 -0
+	if [ "$target" = "$before" ] || [ "$target" -gt "$max" ] ||
+	   [ "$target" -lt "$min" ]; then
+		log_test_skip "DPLL pin phase-adjust set/get" "range too narrow"
+		return
+	fi

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112130359.840795-1-poros%40redhat.com
author
#19 lore raw

PATCH v4 13/14 selftests: dpll: add concurrency stress tests

In reply to Petr Oros

Extend the stress script with tests that register and unregister devices from several processes at once and that keep a number of devices with many pins live at the same time, checking that every one of them is visible on netlink with all its pins.

The workers run in subshells, so the parent cannot track the device a worker has in flight. Each worker removes it from its own exit trap instead, and the parent reserves a range of clock IDs for every worker, so that the devices of a worker cannot collide with those of another worker or of the parent and whatever a killed worker left behind can be removed by name, at the end of the test and from the cleanup handler. The handler stops the recorded workers together with the jobs of the shell, gives them a few seconds to run their exit traps before forcing the survivors, and goes on without a worker that does not die, since one stuck in the kernel would hang the teardown. A worker that a signal interrupts exits with the status of the signal, inside a trap $? is the status of whatever ran last and the worker could pass for one that finished. bash reaps a worker as soon as it exits, so a recorded pid may have been handed out again by the time the handler runs, and it signals a pid only while that is still a child of the script. Deleting a device treats a part of it that is gone by the time its step runs as removed, so that a removal running concurrently with the one of a worker does not turn into a spurious failure. The workers inherit the open lock file of the library, so the lock is held until the script and every worker have exited.

---
v4:
- signal a recorded pid only while it is still a running child of the script, bash reaps finished workers on its own and the pid may have been reused
- rename the "maximum devices" test to "many devices" and check that every device shows all its pins
- say what happens to a helper of a worker that is stuck in the kernel
- exit a signalled worker with the status of the signal, it could pass for one that finished

v3:
- follow the move of the selftests to
tools/testing/selftests/drivers/dpll

v2:
- quote the failed and ret expansions (netdev CI shellcheck)

v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

---
 .../selftests/drivers/dpll/dpll_lib.sh        |  30 ++-
 .../selftests/drivers/dpll/dpll_stress.sh     | 237 +++++++++++++++++-
 2 files changed, 259 insertions(+), 8 deletions(-)
tools/testing/selftests/drivers/dpll/dpll_lib.sh +23 -7
index 6b99dae5a4f379..1dfe15943f3431 100644
@@ -55,8 +55,10 @@ dpll_lib_check_prereqs()
 # The scripts that create dpllsim devices share the one dpllsim directory
 # and cannot run alongside each other, so each takes a lock on
 # DPLL_LOCK_FILE before it mounts or creates anything and skips when
-# another run holds it. The file lives under /run rather than in the
-# world-writable /tmp, where a planted symlink could redirect the open.
+# another run holds it. The workers a script forks inherit the open file
+# and keep the lock until they exit. The file lives under /run rather
+# than in the world-writable /tmp, where a planted symlink could
+# redirect the open.
 DPLL_RUN_DIR="/run/dpll-selftest"
 DPLL_LOCK_FILE="$DPLL_RUN_DIR/lock"
 DPLL_LOCK_FD=""
@@ -644,8 +646,12 @@ dpllsim_undeploy()
 
 # Take the device offline and remove it together with all its pins.
 # Every step is attempted even when an earlier one failed, the return
-# value is non-zero when any did. A device that does not exist counts as
-# deleted.
+# value is non-zero when any did. A device that does not exist counts
+# as deleted, and so does a part of it that is gone by the time its
+# step runs, the live file of the undeploy and the pin or device
+# directory of an rmdir, so that a removal running concurrently, or an
+# earlier one whose later steps failed, does not turn into a spurious
+# failure here.
 dpllsim_delete_device()
 {
 	local dev_path="$DPLLSIM_CFG/$1"
@@ -653,12 +659,12 @@ dpllsim_delete_device()
 
 	[ -d "$dev_path" ] || return 0
 
-	dpllsim_undeploy "$1" || ret=1
+	dpllsim_undeploy "$1" || [ ! -e "$dev_path/live" ] || ret=1
 	for pin_path in "$dev_path"/pins/*/; do
 		[ -d "$pin_path" ] || continue
-		rmdir "$pin_path" || ret=1
+		rmdir "$pin_path" || [ ! -d "$pin_path" ] || ret=1
 	done
-	rmdir "$dev_path" || ret=1
+	rmdir "$dev_path" || [ ! -d "$dev_path" ] || ret=1
 
 	return "$ret"
 }
@@ -670,6 +676,16 @@ dpllsim_alloc_clock_id()
 	DPLLSIM_CLOCK_ID=$((DPLLSIM_NEXT_CLOCK_ID++))
 }
 
+# Set DPLLSIM_CLOCK_ID to the first of $1 consecutive clock-ids unique
+# within this test run and move the allocator past them, for a worker
+# that derives the clock-ids of its devices from it. A device the parent
+# creates afterwards cannot collide with one of the worker.
+dpllsim_alloc_clock_id_range()
+{
+	DPLLSIM_CLOCK_ID=$DPLLSIM_NEXT_CLOCK_ID
+	DPLLSIM_NEXT_CLOCK_ID=$((DPLLSIM_NEXT_CLOCK_ID + $1))
+}
+
 # Create a device with the standard 3-pin layout, deploy it and resolve
 # the netlink device id. Sets DPLLSIM_CREATED_NAME, DPLLSIM_CLOCK_ID and
 # DPLLSIM_DEV_ID.
tools/testing/selftests/drivers/dpll/dpll_stress.sh +236 -1

279 lines not on this page · raw message

Signature · 1 line
2.56.0
#20 lore raw

Re: [PATCH net-next v4 13/14] selftests: dpll: add concurrency stress tests

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…

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] In tools/testing/selftests/drivers/dpll/dpll_stress.sh, concurrent_worker() installs worker_exit as its EXIT trap (line 281)…
- [Low] delete_worker_devices() (dpll_stress.sh:56-66) calls dpllsim_delete_device on every name…
- [Low] test_concurrent_workers() clears WORKER_BASES unconditionally (dpll_stress.sh:322) after the end-of-test sweep.

--

selftests: dpll: add concurrency stress tests

This adds test_concurrent_workers and test_many_devices to dpll_stress.sh. Each worker runs in a subshell, gets its own reserved range of clock-ids, and removes the device it has in flight from an exit trap. The parent removes worker devices by name at the end of the test and from cleanup().

Quoted 4 lines
tools/testing/selftests/drivers/dpll/dpll_stress.sh +0 -0
index 1745643955da1..2abfacc43b48b 100755

[ ... ]

Quoted 8 lines
tools/testing/selftests/drivers/dpll/dpll_stress.sh +4 -0
@@ -39,18 +50,111 @@ untrack_device()
 	CREATED_DEVICES=("${remaining[@]}")
 }
 
+# Remove whatever a worker started from the given base clock-id left
+# behind, which is the device in flight when the worker had to be killed.
+# A device that does not exist counts as deleted.
+delete_worker_devices()

tools/testing/selftests/drivers/dpll/dpll_stress.sh untrack_device() · line 66

Quoted 10 lines
tools/testing/selftests/drivers/dpll/dpll_stress.sh +10 -0
+{
+	local base=$1
+	local i name
+
+	for i in $(seq 1 "$STRESS_WORKER_ITERATIONS"); do
+		name="st$((base + i))"
+		dpllsim_delete_device "$name" ||
+			log_info "cannot delete device $name"
+	done
+}

[Severity: Low]
Can this sweep remove a device that this run never created?

dpllsim_create_device() in dpll_lib.sh refuses to take over an existing directory:

# A directory of that name was left behind by something else and # must never be recorded as a device of this run.
[ -e "$dev_path" ] && return 1

Clock-ids start at 96000 + RANDOM, so the st<N> left behind by an earlier failed run can fall inside a worker's range. dpll_lib_cleanup() keeps configfs mounted on purpose in that case.

When that happens, the worker's create fails and it only counts a failure. Then delete_worker_devices(), called from test_concurrent_workers() and from cleanup() for every base in WORKER_BASES, undeploys and removes that leftover device and its pins by name anyway.

Should the sweep only cover names a worker actually created, or skip names that already existed before the worker started?

[ ... ]

Quoted 8 lines
tools/testing/selftests/drivers/dpll/dpll_stress.sh +8 -0
+# Create and delete STRESS_WORKER_ITERATIONS devices with clock-ids
+# following the given base, in a subshell. Each worker derives its own
+# unique clock-ids from a range reserved for it, so its devices can never
+# be confused with those of another worker or of the parent. The parent
+# records the base of every worker, so that the device a killed worker
+# left behind can be removed by name.
+concurrent_worker()
+{

tools/testing/selftests/drivers/dpll/dpll_stress.sh test_rapid_create_delete() · line 283

Quoted 10 lines
tools/testing/selftests/drivers/dpll/dpll_stress.sh +10 -0
+	# The workers inherit the state of the generator from the parent
+	# and would draw the same pin layouts, so reseed it with the pid of
+	# the subshell first.
+	RANDOM=$BASHPID
+	local base=$1
+	local i name failed=0
+
+	trap worker_exit EXIT
+	trap 'exit 143' TERM
+	trap 'exit 130' INT

[Severity: Low]
Is DPLLSIM_CREATED_NAME still set to the parent's value when this trap is armed?

The subshell forked by "concurrent_worker "$base" &" gets a copy of the parent's DPLLSIM_CREATED_NAME. After test_rapid_create_delete() the parent's copy still names its last device, because nothing clears it after the successful delete.

The worker only overwrites it once dpllsim_create_device() gets past the "[ -e "$dev_path" ] && return 1" check. There are two ways it can reach worker_exit() with the inherited name:

- cleanup() sends SIGTERM before the worker's first create
- every create in the worker fails at the -e check

In both cases worker_exit() runs:

if [ -n "$DPLLSIM_CREATED_NAME" ]; then
dpllsim_delete_device "$DPLLSIM_CREATED_NAME"

and that acts on a parent device outside the worker's reserved range. This conflicts with the comment above, which says a worker's devices "can never be confused with those of another worker or of the parent".

Would setting DPLLSIM_CREATED_NAME="" at the start of concurrent_worker(), before the EXIT trap is installed, close this gap?

Quoted 16 lines
tools/testing/selftests/drivers/dpll/dpll_stress.sh +16 -0
+
+	for i in $(seq 1 "$STRESS_WORKER_ITERATIONS"); do
+		if ! create_stress_device $((base + i)) 3; then
+			failed=$((failed + 1))
+			continue
+		fi
+		name=$DPLLSIM_CREATED_NAME
+		dpllsim_delete_device "$name" ||
+			failed=$((failed + 1))
+	done
+
+	[ "$failed" -eq 0 ]
+}
+
+test_concurrent_workers()
+{

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_stress.sh test_rapid_create_delete() · line 322

Quoted 6 lines
tools/testing/selftests/drivers/dpll/dpll_stress.sh +6 -0
+	check_err "$failed" "some concurrent workers failed"
+
+	for base in "${WORKER_BASES[@]}"; do
+		delete_worker_devices "$base"
+	done
+	WORKER_BASES=()

[Severity: Low]
What happens to a worker device that this sweep fails to remove?

delete_worker_devices() only passes a failed dpllsim_delete_device() to log_info and does not return the failure. WORKER_BASES is then cleared unconditionally.

After that the device is not in CREATED_DEVICES, not in WORKER_BASES, and not in the parent's DPLLSIM_CREATED_NAME, so cleanup() never tries to remove it again.

The other tests in this file, test_many_devices() for example, keep the device tracked when removal fails:

if dpllsim_delete_device "$i"; then
untrack_device "$i"
else
check_err 1 "cannot delete device $i"
fi

Should the base of a worker whose devices were not all removed stay in WORKER_BASES, with the failure reported through check_err?

Quoted 3 lines
tools/testing/selftests/drivers/dpll/dpll_stress.sh +3 -0
+
+	log_test "DPLL concurrent workers ($STRESS_CONCURRENT_PROCS processes)"
+}

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112130359.840795-1-poros%40redhat.com
author
#21 lore raw

PATCH v4 14/14 selftests: dpll: add reference leak tests

In reply to Petr Oros

With CONFIG_DPLL_REFCNT_TRACKER the DPLL core keeps the stack traces of unreleased device and pin references in debugfs. The entries do not name their owner, so add library helpers that snapshot the entries present before a test creates its devices and fail when an entry that is not in the snapshot still holds references afterwards. An entry in the snapshot belongs to an object of another driver and is ignored even when its content changed, since other drivers take and drop references while the tests run. The teardown of a device releases its references before the write to live returns, so the entries are expected to be gone at the first look; the check still polls for a while before it reports a leak, so that it does not fail on a single read. Attributing by name means that a leak of an earlier run goes unnoticed, that an object reusing the address of a freed one from the snapshot can hide a leak and that an object another driver registers while a script runs is reported as a leak, which is accepted, the entries carry nothing better to go by. ref_tracker removes the file of a freed object from a work item and a read of it fails until then, so the snapshot waits for such files to go away and records only entries it can read, or the file of the probe device could get into it and hide the next object allocated at that address. A second run alongside would have its devices attributed to this one, which is one more reason for the lock every script takes.

Whether the tracker works is probed with a throwaway device, which has to show entries while it is live and to drain them once it is deleted, so that a kernel without the tracker is told apart from a broken simulator and from a leak. The entries exist without CONFIG_DPLL_REFCNT_TRACKER too and just stay empty, so a probe that saw no reference is a skip unless /proc/config.gz says the tracker is built in, which makes it a failure. The probe runs as the first test of the stress script, which gains a final leak check that is skipped when an earlier test left a device behind, and of the new dpll_reftrack.sh, which registers a device, removes it and verifies that no reference survived. The snapshot file lives next to the lock file under /run, for the same reason the lock file does not live in /tmp. The library mounts debugfs when nothing else did, like it does for configfs, and the selftest config enables the tracker together with CONFIG_DEBUG_KERNEL, which it depends on, debugfs and CONFIG_IKCONFIG_PROC for the look at /proc/config.gz.

---
v4:
- wait for the files of freed objects to go away before a snapshot and record only entries that can be read
- a probe that saw no reference is a failure when /proc/config.gz says the tracker is built in, a skip otherwise
- skip the final leak check of the stress script when an earlier test left a device behind
- record the debugfs mount before mounting
- say that objects another driver registers during a run are reported
- enable CONFIG_IKCONFIG_PROC in the selftest config, the probe reads /proc/config.gz
- say that the probe device could not be created or deployed, not only created
- add the Reviewed-by given to v3 (Ivan Vecera)

v3:
- say what the leak check waits for instead of a concurrent dump holding references, which nothing does (Ivan Vecera)
- follow the move of the selftests to tools/testing/selftests/drivers/dpll

v2:
- keep the config file sorted and quote the ret expansions (netdev CI shellcheck)

v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

---
 tools/testing/selftests/drivers/dpll/Makefile |   1 +
 tools/testing/selftests/drivers/dpll/config   |   5 +
 .../selftests/drivers/dpll/dpll_lib.sh        | 308 ++++++++++++++++--
 .../selftests/drivers/dpll/dpll_reftrack.sh   | 190 +++++++++++
 .../selftests/drivers/dpll/dpll_stress.sh     | 105 +++++-
 5 files changed, 584 insertions(+), 25 deletions(-)
 create mode 100755 tools/testing/selftests/drivers/dpll/dpll_reftrack.sh
tools/testing/selftests/drivers/dpll/Makefile +1 -0
index 1349d078fa2660..d292ea049edfa3 100644
@@ -10,6 +10,7 @@ TEST_FILES := dpll_lib.sh
 TEST_PROGS := \
 	dpll_basic.sh \
 	dpll_features.sh \
+	dpll_reftrack.sh \
 	dpll_stress.sh \
 # end of TEST_PROGS
 
tools/testing/selftests/drivers/dpll/config +5 -0
index e2c90b6970bd43..69ff54875712c6 100644
@@ -1,3 +1,8 @@
 CONFIG_CONFIGFS_FS=y
+CONFIG_DEBUG_FS=y
+CONFIG_DEBUG_KERNEL=y
 CONFIG_DPLL=y
+CONFIG_DPLL_REFCNT_TRACKER=y
 CONFIG_DPLLSIM=m
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
tools/testing/selftests/drivers/dpll/dpll_lib.sh +288 -20

345 lines not on this page · raw message

tools/testing/selftests/drivers/dpll/dpll_reftrack.sh new file +190 -0

190 lines not on this page · raw message

tools/testing/selftests/drivers/dpll/dpll_stress.sh +100 -5

139 lines not on this page · raw message

Signature · 1 line
2.56.0
#22 lore raw

Re: [PATCH net-next v4 14/14] selftests: dpll: add reference leak tests

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…

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 commit message says the stress script's final leak check "is skipped when an earlier test left a device behind", but the skip only…
- [Low] In dpll_reftrack.sh, test_basic_reftrack carries on to dpll_ref_tracker_check_leaks after destroy_device has failed.
- [Low] The leak check can miss a leaking object because of the asynchronous ref_tracker reap work.
- [Low] __dpll_ref_tracker_new_entries counts a new entry as a leak only if reading it returns content ([ -n "$content" ] || continue,…

--

selftests: dpll: add reference leak tests

This patch adds helpers to dpll_lib.sh that snapshot the DPLL ref_tracker debugfs entries and report non-empty entries that are not in the snapshot as leaks. A throwaway dpllsim device probes whether the tracker works. The new dpll_reftrack.sh uses the helpers, dpll_stress.sh gains a final leak check, and the selftest config enables CONFIG_DPLL_REFCNT_TRACKER and the options it needs.

Quoted 4 lines
tools/testing/selftests/drivers/dpll/dpll_lib.sh +0 -0
index 1dfe15943f343..f7bfe046edf93 100644

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_lib.sh dpllsim_setup_standard_device() · line 746

Quoted 12 lines
tools/testing/selftests/drivers/dpll/dpll_lib.sh +8 -0
@@ -719,3 +736,254 @@ dpllsim_setup_standard_device()
 		return 1
 	fi
 }
+
+##############################################################################
+# ref_tracker leak checking
+#
+# With CONFIG_DPLL_REFCNT_TRACKER=y the DPLL core creates regular files
+# named dpll_device@<ptr> / dpll_pin@<ptr> under the ref_tracker debugfs
+# dir. Reading one prints the stack traces of currently unreleased
+# references; an empty (or removed) file means no leaks.

[Severity: Low]
Does "an empty (or removed) file means no leaks" match how ref_tracker behaves?

In lib/ref_tracker.c, ref_tracker_dir_exit() marks the dir REF_TRACKER_DIR_DEAD before the object is freed. From then until the reap work removes the file, ref_tracker_debugfs_show() returns -ENODATA:

    if (!xa_load(&debugfs_dentries, index) ||
        xa_get_mark(&debugfs_dentries, index, REF_TRACKER_DIR_DEAD)) {
        xa_unlock_irqrestore(&debugfs_dentries, flags);
        return -ENODATA;
    }

That means a file that reads back successfully but empty belongs to an object that is still alive. __ref_tracker_dir_pr_ostream() prints nothing when dir->list is empty. That happens when the refcount is held through no_tracker or untracked holds, or after an imbalance where the tracker was freed but the refcount was not dropped.

__dpll_ref_tracker_new_entries() below treats a readable empty entry the same as an unreadable one:

    content=$(cat "$entry" 2>/dev/null)
    [ -n "$content" ] || continue

Could that kind of object leak pass both dpll_reftrack.sh and the final check in dpll_stress.sh? No in-tree caller seems to pass a NULL tracker today, so this is about catching a future regression.

Counting every readable entry that is not in the snapshot as a leak would close the gap. Entries waiting for the reap would still be skipped.

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_lib.sh dpllsim_setup_standard_device() · line 862

Quoted 12 lines
tools/testing/selftests/drivers/dpll/dpll_lib.sh +12 -0
+__dpll_ref_tracker_new_entries()
+{
+	local file=$1
+	local entry name content
+
+	for entry in "$DPLL_REF_TRACKER_DIR"/dpll_device@* \
+		     "$DPLL_REF_TRACKER_DIR"/dpll_pin@*; do
+		[ -f "$entry" ] || continue
+		name=$(basename "$entry")
+		grep -q "^$name " "$file" && continue
+		content=$(cat "$entry" 2>/dev/null)
+		[ -n "$content" ] || continue

[Severity: Low]
Can the asynchronous reap in ref_tracker cause this check to miss a leaking object?

__dpll_device_put() calls ref_tracker_dir_exit() and then kfree(dpll) straight away:

    ref_tracker_dir_exit(&dpll->refcnt_tracker);
    kfree(dpll);

ref_tracker_dir_exit() only sets REF_TRACKER_DIR_DEAD and schedules debugfs_reap_worker. Suppose dpll_device_alloc() returns the same address before the reap work runs. Then ref_tracker_dir_init()->ref_tracker_dir_debugfs() finds the old dentry and creates no file:

    /* No-op if already created */
    dentry = xa_load(&debugfs_dentries, (unsigned long)dir);
    if (dentry && !xa_is_err(dentry))
        return;

Reads of the old file then return -ENODATA, even though a live object now owns that address. Once the reap work runs, the file is removed, and the new object has no entry at all.

The cat above fails quietly and the entry is skipped. A leak in that object would then never show up in test_ref_leaks() or test_final_leak_check(). In test_concurrent_workers(), several processes create and delete devices in tight loops, which gives exactly this free-then-allocate pattern.

ref_tracker_dir_debugfs() was already missing the DEAD check before this patch, but the new leak check depends on that function and inherits the blind spot. The commit message lists the other limitations it accepts. Should this one be listed there too?

Quoted 4 lines
tools/testing/selftests/drivers/dpll/dpll_lib.sh +4 -0
+		echo "Unreleased references in $name:"
+		echo "$content"
+	done
+}

[ ... ]

Quoted 6 lines
tools/testing/selftests/drivers/dpll/dpll_reftrack.sh new file +0 -0
new file mode 100755
index 0000000000000..f2871b5ad8472
@@ -0,0 +1,190 @@

[ ... ]

Quoted 4 lines
tools/testing/selftests/drivers/dpll/dpll_reftrack.sh new file +4 -0
+test_basic_reftrack()
+{
+	RET=0
+

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_reftrack.sh line 143

Quoted 11 lines
tools/testing/selftests/drivers/dpll/dpll_reftrack.sh new file +11 -0
+	CREATED_DEVICE=$DPLLSIM_CREATED_NAME
+
+	destroy_device
+	check_err $? "cannot delete device $CREATED_DEVICE"
+
+	if ! dpll_device_wait_gone_by_clock_id "$DPLLSIM_CLOCK_ID" dpllsim; then
+		check_err 1 "device still on netlink after delete"
+	fi
+
+	dpll_ref_tracker_check_leaks "$REF_SNAPSHOT"
+	check_err $? "leaked references after device removal"

[Severity: Low]
If destroy_device() fails, should test_basic_reftrack() still go on to dpll_ref_tracker_check_leaks()?

When the undeploy fails, the device is still registered, so its normal references show up as new, non-empty entries. The check then waits the full BUSYWAIT_TIMEOUT and prints "References not released within ... ms" with stack traces for a device that is still live.

test_final_leak_check() and test_ref_leaks() skip on purpose in this situation ("the failure to report is that one"). retmsg keeps the first message, so it still shows the delete failure. The leak dump and the delay still happen, though.

A separate point: test_final_leak_check() runs the same check against the same snapshot, and nothing is created or destroyed in between. __dpll_ref_tracker_note_changed() only rewrites lines that are already in the snapshot. So a real leak found by test_basic_reftrack() would be reported again by test_final_leak_check(), after another BUSYWAIT_TIMEOUT.

What is the second check meant to catch that the first one does not?

[ ... ]

Quoted 4 lines
tools/testing/selftests/drivers/dpll/dpll_stress.sh +0 -0
index 2abfacc43b48b..226e2767ee897 100755

[ ... ]

Quoted 8 lines
tools/testing/selftests/drivers/dpll/dpll_stress.sh +4 -0
@@ -496,16 +563,44 @@ test_deploy_cycle()
 	log_test "DPLL deploy/undeploy cycling"
 }
 
+test_ref_leaks()
+{
+	RET=0
+

[ ... ]

tools/testing/selftests/drivers/dpll/dpll_stress.sh test_deploy_cycle() · line 583

Quoted 7 lines
tools/testing/selftests/drivers/dpll/dpll_stress.sh +7 -0
+	# A device an earlier test could not remove still holds its
+	# references, the failure to report is that one.
+	if [ "${#CREATED_DEVICES[@]}" -gt 0 ]; then
+		log_test_skip "DPLL stress ref_tracker check" \
+			      "device from an earlier test still present"
+		return
+	fi

[Severity: Low]
The commit message says the final leak check "is skipped when an earlier test left a device behind". Is every leftover device actually in CREATED_DEVICES?

The workers in test_concurrent_workers() run in subshells and never call track_device(). delete_worker_devices() only logs a failed delete:

dpllsim_delete_device "$name" ||
log_info "cannot delete device $name"

After that, test_concurrent_workers() clears the list whatever the result was:

    for base in "${WORKER_BASES[@]}"; do
        delete_worker_devices "$base"
    done
    WORKER_BASES=()

dpllsim_setup_standard_device() and create_stress_device() also roll back with dpllsim_delete_device() and ignore its result:

    if ! DPLLSIM_DEV_ID=$(dpll_device_wait_by_clock_id "$clock_id" \
                              dpllsim); then
        dpllsim_delete_device "$name"
        return 1
    fi

If that undeploy fails, DPLLSIM_CREATED_NAME is the only record of the live device. test_final_leak_check() in dpll_reftrack.sh has the same gap. It checks only CREATED_DEVICE, and that is set only after dpllsim_setup_standard_device() succeeds.

In these cases dpll_ref_tracker_check_leaks() waits out BUSYWAIT_TIMEOUT. It then reports the device's ordinary references as "leaked DPLL references after stress" or "leaked DPLL references at end of test".

dpll_lib_cleanup() in this patch finds leftovers by scanning "$DPLLSIM_CFG"/*/. Would the same scan work for these skips?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112130359.840795-1-poros%40redhat.com