From nobody Mon Sep 28 07:18:17 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3F413E5A29; Tue, 25 Aug 2026 08:59:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787648345; cv=none; b=UVfoyk1Zf4Hjui1qHhtxEmYkUPpi0fCmBWRNjoKiOh3bsONsdvYjzvX7LDeLbBiCvJJaL2pomT3G6qs05tGQ8IRpXo/zYTxL2kAsCpf79cyAGIqaNCopqN9cwVdnpRw7urJ2UPSuZv8oVhVaCDQddRwpGkCZg6X7MVwSk+7um6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787648345; c=relaxed/simple; bh=k6pCBBFFABJ70TEgwYH2rVhFPANiPd56PqlXBpQlIFU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X1PeTzkAwHWUztWvCCLIMN5ryQDnMcbfYjcC8nRAurUxYevDjqUNCnvQDxS8HZI2+xFbF/hLfGgELkCD7VfsjQjcF6s+vSUWrfh3Rg/y4on3WXbaRGcQnSdFZ1xZHv9pSLcD458DpJnqmhhgxmXU7hVCupt7h5HkUANYK5Bz8sA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 31e259c8a06311f19a56ed5b684f684d-20260825 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CC_NO_NAME, HR_CTE_8B HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME HR_SJ_DIGIT_LEN, HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM HR_SJ_PHRASE, HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT HR_TO_NO_NAME, IP_TRUSTED, SRC_TRUSTED, DN_TRUSTED, SA_TRUSTED SA_EXISTED, SN_TRUSTED, SN_EXISTED, SPF_NOPASS, DKIM_NOPASS DMARC_NOPASS, CIE_BAD, CIE_GOOD, CIE_GOOD_SPF, GTI_FG_BS GTI_RG_INFO, GTI_C_BU, AMN_GOOD, ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19,REQID:c80b6f39-c982-4c30-b324-adf35004c805,IP:10, URL:0,TC:0,Content:-5,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:30 X-CID-INFO: VERSION:1.3.19,REQID:c80b6f39-c982-4c30-b324-adf35004c805,IP:10,UR L:0,TC:0,Content:-5,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:30 X-CID-META: VersionHash:7db8b62,CLOUDID:e2087ae7da2c6fd8314fb0e0e8f1a487,BulkI D:260825165857GUSL112D,BulkQuantity:0,SF:17|19|38|66|78|81|82|102|127|865| 898,TC:nil,Content:0|15|50,EDM:5,IP:-2,URL:0,File:nil,RT:nil,Bulk:nil,QS:n il,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC :0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 31e259c8a06311f19a56ed5b684f684d-20260825 X-User: husong@kylinos.cn Received: from ctao-book.. [(223.70.159.239)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1638996277; Tue, 25 Aug 2026 16:58:52 +0800 From: Song Hu To: akpm@linux-foundation.org, usama.anjum@arm.com Cc: linux-mm@kvack.org, shuah@kernel.org, david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, peterx@redhat.com, sarthak.sharma@arm.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Song Hu Subject: [PATCH v4 1/3] selftests/mm: emit TAP header in uffd-wp-mremap Date: Tue, 25 Aug 2026 16:57:54 +0800 Message-ID: <20260825085756.63030-2-husong@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825085756.63030-1-husong@kylinos.cn> References: <20260825085756.63030-1-husong@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" uffd-wp-mremap calls ksft_set_plan() without ksft_print_header(), so its output is not valid KTAP. Add the header, like the sibling uffd tests (uffd-stress, uffd-unit-tests). Acked-by: Mike Rapoport (Microsoft) Reviewed-by: Sarthak Sharma Acked-by: Lorenzo Stoakes (ARM) Reviewed-by: Muhammad Usama Anjum Tested-by: Muhammad Usama Anjum Signed-off-by: Song Hu Acked-by: David Hildenbrand (Arm) --- tools/testing/selftests/mm/uffd-wp-mremap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/mm/uffd-wp-mremap.c b/tools/testing/se= lftests/mm/uffd-wp-mremap.c index c973d6722720..572c2516e874 100644 --- a/tools/testing/selftests/mm/uffd-wp-mremap.c +++ b/tools/testing/selftests/mm/uffd-wp-mremap.c @@ -347,6 +347,8 @@ int main(int argc, char **argv) struct thp_settings settings; int i, j, plan =3D 0; =20 + ksft_print_header(); + hugepage_save_settings(true, true); =20 check_uffd_wp_feature_supported(); --=20 2.43.0 From nobody Mon Sep 28 07:18:17 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFD983E5577; Tue, 25 Aug 2026 08:59:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787648347; cv=none; b=UzMJECb/d+VivLAtfxw+faS9Xuzor9OqNFOtC7oOPvIxd8JHIRS9TUbnc87E3B9BF+P0Kn7KDQoy9zb6JCeR3yyjn1hTJmLkALg351KHY0yz0L3C5pf6Z3N3qpz3aKf2kH7M5bTTaLsVmLNp0YjqsYwZVgGUEA5DxKUedSmrk9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787648347; c=relaxed/simple; bh=ekQ6llSsKW5YmufIU9CduWPGTA4ccClnR6Qhv7DH8vk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kgq3Hec8prUutcGTrkvNbW3qyvZqHX9ECQ4W8cYCTl4w6ewPYe9977BNm2wRPckmT/PCGa5GE6ccTXJgQ/QBRSOV35KSBAF6MbD3jQ1qlOGfIQRQ59qtVnvPWfbSAsQylYRK7M3XhehR4EABRZ5vxd5ZQpjij88AWFBKng3dLZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 340a63a8a06311f19a56ed5b684f684d-20260825 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CC_NO_NAME, HR_CTE_8B HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME HR_SJ_DIGIT_LEN, HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM HR_SJ_PHRASE, HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT HR_TO_NO_NAME, IP_TRUSTED, SRC_TRUSTED, DN_TRUSTED, SA_TRUSTED SA_EXISTED, SN_TRUSTED, SN_EXISTED, SPF_NOPASS, DKIM_NOPASS DMARC_NOPASS, CIE_BAD, CIE_GOOD, CIE_GOOD_SPF, GTI_FG_BS GTI_RG_INFO, GTI_C_BU, AMN_GOOD, ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19,REQID:d15b4706-d242-483d-acee-2c5a758a1985,IP:10, URL:0,TC:0,Content:0,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:35 X-CID-INFO: VERSION:1.3.19,REQID:d15b4706-d242-483d-acee-2c5a758a1985,IP:10,UR L:0,TC:0,Content:0,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:35 X-CID-META: VersionHash:7db8b62,CLOUDID:371e4b14d4f9886783239c063ed44db9,BulkI D:260825165900FI2LVGZY,BulkQuantity:0,SF:17|19|38|66|78|81|82|102|127|865| 898,TC:nil,Content:0|15|50,EDM:5,IP:-2,URL:0,File:nil,RT:nil,Bulk:nil,QS:n il,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC :0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_FSD,TF_CID_SPAM_SNR,TF_CID_SPAM_FAS X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 340a63a8a06311f19a56ed5b684f684d-20260825 X-User: husong@kylinos.cn Received: from ctao-book.. [(223.70.159.239)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 342430873; Tue, 25 Aug 2026 16:58:56 +0800 From: Song Hu To: akpm@linux-foundation.org, usama.anjum@arm.com Cc: linux-mm@kvack.org, shuah@kernel.org, david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, peterx@redhat.com, sarthak.sharma@arm.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Song Hu Subject: [PATCH v4 2/3] selftests/mm: emit TAP header and use TAP skip in mremap_test Date: Tue, 25 Aug 2026 16:57:55 +0800 Message-ID: <20260825085756.63030-3-husong@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825085756.63030-1-husong@kylinos.cn> References: <20260825085756.63030-1-husong@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" mremap_test calls ksft_set_plan() without ksft_print_header(), and its get_mmap_min_addr() skip path uses a bare exit(KSFT_SKIP) that prints no TAP line, so its output is not valid KTAP. Add the header and switch the skip to ksft_exit_skip(). Also fix two more KTAP compliance issues spotted in review: - get_mmap_min_addr() calls strerror(errno) after fclose(), which may clobber errno; save errno before fclose() instead. - Some ksft_*() messages embed "\n\t", so the text after each embedded newline is printed without the "# " prefix. Split those into separate messages. And cache mmap_min_addr in main() before ksft_set_plan(), so that the skip paths in get_mmap_min_addr() are taken before the plan is set; a skip after the plan leaves the run with fewer tests than planned. Acked-by: Mike Rapoport (Microsoft) Reviewed-by: Sarthak Sharma Reviewed-by: Muhammad Usama Anjum Tested-by: Muhammad Usama Anjum Acked-by: Lorenzo Stoakes (ARM) Signed-off-by: Song Hu --- tools/testing/selftests/mm/mremap_test.c | 43 ++++++++++++++---------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selft= ests/mm/mremap_test.c index 131d9d6db867..ab5420f2e875 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -111,18 +111,17 @@ static unsigned long long get_mmap_min_addr(void) return addr; =20 fp =3D fopen("/proc/sys/vm/mmap_min_addr", "r"); - if (fp =3D=3D NULL) { - ksft_print_msg("Failed to open /proc/sys/vm/mmap_min_addr: %s\n", - strerror(errno)); - exit(KSFT_SKIP); - } + if (!fp) + ksft_exit_skip("Failed to open /proc/sys/vm/mmap_min_addr: %s\n", + strerror(errno)); =20 n_matched =3D fscanf(fp, "%llu", &addr); if (n_matched !=3D 1) { - ksft_print_msg("Failed to read /proc/sys/vm/mmap_min_addr: %s\n", - strerror(errno)); + int err =3D errno; + fclose(fp); - exit(KSFT_SKIP); + ksft_exit_skip("Failed to read /proc/sys/vm/mmap_min_addr: %s\n", + strerror(err)); } =20 fclose(fp); @@ -1164,10 +1163,11 @@ static void run_mremap_test_case(struct test test_c= ase, int *failures, rand_addr); =20 if (remap_time < 0) { - if (test_case.expect_failure) - ksft_test_result_xfail("%s\n\tExpected mremap failure\n", - test_case.name); - else { + if (test_case.expect_failure) { + ksft_print_msg("%s: expected mremap failure\n", + test_case.name); + ksft_test_result_xfail("%s\n", test_case.name); + } else { ksft_test_result_fail("%s\n", test_case.name); *failures +=3D 1; } @@ -1177,11 +1177,13 @@ static void run_mremap_test_case(struct test test_c= ase, int *failures, * was faulted in. */ if (threshold_mb =3D=3D VALIDATION_NO_THRESHOLD || - test_case.config.region_size <=3D threshold_mb * _1MB) - ksft_test_result_pass("%s\n\tmremap time: %12lldns\n", - test_case.name, remap_time); - else + test_case.config.region_size <=3D threshold_mb * _1MB) { + ksft_print_msg("%s: mremap time: %12lldns\n", + test_case.name, remap_time); ksft_test_result_pass("%s\n", test_case.name); + } else { + ksft_test_result_pass("%s\n", test_case.name); + } } } =20 @@ -1250,13 +1252,18 @@ int main(int argc, char **argv) time_t t; FILE *maps_fp; =20 + ksft_print_header(); + + get_mmap_min_addr(); + pattern_seed =3D (unsigned int) time(&t); =20 if (parse_args(argc, argv, &threshold_mb, &pattern_seed) < 0) exit(EXIT_FAILURE); =20 - ksft_print_msg("Test configs:\n\tthreshold_mb=3D%u\n\tpattern_seed=3D%u\n= \n", - threshold_mb, pattern_seed); + ksft_print_msg("Test configs:\n"); + ksft_print_msg("threshold_mb=3D%u\n", threshold_mb); + ksft_print_msg("pattern_seed=3D%u\n", pattern_seed); =20 /* * set preallocated random array according to test configs; see the --=20 2.43.0 From nobody Mon Sep 28 07:18:17 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3ED13EA973; Tue, 25 Aug 2026 08:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787648348; cv=none; b=VDZ52ZYjCSy5voV0/NjEfdjNNkWBz/+JpeWa+TEe0CB+UcspNN2XfXbIEqQOuRnTcQ3u7kPuw/rKHCp88mxJLhOtv5w3DZWZz4X4h95cQzvfB0hTxmcGOgqxyd+TjT4r1/qKj637SiXcssQaG6t+Doa4ATFpkqcPk46QI0/4pIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787648348; c=relaxed/simple; bh=PzJfx4cGNY4kjx3CW6zgB/uPXf0Q67UQ/WJDvKSZGS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MEqKgrsyYx6QkFUrTa5ae1J6OtqQZCJHhzyUoPc+9wmdirFuA6hl61dzV+fYyru2GgNJTR74xwozIErSz0EvdHu/VYwnX6/LcMvHQVeYP75qW4uIaSqb5yxrz/tTa4P7ptRVxt8kRYHpsiE9XSkCZ4R2pwJoF9fsFHgifo+oFB8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 3638108aa06311f19a56ed5b684f684d-20260825 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CC_NO_NAME, HR_CTE_8B HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME HR_SJ_DIGIT_LEN, HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM HR_SJ_PHRASE, HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT HR_TO_NO_NAME, IP_TRUSTED, SRC_TRUSTED, DN_TRUSTED, SA_TRUSTED SA_EXISTED, SN_TRUSTED, SN_EXISTED, SPF_NOPASS, DKIM_NOPASS DMARC_NOPASS, CIE_BAD, CIE_GOOD, CIE_GOOD_SPF, GTI_FG_BS GTI_RG_INFO, GTI_C_BU, AMN_GOOD, ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19,REQID:82749ddd-5abf-47df-87ac-e335f40255ec,IP:10, URL:0,TC:0,Content:0,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:35 X-CID-INFO: VERSION:1.3.19,REQID:82749ddd-5abf-47df-87ac-e335f40255ec,IP:10,UR L:0,TC:0,Content:0,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:35 X-CID-META: VersionHash:7db8b62,CLOUDID:9f4af4901fe8095e1c04f2e2c1a67177,BulkI D:260825165903ABRGIBZD,BulkQuantity:0,SF:17|19|38|66|78|81|82|102|127|865| 898,TC:nil,Content:0|15|50,EDM:5,IP:-2,URL:0,File:nil,RT:nil,Bulk:nil,QS:n il,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC :0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 3638108aa06311f19a56ed5b684f684d-20260825 X-User: husong@kylinos.cn Received: from ctao-book.. [(223.70.159.239)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 727345008; Tue, 25 Aug 2026 16:58:59 +0800 From: Song Hu To: akpm@linux-foundation.org, usama.anjum@arm.com Cc: linux-mm@kvack.org, shuah@kernel.org, david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, peterx@redhat.com, sarthak.sharma@arm.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Song Hu Subject: [PATCH v4 3/3] selftests/mm: restore enable_soft_offline in hugetlb-soft-offline Date: Tue, 25 Aug 2026 16:57:56 +0800 Message-ID: <20260825085756.63030-4-husong@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825085756.63030-1-husong@kylinos.cn> References: <20260825085756.63030-1-husong@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" hugetlb-soft-offline toggles /proc/sys/vm/enable_soft_offline between 1 and 0 (test_soft_offline_common(1) then (0)) and leaves it at 0 when it finishes, silently disabling soft offlining for the whole system after the run. Save the original value before the test and restore it from an atexit() handler, as hugepage_restore_settings_atexit() in hugepage_settings.c already does. Use read_num()/write_num() from vm_util instead of hand-rolled popen()/fopen() helpers. The restore handler must not call write_num(): on failure it re-enters exit() through ksft_exit_fail_msg(), which is undefined behavior from inside an atexit handler. A non-root run hits it directly - the restore write fails the same way the write that triggered the exit did. Restore with plain open()/write(), best effort. Signed-off-by: Song Hu Acked-by: David Hildenbrand (Arm) Reviewed-by/Tested-by no longer apply and were dropped. Reviewed-by: Muhammad Usama Anjum --- Changes since v3: the restore handler no longer uses write_num(), whose failure path calls exit() from inside an atexit handler - undefined behavior on a non-root run. Restore with plain open()/write(), best effort. .../selftests/mm/hugetlb-soft-offline.c | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb-soft-offline.c b/tools/test= ing/selftests/mm/hugetlb-soft-offline.c index bc202e4ed2bd..4af9d3db7b5b 100644 --- a/tools/testing/selftests/mm/hugetlb-soft-offline.c +++ b/tools/testing/selftests/mm/hugetlb-soft-offline.c @@ -11,6 +11,7 @@ =20 #define _GNU_SOURCE #include +#include #include #include #include @@ -23,6 +24,7 @@ #include =20 #include "kselftest.h" +#include "vm_util.h" #include "hugepage_settings.h" =20 #ifndef MADV_SOFT_OFFLINE @@ -31,6 +33,8 @@ =20 #define EPREFIX " !!! " =20 +#define ENABLE_SOFT_OFFLINE_PATH "/proc/sys/vm/enable_soft_offline" + static int do_soft_offline(int fd, size_t len, int expect_errno) { char *filemap =3D NULL; @@ -77,26 +81,29 @@ static int do_soft_offline(int fd, size_t len, int expe= ct_errno) return ret; } =20 -static int set_enable_soft_offline(int value) -{ - char cmd[256] =3D {0}; - FILE *cmdfile =3D NULL; - - if (value !=3D 0 && value !=3D 1) - return -EINVAL; +static unsigned long orig_enable_soft_offline =3D -1UL; =20 - sprintf(cmd, "echo %d > /proc/sys/vm/enable_soft_offline", value); - cmdfile =3D popen(cmd, "r"); +/* + * Runs from an atexit handler, so it must not call anything that + * exits on failure: write_num() would re-enter exit() through + * ksft_exit_fail_msg(). + */ +static void restore_enable_soft_offline(void) +{ + char buf[24]; + int fd, len; =20 - if (cmdfile) - ksft_print_msg("enable_soft_offline =3D> %d\n", value); - else { - ksft_perror(EPREFIX "failed to set enable_soft_offline"); - return errno; - } + if (orig_enable_soft_offline =3D=3D -1UL) + return; =20 - pclose(cmdfile); - return 0; + len =3D snprintf(buf, sizeof(buf), "%lu", orig_enable_soft_offline); + fd =3D open(ENABLE_SOFT_OFFLINE_PATH, O_WRONLY); + if (fd < 0) + return; + if (write(fd, buf, len) !=3D len) + ksft_print_msg("failed to restore enable_soft_offline: %s\n", + strerror(errno)); + close(fd); } =20 static int create_hugetlbfs_file(struct statfs *file_stat) @@ -145,10 +152,7 @@ static void test_soft_offline_common(int enable_soft_o= ffline) hugepagesize_kb =3D file_stat.f_bsize / 1024; ksft_print_msg("Hugepagesize is %ldkB\n", hugepagesize_kb); =20 - if (set_enable_soft_offline(enable_soft_offline) !=3D 0) { - close(fd); - ksft_exit_fail_msg("Failed to set enable_soft_offline\n"); - } + write_num(ENABLE_SOFT_OFFLINE_PATH, enable_soft_offline); =20 nr_hugepages_before =3D hugetlb_nr_default_pages(); =20 @@ -192,6 +196,9 @@ int main(int argc, char **argv) =20 ksft_set_plan(2); =20 + orig_enable_soft_offline =3D read_num(ENABLE_SOFT_OFFLINE_PATH); + atexit(restore_enable_soft_offline); + test_soft_offline_common(1); test_soft_offline_common(0); =20 --=20 2.43.0