The patch titled Subject: selftests-add-selftests-for-cachestat-fix-2 has been added to the -mm mm-unstable branch. Its filename is selftests-add-selftests-for-cachestat-fix-2.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/selftests-add-selftests-for-cachestat-fix-2.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Michael Ellerman <mpe@xxxxxxxxxxxxxx> Subject: selftests-add-selftests-for-cachestat-fix-2 Date: Thu, 11 May 2023 13:21:28 +1000 On kernels with 64K pages (powerpc at least), this tries to allocate 64MB on the stack which segfaults. Allocating data with malloc avoids the problem and allows the test to pass. Link: https://lkml.kernel.org/r/877ctfa6yv.fsf@mail.lhotse Signed-off-by: Michael Ellerman <mpe@xxxxxxxxxxxxxx> Cc: Brian Foster <bfoster@xxxxxxxxxx> Cc: Colin Ian King <colin.i.king@xxxxxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx> Cc: Michael Kerrisk <mtk.manpages@xxxxxxxxx> Cc: Nhat Pham <nphamcs@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- tools/testing/selftests/cachestat/test_cachestat.c | 69 ++++++----- 1 file changed, 40 insertions(+), 29 deletions(-) --- a/tools/testing/selftests/cachestat/test_cachestat.c~selftests-add-selftests-for-cachestat-fix-2 +++ a/tools/testing/selftests/cachestat/test_cachestat.c @@ -31,48 +31,59 @@ void print_cachestat(struct cachestat *c bool write_exactly(int fd, size_t filesize) { - char data[filesize]; - bool ret = true; int random_fd = open("/dev/urandom", O_RDONLY); + char *cursor, *data; + int remained; + bool ret; if (random_fd < 0) { ksft_print_msg("Unable to access urandom.\n"); ret = false; goto out; - } else { - int remained = filesize; - char *cursor = data; - - while (remained) { - ssize_t read_len = read(random_fd, cursor, remained); - - if (read_len <= 0) { - ksft_print_msg("Unable to read from urandom.\n"); - ret = false; - goto close_random_fd; - } + } + + data = malloc(filesize); + if (!data) { + ksft_print_msg("Unable to allocate data.\n"); + ret = false; + goto close_random_fd; + } - remained -= read_len; - cursor += read_len; + remained = filesize; + cursor = data; + + while (remained) { + ssize_t read_len = read(random_fd, cursor, remained); + + if (read_len <= 0) { + ksft_print_msg("Unable to read from urandom.\n"); + ret = false; + goto out_free_data; } - /* write random data to fd */ - remained = filesize; - cursor = data; - while (remained) { - ssize_t write_len = write(fd, cursor, remained); - - if (write_len <= 0) { - ksft_print_msg("Unable write random data to file.\n"); - ret = false; - goto close_random_fd; - } + remained -= read_len; + cursor += read_len; + } - remained -= write_len; - cursor += write_len; + /* write random data to fd */ + remained = filesize; + cursor = data; + while (remained) { + ssize_t write_len = write(fd, cursor, remained); + + if (write_len <= 0) { + ksft_print_msg("Unable write random data to file.\n"); + ret = false; + goto out_free_data; } + + remained -= write_len; + cursor += write_len; } + ret = true; +out_free_data: + free(data); close_random_fd: close(random_fd); out: _ Patches currently in -mm which might be from mpe@xxxxxxxxxxxxxx are mm-kfence-fix-false-positives-on-big-endian.patch selftests-add-selftests-for-cachestat-fix-2.patch