mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] futex: Fixups for the testsuite and FUTEX_NUMA
@ 2025-05-28  8:55 Sebastian Andrzej Siewior
  2025-05-28  8:55 ` [PATCH 1/3] selftests/futex: getopt() requires int as return value Sebastian Andrzej Siewior
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-05-28  8:55 UTC (permalink / raw)
  To: linux-kernel
  Cc: André Almeida, Darren Hart, Davidlohr Bueso, Ingo Molnar,
	Juri Lelli, Peter Zijlstra, Thomas Gleixner, Valentin Schneider,
	Waiman Long, Sebastian Andrzej Siewior

This is a collection of random fixes related to the recent private
futex/ NUMA addition:

 - Some of the test fail on ARM due bad command line parsing.

 - The MPOL test fails because the home node was never set.

 - The syzbot used a negative NODE number which was not tested for.

Peter Zijlstra (1):
  futex: Handle invalid node numbers supplied by user

Sebastian Andrzej Siewior (2):
  selftests/futex: getopt() requires int as return value.
  selftests/futex: Set the home_node in futex_numa_mpol

 kernel/futex/core.c                                    |  4 ++--
 .../selftests/futex/functional/futex_numa_mpol.c       | 10 +++++++---
 .../selftests/futex/functional/futex_priv_hash.c       |  2 +-
 3 files changed, 10 insertions(+), 6 deletions(-)

-- 
2.49.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] selftests/futex: getopt() requires int as return value.
  2025-05-28  8:55 [PATCH 0/3] futex: Fixups for the testsuite and FUTEX_NUMA Sebastian Andrzej Siewior
@ 2025-05-28  8:55 ` Sebastian Andrzej Siewior
  2025-06-11  9:20   ` [tip: locking/urgent] " tip-bot2 for Sebastian Andrzej Siewior
  2025-05-28  8:55 ` [PATCH 2/3] selftests/futex: Set the home_node in futex_numa_mpol Sebastian Andrzej Siewior
  2025-05-28  8:55 ` [PATCH 3/3] futex: Handle invalid node numbers supplied by user Sebastian Andrzej Siewior
  2 siblings, 1 reply; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-05-28  8:55 UTC (permalink / raw)
  To: linux-kernel
  Cc: André Almeida, Darren Hart, Davidlohr Bueso, Ingo Molnar,
	Juri Lelli, Peter Zijlstra, Thomas Gleixner, Valentin Schneider,
	Waiman Long, Sebastian Andrzej Siewior, Mark Brown

Mark reported that futex_priv_hash fails on ARM64.
It turns out that the command line parsing does not terminate properly
and ends in the default case assuming an invalid option was passed.

Use an int as the return type for getopt().

Reported-by: Mark Brown <broonie@kernel.org>
Closes: https://lore.kernel.org/all/31869a69-063f-44a3-a079-ba71b2506cce@sirena.org.uk/
Fixes: 3163369407baf ("selftests/futex: Add futex_numa_mpol")
Fixes: cda95faef7bcf ("selftests/futex: Add futex_priv_hash")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 tools/testing/selftests/futex/functional/futex_numa_mpol.c | 2 +-
 tools/testing/selftests/futex/functional/futex_priv_hash.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/futex/functional/futex_numa_mpol.c b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
index 20a9d3ecf7433..564dbd02d2f46 100644
--- a/tools/testing/selftests/futex/functional/futex_numa_mpol.c
+++ b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
@@ -144,7 +144,7 @@ int main(int argc, char *argv[])
 	struct futex32_numa *futex_numa;
 	int mem_size, i;
 	void *futex_ptr;
-	char c;
+	int c;
 
 	while ((c = getopt(argc, argv, "chv:")) != -1) {
 		switch (c) {
diff --git a/tools/testing/selftests/futex/functional/futex_priv_hash.c b/tools/testing/selftests/futex/functional/futex_priv_hash.c
index 2dca18fefedcd..24a92dc94eb86 100644
--- a/tools/testing/selftests/futex/functional/futex_priv_hash.c
+++ b/tools/testing/selftests/futex/functional/futex_priv_hash.c
@@ -130,7 +130,7 @@ int main(int argc, char *argv[])
 	pthread_mutexattr_t mutex_attr_pi;
 	int use_global_hash = 0;
 	int ret;
-	char c;
+	int c;
 
 	while ((c = getopt(argc, argv, "cghv:")) != -1) {
 		switch (c) {
-- 
2.49.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/3] selftests/futex: Set the home_node in futex_numa_mpol
  2025-05-28  8:55 [PATCH 0/3] futex: Fixups for the testsuite and FUTEX_NUMA Sebastian Andrzej Siewior
  2025-05-28  8:55 ` [PATCH 1/3] selftests/futex: getopt() requires int as return value Sebastian Andrzej Siewior
