Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rama Krishna Katta" <ramakrishna.katta@arm.com>, linux-mm@kvack.org
Cc: "Annam Sai Manisha" <Annam.SaiManisha@arm.com>,
	"David Hildenbrand" <david@kernel.org>,
	"Oscar Salvador" <osalvador@suse.de>,
	"Shuah Khan" <shuah@kernel.org>,
	linux-cxl@vger.kernel.org
Subject: Re: [PATCH] selftests/mm: improve memory hotplug test reliability
Date: Mon, 30 Nov 2026 21:11:40 +0000	[thread overview]
Message-ID: <sashiko-outbox-241977@kernel.org> (raw)
In-Reply-To: <20261129211101.3568096-1-ramakrishna.katta@arm.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] selftests/mm: late EXIT trap registration leaks module and
  offlined state
- [Medium] selftests/mm: restore_memory_blocks() fails to restore
  initial memory zone
- [Medium] selftests/mm: find_test_memory_blocks() loop exceeds 45s
  kselftest timeout
- [Low] selftests/mm: unchecked online_memory_blocks() setup before
  offline test
--

commit d0716524d2006fd022c5934bf01a1bab082cc05c
Author: Rama Krishna Katta <ramakrishna.katta@arm.com>

selftests/mm: improve memory hotplug test reliability

This commit converts mem-on-off-test.sh to KTAP output, selects up to four
memory blocks by attempting to offline them with a 10-second timeout,
exercises notifier error injection and ZONE_MOVABLE onlining, and registers
the script in TEST_PROGS.

> diff --git a/tools/testing/selftests/memory-hotplug/Makefile b/tools/testing/selftests/memory-hotplug/Makefile
> index e0a625e34f400..1cda8845977d3 100644
> --- a/tools/testing/selftests/memory-hotplug/Makefile
> +++ b/tools/testing/selftests/memory-hotplug/Makefile
> @@ -1,11 +1,8 @@
>  # SPDX-License-Identifier: GPL-2.0
> -all:
> -
> -include ../lib.mk
>  
>  TEST_PROGS := mem-on-off-test.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 611be86eaf3de..78e802587772e 100755
> --- a/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
> +++ b/tools/testing/selftests/memory-hotplug/mem-on-off-test.sh

[ ... ]

> +offline_memory()
> +{
> +	timeout --foreground 10s sh -c 'echo offline > "$1"' sh \
> +		"$SYSFS/devices/system/memory/memory$1/state"
> +}

[ ... ]

