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: 13194499 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 DAEB8C6FD1D for ; Thu, 30 Mar 2023 16:08:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73E626B009A; Thu, 30 Mar 2023 12:08:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EE0A900003; Thu, 30 Mar 2023 12:08:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5684A900002; Thu, 30 Mar 2023 12:08:15 -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 46A106B009A for ; Thu, 30 Mar 2023 12:08:15 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1110D1A0A83 for ; Thu, 30 Mar 2023 16:08:15 +0000 (UTC) X-FDA: 80626046550.18.E2BA5BF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id E67C0120029 for ; Thu, 30 Mar 2023 16:08:11 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IKHaQDFp; spf=pass (imf29.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.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=1680192492; 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=lYveN9kYI+AE0CuBqSxlkzyTIkRFNshZ9iE0ExlkrHo=; b=k/qyIzuAKLPBpyFW+nA0u2ymWtT2oPaNUWD0LGphJfZItGp/XroXCDY/qNCVBFYZrL8A5o vWR5QSzvhbbpS2mIdIERXX2CPHMy6H8mN1qMI4LoHhhR7PSxxYYptfHBkS2u03yRjwcCuP VGG9Z/UP+vrQWoCcRBu0OZi0ZWB6Dho= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IKHaQDFp; spf=pass (imf29.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.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=1680192492; a=rsa-sha256; cv=none; b=JlVFZN6DhPbKQUw+HxhCWV30PasTj2/Y0P0l7l7mpbjs4aqk4G4pvvY7wvNo3dB27Ls/Me 0lgws/KvFZfkfjlxSDlifFGMWNwGDMyZtiXNkDrCrR5yPIHlCDEMoF1wUWSyx2WJ7EgWnW imaMXyAPRaDesbhfioY+oK0NzNgUTXg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192491; 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=lYveN9kYI+AE0CuBqSxlkzyTIkRFNshZ9iE0ExlkrHo=; b=IKHaQDFpblHJsz3dbKnQRrDVfs24SCteyX8Z0R7IdcSBIaTd8JCzfqHvcSC5ryW7hL9o36 3EfLI53zbZu8rN5e83E+I3uYLRXFDVGCcxIPjpPcub83X8jKwKIWgwat6srWSNVbvCY4JH rx1dfSGdU8mCNehWLtyBfzJs8z7Laww= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-FOS8VbWgNRKP3r0VSt2mgw-1; Thu, 30 Mar 2023 12:08:09 -0400 X-MC-Unique: FOS8VbWgNRKP3r0VSt2mgw-1 Received: by mail-qt1-f200.google.com with SMTP id u1-20020a05622a198100b003e12a0467easo12705657qtc.11 for ; Thu, 30 Mar 2023 09:08:09 -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=vLJDv1mVi8hBjlSuzGegagQ7t8MLeruF9lZdDKtKF8puykRmE+dZFhEAOVRN/c+0Rh Vi70aGMVkdzBxMso48QX2OgSFJ8nnKnPhfOfrFiZqrdYtiAmL581gKFIQ1sKny85DWWY yuwzg/Ad3RqHlj+pvv7zExpFbHeb8BoF1Fvc1ircoS4u3wobr0eaJKjumOVJJvSytV6p y3+DaqgWUHvltP3EUT8HpXMHjNOhRRWuLpM8qeBYlLZu1ktt5F6NFvcWW5cC7w696Tnw XsjIL+os5CQW1DCZgzjFsUmL0HU4HtyuIVwI6kzuvZiLk8ktcHYsMFyPFNh39XEP7d96 2OJw== X-Gm-Message-State: AAQBX9d/9t0Kxcp6EHtqC2IhwnpD+dp9BHTFEmWzFI0WNtCANznSHrrB 0FtmL5wJfMnDSiqdQG69tInA2iITM3tr+SX440m3MxMCr9bSCPkTK506/mEV5OkrVUYO8GOU4T/ ekD1Hr8UlfX4= X-Received: by 2002:a05:6214:4005:b0:56c:d9e:c9a0 with SMTP id kd5-20020a056214400500b0056c0d9ec9a0mr3701330qvb.1.1680192489104; Thu, 30 Mar 2023 09:08:09 -0700 (PDT) X-Google-Smtp-Source: AKy350aTdkYANw/GA8UM9SuMd+jqJY9HVceHWacP5BOag5vY6hpxHhAdpkx3urUgNiYoPKaL8hSmQg== 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Stat-Signature: 1wu3rad1zkafuwcbzqxqwbymyj1i7uri X-Rspam-User: X-Rspamd-Queue-Id: E67C0120029 X-Rspamd-Server: rspam06 X-HE-Tag: 1680192491-186102 X-HE-Meta: U2FsdGVkX1+vRe1UMxZR/cUxzcbN8pbLfkK240jiurrMda/hH9YTNIOtHcnNpeuWgDwzRqzfnhcroVOaCjg4TB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SNE5K08DTmZE++T9MNAuAyvDtD1+a2goMLWm25Li9dyphgnrDcYemOe8xuSKnhUIQuS12cJE3kqccRyxigVqxsCnk/XjpmgzvlT3Ee4cQWV+CRHS00cBtAyETOOL5V/CU03slx84WKE1WQHSG3jC2ICqdrsfGaHXbJwUvwcT+D+UnHAP92iWXRZEIoYfciyqhP3waQmK1wQkS/o8yoAoSSTyNeoEaB4kZVI2CgwI/GmjjFGgrlwGAGHcn61VGxZAA2crpvQionUT7A1MveVFw8d6EeTEBxyqGQ8V9g69C6saQWi7GzeV3oAWqk90aAlpyT0cZOvkeRsv7S4IOV/3tVoKwDGIMi/ZWk6+0+es1EU= 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. 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();