@ 2025-05-28  8:55 ` Sebastian Andrzej Siewior
  2025-06-11  9:20   ` [tip: locking/urgent] " tip-bot2 for Sebastian Andrzej Siewior
  2025-05-28  8:55 ` [PATCH 3/3] futex: Handle invalid node numbers supplied by user Sebastian Andrzej Siewior
  2 siblings, 1 reply; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-05-28  8:55 UTC (permalink / raw)
  To: linux-kernel
  Cc: André Almeida, Darren Hart, Davidlohr Bueso, Ingo Molnar,
	Juri Lelli, Peter Zijlstra, Thomas Gleixner, Valentin Schneider,
	Waiman Long, Sebastian Andrzej Siewior, Vlastimil Babka

The test fails at the MPOL step if multiple nodes are available. The
reason is that mbind() sets the policy but the home_node, which is
retrieved by the futex code, is not set. This causes to retrieve the
current node and with multiple nodes it fails on one of the iterations.

Use numa_set_mempolicy_home_node() to set the expected node.
Use ksft_exit_fail_msg() to fail and exit in order not to confuse ktap.

Fixes: 3163369407baf ("selftests/futex: Add futex_numa_mpol")
Suggested-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 .../testing/selftests/futex/functional/futex_numa_mpol.c  | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/futex/functional/futex_numa_mpol.c b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
index 564dbd02d2f46..a9ecfb2d3932a 100644
--- a/tools/testing/selftests/futex/functional/futex_numa_mpol.c
+++ b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
@@ -210,6 +210,10 @@ int main(int argc, char *argv[])
 		ret = mbind(futex_ptr, mem_size, MPOL_BIND, &nodemask,
 			    sizeof(nodemask) * 8, 0);
 		if (ret == 0) {
+			ret = numa_set_mempolicy_home_node(futex_ptr, mem_size, i, 0);
+			if (ret != 0)
+				ksft_exit_fail_msg("Failed to set home node: %m, %d\n", errno);
+
 			ksft_print_msg("Node %d test\n", i);
 			futex_numa->futex = 0;
 			futex_numa->numa = FUTEX_NO_NODE;
@@ -220,8 +224,8 @@ int main(int argc, char *argv[])
 			if (0)
 				test_futex_mpol(futex_numa, 0);
 			if (futex_numa->numa != i) {
-				ksft_test_result_fail("Returned NUMA node is %d expected %d\n",
-						      futex_numa->numa, i);
+				ksft_exit_fail_msg("Returned NUMA node is %d expected %d\n",
+						   futex_numa->numa, i);
 			}
 		}
 	}
-- 
2.49.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/3] futex: Handle invalid node numbers supplied by user
  2025-05-28  8:55 [PATCH 0/3] futex: Fixups for the testsuite and FUTEX_NUMA Sebastian Andrzej Siewior
  2025-05-28  8:55 ` [PATCH 1/3] selftests/futex: getopt() requires int as return value Sebastian Andrzej Siewior
  2025-05-28  8:55 ` [PATCH 2/3] selftests/futex: Set the home_node in futex_numa_mpol Sebastian Andrzej Siewior
@ 2025-05-28  8:55 ` Sebastian Andrzej Siewior
  2025-06-11  9:20   ` [tip: locking/urgent] " tip-bot2 for Peter Zijlstra
  2 siblings, 1 reply; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-05-28  8:55 UTC (permalink / raw)
  To: linux-kernel
  Cc: André Almeida, Darren Hart, Davidlohr Bueso, Ingo Molnar,
	Juri Lelli, Peter Zijlstra, Thomas Gleixner, Valentin Schneider,
	Waiman Long, syzbot+9afaf6749e3a7aa1bdf3,
	Sebastian Andrzej Siewior

From: Peter Zijlstra <peterz@infradead.org>

syzbot used a negative node number which was not rejected early and led
to invalid memory access in node_possible().

Reject negative node numbers except for FUTEX_NO_NODE.

[bigeasy: Keep the FUTEX_NO_NODE check]

Reported-by: syzbot+9afaf6749e3a7aa1bdf3@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/6835bfe3.a70a0220.253bc2.00b5.GAE@google.com/
Fixes: cec199c5e39bd ("futex: Implement FUTEX2_NUMA")
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 kernel/futex/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index 19a2c65f3d373..1cd3a646c91fd 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -583,8 +583,8 @@ int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key,
 		if (futex_get_value(&node, naddr))
 			return -EFAULT;
 
-		if (node != FUTEX_NO_NODE &&
-		    (node >= MAX_NUMNODES || !node_possible(node)))
+		if ((node != FUTEX_NO_NODE) &&
+		    ((unsigned int)node >= MAX_NUMNODES || !node_possible(node)))
 			return -EINVAL;
 	}
 
-- 
2.49.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [tip: locking/urgent] futex: Handle invalid node numbers supplied by user
  2025-05-28  8:55 ` [PATCH 3/3] futex: Handle invalid node numbers supplied by user Sebastian Andrzej Siewior
