Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1071790rdd; Wed, 10 Jan 2024 07:54:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfpbPxZajCCO9XqW+XygPgyNCokRxmsV8ghIOx1GeRrgo0J2DYvc59nja/jni8bd3fAlVe X-Received: by 2002:a05:6512:4896:b0:50b:f7bb:4545 with SMTP id eq22-20020a056512489600b0050bf7bb4545mr520587lfb.68.1704902042626; Wed, 10 Jan 2024 07:54:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704902042; cv=none; d=google.com; s=arc-20160816; b=dPhTA46BbPHJfb7RIF/C0FtkPCDAc552f1eXRFAWDcKfiVMyGyGq1XLKU6wOwFaMs5 vFPKuFC5/dCLhlQKIfPsLd9sz28kJpL7Yc3li3KUipMmivRrA/cAyjLdZudHWZj78Mh1 7WUunsFYPFpWm3YOY/qN83VnynKPVUjuSCmA7rFfOM62EHLRqZwxsHz13UBe66RZ491i 2D34WeQ1eH9yWfsZn/+yD4dzRfr9hROny0vnwAPyoUuwUD97Jph6WmRebS0Lg/0jDwo5 pNobg7JPgRO3QCdJKNh4B3uAzrmgy4L1Qa1YfOV182rd8PbiUJXNlzwQyQC/C24QrCqX oX2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=gTa+0u9JoTUhnwuYrBd6dl7EiHdv21BYr/eMNJ7K3cQ=; fh=Wln7YX1VOGRbVUZYzWSEbW+NVyAgzPR8aWNWWLezgPE=; b=rOnFRhQveMAjOdY2sq/2XI4Bp7dmJTWbbsz73jxAwZ8atIhDYn1YId4kUqoBxs4Pw1 jlbv4YRiH6xukpFQBIecqdEQka3PqbsAbnwmNc6QTN8dmTCTV3DwPZycQcuahlcb2LbU 3eaLOkC9601KadL6lDBqQufoNFAtXVKzISlOhU0J7eq6t1/ym6OGFCmxNG6Z73vo6NBo KssF8XtHN8hP8nPZ9HB7NOPv1NmyfV5llQzYbLtbFs47B5zvjTq3bW4Aoi2pfNOefo3Z o7p9ROC69hv2JSIgxzTHRgVeaGMUwfeHkor0bvCZ9nGGyUgf9beDX3jcB2x/qDO+V7il xAaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=ZQ9oPBt7; spf=pass (google.com: domain of linux-kernel+bounces-22460-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22460-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lo3-20020a170906fa0300b00a2a6ad0c300si1800657ejb.912.2024.01.10.07.54.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 07:54:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22460-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=ZQ9oPBt7; spf=pass (google.com: domain of linux-kernel+bounces-22460-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22460-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5CF731F29439 for ; Wed, 10 Jan 2024 15:54:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E08064C3C8; Wed, 10 Jan 2024 15:53:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="ZQ9oPBt7" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 104894BAB6; Wed, 10 Jan 2024 15:53:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46889C433F1; Wed, 10 Jan 2024 15:53:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1704902032; bh=VExTAiazsv1g0aY0B55Q7g+sXT0qRACvGzmBLH2Jgb0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ZQ9oPBt7bDzRZBHYow8LOiyL91eqgYQn2ntahsGax2Fw+QLnKGR9Nbjjnwdpv6qYZ 3n2yxOVXeMsbtaRCMeqbY8oiXEkYun5nZoB84f34g4rSZAygKfeCEjW+h9l436TnuM VUd8g7DUaP6AGF7KPd9Rf/qwlupWUUF4ecYhgFOQ= Date: Wed, 10 Jan 2024 07:53:51 -0800 From: Andrew Morton To: Donet Tom Cc: linux-kselftest@vger.kernel.org, Aneesh Kumar , linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Geetika Moolchandani , Muchun Song Subject: Re: [PATCH 1/1] selftests: mm: hugepage-vmemmap fails on 64K page size systems. Message-Id: <20240110075351.f4b6f43e31629ddcb96503cc@linux-foundation.org> In-Reply-To: <3b3a3ae37ba21218481c482a872bbf7526031600.1704865754.git.donettom@linux.vnet.ibm.com> References: <3b3a3ae37ba21218481c482a872bbf7526031600.1704865754.git.donettom@linux.vnet.ibm.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit (cc Muchun) On Wed, 10 Jan 2024 14:03:35 +0530 Donet Tom wrote: > 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) I'll add Fixes: b147c89cd429 ("selftests: vm: add a hugetlb test case") Cc: > > 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); > } > -- > 2.43.0