From: Wake Liu via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: kaleshsingh@google.com
Subject: [LTP] [PATCH v2 1/2] msync04: Check smaps when the page frame number is not exposed
Date: Mon, 16 Nov 2026 14:22:39 +0000 [thread overview]
Message-ID: <20261116142240.3153725-2-wakel@google.com> (raw)
In-Reply-To: <20261116142240.3153725-1-wakel@google.com>
The test looks up the dirty flag of the mapped page in /proc/kpageflags,
using the PFN it reads from /proc/self/pagemap. If the PFN is reported
as zero, get_dirty_bit() returns 0 and the test falls back to checking
the file content, which can end only with TCONF or TFAIL.
The PFN of a present page is reported as zero with the 16K page size
emulation that Android uses on x86_64, where each entry of the emulated
pagemap covers four 4K kernel pages and therefore carries no single PFN.
The test then reports:
TCONF: Write was too fast, couldn't test msync()
When the page is present but its PFN is not exposed, sum up the
Shared_Dirty and Private_Dirty counters of the mapping in
/proc/self/smaps instead. They account for both the dirty bit in the
page table and the dirty flag of the page, and drop to zero once
msync() has written the page back. Nothing changes on kernels that
expose the PFN to root.
Signed-off-by: Wake Liu <wakel@google.com>
---
testcases/kernel/syscalls/msync/msync04.c | 46 ++++++++++++++++++++++-
1 file changed, 44 insertions(+), 2 deletions(-)
diff --git a/testcases/kernel/syscalls/msync/msync04.c b/testcases/kernel/syscalls/msync/msync04.c
index 1251388b6..1ed56fec6 100644
--- a/testcases/kernel/syscalls/msync/msync04.c
+++ b/testcases/kernel/syscalls/msync/msync04.c
@@ -17,6 +17,7 @@
#define _GNU_SOURCE
#include <errno.h>
#include "tst_test.h"
+#include "tst_safe_stdio.h"
static int test_fd;
static char *mmaped_area;
@@ -24,6 +25,39 @@ static long pagesize;
#define STRING_TO_WRITE "AAAAAAAAAA"
+#define PM_PFRAME_MASK ((1ULL << 55) - 1)
+#define PM_PRESENT (1ULL << 63)
+
+/*
+ * Returns the amount of dirty memory of the mapping starting at addr, as
+ * accounted in /proc/self/smaps.
+ */
+static long get_smaps_dirty_kb(unsigned long addr)
+{
+ FILE *fp = SAFE_FOPEN("/proc/self/smaps", "r");
+ unsigned long start, end;
+ long dirty_kb = 0, kb;
+ char line[1024];
+ int found = 0;
+
+ while (fgets(line, sizeof(line), fp)) {
+ if (sscanf(line, "%lx-%lx ", &start, &end) == 2) {
+ found = start == addr;
+ continue;
+ }
+
+ if (!found)
+ continue;
+
+ if (sscanf(line, "Shared_Dirty: %ld kB", &kb) == 1 ||
+ sscanf(line, "Private_Dirty: %ld kB", &kb) == 1)
+ dirty_kb += kb;
+ }
+
+ SAFE_FCLOSE(fp);
+ return dirty_kb;
+}
+
static uint64_t get_dirty_bit(void *data)
{
int pagemap_fd, pageflags_fd;
@@ -37,9 +71,17 @@ static uint64_t get_dirty_bit(void *data)
SAFE_READ(SAFE_READ_ALL, pagemap_fd, &pagemap_entry,
sizeof(pagemap_entry));
SAFE_CLOSE(pagemap_fd);
- pfn = pagemap_entry & ((1ULL << 55) - 1);
- if (!pfn)
+ pfn = pagemap_entry & PM_PFRAME_MASK;
+ if (!pfn) {
+ /*
+ * The PFN of a present page may not be exposed, check the
+ * dirty accounting of the mapping in smaps instead.
+ */
+ if (pagemap_entry & PM_PRESENT)
+ return get_smaps_dirty_kb(addr) > 0;
+
return 0;
+ }
pageflags_fd = SAFE_OPEN("/proc/kpageflags", O_RDONLY);
index = pfn * sizeof(uint64_t);
SAFE_LSEEK(pageflags_fd, index, SEEK_SET);
--
2.56.0.611.g1030f0b940-goog
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-11-16 14:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 7:23 [LTP] [PATCH 0/2] msync04, pipe2_04: Support kernel/userspace page size mismatch Wake Liu via ltp
2026-11-16 7:23 ` [LTP] [PATCH 1/2] msync04: Check smaps when the page frame number is not exposed Wake Liu via ltp
2026-11-16 12:09 ` [LTP] " linuxtestproject.agent
2026-11-16 7:23 ` [LTP] [PATCH 2/2] pipe2_04: Don't assume the minimum pipe size is getpagesize() Wake Liu via ltp
2026-11-16 14:22 ` [LTP] [PATCH v2 0/2] msync04, pipe2_04: Support kernel/userspace page size mismatch Wake Liu via ltp
2026-11-16 14:22 ` Wake Liu via ltp [this message]
2026-11-16 22:35 ` [LTP] msync04: Check smaps when the page frame number is not exposed linuxtestproject.agent
2026-11-16 14:22 ` [LTP] [PATCH v2 2/2] pipe2_04: Don't assume the minimum pipe size is getpagesize() Wake Liu via ltp
2026-11-24 8:42 ` [LTP] [PATCH v2 0/2] msync04, pipe2_04: Support kernel/userspace page size mismatch Wake Liu via ltp
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=20261116142240.3153725-2-wakel@google.com \
--to=ltp@lists.linux.it \
--cc=kaleshsingh@google.com \
--cc=wakel@google.com \
/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