From patchwork Wed Jan 10 08:33:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donet Tom X-Patchwork-Id: 13515754 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07495C3DA6E for ; Wed, 10 Jan 2024 08:33:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 712186B007B; Wed, 10 Jan 2024 03:33:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C0FA6B007D; Wed, 10 Jan 2024 03:33:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 588326B0080; Wed, 10 Jan 2024 03:33:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 48CED6B007B for ; Wed, 10 Jan 2024 03:33:45 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1AB131209BF for ; Wed, 10 Jan 2024 08:33:45 +0000 (UTC) X-FDA: 81662738010.16.32270D3 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf17.hostedemail.com (Postfix) with ESMTP id F3E1040006 for ; Wed, 10 Jan 2024 08:33:42 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b="jeJNV/GF"; spf=none (imf17.hostedemail.com: domain of donettom@linux.vnet.ibm.com has no SPF policy when checking 148.163.158.5) smtp.mailfrom=donettom@linux.vnet.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704875623; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=GQLmdzTFvokN1N5EM1lR19Xz2d+PKMEyH5r0sANs38s=; b=QD9yqDup5oq1b4Bk0GSMhcJhlFyKa/Qsc/Lw21jtgaNUMbSnRREfmOzMw7G0zC7so+8cQd Y2lwjuaE48mDQofxwge1lOua+mvxQE5Z1SMePBXCGCTwVoNjKAdiJpwgVnhgJ/AGkc10TQ PHlNBAhO9314EiuzvwjgnKA6ghw1XbI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704875623; a=rsa-sha256; cv=none; b=ZebKaUnjqlDBId1tkGa1D8q/tDQCTmTKSU7LNDGuboVntK9b3Z77SEdm3NkAcdryqBQwpX l1MGLmi9eoC99Esb4zhoFADaVAnr/X2WRPJN6DPUmS3/qRe1lOmXxQTtglEoAOx3CLVwOe 9dRDE6i30rosZ2fZM38gDwvR+Sm2II4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b="jeJNV/GF"; spf=none (imf17.hostedemail.com: domain of donettom@linux.vnet.ibm.com has no SPF policy when checking 148.163.158.5) smtp.mailfrom=donettom@linux.vnet.ibm.com; dmarc=pass (policy=none) header.from=ibm.com Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40A8WjVa005535; Wed, 10 Jan 2024 08:33:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=GQLmdzTFvokN1N5EM1lR19Xz2d+PKMEyH5r0sANs38s=; b=jeJNV/GFGOMjMkhcI6J8PGwyQZgbFboUFjUx7WBkX7YPgfaAk9yFNSZYgsI9ljRF253w jS67iErR0xXwmy2ManTYBrEH3pfpzsRWcT5JCRIYOWRYcslZWnBEJZRq7ZZc9HoRm5pt b5CzTlC82JYwrExgszisyjiFr/iRBHEwGGX/KjFIp0U+wjQdRUez+sGrrr82N60ZNZNB UvtnmnogN6wJgDNVT3nAzCOJICsgMm1yf6gaUVHySdOhZQfJK1uk/sOfdEnJQXBF66tV lDU9A7xRNt/9/nHrfD6ahNWy0BARJcI2WxFjp49yPhZ1yjKtIHQmqXwhnpSzoTp2Om5I Vg== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vhqtng0xf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 08:33:41 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 40A7a5Ob028052; Wed, 10 Jan 2024 08:33:40 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3vgwfsr3xw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 08:33:40 +0000 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 40A8Xb4W14680706 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 08:33:37 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B8B292004B; Wed, 10 Jan 2024 08:33:37 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D80FE20040; Wed, 10 Jan 2024 08:33:35 +0000 (GMT) Received: from li-06431bcc-2712-11b2-a85c-a6fe68df28f9.in.ibm.com (unknown [9.109.245.191]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 10 Jan 2024 08:33:35 +0000 (GMT) From: Donet Tom To: Andrew Morton , linux-kselftest@vger.kernel.org Cc: Aneesh Kumar , linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Geetika Moolchandani Subject: [PATCH 1/1] selftests: mm: hugepage-vmemmap fails on 64K page size systems. Date: Wed, 10 Jan 2024 14:03:35 +0530 Message-ID: <3b3a3ae37ba21218481c482a872bbf7526031600.1704865754.git.donettom@linux.vnet.ibm.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ZSKpAOiSoWt1ETnpvKHBG_uRZdBm_ixf X-Proofpoint-ORIG-GUID: ZSKpAOiSoWt1ETnpvKHBG_uRZdBm_ixf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_02,2024-01-09_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=999 impostorscore=0 malwarescore=0 bulkscore=0 clxscore=1011 suspectscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100069 X-Rspamd-Queue-Id: F3E1040006 X-Rspam-User: X-Stat-Signature: tmu7596fxgydzuxxujdty69st3gn8xzt X-Rspamd-Server: rspam03 X-HE-Tag: 1704875622-972276 X-HE-Meta: U2FsdGVkX1//oy1pZluk8SVvp06IaM84RkwAGXlwKGF3RJNQZfrVTqqBdok7BoUJQDs7cgfWd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SyW5Z2aOuWtPIvoAHeL04xuNOfZyajwANgFLpu9pLvaxALvPtIXH8Ri9FBuqEm5NbIH6C5Y3DfhsCvUvPIhxSzVfq X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The kernel sefltest mm/hugepage-vmemmap fails on architectures which has different page size other than 4K. In hugepage-vmemmap page size used is 4k so the pfn calculation will go wrong on systems which has different page size .The length of MAP_HUGETLB memory must be hugepage aligned but in hugepage-vmemmap map length is 2M so this will not get aligned if the system has differnet hugepage size. Added psize() to get the page size and default_huge_page_size() to get the default hugepage size at run time, hugepage-vmemmap test pass on powerpc with 64K page size and x86 with 4K page size. Result on powerpc without patch (page size 64K) *# ./hugepage-vmemmap Returned address is 0x7effff000000 whose pfn is 0 Head page flags (100000000) is invalid check_page_flags: Invalid argument *# Result on powerpc with patch (page size 64K) *# ./hugepage-vmemmap Returned address is 0x7effff000000 whose pfn is 600 *# Result on x86 with patch (page size 4K) *# ./hugepage-vmemmap Returned address is 0x7fc7c2c00000 whose pfn is 1dac00 *# Signed-off-by: Donet Tom Reported-by : Geetika Moolchandani (geetika@linux.ibm.com) Tested-by : Geetika Moolchandani (geetika@linux.ibm.com) Acked-by: Muchun Song --- tools/testing/selftests/mm/hugepage-vmemmap.c | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/mm/hugepage-vmemmap.c b/tools/testing/selftests/mm/hugepage-vmemmap.c index 5b354c209e93..894d28c3dd47 100644 --- a/tools/testing/selftests/mm/hugepage-vmemmap.c +++ b/tools/testing/selftests/mm/hugepage-vmemmap.c @@ -10,10 +10,7 @@ #include #include #include - -#define MAP_LENGTH (2UL * 1024 * 1024) - -#define PAGE_SIZE 4096 +#include "vm_util.h" #define PAGE_COMPOUND_HEAD (1UL << 15) #define PAGE_COMPOUND_TAIL (1UL << 16) @@ -39,6 +36,9 @@ #define MAP_FLAGS (MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB) #endif +static size_t pagesize; +static size_t maplength; + static void write_bytes(char *addr, size_t length) { unsigned long i; @@ -56,7 +56,7 @@ static unsigned long virt_to_pfn(void *addr) if (fd < 0) return -1UL; - lseek(fd, (unsigned long)addr / PAGE_SIZE * sizeof(pagemap), SEEK_SET); + lseek(fd, (unsigned long)addr / pagesize * sizeof(pagemap), SEEK_SET); read(fd, &pagemap, sizeof(pagemap)); close(fd); @@ -86,7 +86,7 @@ static int check_page_flags(unsigned long pfn) * this also verifies kernel has correctly set the fake page_head to tail * while hugetlb_free_vmemmap is enabled. */ - for (i = 1; i < MAP_LENGTH / PAGE_SIZE; i++) { + for (i = 1; i < maplength / pagesize; i++) { read(fd, &pageflags, sizeof(pageflags)); if ((pageflags & TAIL_PAGE_FLAGS) != TAIL_PAGE_FLAGS || (pageflags & HEAD_PAGE_FLAGS) == HEAD_PAGE_FLAGS) { @@ -106,18 +106,25 @@ int main(int argc, char **argv) void *addr; unsigned long pfn; - addr = mmap(MAP_ADDR, MAP_LENGTH, PROT_READ | PROT_WRITE, MAP_FLAGS, -1, 0); + pagesize = psize(); + maplength = default_huge_page_size(); + if (!maplength) { + printf("Unable to determine huge page size\n"); + exit(1); + } + + addr = mmap(MAP_ADDR, maplength, PROT_READ | PROT_WRITE, MAP_FLAGS, -1, 0); if (addr == MAP_FAILED) { perror("mmap"); exit(1); } /* Trigger allocation of HugeTLB page. */ - write_bytes(addr, MAP_LENGTH); + write_bytes(addr, maplength); pfn = virt_to_pfn(addr); if (pfn == -1UL) { - munmap(addr, MAP_LENGTH); + munmap(addr, maplength); perror("virt_to_pfn"); exit(1); } @@ -125,13 +132,13 @@ int main(int argc, char **argv) printf("Returned address is %p whose pfn is %lx\n", addr, pfn); if (check_page_flags(pfn) < 0) { - munmap(addr, MAP_LENGTH); + munmap(addr, maplength); perror("check_page_flags"); exit(1); } /* munmap() length of MAP_HUGETLB memory must be hugepage aligned */ - if (munmap(addr, MAP_LENGTH)) { + if (munmap(addr, maplength)) { perror("munmap"); exit(1); }