Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2439612pxb; Tue, 13 Apr 2021 01:44:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWuNyNXbge/FizftChLrVSvncb+6DLFr24PiUpBhg868b5pLCJQOqPyb+wpLK7BtFMMYv9 X-Received: by 2002:a17:90a:5884:: with SMTP id j4mr3871771pji.33.1618303448331; Tue, 13 Apr 2021 01:44:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618303448; cv=none; d=google.com; s=arc-20160816; b=orJVd0MjnF1s+J5PrueDRCtCRV+267tfgUaD6aO9STkN+OfaozV2eB7PMAMOO3zRCF n+VuZxCFKqJYbRmvkoK2ShRRpf4+pAALu3wZNoyYOpPEa6VV7FVFzZBx1Luty4O8zGb7 5OaTSTsRoKy8e7v8LWth7OuQDbofkoZsTgZl+CBGdJg9KKgLZKa1cY4Cfb9I10mWsfG6 WG7IvRwCTHXiHCRwrlaxeL+7YPYrKMgiqKYungALlyYGecrLCQkdrbMbAOAxIPtP6ACs 1wsPxWqJ0kZuVoOhhW55I7XmzI0pa+JK4doN/VNbhjzsWuafUoy5h2sS4GshKJFo76oi xVJw== 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=ArLA7VCb9t489S2A8vdExWcG4gs0ZfEI51msDdZxM/g=; b=WWOIFqNU+MtE/sTvKnZVN/dB5Wgz3ABIFqItql0BOLTIP97237xdVuKlHSHl/cPQR0 3HLVsa6w/aG470BygZJw9VE2/R+qmHHn/8mylIwpC6iBP9Nec+zKYosDg6IQrXfKju/S ZNlDn/i7dteC+FZd6M5H5+kr3P0xln1H9DMIUyZZh2i3CxdcGt7LmytI+m8k0ry9tZGk ez4uYhJ08WXFg0KSxEXu/09A1RSaR4zq+sKvCWNaeUwd89t8Ev75YLyT+psx4N/9dhY7 X8b/nFzdMlTtSQDXV/2ob+SlgzbN4LqYmIfWJi8kCeiNUVw0qlpt16ML4kT0d+Xpkaee 3h4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=UgWXUdE3; 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 q21si1521594pfk.214.2021.04.13.01.43.55; Tue, 13 Apr 2021 01:44:08 -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=UgWXUdE3; 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 S243601AbhDMFSS (ORCPT + 99 others); Tue, 13 Apr 2021 01:18:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344479AbhDMFR7 (ORCPT ); Tue, 13 Apr 2021 01:17:59 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F394DC06134B for ; Mon, 12 Apr 2021 22:17:34 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id p68so8323453ybg.20 for ; Mon, 12 Apr 2021 22:17:34 -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=ArLA7VCb9t489S2A8vdExWcG4gs0ZfEI51msDdZxM/g=; b=UgWXUdE3GefvJEVOqa3TKqXsCgsdMGB3WMQdPFhHnZNIV4qJbriENFW22vE65M82He mBTniwEzW2nTjKQg/dmE56u1lM/vARivE/L7BvQtuFTFR6uaTv736jDv757nPHvgeDe3 7SHXcFpeL/F9bay6OBw69RxJIJ3xPTBds5lbPHPa8aR5ovSQap6xtDaji4xiyQW4nNmC jTTCQK0OCZ39nqsb+PtWmiZnS6stOKExryQwdkAeqMdCgV8c+c+R2j/inFG+grv1Po0U KcUJa0HXgn9nr9X1nmqdc6VHP5spZiWd+jDktD8UXCBRYU2idpI5VJvnKNg4tQHzryLI 6ZPw== 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=ArLA7VCb9t489S2A8vdExWcG4gs0ZfEI51msDdZxM/g=; b=dWfJkg4LBegftIljycQy0wGXhbmQEFpERTK1lX0lsH3Uysb2Ll0O3mH31xF3GQgOuT /mM5LYHi8sP/17Z5BHAcTQLaY9S8umh/gb+5vyw8pVBHJAC3R6inVEwdBtTFNKmR0SiR nDK3lyHhnbTTkJQ5pa1GT0w1yI3OU1dmfL5PzkOvclbFBQ/hUu7G5N3tH7Wk13n4XbZE lQAk8BVnakHy9KdeKeu/8w81Ioqak/M2/s5igGkFPuswivJ5M+suTovR0UHePdbMBCKk oUx8usKAYT5nGCEhQdrIEpptwhJv5P5NEkCDc1k2/SOXYa4hu9mo1KhL8F+iOYMXkTST HwYg== X-Gm-Message-State: AOAM531PVGrIuipu+g7+VdNw9bFaiQ1HYwmNzTIAUWrD25INIEkh24Tt HSd6Ju/9yRatBnYIrXMvyfkNSadNOA1cKm0Mq5Fk X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:d508:eee5:2d57:3e32]) (user=axelrasmussen job=sendgmr) by 2002:a25:e6c7:: with SMTP id d190mr10780764ybh.394.1618291054231; Mon, 12 Apr 2021 22:17:34 -0700 (PDT) Date: Mon, 12 Apr 2021 22:17:17 -0700 In-Reply-To: <20210413051721.2896915-1-axelrasmussen@google.com> Message-Id: <20210413051721.2896915-6-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210413051721.2896915-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.31.1.295.g9ea45b61b8-goog Subject: [PATCH v2 5/9] 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. 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.295.g9ea45b61b8-goog