From patchwork Wed Apr 12 16:43:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209353 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 767CAC7619A for ; Wed, 12 Apr 2023 16:43:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12CA0900005; Wed, 12 Apr 2023 12:43:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DD67900003; Wed, 12 Apr 2023 12:43:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE712900005; Wed, 12 Apr 2023 12:43:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E0370900003 for ; Wed, 12 Apr 2023 12:43:38 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 811B21C3677 for ; Wed, 12 Apr 2023 16:43:38 +0000 (UTC) X-FDA: 80673310116.02.CFBDABC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 65AD74000E for ; Wed, 12 Apr 2023 16:43:36 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ss9IfbrG; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681317816; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mjojpcmOEAy9sHKJxFBhh1D6ilVghlmR8goVSOpVaAo=; b=I7/kWRYP5UQO05kkDpowFIMnoZxNPxHFsnca9L6RTtMKjGp3TlkaLnBbMgEJygi97CVEvB bI8dR4VMDmIg2F8x9Ai3OV+PidhhJMKxoOsqVo5na5YwP2F61LypiGpUtiPfaWxdJEmwqb 6obUp5x1XBKUoDlRZx/0Wd5/IxkbuQo= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ss9IfbrG; spf=pass (imf04.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681317816; a=rsa-sha256; cv=none; b=u7QL2w9Plfvc5ly+bZ4PMzwA/Ajfh/HO6Dw/JB0l9NlCkNdIMRGHSZr1ryNtIiEPQs4UfK qD9x1Wa0pLn3aL+Rxzbr45fnvDQJv6U3xuJABNzSDrWuoQw4h1iLG5cChCCJG+X6lSB7C0 7WpsgSAUhzVWuko7yuhimO54jAmqplY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317815; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mjojpcmOEAy9sHKJxFBhh1D6ilVghlmR8goVSOpVaAo=; b=Ss9IfbrGYFTqiR1+aWetUFv6pg22B8yNmEIFF+foz3OwAhdrUAMuhLyG2kV+bDQR7y/rS7 ORKgl8Tki2wGg+dBNFWGGCaoq3aNGXP+5d88yMcLqsmMkbIiWLQQ16GWyAxmKJJThST1qk UnuVaxvfmKhfPP0yL2CQbofQ+ZPRDFg= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-213-SHqHvRbrP7KoshbGaJJr0w-1; Wed, 12 Apr 2023 12:43:34 -0400 X-MC-Unique: SHqHvRbrP7KoshbGaJJr0w-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-74a90355636so62126185a.0 for ; Wed, 12 Apr 2023 09:43:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317814; x=1683909814; 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=mjojpcmOEAy9sHKJxFBhh1D6ilVghlmR8goVSOpVaAo=; b=eU+QhTFWEwLpn2LuETLHsEOHPAOxNtUT6bBhhRVBmNZI5kKuNEIse7/f1ow/xoIGLv Cz0SNgAAdmxMkY7r+MeIpXEo1HZZ6pAKmsx6LO76WRJv9gAkpqJbzY/gjX3QTOfOakpn CXDDrgoos5bQ7XYwecyRwwY1acSGI9fHEb5dw5t48gV1+2IQnj+CjXdJXKCvFGKbupVX My61cTMjmoamn+zxbjAfXCshBY57ynBc4++HKqgY7QWbP3q+p0+JYmRpLRSqO8QPIWOP n5fwHEmGr4b6GCx+bCFR00Un/Sy3kTgBCFidKQ3EbBVJHuhz2reLsO0LomWw/BDyxomk sX4Q== X-Gm-Message-State: AAQBX9dAlYxkrLu/Cecbmno0VLtZNz5iJ7ll3K6z6ve65zsEXU1yhhRc G4d7p7c9k7IiKSWhIu6F1vBbXr2Yq1tkf7m2tKyuph5wTSkdnLFOsNxJOzVjdvzm57jw1x2N5nh MdelznkSM6Re16K9b3Vk= X-Received: by 2002:a05:6214:4009:b0:5ac:325c:a28f with SMTP id kd9-20020a056214400900b005ac325ca28fmr28040721qvb.0.1681317813755; Wed, 12 Apr 2023 09:43:33 -0700 (PDT) X-Google-Smtp-Source: AKy350aCRUYX9XSVZcq8LYLtGSnSwVz7FM081yXsn58IDzHk0UjUVjNJXSLp/S7y3S1wvu+8J1/rtQ== X-Received: by 2002:a05:6214:4009:b0:5ac:325c:a28f with SMTP id kd9-20020a056214400900b005ac325ca28fmr28040704qvb.0.1681317813518; Wed, 12 Apr 2023 09:43:33 -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 k16-20020a05621414f000b005eea9d3137fsm1749862qvw.134.2023.04.12.09.43.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:43:32 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Hildenbrand , Andrew Morton , Leonardo Bras Soares Passos , peterx@redhat.com, Andrea Arcangeli , Nadav Amit , Mike Rapoport , Axel Rasmussen , Mike Kravetz , Mike Rapoport Subject: [PATCH v2 17/31] selftests/mm: Drop global mem_fd in uffd tests Date: Wed, 12 Apr 2023 12:43:31 -0400 Message-Id: <20230412164331.328584-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: 6jy6npaomjwgccrzw94f9ihdqzywp6dc X-Rspam-User: X-Rspamd-Queue-Id: 65AD74000E X-Rspamd-Server: rspam06 X-HE-Tag: 1681317816-510826 X-HE-Meta: U2FsdGVkX1/5EhrarZVGc3KzqDxJ07v9yq5u+c+FJblcZfh5CJMI/iKqflZTqnySL4hkr3vZ/dp1/WwK1/v0VC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yROv29uTBlp6qElKMMdl+FWTMe2a+gw1/DWk2vwl2ePMDiKdGdl8NPRUw/LZYK46smUBFGdICVPUYdOx6lI/zbARnbWihVYOIJPjaE2T/BKFrB0+G7gyKpoOnE+EjxbQ60pXbP2wv9iNwmFtCp4ktzBAyN7l6S60NK/x5nsOjKvsrgnIIgzizGniS+iTeAFAXuiupZ0zPBa4Zs4OW4jyc6yrI4LiUDfJPQDjRqENM8Q1WpY+hN2tGCOV/hROLeOw9hC1OCDkMW1+nLbyh1sbMOvhzrhYBDLqzH7jd0VeRJOGBwPOY7UqFey4+9qXDCA7slrhD+UhGQ+gEmcvn6+5gvmJJvvkT6dhMfpmv+c+o99QcIzsXU2+/gfm9DxKZysZV+xbL2W8GbmFWa1Kx2ukV2m1WQCpnbdpItQ= 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: Drop it by creating the memfd dynamically in the tests. Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- 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 09ea24c5f02c..b1617f5d4517 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();