From patchwork Thu Mar 30 16:08:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 77299 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1251421vqo; Thu, 30 Mar 2023 09:23:37 -0700 (PDT) X-Google-Smtp-Source: AKy350ZebEEP+pdln+pHjGX3Tk9NyJxQDjEuz5RTZwVs5f1ZqqyXwq9Eb4HZ1s95OekRWmSJ8VDM X-Received: by 2002:a17:903:6c5:b0:19d:778:ff5 with SMTP id kj5-20020a17090306c500b0019d07780ff5mr21897945plb.15.1680193417237; Thu, 30 Mar 2023 09:23:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680193417; cv=none; d=google.com; s=arc-20160816; b=U6dokhJy/MFnnYT3lzoNODFahD1im1UKSWx1Z7ALERU76xLQxnFrDKbpqLwwNAOfxz VxHtiwxVKibTz2YgQmScESo8jZK+rWAwQqZ7GoGWzqfNcKYv73Uwu7klGUtGHfTkl/am KMHjPJnZSLHi4bbdZ6DH57fH55YG35JnPl6x0xpXgaBgGrnaTAsPvc4JzYFS+sSeBxTe tptq8qIi/0iOASK3dN9IhNVaxXdxbtkx8TJ+ujEpHN/fCXTw6nI9W/wRrac/irADC4CU 1sC0t/aKbJvJcangguVLB4WyoYpezzG3JH/YHlXtbQyWd5OLD63SDOAscuz0DSqo7vba 69sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lYveN9kYI+AE0CuBqSxlkzyTIkRFNshZ9iE0ExlkrHo=; b=X4PqnMUQL5wD3oHCX/An4ojT47jl+/fovy3zmeHBNQYkZnP/0DyjmTNNWdNJJYNBav SAmHBLcz/9eW3yNCZMW7Hm/DlMDJ65FwK2VCHn8Mf8+bFXjpvby8Fws7FzYH8YAgHPLe Gip6hnEy9zUI238YIfD7+j4wgqVtft2IIqThwjH+p7ub8IpP/6f/tqVPU2tPAc2P/Uoq Sg3T3Y01mlQ13bJMHgO3PrfZu/aceG/zgI7VXF6NJ/TNnBCbp+4C0k03UIs0iWs2wq0Z BLQPRqDGaU/yIfCl1XMkrUPgSBi5nSI+jD2eZI2/tHZXB1cdov1/flASzhSaaVkg8BMp rmGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eQRu5bWa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b12-20020a170902d88c00b001a220a984f9si13970235plz.546.2023.03.30.09.23.21; Thu, 30 Mar 2023 09:23:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eQRu5bWa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229609AbjC3QJm (ORCPT + 99 others); Thu, 30 Mar 2023 12:09:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232010AbjC3QJZ (ORCPT ); Thu, 30 Mar 2023 12:09:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B9B3D32E for ; Thu, 30 Mar 2023 09:08:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192492; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lYveN9kYI+AE0CuBqSxlkzyTIkRFNshZ9iE0ExlkrHo=; b=eQRu5bWaFjcdN08/IhsDIeE4uWoLMiMRDyk/z31AxtJKFDPm7F7DmMIFZi9xHzI29VVC7u 0zP9/GRE33UdT7i9e110PySv0PnA2j2+0V3mG2BLEHNqD2AAsMFC74uK7uIB3CXPFGpxdK JotC3of7xV5OhojbsbN+YkTgS/3wKok= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-474-bC1EW9GVNo-k5HgQypLCNQ-1; Thu, 30 Mar 2023 12:08:10 -0400 X-MC-Unique: bC1EW9GVNo-k5HgQypLCNQ-1 Received: by mail-qt1-f197.google.com with SMTP id b11-20020ac87fcb000000b003e37d72d532so12708542qtk.18 for ; Thu, 30 Mar 2023 09:08:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192489; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lYveN9kYI+AE0CuBqSxlkzyTIkRFNshZ9iE0ExlkrHo=; b=6XUA39pzDaarttByQdil8sROGUzD5cfka89pNWKY3PbVnpqdWDJnK4v9QExU8gpsrn 4FKT38VqYJmhWBKojutOLcuSYU0Cv82InchXyw8X1a/pnVTGgoIsWWnabYIzn6pOOQIb ZZNdZhjG7OlSe1rvJA2vcT2BgN+6V/ouXCYRhLvtIl/qOUScw0sasmRLrReHHcxNCNU3 UNnrWsQaLEVZ9QfLV5ojwmlK/unSLSOkemZG70VJvkhb7sAjQyq7kY4hBvnqJw8kpAwR La0HeFOH78bNYmwOZt2JP/rnUYoEkeaVXGhG2UfHZNNh2ZdiodrLiv4hQqw/BuXh8FBH X2kA== X-Gm-Message-State: AAQBX9dN2zNjlNxSdjN4DZ0bQ4DJTPi6ccg0PRlw4KZzlGXgEcqVmF25 9EDQuEVzwaz6uHVAyow3efCF5FqM3xytHJWHRmRYw0yljp3PZv62uHADPhsU/6KpfMAsrcVOS/J uX+2oStrnnWoWwtNznLXUvS/6TCtwjGMh4POMwMWmoGmT53KxQgiAfA2nxISvhBGJG1mTBWYzRz FK1MD11A== X-Received: by 2002:a05:6214:4005:b0:56c:d9e:c9a0 with SMTP id kd5-20020a056214400500b0056c0d9ec9a0mr3701343qvb.1.1680192489198; Thu, 30 Mar 2023 09:08:09 -0700 (PDT) X-Received: by 2002:a05:6214:4005:b0:56c:d9e:c9a0 with SMTP id kd5-20020a056214400500b0056c0d9ec9a0mr3701286qvb.1.1680192488771; Thu, 30 Mar 2023 09:08:08 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id m12-20020ad44a0c000000b005dd8b93456dsm5504054qvz.5.2023.03.30.09.08.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:08:08 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Leonardo Bras Soares Passos , Andrew Morton , David Hildenbrand , Axel Rasmussen , Nadav Amit Subject: [PATCH 17/29] selftests/mm: Drop global mem_fd in uffd tests Date: Thu, 30 Mar 2023 12:08:06 -0400 Message-Id: <20230330160806.3107497-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761810493145134631?= X-GMAIL-MSGID: =?utf-8?q?1761810493145134631?= Drop it by creating the memfd dynamically in the tests. Signed-off-by: Peter Xu Reviewed-by: Mike Rapoport (IBM) --- tools/testing/selftests/mm/uffd-common.c | 28 +++++++++++++++++++++++- tools/testing/selftests/mm/uffd-common.h | 2 +- tools/testing/selftests/mm/uffd-stress.c | 15 ------------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index 3a9b5c1aca9d..a2b6e4957d0f 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -12,12 +12,32 @@ volatile bool test_uffdio_copy_eexist = true; unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size, hpage_size; char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap; -int mem_fd, uffd = -1, uffd_flags, finished, *pipefd, test_type; +int uffd = -1, uffd_flags, finished, *pipefd, test_type; bool map_shared, test_collapse, test_dev_userfaultfd; bool test_uffdio_wp = true, test_uffdio_minor = false; unsigned long long *count_verify; uffd_test_ops_t *uffd_test_ops; +static int uffd_mem_fd_create(off_t mem_size, bool hugetlb) +{ + unsigned int memfd_flags = 0; + int mem_fd; + + if (hugetlb) + memfd_flags = MFD_HUGETLB; + mem_fd = memfd_create("uffd-test", memfd_flags); + if (mem_fd < 0) + err("memfd_create"); + if (ftruncate(mem_fd, mem_size)) + err("ftruncate"); + if (fallocate(mem_fd, + FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, + mem_size)) + err("fallocate"); + + return mem_fd; +} + static void anon_release_pages(char *rel_area) { if (madvise(rel_area, nr_pages * page_size, MADV_DONTNEED)) @@ -51,6 +71,7 @@ static void hugetlb_allocate_area(void **alloc_area, bool is_src) off_t offset = is_src ? 0 : size; void *area_alias = NULL; char **alloc_area_alias; + int mem_fd = uffd_mem_fd_create(size * 2, true); *alloc_area = mmap(NULL, size, PROT_READ | PROT_WRITE, (map_shared ? MAP_SHARED : MAP_PRIVATE) | @@ -73,6 +94,8 @@ static void hugetlb_allocate_area(void **alloc_area, bool is_src) } if (area_alias) *alloc_area_alias = area_alias; + + close(mem_fd); } static void hugetlb_alias_mapping(__u64 *start, size_t len, unsigned long offset) @@ -95,6 +118,7 @@ static void shmem_allocate_area(void **alloc_area, bool is_src) size_t bytes = nr_pages * page_size; unsigned long offset = is_src ? 0 : bytes; char *p = NULL, *p_alias = NULL; + int mem_fd = uffd_mem_fd_create(bytes * 2, false); if (test_collapse) { p = BASE_PMD_ADDR; @@ -124,6 +148,8 @@ static void shmem_allocate_area(void **alloc_area, bool is_src) area_src_alias = area_alias; else area_dst_alias = area_alias; + + close(mem_fd); } static void shmem_alias_mapping(__u64 *start, size_t len, unsigned long offset) diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index 11f770391bd9..0dfab7057295 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -87,7 +87,7 @@ typedef struct uffd_test_ops uffd_test_ops_t; extern unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size, hpage_size; extern char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap; -extern int mem_fd, uffd, uffd_flags, finished, *pipefd, test_type; +extern int uffd, uffd_flags, finished, *pipefd, test_type; extern bool map_shared, test_collapse, test_dev_userfaultfd; extern bool test_uffdio_wp, test_uffdio_minor; extern unsigned long long *count_verify; diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index e6d39a755082..4eca1a0276c2 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -1090,21 +1090,6 @@ int main(int argc, char **argv) } nr_pages = nr_pages_per_cpu * nr_cpus; - if (test_type == TEST_SHMEM || test_type == TEST_HUGETLB) { - unsigned int memfd_flags = 0; - - if (test_type == TEST_HUGETLB) - memfd_flags = MFD_HUGETLB; - mem_fd = memfd_create(argv[0], memfd_flags); - if (mem_fd < 0) - err("memfd_create"); - if (ftruncate(mem_fd, nr_pages * page_size * 2)) - err("ftruncate"); - if (fallocate(mem_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); return userfaultfd_stress();