From nobody Fri Jun 12 01:47:14 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 8849E2DA75B; Thu, 11 Jun 2026 03:41:40 +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=1781149301; cv=none; b=EqvPnFaNvhHO9iIU56H3R9iAde7U/oXL4Yo5t5yELHgo/gDZK4kuRN6IRZJ5YBCY9KzSpCbRVrH9kSSzGFzhQrPuHiuEdrW6LEDYSw/kfo5Hkv53a1Ev0FiEKKHw9thLe2PdoCTULIZyox74yWBBb4fL481AipAWjfRJOfx8Wuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781149301; c=relaxed/simple; bh=S4hIrOQ515NeYorUKQiiOkP+zguTG2NH7VSWRYnTPIE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WlMcjHlUGsolsl1zs7dfMsycwG9RokDpUaBpuI0rje/AXhxKkfj2YN511QxSevO5Dy8qPmx7oprlpGclpQ4pI0aLcVd92YORTZhJJslw8V84a+44eovvxL+TODee7PRr54L6KVEq/ywF0mZTr179nUj2ZWtWD8Il5EBX2InkS/4= 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=G8R/N8fq; 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="G8R/N8fq" Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 65AJu5lp4146614; Thu, 11 Jun 2026 03:41:24 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=2MXeK/N/OwRrmCK72 J9wvshsJl5VGxnckcTpkBJEuXs=; b=G8R/N8fqkMWE66u9GJT7uFIbSDRyPat82 slJ09zFfXBBNtWYHBmWuVm+/WmFa8vRaf4luxexPyXr6Ed5Kere+Fh43hsvEnHii J34JFLsskfq06czObBRyvQlYq2qlK9PkaKcujtesaggIJ9nCyJW66laFX8FRRFq1 HykRgOg4qM9a5/qlWlAYp7KkOAiP/bTBd3kQOsrkiHaryGr50FhrM5ukavrLbnkW dxo7RvFTxghGJFszCUg1mpGIlylSbLC7Aw7tof0UJR45hsrU5sE01oE+PifTpaez yoXNMT2BbYlnvrh9fMq1Tl83/i+R4/MV6ATZRhWr/8r5PQBLOk4nA== 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 4eqe8c18x4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Jun 2026 03:41:23 +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 65B3YlWW027309; Thu, 11 Jun 2026 03:41:22 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4eqe0a1f6m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Jun 2026 03:41:22 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 65B3fISd49807692 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Jun 2026 03:41:18 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4BE9A20043; Thu, 11 Jun 2026 03:41:18 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1814620040; Thu, 11 Jun 2026 03:41:12 +0000 (GMT) Received: from aboo.ibm.com.com (unknown [9.39.27.36]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 11 Jun 2026 03:41:11 +0000 (GMT) From: Aboorva Devarajan To: Andrew Morton , linux-mm@kvack.org Cc: Jason Gunthorpe , Leon Romanovsky , David Hildenbrand , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Shuah Khan , Ralph Campbell , Matthew Brost , Balbir Singh , Alistair Popple , Alex Sierra , Matthew Wilcox , Sayali Patil , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Aboorva Devarajan Subject: [PATCH v3 1/3] selftests/mm: allow PUD-level entries in compound testcase of hmm tests Date: Thu, 11 Jun 2026 09:11:00 +0530 Message-ID: <20260611034102.1030738-2-aboorvad@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260611034102.1030738-1-aboorvad@linux.ibm.com> References: <20260611034102.1030738-1-aboorvad@linux.ibm.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-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYwNjExMDAzMiBTYWx0ZWRfXxvrgIIXBIsXr GR40/jSJwYatx1+BKDG9g9ETTz3msalSpQhdaP6DfDoyKH9FVv0mR+mlLcUZxRCzIhhDgkFtPGj BRPKrq6WpJXQ8DAOLwWhili0atAng7Q= X-Authority-Analysis: v=2.4 cv=AYCB2XXG c=1 sm=1 tr=0 ts=6a2a2e64 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=FelO9ux0wxsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VnNF1IyMAAAA:8 a=HVGCuyRmRnZzIc_11p0A:9 X-Proofpoint-GUID: J5UEU4C4qU65iafWaAk5H4F8HPmtDoGR X-Proofpoint-ORIG-GUID: Eh7ueyuKhYUPUC1uy7GRqEaxyGCuesve X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjExMDAzMiBTYWx0ZWRfX5pcD7aFI/Kon 4zR8zaRyIjKrWNE0MJk0QtNwmT555dISFh33lo0E4EiFV6sONYMYzvO5G9e04ciGoFU98cyXN7B dXEV0wB1F/J+AV2D72jRz5nnMrGQehc8u+jtMhXCMnpXekqI37/5WPxbnoGmProjNVj35fyYjRW AeO9Kh52suWxfEv4KURFVEJ+9inSLSMwQfmIHA7kUS28fp2DPpi2/pWeszCUB4s+893NYha9se4 5jHQI5ysjtTYcrHksoBa9PGooTkxAe4yjqKUFm5BNYmElfDJZErLNwiLy9trFsq0YvI/cgbicpQ iZM+nq5kOrF6KhebPwq/ok64MdCpus+6+rQR/mNybpi4qMF9X8AJv32Ietn67Fs8NX8q2+mOeca g8CFjW2rfpnpm/8LKEePZUqIjNH47F8Kg9FOx5OEx1NqGQUowQuNADopzLWvA0iWfRc8bRPf0ms gN2fQN3zt8vuAdd4WxQ== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-11_01,2026-06-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 malwarescore=0 spamscore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 adultscore=0 priorityscore=1501 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606040000 definitions=main-2606110032 Content-Type: text/plain; charset="utf-8" From: Sayali Patil The HMM compound testcase currently assumes only PMD-level mappings and fails on systems where default_hugepagesz=3D1G is set, because the region is then reported by the device at PUD level. Determine the mapping level (PMD or PUD) the device reports for the first page of the range and require every page to match that level exactly via ASSERT_EQ(). This accepts PUD-level mappings while preserving the expected/observed protection values printed on failure, and rejects a fragmented mapping that mixes PMD- and PUD-level entries within the same range (which a per-page OR check would have let pass). Fixes: e478425bec93 ("mm/hmm: add tests for hmm_pfn_to_map_order()") Signed-off-by: Sayali Patil Co-developed-by: Aboorva Devarajan Signed-off-by: Aboorva Devarajan --- tools/testing/selftests/mm/hmm-tests.c | 32 +++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftes= ts/mm/hmm-tests.c index 46e0c8c921c3..deb6a7485650 100644 --- a/tools/testing/selftests/mm/hmm-tests.c +++ b/tools/testing/selftests/mm/hmm-tests.c @@ -1602,8 +1602,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) { @@ -1613,6 +1613,7 @@ TEST_F(hmm, compound) unsigned long default_hsize =3D default_huge_page_size(); int *ptr; unsigned char *m; + unsigned char prot; int ret; unsigned long i; =20 @@ -1648,11 +1649,20 @@ TEST_F(hmm, compound) ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); =20 - /* Check what the device saw. */ + /* + * Check what the device saw. The region is backed by a single huge + * page that the device reports either at PMD or at PUD level depending + * on the configured default hugepage size. Determine that level from + * the first page and require every page in the range to match it + * exactly, so that a fragmented mapping mixing levels (or a missing + * large-page bit) is still caught and reported with its actual value. + */ m =3D buffer->mirror; + prot =3D HMM_DMIRROR_PROT_WRITE | + ((m[0] & HMM_DMIRROR_PROT_PUD) ? HMM_DMIRROR_PROT_PUD : + HMM_DMIRROR_PROT_PMD); for (i =3D 0; i < npages; ++i) - ASSERT_EQ(m[i], HMM_DMIRROR_PROT_WRITE | - HMM_DMIRROR_PROT_PMD); + ASSERT_EQ(m[i], prot); =20 /* Make the region read-only. */ ret =3D mprotect(buffer->ptr, size, PROT_READ); @@ -1663,11 +1673,17 @@ TEST_F(hmm, compound) ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); =20 - /* Check what the device saw. */ + /* + * Check what the device saw after mprotect(PROT_READ). Same + * approach as above: determine the mapping level from the first + * page and require every page to match it exactly. + */ m =3D buffer->mirror; + prot =3D HMM_DMIRROR_PROT_READ | + ((m[0] & HMM_DMIRROR_PROT_PUD) ? HMM_DMIRROR_PROT_PUD : + HMM_DMIRROR_PROT_PMD); for (i =3D 0; i < npages; ++i) - ASSERT_EQ(m[i], HMM_DMIRROR_PROT_READ | - HMM_DMIRROR_PROT_PMD); + ASSERT_EQ(m[i], prot); =20 munmap(buffer->ptr, buffer->size); buffer->ptr =3D NULL; base-commit: 801c5efa788952095586d076fed1ea4902facff8 --=20 2.54.0 From nobody Fri Jun 12 01:47:14 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 5A8582DA75B; Thu, 11 Jun 2026 03:41:45 +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=1781149306; cv=none; b=iMjDr3XQK6/eBW+CBhgNoVEy4lhY4aJZWw79YfSuHRqZo11lNR+8zg9uJoYe9hOCM+cRwshZj1Ma2sp7rJkv2HygbW9ee2/NL4TlaLAQpPJdUJTnaAYnKRHGCaijMhy1ESi0AxQP6b/HsACRT2ic1v85dam4GHsA4mVenN6gYDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781149306; c=relaxed/simple; bh=+jXnO+QIxicMmxuN4/BXsBurEN7B74qgN0aTNV4duVs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eJ9m0MpjJ3v2eupY6/rpdDJ8y3fJLzQaLXpu/7R05wIhaqDH+bP1XIVcGhZMhzkw0HWMA21norBiCQns0RhYqhci8yUhHJQ1p64YS+n0MG+N8b8LIvwjkdXQsuUNF2J6cABiR8XMM5Q/dcn0pwABhZHGO1JfW8RHUDUDcxuFz4M= 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=orBchVp8; 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="orBchVp8" 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 65AJu3Ac3872831; Thu, 11 Jun 2026 03:41:31 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=pOTyR7ZmVR/FuBL3T f+HX+H8rb4MurVSt964bZC76lI=; b=orBchVp8yBJTDJhpQStlF4qbyicApknR+ mv8Va9eJfYc2HyXAMKzEfRAGEj/mtEvWcWXuPQ06Ldln1fW+92yDK0IHell76bix sbL4Av2jvjAbpTuiVreAcp+UkSGfXmejloku4I7tTgBvRaBKm2rpCgtsAK6LA9dx 2/siVsAM11MmMFGApFkt1NJnmc/FTVTCcDW2MWVHspJzxJhSr2J/39j6JDCqxVRk 4w9BVUabTuTY/Cfrz0zv734MoTZDzFEA0xt9wNzsqe0MY33lympkoFs0VDpNaINK yirfMOZ7Hg3UaFnFbK2idGneaDlFkU1ftP/k0lXtME8X8uTt6NOgw== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4eqe8es907-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Jun 2026 03:41:30 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 65B3YdV2004525; Thu, 11 Jun 2026 03:41:28 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4eqe08heyf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Jun 2026 03:41:28 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 65B3fPBn42140082 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Jun 2026 03:41:25 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0885C20043; Thu, 11 Jun 2026 03:41:25 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BC49D20040; Thu, 11 Jun 2026 03:41:18 +0000 (GMT) Received: from aboo.ibm.com.com (unknown [9.39.27.36]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 11 Jun 2026 03:41:18 +0000 (GMT) From: Aboorva Devarajan To: Andrew Morton , linux-mm@kvack.org Cc: Jason Gunthorpe , Leon Romanovsky , David Hildenbrand , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Shuah Khan , Ralph Campbell , Matthew Brost , Balbir Singh , Alistair Popple , Alex Sierra , Matthew Wilcox , Sayali Patil , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Aboorva Devarajan Subject: [PATCH v3 2/3] selftests/mm: remove hardcoded THP sizing assumptions in hmm tests Date: Thu, 11 Jun 2026 09:11:01 +0530 Message-ID: <20260611034102.1030738-3-aboorvad@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260611034102.1030738-1-aboorvad@linux.ibm.com> References: <20260611034102.1030738-1-aboorvad@linux.ibm.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-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjExMDAzMiBTYWx0ZWRfX6yHiMJKbyPOU DP2cSBd4Z+gjH9lZQtbENJP4ePpBNPlVBVEloZ6BZhIpztSWPSa6dGS+xwvW6SWDcz12AGFpwWh LUQ6JTvQWePJqBmPqd7x7DOB9lONx4nSYiY+XxPtc+eCyy4H0z1Ine42faiFT/6A4pStDrGX7Rf MG+IBey4haq1zE+fKO7/AJxU2c68GCqHB33HXv+S4Q5jn3fbWzD/3lIL80aJaBQRsT3R7D7pVW+ lSacAvqevHDLzycXy14+9muowWgA8LgmoM/6Z1NFtZ7Yy4P7Qn1hAzeQE8qiVcDphakrrkt6IuR DkTnb6QZajd7p/5BUiaHPlWQm8fVvpio88TCci6iGoGEt3PVF3yTISUiXVc1MyXSrDbVlniY8bc aQj7qnwtOe6BV1FAL3LHxos5SeVKZnVXVZGS+cBL72pfQrnz8pDlxoZF8amhunz7bxmL0ourLtu dMOXhIBvmnr8t6NxNZA== X-Authority-Analysis: v=2.4 cv=dr7rzVg4 c=1 sm=1 tr=0 ts=6a2a2e6a cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=FelO9ux0wxsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=ca_0sX59trYgcfZ9MnEA:9 X-Proofpoint-ORIG-GUID: HedVgQD8qa-QM20khZr5_Hhx5jo3NWR9 X-Proofpoint-GUID: 9hgyd95hIR9gSVDhCECFrWb4OWeWwHnG X-Proofpoint-Spam-Info: AW1haW4tMjYwNjExMDAzMiBTYWx0ZWRfX/vIGuWd1T0Zc tOMrf3JjqPInXgemjpC7jfJxxtgPp1Zr0AVZVa6tOJxjATDzvhwNSO8zOWUCfjcoYfT2hOwcGo1 GoIeQN9t/X4w9G9EcAx92ndkvKZEZIU= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-11_01,2026-06-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 adultscore=0 suspectscore=0 priorityscore=1501 phishscore=0 clxscore=1015 bulkscore=0 impostorscore=0 lowpriorityscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606040000 definitions=main-2606110032 Content-Type: text/plain; charset="utf-8" From: Sayali Patil migrate_partial_unmap_fault() and migrate_remap_fault() use hardcoded offsets based on a 2MB PMD size. Similarly, 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(). If unavailable, fall back to TWOMEG. 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. On systems with larger PMD sizes, computed test buffer sizes can exceed INT_MAX. Skip such test cases to avoid overflow. 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 | 62 ++++++++++++++++++-------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftes= ts/mm/hmm-tests.c index deb6a7485650..8f4f82467043 100644 --- a/tools/testing/selftests/mm/hmm-tests.c +++ b/tools/testing/selftests/mm/hmm-tests.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -2380,12 +2381,21 @@ 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; + unsigned long offsets[3]; unsigned long i; void *old_ptr; void *map; int *ptr; int ret, j, use_thp; - int offsets[] =3D { 0, 512 * ONEKB, ONEMEG }; + + if (!size) + size =3D TWOMEG; + + unmap_size =3D size / 2; + offsets[0] =3D 0; + offsets[1] =3D size / 4; + offsets[2] =3D size / 2; =20 for (use_thp =3D 0; use_thp < 2; ++use_thp) { for (j =3D 0; j < ARRAY_SIZE(offsets); ++j) { @@ -2427,12 +2437,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; @@ -2446,12 +2456,19 @@ TEST_F(hmm, migrate_remap_fault) struct hmm_buffer *buffer; unsigned long npages; unsigned long size =3D read_pmd_pagesize(); + unsigned long offsets[3]; 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 }; + + if (!size) + size =3D TWOMEG; + + offsets[0] =3D 0; + offsets[1] =3D size / 4; + offsets[2] =3D size / 2; =20 for (before =3D 0; before < 2; ++before) { for (dont_unmap =3D 0; dont_unmap < 2; ++dont_unmap) { @@ -2854,38 +2871,45 @@ static inline int run_migration_benchmark(int fd, i= nt 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; =20 + if (!thp_size) + thp_size =3D TWOMEG; + printf("\nHMM THP Migration Benchmark\n"); printf("---------------------------\n"); printf("System page size: %ld bytes\n", sysconf(_SC_PAGESIZE)); =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 * 128, /* one twenty eight THPs */ }; =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", + "One twenty eight THP Size" }; =20 int num_tests =3D ARRAY_SIZE(test_sizes); =20 /* Run all tests */ for (int i =3D 0; i < num_tests; i++) { + /* Skip test sizes exceeding INT_MAX to avoid overflow */ + if (test_sizes[i] > INT_MAX) + break; + /* Test with THP */ ASSERT_EQ(run_migration_benchmark(self->fd, 1, test_sizes[i], iterations, &thp_results), 0); --=20 2.54.0 From nobody Fri Jun 12 01:47:14 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 1B257311C2A; Thu, 11 Jun 2026 03:42:03 +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=1781149325; cv=none; b=mQ+Wh0vrSM6YSR8znBLyfNdvpQAnHO22sYJPWbJEam9xegFJ7zWg+iretjZ+4o1yhfllGYSUBtGFsFhuXwdgoZihaHFi5HZZCFw56nVYfZjWluO47D20S/VznaBi5NPZ95ANHk1KVhntnklSXtTQsFe4bEqodzVQyobKx+dRFVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781149325; c=relaxed/simple; bh=YCzVzW/BsPEbbOja/j02yPmWwf9lZLthupw9glrzbzg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ER2WNTJVAawlS+UoiCfqiroJa1aISZDdVELgvPREvoUaOxrUz3vMD0M5ReOcdF0uMt/WITBVRcUZDaqUV9Q/mSTxfFosjhmfEr+biN+wdgmM3IZUxF/fQAbLrfcbqIJN+Z/ZfBXpNfjJWzV+vPjd3HvDAUzjCb5UdETXPnvzt+k= 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=Jlzkl5Xy; 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="Jlzkl5Xy" 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 65AJu3op1741881; Thu, 11 Jun 2026 03:41:37 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=NhRSo6Z/W4jD3irkb V2apRuLXcxRfq9kkdO+okO3Cxw=; b=Jlzkl5XyMkwM9GervKpM1nrFhbWDSq/FM rauRTRXeLZmmAK9w/NnVvDb+ru6TTkBd8TNTB3WuerAB3RaHwjep9YDEcofxUamO qIBJ1mDtd5YbyZHtk1wUxylVv1KI/PIhz9sRX7UEsctfRz3pNKwLXzVzm/Y6wr5/ VPqh/fGHygiycvMqsiynVttkRk0fMF9vb1zhHqY1/RE+476Dx4pOOZYuAK0JmSSA zqhizDcNV6XoPLAcaO/MieLCF3N1U0M6iVTXmAmRSBpwqI9J1bDRB0Ebxo0pv809 5Ya7OIGvEugGiyKYBzJW146439t7UC87zY0UtyTJAVHxVDvKYVo/A== 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 4eqe8bh80w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Jun 2026 03:41:36 +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 65B3dAjQ001974; Thu, 11 Jun 2026 03:41:35 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4eqe09hf7b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Jun 2026 03:41:35 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 65B3fVk114942694 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Jun 2026 03:41:32 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D4E2A20043; Thu, 11 Jun 2026 03:41:31 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9D47820040; Thu, 11 Jun 2026 03:41:25 +0000 (GMT) Received: from aboo.ibm.com.com (unknown [9.39.27.36]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 11 Jun 2026 03:41:25 +0000 (GMT) From: Aboorva Devarajan To: Andrew Morton , linux-mm@kvack.org Cc: Jason Gunthorpe , Leon Romanovsky , David Hildenbrand , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Shuah Khan , Ralph Campbell , Matthew Brost , Balbir Singh , Alistair Popple , Alex Sierra , Matthew Wilcox , Sayali Patil , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Aboorva Devarajan Subject: [PATCH v3 3/3] selftests/mm: fix exclusive_cow test fork() handling Date: Thu, 11 Jun 2026 09:11:02 +0530 Message-ID: <20260611034102.1030738-4-aboorvad@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260611034102.1030738-1-aboorvad@linux.ibm.com> References: <20260611034102.1030738-1-aboorvad@linux.ibm.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-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=Xfa5Co55 c=1 sm=1 tr=0 ts=6a2a2e70 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=FelO9ux0wxsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=qerImOSnxKlIG2EQ76sA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjExMDAzMiBTYWx0ZWRfXwuBRMA9ofurN DRF9/IxvT7YfjGofRDu3rufKRwBD/EFBtft/ebk+6w3tHTYcUueien8y4OX4twbkGaaluN5AmAn zDomrsbKg/RVhlAht7kYRLV5zeZTc+//H5quTBJsJMmPuAkS/JSMEjUZ3oQn3/RKbxrBmFoD4V7 HpL0iPmy1RbIp+Xh1o+XUZs/bIgz4RCGl+NWwdvX1PbyJgZNtLoklGEFabBJ+THs4lXtkSdGFdV hMvoUE/GKK4PrLxjg1urjzD1dkD/o1DgmZl244bohffeQLRB079kPGzUtfoIMKmG7OtXdijfJmz XOrNqMX3iVvL2CdPidhljgQymQs2rg7hDkPTF+fjysrgAw0SD8g+8poZVNoP399e06sULab+Yi8 n0re2BbHaIQ6lGk5WPlVTcpBxgVgn11v0YuiP8BBimmqNGeaoHERIhyJmX3grQOTA6Ilh5FgxGR mAJ4YEaZv2QJVroaxeg== X-Proofpoint-Spam-Info: AW1haW4tMjYwNjExMDAzMiBTYWx0ZWRfX23Z/1Tm6Hdq+ n67wZ+D4GD4hpN/3qZ5ji4oLyp7WxipbR0m8fmtJGrX1HBbs5dK+u5+NRucy4Syfxv0wOlELfLA rFLyjtJ1mPpe7sxAMabF0hQWXYPesfo= X-Proofpoint-ORIG-GUID: 0LkASIrnKhk4Zh6sHYbQn9nK8TJmjTT1 X-Proofpoint-GUID: Q8hGwmMOMMTc_3yFvNLksDWfLZ7DXacl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-11_01,2026-06-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 suspectscore=0 clxscore=1015 phishscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606040000 definitions=main-2606110032 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 Acked-by: Balbir Singh --- tools/testing/selftests/mm/hmm-tests.c | 31 +++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftes= ts/mm/hmm-tests.c index 8f4f82467043..e4c49699f3f7 100644 --- a/tools/testing/selftests/mm/hmm-tests.c +++ b/tools/testing/selftests/mm/hmm-tests.c @@ -1884,6 +1884,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); @@ -1912,14 +1914,37 @@ 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 verifies COW independently, then _exit(0)s so it does + * not run the test teardown. A failed ASSERT_* here makes the + * harness abort() the child, so the parent sees + * !WIFEXITED(status) below and fails in turn. + */ + 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