From: Muhammad Usama Anjum <usama.anjum@collabora.com>
To: Andrei Vagin <avagin@google.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] selftests/mm: check that PAGEMAP_SCAN returns correct categories
Date: Tue, 7 Nov 2023 11:14:57 +0500 [thread overview]
Message-ID: <3c8bd9ab-0da0-4c12-8a3e-ce1eef1499c8@collabora.com> (raw)
In-Reply-To: <20231106220959.296568-2-avagin@google.com>
On 11/7/23 3:09 AM, Andrei Vagin wrote:
> Right now, tests read page flags from /proc/pid/pagemap files. With this
> change, tests will check that PAGEMAP_SCAN return correct information
> too.
>
> Signed-off-by: Andrei Vagin <avagin@google.com>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Tested-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> tools/testing/selftests/mm/vm_util.c | 53 ++++++++++++++++++++++++++--
> 1 file changed, 50 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
> index 3082b40492dd..ec3478b96e4c 100644
> --- a/tools/testing/selftests/mm/vm_util.c
> +++ b/tools/testing/selftests/mm/vm_util.c
> @@ -4,6 +4,7 @@
> #include <dirent.h>
> #include <sys/ioctl.h>
> #include <linux/userfaultfd.h>
> +#include <linux/fs.h>
> #include <sys/syscall.h>
> #include <unistd.h>
> #include "../kselftest.h"
> @@ -28,19 +29,65 @@ uint64_t pagemap_get_entry(int fd, char *start)
> return entry;
> }
>
> +static uint64_t pagemap_scan_get_categories(int fd, char *start)
> +{
> + struct pm_scan_arg arg;
> + struct page_region r;
> + long ret;
> +
> + arg.start = (uintptr_t)start;
> + arg.end = (uintptr_t)(start + psize());
> + arg.vec = (uintptr_t)&r;
> + arg.vec_len = 1;
> + arg.flags = 0;
> + arg.size = sizeof(struct pm_scan_arg);
> + arg.max_pages = 0;
> + arg.category_inverted = 0;
> + arg.category_mask = 0;
> + arg.category_anyof_mask = PAGE_IS_WPALLOWED | PAGE_IS_WRITTEN | PAGE_IS_FILE |
> + PAGE_IS_PRESENT | PAGE_IS_SWAPPED | PAGE_IS_PFNZERO |
> + PAGE_IS_HUGE | PAGE_IS_SOFT_DIRTY;
> + arg.return_mask = arg.category_anyof_mask;
> +
> + ret = ioctl(fd, PAGEMAP_SCAN, &arg);
> + if (ret < 0)
> + ksft_exit_fail_msg("PAGEMAP_SCAN failed: %s\n", strerror(errno));
> + if (ret == 0)
> + return 0;
> + return r.categories;
> +}
> +
> +static bool page_entry_is(int fd, char *start, char *desc,
> + uint64_t pagemap_flags, uint64_t pagescan_flags)
> +{
> + bool m, s;
> +
> + m = pagemap_get_entry(fd, start) & pagemap_flags;
> + s = pagemap_scan_get_categories(fd, start) & pagescan_flags;
> + if (m == s)
> + return m;
> +
> + ksft_exit_fail_msg(
> + "read and ioctl return unmatched results for %s: %d %d", desc, m, s);
> + return m;
> +}
> +
> bool pagemap_is_softdirty(int fd, char *start)
> {
> - return pagemap_get_entry(fd, start) & PM_SOFT_DIRTY;
> + return page_entry_is(fd, start, "soft-dirty",
> + PM_SOFT_DIRTY, PAGE_IS_SOFT_DIRTY);
> }
>
> bool pagemap_is_swapped(int fd, char *start)
> {
> - return pagemap_get_entry(fd, start) & PM_SWAP;
> + return page_entry_is(fd, start, "swap", PM_SWAP, PAGE_IS_SWAPPED);
> }
>
> bool pagemap_is_populated(int fd, char *start)
> {
> - return pagemap_get_entry(fd, start) & (PM_PRESENT | PM_SWAP);
> + return page_entry_is(fd, start, "populated",
> + PM_PRESENT | PM_SWAP,
> + PAGE_IS_PRESENT | PAGE_IS_SWAPPED);
> }
>
> unsigned long pagemap_get_pfn(int fd, char *start)
--
BR,
Muhammad Usama Anjum
next prev parent reply other threads:[~2023-11-07 6:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-06 22:09 [PATCH 1/2 v2] fs/proc/task_mmu: report SOFT_DIRTY bits through the PAGEMAP_SCAN ioctl Andrei Vagin
2023-11-06 22:09 ` [PATCH 2/2] selftests/mm: check that PAGEMAP_SCAN returns correct categories Andrei Vagin
2023-11-07 6:14 ` Muhammad Usama Anjum [this message]
2023-11-14 16:06 ` Ryan Roberts
2023-11-07 5:49 ` [PATCH 1/2 v2] fs/proc/task_mmu: report SOFT_DIRTY bits through the PAGEMAP_SCAN ioctl Muhammad Usama Anjum
2023-11-07 16:41 [PATCH 1/2 v3] " Andrei Vagin
2023-11-07 16:41 ` [PATCH 2/2] selftests/mm: check that PAGEMAP_SCAN returns correct categories Andrei Vagin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3c8bd9ab-0da0-4c12-8a3e-ce1eef1499c8@collabora.com \
--to=usama.anjum@collabora.com \
--cc=akpm@linux-foundation.org \
--cc=avagin@google.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®