* [PATCH] selftests/mm: fix format warnings on 32-bit architectures
@ 2026-11-03 15:54 Sasha Levin
2026-11-03 16:03 ` Lorenzo Stoakes (ARM)
2026-11-03 16:11 ` Zi Yan
0 siblings, 2 replies; 3+ messages in thread
From: Sasha Levin @ 2026-11-03 15:54 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand
Cc: Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Shuah Khan, Zi Yan,
Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, linux-mm,
linux-kselftest, linux-kernel
On 32-bit architectures size_t and uintptr_t are unsigned int and
ssize_t is int, and with _FILE_OFFSET_BITS=64 off_t is long long, so
printing them with %ld, %lu or %lx, or scanning /proc/self/maps into
uintptr_t variables with %lx, warns:
hugetlb-read-hwpoison.c:32:58: warning: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
Print size_t with %zu and %zx, casting the nonnegative ssize_t read
totals to size_t, print off_t as unsigned long long, and scan the
addresses into unsigned long variables.
split_huge_page_test also builds its debugfs commands from uint64_t
addresses with %lx. write_debugfs() has no format attribute, so nothing
warned, but on 32-bit the commands get the wrong addresses. Print them
with PRIx64, add the attribute, and cast the pointers through uintptr_t,
as casting them straight to uint64_t warns on 32-bit too.
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
Found with a 32-bit build of the selftests with a 64-bit time_t (gcc 16
and clang 21 with -m32 -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64);
KernelCI's 32-bit arm builds show the same warnings. The changed files
build without format warnings there now, and the x86_64 builds don't
change. The other selftests get the same kind of fix in separate
patches.
.../selftests/mm/hugetlb-read-hwpoison.c | 25 +++++++-------
.../selftests/mm/hugetlb-soft-offline.c | 2 +-
tools/testing/selftests/mm/mseal_test.c | 2 +-
.../selftests/mm/split_huge_page_test.c | 34 +++++++++----------
4 files changed, 32 insertions(+), 31 deletions(-)
diff --git a/tools/testing/selftests/mm/hugetlb-read-hwpoison.c b/tools/testing/selftests/mm/hugetlb-read-hwpoison.c
index 31748a24448f8..91b954a078483 100644
--- a/tools/testing/selftests/mm/hugetlb-read-hwpoison.c
+++ b/tools/testing/selftests/mm/hugetlb-read-hwpoison.c
@@ -29,15 +29,15 @@ static void report_status(enum test_status status, const char *test_name,
{
switch (status) {
case TEST_PASSED:
- ksft_test_result_pass("%s chunk_size=0x%lx\n",
+ ksft_test_result_pass("%s chunk_size=0x%zx\n",
test_name, chunk_size);
break;
case TEST_FAILED:
- ksft_test_result_fail("%s chunk_size=0x%lx\n",
+ ksft_test_result_fail("%s chunk_size=0x%zx\n",
test_name, chunk_size);
break;
case TEST_SKIPPED:
- ksft_test_result_skip("%s chunk_size=0x%lx\n",
+ ksft_test_result_skip("%s chunk_size=0x%zx\n",
test_name, chunk_size);
break;
}
@@ -62,7 +62,7 @@ static bool verify_chunk(char *buf, size_t len, char val)
for (i = 0; i < len; ++i) {
if (buf[i] != val) {
- ksft_print_msg("check fail: buf[%lu] = %u != %u\n",
+ ksft_print_msg("check fail: buf[%zu] = %u != %u\n",
i, buf[i], val);
return false;
}
@@ -79,8 +79,9 @@ static bool seek_read_hugepage_filemap(int fd, size_t len, size_t wr_chunk_size,
ssize_t total_ret_count = 0;
char val = offset / wr_chunk_size + offset % wr_chunk_size;
- ksft_print_msg("init val=%u with offset=0x%lx\n", val, offset);
- ksft_print_msg("expect to read 0x%lx bytes of data in total\n",
+ ksft_print_msg("init val=%u with offset=0x%llx\n", val,
+ (unsigned long long)offset);
+ ksft_print_msg("expect to read 0x%zx bytes of data in total\n",
expected);
if (lseek(fd, offset, SEEK_SET) < 0) {
ksft_perror("seek failed");
@@ -102,8 +103,8 @@ static bool seek_read_hugepage_filemap(int fd, size_t len, size_t wr_chunk_size,
total_ret_count += ret_count;
}
- ksft_print_msg("actually read 0x%lx bytes of data in total\n",
- total_ret_count);
+ ksft_print_msg("actually read 0x%zx bytes of data in total\n",
+ (size_t)total_ret_count);
return total_ret_count == expected;
}
@@ -116,7 +117,7 @@ static bool read_hugepage_filemap(int fd, size_t len,
ssize_t total_ret_count = 0;
char val = 0;
- ksft_print_msg("expect to read 0x%lx bytes of data in total\n",
+ ksft_print_msg("expect to read 0x%zx bytes of data in total\n",
expected);
while (total_ret_count < len) {
ret_count = read(fd, buf, wr_chunk_size);
@@ -133,8 +134,8 @@ static bool read_hugepage_filemap(int fd, size_t len,
total_ret_count += ret_count;
}
- ksft_print_msg("actually read 0x%lx bytes of data in total\n",
- total_ret_count);
+ ksft_print_msg("actually read 0x%zx bytes of data in total\n",
+ (size_t)total_ret_count);
return total_ret_count == expected;
}
@@ -293,7 +294,7 @@ int main(void)
signal(SIGBUS, sigbus_handler);
for (i = 0; i < ARRAY_SIZE(wr_chunk_sizes); ++i) {
- ksft_print_msg("Write/read chunk size=0x%lx\n",
+ ksft_print_msg("Write/read chunk size=0x%zx\n",
wr_chunk_sizes[i]);
fd = create_hugetlbfs_file(&file_stat);
diff --git a/tools/testing/selftests/mm/hugetlb-soft-offline.c b/tools/testing/selftests/mm/hugetlb-soft-offline.c
index d9565219378aa..9bdd78636dc2a 100644
--- a/tools/testing/selftests/mm/hugetlb-soft-offline.c
+++ b/tools/testing/selftests/mm/hugetlb-soft-offline.c
@@ -56,7 +56,7 @@ static int do_soft_offline(int fd, size_t len, int expect_errno)
}
memset(filemap, 0xab, len);
- ksft_print_msg("Allocated %#lx bytes of hugetlb pages\n", len);
+ ksft_print_msg("Allocated %#zx bytes of hugetlb pages\n", len);
hwp_addr = filemap + len / 2;
ret = madvise(hwp_addr, pagesize, MADV_SOFT_OFFLINE);
diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c
index 1a05e6921fed7..cea6c47cf5091 100644
--- a/tools/testing/selftests/mm/mseal_test.c
+++ b/tools/testing/selftests/mm/mseal_test.c
@@ -24,7 +24,7 @@ static unsigned long get_vma_size(void *addr, int *prot)
FILE *maps;
char line[256];
int size = 0;
- uintptr_t addr_start, addr_end;
+ unsigned long addr_start, addr_end;
char protstr[5];
*prot = 0;
diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
index 36a6719ff09a8..f8744b5dbf990 100644
--- a/tools/testing/selftests/mm/split_huge_page_test.c
+++ b/tools/testing/selftests/mm/split_huge_page_test.c
@@ -32,9 +32,9 @@ int *expected_orders;
#define SMAP_PATH "/proc/self/smaps"
#define INPUT_MAX 80
-#define PID_FMT "%d,0x%lx,0x%lx,%d"
-#define PID_FMT_OFFSET "%d,0x%lx,0x%lx,%d,%d"
-#define PATH_FMT "%s,0x%lx,0x%lx,%d"
+#define PID_FMT "%d,0x%" PRIx64 ",0x%" PRIx64 ",%d"
+#define PID_FMT_OFFSET "%d,0x%" PRIx64 ",0x%" PRIx64 ",%d,%d"
+#define PATH_FMT "%s,0x%" PRIx64 ",0x%" PRIx64 ",%d"
const char *pagemap_proc = "/proc/self/pagemap";
const char *kpageflags_proc = "/proc/kpageflags";
@@ -70,7 +70,7 @@ static int check_after_split_folio_orders(char *vaddr_start, size_t len,
return status;
}
-static void write_debugfs(const char *fmt, ...)
+static __printf(1, 2) void write_debugfs(const char *fmt, ...)
{
char input[INPUT_MAX];
int ret;
@@ -132,12 +132,12 @@ static void verify_rss_anon_split_huge_page_all_zeroes(char *one_page, int nr_hp
disable_khugepaged(one_page, len);
/* split all THPs */
- write_debugfs(PID_FMT, getpid(), (uint64_t)one_page,
- (uint64_t)one_page + len, 0);
+ write_debugfs(PID_FMT, getpid(), (uint64_t)(uintptr_t)one_page,
+ (uint64_t)(uintptr_t)one_page + len, 0);
for (i = 0; i < len; i++)
if (one_page[i] != (char)0)
- ksft_exit_fail_msg("%ld byte corrupted\n", i);
+ ksft_exit_fail_msg("%zu byte corrupted\n", i);
if (!check_huge_anon(one_page, nr_hpages * pmd_pagesize, 0, pmd_pagesize))
ksft_exit_fail_msg("Still AnonHugePages not split\n");
@@ -181,12 +181,12 @@ static void split_pmd_thp_to_order(int order)
disable_khugepaged(one_page, len);
/* split all THPs */
- write_debugfs(PID_FMT, getpid(), (uint64_t)one_page,
- (uint64_t)one_page + len, order);
+ write_debugfs(PID_FMT, getpid(), (uint64_t)(uintptr_t)one_page,
+ (uint64_t)(uintptr_t)one_page + len, order);
for (i = 0; i < len; i++)
if (one_page[i] != (char)i)
- ksft_exit_fail_msg("%ld byte corrupted\n", i);
+ ksft_exit_fail_msg("%zu byte corrupted\n", i);
memset(expected_orders, 0, sizeof(int) * (pmd_order + 1));
expected_orders[order] = 4 << (pmd_order - order);
@@ -269,8 +269,8 @@ static void split_pte_mapped_thp(void)
}
/* Split all THPs through the remapped pages. */
- write_debugfs(PID_FMT, getpid(), (uint64_t)page_area,
- (uint64_t)page_area + page_area_size, 0);
+ write_debugfs(PID_FMT, getpid(), (uint64_t)(uintptr_t)page_area,
+ (uint64_t)(uintptr_t)page_area + page_area_size, 0);
/* Corruption during mremap or split? */
for (i = 0; i < page_area_size; i++) {
@@ -536,16 +536,16 @@ static void split_thp_in_pagecache_to_order_at(size_t fd_size,
*/
if (offset == -1) {
for (split_addr = addr; split_addr < addr + fd_size; split_addr += pmd_pagesize)
- write_debugfs(PID_FMT, getpid(), (uint64_t)split_addr,
- (uint64_t)split_addr + pagesize, order);
+ write_debugfs(PID_FMT, getpid(), (uint64_t)(uintptr_t)split_addr,
+ (uint64_t)(uintptr_t)split_addr + pagesize, order);
expected_orders[order] = fd_size / (pagesize << order);
} else {
int times = fd_size / pmd_pagesize;
for (split_addr = addr; split_addr < addr + fd_size; split_addr += pmd_pagesize)
- write_debugfs(PID_FMT_OFFSET, getpid(), (uint64_t)split_addr,
- (uint64_t)split_addr + pagesize, order, offset);
+ write_debugfs(PID_FMT_OFFSET, getpid(), (uint64_t)(uintptr_t)split_addr,
+ (uint64_t)(uintptr_t)split_addr + pagesize, order, offset);
for (i = order + 1; i < pmd_order; i++)
expected_orders[i] = times;
@@ -554,7 +554,7 @@ static void split_thp_in_pagecache_to_order_at(size_t fd_size,
for (i = 0; i < fd_size; i++)
if (*(addr + i) != (char)i) {
- ksft_print_msg("%lu byte corrupted in the file\n", i);
+ ksft_print_msg("%zu byte corrupted in the file\n", i);
err = EXIT_FAILURE;
goto out;
}
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] selftests/mm: fix format warnings on 32-bit architectures
2026-11-03 15:54 [PATCH] selftests/mm: fix format warnings on 32-bit architectures Sasha Levin
@ 2026-11-03 16:03 ` Lorenzo Stoakes (ARM)
2026-11-03 16:11 ` Zi Yan
1 sibling, 0 replies; 3+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-03 16:03 UTC (permalink / raw)
To: Sasha Levin
Cc: Andrew Morton, David Hildenbrand, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Shuah Khan, Zi Yan, Baolin Wang, Nico Pache, Ryan Roberts,
Dev Jain, Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau,
linux-mm, linux-kselftest, linux-kernel
On Tue, Nov 03, 2026 at 10:54:51AM -0500, Sasha Levin wrote:
> On 32-bit architectures size_t and uintptr_t are unsigned int and
> ssize_t is int, and with _FILE_OFFSET_BITS=64 off_t is long long, so
> printing them with %ld, %lu or %lx, or scanning /proc/self/maps into
> uintptr_t variables with %lx, warns:
>
> hugetlb-read-hwpoison.c:32:58: warning: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
>
> Print size_t with %zu and %zx, casting the nonnegative ssize_t read
> totals to size_t, print off_t as unsigned long long, and scan the
> addresses into unsigned long variables.
>
> split_huge_page_test also builds its debugfs commands from uint64_t
> addresses with %lx. write_debugfs() has no format attribute, so nothing
> warned, but on 32-bit the commands get the wrong addresses. Print them
> with PRIx64, add the attribute, and cast the pointers through uintptr_t,
> as casting them straight to uint64_t warns on 32-bit too.
>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
All looks reasonable so:
Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> ---
> Found with a 32-bit build of the selftests with a 64-bit time_t (gcc 16
> and clang 21 with -m32 -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64);
> KernelCI's 32-bit arm builds show the same warnings. The changed files
> build without format warnings there now, and the x86_64 builds don't
> change. The other selftests get the same kind of fix in separate
> patches.
>
> .../selftests/mm/hugetlb-read-hwpoison.c | 25 +++++++-------
> .../selftests/mm/hugetlb-soft-offline.c | 2 +-
> tools/testing/selftests/mm/mseal_test.c | 2 +-
> .../selftests/mm/split_huge_page_test.c | 34 +++++++++----------
> 4 files changed, 32 insertions(+), 31 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/hugetlb-read-hwpoison.c b/tools/testing/selftests/mm/hugetlb-read-hwpoison.c
> index 31748a24448f8..91b954a078483 100644
> --- a/tools/testing/selftests/mm/hugetlb-read-hwpoison.c
> +++ b/tools/testing/selftests/mm/hugetlb-read-hwpoison.c
> @@ -29,15 +29,15 @@ static void report_status(enum test_status status, const char *test_name,
> {
> switch (status) {
> case TEST_PASSED:
> - ksft_test_result_pass("%s chunk_size=0x%lx\n",
> + ksft_test_result_pass("%s chunk_size=0x%zx\n",
> test_name, chunk_size);
> break;
> case TEST_FAILED:
> - ksft_test_result_fail("%s chunk_size=0x%lx\n",
> + ksft_test_result_fail("%s chunk_size=0x%zx\n",
> test_name, chunk_size);
> break;
> case TEST_SKIPPED:
> - ksft_test_result_skip("%s chunk_size=0x%lx\n",
> + ksft_test_result_skip("%s chunk_size=0x%zx\n",
> test_name, chunk_size);
> break;
> }
> @@ -62,7 +62,7 @@ static bool verify_chunk(char *buf, size_t len, char val)
>
> for (i = 0; i < len; ++i) {
> if (buf[i] != val) {
> - ksft_print_msg("check fail: buf[%lu] = %u != %u\n",
> + ksft_print_msg("check fail: buf[%zu] = %u != %u\n",
> i, buf[i], val);
> return false;
> }
> @@ -79,8 +79,9 @@ static bool seek_read_hugepage_filemap(int fd, size_t len, size_t wr_chunk_size,
> ssize_t total_ret_count = 0;
> char val = offset / wr_chunk_size + offset % wr_chunk_size;
>
> - ksft_print_msg("init val=%u with offset=0x%lx\n", val, offset);
> - ksft_print_msg("expect to read 0x%lx bytes of data in total\n",
> + ksft_print_msg("init val=%u with offset=0x%llx\n", val,
> + (unsigned long long)offset);
> + ksft_print_msg("expect to read 0x%zx bytes of data in total\n",
> expected);
> if (lseek(fd, offset, SEEK_SET) < 0) {
> ksft_perror("seek failed");
> @@ -102,8 +103,8 @@ static bool seek_read_hugepage_filemap(int fd, size_t len, size_t wr_chunk_size,
>
> total_ret_count += ret_count;
> }
> - ksft_print_msg("actually read 0x%lx bytes of data in total\n",
> - total_ret_count);
> + ksft_print_msg("actually read 0x%zx bytes of data in total\n",
> + (size_t)total_ret_count);
>
> return total_ret_count == expected;
> }
> @@ -116,7 +117,7 @@ static bool read_hugepage_filemap(int fd, size_t len,
> ssize_t total_ret_count = 0;
> char val = 0;
>
> - ksft_print_msg("expect to read 0x%lx bytes of data in total\n",
> + ksft_print_msg("expect to read 0x%zx bytes of data in total\n",
> expected);
> while (total_ret_count < len) {
> ret_count = read(fd, buf, wr_chunk_size);
> @@ -133,8 +134,8 @@ static bool read_hugepage_filemap(int fd, size_t len,
>
> total_ret_count += ret_count;
> }
> - ksft_print_msg("actually read 0x%lx bytes of data in total\n",
> - total_ret_count);
> + ksft_print_msg("actually read 0x%zx bytes of data in total\n",
> + (size_t)total_ret_count);
>
> return total_ret_count == expected;
> }
> @@ -293,7 +294,7 @@ int main(void)
>
> signal(SIGBUS, sigbus_handler);
> for (i = 0; i < ARRAY_SIZE(wr_chunk_sizes); ++i) {
> - ksft_print_msg("Write/read chunk size=0x%lx\n",
> + ksft_print_msg("Write/read chunk size=0x%zx\n",
> wr_chunk_sizes[i]);
>
> fd = create_hugetlbfs_file(&file_stat);
> diff --git a/tools/testing/selftests/mm/hugetlb-soft-offline.c b/tools/testing/selftests/mm/hugetlb-soft-offline.c
> index d9565219378aa..9bdd78636dc2a 100644
> --- a/tools/testing/selftests/mm/hugetlb-soft-offline.c
> +++ b/tools/testing/selftests/mm/hugetlb-soft-offline.c
> @@ -56,7 +56,7 @@ static int do_soft_offline(int fd, size_t len, int expect_errno)
> }
>
> memset(filemap, 0xab, len);
> - ksft_print_msg("Allocated %#lx bytes of hugetlb pages\n", len);
> + ksft_print_msg("Allocated %#zx bytes of hugetlb pages\n", len);
>
> hwp_addr = filemap + len / 2;
> ret = madvise(hwp_addr, pagesize, MADV_SOFT_OFFLINE);
> diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c
> index 1a05e6921fed7..cea6c47cf5091 100644
> --- a/tools/testing/selftests/mm/mseal_test.c
> +++ b/tools/testing/selftests/mm/mseal_test.c
> @@ -24,7 +24,7 @@ static unsigned long get_vma_size(void *addr, int *prot)
> FILE *maps;
> char line[256];
> int size = 0;
> - uintptr_t addr_start, addr_end;
> + unsigned long addr_start, addr_end;
> char protstr[5];
> *prot = 0;
>
> diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
> index 36a6719ff09a8..f8744b5dbf990 100644
> --- a/tools/testing/selftests/mm/split_huge_page_test.c
> +++ b/tools/testing/selftests/mm/split_huge_page_test.c
> @@ -32,9 +32,9 @@ int *expected_orders;
> #define SMAP_PATH "/proc/self/smaps"
> #define INPUT_MAX 80
>
> -#define PID_FMT "%d,0x%lx,0x%lx,%d"
> -#define PID_FMT_OFFSET "%d,0x%lx,0x%lx,%d,%d"
> -#define PATH_FMT "%s,0x%lx,0x%lx,%d"
> +#define PID_FMT "%d,0x%" PRIx64 ",0x%" PRIx64 ",%d"
> +#define PID_FMT_OFFSET "%d,0x%" PRIx64 ",0x%" PRIx64 ",%d,%d"
> +#define PATH_FMT "%s,0x%" PRIx64 ",0x%" PRIx64 ",%d"
>
> const char *pagemap_proc = "/proc/self/pagemap";
> const char *kpageflags_proc = "/proc/kpageflags";
> @@ -70,7 +70,7 @@ static int check_after_split_folio_orders(char *vaddr_start, size_t len,
> return status;
> }
>
> -static void write_debugfs(const char *fmt, ...)
> +static __printf(1, 2) void write_debugfs(const char *fmt, ...)
> {
> char input[INPUT_MAX];
> int ret;
> @@ -132,12 +132,12 @@ static void verify_rss_anon_split_huge_page_all_zeroes(char *one_page, int nr_hp
> disable_khugepaged(one_page, len);
>
> /* split all THPs */
> - write_debugfs(PID_FMT, getpid(), (uint64_t)one_page,
> - (uint64_t)one_page + len, 0);
> + write_debugfs(PID_FMT, getpid(), (uint64_t)(uintptr_t)one_page,
> + (uint64_t)(uintptr_t)one_page + len, 0);
>
> for (i = 0; i < len; i++)
> if (one_page[i] != (char)0)
> - ksft_exit_fail_msg("%ld byte corrupted\n", i);
> + ksft_exit_fail_msg("%zu byte corrupted\n", i);
>
> if (!check_huge_anon(one_page, nr_hpages * pmd_pagesize, 0, pmd_pagesize))
> ksft_exit_fail_msg("Still AnonHugePages not split\n");
> @@ -181,12 +181,12 @@ static void split_pmd_thp_to_order(int order)
> disable_khugepaged(one_page, len);
>
> /* split all THPs */
> - write_debugfs(PID_FMT, getpid(), (uint64_t)one_page,
> - (uint64_t)one_page + len, order);
> + write_debugfs(PID_FMT, getpid(), (uint64_t)(uintptr_t)one_page,
> + (uint64_t)(uintptr_t)one_page + len, order);
>
> for (i = 0; i < len; i++)
> if (one_page[i] != (char)i)
> - ksft_exit_fail_msg("%ld byte corrupted\n", i);
> + ksft_exit_fail_msg("%zu byte corrupted\n", i);
>
> memset(expected_orders, 0, sizeof(int) * (pmd_order + 1));
> expected_orders[order] = 4 << (pmd_order - order);
> @@ -269,8 +269,8 @@ static void split_pte_mapped_thp(void)
> }
>
> /* Split all THPs through the remapped pages. */
> - write_debugfs(PID_FMT, getpid(), (uint64_t)page_area,
> - (uint64_t)page_area + page_area_size, 0);
> + write_debugfs(PID_FMT, getpid(), (uint64_t)(uintptr_t)page_area,
> + (uint64_t)(uintptr_t)page_area + page_area_size, 0);
>
> /* Corruption during mremap or split? */
> for (i = 0; i < page_area_size; i++) {
> @@ -536,16 +536,16 @@ static void split_thp_in_pagecache_to_order_at(size_t fd_size,
> */
> if (offset == -1) {
> for (split_addr = addr; split_addr < addr + fd_size; split_addr += pmd_pagesize)
> - write_debugfs(PID_FMT, getpid(), (uint64_t)split_addr,
> - (uint64_t)split_addr + pagesize, order);
> + write_debugfs(PID_FMT, getpid(), (uint64_t)(uintptr_t)split_addr,
> + (uint64_t)(uintptr_t)split_addr + pagesize, order);
>
> expected_orders[order] = fd_size / (pagesize << order);
> } else {
> int times = fd_size / pmd_pagesize;
>
> for (split_addr = addr; split_addr < addr + fd_size; split_addr += pmd_pagesize)
> - write_debugfs(PID_FMT_OFFSET, getpid(), (uint64_t)split_addr,
> - (uint64_t)split_addr + pagesize, order, offset);
> + write_debugfs(PID_FMT_OFFSET, getpid(), (uint64_t)(uintptr_t)split_addr,
> + (uint64_t)(uintptr_t)split_addr + pagesize, order, offset);
>
> for (i = order + 1; i < pmd_order; i++)
> expected_orders[i] = times;
> @@ -554,7 +554,7 @@ static void split_thp_in_pagecache_to_order_at(size_t fd_size,
>
> for (i = 0; i < fd_size; i++)
> if (*(addr + i) != (char)i) {
> - ksft_print_msg("%lu byte corrupted in the file\n", i);
> + ksft_print_msg("%zu byte corrupted in the file\n", i);
> err = EXIT_FAILURE;
> goto out;
> }
> --
> 2.53.0
>
--
Cheers, Lorenzo
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] selftests/mm: fix format warnings on 32-bit architectures
2026-11-03 15:54 [PATCH] selftests/mm: fix format warnings on 32-bit architectures Sasha Levin
2026-11-03 16:03 ` Lorenzo Stoakes (ARM)
@ 2026-11-03 16:11 ` Zi Yan
1 sibling, 0 replies; 3+ messages in thread
From: Zi Yan @ 2026-11-03 16:11 UTC (permalink / raw)
To: Sasha Levin
Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Shuah Khan, Baolin Wang,
Nico Pache, Ryan Roberts, Dev Jain, Barry Song, Lance Yang,
Usama Arif, Kiryl Shutsemau, linux-mm, linux-kselftest,
linux-kernel
On 3 Nov 2026, at 10:54, Sasha Levin wrote:
> On 32-bit architectures size_t and uintptr_t are unsigned int and
> ssize_t is int, and with _FILE_OFFSET_BITS=64 off_t is long long, so
> printing them with %ld, %lu or %lx, or scanning /proc/self/maps into
> uintptr_t variables with %lx, warns:
>
> hugetlb-read-hwpoison.c:32:58: warning: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
>
> Print size_t with %zu and %zx, casting the nonnegative ssize_t read
> totals to size_t, print off_t as unsigned long long, and scan the
> addresses into unsigned long variables.
>
> split_huge_page_test also builds its debugfs commands from uint64_t
> addresses with %lx. write_debugfs() has no format attribute, so nothing
> warned, but on 32-bit the commands get the wrong addresses. Print them
> with PRIx64, add the attribute, and cast the pointers through uintptr_t,
> as casting them straight to uint64_t warns on 32-bit too.
>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> Found with a 32-bit build of the selftests with a 64-bit time_t (gcc 16
> and clang 21 with -m32 -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64);
> KernelCI's 32-bit arm builds show the same warnings. The changed files
> build without format warnings there now, and the x86_64 builds don't
> change. The other selftests get the same kind of fix in separate
> patches.
>
> .../selftests/mm/hugetlb-read-hwpoison.c | 25 +++++++-------
> .../selftests/mm/hugetlb-soft-offline.c | 2 +-
> tools/testing/selftests/mm/mseal_test.c | 2 +-
> .../selftests/mm/split_huge_page_test.c | 34 +++++++++----------
> 4 files changed, 32 insertions(+), 31 deletions(-)
>
<snip>
> @@ -70,7 +70,7 @@ static int check_after_split_folio_orders(char *vaddr_start, size_t len,
> return status;
> }
>
> -static void write_debugfs(const char *fmt, ...)
> +static __printf(1, 2) void write_debugfs(const char *fmt, ...)
TIL, __printf() tells the compiler that write_debugfs() is doing
printf_style arguments and the compiler will do the corresponding
checks.
LGTM. Thanks.
Acked-by: Zi Yan <ziy@nvidia.com>
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-03 16:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 15:54 [PATCH] selftests/mm: fix format warnings on 32-bit architectures Sasha Levin
2026-11-03 16:03 ` Lorenzo Stoakes (ARM)
2026-11-03 16:11 ` Zi Yan
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®