From mboxrd@z Thu Jan 1 00:00:00 1970 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 CAFE1C433EF for ; Wed, 2 Feb 2022 06:12:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 191AB8D00EE; Wed, 2 Feb 2022 01:12:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 141708D00C9; Wed, 2 Feb 2022 01:12:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 008CD8D00EE; Wed, 2 Feb 2022 01:12:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0165.hostedemail.com [216.40.44.165]) by kanga.kvack.org (Postfix) with ESMTP id E4FF98D00C9 for ; Wed, 2 Feb 2022 01:12:07 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 9B0DE829CF4C for ; Wed, 2 Feb 2022 06:12:07 +0000 (UTC) X-FDA: 79096819494.05.08285AA Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf14.hostedemail.com (Postfix) with ESMTP id 30209100004 for ; Wed, 2 Feb 2022 06:12:07 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2F0D161706; Wed, 2 Feb 2022 06:12:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79C0AC340EC; Wed, 2 Feb 2022 06:12:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643782325; bh=6Z1LUyHDGqpVzlaGZNpCJgZiHw2AD96G0aoaSJiw7bs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SOJgsm/hkyTLZh5unQDpcOq2QZaxgqLwywMfNdSyyZeQbY6bPzFn1DF7iA0xob2ZU d5rJ0Vua6VoBalmLZ/sJJho7Pp02ft0s5N2SibV/SYLIvgFLtSWi/8TOphDplGDBei vkeumGhpF+de9+87SB+/eQBMknJdXGt6K85exYa5EgyfpZoiQ2XEcGBP6GQZZ9hSXP DbvJ6xN58DRKO9adAamfWignpgf2+37JN1otiTiABAdl3CMOyeKFs8TyvBzu8XDEax Cj5sQRugkv0YtKA3Hd/rrnwZcNmKiZxxrsLffG3rQII5s+9dWOOQ19d1RjUTLnzKE+ SD32Vo7+2miEw== Date: Wed, 2 Feb 2022 08:11:56 +0200 From: Mike Rapoport To: Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Naoya Horiguchi , David Hildenbrand , Axel Rasmussen , Mina Almasry , Michal Hocko , Peter Xu , Andrea Arcangeli , Shuah Khan , Andrew Morton Subject: Re: [PATCH v2 3/3] userfaultfd/selftests: enable huegtlb remap and remove event testing Message-ID: References: <20220202014034.182008-1-mike.kravetz@oracle.com> <20220202014034.182008-4-mike.kravetz@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220202014034.182008-4-mike.kravetz@oracle.com> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 30209100004 X-Rspam-User: nil Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="SOJgsm/h"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org X-Stat-Signature: x8h96dahokz6g4g5s13be9asd998nroz X-HE-Tag: 1643782327-720484 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: On Tue, Feb 01, 2022 at 05:40:34PM -0800, Mike Kravetz wrote: > Subject: [PATCH v2 3/3] userfaultfd/selftests: enable huegtlb remap and remove event testing Nit: ^ hugetlb > With MADV_DONTNEED support added to hugetlb mappings, mremap testing > can also be enabled for hugetlb. > > Modify the tests to use madvise MADV_DONTNEED and MADV_REMOVE instead of > fallocate hole puch for releasing hugetlb pages. > > Signed-off-by: Mike Kravetz > Reviewed-by: Axel Rasmussen > --- > tools/testing/selftests/vm/run_vmtests.sh | 3 +- > tools/testing/selftests/vm/userfaultfd.c | 69 ++++++++++++----------- > 2 files changed, 36 insertions(+), 36 deletions(-) > > diff --git a/tools/testing/selftests/vm/run_vmtests.sh b/tools/testing/selftests/vm/run_vmtests.sh > index ff901ee66838..7178d6fa8c92 100755 > --- a/tools/testing/selftests/vm/run_vmtests.sh > +++ b/tools/testing/selftests/vm/run_vmtests.sh > @@ -207,14 +207,13 @@ echo "running userfaultfd_hugetlb" > echo "---------------------------" > # Test requires source and destination huge pages. Size of source > # (half_ufd_size_MB) is passed as argument to test. > -./userfaultfd hugetlb $half_ufd_size_MB 32 $mnt/ufd_test_file > +./userfaultfd hugetlb $half_ufd_size_MB 32 > if [ $? -ne 0 ]; then > echo "[FAIL]" > exitcode=1 > else > echo "[PASS]" > fi > -rm -f $mnt/ufd_test_file > > echo "-------------------------" > echo "running userfaultfd_shmem" > diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c > index d2480ab93037..c18beebc0dd6 100644 > --- a/tools/testing/selftests/vm/userfaultfd.c > +++ b/tools/testing/selftests/vm/userfaultfd.c > @@ -88,7 +88,6 @@ static bool test_uffdio_minor = false; > static bool map_shared; > static int shm_fd; > static int huge_fd; > -static char *huge_fd_off0; > static unsigned long long *count_verify; > static int uffd = -1; > static int uffd_flags, finished, *pipefd; > @@ -127,9 +126,9 @@ const char *examples = > "./userfaultfd anon 100 99999\n\n" > "# Run share memory test on 1GiB region with 99 bounces:\n" > "./userfaultfd shmem 1000 99\n\n" > - "# Run hugetlb memory test on 256MiB region with 50 bounces (using /dev/hugepages/hugefile):\n" > - "./userfaultfd hugetlb 256 50 /dev/hugepages/hugefile\n\n" > - "# Run the same hugetlb test but using shmem:\n" > + "# Run hugetlb memory test on 256MiB region with 50 bounces:\n" > + "./userfaultfd hugetlb 256 50\n\n" > + "# Run the same hugetlb test but using shared file:\n" > "./userfaultfd hugetlb_shared 256 50 /dev/hugepages/hugefile\n\n" > "# 10MiB-~6GiB 999 bounces anonymous test, " > "continue forever unless an error triggers\n" > @@ -226,10 +225,13 @@ static void noop_alias_mapping(__u64 *start, size_t len, unsigned long offset) > > static void hugetlb_release_pages(char *rel_area) > { > - if (fallocate(huge_fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, > - rel_area == huge_fd_off0 ? 0 : nr_pages * page_size, > - nr_pages * page_size)) > - err("fallocate() failed"); > + if (!map_shared) { > + if (madvise(rel_area, nr_pages * page_size, MADV_DONTNEED)) > + err("madvise(MADV_DONTNEED) failed"); > + } else { > + if (madvise(rel_area, nr_pages * page_size, MADV_REMOVE)) > + err("madvise(MADV_REMOVE) failed"); > + } > } > > static void hugetlb_allocate_area(void **alloc_area) > @@ -237,26 +239,37 @@ static void hugetlb_allocate_area(void **alloc_area) > void *area_alias = NULL; > char **alloc_area_alias; > > - *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, > - (map_shared ? MAP_SHARED : MAP_PRIVATE) | > - MAP_HUGETLB | > - (*alloc_area == area_src ? 0 : MAP_NORESERVE), > - huge_fd, *alloc_area == area_src ? 0 : > - nr_pages * page_size); > + if (!map_shared) > + *alloc_area = mmap(NULL, > + nr_pages * page_size, > + PROT_READ | PROT_WRITE, > + MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | > + (*alloc_area == area_src ? 0 : MAP_NORESERVE), > + -1, > + 0); > + else > + *alloc_area = mmap(NULL, > + nr_pages * page_size, > + PROT_READ | PROT_WRITE, > + MAP_SHARED | > + (*alloc_area == area_src ? 0 : MAP_NORESERVE), > + huge_fd, > + *alloc_area == area_src ? 0 : nr_pages * page_size); > if (*alloc_area == MAP_FAILED) > err("mmap of hugetlbfs file failed"); > > if (map_shared) { > - area_alias = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, > - MAP_SHARED | MAP_HUGETLB, > - huge_fd, *alloc_area == area_src ? 0 : > - nr_pages * page_size); > + area_alias = mmap(NULL, > + nr_pages * page_size, > + PROT_READ | PROT_WRITE, > + MAP_SHARED, > + huge_fd, > + *alloc_area == area_src ? 0 : nr_pages * page_size); > if (area_alias == MAP_FAILED) > err("mmap of hugetlb file alias failed"); > } > > if (*alloc_area == area_src) { > - huge_fd_off0 = *alloc_area; > alloc_area_alias = &area_src_alias; > } else { > alloc_area_alias = &area_dst_alias; > @@ -269,12 +282,7 @@ static void hugetlb_alias_mapping(__u64 *start, size_t len, unsigned long offset > { > if (!map_shared) > return; > - /* > - * We can't zap just the pagetable with hugetlbfs because > - * MADV_DONTEED won't work. So exercise -EEXIST on a alias > - * mapping where the pagetables are not established initially, > - * this way we'll exercise the -EEXEC at the fs level. > - */ > + > *start = (unsigned long) area_dst_alias + offset; > } > > @@ -427,7 +435,6 @@ static void uffd_test_ctx_clear(void) > uffd = -1; > } > > - huge_fd_off0 = NULL; > munmap_area((void **)&area_src); > munmap_area((void **)&area_src_alias); > munmap_area((void **)&area_dst); > @@ -925,10 +932,7 @@ static int faulting_process(int signal_test) > struct sigaction act; > unsigned long signalled = 0; > > - if (test_type != TEST_HUGETLB) > - split_nr_pages = (nr_pages + 1) / 2; > - else > - split_nr_pages = nr_pages; > + split_nr_pages = (nr_pages + 1) / 2; > > if (signal_test) { > sigbuf = &jbuf; > @@ -985,9 +989,6 @@ static int faulting_process(int signal_test) > if (signal_test) > return signalled != split_nr_pages; > > - if (test_type == TEST_HUGETLB) > - return 0; > - > area_dst = mremap(area_dst, nr_pages * page_size, nr_pages * page_size, > MREMAP_MAYMOVE | MREMAP_FIXED, area_src); > if (area_dst == MAP_FAILED) > @@ -1670,7 +1671,7 @@ int main(int argc, char **argv) > } > nr_pages = nr_pages_per_cpu * nr_cpus; > > - if (test_type == TEST_HUGETLB) { > + if (test_type == TEST_HUGETLB && map_shared) { > if (argc < 5) > usage(); > huge_fd = open(argv[4], O_CREAT | O_RDWR, 0755); > -- > 2.34.1 > > -- Sincerely yours, Mike.