* [PATCH v2 1/2] selftest/futex: Make the error check more precise for futex_numa_mpol
@ 2025-09-04 16:55 André Almeida
2025-09-04 16:55 ` [PATCH v2 2/2] selftest/futex: Reintroduce "Memory out of range" numa_mpol's subtest André Almeida
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: André Almeida @ 2025-09-04 16:55 UTC (permalink / raw)
To: Sebastian Andrzej Siewior, linux-kernel
Cc: Darren Hart, Davidlohr Bueso, Ingo Molnar, Juri Lelli,
Peter Zijlstra, Thomas Gleixner, Valentin Schneider,
Borislav Petkov, Waiman Long, kernel-dev, André Almeida
Instead of just checking if the syscall failed as expected, check as
well what is the error code returned, to check if it's match the
expectation and it's failing in the correct error path inside the
kernel.
Signed-off-by: André Almeida <andrealmeid@igalia.com>
---
Changes from v1:
- Use error code mnemonics instead of numberic values
---
.../futex/functional/futex_numa_mpol.c | 36 +++++++++++--------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/tools/testing/selftests/futex/functional/futex_numa_mpol.c b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
index 802c15c82190..dd7b05e8cda4 100644
--- a/tools/testing/selftests/futex/functional/futex_numa_mpol.c
+++ b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
@@ -77,7 +77,7 @@ static void join_max_threads(void)
}
}
-static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flags)
+static void __test_futex(void *futex_ptr, int err_value, unsigned int futex_flags)
{
int to_wake, ret, i, need_exit = 0;
@@ -88,11 +88,17 @@ static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flag
do {
ret = futex2_wake(futex_ptr, to_wake, futex_flags);
- if (must_fail) {
- if (ret < 0)
- break;
- ksft_exit_fail_msg("futex2_wake(%d, 0x%x) should fail, but didn't\n",
- to_wake, futex_flags);
+
+ if (err_value) {
+ if (ret >= 0)
+ ksft_exit_fail_msg("futex2_wake(%d, 0x%x) should fail, but didn't\n",
+ to_wake, futex_flags);
+
+ if (errno != err_value)
+ ksft_exit_fail_msg("futex2_wake(%d, 0x%x) expected error was %d, but returned %d (%s)\n",
+ to_wake, futex_flags, err_value, errno, strerror(errno));
+
+ break;
}
if (ret < 0) {
ksft_exit_fail_msg("Failed futex2_wake(%d, 0x%x): %m\n",
@@ -106,12 +112,12 @@ static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flag
join_max_threads();
for (i = 0; i < MAX_THREADS; i++) {
- if (must_fail && thread_args[i].result != -1) {
+ if (err_value && thread_args[i].result != -1) {
ksft_print_msg("Thread %d should fail but succeeded (%d)\n",
i, thread_args[i].result);
need_exit = 1;
}
- if (!must_fail && thread_args[i].result != 0) {
+ if (!err_value && thread_args[i].result != 0) {
ksft_print_msg("Thread %d failed (%d)\n", i, thread_args[i].result);
need_exit = 1;
}
@@ -120,14 +126,14 @@ static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flag
ksft_exit_fail_msg("Aborting due to earlier errors.\n");
}
-static void test_futex(void *futex_ptr, int must_fail)
+static void test_futex(void *futex_ptr, int err_value)
{
- __test_futex(futex_ptr, must_fail, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA);
+ __test_futex(futex_ptr, err_value, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA);
}
-static void test_futex_mpol(void *futex_ptr, int must_fail)
+static void test_futex_mpol(void *futex_ptr, int err_value)
{
- __test_futex(futex_ptr, must_fail, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA | FUTEX2_MPOL);
+ __test_futex(futex_ptr, err_value, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA | FUTEX2_MPOL);
}
static void usage(char *prog)
@@ -184,16 +190,16 @@ int main(int argc, char *argv[])
/* FUTEX2_NUMA futex must be 8-byte aligned */
ksft_print_msg("Mis-aligned futex\n");
- test_futex(futex_ptr + mem_size - 4, 1);
+ test_futex(futex_ptr + mem_size - 4, EINVAL);
futex_numa->numa = FUTEX_NO_NODE;
mprotect(futex_ptr, mem_size, PROT_READ);
ksft_print_msg("Memory, RO\n");
- test_futex(futex_ptr, 1);
+ test_futex(futex_ptr, EFAULT);
mprotect(futex_ptr, mem_size, PROT_NONE);
ksft_print_msg("Memory, no access\n");
- test_futex(futex_ptr, 1);
+ test_futex(futex_ptr, EFAULT);
mprotect(futex_ptr, mem_size, PROT_READ | PROT_WRITE);
ksft_print_msg("Memory back to RW\n");
--
2.51.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] selftest/futex: Reintroduce "Memory out of range" numa_mpol's subtest
2025-09-04 16:55 [PATCH v2 1/2] selftest/futex: Make the error check more precise for futex_numa_mpol André Almeida
@ 2025-09-04 16:55 ` André Almeida
2025-09-04 17:01 ` [PATCH v2 1/2] selftest/futex: Make the error check more precise for futex_numa_mpol Waiman Long
2025-09-15 7:51 ` Sebastian Andrzej Siewior
2 siblings, 0 replies; 6+ messages in thread
From: André Almeida @ 2025-09-04 16:55 UTC (permalink / raw)
To: Sebastian Andrzej Siewior, linux-kernel
Cc: Darren Hart, Davidlohr Bueso, Ingo Molnar, Juri Lelli,
Peter Zijlstra, Thomas Gleixner, Valentin Schneider,
Borislav Petkov, Waiman Long, kernel-dev, André Almeida
Commit d8e2f919997 ("selftests/futex: Fix some futex_numa_mpol
subtests") removed the "Memory out of range" subtest due to it being
dependent on the memory layout of the test process having an invalid
memory address just after the `*futex_ptr` allocated memory.
Reintroduce this test and make it deterministic, by allocation two
memory pages and marking the second one with PROT_NONE.
Reviewed-by: Waiman Long <longman@redhat.com>
Signed-off-by: André Almeida <andrealmeid@igalia.com>
---
Changes from v1:
- Use error code mnemonics instead of numberic values
---
.../testing/selftests/futex/functional/futex_numa_mpol.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/futex/functional/futex_numa_mpol.c b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
index dd7b05e8cda4..5f4e3111269c 100644
--- a/tools/testing/selftests/futex/functional/futex_numa_mpol.c
+++ b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
@@ -174,10 +174,13 @@ int main(int argc, char *argv[])
ksft_set_plan(1);
mem_size = sysconf(_SC_PAGE_SIZE);
- futex_ptr = mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+ futex_ptr = mmap(NULL, mem_size * 2, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
if (futex_ptr == MAP_FAILED)
ksft_exit_fail_msg("mmap() for %d bytes failed\n", mem_size);
+ /* Create an invalid memory region for the "Memory out of range" test */
+ mprotect(futex_ptr + mem_size, mem_size, PROT_NONE);
+
futex_numa = futex_ptr;
ksft_print_msg("Regular test\n");
@@ -192,6 +195,9 @@ int main(int argc, char *argv[])
ksft_print_msg("Mis-aligned futex\n");
test_futex(futex_ptr + mem_size - 4, EINVAL);
+ ksft_print_msg("Memory out of range\n");
+ test_futex(futex_ptr + mem_size, EFAULT);
+
futex_numa->numa = FUTEX_NO_NODE;
mprotect(futex_ptr, mem_size, PROT_READ);
ksft_print_msg("Memory, RO\n");
--
2.51.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] selftest/futex: Make the error check more precise for futex_numa_mpol
2025-09-04 16:55 [PATCH v2 1/2] selftest/futex: Make the error check more precise for futex_numa_mpol André Almeida
2025-09-04 16:55 ` [PATCH v2 2/2] selftest/futex: Reintroduce "Memory out of range" numa_mpol's subtest André Almeida
@ 2025-09-04 17:01 ` Waiman Long
2025-09-15 7:51 ` Sebastian Andrzej Siewior
2 siblings, 0 replies; 6+ messages in thread
From: Waiman Long @ 2025-09-04 17:01 UTC (permalink / raw)
To: André Almeida, Sebastian Andrzej Siewior, linux-kernel
Cc: Darren Hart, Davidlohr Bueso, Ingo Molnar, Juri Lelli,
Peter Zijlstra, Thomas Gleixner, Valentin Schneider,
Borislav Petkov, kernel-dev
On 9/4/25 12:55 PM, André Almeida wrote:
> Instead of just checking if the syscall failed as expected, check as
> well what is the error code returned, to check if it's match the
> expectation and it's failing in the correct error path inside the
> kernel.
>
> Signed-off-by: André Almeida <andrealmeid@igalia.com>
> ---
> Changes from v1:
> - Use error code mnemonics instead of numberic values
> ---
> .../futex/functional/futex_numa_mpol.c | 36 +++++++++++--------
> 1 file changed, 21 insertions(+), 15 deletions(-)
>
> diff --git a/tools/testing/selftests/futex/functional/futex_numa_mpol.c b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
> index 802c15c82190..dd7b05e8cda4 100644
> --- a/tools/testing/selftests/futex/functional/futex_numa_mpol.c
> +++ b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
> @@ -77,7 +77,7 @@ static void join_max_threads(void)
> }
> }
>
> -static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flags)
> +static void __test_futex(void *futex_ptr, int err_value, unsigned int futex_flags)
> {
> int to_wake, ret, i, need_exit = 0;
>
> @@ -88,11 +88,17 @@ static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flag
>
> do {
> ret = futex2_wake(futex_ptr, to_wake, futex_flags);
> - if (must_fail) {
> - if (ret < 0)
> - break;
> - ksft_exit_fail_msg("futex2_wake(%d, 0x%x) should fail, but didn't\n",
> - to_wake, futex_flags);
> +
> + if (err_value) {
> + if (ret >= 0)
> + ksft_exit_fail_msg("futex2_wake(%d, 0x%x) should fail, but didn't\n",
> + to_wake, futex_flags);
> +
> + if (errno != err_value)
> + ksft_exit_fail_msg("futex2_wake(%d, 0x%x) expected error was %d, but returned %d (%s)\n",
> + to_wake, futex_flags, err_value, errno, strerror(errno));
> +
> + break;
> }
> if (ret < 0) {
> ksft_exit_fail_msg("Failed futex2_wake(%d, 0x%x): %m\n",
> @@ -106,12 +112,12 @@ static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flag
> join_max_threads();
>
> for (i = 0; i < MAX_THREADS; i++) {
> - if (must_fail && thread_args[i].result != -1) {
> + if (err_value && thread_args[i].result != -1) {
> ksft_print_msg("Thread %d should fail but succeeded (%d)\n",
> i, thread_args[i].result);
> need_exit = 1;
> }
> - if (!must_fail && thread_args[i].result != 0) {
> + if (!err_value && thread_args[i].result != 0) {
> ksft_print_msg("Thread %d failed (%d)\n", i, thread_args[i].result);
> need_exit = 1;
> }
> @@ -120,14 +126,14 @@ static void __test_futex(void *futex_ptr, int must_fail, unsigned int futex_flag
> ksft_exit_fail_msg("Aborting due to earlier errors.\n");
> }
>
> -static void test_futex(void *futex_ptr, int must_fail)
> +static void test_futex(void *futex_ptr, int err_value)
> {
> - __test_futex(futex_ptr, must_fail, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA);
> + __test_futex(futex_ptr, err_value, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA);
> }
>
> -static void test_futex_mpol(void *futex_ptr, int must_fail)
> +static void test_futex_mpol(void *futex_ptr, int err_value)
> {
> - __test_futex(futex_ptr, must_fail, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA | FUTEX2_MPOL);
> + __test_futex(futex_ptr, err_value, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA | FUTEX2_MPOL);
> }
>
> static void usage(char *prog)
> @@ -184,16 +190,16 @@ int main(int argc, char *argv[])
>
> /* FUTEX2_NUMA futex must be 8-byte aligned */
> ksft_print_msg("Mis-aligned futex\n");
> - test_futex(futex_ptr + mem_size - 4, 1);
> + test_futex(futex_ptr + mem_size - 4, EINVAL);
>
> futex_numa->numa = FUTEX_NO_NODE;
> mprotect(futex_ptr, mem_size, PROT_READ);
> ksft_print_msg("Memory, RO\n");
> - test_futex(futex_ptr, 1);
> + test_futex(futex_ptr, EFAULT);
>
> mprotect(futex_ptr, mem_size, PROT_NONE);
> ksft_print_msg("Memory, no access\n");
> - test_futex(futex_ptr, 1);
> + test_futex(futex_ptr, EFAULT);
>
> mprotect(futex_ptr, mem_size, PROT_READ | PROT_WRITE);
> ksft_print_msg("Memory back to RW\n");
Reviewed-by: Waiman Long <longman@redhat.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] selftest/futex: Make the error check more precise for futex_numa_mpol
2025-09-04 16:55 [PATCH v2 1/2] selftest/futex: Make the error check more precise for futex_numa_mpol André Almeida
2025-09-04 16:55 ` [PATCH v2 2/2] selftest/futex: Reintroduce "Memory out of range" numa_mpol's subtest André Almeida
2025-09-04 17:01 ` [PATCH v2 1/2] selftest/futex: Make the error check more precise for futex_numa_mpol Waiman Long
@ 2025-09-15 7:51 ` Sebastian Andrzej Siewior
2025-09-15 12:58 ` André Almeida
2 siblings, 1 reply; 6+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-09-15 7:51 UTC (permalink / raw)
To: André Almeida
Cc: linux-kernel, Darren Hart, Davidlohr Bueso, Ingo Molnar,
Juri Lelli, Peter Zijlstra, Thomas Gleixner, Valentin Schneider,
Borislav Petkov, Waiman Long, kernel-dev
On 2025-09-04 13:55:55 [-0300], André Almeida wrote:
> Instead of just checking if the syscall failed as expected, check as
> well what is the error code returned, to check if it's match the
> expectation and it's failing in the correct error path inside the
> kernel.
André, these two are the only ones that are still pending?
Sebastian
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] selftest/futex: Make the error check more precise for futex_numa_mpol
2025-09-15 7:51 ` Sebastian Andrzej Siewior
@ 2025-09-15 12:58 ` André Almeida
2025-09-15 13:12 ` Sebastian Andrzej Siewior
0 siblings, 1 reply; 6+ messages in thread
From: André Almeida @ 2025-09-15 12:58 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: linux-kernel, Darren Hart, Davidlohr Bueso, Ingo Molnar,
Juri Lelli, Peter Zijlstra, Thomas Gleixner, Valentin Schneider,
Borislav Petkov, Waiman Long, kernel-dev
Hi Sebastian,
Em 15/09/2025 04:51, Sebastian Andrzej Siewior escreveu:
> On 2025-09-04 13:55:55 [-0300], André Almeida wrote:
>> Instead of just checking if the syscall failed as expected, check as
>> well what is the error code returned, to check if it's match the
>> expectation and it's failing in the correct error path inside the
>> kernel.
>
> André, these two are the only ones that are still pending?
>
For now, yes. I have more selftests cleanups that I would like to send,
but they will be done on top of those two, so I would prefer to get
those queued first.
Thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] selftest/futex: Make the error check more precise for futex_numa_mpol
2025-09-15 12:58 ` André Almeida
@ 2025-09-15 13:12 ` Sebastian Andrzej Siewior
0 siblings, 0 replies; 6+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-09-15 13:12 UTC (permalink / raw)
To: André Almeida
Cc: linux-kernel, Darren Hart, Davidlohr Bueso, Ingo Molnar,
Juri Lelli, Peter Zijlstra, Thomas Gleixner, Valentin Schneider,
Borislav Petkov, Waiman Long, kernel-dev
On 2025-09-15 09:58:11 [-0300], André Almeida wrote:
> Hi Sebastian,
Hi André,
> For now, yes. I have more selftests cleanups that I would like to send, but
> they will be done on top of those two, so I would prefer to get those queued
> first.
Thank you for the confirmation. In that case let me repost this and the
numa related patch I had and lost…
> Thanks!
Sebastian
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-09-15 13:12 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-04 16:55 [PATCH v2 1/2] selftest/futex: Make the error check more precise for futex_numa_mpol André Almeida
2025-09-04 16:55 ` [PATCH v2 2/2] selftest/futex: Reintroduce "Memory out of range" numa_mpol's subtest André Almeida
2025-09-04 17:01 ` [PATCH v2 1/2] selftest/futex: Make the error check more precise for futex_numa_mpol Waiman Long
2025-09-15 7:51 ` Sebastian Andrzej Siewior
2025-09-15 12:58 ` André Almeida
2025-09-15 13:12 ` Sebastian Andrzej Siewior
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®