Linux CXL
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rama Krishna Katta" <ramakrishna.katta@arm.com>,
	david@kernel.org, osalvador@suse.de, shuah@kernel.org
Cc: linux-mm@kvack.org, linux-cxl@vger.kernel.org,
	"Annam Sai Manisha" <Annam.SaiManisha@arm.com>
Subject: Re: [PATCH v2] selftests/mm: improve memory hotplug test reliability
Date: Thu, 03 Dec 2026 15:38:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-248132@kernel.org> (raw)
In-Reply-To: <20261202204303.2777765-1-ramakrishna.katta@arm.com>

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

      reply	other threads:[~2026-12-03 15:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 20:43 [PATCH v2] selftests/mm: improve memory hotplug test reliability Rama Krishna Katta
2026-12-03 15:38 ` 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-248132@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