From nobody Sun Apr 5 16:28:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 987C342050 for ; Thu, 2 Apr 2026 01:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775094375; cv=none; b=pqYnpXrgfXm7F8ri1pQLESpFIrs4yAj9v/hhlo6RH34yYoHytdRlLCNQiGM6v20QiLoaEtrTbflgX9Obvlbr84smLiz0AJm45tioBVFbotYYAgPDJJxtF6YJWhhmWkUsOyux4XBnYx2hDbmxmQvPU67qwknDy2MTsR44XooCWGo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775094375; c=relaxed/simple; bh=91ifg2wEJIjxKprIIwRg4nIUGRb1cJdHSKa9VgWepH0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QAkMYBPMETu0QRlVAdPrjpPSd158PdLZG8vLDfLIp3q7ltLQ3tX9omB+BGP235hSI8jrePIzZEB/ELfJ+y1DqvYHXzJ+NHZVDFUL6Q1xy2eCrSso9tw7f7rTzq+SuAT+5ZW/ApcIEOPXHbPOBP1dMgRdf+XS/AxPFiAmHzPuz6A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ble5kxhm; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ble5kxhm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775094372; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i/pPSxcnZYo2SMuy8vaLW5s+T4/KTmPmuksnl9sWXmE=; b=ble5kxhmt6yPDfgHMY6/AKz4vGrEk9AEITIEOJkH70gqqWuAyp8ikvba+nG6VShe6eFJjP pl8KjyMGyxdwYdX3x4ASwl925EFTzyUa006qivyhXMASqv2AurctDQM1fSFpHb0GV6/fHl p6Vshyogms7CIGhGDAqKEZQoQrBzS2Q= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-20-5YxuQcR5PYealfh2_AOtGQ-1; Wed, 01 Apr 2026 21:46:08 -0400 X-MC-Unique: 5YxuQcR5PYealfh2_AOtGQ-1 X-Mimecast-MFC-AGG-ID: 5YxuQcR5PYealfh2_AOtGQ_1775094366 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AC19C1956055; Thu, 2 Apr 2026 01:46:05 +0000 (UTC) Received: from dell-per7425-02.rhts.eng.pek2.redhat.com (dell-per7425-02.rhts.eng.pek2.redhat.com [10.73.116.18]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CCF761955F2E; Thu, 2 Apr 2026 01:45:56 +0000 (UTC) From: Chunyu Hu To: akpm@linux-foundation.org, david@kernel.org, shuah@kernel.org, linux-mm@kvack.org, ljs@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, chuhu@redhat.com, Li Wang Subject: [PATCH v8 1/6] selftests/mm/guard-regions: skip collapse test when thp not enabled Date: Thu, 2 Apr 2026 09:45:38 +0800 Message-ID: <20260402014543.1671131-2-chuhu@redhat.com> In-Reply-To: <20260402014543.1671131-1-chuhu@redhat.com> References: <20260402014543.1671131-1-chuhu@redhat.com> 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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" When thp is not available, just skip the collape tests to avoid the false negative. Without the change, run with a thp disabled kernel: ./run_vmtests.sh -t madv_guard -n 1 # RUN guard_regions.anon.collapse ... # guard-regions.c:2217:collapse:Expected madvise(ptr, size, MADV_NOHUGEPA= GE) (-1) =3D=3D 0 (0) # collapse: Test terminated by assertion # FAIL guard_regions.anon.collapse not ok 2 guard_regions.anon.collapse # RUN guard_regions.shmem.collapse ... # guard-regions.c:2217:collapse:Expected madvise(ptr, size, MADV_NOHUGEPA= GE) (-1) =3D=3D 0 (0) # collapse: Test terminated by assertion # FAIL guard_regions.shmem.collapse not ok 32 guard_regions.shmem.collapse # RUN guard_regions.file.collapse ... # guard-regions.c:2217:collapse:Expected madvise(ptr, size, MADV_NOHUGEPA= GE) (-1) =3D=3D 0 (0) # collapse: Test terminated by assertion # FAIL guard_regions.file.collapse not ok 62 guard_regions.file.collapse # FAILED: 87 / 90 tests passed. # 17 skipped test(s) detected. Consider enabling relevant config options = to improve coverage. # Totals: pass:70 fail:3 xfail:0 xpass:0 skip:17 error:0 With this change, run with thp disabled kernel: ./run_vmtests.sh -t madv_guard -n 1 # RUN guard_regions.anon.collapse ... # SKIP Transparent Hugepages not available # OK guard_regions.anon.collapse ok 2 guard_regions.anon.collapse # SKIP Transparent Hugepages not availab= le # RUN guard_regions.file.collapse ... # SKIP Transparent Hugepages not available # OK guard_regions.file.collapse ok 62 guard_regions.file.collapse # SKIP Transparent Hugepages not availa= ble # RUN guard_regions.shmem.collapse ... # SKIP Transparent Hugepages not available # OK guard_regions.shmem.collapse ok 32 guard_regions.shmem.collapse # SKIP Transparent Hugepages not avail= able # PASSED: 90 / 90 tests passed. # 20 skipped test(s) detected. Consider enabling relevant config options = to improve coverage. # Totals: pass:70 fail:0 xfail:0 xpass:0 skip:20 error:0 Reviewed-by: Lorenzo Stoakes (Oracle) Acked-by: David Hildenbrand (Arm) Reviewed-by: Zi Yan Acked-by: Mike Rapoport (Microsoft) CC: Li Wang Signed-off-by: Chunyu Hu --- Changes in v7: - Add reviewed-by from Lorenzo Changes in v5: - updated reviewed-by and acked-by Changes in v4: - use thp_available instead of thp_is_enabled() as when thp is set to never, madvise(MADV_COLLAPSE) will still succeed by design. So a failure in madvise(MADV_COLLAPSE) on guard region will verify guard region denies it. This is suggested from AI. - removed the 'Reviewed-by' and 'Acked-by' as the code changes. Sorry for that but it seems the changes is a little huge? (1 out of 2 lines).. Changes in v3: - commit message: update the log snippet with where the fail happens and add the '-n1' to the command. - fix the 'false positive' to 'false negative' - add reviwed by from Mike Changes in v2: - add reviewed by from Zi and Lorenzo - add acked-by from David --- tools/testing/selftests/mm/guard-regions.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/mm/guard-regions.c b/tools/testing/sel= ftests/mm/guard-regions.c index dbd21d66d383..48e8b1539be3 100644 --- a/tools/testing/selftests/mm/guard-regions.c +++ b/tools/testing/selftests/mm/guard-regions.c @@ -21,6 +21,7 @@ #include #include #include "vm_util.h" +#include "thp_settings.h" =20 #include "../pidfd/pidfd.h" =20 @@ -2195,6 +2196,9 @@ TEST_F(guard_regions, collapse) char *ptr; int i; =20 + if (!thp_available()) + SKIP(return, "Transparent Hugepages not available\n"); + /* Need file to be correct size for tests for non-anon. */ if (variant->backing !=3D ANON_BACKED) ASSERT_EQ(ftruncate(self->fd, size), 0); --=20 2.53.0 From nobody Sun Apr 5 16:28:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 3D93929D267 for ; Thu, 2 Apr 2026 01:46:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775094381; cv=none; b=s9dckcLgg0N5QAWqG/8ciB09kc9d79JDjYFxAx2l3Z89B/oIkfigsu8DBucHoXr4dgYo6t0O2ppMGy9sP9I0Fx6U3wR5oxXHOWwUqQqf8ZIpVvFXvRb/usgLfRBdxJmxauTHVQ85zkrEpaQ6JVOwFfta4tultlLX4MR1Kg5Z8yE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775094381; c=relaxed/simple; bh=OR4axWDR5ba1eCvLKgk0UjjVPAv805aONe5n26nMGn4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aBt0YNXDHtHTZPxnkyBOqZfw1i9Z1qHbBVmTZhKEgz+WdgxuEmHXGkhUR74ynkIzUEac0pmU+4ut9niKtIjhmWpoG92FH2KQ9QyZKvDlrWy1rXZ+H/KI9XSJz6LjM5IHRHj16uJrj7FB4XqpHQIz5y8Za3SNNQgzSFOpg60vf+E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=L1uGEr+i; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="L1uGEr+i" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775094379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n94zkV/pmZZJ7k7RKaGT+ic/vcFa4MFeGtug2QtIPI4=; b=L1uGEr+iyLtL4ff766YvOpAiGkHdHGvKSqpqlknEedDrk2Izjb4hLhl8ngJqAEvFWD+4m7 VSbrV0stiZxtGXydh6e2oJYngphpx36tAyTc36vQMbxyiN0gBvcXQftfYJx1F35U/ak5Bw dGEyuQEljEGAuCGsMLkn+OtvrSU/dHM= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-502-NNDtiJKwNi2izcF6TcqZvA-1; Wed, 01 Apr 2026 21:46:17 -0400 X-MC-Unique: NNDtiJKwNi2izcF6TcqZvA-1 X-Mimecast-MFC-AGG-ID: NNDtiJKwNi2izcF6TcqZvA_1775094375 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CA7F61956096; Thu, 2 Apr 2026 01:46:14 +0000 (UTC) Received: from dell-per7425-02.rhts.eng.pek2.redhat.com (dell-per7425-02.rhts.eng.pek2.redhat.com [10.73.116.18]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 666D519560AB; Thu, 2 Apr 2026 01:46:06 +0000 (UTC) From: Chunyu Hu To: akpm@linux-foundation.org, david@kernel.org, shuah@kernel.org, linux-mm@kvack.org, ljs@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, chuhu@redhat.com, Li Wang Subject: [PATCH v8 2/6] selftests/mm: soft-dirty: skip two tests when thp is not available Date: Thu, 2 Apr 2026 09:45:39 +0800 Message-ID: <20260402014543.1671131-3-chuhu@redhat.com> In-Reply-To: <20260402014543.1671131-1-chuhu@redhat.com> References: <20260402014543.1671131-1-chuhu@redhat.com> 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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" The test_hugepage test contain two sub tests. If just reporting one skip when thp not available, there will be error in the log because the test count don't match the test plan. Change to skip two tests by running the ksft_test_result_skip twice in this case. Without the fix (run test on thp disabled kernel): ./run_vmtests.sh -t soft_dirty # -------------------- # running ./soft-dirty # -------------------- # TAP version 13 # 1..19 # ok 1 Test test_simple # ok 2 Test test_vma_reuse dirty bit of allocated page # ok 3 Test test_vma_reuse dirty bit of reused address page # ok 4 # SKIP Transparent Hugepages not available # ok 5 Test test_mprotect-anon dirty bit of new written page # ok 6 Test test_mprotect-anon soft-dirty clear after clear_refs # ok 7 Test test_mprotect-anon soft-dirty clear after marking RO # ok 8 Test test_mprotect-anon soft-dirty clear after marking RW # ok 9 Test test_mprotect-anon soft-dirty after rewritten # ok 10 Test test_mprotect-file dirty bit of new written page # ok 11 Test test_mprotect-file soft-dirty clear after clear_refs # ok 12 Test test_mprotect-file soft-dirty clear after marking RO # ok 13 Test test_mprotect-file soft-dirty clear after marking RW # ok 14 Test test_mprotect-file soft-dirty after rewritten # ok 15 Test test_merge-anon soft-dirty after remap merge 1st pg # ok 16 Test test_merge-anon soft-dirty after remap merge 2nd pg # ok 17 Test test_merge-anon soft-dirty after mprotect merge 1st pg # ok 18 Test test_merge-anon soft-dirty after mprotect merge 2nd pg # # 1 skipped test(s) detected. Consider enabling relevant config options= to improve coverage. # # Planned tests !=3D run tests (19 !=3D 18) # # Totals: pass:17 fail:0 xfail:0 xpass:0 skip:1 error:0 # [FAIL] not ok 52 soft-dirty # exit=3D1 With the fix (run test on thp disabled kernel): ./run_vmtests.sh -t soft_dirty # -------------------- # running ./soft-dirty # TAP version 13 # -------------------- # running ./soft-dirty # -------------------- # TAP version 13 # 1..19 # ok 1 Test test_simple # ok 2 Test test_vma_reuse dirty bit of allocated page # ok 3 Test test_vma_reuse dirty bit of reused address page # # Transparent Hugepages not available # ok 4 # SKIP Test test_hugepage huge page allocation # ok 5 # SKIP Test test_hugepage huge page dirty bit # ok 6 Test test_mprotect-anon dirty bit of new written page # ok 7 Test test_mprotect-anon soft-dirty clear after clear_refs # ok 8 Test test_mprotect-anon soft-dirty clear after marking RO # ok 9 Test test_mprotect-anon soft-dirty clear after marking RW # ok 10 Test test_mprotect-anon soft-dirty after rewritten # ok 11 Test test_mprotect-file dirty bit of new written page # ok 12 Test test_mprotect-file soft-dirty clear after clear_refs # ok 13 Test test_mprotect-file soft-dirty clear after marking RO # ok 14 Test test_mprotect-file soft-dirty clear after marking RW # ok 15 Test test_mprotect-file soft-dirty after rewritten # ok 16 Test test_merge-anon soft-dirty after remap merge 1st pg # ok 17 Test test_merge-anon soft-dirty after remap merge 2nd pg # ok 18 Test test_merge-anon soft-dirty after mprotect merge 1st pg # ok 19 Test test_merge-anon soft-dirty after mprotect merge 2nd pg # # 2 skipped test(s) detected. Consider enabling relevant config options= to improve coverage. # # Totals: pass:17 fail:0 xfail:0 xpass:0 skip:2 error:0 # [PASS] ok 1 soft-dirty hwpoison_inject # SUMMARY: PASS=3D1 SKIP=3D0 FAIL=3D0 1..1 Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Lorenzo Stoakes (Oracle) Acked-by: David Hildenbrand (Arm) Reviewed-by: Zi Yan CC: Li Wang Signed-off-by: Chunyu Hu --- Changes in v3: - Add reviewed by from Mike Changes in v2: - add reviewed by from Lorenzo and Zi - add acked-by from David --- tools/testing/selftests/mm/soft-dirty.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/soft-dirty.c b/tools/testing/selfte= sts/mm/soft-dirty.c index 59c0dbe99a9b..bcfcac99b436 100644 --- a/tools/testing/selftests/mm/soft-dirty.c +++ b/tools/testing/selftests/mm/soft-dirty.c @@ -82,7 +82,9 @@ static void test_hugepage(int pagemap_fd, int pagesize) int i, ret; =20 if (!thp_is_enabled()) { - ksft_test_result_skip("Transparent Hugepages not available\n"); + ksft_print_msg("Transparent Hugepages not available\n"); + ksft_test_result_skip("Test %s huge page allocation\n", __func__); + ksft_test_result_skip("Test %s huge page dirty bit\n", __func__); return; } =20 --=20 2.53.0 From nobody Sun Apr 5 16:28:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 4EEF029A31C for ; Thu, 2 Apr 2026 01:46:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775094391; cv=none; b=i1MO2Jgky7ZjPfeJIXSU+onF4Lyz/na5ROVwcCAAwfFCgv9DHvhiAFqGZCQXcUBvziccll+AKmjNmyjnDudBROAhBpxqkwNc6QMKnjlolMSJzTL6PsxNIIgpjyu6RWn61hgLqqUHZ7ZYVAurYOea5pIRp3AYn3scNN/f5Mi2RHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775094391; c=relaxed/simple; bh=v8gKI+PNCs7vEzGBzviHnReOhtiQ1Yf/5kZHPLYZtH4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U8IS/wapXqj4tZgvBZBXWRmP9bI35RbEHNE9jP6VH9PEe//SoqxIp2Wl41vBOTfLWqgZFhUVuACfDlNk6D4PznjQTAceZxYSayHtjR65TWa2LKQ0+E9VxJRtJjKFvcZx3+w1HOs0uEEThDLZ0YKyNaVyePHtti0CZ+Ol1QoMqeg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=OrnSis+Y; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OrnSis+Y" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775094389; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9tZowJL8GjFLSw4sIge6Gujv1KBlMa1KFIvCe3PwXUI=; b=OrnSis+YwA4z/3wyklxF5y96oJ0rRT73kD4ImdWpvfjkjRKrbrDyk2eN+MI0BzZIgKMn3X 3vePJO5OTK55mbSAST9FsxDe6nRDNLjT7ya0arOcfXujVNtc72aJWR0EiBcohd9EpQhop9 lozO3YfbyIAbqIroHx/UVJZkj/glaI8= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-486-CrXok06gMk2u5HjxF2_H3g-1; Wed, 01 Apr 2026 21:46:26 -0400 X-MC-Unique: CrXok06gMk2u5HjxF2_H3g-1 X-Mimecast-MFC-AGG-ID: CrXok06gMk2u5HjxF2_H3g_1775094383 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 70A4F1956065; Thu, 2 Apr 2026 01:46:23 +0000 (UTC) Received: from dell-per7425-02.rhts.eng.pek2.redhat.com (dell-per7425-02.rhts.eng.pek2.redhat.com [10.73.116.18]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 774CB1955F25; Thu, 2 Apr 2026 01:46:15 +0000 (UTC) From: Chunyu Hu To: akpm@linux-foundation.org, david@kernel.org, shuah@kernel.org, linux-mm@kvack.org, ljs@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, chuhu@redhat.com Subject: [PATCH v8 3/6] selftests/mm: move write_file helper to vm_util Date: Thu, 2 Apr 2026 09:45:40 +0800 Message-ID: <20260402014543.1671131-4-chuhu@redhat.com> In-Reply-To: <20260402014543.1671131-1-chuhu@redhat.com> References: <20260402014543.1671131-1-chuhu@redhat.com> 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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" thp_settings provides write_file() helper for safely writing to a file and exit when write failure happens. It's a very low level helper and many sub tests need such a helper, not only thp tests. split_huge_page_test also defines a write_file locally. The two have minior differences in return type and used exit api. And there would be conflicts if split_huge_page_test wanted to include thp_settings.h because of different prototype, making it less convenient. It's possisble to merge the two, although some tests don't use the kselftest infrastrucutre for testing. It would also work when using the ksft_exit_msg() to exit in my test, as the counters are all zero. Output will be like: TAP version 13 1..62 Bail out! /proc/sys/vm/drop_caches1 open failed: No such file or directory # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0 So here we just keep the version in split_huge_page_test, and move it into the vm_util. This makes it easy to maitain and user could just include one vm_util.h when they don't need thp setting helpers. Keep the prototype of void return as the function will exit on any error, return value is not necessary, and will simply the callers like write_num() and write_string(). Reviewed-by: Lorenzo Stoakes (Oracle) Acked-by: David Hildenbrand (Arm) Reviewed-by: Zi Yan Acked-by: Mike Rapoport (Microsoft) Suggested-by: Mike Rapoport Signed-off-by: Chunyu Hu --- Changes in v6: - add reviewed-by from Lorenzo Changes in v5: - updated acked-by and reviewed-by Changes in v3: - make the write_file void return Changes in v2: new patch from v2 --- .../selftests/mm/split_huge_page_test.c | 15 -------- tools/testing/selftests/mm/thp_settings.c | 35 ++----------------- tools/testing/selftests/mm/thp_settings.h | 1 - tools/testing/selftests/mm/vm_util.c | 15 ++++++++ tools/testing/selftests/mm/vm_util.h | 2 ++ 5 files changed, 20 insertions(+), 48 deletions(-) diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/test= ing/selftests/mm/split_huge_page_test.c index e0167111bdd1..93f205327b84 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -255,21 +255,6 @@ static int check_after_split_folio_orders(char *vaddr_= start, size_t len, return status; } =20 -static void write_file(const char *path, const char *buf, size_t buflen) -{ - int fd; - ssize_t numwritten; - - fd =3D open(path, O_WRONLY); - if (fd =3D=3D -1) - ksft_exit_fail_msg("%s open failed: %s\n", path, strerror(errno)); - - numwritten =3D write(fd, buf, buflen - 1); - close(fd); - if (numwritten < 1) - ksft_exit_fail_msg("Write failed\n"); -} - static void write_debugfs(const char *fmt, ...) { char input[INPUT_MAX]; diff --git a/tools/testing/selftests/mm/thp_settings.c b/tools/testing/self= tests/mm/thp_settings.c index 574bd0f8ae48..e748ebfb3d4e 100644 --- a/tools/testing/selftests/mm/thp_settings.c +++ b/tools/testing/selftests/mm/thp_settings.c @@ -6,6 +6,7 @@ #include #include =20 +#include "vm_util.h" #include "thp_settings.h" =20 #define THP_SYSFS "/sys/kernel/mm/transparent_hugepage/" @@ -64,29 +65,6 @@ int read_file(const char *path, char *buf, size_t buflen) return (unsigned int) numread; } =20 -int write_file(const char *path, const char *buf, size_t buflen) -{ - int fd; - ssize_t numwritten; - - fd =3D open(path, O_WRONLY); - if (fd =3D=3D -1) { - printf("open(%s)\n", path); - exit(EXIT_FAILURE); - return 0; - } - - numwritten =3D write(fd, buf, buflen - 1); - close(fd); - if (numwritten < 1) { - printf("write(%s)\n", buf); - exit(EXIT_FAILURE); - return 0; - } - - return (unsigned int) numwritten; -} - unsigned long read_num(const char *path) { char buf[21]; @@ -104,10 +82,7 @@ void write_num(const char *path, unsigned long num) char buf[21]; =20 sprintf(buf, "%ld", num); - if (!write_file(path, buf, strlen(buf) + 1)) { - perror(path); - exit(EXIT_FAILURE); - } + write_file(path, buf, strlen(buf) + 1); } =20 int thp_read_string(const char *name, const char * const strings[]) @@ -165,11 +140,7 @@ void thp_write_string(const char *name, const char *va= l) printf("%s: Pathname is too long\n", __func__); exit(EXIT_FAILURE); } - - if (!write_file(path, val, strlen(val) + 1)) { - perror(path); - exit(EXIT_FAILURE); - } + write_file(path, val, strlen(val) + 1); } =20 unsigned long thp_read_num(const char *name) diff --git a/tools/testing/selftests/mm/thp_settings.h b/tools/testing/self= tests/mm/thp_settings.h index 76eeb712e5f1..7748a9009191 100644 --- a/tools/testing/selftests/mm/thp_settings.h +++ b/tools/testing/selftests/mm/thp_settings.h @@ -63,7 +63,6 @@ struct thp_settings { }; =20 int read_file(const char *path, char *buf, size_t buflen); -int write_file(const char *path, const char *buf, size_t buflen); unsigned long read_num(const char *path); void write_num(const char *path, unsigned long num); =20 diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests= /mm/vm_util.c index a6d4ff7dfdc0..ad96d19d1b85 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -764,3 +764,18 @@ int unpoison_memory(unsigned long pfn) =20 return ret > 0 ? 0 : -errno; } + +void write_file(const char *path, const char *buf, size_t buflen) +{ + int fd; + ssize_t numwritten; + + fd =3D open(path, O_WRONLY); + if (fd =3D=3D -1) + ksft_exit_fail_msg("%s open failed: %s\n", path, strerror(errno)); + + numwritten =3D write(fd, buf, buflen - 1); + close(fd); + if (numwritten < 1) + ksft_exit_fail_msg("Write failed\n"); +} diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests= /mm/vm_util.h index e9c4e24769c1..1a07305ceff4 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -166,3 +166,5 @@ int unpoison_memory(unsigned long pfn); =20 #define PAGEMAP_PRESENT(ent) (((ent) & (1ull << 63)) !=3D 0) #define PAGEMAP_PFN(ent) ((ent) & ((1ull << 55) - 1)) + +void write_file(const char *path, const char *buf, size_t buflen); --=20 2.53.0 From nobody Sun Apr 5 16:28:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 9D93C3254B2 for ; Thu, 2 Apr 2026 01:46:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775094402; cv=none; b=TNney3f7NlfcZbMIzJYnpx1xFS3JsQAomUYkvc/N/4xn0pSknNNgJcupQcBTsO67048EnSzJ4qtkAYjA7jm2Uq6en0MJ+NAVh3thw7dPl/v+3ezwXlTh51VxzqBSvUZo69RxZKPq9ucQaf77cXK2ld1MiOQKRbtSVA2NU8ksQPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775094402; c=relaxed/simple; bh=F/tQZ7MZbHJuL6ABQZeL560ScXtKvvHOv6ROCzLjtdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SPStLukf4xa7uY0z+tQMH+An/E5acsZBLfFQ/L78s9imIaZw98CUWJH2RTZGy5vIpjmdO/WLkoNnKgvJ02YCmO8bSirICmimKRNxKFmOfsKseuVxsA3XLNkJvGb2kxzwZ2hr296zxXZZIt64ksFre+lTy1NqvkxIAopFuvlpu1I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=B2HTg37d; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="B2HTg37d" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775094398; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KDU4afNqvnoHoqSo/k3e5WTx+bzCLp33/wZdOxE3SPA=; b=B2HTg37dRVGgIDxkbv+xbVw71b6OEERBXos6Q1ekSNt5a3ApWBVRczseq/HxcPmlfd57XQ 1Rh7qcQGVE3H1dKp7n0OxOeDgaGW8lNv2phCgr9DghbIbTvRWdDMmc6Lh1g0mHoH3ymmTr jP+YMIXfk+7ByvirmxBQSVraYpklyy8= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-248-CzV-77pMPretbtz4CzGeKg-1; Wed, 01 Apr 2026 21:46:34 -0400 X-MC-Unique: CzV-77pMPretbtz4CzGeKg-1 X-Mimecast-MFC-AGG-ID: CzV-77pMPretbtz4CzGeKg_1775094392 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 09E8D195604F; Thu, 2 Apr 2026 01:46:32 +0000 (UTC) Received: from dell-per7425-02.rhts.eng.pek2.redhat.com (dell-per7425-02.rhts.eng.pek2.redhat.com [10.73.116.18]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0862F19560AB; Thu, 2 Apr 2026 01:46:23 +0000 (UTC) From: Chunyu Hu To: akpm@linux-foundation.org, david@kernel.org, shuah@kernel.org, linux-mm@kvack.org, ljs@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, chuhu@redhat.com Subject: [PATCH v8 4/6] selftests/mm/vm_util: robust write_file() Date: Thu, 2 Apr 2026 09:45:41 +0800 Message-ID: <20260402014543.1671131-5-chuhu@redhat.com> In-Reply-To: <20260402014543.1671131-1-chuhu@redhat.com> References: <20260402014543.1671131-1-chuhu@redhat.com> 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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Add three more checks for buflen and numwritten. The buflen should be at least two, that means at least one char and the null-end. The error case check is added by checking numwriten < 0 instead of numwritten < 1. And the truncate case is checked. The test will exit if any of these conditions aren't met. Additionally, add more print information when a write failure occurs or a truncated write happens, providing clearer diagnostics. Signed-off-by: Chunyu Hu Acked-by: David Hildenbrand (Arm) --- Changes in v8: - go back to ksft_exit_fail_msg in the two error exit path as no clean ksft_exit_fail_perror that supports va_list Changes in v7: - add an empty line before the 'buflen < 1' line. And change to 'buflen < 2 to limit the buflen at least to be 2, so at least one char is allowed. - handle the numwriten < 0 case, which is the error path. - use ksft_exit_fail_perror in error exit path. - use %.*s to print the buf when error happened Changes in v6: - save/restore errno before and after the close(), so the log could show the correct error info on failure. Suggested by AI. Chagnes in v5: - new patch for making improve on write_file. Add more safety checks and diagnostics info in log --- tools/testing/selftests/mm/vm_util.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests= /mm/vm_util.c index ad96d19d1b85..db94564f4431 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -767,15 +767,24 @@ int unpoison_memory(unsigned long pfn) =20 void write_file(const char *path, const char *buf, size_t buflen) { - int fd; + int fd, saved_errno; ssize_t numwritten; =20 + if (buflen < 2) + ksft_exit_fail_msg("Incorrect buffer len: %zu\n", buflen); + fd =3D open(path, O_WRONLY); if (fd =3D=3D -1) ksft_exit_fail_msg("%s open failed: %s\n", path, strerror(errno)); =20 numwritten =3D write(fd, buf, buflen - 1); + saved_errno =3D errno; close(fd); - if (numwritten < 1) - ksft_exit_fail_msg("Write failed\n"); + errno =3D saved_errno; + if (numwritten < 0) + ksft_exit_fail_msg("%s write(%.*s) failed: %s\n", path, (int)(buflen - 1= ), + buf, strerror(errno)); + if (numwritten !=3D buflen - 1) + ksft_exit_fail_msg("%s write(%.*s) is truncated, expected %zu bytes, got= %zd bytes\n", + path, (int)(buflen - 1), buf, buflen - 1, numwritten); } --=20 2.53.0 From nobody Sun Apr 5 16:28:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 C9A9229A31C for ; Thu, 2 Apr 2026 01:46:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775094410; cv=none; b=RrE/yrntXk0LRo4YyinLGsFsAFRFLgNHO4ZFBlTZXQmXk3tyTGv0R9D85k5ZeUCtI6mbGrhd56Z7vF0Rg6k6M52/zkTuyW8LSot41vgHecdPMi5bJiWbJMJ6bTkVVQWy7JSSKg0eOKyI8asQ66H3f6H5rmUE2691YGZXQbPMMUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775094410; c=relaxed/simple; bh=8kcSjbIIEeXJAGXv7dzdKrrWxBbWF0Q3ow1gEe2ds6c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wpy+nWxvYSUpSgNPatgBhlPBr3Te6Nr3NKnYdRfKxMbzXmvrbXzyAz7xDH/23j7k84N8xkdooTjjmecnhFGQ3pD3dGTOS7M4rRwz85WC7kC3YPIjghP3vWFFQs/lK2xKH1F0Hz5bP7S5SUJRYi+pWy+6Fa67z7UcZ+OEOfd1vno= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bx1ABcqs; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bx1ABcqs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775094408; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cP9CaaUU0YGWeU606cF4HfEnHjH3cqBLv/sm6TUkYWs=; b=bx1ABcqsmA1BZHr6QoF18ANh9bZgw8W5NVlPcilksRLKYIWloStgtFNbpvJpxFjBnwc5nQ bpkTZP+1qJjo4zhV9yDdMhOt4wLaCsdNIY8gmiI95C3lBbXXoRbPLOUNPgVA1IbdFKha/0 hdiU/SX/8lYTNXSnmSfsSM4a8cPitVo= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-147-ikX5ZTKfMBSHvO7QSL9muw-1; Wed, 01 Apr 2026 21:46:43 -0400 X-MC-Unique: ikX5ZTKfMBSHvO7QSL9muw-1 X-Mimecast-MFC-AGG-ID: ikX5ZTKfMBSHvO7QSL9muw_1775094401 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3D56C19560A2; Thu, 2 Apr 2026 01:46:41 +0000 (UTC) Received: from dell-per7425-02.rhts.eng.pek2.redhat.com (dell-per7425-02.rhts.eng.pek2.redhat.com [10.73.116.18]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BB5E219560AB; Thu, 2 Apr 2026 01:46:32 +0000 (UTC) From: Chunyu Hu To: akpm@linux-foundation.org, david@kernel.org, shuah@kernel.org, linux-mm@kvack.org, ljs@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, chuhu@redhat.com, Li Wang Subject: [PATCH v8 5/6] selftests/mm: split_huge_page_test: skip the test when thp is not available Date: Thu, 2 Apr 2026 09:45:42 +0800 Message-ID: <20260402014543.1671131-6-chuhu@redhat.com> In-Reply-To: <20260402014543.1671131-1-chuhu@redhat.com> References: <20260402014543.1671131-1-chuhu@redhat.com> 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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" When thp is not enabled on some kernel config such as realtime kernel, the test will report failure. Fix the false positive by skipping the test directly when thp is not enabled. Tested with thp disabled kernel: Before The fix: # -------------------------------------------------- # running ./split_huge_page_test /tmp/xfs_dir_Ywup9p # -------------------------------------------------- # TAP version 13 # Bail out! Reading PMD pagesize failed # # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0 # [FAIL] not ok 61 split_huge_page_test /tmp/xfs_dir_Ywup9p # exit=3D1 After the fix: # -------------------------------------------------- # running ./split_huge_page_test /tmp/xfs_dir_YHPUPl # -------------------------------------------------- # TAP version 13 # 1..0 # SKIP Transparent Hugepages not available # [SKIP] ok 6 split_huge_page_test /tmp/xfs_dir_YHPUPl # SKIP Acked-by: David Hildenbrand (Arm) Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Lorenzo Stoakes (Oracle) Reviewed-by: Zi Yan CC: Li Wang Signed-off-by: Chunyu Hu --- V3 chagnes: - add acked-by from David - add reviewed by from Mike V2 changes: - removed the {} in if block - removed the write_file helper rename chunk, as there's a new patch 3 to resolve the conflict with thp_settings.h by moving it to vm_util. - Add reviewed by from Zi and Lorenzo --- tools/testing/selftests/mm/split_huge_page_test.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/test= ing/selftests/mm/split_huge_page_test.c index 93f205327b84..500d07c4938b 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -21,6 +21,7 @@ #include #include "vm_util.h" #include "kselftest.h" +#include "thp_settings.h" =20 uint64_t pagesize; unsigned int pageshift; @@ -757,6 +758,9 @@ int main(int argc, char **argv) ksft_finished(); } =20 + if (!thp_is_enabled()) + ksft_exit_skip("Transparent Hugepages not available\n"); + if (argc > 1) optional_xfs_path =3D argv[1]; =20 --=20 2.53.0 From nobody Sun Apr 5 16:28:25 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 352F929A31C for ; Thu, 2 Apr 2026 01:46:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775094419; cv=none; b=ucRJEicPlhlNu/3cw03lmA+KIjy8o1sOhn3K8g5W5r0/c2HLPlnUiAbO4rGrB+cv6YcnPpAYVZpiouOmU5tjhGQddeCx3cNBDQQCoipROE3xvFjdpWweAWwZt3YKjah1iAyY+FlT5zFaEDA1Zu2Mm0jyA4wf01t7hRXkaj0RFis= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775094419; c=relaxed/simple; bh=0ZNjKjARdZvcdL31QoVs+UqP+O/z4+0bO2/UPGbm13o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uUPLBWUTOLgOEAvZ6UiQKOJjjXYj96wXpTp75nIBx6ef904jUx7vW4PnlH63fqxQN8/HtF3/2FF/fns3bMpNzgZcLEbF/9e4G1NBZyAT1ZOGjbcaxEbBpDgi2JOeFs9xTQg554W/nASWOkGBhY7bnJb+uttPmGJibU/ffff06CA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=BttI9Wlv; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BttI9Wlv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775094417; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z5cQUZey16cto7EAHb0l8lICJnDidIXEapbKPGxTzr4=; b=BttI9WlvPjeS75GlRQlf5ConD35MlCZGheInVW0VbrMDkYMBoG0IRD6CaV0uuqNyFUj2WU KposspemBuyN4a5c0ajcMlO6KC3PngciYGYEqrJFj+WGHgfE7HHjICu4Kau02G9NPRHxi2 KAGAPSbOTjfh/936WCsgr4JcmdoW/go= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-304-Ys615eQANGK9p86PrAQtoA-1; Wed, 01 Apr 2026 21:46:52 -0400 X-MC-Unique: Ys615eQANGK9p86PrAQtoA-1 X-Mimecast-MFC-AGG-ID: Ys615eQANGK9p86PrAQtoA_1775094410 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4879E1956055; Thu, 2 Apr 2026 01:46:50 +0000 (UTC) Received: from dell-per7425-02.rhts.eng.pek2.redhat.com (dell-per7425-02.rhts.eng.pek2.redhat.com [10.73.116.18]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DE9F519560AB; Thu, 2 Apr 2026 01:46:41 +0000 (UTC) From: Chunyu Hu To: akpm@linux-foundation.org, david@kernel.org, shuah@kernel.org, linux-mm@kvack.org, ljs@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, chuhu@redhat.com, Li Wang Subject: [PATCH v8 6/6] selftests/mm: transhuge_stress: skip the test when thp not available Date: Thu, 2 Apr 2026 09:45:43 +0800 Message-ID: <20260402014543.1671131-7-chuhu@redhat.com> In-Reply-To: <20260402014543.1671131-1-chuhu@redhat.com> References: <20260402014543.1671131-1-chuhu@redhat.com> 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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" The test requires thp, skip the test when thp is not available to avoid false positive. Tested with thp disabled kernel. Before the fix: # -------------------------------- # running ./transhuge-stress -d 20 # -------------------------------- # TAP version 13 # 1..1 # transhuge-stress: allocate 1453 transhuge pages, using 2907 MiB virtual= memory and 11 MiB of ram # Bail out! MADV_HUGEPAGE# Planned tests !=3D run tests (1 !=3D 0) # # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0 # [FAIL] not ok 60 transhuge-stress -d 20 # exit=3D1 After the fix: # -------------------------------- # running ./transhuge-stress -d 20 # -------------------------------- # TAP version 13 # 1..0 # SKIP Transparent Hugepages not available # [SKIP] ok 5 transhuge-stress -d 20 # SKIP Acked-by: David Hildenbrand (Arm) Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Lorenzo Stoakes (Oracle) Reviewed-by: Zi Yan CC: Li Wang Signed-off-by: Chunyu Hu --- V3 changes: - Add review by from Mike - Add acked-by from David V2 changes: - Move the exit chunk to the front of ksft_print_headers() as suggested by David. - Add reviewed by from Zi and Lorenzo --- tools/testing/selftests/mm/transhuge-stress.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/mm/transhuge-stress.c b/tools/testing/= selftests/mm/transhuge-stress.c index bcad47c09518..7a9f1035099b 100644 --- a/tools/testing/selftests/mm/transhuge-stress.c +++ b/tools/testing/selftests/mm/transhuge-stress.c @@ -17,6 +17,7 @@ #include #include "vm_util.h" #include "kselftest.h" +#include "thp_settings.h" =20 int backing_fd =3D -1; int mmap_flags =3D MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE; @@ -37,6 +38,9 @@ int main(int argc, char **argv) =20 ksft_print_header(); =20 + if (!thp_is_enabled()) + ksft_exit_skip("Transparent Hugepages not available\n"); + ram =3D sysconf(_SC_PHYS_PAGES); if (ram > SIZE_MAX / psize() / 4) ram =3D SIZE_MAX / 4; --=20 2.53.0