Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/mm: fix faulting-in code in pagemap_ioctl test

One of the pagemap_ioctl tests attempts to fault in pages by memcpy()'ing
them to an unused buffer. This probably worked originally, but since
commit 46036188ea1f ("selftests/mm: build with -O2") the compiler is free
to optimise away that unused buffer and the memcpy() with it. As a result
there might not be any resident page in the mapping and the test may fail.

We don't need to copy all that memory anyway. Just fault in every page.

While at it also make sure to compute the number of pages once using
simple integer arithmetic instead of ceilf() and implicit conversions.

Link: https://lkml.kernel.org/r/20260122170224.4056513-8-kevin.brodsky@arm.com
Fixes: 46036188ea1f ("selftests/mm: build with -O2")
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@arm.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: SeongJae Park <sj@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: wang lian <lianux.mm@gmail.com>
Cc: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kevin Brodsky and committed by
Andrew Morton
7e938f00 dd2b4e04

+4 -5
+4 -5
tools/testing/selftests/mm/pagemap_ioctl.c
··· 1052 1052 int sanity_tests(void) 1053 1053 { 1054 1054 unsigned long long mem_size, vec_size; 1055 - long ret, fd, i, buf_size; 1055 + long ret, fd, i, buf_size, nr_pages; 1056 1056 struct page_region *vec; 1057 1057 char *mem, *fmem; 1058 1058 struct stat sbuf; 1059 - char *tmp_buf; 1060 1059 1061 1060 /* 1. wrong operation */ 1062 1061 mem_size = 10 * page_size; ··· 1166 1167 if (fmem == MAP_FAILED) 1167 1168 ksft_exit_fail_msg("error nomem %d %s\n", errno, strerror(errno)); 1168 1169 1169 - tmp_buf = malloc(sbuf.st_size); 1170 - memcpy(tmp_buf, fmem, sbuf.st_size); 1170 + nr_pages = (sbuf.st_size + page_size - 1) / page_size; 1171 + force_read_pages(fmem, nr_pages, page_size); 1171 1172 1172 1173 ret = pagemap_ioctl(fmem, sbuf.st_size, vec, vec_size, 0, 0, 1173 1174 0, PAGEMAP_NON_WRITTEN_BITS, 0, PAGEMAP_NON_WRITTEN_BITS); 1174 1175 1175 1176 ksft_test_result(ret >= 0 && vec[0].start == (uintptr_t)fmem && 1176 - LEN(vec[0]) == ceilf((float)sbuf.st_size/page_size) && 1177 + LEN(vec[0]) == nr_pages && 1177 1178 (vec[0].categories & PAGE_IS_FILE), 1178 1179 "%s Memory mapped file\n", __func__); 1179 1180