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

selftests/mm/mlock: print error on failure

It's not really possible to start diagnosing this without knowing the
actual error.

Also update the mlock2 helper to behave like libc would by setting errno
and returning -1.

Link: https://lkml.kernel.org/r/20250311-mm-selftests-v4-12-dec210a658f5@google.com
Signed-off-by: Brendan Jackman <jackmanb@google.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Brendan Jackman and committed by
Andrew Morton
1ddae9d6 5d2146a3

+9 -3
+2 -2
tools/testing/selftests/mm/mlock-random-test.c
··· 161 161 MLOCK_ONFAULT); 162 162 163 163 if (ret) 164 - ksft_exit_fail_msg("%s() failure at |%p(%d)| mlock:|%p(%d)|\n", 164 + ksft_exit_fail_msg("%s() failure (%s) at |%p(%d)| mlock:|%p(%d)|\n", 165 165 is_mlock ? "mlock" : "mlock2", 166 - p, alloc_size, 166 + strerror(errno), p, alloc_size, 167 167 p + start_offset, lock_size); 168 168 } 169 169
+7 -1
tools/testing/selftests/mm/mlock2.h
··· 6 6 7 7 static int mlock2_(void *start, size_t len, int flags) 8 8 { 9 - return syscall(__NR_mlock2, start, len, flags); 9 + int ret = syscall(__NR_mlock2, start, len, flags); 10 + 11 + if (ret) { 12 + errno = ret; 13 + return -1; 14 + } 15 + return 0; 10 16 } 11 17 12 18 static FILE *seek_to_smaps_entry(unsigned long addr)