* [PATCH 0/2] gpio: virtuser: add a selftest
@ 2026-12-01 14:27 Lin Tzu Yang
2026-12-01 14:27 ` [PATCH 1/2] Documentation: gpio: virtuser: list the accepted direction values Lin Tzu Yang
2026-12-01 14:27 ` [PATCH 2/2] selftests: gpio: add a test for gpio-virtuser Lin Tzu Yang
0 siblings, 2 replies; 4+ messages in thread
From: Lin Tzu Yang @ 2026-12-01 14:27 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Shuah Khan
Cc: Bamvor Jian Zhang, Jonathan Corbet, linux-gpio, linux-kselftest,
linux-doc, linux-kernel
gpio-virtuser has no selftest yet, while gpio-sim and gpio-aggregator
do. Patch 2 adds one, driving the consumer against a gpio-sim chip.
Writing it turned up a documentation mismatch, fixed in patch 1, and
two driver bugs, fixed separately against gpio/for-current:
- "gpio: virtuser: fix one-byte overflow in lookup entry key show"
(20261201024151.872725-1-rongh7426@gmail.com, sent earlier today):
test 2.3 reads back a 4095-byte key. Without that fix the read
still returns the right bytes, but KASAN reports the overflow.
- "gpio: virtuser: report the right dev_name before the device is
live" (sent just before this series): without it, test 1.1 fails
with "dev_name changed when the consumer was enabled".
Testing, in a QEMU/KVM arm64 guest (KASAN, configfs-next 2e0fad9d2eae,
gpio-sim and gpio-virtuser built in, busybox userspace):
- with both fixes: PASS in five runs, no kernel warnings
- without the dev_name fix: FAIL at 1.1, as expected
- with only the dev_name fix: PASS, plus two KASAN reports from 2.3
The series is against gpio/for-next.
This series was written with the help of an AI coding assistant
(Claude). I ran the tests above and reviewed the changes.
Lin Tzu Yang (2):
Documentation: gpio: virtuser: list the accepted direction values
selftests: gpio: add a test for gpio-virtuser
.../admin-guide/gpio/gpio-virtuser.rst | 5 +-
tools/testing/selftests/gpio/Makefile | 3 +-
tools/testing/selftests/gpio/config | 2 +
tools/testing/selftests/gpio/gpio-virtuser.sh | 420 ++++++++++++++++++
4 files changed, 427 insertions(+), 3 deletions(-)
create mode 100755 tools/testing/selftests/gpio/gpio-virtuser.sh
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] Documentation: gpio: virtuser: list the accepted direction values
2026-12-01 14:27 [PATCH 0/2] gpio: virtuser: add a selftest Lin Tzu Yang
@ 2026-12-01 14:27 ` Lin Tzu Yang
2026-12-01 14:27 ` [PATCH 2/2] selftests: gpio: add a test for gpio-virtuser Lin Tzu Yang
1 sibling, 0 replies; 4+ messages in thread
From: Lin Tzu Yang @ 2026-12-01 14:27 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Shuah Khan
Cc: Bamvor Jian Zhang, Jonathan Corbet, linux-gpio, linux-kselftest,
linux-doc, linux-kernel
The direction and direction_atomic debugfs attributes are documented
as accepting "input" and "output". Writing "output" fails with
-EINVAL: the driver accepts "input", "output-high" and "output-low",
and reads the direction back as "input" or "output".
Document the values the driver actually takes.
Fixes: 91581c4b3f29 ("gpio: virtuser: new virtual testing driver for the GPIO API")
Signed-off-by: Lin Tzu Yang <rongh7426@gmail.com>
---
Documentation/admin-guide/gpio/gpio-virtuser.rst | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/Documentation/admin-guide/gpio/gpio-virtuser.rst b/Documentation/admin-guide/gpio/gpio-virtuser.rst
index 7e7c0df516..236e9d5f54 100644
--- a/Documentation/admin-guide/gpio/gpio-virtuser.rst
+++ b/Documentation/admin-guide/gpio/gpio-virtuser.rst
@@ -159,8 +159,9 @@ Allows to set and read the debounce period of the GPIO line.
**Attribute:** ``/sys/kernel/debug/gpio-virtuser/$dev_name/gpiod:foo:$index/direction_atomic``
These two attributes allow to set the direction of the GPIO line. They accept
-"input" and "output" as values. The atomic variant executes the driver callback
-in interrupt context.
+"input", "output-high" and "output-low" as values, and read back as
+"input" or "output". The atomic variant executes the driver callback in
+interrupt context.
**Attribute:** ``/sys/kernel/debug/gpio-virtuser/$dev_name/gpiod:foo:$index/interrupts``
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] selftests: gpio: add a test for gpio-virtuser
2026-12-01 14:27 [PATCH 0/2] gpio: virtuser: add a selftest Lin Tzu Yang
2026-12-01 14:27 ` [PATCH 1/2] Documentation: gpio: virtuser: list the accepted direction values Lin Tzu Yang
@ 2026-12-01 14:27 ` Lin Tzu Yang
2026-12-01 14:39 ` sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Lin Tzu Yang @ 2026-12-01 14:27 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Shuah Khan
Cc: Bamvor Jian Zhang, Jonathan Corbet, linux-gpio, linux-kselftest,
linux-doc, linux-kernel
gpio-sim and gpio-aggregator have selftests, gpio-virtuser has none.
Add one that uses a gpio-sim chip as the provider, in the style of
gpio-aggregator.sh. It covers:
- creating and removing consumers, with lookups by chip label and
offset and by line name, several GPIOs and connector IDs, and the
cases that must fail: no lookup, a missing chip or offset, a line
that is already requested, and writing the current state to 'live'
- the configfs attributes: defaults, accepted and rejected values,
a key of the maximum length, and that the configuration is locked
while the consumer is live
- driving lines over debugfs and checking them on the gpio-sim side:
output and input values, array values, active_low, the consumer
name and edge interrupt counting
- that a consumer can't be enabled while its provider is disabled
The *_atomic debugfs attributes are not tested, because gpio-sim
lines can sleep.
Signed-off-by: Lin Tzu Yang <rongh7426@gmail.com>
---
tools/testing/selftests/gpio/Makefile | 3 +-
tools/testing/selftests/gpio/config | 2 +
tools/testing/selftests/gpio/gpio-virtuser.sh | 420 ++++++++++++++++++
3 files changed, 424 insertions(+), 1 deletion(-)
create mode 100755 tools/testing/selftests/gpio/gpio-virtuser.sh
diff --git a/tools/testing/selftests/gpio/Makefile b/tools/testing/selftests/gpio/Makefile
index 741ab21e12..a68b98879e 100644
--- a/tools/testing/selftests/gpio/Makefile
+++ b/tools/testing/selftests/gpio/Makefile
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
-TEST_PROGS := gpio-mockup.sh gpio-sim.sh gpio-aggregator.sh gpio-cdev-uaf.sh
+TEST_PROGS := gpio-mockup.sh gpio-sim.sh gpio-aggregator.sh gpio-cdev-uaf.sh \
+ gpio-virtuser.sh
TEST_FILES := gpio-mockup-sysfs.sh
TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info gpio-line-name \
gpio-cdev-uaf
diff --git a/tools/testing/selftests/gpio/config b/tools/testing/selftests/gpio/config
index 1287abeaac..12a6639cc1 100644
--- a/tools/testing/selftests/gpio/config
+++ b/tools/testing/selftests/gpio/config
@@ -3,3 +3,5 @@ CONFIG_GPIO_CDEV=y
CONFIG_GPIO_MOCKUP=m
CONFIG_GPIO_SIM=m
CONFIG_GPIO_AGGREGATOR=m
+CONFIG_GPIO_VIRTUSER=m
+CONFIG_DEBUG_FS=y
diff --git a/tools/testing/selftests/gpio/gpio-virtuser.sh b/tools/testing/selftests/gpio/gpio-virtuser.sh
new file mode 100755
index 0000000000..f5993904d3
--- /dev/null
+++ b/tools/testing/selftests/gpio/gpio-virtuser.sh
@@ -0,0 +1,420 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2026 Lin Tzu Yang <rongh7426@gmail.com>
+
+CONFIGFS_SIM_DIR="/sys/kernel/config/gpio-sim"
+CONFIGFS_VU_DIR="/sys/kernel/config/gpio-virtuser"
+DEBUGFS_VU_DIR="/sys/kernel/debug/gpio-virtuser"
+MODULE="gpio-virtuser"
+
+fail() {
+ echo "$*" >&2
+ echo "GPIO $MODULE test FAIL"
+ exit 1
+}
+
+skip() {
+ echo "$*" >&2
+ echo "GPIO $MODULE test SKIP"
+ exit 4
+}
+
+# gpio-sim
+
+sim_create_chip() {
+ local CHIP=$1
+ local LABEL=$2
+ local NUM_LINES=$3
+
+ mkdir "$CONFIGFS_SIM_DIR/$CHIP" || fail "Unable to create the chip"
+ mkdir "$CONFIGFS_SIM_DIR/$CHIP/bank0" || fail "Unable to create the bank"
+ echo "$LABEL" > "$CONFIGFS_SIM_DIR/$CHIP/bank0/label" || \
+ fail "Unable to set the chip label"
+ echo "$NUM_LINES" > "$CONFIGFS_SIM_DIR/$CHIP/bank0/num_lines" || \
+ fail "Unable to set the number of lines"
+}
+
+sim_set_line_name() {
+ local CHIP=$1
+ local OFFSET=$2
+ local NAME=$3
+ local LINE_DIR="$CONFIGFS_SIM_DIR/$CHIP/bank0/line$OFFSET"
+
+ mkdir -p "$LINE_DIR" || fail "Unable to create the line"
+ echo "$NAME" > "$LINE_DIR/name" || fail "Unable to set the line name"
+}
+
+sim_enable_chip() {
+ echo 1 > "$CONFIGFS_SIM_DIR/$1/live" || fail "Unable to enable the chip"
+}
+
+sim_disable_chip() {
+ echo 0 > "$CONFIGFS_SIM_DIR/$1/live" || fail "Unable to disable the chip"
+}
+
+sim_sysfs_line() {
+ local CHIP=$1
+ local OFFSET=$2
+ local DEV_NAME=$(cat "$CONFIGFS_SIM_DIR/$CHIP/dev_name")
+ local CHIP_NAME=$(cat "$CONFIGFS_SIM_DIR/$CHIP/bank0/chip_name")
+
+ echo "/sys/devices/platform/$DEV_NAME/$CHIP_NAME/sim_gpio$OFFSET"
+}
+
+sim_get_value() {
+ cat "$(sim_sysfs_line "$1" "$2")/value" || \
+ fail "Unable to read the simulated line value"
+}
+
+sim_set_pull() {
+ echo "$3" > "$(sim_sysfs_line "$1" "$2")/pull" || \
+ fail "Unable to set the simulated line pull"
+}
+
+sim_configfs_cleanup() {
+ local NOCHECK=${1:-0}
+
+ for CHIP_DIR in "$CONFIGFS_SIM_DIR"/*; do
+ [ -d "$CHIP_DIR" ] || continue
+ echo 0 > "$CHIP_DIR/live" 2> /dev/null
+ find "$CHIP_DIR" -depth -type d -exec rmdir {} \;
+ done
+ [ "$NOCHECK" -eq 1 ] && return
+ remaining=$(find "$CONFIGFS_SIM_DIR" -mindepth 1 -type d 2> /dev/null)
+ if [ -n "$remaining" ]; then
+ fail "Directories remain in $CONFIGFS_SIM_DIR: $remaining"
+ fi
+}
+
+# gpio-virtuser
+
+vu_create_dev() {
+ mkdir "$CONFIGFS_VU_DIR/$1" || fail "Unable to create the consumer"
+}
+
+vu_remove_dev() {
+ find "$CONFIGFS_VU_DIR/$1" -depth -type d -exec rmdir {} \; || \
+ fail "Unable to remove the consumer"
+}
+
+# Add one GPIO to the lookup for connector ID $2 of consumer $1.
+# $3 is the entry name, $4 the key, $5 the offset (-1 for a line name).
+vu_add_entry() {
+ local ENTRY_DIR="$CONFIGFS_VU_DIR/$1/$2/$3"
+
+ mkdir -p "$ENTRY_DIR" || fail "Unable to create the lookup entry"
+ echo "$4" > "$ENTRY_DIR/key" || fail "Unable to set the lookup key"
+ echo "$5" > "$ENTRY_DIR/offset" || fail "Unable to set the lookup offset"
+}
+
+vu_enable_dev() {
+ echo 1 > "$CONFIGFS_VU_DIR/$1/live" || fail "Unable to enable the consumer"
+}
+
+vu_disable_dev() {
+ echo 0 > "$CONFIGFS_VU_DIR/$1/live" || fail "Unable to disable the consumer"
+}
+
+vu_debugfs_dir() {
+ local DEV_NAME=$(cat "$CONFIGFS_VU_DIR/$1/dev_name")
+
+ echo "$DEBUGFS_VU_DIR/$DEV_NAME"
+}
+
+vu_configfs_cleanup() {
+ local NOCHECK=${1:-0}
+
+ for DEV_DIR in "$CONFIGFS_VU_DIR"/*; do
+ [ -d "$DEV_DIR" ] || continue
+ echo 0 > "$DEV_DIR/live" 2> /dev/null
+ find "$DEV_DIR" -depth -type d -exec rmdir {} \;
+ done
+ [ "$NOCHECK" -eq 1 ] && return
+ remaining=$(find "$CONFIGFS_VU_DIR" -mindepth 1 -type d 2> /dev/null)
+ if [ -n "$remaining" ]; then
+ fail "Directories remain in $CONFIGFS_VU_DIR: $remaining"
+ fi
+}
+
+# Load the modules. This will pull in configfs if needed too.
+modprobe gpio-sim || skip "unable to load the gpio-sim module"
+modprobe gpio-virtuser || skip "unable to load the gpio-virtuser module"
+
+# Make sure configfs is mounted at /sys/kernel/config. Wait a bit if needed.
+for IDX in $(seq 5); do
+ if [ "$IDX" -eq "5" ]; then
+ skip "configfs not mounted at /sys/kernel/config"
+ fi
+
+ mountpoint -q /sys/kernel/config && break
+ sleep 0.1
+done
+
+[ -d "$DEBUGFS_VU_DIR" ] || skip "debugfs not mounted at /sys/kernel/debug"
+
+# If the modules were already loaded: remove all previous devices
+vu_configfs_cleanup
+sim_configfs_cleanup
+
+trap "exit 1" TERM INT
+trap "vu_configfs_cleanup 1; sim_configfs_cleanup 1" EXIT
+
+# Use a gpio-sim chip with named lines as the provider
+sim_create_chip sim0 "gpio-virtuser-test" 8
+for IDX in $(seq 0 7); do
+ sim_set_line_name sim0 "$IDX" "vu-test-line$IDX"
+done
+sim_enable_chip sim0
+
+echo "1. Consumer creation and removal"
+
+echo "1.1. Lookup by chip label and offset"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 3
+test "$(cat "$CONFIGFS_VU_DIR/dev0/live")" = "0" || fail "consumer is live before enabling"
+DEV_NAME=$(cat "$CONFIGFS_VU_DIR/dev0/dev_name")
+vu_enable_dev dev0
+test "$(cat "$CONFIGFS_VU_DIR/dev0/live")" = "1" || fail "consumer is not live"
+test "$(cat "$CONFIGFS_VU_DIR/dev0/dev_name")" = "$DEV_NAME" || \
+ fail "dev_name changed when the consumer was enabled"
+test -d "/sys/bus/platform/devices/$DEV_NAME" || fail "no platform device $DEV_NAME"
+DBG_DIR=$(vu_debugfs_dir dev0)
+test -d "$DBG_DIR/gpiod:foo" || fail "debugfs array directory missing"
+test -d "$DBG_DIR/gpiod:foo:0" || fail "debugfs line directory missing"
+vu_disable_dev dev0
+test -d "$DBG_DIR" && fail "debugfs directory still present after disabling"
+vu_remove_dev dev0
+
+echo "1.2. Lookup by line name"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "vu-test-line5" -1
+vu_enable_dev dev0
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "1.3. Several GPIOs and several connector IDs"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 0
+vu_add_entry dev0 foo 1 "gpio-virtuser-test" 1
+vu_add_entry dev0 bar 0 "vu-test-line2" -1
+vu_enable_dev dev0
+DBG_DIR=$(vu_debugfs_dir dev0)
+for DIR in gpiod:foo gpiod:foo:0 gpiod:foo:1 gpiod:bar gpiod:bar:0; do
+ test -d "$DBG_DIR/$DIR" || fail "debugfs directory $DIR missing"
+done
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "1.4. Can't enable a consumer without any lookup"
+vu_create_dev dev0
+echo 1 > "$CONFIGFS_VU_DIR/dev0/live" 2> /dev/null && \
+ fail "consumer without lookups unexpectedly enabled"
+test "$(cat "$CONFIGFS_VU_DIR/dev0/live")" = "0" || fail "consumer unexpectedly alive"
+vu_remove_dev dev0
+
+echo "1.5. Can't enable a consumer whose GPIO doesn't exist"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "no-such-chip" 0
+echo 1 > "$CONFIGFS_VU_DIR/dev0/live" 2> /dev/null && \
+ fail "consumer with a missing chip unexpectedly enabled"
+vu_remove_dev dev0
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 8
+echo 1 > "$CONFIGFS_VU_DIR/dev0/live" 2> /dev/null && \
+ fail "consumer with an out-of-range offset unexpectedly enabled"
+vu_remove_dev dev0
+
+echo "1.6. Can't request a line twice"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 4
+vu_enable_dev dev0
+vu_create_dev dev1
+vu_add_entry dev1 foo 0 "gpio-virtuser-test" 4
+echo 1 > "$CONFIGFS_VU_DIR/dev1/live" 2> /dev/null && \
+ fail "second consumer of the same line unexpectedly enabled"
+vu_remove_dev dev1
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "1.7. Writing the current state to 'live' fails"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 0
+echo 0 > "$CONFIGFS_VU_DIR/dev0/live" 2> /dev/null && \
+ fail "disabling a disabled consumer unexpectedly succeeded"
+vu_enable_dev dev0
+echo 1 > "$CONFIGFS_VU_DIR/dev0/live" 2> /dev/null && \
+ fail "enabling an enabled consumer unexpectedly succeeded"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "2. Configfs attributes"
+
+ENTRY_DIR="$CONFIGFS_VU_DIR/dev0/foo/0"
+
+echo "2.1. Default values"
+vu_create_dev dev0
+mkdir -p "$ENTRY_DIR" || fail "Unable to create the lookup entry"
+test "$(cat "$ENTRY_DIR/key")" = "" || fail "default key is not empty"
+test "$(cat "$ENTRY_DIR/offset")" = "0" || fail "default offset is not 0"
+test "$(cat "$ENTRY_DIR/drive")" = "push-pull" || fail "default drive is not push-pull"
+test "$(cat "$ENTRY_DIR/pull")" = "as-is" || fail "default pull is not as-is"
+test "$(cat "$ENTRY_DIR/active_low")" = "0" || fail "default active_low is not 0"
+test "$(cat "$ENTRY_DIR/transitory")" = "0" || fail "default transitory is not 0"
+vu_remove_dev dev0
+
+echo "2.2. Valid values are accepted and invalid ones rejected"
+vu_create_dev dev0
+mkdir -p "$ENTRY_DIR" || fail "Unable to create the lookup entry"
+for VAL in open-drain open-source push-pull; do
+ echo "$VAL" > "$ENTRY_DIR/drive" || fail "drive $VAL rejected"
+ test "$(cat "$ENTRY_DIR/drive")" = "$VAL" || fail "drive $VAL not stored"
+done
+echo foobar > "$ENTRY_DIR/drive" 2> /dev/null && fail "invalid drive accepted"
+for VAL in pull-up pull-down pull-disabled as-is; do
+ echo "$VAL" > "$ENTRY_DIR/pull" || fail "pull $VAL rejected"
+ test "$(cat "$ENTRY_DIR/pull")" = "$VAL" || fail "pull $VAL not stored"
+done
+echo foobar > "$ENTRY_DIR/pull" 2> /dev/null && fail "invalid pull accepted"
+echo 65534 > "$ENTRY_DIR/offset" || fail "offset 65534 rejected"
+echo 65535 > "$ENTRY_DIR/offset" 2> /dev/null && fail "offset 65535 accepted"
+echo foo > "$ENTRY_DIR/offset" 2> /dev/null && fail "non-numeric offset accepted"
+echo x > "$ENTRY_DIR/active_low" 2> /dev/null && fail "invalid active_low accepted"
+echo x > "$ENTRY_DIR/transitory" 2> /dev/null && fail "invalid transitory accepted"
+echo 1 > "$ENTRY_DIR/active_low" || fail "active_low 1 rejected"
+test "$(cat "$ENTRY_DIR/active_low")" = "1" || fail "active_low not stored"
+echo 1 > "$ENTRY_DIR/transitory" || fail "transitory 1 rejected"
+test "$(cat "$ENTRY_DIR/transitory")" = "1" || fail "transitory not stored"
+vu_remove_dev dev0
+
+echo "2.3. A key of the maximum length reads back intact"
+# A show that writes past the page for such a key is only caught by KASAN.
+vu_create_dev dev0
+mkdir -p "$ENTRY_DIR" || fail "Unable to create the lookup entry"
+head -c 4095 /dev/zero | tr '\0' 'k' > "$ENTRY_DIR/key" || fail "long key rejected"
+test "$(cat "$ENTRY_DIR/key" | wc -c)" -ge 4095 || fail "long key truncated"
+test "$(cat "$ENTRY_DIR/key" | tr -d 'k\n' | wc -c)" = "0" || \
+ fail "long key read back corrupted"
+vu_remove_dev dev0
+
+echo "2.4. Configuration is locked while the consumer is live"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 0
+vu_enable_dev dev0
+for ATTR in key offset drive pull active_low transitory; do
+ VAL=$(cat "$ENTRY_DIR/$ATTR")
+ echo "$VAL" > "$ENTRY_DIR/$ATTR" 2> /dev/null && \
+ fail "$ATTR unexpectedly writable while live"
+done
+mkdir "$CONFIGFS_VU_DIR/dev0/foo/1" 2> /dev/null && \
+ fail "entry unexpectedly created while live"
+mkdir "$CONFIGFS_VU_DIR/dev0/bar" 2> /dev/null && \
+ fail "lookup unexpectedly created while live"
+rmdir "$ENTRY_DIR" 2> /dev/null && fail "entry unexpectedly removed while live"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "3. Controlling lines over debugfs"
+
+echo "3.1. Output values reach the provider"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 1
+vu_enable_dev dev0
+LINE_DIR="$(vu_debugfs_dir dev0)/gpiod:foo:0"
+echo output-high > "$LINE_DIR/direction" || fail "Unable to set direction"
+test "$(cat "$LINE_DIR/direction")" = "output" || fail "direction is not output"
+test "$(sim_get_value sim0 1)" = "1" || fail "output-high not seen by the provider"
+echo 0 > "$LINE_DIR/value" || fail "Unable to set value"
+test "$(sim_get_value sim0 1)" = "0" || fail "value 0 not seen by the provider"
+echo 1 > "$LINE_DIR/value" || fail "Unable to set value"
+test "$(sim_get_value sim0 1)" = "1" || fail "value 1 not seen by the provider"
+echo 2 > "$LINE_DIR/value" 2> /dev/null && fail "invalid value accepted"
+echo output > "$LINE_DIR/direction" 2> /dev/null && fail "invalid direction accepted"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "3.2. Input values come from the provider"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 2
+vu_enable_dev dev0
+LINE_DIR="$(vu_debugfs_dir dev0)/gpiod:foo:0"
+echo input > "$LINE_DIR/direction" || fail "Unable to set direction"
+test "$(cat "$LINE_DIR/direction")" = "input" || fail "direction is not input"
+sim_set_pull sim0 2 pull-up
+test "$(cat "$LINE_DIR/value")" = "1" || fail "pull-up not seen by the consumer"
+sim_set_pull sim0 2 pull-down
+test "$(cat "$LINE_DIR/value")" = "0" || fail "pull-down not seen by the consumer"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "3.3. Array values"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 5
+vu_add_entry dev0 foo 1 "gpio-virtuser-test" 6
+vu_enable_dev dev0
+DBG_DIR=$(vu_debugfs_dir dev0)
+echo output-low > "$DBG_DIR/gpiod:foo:0/direction" || fail "Unable to set direction"
+echo output-low > "$DBG_DIR/gpiod:foo:1/direction" || fail "Unable to set direction"
+echo 10 > "$DBG_DIR/gpiod:foo/values" || fail "Unable to set array values"
+test "$(sim_get_value sim0 5)$(sim_get_value sim0 6)" = "10" || \
+ fail "array values not seen by the provider"
+test "$(cat "$DBG_DIR/gpiod:foo/values")" = "10" || fail "array values read back wrong"
+echo 01 > "$DBG_DIR/gpiod:foo/values" || fail "Unable to set array values"
+test "$(sim_get_value sim0 5)$(sim_get_value sim0 6)" = "01" || \
+ fail "array values not seen by the provider"
+echo 1 > "$DBG_DIR/gpiod:foo/values" 2> /dev/null && fail "short array accepted"
+echo 111 > "$DBG_DIR/gpiod:foo/values" 2> /dev/null && fail "long array accepted"
+echo 1x > "$DBG_DIR/gpiod:foo/values" 2> /dev/null && fail "invalid array accepted"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "3.4. active_low inverts the logical value"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 7
+echo 1 > "$ENTRY_DIR/active_low" || fail "Unable to set active_low"
+vu_enable_dev dev0
+LINE_DIR="$(vu_debugfs_dir dev0)/gpiod:foo:0"
+echo output-high > "$LINE_DIR/direction" || fail "Unable to set direction"
+test "$(sim_get_value sim0 7)" = "0" || fail "active-low output-high is not low"
+echo 0 > "$LINE_DIR/value" || fail "Unable to set value"
+test "$(sim_get_value sim0 7)" = "1" || fail "active-low value 0 is not high"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "3.5. Consumer name"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 0
+vu_enable_dev dev0
+LINE_DIR="$(vu_debugfs_dir dev0)/gpiod:foo:0"
+test "$(cat "$LINE_DIR/consumer")" = "foo" || fail "default consumer name is not foo"
+echo test-consumer > "$LINE_DIR/consumer" || fail "Unable to set the consumer name"
+test "$(cat "$LINE_DIR/consumer")" = "test-consumer" || fail "consumer name not stored"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "3.6. Edge interrupts are counted"
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 3
+vu_enable_dev dev0
+LINE_DIR="$(vu_debugfs_dir dev0)/gpiod:foo:0"
+echo input > "$LINE_DIR/direction" || fail "Unable to set direction"
+sim_set_pull sim0 3 pull-down
+echo 1 > "$LINE_DIR/interrupts" || fail "Unable to enable interrupts"
+test "$(cat "$LINE_DIR/interrupts")" = "0" || fail "interrupt count is not 0"
+sim_set_pull sim0 3 pull-up
+sim_set_pull sim0 3 pull-down
+test "$(cat "$LINE_DIR/interrupts")" = "2" || fail "interrupt count is not 2"
+echo 0 > "$LINE_DIR/interrupts" || fail "Unable to disable interrupts"
+vu_disable_dev dev0
+vu_remove_dev dev0
+
+echo "4. Provider availability"
+
+echo "4.1. Can't enable a consumer while the provider is disabled"
+sim_disable_chip sim0
+vu_create_dev dev0
+vu_add_entry dev0 foo 0 "gpio-virtuser-test" 0
+echo 1 > "$CONFIGFS_VU_DIR/dev0/live" 2> /dev/null && \
+ fail "consumer unexpectedly enabled with the provider disabled"
+vu_remove_dev dev0
+
+echo "GPIO $MODULE test PASS"
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 2/2] selftests: gpio: add a test for gpio-virtuser
2026-12-01 14:27 ` [PATCH 2/2] selftests: gpio: add a test for gpio-virtuser Lin Tzu Yang
@ 2026-12-01 14:39 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-01 14:39 UTC (permalink / raw)
To: Lin Tzu Yang; +Cc: linux-gpio
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] selftests: gpio: test 1.1 fails due to dev_name mismatch in
gpio-virtuser
- [Medium] selftests: gpio: test 2.3 triggers 1-byte OOB write in
key_show()
--
commit b7b1a25a7e497e2091e3d44b29aedb3593d4949c
Author: Lin Tzu Yang <rongh7426@gmail.com>
selftests: gpio: add a test for gpio-virtuser
This commit adds a selftest script for the gpio-virtuser driver using a
gpio-sim chip as the provider to exercise configfs and debugfs interfaces.
> diff --git a/tools/testing/selftests/gpio/gpio-virtuser.sh b/tools/testing/selftests/gpio/gpio-virtuser.sh
> new file mode 100755
> index 0000000000000..f5993904d302c
> --- /dev/null
> +++ b/tools/testing/selftests/gpio/gpio-virtuser.sh
> @@ -0,0 +1,420 @@
[ ... ]
> +echo "1.1. Lookup by chip label and offset"
> +vu_create_dev dev0
> +vu_add_entry dev0 foo 0 "gpio-virtuser-test" 3
> +test "$(cat "$CONFIGFS_VU_DIR/dev0/live")" = "0" || fail "consumer is live before enabling"
> +DEV_NAME=$(cat "$CONFIGFS_VU_DIR/dev0/dev_name")
> +vu_enable_dev dev0
> +test "$(cat "$CONFIGFS_VU_DIR/dev0/live")" = "1" || fail "consumer is not live"
> +test "$(cat "$CONFIGFS_VU_DIR/dev0/dev_name")" = "$DEV_NAME" || \
> + fail "dev_name changed when the consumer was enabled"
[Severity: Medium]
Does this dev_name check depend on an unmerged fix to
gpio_virtuser_device_config_dev_name_show()?
In the current tree, gpio_virtuser_device_config_dev_name_show() formats
the pre-activation fallback name as "gpio-sim.%d" when dev->pdev is NULL,
whereas activating the device registers the platform device as
"gpio-virtuser.%d":
drivers/gpio/gpio-virtuser.c:gpio_virtuser_device_config_dev_name_show() {
...
pdev = dev->pdev;
if (pdev)
return sprintf(page, "%s\n", dev_name(&pdev->dev));
return sprintf(page, "gpio-sim.%d\n", dev->id);
}
As a result, DEV_NAME is "gpio-sim.0" before vu_enable_dev and
"gpio-virtuser.0" afterwards, causing test 1.1 to fail on every run.
[ ... ]
> +echo "2.3. A key of the maximum length reads back intact"
> +# A show that writes past the page for such a key is only caught by KASAN.
> +vu_create_dev dev0
> +mkdir -p "$ENTRY_DIR" || fail "Unable to create the lookup entry"
> +head -c 4095 /dev/zero | tr '\0' 'k' > "$ENTRY_DIR/key" || fail "long key rejected"
> +test "$(cat "$ENTRY_DIR/key" | wc -c)" -ge 4095 || fail "long key truncated"
> +test "$(cat "$ENTRY_DIR/key" | tr -d 'k\n' | wc -c)" = "0" || \
> + fail "long key read back corrupted"
> +vu_remove_dev dev0
[Severity: Medium]
Does reading back a 4095-byte key here trigger a 1-byte slab-out-of-bounds
write in gpio_virtuser_lookup_entry_config_key_show()?
drivers/gpio/gpio-virtuser.c:gpio_virtuser_lookup_entry_config_key_show() {
...
return sprintf(page, "%s\n", entry->key ?: "");
}
Configfs allocates a PAGE_SIZE (4096-byte on 4K-page kernels) read buffer
in fill_read_buffer(), so formatting a 4095-byte key plus a newline and
terminating NUL with sprintf() writes 4097 bytes and overflows the page by
1 byte unless gpio_virtuser_lookup_entry_config_key_show() is switched to
sysfs_emit() first.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201142703.900902-1-rongh7426@gmail.com?part=2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-01 14:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 14:27 [PATCH 0/2] gpio: virtuser: add a selftest Lin Tzu Yang
2026-12-01 14:27 ` [PATCH 1/2] Documentation: gpio: virtuser: list the accepted direction values Lin Tzu Yang
2026-12-01 14:27 ` [PATCH 2/2] selftests: gpio: add a test for gpio-virtuser Lin Tzu Yang
2026-12-01 14:39 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox