Skip to content

Commit aff2a7e

Browse files
committed
Merge tag 'locking_urgent_for_v6.16_rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull locking fixes from Borislav Petkov: - Make sure the switch to the global hash is requested always under a lock so that two threads requesting that simultaneously cannot get to inconsistent state - Reject negative NUMA nodes earlier in the futex NUMA interface handling code - Selftests fixes * tag 'locking_urgent_for_v6.16_rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: futex: Verify under the lock if hash can be replaced futex: Handle invalid node numbers supplied by user selftests/futex: Set the home_node in futex_numa_mpol selftests/futex: getopt() requires int as return value.
2 parents 73543ba + 69a14d1 commit aff2a7e

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

kernel/futex/core.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,8 @@ int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key,
583583
if (futex_get_value(&node, naddr))
584584
return -EFAULT;
585585

586-
if (node != FUTEX_NO_NODE &&
587-
(node >= MAX_NUMNODES || !node_possible(node)))
586+
if ((node != FUTEX_NO_NODE) &&
587+
((unsigned int)node >= MAX_NUMNODES || !node_possible(node)))
588588
return -EINVAL;
589589
}
590590

@@ -1629,6 +1629,16 @@ static int futex_hash_allocate(unsigned int hash_slots, unsigned int flags)
16291629
mm->futex_phash_new = NULL;
16301630

16311631
if (fph) {
1632+
if (cur && (!cur->hash_mask || cur->immutable)) {
1633+
/*
1634+
* If two threads simultaneously request the global
1635+
* hash then the first one performs the switch,
1636+
* the second one returns here.
1637+
*/
1638+
free = fph;
1639+
mm->futex_phash_new = new;
1640+
return -EBUSY;
1641+
}
16321642
if (cur && !new) {
16331643
/*
16341644
* If we have an existing hash, but do not yet have

tools/testing/selftests/futex/functional/futex_numa_mpol.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ int main(int argc, char *argv[])
144144
struct futex32_numa *futex_numa;
145145
int mem_size, i;
146146
void *futex_ptr;
147-
char c;
147+
int c;
148148

149149
while ((c = getopt(argc, argv, "chv:")) != -1) {
150150
switch (c) {
@@ -210,6 +210,10 @@ int main(int argc, char *argv[])
210210
ret = mbind(futex_ptr, mem_size, MPOL_BIND, &nodemask,
211211
sizeof(nodemask) * 8, 0);
212212
if (ret == 0) {
213+
ret = numa_set_mempolicy_home_node(futex_ptr, mem_size, i, 0);
214+
if (ret != 0)
215+
ksft_exit_fail_msg("Failed to set home node: %m, %d\n", errno);
216+
213217
ksft_print_msg("Node %d test\n", i);
214218
futex_numa->futex = 0;
215219
futex_numa->numa = FUTEX_NO_NODE;
@@ -220,8 +224,8 @@ int main(int argc, char *argv[])
220224
if (0)
221225
test_futex_mpol(futex_numa, 0);
222226
if (futex_numa->numa != i) {
223-
ksft_test_result_fail("Returned NUMA node is %d expected %d\n",
224-
futex_numa->numa, i);
227+
ksft_exit_fail_msg("Returned NUMA node is %d expected %d\n",
228+
futex_numa->numa, i);
225229
}
226230
}
227231
}

tools/testing/selftests/futex/functional/futex_priv_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int main(int argc, char *argv[])
130130
pthread_mutexattr_t mutex_attr_pi;
131131
int use_global_hash = 0;
132132
int ret;
133-
char c;
133+
int c;
134134

135135
while ((c = getopt(argc, argv, "cghv:")) != -1) {
136136
switch (c) {

0 commit comments

Comments
 (0)