From patchwork Thu Mar 30 16:07:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13194490 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 EC758C6FD1D for ; Thu, 30 Mar 2023 16:07:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C71886B0082; Thu, 30 Mar 2023 12:07:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C20666B0083; Thu, 30 Mar 2023 12:07:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A72676B0085; Thu, 30 Mar 2023 12:07:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 92C866B0082 for ; Thu, 30 Mar 2023 12:07:20 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 58495A096A for ; Thu, 30 Mar 2023 16:07:20 +0000 (UTC) X-FDA: 80626044240.16.6D4E2CE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 01B60A0027 for ; Thu, 30 Mar 2023 16:07:16 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LPaGa3de; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192437; 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=GWrLladF+2uMEiKA8QDU9N/tbvqlj2DcoX5RP21NYpg=; b=ps5DfwdtpPtdrwSaiYvIbdyEqG8IDf3hrTVwWC03/VPMlhk+8UiobnVqYkEeLD0ncE8UJL OVfvQI6Sv53WBgkPKGpG2TGYRSHlrOgMlZAZ1uzVNGf/hX2Jwr/L7yk46rzklarDRwr1z2 qhyCVy3xdjZnLD0sThJMc35WZBBzahg= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LPaGa3de; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192437; a=rsa-sha256; cv=none; b=NjwRTe8WuJPogfWKntr6bwdUM/OJhcQm4VnGHx8MISZYUOam9Z/B2z3GLgpsSUUWhMjs6n 4qMMSnAQiAx9ggzEjT0M0wmEvvoU0b+zRcULSfESsPU9zawtclI3Cy+tk0BVOYmySzRSmY 5j9/Wbo6Tp3agEKWN+CJJnlMTj2/aAU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192436; 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=GWrLladF+2uMEiKA8QDU9N/tbvqlj2DcoX5RP21NYpg=; b=LPaGa3de5lR1fHs+zZEfPitm/BAEp3UBGBw2P5Heez/A8LOayumVpekFKVBqDfxCxoSf4/ L4TIyhrIVy6Yj9tK8Gn4ODNEDcgc+IDr5+gE1I28+yprJ0XjudLXR1PJMso9nILwQWf3hG F2fxr3pQ3SOLHdxD2Nd14RBSOVkF+DE= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-yv-YAHyFOaW-cW2y8zYFuA-1; Thu, 30 Mar 2023 12:07:15 -0400 X-MC-Unique: yv-YAHyFOaW-cW2y8zYFuA-1 Received: by mail-qt1-f199.google.com with SMTP id v7-20020a05622a188700b003e0e27bbc2eso12710363qtc.8 for ; Thu, 30 Mar 2023 09:07:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192432; x=1682784432; 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=GWrLladF+2uMEiKA8QDU9N/tbvqlj2DcoX5RP21NYpg=; b=pw2MrJSPblTg5RETCajJoHN5hHOhWu+mDQvDI4cb1r1qxdhC2c0SDruMBLjQH3ju3H ZNMdQh+pD+Dhglv5kMvfV1wgzrU1+jRh5+RNqdnQ1MZb+VuM0e4V5GdGF2qhi5jmOmbZ tZGM2GIiXD3ectgpjTs8R9WAN/Sz7zDGiN4k2+aBprAVsh+LNt7p159f4F3pyUAIpqd1 5uZDJe9NOsWfTT/1astg99qrxCajeGd8NcZEsbKvWbwbroVT1SUBvnNesIV/TitLG7KZ pv2o/TUHilfynpMyawmmxsWDf99lmKcyHUu1uQr1B/kgyjLjfE93gBBt+W5gFyiS7Aac jQhQ== X-Gm-Message-State: AO0yUKXlbC7AVAmG9RSVjEP6CH+s5iD0vlvt5bEbIV7tX5jb+11PH+4T eZCnBa7nhsuJVEvzEvIw2624BqZKLy+4iz1qda1VryZ+ko9/2bYTXXNdzX6COPdbdjrF7khc8DC /dC3DU9Zab0/XWXzHlSzgnBkMBSS46iKvss7CaKowPIhPEHjiCfB9LfLma3Korv0HH17f X-Received: by 2002:a05:622a:1886:b0:3d1:16f4:ae58 with SMTP id v6-20020a05622a188600b003d116f4ae58mr37195482qtc.2.1680192431693; Thu, 30 Mar 2023 09:07:11 -0700 (PDT) X-Google-Smtp-Source: AK7set8GQWWP5A2SWociPwDs+/krj5i0TiQOKiGvePWsmn+f7FgX8FsfyTl2mFFLsw0jAZRNZOJYbg== X-Received: by 2002:a05:622a:1886:b0:3d1:16f4:ae58 with SMTP id v6-20020a05622a188600b003d116f4ae58mr37195424qtc.2.1680192431235; Thu, 30 Mar 2023 09:07:11 -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 12-20020a370b0c000000b0074680682acdsm14989583qkl.76.2023.03.30.09.07.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:07:10 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen , Mike Kravetz , Leonardo Bras Soares Passos , Mike Rapoport , Nadav Amit Subject: [PATCH 08/29] selftests/mm: Use PM_* macros in vm_utils.h Date: Thu, 30 Mar 2023 12:07:08 -0400 Message-Id: <20230330160708.3106977-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-Rspamd-Queue-Id: 01B60A0027 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: qknbx1xkxt8jhy9ki5tg7sybt7ffr7p1 X-HE-Tag: 1680192436-417943 X-HE-Meta: U2FsdGVkX18oBbd5aYc4tvO0UQPKG2REhXsll4slG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lJwhMJA71stB2JGpve4jtB8TMhnARFONUAagYrhk+6Ef28C/v2uGSl8V+WNml0RYMn367VX0xmF9aUpd/oZeq31CkhUlkHMQ0CIjSFmDMozch9W0biOBVZwHSq4ewENCCchkd1d8M0nlLMV81zgSHL+dQlS3ln8we93drhzRmXYF9W3NnpR/FSPwcAwbdT69xtAhIqvxgbY9IgHYsdjH9686ZSITJq7qTT+X3/LO59XC+xWlzgVJPomGeOC3Dc/q78s1VA+4DUD2d7YnJ9vs4DsqjNGvx3u3DK2C/tb6AhD9CUKYo31GyAtv7jraHecsYg2MbGunXuoNaYYo2w69y1qHkAQLeDV0yFTEEzzIGwE/55AT+T1LEEnGRxNxPug= 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: We've got the macros in uffd-stress.c, move it over and use it in vm_util.h. Signed-off-by: Peter Xu Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) --- tools/testing/selftests/mm/userfaultfd.c | 8 -------- tools/testing/selftests/mm/vm_util.c | 16 ++++------------ tools/testing/selftests/mm/vm_util.h | 8 ++++++++ 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/mm/userfaultfd.c b/tools/testing/selftests/mm/userfaultfd.c index 4cc80a0e8955..7e841f7e2884 100644 --- a/tools/testing/selftests/mm/userfaultfd.c +++ b/tools/testing/selftests/mm/userfaultfd.c @@ -1389,14 +1389,6 @@ static int userfaultfd_minor_test(void) return stats.missing_faults != 0 || stats.minor_faults != nr_pages; } -#define BIT_ULL(nr) (1ULL << (nr)) -#define PM_SOFT_DIRTY BIT_ULL(55) -#define PM_MMAP_EXCLUSIVE BIT_ULL(56) -#define PM_UFFD_WP BIT_ULL(57) -#define PM_FILE BIT_ULL(61) -#define PM_SWAP BIT_ULL(62) -#define PM_PRESENT BIT_ULL(63) - static int pagemap_open(void) { int fd = open("/proc/self/pagemap", O_RDONLY); diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 12dc654b5be3..8e9da621764a 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -25,25 +25,17 @@ uint64_t pagemap_get_entry(int fd, char *start) bool pagemap_is_softdirty(int fd, char *start) { - uint64_t entry = pagemap_get_entry(fd, start); - - // Check if dirty bit (55th bit) is set - return entry & 0x0080000000000000ull; + return pagemap_get_entry(fd, start) & PM_SOFT_DIRTY; } bool pagemap_is_swapped(int fd, char *start) { - uint64_t entry = pagemap_get_entry(fd, start); - - return entry & 0x4000000000000000ull; + return pagemap_get_entry(fd, start) & PM_SWAP; } bool pagemap_is_populated(int fd, char *start) { - uint64_t entry = pagemap_get_entry(fd, start); - - /* Present or swapped. */ - return entry & 0xc000000000000000ull; + return pagemap_get_entry(fd, start) & (PM_PRESENT | PM_SWAP); } unsigned long pagemap_get_pfn(int fd, char *start) @@ -51,7 +43,7 @@ unsigned long pagemap_get_pfn(int fd, char *start) uint64_t entry = pagemap_get_entry(fd, start); /* If present (63th bit), PFN is at bit 0 -- 54. */ - if (entry & 0x8000000000000000ull) + if (entry & PM_PRESENT) return entry & 0x007fffffffffffffull; return -1ul; } diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index d7163fff8fb7..d9fadddb5c69 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -6,6 +6,14 @@ #include /* ffsl() */ #include /* _SC_PAGESIZE */ +#define BIT_ULL(nr) (1ULL << (nr)) +#define PM_SOFT_DIRTY BIT_ULL(55) +#define PM_MMAP_EXCLUSIVE BIT_ULL(56) +#define PM_UFFD_WP BIT_ULL(57) +#define PM_FILE BIT_ULL(61) +#define PM_SWAP BIT_ULL(62) +#define PM_PRESENT BIT_ULL(63) + extern unsigned int __page_size; extern unsigned int __page_shift;