[LTP] [PATCH v2 3/4] ioctl10: Compare vma_page_size with KernelPageSize from smaps
Wake Liu
wakel@google.com
Mon Nov 16 15:22:05 CET 2026
PROCMAP_QUERY returns in vma_page_size the page size the kernel uses to
back the VMA, i.e. vma_kernel_pagesize(), which /proc/$PID/smaps shows
as KernelPageSize. The test compares it with getpagesize() instead,
which is only correct as long as the kernel page size equals the page
size reported to userspace.
That is not the case with the 16K page size emulation that Android uses
on x86_64, where the kernel keeps using 4K pages internally:
TFAIL: q->vma_page_size (4096) != getpagesize() (16384)
Compare it with KernelPageSize of the same VMA in /proc/self/smaps
instead. This also cross-checks the two kernel interfaces, the same way
the other fields are checked against /proc/self/maps. Nothing changes
on kernels where both page sizes are equal.
Signed-off-by: Wake Liu <wakel@google.com>
---
testcases/kernel/syscalls/ioctl/ioctl10.c | 34 ++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/testcases/kernel/syscalls/ioctl/ioctl10.c b/testcases/kernel/syscalls/ioctl/ioctl10.c
index 8a4f8ae40..5dd2a866d 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl10.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl10.c
@@ -28,6 +28,7 @@
#include "lapi/ioctl.h"
#define PROC_MAP_PATH "/proc/self/maps"
+#define PROC_SMAPS_PATH "/proc/self/smaps"
struct map_entry {
unsigned long vm_start;
@@ -86,6 +87,37 @@ static void parse_maps_file(const char *filename, const char *keyword, struct ma
tst_brk(TFAIL, "parse maps file /proc/self/maps failed");
}
+/*
+ * vma_page_size is the page size the kernel uses to back the VMA, which is
+ * reported as KernelPageSize in /proc/self/smaps. It is not necessarily
+ * equal to getpagesize(), e.g. for hugetlb mappings or when the kernel
+ * reports a larger page size to userspace than it uses internally.
+ */
+static unsigned long get_kernel_page_size(unsigned long vm_start)
+{
+ FILE *fp = SAFE_FOPEN(PROC_SMAPS_PATH, "r");
+ unsigned long start, end, size_kb;
+ char line[1024];
+ int found = 0;
+
+ while (fgets(line, sizeof(line), fp)) {
+ if (sscanf(line, "%lx-%lx ", &start, &end) == 2) {
+ found = start == vm_start;
+ continue;
+ }
+
+ if (found && sscanf(line, "KernelPageSize: %lu kB", &size_kb) == 1) {
+ SAFE_FCLOSE(fp);
+ return size_kb * 1024;
+ }
+ }
+
+ SAFE_FCLOSE(fp);
+ tst_brk(TBROK, "KernelPageSize of %lx not found in %s",
+ vm_start, PROC_SMAPS_PATH);
+ return 0;
+}
+
static void verify_ioctl(void)
{
struct map_entry entry;
@@ -107,7 +139,7 @@ static void verify_ioctl(void)
TST_EXP_EQ_LU(q->vma_flags, entry.vm_flags);
TST_EXP_EQ_LU(q->vma_start, entry.vm_start);
TST_EXP_EQ_LU(q->vma_end, entry.vm_end);
- TST_EXP_EQ_LU(q->vma_page_size, getpagesize());
+ TST_EXP_EQ_LU(q->vma_page_size, get_kernel_page_size(entry.vm_start));
TST_EXP_EQ_LU(q->vma_offset, entry.vm_pgoff);
TST_EXP_EQ_LU(q->inode, entry.vm_inode);
TST_EXP_EQ_LU(q->dev_major, entry.vm_major);
--
2.56.0.611.g1030f0b940-goog
More information about the ltp
mailing list