Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp151898pxy; Tue, 20 Apr 2021 15:12:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylqvcB6ccaEymJUmMX1lgyYNaXD7UjvKGoABr3l2w1u/EfjDLuupe2bK0d8oLjCh64fvmL X-Received: by 2002:a17:906:68da:: with SMTP id y26mr30276054ejr.442.1618956724152; Tue, 20 Apr 2021 15:12:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618956724; cv=none; d=google.com; s=arc-20160816; b=0MJIav9QeFiQm1XU2pdRcCdY32vrl2BXKFa1QReO9WzoLnlfj3XdAFI6zZgNGz06ma eIooI2ZFd8mU/W+9H5jQzeeDvm1hULVreLI3SrZ7izTtQT2Rv0ZdMJuwIRWlK92ADGdP FcuQQVhOb/MjiY30uM57eRvCkftmhvWMIw3lf85Ow+RJRQX4z8/TiIbBolzrYMbyHuIK YC+dFw2gauw9Yfy4mWLyNwGwYf/4zb01/SKZDcDnmc5QLXHHPoLQAyHPC3mr4sEucmrC Wjckzdl11uPBR1yRzhZ3oyAy5jO54d4N8ruD970zybCQZV00GrY1Ariijq+0QgONldgI DSaA== 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=q0uullLY89k5tjNP5bU3tD7YqwSbU41Jf2SRzlEhX2Q=; b=en9Xj4hodFcNozt0+Ex4+gJO+rafmZPn7fPNFtlw9YFuUrRG/m5xFJ528EEgQeJweO 8MzG4Y9w6SNMVJQMRvX2e5/+csO9tlngbbKOPBubnxAMFi2hvwhLstcvmfAnFzHDSuk4 ZffPamq897OY8zr8g7C+XTiWbEDyD3eEbeK0Z+xKLfHFcx3Jjfo41uprQKJpuhaOh/2F sgy2j/H2hr6154oUzw0hfPabNonttfJRljscpgLtYHfPryyx07bGMNBNjeJjjrt33Cf8 /lxxQq0Axn3OhxFsViVhkZMww2tjVlB1YbUjSL0HQl9JSXi+mAYRtyvOFNPUVnrfcnsw tJFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=sDY5fiUu; 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 dt12si86123ejb.115.2021.04.20.15.11.39; Tue, 20 Apr 2021 15:12:04 -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=sDY5fiUu; 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 S234268AbhDTWKw (ORCPT + 99 others); Tue, 20 Apr 2021 18:10:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234269AbhDTWIw (ORCPT ); Tue, 20 Apr 2021 18:08:52 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4ACCC06138D for ; Tue, 20 Apr 2021 15:08:18 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 135-20020a25048d0000b02904e4ed8b411bso13597244ybe.20 for ; Tue, 20 Apr 2021 15:08:18 -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=q0uullLY89k5tjNP5bU3tD7YqwSbU41Jf2SRzlEhX2Q=; b=sDY5fiUuvC0Rx6q5+VtW2pUXtXPN28Dpcq442NoR4o5Q7ncPbrml5nRuyZyd2xyYJO zduDulUJHI6EWSx9HKsTUErWdKEUuFYZr+xR9rJNfE/H6mkaRUzEAjms+9w6kvxskGj1 Nur1rZu+ynGqrWgwuUXixlMLcKGLtjKwC07MFESZpxI3GRbWslF6J9bleAcqYL/P3N0L ZVDSqYoudAuN+pF5eP6HhajJbpFGdoc4dcwVz8YQcclCijhrbExCMgqfkGczNNfmjgwI IH7UY9zoBuqr4U01GJqpSd7amvWJNhrFWpBlHU26toc+qlCBox4xow+ryia3+5CyH0zV a8lA== 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=q0uullLY89k5tjNP5bU3tD7YqwSbU41Jf2SRzlEhX2Q=; b=SMRYcl3rjIbNyPlDSWvTp2TkCAaAhUR1RsQWljcF40iYbePjUKln7sd9pnnvCkIAeI JG/Q1XL7bb2b8MVx8+nKP+0OBf9rsP9sRm2i/mSdrVCaIi/jE65QUBMGEJ0ozk5MScjj BN9lbcBX8Sngh4J0hmDZ/NZBYM7LUWJjWqH8Gs46zCV/8ynEhC7ZmW+zfzp3Nf/RiSVn ttEpVyTgYOXlgLbgDfAr/BPjWyayadU6onVFrFcjtOY1Tf/H2MalhktXq/ISt6ymnWLc G/1Zps/RLwTWbCVOMlG44sYajwgojf1T+LYS/KR491GYtmlHwY/fqJcr0k4OS2mkn0UN Z7hA== X-Gm-Message-State: AOAM533BrEsVTS9Z24yMtYwXafFY2HxgNW5JHHzjk82VMfGHfyVvcgC8 jFLiVROEsAe0N2/lmzdsJvqapc1sB3lCrBQjFisN X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:c40e:ee2c:2ab8:257a]) (user=axelrasmussen job=sendgmr) by 2002:a25:b983:: with SMTP id r3mr28386146ybg.238.1618956497914; Tue, 20 Apr 2021 15:08:17 -0700 (PDT) Date: Tue, 20 Apr 2021 15:07:59 -0700 In-Reply-To: <20210420220804.486803-1-axelrasmussen@google.com> Message-Id: <20210420220804.486803-6-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210420220804.486803-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog Subject: [PATCH v4 05/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.368.gbe11c130af-goog