From: Waiman Long <longman@redhat.com>
The "Memory out of range" subtest of futex_numa_mpol assumes that memory
access outside of the mmap'ed area is invalid. That may not be the case
depending on the actual memory layout of the test application. When
that subtest was run on an x86-64 system with latest upstream kernel,
the test passed as an error was returned from futex_wake(). On another
powerpc system, the same subtest failed because futex_wake() returned 0.
Bail out! futex2_wake(64, 0x86) should fail, but didn't
Looking further into the passed subtest on x86-64, it was found that an
-EINVAL was returned instead of -EFAULT. The -EINVAL error was returned
because the node value test with FLAGS_NUMA set failed with a node value
of 0x7f7f. IOW, the futex memory was accessible and futex_wake() failed
because the supposed node number wasn't valid. If that memory location
happens to have a very small value (e.g. 0), the test will pass and no
error will be returned.
Since this subtest is non-deterministic, it is dropped unless we
explicitly set a guard page beyond the mmap region.
The other problematic test is the "Memory too small" test. The
futex_wake() function returns the -EINVAL error code because the given
futex address isn't 8-byte aligned, not because only 4 of the 8 bytes
are valid and the other 4 bytes are not. So proper name of this subtest
is changed to "Mis-aligned futex" to reflect the reality.
Fixes: 3163369407ba ("selftests/futex: Add futex_numa_mpol")
Signed-off-by: Waiman Long <longman@redhat.com>
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://lore.kernel.org/r/20250810222742.290485-1-longman@redhat.com
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
tools/testing/selftests/futex/functional/futex_numa_mpol.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/futex/functional/futex_numa_mpol.c b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
index a9ecfb2d3932a..802c15c821906 100644
--- a/tools/testing/selftests/futex/functional/futex_numa_mpol.c
+++ b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
@@ -182,12 +182,10 @@ int main(int argc, char *argv[])
if (futex_numa->numa == FUTEX_NO_NODE)
ksft_exit_fail_msg("NUMA node is left uninitialized\n");
- ksft_print_msg("Memory too small\n");
+ /* FUTEX2_NUMA futex must be 8-byte aligned */
+ ksft_print_msg("Mis-aligned futex\n");
test_futex(futex_ptr + mem_size - 4, 1);
- ksft_print_msg("Memory out of range\n");
- test_futex(futex_ptr + mem_size, 1);
-
futex_numa->numa = FUTEX_NO_NODE;
mprotect(futex_ptr, mem_size, PROT_READ);
ksft_print_msg("Memory, RO\n");
--
2.50.1
Em 27/08/2025 10:00, Sebastian Andrzej Siewior escreveu: > From: Waiman Long <longman@redhat.com> > > The "Memory out of range" subtest of futex_numa_mpol assumes that memory > access outside of the mmap'ed area is invalid. That may not be the case > depending on the actual memory layout of the test application. When > that subtest was run on an x86-64 system with latest upstream kernel, > the test passed as an error was returned from futex_wake(). On another > powerpc system, the same subtest failed because futex_wake() returned 0. > > Bail out! futex2_wake(64, 0x86) should fail, but didn't > > Looking further into the passed subtest on x86-64, it was found that an > -EINVAL was returned instead of -EFAULT. The -EINVAL error was returned > because the node value test with FLAGS_NUMA set failed with a node value > of 0x7f7f. IOW, the futex memory was accessible and futex_wake() failed > because the supposed node number wasn't valid. If that memory location > happens to have a very small value (e.g. 0), the test will pass and no > error will be returned. > > Since this subtest is non-deterministic, it is dropped unless we > explicitly set a guard page beyond the mmap region. > > The other problematic test is the "Memory too small" test. The > futex_wake() function returns the -EINVAL error code because the given > futex address isn't 8-byte aligned, not because only 4 of the 8 bytes > are valid and the other 4 bytes are not. So proper name of this subtest > is changed to "Mis-aligned futex" to reflect the reality. > As we discussed in the original patch thread[1], I have a proposal for this test case to be refactored instead of being removed. I will send a patch for this in a bit. [1] https://lore.kernel.org/all/336a1a43-54ac-4f53-b3a8-5e46f6d45359@igalia.com/
On 2025-08-27 12:40:26 [-0300], André Almeida wrote: > As we discussed in the original patch thread[1], I have a proposal for this > test case to be refactored instead of being removed. I will send a patch for > this in a bit. As per https://lore.kernel.org/all/c61e7737-bfc7-4de8-962e-652aa3dbfd40@igalia.com/ André does not object getting in the -rc cycle. I would prefer this now and the rework for the merge window. If you prefer to wait for it and delay it until the next -rc release, be my guest. Sebastian
The following commit has been merged into the locking/futex branch of tip:
Commit-ID: d8e2f919997b14665e4509ef9a5278f291598d6e
Gitweb: https://git.kernel.org/tip/d8e2f919997b14665e4509ef9a5278f291598d6e
Author: Waiman Long <longman@redhat.com>
AuthorDate: Wed, 27 Aug 2025 15:00:08 +02:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Mon, 01 Sep 2025 16:12:54 +02:00
selftests/futex: Fix some futex_numa_mpol subtests
The "Memory out of range" subtest of futex_numa_mpol assumes that memory
access outside of the mmap'ed area is invalid. That may not be the case
depending on the actual memory layout of the test application. When that
subtest was run on an x86-64 system with latest upstream kernel, the test
passed as an error was returned from futex_wake(). On another PowerPC system,
the same subtest failed because futex_wake() returned 0.
Bail out! futex2_wake(64, 0x86) should fail, but didn't
Looking further into the passed subtest on x86-64, it was found that an
-EINVAL was returned instead of -EFAULT. The -EINVAL error was returned
because the node value test with FLAGS_NUMA set failed with a node value
of 0x7f7f. IOW, the futex memory was accessible and futex_wake() failed
because the supposed node number wasn't valid. If that memory location
happens to have a very small value (e.g. 0), the test will pass and no
error will be returned.
Since this subtest is non-deterministic, drop it unless a guard page beyond
the mmap region is explicitly set.
The other problematic test is the "Memory too small" test. The futex_wake()
function returns the -EINVAL error code because the given futex address isn't
8-byte aligned, not because only 4 of the 8 bytes are valid and the other
4 bytes are not. So change the name of this subtest to "Mis-aligned futex" to
reflect the reality.
[ bp: Massage commit message. ]
Fixes: 3163369407ba ("selftests/futex: Add futex_numa_mpol")
Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://lore.kernel.org/20250827130011.677600-3-bigeasy@linutronix.de
---
tools/testing/selftests/futex/functional/futex_numa_mpol.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/futex/functional/futex_numa_mpol.c b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
index a9ecfb2..802c15c 100644
--- a/tools/testing/selftests/futex/functional/futex_numa_mpol.c
+++ b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
@@ -182,12 +182,10 @@ int main(int argc, char *argv[])
if (futex_numa->numa == FUTEX_NO_NODE)
ksft_exit_fail_msg("NUMA node is left uninitialized\n");
- ksft_print_msg("Memory too small\n");
+ /* FUTEX2_NUMA futex must be 8-byte aligned */
+ ksft_print_msg("Mis-aligned futex\n");
test_futex(futex_ptr + mem_size - 4, 1);
- ksft_print_msg("Memory out of range\n");
- test_futex(futex_ptr + mem_size, 1);
-
futex_numa->numa = FUTEX_NO_NODE;
mprotect(futex_ptr, mem_size, PROT_READ);
ksft_print_msg("Memory, RO\n");
© 2016 - 2025 Red Hat, Inc.