@ 2025-06-11  9:20   ` tip-bot2 for Peter Zijlstra
  0 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Peter Zijlstra @ 2025-06-11  9:20 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Peter Zijlstra (Intel),
	syzbot+9afaf6749e3a7aa1bdf3, Sebastian Andrzej Siewior, x86,
	linux-kernel

The following commit has been merged into the locking/urgent branch of tip:

Commit-ID:     8337204c58899fe422db765b481711eb2d95eb0b
Gitweb:        https://git.kernel.org/tip/8337204c58899fe422db765b481711eb2d95eb0b
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Wed, 28 May 2025 10:55:21 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Thu, 05 Jun 2025 14:37:58 +02:00

futex: Handle invalid node numbers supplied by user

syzbot used a negative node number which was not rejected early and led
to invalid memory access in node_possible().

Reject negative node numbers except for FUTEX_NO_NODE.

[bigeasy: Keep the FUTEX_NO_NODE check]

Closes: https://lore.kernel.org/all/6835bfe3.a70a0220.253bc2.00b5.GAE@google.com/
Fixes: cec199c5e39bd ("futex: Implement FUTEX2_NUMA")
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reported-by: syzbot+9afaf6749e3a7aa1bdf3@syzkaller.appspotmail.com
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20250528085521.1938355-4-bigeasy@linutronix.de
---
 kernel/futex/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index 565f971..b652d2f 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -583,8 +583,8 @@ int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key,
 		if (futex_get_value(&node, naddr))
 			return -EFAULT;
 
-		if (node != FUTEX_NO_NODE &&
-		    (node >= MAX_NUMNODES || !node_possible(node)))
+		if ((node != FUTEX_NO_NODE) &&
+		    ((unsigned int)node >= MAX_NUMNODES || !node_possible(node)))
 			return -EINVAL;
 	}
 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [tip: locking/urgent] selftests/futex: Set the home_node in futex_numa_mpol
  2025-05-28  8:55 ` [PATCH 2/3] selftests/futex: Set the home_node in futex_numa_mpol Sebastian Andrzej Siewior
@ 2025-06-11  9:20   ` tip-bot2 for Sebastian Andrzej Siewior
  0 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2025-06-11  9:20 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Vlastimil Babka, Sebastian Andrzej Siewior,
	Peter Zijlstra (Intel),
	x86, linux-kernel

The following commit has been merged into the locking/urgent branch of tip:

Commit-ID:     0ecb4232fc65e659ca7020f8bb2e0fc347acfb7d
Gitweb:        https://git.kernel.org/tip/0ecb4232fc65e659ca7020f8bb2e0fc347acfb7d
Author:        Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate:    Wed, 28 May 2025 10:55:20 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Thu, 05 Jun 2025 14:37:58 +02:00

selftests/futex: Set the home_node in futex_numa_mpol

The test fails at the MPOL step if multiple nodes are available. The
reason is that mbind() sets the policy but the home_node, which is
retrieved by the futex code, is not set. This causes to retrieve the
current node and with multiple nodes it fails on one of the iterations.

Use numa_set_mempolicy_home_node() to set the expected node.
Use ksft_exit_fail_msg() to fail and exit in order not to confuse ktap.

Fixes: 3163369407baf ("selftests/futex: Add futex_numa_mpol")
Suggested-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20250528085521.1938355-3-bigeasy@linutronix.de
---
 tools/testing/selftests/futex/functional/futex_numa_mpol.c | 8 +++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/futex/functional/futex_numa_mpol.c b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
index 564dbd0..a9ecfb2 100644
--- a/tools/testing/selftests/futex/functional/futex_numa_mpol.c
+++ b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
@@ -210,6 +210,10 @@ int main(int argc, char *argv[])
 		ret = mbind(futex_ptr, mem_size, MPOL_BIND, &nodemask,
 			    sizeof(nodemask) * 8, 0);
 		if (ret == 0) {
+			ret = numa_set_mempolicy_home_node(futex_ptr, mem_size, i, 0);
+			if (ret != 0)
+				ksft_exit_fail_msg("Failed to set home node: %m, %d\n", errno);
+
 			ksft_print_msg("Node %d test\n", i);
 			futex_numa->futex = 0;
 			futex_numa->numa = FUTEX_NO_NODE;
@@ -220,8 +224,8 @@ int main(int argc, char *argv[])
 			if (0)
 				test_futex_mpol(futex_numa, 0);
 			if (futex_numa->numa != i) {
-				ksft_test_result_fail("Returned NUMA node is %d expected %d\n",
-						      futex_numa->numa, i);
+				ksft_exit_fail_msg("Returned NUMA node is %d expected %d\n",
+						   futex_numa->numa, i);
 			}
 		}
 	}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [tip: locking/urgent] selftests/futex: getopt() requires int as return value.
  2025-05-28  8:55 ` [PATCH 1/3] selftests/futex: getopt() requires int as return value Sebastian Andrzej Siewior
