From nobody Mon May 4 13:03:30 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 0726635C193; Mon, 4 May 2026 09:11:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777885885; cv=none; b=Nk0GmNbQepMkOfYdOhY+fFKwYLqCPAuXGV3rCoPL7iKILj5S+AVNzS0bvntH+q1q3r3jlDkEwkLO7W+q7amQk4oHkV6wPtXGSFpkr5A4pl4pZ+MMfDUPjapOh7u1U0m//Y+SKVT9TOm6Eu1KsFnW5rz/CBb5fjLJ/O6LE62L2N0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777885885; c=relaxed/simple; bh=6HinYdwc0G5BYqDhm+RGvNLMsG/4tC5p2U7NJfJQ4Xo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ShRzfcO1FMbc02e8kXqJbIKddieufz3KTp/RYy/Xas91UcFQz1kh9b48b9v4nbVdgF3swrVrXWEuDhhjTPORx/PiXQT8b55ZvWrYUuTPKYT8bVWkppVtuPBhg1NBZ0xrZHMuafKGMry2+cRijRBWm4Pzkr7GNp+WGJJ3zRlPKxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=hKX1mZwB; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="hKX1mZwB" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6441cdh23828299; Mon, 4 May 2026 09:11:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=cIQ8K2HJtwQlSMozF shA6AnsK+LYu4W5byOwdQkFz7o=; b=hKX1mZwBKEg5A0ExFkDzhwzoSVYdN2UFU 664ZtZlz773uh2jNpNdNgXtvVZBQAuj2Ge7o26FLuSTqM302v7fVhRADNyoq3UyR tA2StNtcEo+XM8uEtbZA+smrZ2yAf6U8Bnt13mUdSRG9IM+wve9/WnwD3pM4gndi N/0/FvUMUlJVmeeNlM909U2xh3pRrFbVws72Sn8h5qjRVLMAWe/8XvKnEZxYcyDk 1d5pgPvGbvAtEWXcXGT0lHyRWtz2Dhl4ykhbesjUYzQ2Do3lrdXivSASYq2h5kNs /oJfzN3c7+kRC6DJnEFL7jNlKf9Vd2RV9PGrhW8BYhuQGd2Pg/dhA== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4dw9xxe20b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 May 2026 09:11:17 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 64499Sxc005944; Mon, 4 May 2026 09:11:17 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4dww3gvcqc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 May 2026 09:11:17 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6449BDPE47841598 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 4 May 2026 09:11:13 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3B9EA2004D; Mon, 4 May 2026 09:11:13 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AE09420040; Mon, 4 May 2026 09:11:11 +0000 (GMT) Received: from aboo.bl1-in.ibm.com (unknown [9.123.14.187]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 4 May 2026 09:11:11 +0000 (GMT) From: Aboorva Devarajan To: Andrew Morton , Shuah Khan , linux-mm@kvack.org, linux-kselftest@vger.kernel.org Cc: Sayali Patil , linux-kernel@vger.kernel.org, Aboorva Devarajan Subject: [PATCH 1/3] selftests/mm: allow PUD-level entries in compound testcase of hmm tests Date: Mon, 4 May 2026 14:41:06 +0530 Message-ID: X-Mailer: git-send-email 2.54.0 In-Reply-To: References: 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-TM-AS-GCONF: 00 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA0MDA5NyBTYWx0ZWRfX2OTKEwUdMLi/ ntGJYwlcp8C1ZyrhHAxE5H89GTwk7NKGtr0nohDG9mGLpvMJgjB2xJaerwrO5DwPT4MHmR2pf5K Sg9MkFfuoVvEXQdnc9rklJ7mE0GBO+bMcvKIOB54VIaEbcUOKo3FujSQpdBrGuEIaBdPJufFqwV Z/CiWs8s5X7/brmNoeT++Ytc2yn1xvBhKLjK+g4vFutzDlutNL9rMi5txFegCKxUpHkFkWGrxmk ZvM5L4Hf5K3WCs/pojwhhYCJohaDIpJq9+DA97XZTl0wmdwNxBfRplaHXJdYWEYAcl1SyoMa9Us CzsAbyRl5E2IS6iyY4FkKIVn9dJoI4TKiJ3//GSA+oM92wnyCrxjrdx8fA+Ebvem5rzH2kordjg jcN7Mn96Z8qBIFNPthXeIphXMfy61DVfwEX4+5ZI2I8dYLa2NCFQ3mdWt9vArWMbOmCxrDnLq9A th+c+SBH98yol+CAKkQ== X-Proofpoint-ORIG-GUID: wcx_EMfXyr1ZDFrb0a5UjKobkgA1YPmS X-Proofpoint-GUID: wcx_EMfXyr1ZDFrb0a5UjKobkgA1YPmS X-Authority-Analysis: v=2.4 cv=ctWrVV4i c=1 sm=1 tr=0 ts=69f862b5 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=QxgUL920Qp7ezWAymYEA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-04_03,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1011 suspectscore=0 impostorscore=0 spamscore=0 malwarescore=0 phishscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605040097 Content-Type: text/plain; charset="utf-8" From: Sayali Patil The HMM compound testcase currently assume only PMD-level mappings and fail on systems when default_hugepagesz=3D1G is set. Extend the checks to accept PUD-level protections as well, avoiding false failures. Fixes: e478425bec93 ("mm/hmm: add tests for hmm_pfn_to_map_order()") Signed-off-by: Sayali Patil Signed-off-by: Aboorva Devarajan --- tools/testing/selftests/mm/hmm-tests.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftes= ts/mm/hmm-tests.c index 77fb4c5d871b..6dc839866dfe 100644 --- a/tools/testing/selftests/mm/hmm-tests.c +++ b/tools/testing/selftests/mm/hmm-tests.c @@ -1599,8 +1599,8 @@ TEST_F(hmm2, snapshot) } =20 /* - * Test the hmm_range_fault() HMM_PFN_PMD flag for large pages that - * should be mapped by a large page table entry. + * Test the hmm_range_fault() handling of large pages (PMD or PUD) + * that should be mapped by a large page table entry. */ TEST_F(hmm, compound) { @@ -1649,8 +1649,8 @@ TEST_F(hmm, compound) /* Check what the device saw. */ m =3D buffer->mirror; for (i =3D 0; i < npages; ++i) - ASSERT_EQ(m[i], HMM_DMIRROR_PROT_WRITE | - HMM_DMIRROR_PROT_PMD); + ASSERT_TRUE((m[i] =3D=3D (HMM_DMIRROR_PROT_WRITE | HMM_DMIRROR_PROT_PMD)= ) || + (m[i] =3D=3D (HMM_DMIRROR_PROT_WRITE | HMM_DMIRROR_PROT_PUD))); =20 /* Make the region read-only. */ ret =3D mprotect(buffer->ptr, size, PROT_READ); @@ -1664,8 +1664,8 @@ TEST_F(hmm, compound) /* Check what the device saw. */ m =3D buffer->mirror; for (i =3D 0; i < npages; ++i) - ASSERT_EQ(m[i], HMM_DMIRROR_PROT_READ | - HMM_DMIRROR_PROT_PMD); + ASSERT_TRUE((m[i] =3D=3D (HMM_DMIRROR_PROT_READ | HMM_DMIRROR_PROT_PMD))= || + (m[i] =3D=3D (HMM_DMIRROR_PROT_READ | HMM_DMIRROR_PROT_PUD))); =20 munmap(buffer->ptr, buffer->size); buffer->ptr =3D NULL; --=20 2.54.0 From nobody Mon May 4 13:03:30 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 2830535BDA8; Mon, 4 May 2026 09:11:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777885887; cv=none; b=EEYGprAVLjZu0vBp6WpkpyVIduzB7pXqqg2E7Blr6RQwJX4G9VWSC5ZopKcckm+IGQSAoxOHGAIgYUOvDE0DaADe9IkPpiociBsgEEggmBKgTu20afVjMcsasWvFEp46/1MmcIkBVUtz/Bz7cuoHlRVYCPKyTAhiOyw8wJWRwZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777885887; c=relaxed/simple; bh=U2/DR/N8lofsI3rqWwK1p53WUAkIjUvkT+oJNDGgIYM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S6X3emKlPHjlAPj08FWuDCED77sz+lBbZDqYY0MBnVPDTp5R1365DdWugcTjVAyBlceUKeK05jDQzGtOFMsnBxKqNWFbKdDGGrIuiEM4dMs/h8grnEAEDgOY3+5isLNQoHKfaKkvbcvi865MQW8tyqmAE+BLw5kWWDZrNVea5C0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=rzpG1e2C; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="rzpG1e2C" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 643Kl0V93279333; Mon, 4 May 2026 09:11:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=uVBCdFlyMQ1V6MUtu wPKBgnAngZgz58IaT05OqVtHI4=; b=rzpG1e2CGiWiPal63UGg0n8vqK4Rrvbez p1VZZjElDPxpLRmCMZ4ljOdxq17CadnirTR9PrUNrQAbAhy6HATmYmAJBdJoMM8h sgrYtqsiUhA17b9MUMMY3sBcWBB8SVO1oegzOfICfIr7gFxm+C/Xku16streG6Kv zzuC+ITlqm+iqUU07tBtyHudRM3S0fiAF2SGeOC1czpyAolaXiEnmzdZFHCNchCw K5KoCZaW0dEm5IKEJ+h26gb0fX2NTtkBWuszFtDFypCm55y/sQ0e/ySsK0gILmgU +lIiQSgOCFRTqutmHJFJI7xfsBsJFxZq+4Ddhmoxr0w1wAzPGCkDw== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4dw9xxe20k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 May 2026 09:11:19 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 64499Zbc004421; Mon, 4 May 2026 09:11:19 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4dwuyvvjq0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 May 2026 09:11:19 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6449BFO356689010 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 4 May 2026 09:11:15 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5640520040; Mon, 4 May 2026 09:11:15 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 94D282004B; Mon, 4 May 2026 09:11:13 +0000 (GMT) Received: from aboo.bl1-in.ibm.com (unknown [9.123.14.187]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 4 May 2026 09:11:13 +0000 (GMT) From: Aboorva Devarajan To: Andrew Morton , Shuah Khan , linux-mm@kvack.org, linux-kselftest@vger.kernel.org Cc: Sayali Patil , linux-kernel@vger.kernel.org, Aboorva Devarajan Subject: [PATCH 2/3] selftests/mm: remove hardcoded THP sizing assumptions in hmm tests Date: Mon, 4 May 2026 14:41:07 +0530 Message-ID: X-Mailer: git-send-email 2.54.0 In-Reply-To: References: 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-TM-AS-GCONF: 00 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA0MDA5NyBTYWx0ZWRfX4Ce7Mg2HBbJT j8Qe/FwUv4MOtlWOCR0HA7k8E5wj+eOWk7o7cQI3bhgrFIb31MXB8+wutCnDTsir/vlVNcnYrsy T2pSqSgVb/VGmoR3q5UDmC74bTAttQc48XnYww+9fuzsPQzsx7gj2dQioRb5+bR71qUu+0nmpDw 0yZ/2aLQQeUM71caCKU1/DN7cJ/c0ZZBQhnYYxBwHuDoeM5gruKe/F99/VBgTBYkXZepFkRIU7M 1/b98dwWT6BSuFPs3FztFzN1J1BrSduSJjA+K8lb9cRSRh5p2JecYtMxv1BcEoupb8/91+WvWsO rk4XaXe0NgvQfQAXN3FHFMlP6+ZqhaTq7axbXcJojSp+r7DT8s83/C9Si0tlum/fefAJu1MxaHj gwsjv0JDFBI4klfkFFdlYL+CRMcNr9scBPgzEsnCum8X9/l55LH+D2xCAz8pwVDay9dGezUgpsY Pxt68d8880F3uolZAAw== X-Proofpoint-ORIG-GUID: tbQtdIaClcfvD8ppY-xugGVIW4tjpR7a X-Proofpoint-GUID: tbQtdIaClcfvD8ppY-xugGVIW4tjpR7a X-Authority-Analysis: v=2.4 cv=ctWrVV4i c=1 sm=1 tr=0 ts=69f862b7 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=77g_uzDykyn2lBTOjWkA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-04_03,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1015 suspectscore=0 impostorscore=0 spamscore=0 malwarescore=0 phishscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605040097 Content-Type: text/plain; charset="utf-8" From: Sayali Patil migrate_partial_unmap_fault() and migrate_remap_fault() currently use hardcoded offsets based on a 2MB PMD size. Likewise, benchmark_thp_migration() assumes a fixed 2MB THP size when generating test buffer sizes. Derive offsets and test sizes from the runtime PMD page size returned by read_pmd_pagesize(). This allows the tests to adapt correctly on systems where PMD-sized THP differs from 2MB. Also replace the fixed 1MB unmap size with a PMD-relative value derived from the runtime PMD size. Additionally, cap the maximum number of THPs used in benchmark tests to avoid integer overflow when computing large buffer sizes. On systems with larger PMD sizes, multiplying a fixed THP count can exceed INT_MAX. Compute the maximum number of THPs at runtime as (INT_MAX / thp_size) and use the smaller of that value and 128 when constructing the largest benchmark buffer. Fixes: 24c2c5b8ffbd ("selftests/mm/hmm-tests: partial unmap, mremap and ano= n_write tests") Fixes: 271a7b2e3c13 ("selftests/mm/hmm-tests: new throughput tests includin= g THP") Signed-off-by: Sayali Patil Signed-off-by: Aboorva Devarajan --- tools/testing/selftests/mm/hmm-tests.c | 44 +++++++++++++++----------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftes= ts/mm/hmm-tests.c index 6dc839866dfe..1e5c1432ef6b 100644 --- a/tools/testing/selftests/mm/hmm-tests.c +++ b/tools/testing/selftests/mm/hmm-tests.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -2332,12 +2333,13 @@ TEST_F(hmm, migrate_partial_unmap_fault) struct hmm_buffer *buffer; unsigned long npages; unsigned long size =3D read_pmd_pagesize(); + unsigned long unmap_size =3D size / 2; + unsigned long offsets[] =3D { 0, size / 4, size / 2 }; unsigned long i; void *old_ptr; void *map; int *ptr; int ret, j, use_thp; - int offsets[] =3D { 0, 512 * ONEKB, ONEMEG }; =20 for (use_thp =3D 0; use_thp < 2; ++use_thp) { for (j =3D 0; j < ARRAY_SIZE(offsets); ++j) { @@ -2379,12 +2381,12 @@ TEST_F(hmm, migrate_partial_unmap_fault) for (i =3D 0, ptr =3D buffer->mirror; i < size / sizeof(*ptr); ++i) ASSERT_EQ(ptr[i], i); =20 - munmap(buffer->ptr + offsets[j], ONEMEG); + munmap(buffer->ptr + offsets[j], unmap_size); =20 /* Fault pages back to system memory and check them. */ for (i =3D 0, ptr =3D buffer->ptr; i < size / sizeof(*ptr); ++i) if (i * sizeof(int) < offsets[j] || - i * sizeof(int) >=3D offsets[j] + ONEMEG) + i * sizeof(int) >=3D offsets[j] + unmap_size) ASSERT_EQ(ptr[i], i); =20 buffer->ptr =3D old_ptr; @@ -2398,12 +2400,12 @@ TEST_F(hmm, migrate_remap_fault) struct hmm_buffer *buffer; unsigned long npages; unsigned long size =3D read_pmd_pagesize(); + unsigned long offsets[] =3D { 0, size / 4, size / 2 }; unsigned long i; void *old_ptr, *new_ptr =3D NULL; void *map; int *ptr; int ret, j, use_thp, dont_unmap, before; - int offsets[] =3D { 0, 512 * ONEKB, ONEMEG }; =20 for (before =3D 0; before < 2; ++before) { for (dont_unmap =3D 0; dont_unmap < 2; ++dont_unmap) { @@ -2806,8 +2808,12 @@ static inline int run_migration_benchmark(int fd, in= t use_thp, size_t buffer_siz TEST_F_TIMEOUT(hmm, benchmark_thp_migration, 120) { struct benchmark_results thp_results, regular_results; - size_t thp_size =3D 2 * 1024 * 1024; /* 2MB - typical THP size */ + size_t thp_size =3D read_pmd_pagesize(); int iterations =3D 5; + size_t max_thps, num_thps; + + max_thps =3D INT_MAX / thp_size; + num_thps =3D (max_thps > 128) ? 128 : max_thps; =20 printf("\nHMM THP Migration Benchmark\n"); printf("---------------------------\n"); @@ -2815,23 +2821,23 @@ TEST_F_TIMEOUT(hmm, benchmark_thp_migration, 120) =20 /* Test different buffer sizes */ size_t test_sizes[] =3D { - thp_size / 4, /* 512KB - smaller than THP */ - thp_size / 2, /* 1MB - half THP */ - thp_size, /* 2MB - single THP */ - thp_size * 2, /* 4MB - two THPs */ - thp_size * 4, /* 8MB - four THPs */ - thp_size * 8, /* 16MB - eight THPs */ - thp_size * 128, /* 256MB - one twenty eight THPs */ + thp_size / 4, /* quarter THP */ + thp_size / 2, /* half THP */ + thp_size, /* single THP */ + thp_size * 2, /* two THPs */ + thp_size * 4, /* four THPs */ + thp_size * 8, /* eight THPs */ + thp_size * num_thps, /* max THPs without overflow */ }; =20 static const char *const test_names[] =3D { - "Small Buffer (512KB)", - "Half THP Size (1MB)", - "Single THP Size (2MB)", - "Two THP Size (4MB)", - "Four THP Size (8MB)", - "Eight THP Size (16MB)", - "One twenty eight THP Size (256MB)" + "Small Buffer", + "Half THP Size", + "Single THP Size", + "Two THP Size", + "Four THP Size", + "Eight THP Size", + "Large Buffer" }; =20 int num_tests =3D ARRAY_SIZE(test_sizes); --=20 2.54.0 From nobody Mon May 4 13:03:30 2026 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 1B7D835C197; Mon, 4 May 2026 09:11:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777885890; cv=none; b=fqaQiChCmRJXQ62AAE2NP1dLw7u/bbjVtn4Wcw5c4wAmy1B0ROsmqo45/tCjNSFtwx8UvFVS0i6wEC7iZPrSo4UJbhgXub40I980wolSZIpuD3EswfdEU66pwS5OZdye+WPWt5jP8pSC2OMSv/Z/WCjNdq9eWqF1m4guwkwzQus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777885890; c=relaxed/simple; bh=AN5eHcgUWNQZFf4Ztt6bsPYWP2Q+ZWyk5n/OS9iI2sc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k7xySkfTfWgVcxWdeY8DOQSccx66kM5qhy56ore59Hmyz8OQ4Eylyjyvu9rxU0zn5WS1nMQEeeoou+r2ce3KDKlNQaxg/TL37otmEQMYG6Sk+khv9t+F9UtTLd90SKLR6DrzQm+0b3FU2efCyLLaSJuOM4LRqHokZwuErMRDnFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=M7Guab/h; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="M7Guab/h" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6442tF7G068020; Mon, 4 May 2026 09:11:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=jm2w8eq1FHMdDz3aG 4TKoSi7OYPVag1/QptiIakzkcQ=; b=M7Guab/hF7A18bW90wQmaYLM2oR1SFL80 arCpJhW27YtIXqUzxgWAD1g040yZWIpkg5x9HoeluqxcQWPlH1ISxmid6cHc16cb lnHgeGQA80Hih+uslLry7N9XR4TWTDtbekEbAhfcNm+cr3MTWEveDPzWID8Z/G5F rYWxEKKgyc3Gd5OqN4i7K4NnEoVDw1VjNfptrtKU5FrtvNpqcDp4QjEkmd9VYQ7C h6QKLjrvr/E0gtMuoZcMRFl/FL3p1brmdZ9WMDfUo10VcVoU/on/qJAnbNct/GRL jEMZFl6lBAiHyYSAYqCqQKg5x5m6pUseBjHZ8UH5T08CP8Hm0JwOA== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4dw9y168ru-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 May 2026 09:11:21 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 64499V0E025969; Mon, 4 May 2026 09:11:20 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4dwx9y472j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 May 2026 09:11:20 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6449BHLM30605840 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 4 May 2026 09:11:17 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 326012004B; Mon, 4 May 2026 09:11:17 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A058720040; Mon, 4 May 2026 09:11:15 +0000 (GMT) Received: from aboo.bl1-in.ibm.com (unknown [9.123.14.187]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 4 May 2026 09:11:15 +0000 (GMT) From: Aboorva Devarajan To: Andrew Morton , Shuah Khan , linux-mm@kvack.org, linux-kselftest@vger.kernel.org Cc: Sayali Patil , linux-kernel@vger.kernel.org, Aboorva Devarajan Subject: [PATCH 3/3] selftests/mm: fix exclusive_cow test fork() handling Date: Mon, 4 May 2026 14:41:08 +0530 Message-ID: X-Mailer: git-send-email 2.54.0 In-Reply-To: References: 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-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: CLrEPZepVvPWW--8jC581KAg740SAxfb X-Proofpoint-GUID: CLrEPZepVvPWW--8jC581KAg740SAxfb X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA0MDA5NyBTYWx0ZWRfX7828XjCc7lDp W8qiv4I7CvqzBOmj/pcjx0dkovueJ/A9+xgYOCoCwlsC+YoB4oKjwjrKNNrHTiYcJEm0BUUsjlh pkIaOOhPEy+t/n8kABgOC3+DftyLjCiwpNUC11c1fJ5CucRN7wUj4X+m4c4CEHlgFbl0hPMEIWg dTWx1GZ30G1ZUS+IqWR/96+6imawGwcF32NujWVlWOMht7C/eq5jdJydaOGRsMsef9qreffaGya /2fKwqcZZiwQzoE4jJCIKRTPWfHRRCHJQF9Puwx/AbL4GtjP0HvwFHMUKZwgkkFPDxjntAHvn87 WewUU7C1VN+0NGzl2bZOx4Xia3xIqpho7ptYiZGT5KAOB4yM0w80K+qIQOKhlFsawAxE335+JiW XCbTn0h8TOFffsQyM1ACwTuD3qwKLJwakCwuyqS1m+X3zh10v77+aRmHkn4UVIOADN7yIi+OGB9 Q+sHi9QHCXs5amEwBXQ== X-Authority-Analysis: v=2.4 cv=UbFhjqSN c=1 sm=1 tr=0 ts=69f862b9 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=YKbGnN07TdQTFoDUIKcA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-04_03,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 spamscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 adultscore=0 priorityscore=1501 bulkscore=0 phishscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605040097 Content-Type: text/plain; charset="utf-8" The test ignores the return value of fork(), so both the parent and the (newly created) child run the COW verification loops and then call hmm_buffer_free() before returning into the kselftest harness, which _exit()s each side. This duplicated teardown sequence has been observed to manifest as a SIGSEGV in the test child, e.g.: hmm-tests[360141]: segfault (11) at 0 nip 10006964 lr 1000ac3c code 1 in hmm-tests[6964,10000000+30000] Fix this by adopting the same fork()-then-wait pattern already used by the nearby anon_write_child / anon_write_child_shared tests in this file: the child performs the COW verification and then _exit(0)s so it does not run the test teardown, while the parent independently verifies COW, waits for the child, and only then frees the buffer. Fixes: b659baea75469 ("mm: selftests for exclusive device memory") Signed-off-by: Aboorva Devarajan --- tools/testing/selftests/mm/hmm-tests.c | 30 +++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftes= ts/mm/hmm-tests.c index 1e5c1432ef6b..c5000d53b604 100644 --- a/tools/testing/selftests/mm/hmm-tests.c +++ b/tools/testing/selftests/mm/hmm-tests.c @@ -1866,6 +1866,8 @@ TEST_F(hmm, exclusive_cow) unsigned long i; int *ptr; int ret; + pid_t pid; + int status; =20 npages =3D ALIGN(HMM_BUFFER_SIZE, self->page_size) >> self->page_shift; ASSERT_NE(npages, 0); @@ -1894,14 +1896,36 @@ TEST_F(hmm, exclusive_cow) ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); =20 - fork(); + pid =3D fork(); + if (pid =3D=3D -1) + ASSERT_EQ(pid, 0); =20 - /* Fault pages back to system memory and check them. */ + if (pid =3D=3D 0) { + /* + * Child: fault pages back and verify COW, then _exit(). + * On ASSERT failure the harness calls abort(); the parent + * reports it via the WIFEXITED/WEXITSTATUS checks below. + */ + for (i =3D 0, ptr =3D buffer->ptr; i < size / sizeof(*ptr); ++i) + ASSERT_EQ(ptr[i]++, i); + + for (i =3D 0, ptr =3D buffer->ptr; i < size / sizeof(*ptr); ++i) + ASSERT_EQ(ptr[i], i + 1); + + _exit(0); + } + + /* Parent: also increment to verify COW works for both processes. */ for (i =3D 0, ptr =3D buffer->ptr; i < size / sizeof(*ptr); ++i) ASSERT_EQ(ptr[i]++, i); =20 for (i =3D 0, ptr =3D buffer->ptr; i < size / sizeof(*ptr); ++i) - ASSERT_EQ(ptr[i], i+1); + ASSERT_EQ(ptr[i], i + 1); + + /* Parent: wait for child and then free the buffer. */ + ASSERT_EQ(waitpid(pid, &status, 0), pid); + ASSERT_TRUE(WIFEXITED(status)); + ASSERT_EQ(WEXITSTATUS(status), 0); =20 hmm_buffer_free(buffer); } --=20 2.54.0