From patchwork Wed Apr 12 16:42:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209344 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 D39B0C77B6E for ; Wed, 12 Apr 2023 16:42:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6FA21280004; Wed, 12 Apr 2023 12:42:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A934280001; Wed, 12 Apr 2023 12:42:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54AA2280004; Wed, 12 Apr 2023 12:42:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 46563280001 for ; Wed, 12 Apr 2023 12:42:36 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C771CC01BA for ; Wed, 12 Apr 2023 16:42:35 +0000 (UTC) X-FDA: 80673307470.06.8ED29F4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id C0261100017 for ; Wed, 12 Apr 2023 16:42:33 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f6eWiZcP; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.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=1681317753; 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=9VoJC4PMtOZChfNpsShin+Q92n+br8Q3f1O4OPEN8PE=; b=e16OKM0KNZMGjgxzPc8hfOy5tFCefYPc7aGBRRo5BnmgHmOw8eOCtybibiOAAjoB2CEci4 L1kY50fKa9JEXhYPjCZOqgAx6rqKPdSZsZfMakhlo1i7/BHyI/BcdhAiwVPK8BNrWcv9fw qFJmpCXUefqPjFXqQ9int525kVOxXmM= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f6eWiZcP; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.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=1681317753; a=rsa-sha256; cv=none; b=wl984PpN2e1C9vuoWyWB/XzAMfm/5ADY+GPHeMCE6jZc+f+Zjb93XeSr6lRoMk0v+yNXpd E87NmEQ1Vmylhqvr8Gaa6qt+qbggFH19jGXF8H3LGb9V+8mltRCEOAKK7CnZ+HDMOPddYg x4/o1vdx0u/ba+LmKiQzqhcWboP10/U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317753; 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=9VoJC4PMtOZChfNpsShin+Q92n+br8Q3f1O4OPEN8PE=; b=f6eWiZcPGQTMdX4Sy8cDb2AlBnfZrM/yD2w1TvIrZhKZneFjohfluRf0G2lxpcbceaKCCF nJSmS52cg0jk/ZkxINjOQIezI+4TsDaLhbjY7HPg7CRosNoGqHL/8WixATMA7rHSEpaFO7 yKhzT52FH6Adu1qAVc+sgJCBJsyC6dk= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-113-CN9vhb9oOWe0-Tx5uwLlLg-1; Wed, 12 Apr 2023 12:42:31 -0400 X-MC-Unique: CN9vhb9oOWe0-Tx5uwLlLg-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-5ef4122d2dbso1350386d6.1 for ; Wed, 12 Apr 2023 09:42:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317751; x=1683909751; 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=9VoJC4PMtOZChfNpsShin+Q92n+br8Q3f1O4OPEN8PE=; b=UDW5KY2Qu4d1I2xWbB+YcjDHKNecgsNUE2T0vlnW/NGJCFyFs455oOwA0oFhHaPUtt WcOlPxVidFO8hIFtE5iYUt/ll82EoQFuc3dLpF4MuZHdhw2Dp/68hvMvlbnc2mWipZSF 7RIIjNXMZjxYoG/Y3fNJ6gPBiqVDM3kMbytLG9GqIl+fs0BUy2Nz9bv1iWCSOdmgniUK OS98n5sT7Ws9bc6viHNKABr+vYJ1tw877705wBeH6SUsZ4PROgYTf8CTHJNx40K1H4nc 5FUqDoc6ixt94Fx86jbKZDWdmYBxUxtFJQ50387/tXKuNebytkmiNEiRHGpfV7fRFTL/ nxgg== X-Gm-Message-State: AAQBX9ciSx7CpvqCrF+E9fR7bSsxsAsP6m0aoQkolbN5BC9yR7dIGQ0r w9DoPfHGr8cSxc72Puum1O9yxuf6we4higxd9QF3O+CTrgCIqMd1K5F+OHooWxNf459sM2KgvcO Rdt+Cqn4M9FM= X-Received: by 2002:a05:6214:4105:b0:5de:5da:b873 with SMTP id kc5-20020a056214410500b005de05dab873mr4439628qvb.3.1681317751470; Wed, 12 Apr 2023 09:42:31 -0700 (PDT) X-Google-Smtp-Source: AKy350bKIhyvFE421MNKeiw66bcLbViwoq88DKthBLMNBPxf9F5dEOECVmGzHn09x9YPggLZEnerFA== X-Received: by 2002:a05:6214:4105:b0:5de:5da:b873 with SMTP id kc5-20020a056214410500b005de05dab873mr4439540qvb.3.1681317750348; Wed, 12 Apr 2023 09:42:30 -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 j188-20020a3787c5000000b00749fa9e12e9sm4778767qkd.124.2023.04.12.09.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:29 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com, Mike Rapoport Subject: [PATCH v2 08/31] selftests/mm: Use PM_* macros in vm_utils.h Date: Wed, 12 Apr 2023 12:42:27 -0400 Message-Id: <20230412164227.328145-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-Rspamd-Queue-Id: C0261100017 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: fjftayifeght5k3mymtkotgu8cffe84e X-HE-Tag: 1681317753-954064 X-HE-Meta: U2FsdGVkX193mXIqy/Vh5dMAgg5VR2wqnwn7rb5a+8Qm6VM9ZuIUvoZrLZUSCAcCFq9+x6JOyEWNWZg9n1+5w8BGAwgzU0VEghNSRcz8SGEG/qp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I2faD4luJ/4sIXtMNSaoUe97+rUcPHE6YLNHJAQpKNSAe81kVsGCt8tNr0zqddl06W46ra1xSp13kY0IQkP1LJLvmJzXuhWMZueK2i6WtzdrHUSE2Aq++fYboH44WFFFVvWdA0a6z9Cy/kvE8JrM9+UcjBKa6SIc2RPOMf9SyyICJb0m9lhuOvNHAETtmjO0yII6el4UMCSet6BVfp0vC+aQGR3LtCr73R8qa4CYtW/AQDzL+o8QiES/YOjlm6LkfBZTaNpUZtvLn6oHUWDquk/xwJ/gRA5ySubYT8HvCtRaYebYQUkj+9IOTydhrL6Ic8yNvQKIksw9oBHHLQQ3AE+0toE8QyPUjPaWsJJKUY3PNBwNgVaq9BTVuiW1oE3hsoFLbSeV0iBNpvmv2rt7P+r 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. Reviewed-by: Axel Rasmussen Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- 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 7ffad87aa7e8..54d227d6f70a 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;