From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796073102; b=WX/l5ujWiWtxA3w49EnodiUQdzE7nI2Z4suiUUTOadItbTYkWcbVeYymi3fQL6072W8I ytFDGfSGX6xHfOaVcqvHFbuxENQLSj62y1PX6wj4788MEJ2I9HTKhesa8f8G/iovyKBzH +AoL6IPh1ylEV/jKNM20i9OoM3NhjVtqaT4CsOeNvSnaJaMgAUHNe/e3aMy30bZoa/XWF wi9f9Ycvrz+dlM/xA2nELCcyicJWCXojF0o9hyX1Sm0pMRcRPQc7xKb+2QnP5OvsJZq2U M5MtHz7Ht4OO9BziDbxJlRsxyub1fUivWSvX9nO88MhqMlg4xnlFg0+ovmviT/Rmg7w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073102; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=1fk8TyNA18nvnjoAq7/gw4/vAcGQmkMcKxyNGySpy8c=; b=Fom1ydkNqN9rj+WB1srfpgUOLyolPzw2yL21SnrtBAi7soHUBxkwDQ7/bY1e17dY/y6d PtQkMAsfuRi+QDKdg4Drw+wb8fpoLcwaXsPEGgdUnhbpoM4hQ5sRcGMnW++4vObSZsVCr hGqti3Lze3J5oxxd0fOWOITvgLTLrn9/5G4xdPAL8+AqzdnMtLwgOVIIg8Hbig6f/Zbb8 SZ8qp3PUIfsUeEOdEZlIuzEV5s+rsrdjtcjBbdqXMNSGHbJZweVILDtPitwKxlJnZrLEr jk6yne1MaGj8bKoqx5QbAiXJyA3XnHwLqDm+T2uukhPx2E4AWDcnuHXqGIYQqso3neA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UKES1fLn; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E452B606A31A for ; Mon, 30 Nov 2026 21:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UKES1fLn Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FABB1F00897; Mon, 30 Nov 2026 21:11:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796073101; bh=1fk8TyNA18nvnjoAq7/gw4/vAcGQmkMcKxyNGySpy8c=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=UKES1fLnx77e/av3XyhU2l4t+hCFseAghGzxgUK+WUYqELGcwyigaKozSvVpGdZX0 I8IIwxn1q2z+L/A2bbrOxj7xdcP7mGQZMMyi/uuaTu8OcSsFUaQu9j3bYW0IJtxu3M 8thO2wrNQP99mPyfIK27RhaRrVirNPRS73HmtkaTY5B+vViJ9n2U0iZsJPmluXkmAf Ss0CKEe5uLnD978PEk4eX6uQpRrzJd7W1XXZAfOe1DQiFyZeI1XdvQuGSPxDpnjyZ2 SNeQw+BQ4S6FjF1jkp8hXMbEI49KkSnDmEbJ1udBeWCaFO0a/0UB3S28OcMPeVHt95 wHuod5ik+QrUA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] selftests/mm: improve memory hotplug test reliability Reply-To: sashiko-reviews@lists.linux.dev To: "Rama Krishna Katta" , linux-mm@kvack.org Cc: "Annam Sai Manisha" , "David Hildenbrand" , "Oscar Salvador" , "Shuah Khan" , linux-cxl@vger.kernel.org In-Reply-To: <20261129211101.3568096-1-ramakrishna.katta@arm.com> References: <20261129211101.3568096-1-ramakrishna.katta@arm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 21:11:40 +0000 X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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/test= ing/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 > =20 > TEST_PROGS :=3D mem-on-off-test.sh > =20 > -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 > =20 > -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=3D$1 > + local target > =20 > + for path in "$SYSFS"/devices/system/memory/memory[0-9]*; do > + candidates+=3D("${path##*/memory}") > + done > + target=3D$(((${#candidates[@]} + 1) / 2)) > + [ "$target" -gt "$MAX_BLOCKS" ] && target=3D$MAX_BLOCKS > + blocks=3D() > + 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]=3Doffline > + blocks+=3D("$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]=3Donline > + blocks+=3D("$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=3D0 > + for block in "${test_memory[@]}"; do > + if [ "${INITIAL_STATE[$block]}" =3D offline ]; then > + memory_is_offline "$block" || offline_memory "$block" || ret=3D1 > else > + memory_is_online "$block" || online_memory "$block" kernel || ret=3D1 > 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 > } > =20 > +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 > =20 > +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_OF= FLINE/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". --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129211101.3568= 096-1-ramakrishna.katta@arm.com?part=3D1