* [PATCH v2] selftests/mm: improve memory hotplug test reliability
@ 2026-12-02 20:43 Rama Krishna Katta
2026-12-03 15:38 ` sashiko-bot
0 siblings, 1 reply; 3+ messages in thread
From: Rama Krishna Katta @ 2026-12-02 20:43 UTC (permalink / raw)
To: david, osalvador, shuah
Cc: linux-mm, linux-kselftest, linux-cxl, linux-kernel,
Annam Sai Manisha
The removable sysfs attribute does not guarantee that a memory block
can be offlined. The memory hotplug selftest can therefore select
blocks that contain unmovable allocations and fail during setup.
Convert the test to KTAP and select up to four blocks by preferring
offline blocks and trying to offline up to eight online blocks. Limit
each offlining attempt to ten seconds, with a two-second grace period,
and skip if discovery cannot select a block. Give the kselftest runner
360 seconds for discovery, testing and cleanup.
Record each block's state and zone before changing it. Restore the
original state and verify the exact zone for originally online blocks.
Register cleanup before discovery so it can restore blocks even if the
test is interrupted during selection.
Check notifier setup before exercising injected failures. Keep any
pre-existing notifier module in place and report failures to release
the test's module or restore memory as a KTAP failure.
Register the script as a regular kselftest program and make
run_full_test an alias for the standard runner.
Validation on arm64:
TAP version 13
# Selecting up to 4 memory blocks
1..0 # SKIP unable to select an offline memory block
In a diagnostic run, all eight offlining probes (memory4100 through
memory4107) returned EIO. The test exited with status 4 before running
the notifier and restoration cases.
Reported-by: Annam Sai Manisha <Annam.SaiManisha@arm.com>
Signed-off-by: Rama Krishna Katta <ramakrishna.katta@arm.com>
---
Changes in v2:
- Register cleanup before discovery and record state before offlining.
- Restore and verify the original memory zone as well as online state.
- Cap discovery at eight offlining attempts, allow a two-second kill
grace period and set the runner timeout to 360 seconds.
- Check notifier setup, preserve pre-existing modules and report cleanup
failures in the KTAP results.
- Find modprobe through PATH and distinguish offlining timeouts and
command failures from rejected sysfs writes.
- Stage the KTAP helper for out-of-tree kselftest builds.
.../testing/selftests/memory-hotplug/Makefile | 10 +-
.../memory-hotplug/mem-on-off-test.sh | 531 ++++++++++--------
.../testing/selftests/memory-hotplug/settings | 1 +
3 files changed, 304 insertions(+), 238 deletions(-)
create mode 100644 tools/testing/selftests/memory-hotplug/settings
diff --git a/tools/testing/selftests/memory-hotplug/Makefile b/tools/testing/selftests/memory-hotplug/Makefile
index e0a625e..078cb59 100644
--- a/tools/testing/selftests/memory-hotplug/Makefile
+++ b/tools/testing/selftests/memory-hotplug/Makefile
@@ -1,11 +1,9 @@
# SPDX-License-Identifier: GPL-2.0
-all:
-
-include ../lib.mk
TEST_PROGS := mem-on-off-test.sh
+TEST_INCLUDES := ../kselftest/ktap_helpers.sh
-run_full_test:
- @/bin/bash ./mem-on-off-test.sh -r 10 && echo "memory-hotplug selftests: [PASS]" || echo "memory-hotplug selftests: [FAIL]"
+include ../lib.mk
-clean:
+.PHONY: run_full_test
+run_full_test: run_tests
diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
index 611be86..654a981 100755
--- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
+++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
@@ -1,312 +1,379 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
-SYSFS=
+KSELFTEST_KTAP_HELPERS="$(dirname "$(realpath "$0")")/../kselftest/ktap_helpers.sh"
+source "$KSELFTEST_KTAP_HELPERS" || exit 1
-# Kselftest framework requirement - SKIP code is 4.
-ksft_skip=4
+SYSFS=
+MODPROBE=
+NOTIFIER_ERR_INJECT_DIR=
+NOTIFIER_MODULE=memory-notifier-error-inject
+ERR_INJECT_ERRNO=-12
+MAX_BLOCKS=4
+MAX_OFFLINE_ATTEMPTS=8
+
+module_loaded=0
+loading_module=0
+signal_status=0
+injected_action=
+declare -A initial_state initial_zone
+test_memory=()
prerequisite()
{
- msg="skip all tests:"
+ if [ "$UID" -ne 0 ]; then
+ ktap_skip_all "must be run as root"
+ exit "$KSFT_SKIP"
+ fi
- if [ $UID != 0 ]; then
- echo $msg must be run as root >&2
- exit $ksft_skip
+ SYSFS=$(findmnt -n -f -t sysfs -o TARGET)
+ if [ ! -d "$SYSFS/devices/system/memory" ]; then
+ ktap_skip_all "memory hotplug sysfs is not available"
+ exit "$KSFT_SKIP"
fi
+ if ! command -v timeout >/dev/null; then
+ ktap_skip_all "timeout is required"
+ exit "$KSFT_SKIP"
+ fi
+ MODPROBE=$(command -v modprobe)
+}
- SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
+prepare_error_inject()
+{
+ local debugfs action
- if [ ! -d "$SYSFS" ]; then
- echo $msg sysfs is not mounted >&2
- exit $ksft_skip
+ debugfs=$(findmnt -n -f -t debugfs -O rw -o TARGET)
+ if [ ! -d "$debugfs" ]; then
+ ktap_print_msg "writable debugfs is not mounted"
+ return 1
fi
- if ! ls $SYSFS/devices/system/memory/memory* > /dev/null 2>&1; then
- echo $msg memory hotplug is not supported >&2
- exit $ksft_skip
+ NOTIFIER_ERR_INJECT_DIR=$debugfs/notifier-error-inject/memory
+ if [ -d "$NOTIFIER_ERR_INJECT_DIR" ] ||
+ [ -d "$SYSFS/module/memory_notifier_error_inject" ]; then
+ ktap_print_msg "$NOTIFIER_MODULE is already present"
+ return 1
fi
- if ! grep -q 1 $SYSFS/devices/system/memory/memory*/removable; then
- echo $msg no hot-pluggable memory >&2
- exit $ksft_skip
+ if [ -z "$MODPROBE" ]; then
+ ktap_print_msg "modprobe is not available"
+ return 1
fi
-}
-#
-# list all hot-pluggable memory
-#
-hotpluggable_memory()
-{
- local state=${1:-.\*}
+ # Defer a signal until the result of modprobe is recorded.
+ loading_module=1
+ if "$MODPROBE" -q --first-time "$NOTIFIER_MODULE" priority=0; then
+ module_loaded=1
+ fi
+ loading_module=0
+ if [ "$signal_status" -ne 0 ]; then
+ exit "$signal_status"
+ fi
+ if [ "$module_loaded" -eq 0 ]; then
+ ktap_print_msg "could not load $NOTIFIER_MODULE"
+ return 1
+ fi
- for memory in $SYSFS/devices/system/memory/memory*; do
- if grep -q 1 $memory/removable &&
- grep -q $state $memory/state; then
- echo ${memory##/*/memory}
+ for action in MEM_GOING_OFFLINE MEM_GOING_ONLINE; do
+ if [ ! -w "$NOTIFIER_ERR_INJECT_DIR/actions/$action/error" ]; then
+ ktap_print_msg "$action error injection is unavailable"
+ return 1
fi
done
}
-hotpluggable_offline_memory()
+set_injection()
{
- hotpluggable_memory offline
+ local action=$1
+ local error=$2
+
+ # Keep track of the action even if the write fails or is interrupted.
+ injected_action=$action
+ if ! printf '%s\n' "$error" > "$NOTIFIER_ERR_INJECT_DIR/actions/$action/error"; then
+ ktap_print_msg "Could not set $action injection to $error"
+ return 1
+ fi
+ if [ "$error" -eq 0 ]; then
+ injected_action=
+ fi
}
-hotpluggable_online_memory()
+clear_injection()
{
- hotpluggable_memory online
+ [ -z "$injected_action" ] || set_injection "$injected_action" 0
}
-memory_is_online()
+memory_state_is()
{
- grep -q online $SYSFS/devices/system/memory/memory$1/state
+ grep -qx "$2" "$SYSFS/devices/system/memory/memory$1/state"
}
-memory_is_offline()
+memory_zone_is()
{
- grep -q offline $SYSFS/devices/system/memory/memory$1/state
+ grep -Fxq -- "$2" "$SYSFS/devices/system/memory/memory$1/valid_zones"
}
online_memory()
{
- echo online > $SYSFS/devices/system/memory/memory$1/state
+ echo "online_$2" > "$SYSFS/devices/system/memory/memory$1/state"
}
offline_memory()
{
- echo offline > $SYSFS/devices/system/memory/memory$1/state
+ timeout --foreground -k 2s 10s sh -c 'echo offline > "$1"' sh \
+ "$SYSFS/devices/system/memory/memory$1/state"
}
-online_memory_expect_success()
+online_memory_blocks()
{
- local memory=$1
+ local type=$1 expected_ret=$2 block actual_ret ret=0
- if ! online_memory $memory; then
- echo $FUNCNAME $memory: unexpected fail >&2
- return 1
- elif ! memory_is_online $memory; then
- echo $FUNCNAME $memory: unexpected offline >&2
- return 1
- fi
- return 0
+ for block in "${test_memory[@]}"; do
+ if ! memory_state_is "$block" offline; then
+ ktap_print_msg "memory$block must be offline before onlining"
+ ret=1
+ continue
+ fi
+ online_memory "$block" "$type" 2>/dev/null
+ actual_ret=$?
+ if [ "$actual_ret" -ne "$expected_ret" ]; then
+ ktap_print_msg "Onlining memory$block as $type returned $actual_ret," \
+ "expected $expected_ret"
+ ret=1
+ elif [ "$expected_ret" -eq 0 ]; then
+ if ! memory_state_is "$block" online ||
+ ! memory_zone_is "$block" Movable; then
+ ktap_print_msg "memory$block did not come online in ZONE_MOVABLE"
+ ret=1
+ fi
+ elif ! memory_state_is "$block" offline; then
+ ktap_print_msg "memory$block did not stay offline"
+ ret=1
+ fi
+ done
+ return "$ret"
}
-online_memory_expect_fail()
+offline_memory_blocks()
{
- local memory=$1
-
- if online_memory $memory 2> /dev/null; then
- echo $FUNCNAME $memory: unexpected success >&2
- return 1
- elif ! memory_is_offline $memory; then
- echo $FUNCNAME $memory: unexpected online >&2
- return 1
- fi
- return 0
+ local expected_ret=$1 block actual_ret ret=0
+ local expected_state=offline
+
+ [ "$expected_ret" -eq 0 ] || expected_state=online
+ for block in "${test_memory[@]}"; do
+ if ! memory_state_is "$block" online; then
+ ktap_print_msg "memory$block must be online before offlining"
+ ret=1
+ continue
+ fi
+ offline_memory "$block" 2>/dev/null
+ actual_ret=$?
+ if [ "$actual_ret" -eq 124 ]; then
+ ktap_print_msg "Offlining memory$block timed out ($actual_ret)"
+ ret=1
+ elif [ "$actual_ret" -ge 128 ]; then
+ ktap_print_msg "Offlining memory$block was interrupted or killed ($actual_ret)"
+ ret=1
+ elif [ "$actual_ret" -ge 125 ]; then
+ ktap_print_msg "Could not run offlining for memory$block ($actual_ret)"
+ ret=1
+ elif [ "$actual_ret" -ne "$expected_ret" ]; then
+ ktap_print_msg "Offlining memory$block returned $actual_ret," \
+ "expected $expected_ret"
+ ret=1
+ elif ! memory_state_is "$block" "$expected_state"; then
+ ktap_print_msg "memory$block should be $expected_state"
+ ret=1
+ fi
+ done
+ return "$ret"
}
-offline_memory_expect_success()
+find_test_memory_blocks()
{
- local memory=$1
+ local -a candidates=()
+ local path block state zone target attempts=0
- if ! offline_memory $memory; then
- echo $FUNCNAME $memory: unexpected fail >&2
- return 1
- elif ! memory_is_offline $memory; then
- echo $FUNCNAME $memory: unexpected offline >&2
- return 1
- fi
+ for path in "$SYSFS"/devices/system/memory/memory[0-9]*; do
+ block=${path##*/memory}
+ [[ "$block" =~ ^[0-9]+$ ]] && [ -r "$path/valid_zones" ] || continue
+ candidates+=("$path")
+ done
+ target=$(((${#candidates[@]} + 1) / 2))
+ [ "$target" -le "$MAX_BLOCKS" ] || target=$MAX_BLOCKS
+ ktap_print_msg "Selecting up to $target memory blocks"
+
+ for path in "${candidates[@]}"; do
+ [ "${#test_memory[@]}" -lt "$target" ] || break
+ read -r state < "$path/state" || continue
+ [ "$state" = offline ] || continue
+ block=${path##*/memory}
+ initial_state[$block]=offline
+ test_memory+=("$block")
+ done
+
+ for path in "${candidates[@]}"; do
+ [ "${#test_memory[@]}" -lt "$target" ] || break
+ [ "$attempts" -lt "$MAX_OFFLINE_ATTEMPTS" ] || break
+ read -r state < "$path/state" || continue
+ [ "$state" = online ] || continue
+ IFS= read -r zone < "$path/valid_zones" || continue
+ case "$zone" in
+ DMA|DMA32|Normal|Movable) ;;
+ *) continue ;;
+ esac
+ block=${path##*/memory}
+ [ -z "${initial_state[$block]}" ] || continue
+ # The write can change state even if the command reports failure.
+ initial_zone[$block]=$zone
+ initial_state[$block]=online
+ attempts=$((attempts + 1))
+ if offline_memory "$block" 2>/dev/null &&
+ memory_state_is "$block" offline; then
+ test_memory+=("$block")
+ elif memory_state_is "$block" online &&
+ memory_zone_is "$block" "$zone"; then
+ unset 'initial_state[$block]' 'initial_zone[$block]'
+ else
+ ktap_print_msg "Unexpected state or zone after offlining memory$block"
+ return 1
+ fi
+ done
return 0
}
-offline_memory_expect_fail()
+restore_memory_block()
{
- local memory=$1
+ local block=$1 type=kernel zone=${initial_zone[$1]}
- if offline_memory $memory 2> /dev/null; then
- echo $FUNCNAME $memory: unexpected success >&2
- return 1
- elif ! memory_is_online $memory; then
- echo $FUNCNAME $memory: unexpected offline >&2
- return 1
+ if [ "${initial_state[$block]}" = offline ]; then
+ memory_state_is "$block" offline ||
+ offline_memory "$block" || return 1
+ memory_state_is "$block" offline
+ return
fi
- return 0
-}
-online_all_offline_memory()
-{
- for memory in `hotpluggable_offline_memory`; do
- if ! online_memory_expect_success $memory; then
- retval=1
- fi
- done
+ if memory_state_is "$block" online; then
+ memory_zone_is "$block" "$zone" && return 0
+ offline_memory "$block" || return 1
+ fi
+ memory_state_is "$block" offline || return 1
+ # online_kernel selects a kernel zone; verify the exact original zone.
+ [ "$zone" != Movable ] || type=movable
+ online_memory "$block" "$type" || return 1
+ memory_state_is "$block" online && memory_zone_is "$block" "$zone"
}
-error=-12
-priority=0
-# Run with default of ratio=2 for Kselftest run
-ratio=2
-retval=0
-
-while getopts e:hp:r: opt; do
- case $opt in
- e)
- error=$OPTARG
- ;;
- h)
- echo "Usage $0 [ -e errno ] [ -p notifier-priority ] [ -r percent-of-memory-to-offline ]"
- exit
- ;;
- p)
- priority=$OPTARG
- ;;
- r)
- ratio=$OPTARG
- if [ "$ratio" -gt 100 ] || [ "$ratio" -lt 0 ]; then
- echo "The percentage should be an integer within 0~100 range"
- exit 1
- fi
- ;;
- esac
-done
-
-if ! [ "$error" -ge -4095 -a "$error" -lt 0 ]; then
- echo "error code must be -4095 <= errno < 0" >&2
- exit 1
-fi
-
-prerequisite
-
-echo "Test scope: $ratio% hotplug memory"
-
-#
-# Online all hot-pluggable memory
-#
-hotpluggable_num=`hotpluggable_offline_memory | wc -l`
-echo -e "\t online all hot-pluggable memory in offline state:"
-if [ "$hotpluggable_num" -gt 0 ]; then
- for memory in `hotpluggable_offline_memory`; do
- echo "offline->online memory$memory"
- if ! online_memory_expect_success $memory; then
- retval=1
- fi
- done
-else
- echo -e "\t\t SKIPPED - no hot-pluggable memory in offline state"
-fi
+cleanup()
+{
+ local block ret=0
-#
-# Offline $ratio percent of hot-pluggable memory
-#
-hotpluggable_num=`hotpluggable_online_memory | wc -l`
-target=`echo "a=$hotpluggable_num*$ratio; if ( a%100 ) a/100+1 else a/100" | bc`
-echo -e "\t offline $ratio% hot-pluggable memory in online state"
-echo -e "\t trying to offline $target out of $hotpluggable_num memory block(s):"
-for memory in `hotpluggable_online_memory`; do
- if [ "$target" -gt 0 ]; then
- echo "online->offline memory$memory"
- if offline_memory_expect_success $memory &>/dev/null; then
- target=$(($target - 1))
- echo "-> Success"
+ if [ "$module_loaded" -eq 1 ]; then
+ clear_injection || ret=1
+ if "$MODPROBE" -q -r "$NOTIFIER_MODULE"; then
+ module_loaded=0
+ injected_action=
else
- echo "-> Failure"
+ ktap_print_msg "Could not unload $NOTIFIER_MODULE"
+ ret=1
fi
fi
-done
-if [ "$target" -gt 0 ]; then
- retval=1
- echo -e "\t\t FAILED - unable to offline some memory blocks, device busy?"
-fi
-
-#
-# Online all hot-pluggable memory again
-#
-hotpluggable_num=`hotpluggable_offline_memory | wc -l`
-echo -e "\t online all hot-pluggable memory in offline state:"
-if [ "$hotpluggable_num" -gt 0 ]; then
- for memory in `hotpluggable_offline_memory`; do
- echo "offline->online memory$memory"
- if ! online_memory_expect_success $memory; then
- retval=1
+ for block in "${!initial_state[@]}"; do
+ if restore_memory_block "$block"; then
+ unset 'initial_state[$block]' 'initial_zone[$block]'
+ else
+ ktap_print_msg "Could not restore memory$block to" \
+ "${initial_state[$block]} ${initial_zone[$block]}"
+ ret=1
fi
done
-else
- echo -e "\t\t SKIPPED - no hot-pluggable memory in offline state"
-fi
-
-#
-# Test with memory notifier error injection
-#
-
-DEBUGFS=`mount -t debugfs | head -1 | awk '{ print $3 }'`
-NOTIFIER_ERR_INJECT_DIR=$DEBUGFS/notifier-error-inject/memory
+ return "$ret"
+}
-prerequisite_extra()
+cleanup_on_exit()
{
- msg="skip extra tests:"
+ local status=$?
- /sbin/modprobe -q -r memory-notifier-error-inject
- /sbin/modprobe -q memory-notifier-error-inject priority=$priority
+ trap - EXIT
+ trap ':' HUP INT TERM
+ cleanup || status=1
+ exit "$status"
+}
- if [ ! -d "$DEBUGFS" ]; then
- echo $msg debugfs is not mounted >&2
- exit $retval
+handle_signal()
+{
+ signal_status=$1
+ if [ "$loading_module" -eq 0 ]; then
+ exit "$signal_status"
fi
+}
- if [ ! -d $NOTIFIER_ERR_INJECT_DIR ]; then
- echo $msg memory-notifier-error-inject module is not available >&2
- exit $retval
- fi
+test_offline_injection()
+{
+ online_memory_blocks movable 0 &&
+ set_injection MEM_GOING_OFFLINE "$ERR_INJECT_ERRNO" &&
+ offline_memory_blocks 1
}
-echo -e "\t Test with memory notifier error injection"
-prerequisite_extra
+offline_after_injection()
+{
+ clear_injection && offline_memory_blocks 0
+}
-#
-# Offline $ratio percent of hot-pluggable memory
-#
-echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error
-for memory in `hotpluggable_online_memory`; do
- if [ $((RANDOM % 100)) -lt $ratio ]; then
- offline_memory_expect_success $memory &>/dev/null
- fi
-done
-
-#
-# Test memory hot-add error handling (offline => online)
-#
-echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error
-for memory in `hotpluggable_offline_memory`; do
- if ! online_memory_expect_fail $memory; then
- retval=1
- fi
-done
-
-#
-# Online all hot-pluggable memory
-#
-echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error
-online_all_offline_memory
-
-#
-# Test memory hot-remove error handling (online => offline)
-#
-echo $error > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error
-for memory in `hotpluggable_online_memory`; do
- if [ $((RANDOM % 100)) -lt $ratio ]; then
- if ! offline_memory_expect_fail $memory; then
- retval=1
+run_notifier_tests()
+{
+ local offline_test="Offline memory after error injection"
+ local kernel_test="Reject onlining to a kernel zone"
+ local movable_test="Reject onlining to ZONE_MOVABLE"
+
+ ktap_test_result "Reject offlining with error injection" \
+ test_offline_injection
+ if offline_after_injection; then
+ ktap_test_pass "$offline_test"
+ if set_injection MEM_GOING_ONLINE "$ERR_INJECT_ERRNO"; then
+ ktap_test_result "$kernel_test" online_memory_blocks kernel 1
+ ktap_test_result "$movable_test" online_memory_blocks movable 1
+ else
+ ktap_test_fail "$kernel_test (could not enable error injection)"
+ ktap_test_skip "$movable_test"
fi
+ else
+ ktap_test_fail "$offline_test"
+ ktap_test_skip "$kernel_test"
+ ktap_test_skip "$movable_test"
fi
-done
+}
-echo 0 > $NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error
-/sbin/modprobe -q -r memory-notifier-error-inject
+ktap_print_header
+prerequisite
+trap cleanup_on_exit EXIT
+trap 'handle_signal 129' HUP
+trap 'handle_signal 130' INT
+trap 'handle_signal 143' TERM
+
+if ! find_test_memory_blocks; then
+ ktap_set_plan 2
+ ktap_test_fail "Select memory blocks"
+elif [ "${#test_memory[@]}" -eq 0 ]; then
+ ktap_skip_all "unable to select an offline memory block"
+ exit "$KSFT_SKIP"
+else
+ if prepare_error_inject; then
+ notifier_tests=1
+ ktap_set_plan 7
+ else
+ notifier_tests=0
+ ktap_set_plan 3
+ fi
-#
-# Restore memory before exit
-#
-online_all_offline_memory
+ ktap_print_msg "Test scope: ${#test_memory[@]} memory block(s)"
+ ktap_test_result "Online memory to ZONE_MOVABLE" \
+ online_memory_blocks movable 0
+ ktap_test_result "Offline memory" offline_memory_blocks 0
+ if [ "$notifier_tests" -eq 1 ]; then
+ run_notifier_tests
+ fi
+fi
-exit $retval
+ktap_test_result "Restore memory state and release notifier" cleanup
+ktap_finished
diff --git a/tools/testing/selftests/memory-hotplug/settings b/tools/testing/selftests/memory-hotplug/settings
new file mode 100644
index 0000000..eef5338
--- /dev/null
+++ b/tools/testing/selftests/memory-hotplug/settings
@@ -0,0 +1 @@
+timeout=360
--
2.56.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] selftests/mm: improve memory hotplug test reliability
2026-12-02 20:43 [PATCH v2] selftests/mm: improve memory hotplug test reliability Rama Krishna Katta
@ 2026-12-03 15:38 ` sashiko-bot
2026-12-03 15:42 ` David Hildenbrand (Arm)
0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-12-03 15:38 UTC (permalink / raw)
To: Rama Krishna Katta, david, osalvador, shuah
Cc: linux-mm, linux-cxl, Annam Sai Manisha
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] selftests/mm: DMA/DMA32 zone restoration failure in
restore_memory_block()
- [Medium] selftests/mm: out-of-tree run_hotplug failure in
run_full_test target
--
commit b63a4a9a717654c3ff50e9a2c850549c49f04eec
Author: Rama Krishna Katta <ramakrishna.katta@arm.com>
selftests/mm: improve memory hotplug test reliability
This commit converts the memory hotplug selftest to KTAP, bounds memory
block selection and offlining attempts, and adds cleanup to restore each
block's initial state and zone.
> diff --git a/tools/testing/selftests/memory-hotplug/Makefile b/tools/testing/selftests/memory-hotplug/Makefile
> index e0a625e34f400..078cb59cbd07a 100644
> --- a/tools/testing/selftests/memory-hotplug/Makefile
> +++ b/tools/testing/selftests/memory-hotplug/Makefile
> @@ -1,11 +1,9 @@
> # SPDX-License-Identifier: GPL-2.0
> -all:
> -
> -include ../lib.mk
>
> TEST_PROGS := mem-on-off-test.sh
> +TEST_INCLUDES := ../kselftest/ktap_helpers.sh
>
> -run_full_test:
> - @/bin/bash ./mem-on-off-test.sh -r 10 && echo "memory-hotplug selftests: [PASS]" || echo "memory-hotplug selftests: [FAIL]"
> +include ../lib.mk
>
> -clean:
> +.PHONY: run_full_test
> +run_full_test: run_tests
[Severity: Medium]
Does aliasing run_full_test to run_tests break the top-level run_hotplug
target for out-of-tree builds (O= or KBUILD_OUTPUT=)?
tools/testing/selftests/Makefile:
hotplug:
@for TARGET in $(TARGETS_HOTPLUG); do \
BUILD_TARGET=$$BUILD/$$TARGET; \
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
done;
run_hotplug: hotplug
@for TARGET in $(TARGETS_HOTPLUG); do \
BUILD_TARGET=$$BUILD/$$TARGET; \
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
done;
Unlike the top-level all and run_tests targets, hotplug and run_hotplug do
not run mkdir -p $$BUILD_TARGET and do not pass SRC_PATH or OBJ_PATH to
sub-makes. When building_out_of_srctree is set, lib.mk's run_tests fails
to stage TEST_PROGS into a missing $(OUTPUT) directory and runs
INSTALL_INCLUDES with SRC_PATH and OBJ_PATH empty, causing
INSTALL_INCLUDES to strip only the leading slash from entry_dir, cd to
$HOME, and attempt to rsync to /.
> diff --git a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
> index 611be86eaf3de..654a981fa8a11 100755
> --- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
> +++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
[ ... ]
> + for path in "${candidates[@]}"; do
> + [ "${#test_memory[@]}" -lt "$target" ] || break
> + [ "$attempts" -lt "$MAX_OFFLINE_ATTEMPTS" ] || break
> + read -r state < "$path/state" || continue
> + [ "$state" = online ] || continue
> + IFS= read -r zone < "$path/valid_zones" || continue
> + case "$zone" in
> + DMA|DMA32|Normal|Movable) ;;
> + *) continue ;;
> + esac
[ ... ]
> +restore_memory_block()
> +{
> + local block=$1 type=kernel zone=${initial_zone[$1]}
> +
> + if [ "${initial_state[$block]}" = offline ]; then
> + memory_state_is "$block" offline ||
> + offline_memory "$block" || return 1
> + memory_state_is "$block" offline
> + return
> + fi
> +
> + if memory_state_is "$block" online; then
> + memory_zone_is "$block" "$zone" && return 0
> + offline_memory "$block" || return 1
> + fi
> + memory_state_is "$block" offline || return 1
> + # online_kernel selects a kernel zone; verify the exact original zone.
> + [ "$zone" != Movable ] || type=movable
> + online_memory "$block" "$type" || return 1
> + memory_state_is "$block" online && memory_zone_is "$block" "$zone"
> +}
[Severity: Medium]
Can restore_memory_block() fail to restore a DMA or DMA32 block to its
original zone?
When find_test_memory_blocks() offlines a block at the start or end of
ZONE_DMA or ZONE_DMA32 (or the last online block in that zone),
offline_pages() -> remove_pfn_range_from_zone() -> shrink_zone_span()
shrinks the zone span so it no longer covers that block's PFN range. When
restore_memory_block() later writes online_kernel,
default_kernel_zone_for_pfn() checks whether the PFN range still
intersects any zone below ZONE_NORMAL:
mm/memory_hotplug.c:default_kernel_zone_for_pfn() {
for (zid = 0; zid < ZONE_NORMAL; zid++) {
struct zone *zone = &pgdat->node_zones[zid];
if (zone_intersects(zone, start_pfn, nr_pages))
return zone;
}
return &pgdat->node_zones[ZONE_NORMAL];
}
Because the shrunken DMA or DMA32 zone span no longer intersects the
block, the kernel places the block into ZONE_NORMAL, causing the
memory_zone_is check to fail and leaving the block in ZONE_NORMAL.
Should find_test_memory_blocks() only select online blocks from Normal
and Movable zones?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202204303.2777765-1-ramakrishna.katta@arm.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] selftests/mm: improve memory hotplug test reliability
2026-12-03 15:38 ` sashiko-bot
@ 2026-12-03 15:42 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 3+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 15:42 UTC (permalink / raw)
To: sashiko-reviews, Rama Krishna Katta, osalvador, shuah
Cc: linux-mm, linux-cxl, Annam Sai Manisha
I just released these from embargo early.
On 12/3/26 16:38, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [Medium] selftests/mm: DMA/DMA32 zone restoration failure in
> restore_memory_block()
Nobody cares IMHO. We could limit it to NORMAL/MOVABLE zone, but I'd just keep
it as is for now until this is actually a problem.
[...]
> [Severity: Medium]
> Does aliasing run_full_test to run_tests break the top-level run_hotplug
> target for out-of-tree builds (O= or KBUILD_OUTPUT=)?
>
> tools/testing/selftests/Makefile:
> hotplug:
> @for TARGET in $(TARGETS_HOTPLUG); do \
> BUILD_TARGET=$$BUILD/$$TARGET; \
> $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
> done;
>
> run_hotplug: hotplug
> @for TARGET in $(TARGETS_HOTPLUG); do \
> BUILD_TARGET=$$BUILD/$$TARGET; \
> $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
> done;
>
> Unlike the top-level all and run_tests targets, hotplug and run_hotplug do
> not run mkdir -p $$BUILD_TARGET and do not pass SRC_PATH or OBJ_PATH to
> sub-makes. When building_out_of_srctree is set, lib.mk's run_tests fails
> to stage TEST_PROGS into a missing $(OUTPUT) directory and runs
> INSTALL_INCLUDES with SRC_PATH and OBJ_PATH empty, causing
> INSTALL_INCLUDES to strip only the leading slash from entry_dir, cd to
> $HOME, and attempt to rsync to /.
>
@Rama, can you look into that if it's real and if we have to do something here?
--
Cheers,
David
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-03 15:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 20:43 [PATCH v2] selftests/mm: improve memory hotplug test reliability Rama Krishna Katta
2026-12-03 15:38 ` sashiko-bot
2026-12-03 15:42 ` David Hildenbrand (Arm)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox