Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4916205pxy; Tue, 27 Apr 2021 15:56:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2HCeXyz0yoLOsgF8WHafk4JofW/cqFv5T2+EGt3odfvr7/PbCVM6iHmBTGr146Rc+wEU0 X-Received: by 2002:a17:902:4d:b029:ec:94df:c9aa with SMTP id 71-20020a170902004db02900ec94dfc9aamr26887521pla.7.1619564211322; Tue, 27 Apr 2021 15:56:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619564211; cv=none; d=google.com; s=arc-20160816; b=orCmxDThbtz78S+GYMO4TTzswkN/D7ceaAVC7ONvm3nD1D+BA2tEuBJJfx4xKfsbHo IPtYxnVtO2w7tEiSbd4czebLq86K88XL+4kux1pqlcOJHbLN/OWUOmGKotYBWa1039w/ WtYMboWhxA3dBLofbWWQ6I3oUCZQas9aHVYIZvT994NNzCKBLI3ejmoCfvFjrjZ+bIxn gLVyBekmlFJ3kw7DBWRJIRHgS5VzV7MgZAwJ0vWT2uKlJ/Cc9kzC138zxnn/+mMpiaMj e96lOXgVFb9l/8gRMaJUIK2L04zlYFLm0wsOQxjQLhgRfd1VCmni6I8RosYlvHaeCect NhfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=u1gk9aiwDmv6+SRZ0ft4k2Rli22/pgCpQ8yAo+qVnNA=; b=LFQPHsYHTXPy2Z36vmLuiNTBxmg3AlO/VHSsyfsT7vgTnkjp2Qd0oaQEeognhnPkle oiG+1IYC7GvPJsMKaKeyy+QvKJkuY5MYXcGrCA97tV8AsRRy808zUe6p68SEL686Scny 3cjU0USnCJlfogmqCH7wIR/Q1px63bMIvnM19El2b8jlDeAJaz7EJJA5eVur6XWB8zu7 q5PDgekOqRjuOzFzkpZVmyhaEXj65KYcFSoKsjCB6F40dGlirJfbk7Ej4b7ZX0Wtj03H TJrkA6eUMe31kT7xfkO/KjPOX0MA4S+TJIy4dZVxTIX/HMHHcBEApu1A2qA5qpyGSfDq BsDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WhttcOh6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g6si1344756pgg.244.2021.04.27.15.56.38; Tue, 27 Apr 2021 15:56:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WhttcOh6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239493AbhD0WyC (ORCPT + 99 others); Tue, 27 Apr 2021 18:54:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239460AbhD0Wx6 (ORCPT ); Tue, 27 Apr 2021 18:53:58 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B294DC06175F for ; Tue, 27 Apr 2021 15:53:12 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id o129-20020a6292870000b0290241fe341603so22160572pfd.14 for ; Tue, 27 Apr 2021 15:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=u1gk9aiwDmv6+SRZ0ft4k2Rli22/pgCpQ8yAo+qVnNA=; b=WhttcOh6OlYlGtQYO3hqYvxXeiYuKV+rWQSt5GADJGax/zVklA+4aVWY6Vth1HSH3X jwqi4xlCmJmF2uk4C3mUlO9dXP5GKLMafa/YYpnFpCz7vDawNizmXlGB6yjOLRbWnnjs zUKKD0pPXPMq+GNf9mgcyCiC+JYB1W0gdtCctKXlHEeJk0mX+xU28z2b6gRtk8Yu85nl 2JjUUN+ND3iO+ubDxIVQYc87lZwqiydAQ90ZMWi5SimqntNNm/EZWf8oo0PfH30L05ai eXKCJjGA7iP4ZQy64cNZRCZh9nqI8vq5hUhkIc2nfyfHUBlBdiVJlltPIDFueWEmrOik S4mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=u1gk9aiwDmv6+SRZ0ft4k2Rli22/pgCpQ8yAo+qVnNA=; b=qbxzepD6TUCEgIJxFCD3T1m6RkWB6jeHerkEMJjxhQbaWWNtoZ3OQ77NI4wE7Ra68L jUgAF0X1tvh6pO1hNQYyZ8lFKO9P+g9+mOZKQnd0d/nAenoaOifj+a8tbVFs8nVjw27c MsG9F3sLmP3gKqFvRWbhADnJP3LSIqF6bvb8sbHFKHX8l4MNl+lQ0BKMmNuU8stbmEd5 onRTRTGmneBvq4X5ivPZOEi2P7Ir4z4/DhD6DkV7JdC9I+GNIGZd57Ef6YnrkeRU2YLu k1MWwHJaeQypOWJgcXQvLIjUvDfzK66nbxIY2JA23u2+JsVLea/GFaYFCsVgXxyzT1Iw 6Nmw== X-Gm-Message-State: AOAM531Jd8k65nbJAvqt5tEQYSkE4oZSWbY65Q3dE3lb6ZCSzfJO7zdM +OIAUPXrQ7hJPDMUSVqWSbE8JkND0RnOpIiI0V7H X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:c423:570b:b823:c33e]) (user=axelrasmussen job=sendgmr) by 2002:a0c:fcc8:: with SMTP id i8mr14211207qvq.31.1619563981243; Tue, 27 Apr 2021 15:53:01 -0700 (PDT) Date: Tue, 27 Apr 2021 15:52:41 -0700 In-Reply-To: <20210427225244.4326-1-axelrasmussen@google.com> Message-Id: <20210427225244.4326-8-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210427225244.4326-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog Subject: [PATCH v5 07/10] userfaultfd/selftests: use memfd_create for shmem test type From: Axel Rasmussen To: Alexander Viro , Andrea Arcangeli , Andrew Morton , Hugh Dickins , Jerome Glisse , Joe Perches , Lokesh Gidra , Mike Kravetz , Mike Rapoport , Peter Xu , Shaohua Li , Shuah Khan , Stephen Rothwell , Wang Qing Cc: linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Axel Rasmussen , Brian Geffon , "Dr . David Alan Gilbert" , Mina Almasry , Oliver Upton Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a preparatory commit. In the future, we want to be able to setup alias mappings for area_src and area_dst in the shmem test, like we do in the hugetlb_shared test. With a VMA obtained via mmap(MAP_ANONYMOUS | MAP_SHARED), it isn't clear how to do this. So, mmap() with an fd, so we can create alias mappings. Use memfd_create instead of actually passing in a tmpfs path like hugetlb does, since it's more convenient / simpler to run, and works just as well. Future commits will: 1. Setup the alias mappings. 2. Extend our tests to actually take advantage of this, to test new userfaultfd behavior being introduced in this series. Also, a small fix in the area we're changing: when the hugetlb setup fails in main(), pass in the right argv[] so we actually print out the hugetlb file path. Reviewed-by: Peter Xu Signed-off-by: Axel Rasmussen --- tools/testing/selftests/vm/userfaultfd.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index 6339aeaeeff8..fc40831f818f 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -85,6 +85,7 @@ static bool test_uffdio_wp = false; 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; @@ -277,8 +278,11 @@ static void shmem_release_pages(char *rel_area) static void shmem_allocate_area(void **alloc_area) { + unsigned long offset = + alloc_area == (void **)&area_src ? 0 : nr_pages * page_size; + *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_SHARED, -1, 0); + MAP_SHARED, shm_fd, offset); if (*alloc_area == MAP_FAILED) err("mmap of memfd failed"); } @@ -1448,6 +1452,16 @@ int main(int argc, char **argv) err("Open of %s failed", argv[4]); if (ftruncate(huge_fd, 0)) err("ftruncate %s to size 0 failed", argv[4]); + } else if (test_type == TEST_SHMEM) { + shm_fd = memfd_create(argv[0], 0); + if (shm_fd < 0) + err("memfd_create"); + if (ftruncate(shm_fd, nr_pages * page_size * 2)) + err("ftruncate"); + if (fallocate(shm_fd, + FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, + nr_pages * page_size * 2)) + err("fallocate"); } printf("nr_pages: %lu, nr_pages_per_cpu: %lu\n", nr_pages, nr_pages_per_cpu); -- 2.31.1.498.g6c1eba8ee3d-goog