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 37C6DC433F5 for ; Fri, 28 Jan 2022 23:35:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2260F6B00DC; Fri, 28 Jan 2022 18:35:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D2D96B00DD; Fri, 28 Jan 2022 18:35:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04C736B00DE; Fri, 28 Jan 2022 18:35:04 -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 E82306B00DC for ; Fri, 28 Jan 2022 18:35:04 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A3BE68287E08 for ; Fri, 28 Jan 2022 23:35:04 +0000 (UTC) X-FDA: 79081303728.15.BDC9E3F Received: from mail-io1-f46.google.com (mail-io1-f46.google.com [209.85.166.46]) by imf26.hostedemail.com (Postfix) with ESMTP id 1EDE8140004 for ; Fri, 28 Jan 2022 23:35:03 +0000 (UTC) Received: by mail-io1-f46.google.com with SMTP id p63so8843907iod.11 for ; Fri, 28 Jan 2022 15:35:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=JpxTvdtKkLVFIRueCOXz6q3rm9liXhmMzUpLMlmCnLU=; b=g7/+yn+1wuV/EnT2ud8bvqTF+w10NI6OEzAsSl22TTd5ghnv4EncSe/8gGllBy0rVZ Q62XSk5EQ6GfQwP0muWw+uvAAXSc31tPIev3WiOaXTLLtnYW9pnVG+LlI1Bd1Jl6eo9L 1LCDO3Z0/zb7TtpfkucaBFtyVTqZG+PxbqpM8/Ww+Pc7kh7yBeJ+/wqOCiJtb5NyL9Hh x03Ifmpv6zWzidSFG/zSX/BFFT3X7uVVF2B0o2xDbLOruEgDl0uOXk439QUGaKnFYSr+ xhexMcQqGzNUo2DbX3ttUiEH90YR3qvrsXF7WRt42klLthjuw6ylUIHqVb1eg2t7uNcZ T8iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=JpxTvdtKkLVFIRueCOXz6q3rm9liXhmMzUpLMlmCnLU=; b=uSmNAwU3NiWJJOejvszN+cbABD4jHocC22FmCVa3QvmqAISHYpbilxEFmXTbGoOn8S UH5uP693IThsvVwwCOVxlM1NKjhvGuHYIigMEe0NDR6Zal/6E4/C1t+xYreEfGR1yVym 0xC+fEM88nmcgc7esVU1aILigMPwxaaWEbqXPdM5XG6F9PRHsGp8ohAYACbcWZP1SlpS yHo/Abs51HsKlWMgCIIyZ4DIukxW8MJVs9Yqe5m47WKHWBq10c3cD/XJmCeSHy8G+8jb 1pChnQdsIFn/t5fYFfHo93qTUYu5m/rMuGPDgiQPw7D1U8KiPLlyf2CSViXyHX0yXhfc h/lQ== X-Gm-Message-State: AOAM5336S9wOgAGUdDQO7RiPlfIl7uSaV/E4Q03CWhP+bJHMH4qUWmQb ANcPPDWeeJKY5Y38JvqNsX5iKad//kmB8rMtk7lpMg== X-Google-Smtp-Source: ABdhPJwWUB5cbdyBGAqxyMyGHOnbfYZPcT4OjPCpBoMeE03TcdvaUaIgTMJv3osnClnOWBdt7NXijWYqK9dvzOoSVoc= X-Received: by 2002:a6b:bf81:: with SMTP id p123mr6645468iof.171.1643412903171; Fri, 28 Jan 2022 15:35:03 -0800 (PST) MIME-Version: 1.0 References: <20220128222605.66828-1-mike.kravetz@oracle.com> <20220128222605.66828-4-mike.kravetz@oracle.com> In-Reply-To: <20220128222605.66828-4-mike.kravetz@oracle.com> From: Axel Rasmussen Date: Fri, 28 Jan 2022 15:34:27 -0800 Message-ID: Subject: Re: [PATCH 3/3] userfaultfd/selftests: enable huegtlb remap and remove event testing To: Mike Kravetz Cc: Linux MM , LKML , Naoya Horiguchi , David Hildenbrand , Mina Almasry , Michal Hocko , Peter Xu , Andrea Arcangeli , Shuah Khan , Andrew Morton Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1EDE8140004 X-Stat-Signature: bp5n3bkwi6nfxqiow69jpeg8snwzfmn7 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="g7/+yn+1"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of axelrasmussen@google.com designates 209.85.166.46 as permitted sender) smtp.mailfrom=axelrasmussen@google.com X-Rspam-User: nil X-HE-Tag: 1643412903-948131 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: Besides the help text, looks correct to me. I applied the patches and ran the userfaultfd selftests, and everything seems to work properly. Reviewed-by: Axel Rasmussen On Fri, Jan 28, 2022 at 2:26 PM Mike Kravetz wrote: > > 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 > --- > tools/testing/selftests/vm/userfaultfd.c | 67 ++++++++++++------------ > 1 file changed, 34 insertions(+), 33 deletions(-) > > diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c > index d3fd24f9fae8..f5578ef85560 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; > @@ -124,9 +123,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" > + "# Run hugetlb memory test on 256MiB region with 50 bounces:\n" > "./userfaultfd hugetlb 256 50 /dev/hugepages/hugefile\n\n" We should remove the path from the line above here as well, right? Since for the hugetlb test type, we now just MAP_ANONYMOUS | MAP_HUGETLB, we don't open a file descriptor. > - "# Run the same hugetlb test but using shmem:\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" > @@ -223,10 +222,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) > @@ -234,26 +236,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; > @@ -266,12 +279,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; > } > > @@ -424,7 +432,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); > @@ -922,10 +929,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; > @@ -982,9 +986,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) > @@ -1667,7 +1668,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 >