From mboxrd@z Thu Jan 1 00:00:00 1970 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-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 From: Sayali Patil The HMM compound testcase currently assumes only PMD-level mappings and fails on systems where default_hugepagesz=1G 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/selftests/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) } /* - * 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 = default_huge_page_size(); int *ptr; unsigned char *m; + unsigned char prot; int ret; unsigned long i; @@ -1648,11 +1649,20 @@ TEST_F(hmm, compound) ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); - /* 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 = buffer->mirror; + prot = HMM_DMIRROR_PROT_WRITE | + ((m[0] & HMM_DMIRROR_PROT_PUD) ? HMM_DMIRROR_PROT_PUD : + HMM_DMIRROR_PROT_PMD); for (i = 0; i < npages; ++i) - ASSERT_EQ(m[i], HMM_DMIRROR_PROT_WRITE | - HMM_DMIRROR_PROT_PMD); + ASSERT_EQ(m[i], prot); /* Make the region read-only. */ ret = mprotect(buffer->ptr, size, PROT_READ); @@ -1663,11 +1673,17 @@ TEST_F(hmm, compound) ASSERT_EQ(ret, 0); ASSERT_EQ(buffer->cpages, npages); - /* 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 = buffer->mirror; + prot = HMM_DMIRROR_PROT_READ | + ((m[0] & HMM_DMIRROR_PROT_PUD) ? HMM_DMIRROR_PROT_PUD : + HMM_DMIRROR_PROT_PMD); for (i = 0; i < npages; ++i) - ASSERT_EQ(m[i], HMM_DMIRROR_PROT_READ | - HMM_DMIRROR_PROT_PMD); + ASSERT_EQ(m[i], prot); munmap(buffer->ptr, buffer->size); buffer->ptr = NULL; base-commit: 801c5efa788952095586d076fed1ea4902facff8 -- 2.54.0