@ 2025-06-11  9:20   ` tip-bot2 for Sebastian Andrzej Siewior
  0 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2025-06-11  9:20 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Mark Brown, Sebastian Andrzej Siewior, Peter Zijlstra (Intel),
	x86, linux-kernel

The following commit has been merged into the locking/urgent branch of tip:

Commit-ID:     1a9dcf69c7a97e733aa2fc026db22f22928ca7b7
Gitweb:        https://git.kernel.org/tip/1a9dcf69c7a97e733aa2fc026db22f22928ca7b7
Author:        Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate:    Wed, 28 May 2025 10:55:19 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Thu, 05 Jun 2025 14:37:58 +02:00

selftests/futex: getopt() requires int as return value.

Mark reported that futex_priv_hash fails on ARM64.
It turns out that the command line parsing does not terminate properly
and ends in the default case assuming an invalid option was passed.

Use an int as the return type for getopt().

Closes: https://lore.kernel.org/all/31869a69-063f-44a3-a079-ba71b2506cce@sirena.org.uk/
Fixes: 3163369407baf ("selftests/futex: Add futex_numa_mpol")
Fixes: cda95faef7bcf ("selftests/futex: Add futex_priv_hash")
Reported-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20250528085521.1938355-2-bigeasy@linutronix.de
---
 tools/testing/selftests/futex/functional/futex_numa_mpol.c | 2 +-
 tools/testing/selftests/futex/functional/futex_priv_hash.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/futex/functional/futex_numa_mpol.c b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
index 20a9d3e..564dbd0 100644
--- a/tools/testing/selftests/futex/functional/futex_numa_mpol.c
+++ b/tools/testing/selftests/futex/functional/futex_numa_mpol.c
@@ -144,7 +144,7 @@ int main(int argc, char *argv[])
 	struct futex32_numa *futex_numa;
 	int mem_size, i;
 	void *futex_ptr;
-	char c;
+	int c;
 
 	while ((c = getopt(argc, argv, "chv:")) != -1) {
 		switch (c) {
diff --git a/tools/testing/selftests/futex/functional/futex_priv_hash.c b/tools/testing/selftests/futex/functional/futex_priv_hash.c
index 2dca18f..24a92dc 100644
--- a/tools/testing/selftests/futex/functional/futex_priv_hash.c
+++ b/tools/testing/selftests/futex/functional/futex_priv_hash.c
@@ -130,7 +130,7 @@ int main(int argc, char *argv[])
 	pthread_mutexattr_t mutex_attr_pi;
 	int use_global_hash = 0;
 	int ret;
-	char c;
+	int c;
 
 	while ((c = getopt(argc, argv, "cghv:")) != -1) {
 		switch (c) {

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-06-11  9:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-28  8:55 [PATCH 0/3] futex: Fixups for the testsuite and FUTEX_NUMA Sebastian Andrzej Siewior
2025-05-28  8:55 ` [PATCH 1/3] selftests/futex: getopt() requires int as return value Sebastian Andrzej Siewior
2025-06-11  9:20   ` [tip: locking/urgent] " tip-bot2 for Sebastian Andrzej Siewior
2025-05-28  8:55 ` [PATCH 2/3] selftests/futex: Set the home_node in futex_numa_mpol Sebastian Andrzej Siewior
2025-06-11  9:20   ` [tip: locking/urgent] " tip-bot2 for Sebastian Andrzej Siewior
2025-05-28  8:55 ` [PATCH 3/3] futex: Handle invalid node numbers supplied by user Sebastian Andrzej Siewior
2025-06-11  9:20   ` [tip: locking/urgent] " tip-bot2 for Peter Zijlstra

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®