> +find_test_memory_blocks()
> +{
> +	local -a candidates
> +	local cur_block path
> +	local -n blocks=$1
> +	local target
>  
> +	for path in "$SYSFS"/devices/system/memory/memory[0-9]*; do
> +		candidates+=("${path##*/memory}")
> +	done
> +	target=$(((${#candidates[@]} + 1) / 2))
> +	[ "$target" -gt "$MAX_BLOCKS" ] && target=$MAX_BLOCKS
> +	blocks=()
> +	ktap_print_msg "Trying to offline up to $target memory block(s):"
> +
> +	for cur_block in "${candidates[@]}"; do
> +		[ "${#blocks[@]}" -ge "$target" ] && break
> +		if memory_is_offline "$cur_block"; then
> +			ktap_print_msg "$cur_block is already offline"
> +			INITIAL_STATE[$cur_block]=offline
> +			blocks+=("$cur_block")
>  		fi
> +	done
> +	for cur_block in "${candidates[@]}"; do
> +		[ "${#blocks[@]}" -ge "$target" ] && break
> +		memory_is_offline "$cur_block" && continue
> +		memory_is_online "$cur_block" || continue
> +		if offline_memory_blocks cur_block 0 &>/dev/null; then
> +			ktap_print_msg "Offlining $cur_block succeeded"
> +			INITIAL_STATE[$cur_block]=online
> +			blocks+=("$cur_block")
>  		fi
>  	done
> +	[ "${#blocks[@]}" -gt 0 ]
> +}

[Severity: Medium]
Can find_test_memory_blocks() exceed the default 45-second kselftest runner
timeout when scanning online candidates?

Adding mem-on-off-test.sh to TEST_PROGS without a settings file runs the
script under kselftest's 45-second timeout, while each failed
offline_memory() attempt in this loop can take 10 seconds if offline_pages()
is retrying page migration on a busy block.  If five early candidates time
out before $target blocks are collected, runner.sh kills the script with
TIMEOUT instead of letting it complete or skip.

> +restore_memory_blocks()
> +{
> +	local block ret=0
> +	for block in "${test_memory[@]}"; do
> +		if [ "${INITIAL_STATE[$block]}" = offline ]; then
> +			memory_is_offline "$block" || offline_memory "$block" || ret=1
>  		else
> +			memory_is_online "$block" || online_memory "$block" kernel || ret=1
>  		fi
>  	done
> +	return $ret
> +}

[Severity: Medium]
Does restore_memory_blocks() place initially-Movable blocks into a kernel
zone and leave blocks onlined into ZONE_MOVABLE during the test in the wrong
zone?

find_test_memory_blocks() only records "online" in INITIAL_STATE rather than
whether the block was originally in ZONE_MOVABLE or a kernel zone.  When
restore_memory_blocks() runs at the end of the test, online_memory "$block"
kernel writes online_kernel, forcing blocks that were originally in
ZONE_MOVABLE into a kernel zone where unmovable allocations can prevent
future offlining.  Conversely, if cleanup() runs while an initially
kernel-zone block is online in ZONE_MOVABLE, memory_is_online "$block"
succeeds and leaves it in ZONE_MOVABLE.

> +cleanup()
>  {
> +	if [ -n "$NOTIFIER_ERR_INJECT_DIR" ]; then
> +		echo 0 > "$NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error" 2>/dev/null
> +		echo 0 > "$NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_ONLINE/error" 2>/dev/null
> +		/sbin/modprobe -q -r memory-notifier-error-inject
>  	fi
> +	restore_memory_blocks >/dev/null 2>&1
>  }
>  
> +ktap_print_header
> +prerequisite
> +find_test_memory_blocks test_memory
> +if [ "${#test_memory[@]}" -eq 0 ]; then
> +	ktap_skip_all "unable to offline any memory"
> +	exit "$KSFT_SKIP"
> +fi
>  
> +trap cleanup EXIT

[Severity: Medium]
Should trap cleanup EXIT be installed before prerequisite() and
find_test_memory_blocks()?

prerequisite() loads the memory-notifier-error-inject module via
prepare_error_inject(), and find_test_memory_blocks() offlines up to
MAX_BLOCKS memory blocks.  If no blocks can be offlined and the script exits
with $KSFT_SKIP, cleanup() never runs and memory-notifier-error-inject is
left loaded; if the script is interrupted or times out during
find_test_memory_blocks() after offlining some blocks, those blocks are left
offline.

> +if [ -n "$NOTIFIER_ERR_INJECT_DIR" ]; then
> +	ktap_set_plan 7
> +else
> +	ktap_set_plan 3
> +fi
> +ktap_print_msg "Test scope: ${#test_memory[@]} memory block(s)"
> +
> +ktap_test_result "Online memory to ZONE_MOVABLE" \
> +	online_memory_blocks test_memory movable 0
> +ktap_test_result "Offline memory" \
> +	offline_memory_blocks test_memory 0
> +
> +if [ -n "$NOTIFIER_ERR_INJECT_DIR" ]; then
> +	online_memory_blocks test_memory movable 0
> +	echo $ERR_INJECT_ERRNO > "$NOTIFIER_ERR_INJECT_DIR/actions/MEM_GOING_OFFLINE/error"
> +	ktap_test_result "Offline memory with error injection" \
> +		offline_memory_blocks test_memory 1

[Severity: Low]
What happens if the setup call to online_memory_blocks test_memory movable 0
fails before "Offline memory with error injection"?

Its return value is not checked, so any block that failed to re-online stays
offline when offline_memory_blocks test_memory 1 runs; writing offline to an
already-offline block fails with -EINVAL without exercising the
MEM_GOING_OFFLINE notifier, and offline_memory_blocks() then fails with the
misleading message "Memory block $block was offlined unexpectedly".

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129211101.3568096-1-ramakrishna.katta@arm.com?part=1


      parent reply	other threads:[~2026-11-30 21:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 21:11 [PATCH] selftests/mm: improve memory hotplug test reliability Rama Krishna Katta
2026-11-30 11:12 ` David Hildenbrand (Arm)
2026-11-30 21:11 ` sashiko-bot [this message]

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=sashiko-outbox-241977@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Annam.SaiManisha@arm.com \
    --cc=david@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=osalvador@suse.de \
    --cc=ramakrishna.katta@arm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

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

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