Skip to content

Commit b7369eb

Browse files
committed
Merge tag 'locking-urgent-2025-09-07' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull locking fix from Ingo Molnar: "Fix an 'allocation from atomic context' regression in the futex vmalloc variant" * tag 'locking-urgent-2025-09-07' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: futex: Move futex_hash_free() back to __mmput()
2 parents 6a8a34a + d9b0532 commit b7369eb

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

kernel/fork.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,6 @@ void __mmdrop(struct mm_struct *mm)
689689
mm_pasid_drop(mm);
690690
mm_destroy_cid(mm);
691691
percpu_counter_destroy_many(mm->rss_stat, NR_MM_COUNTERS);
692-
futex_hash_free(mm);
693692

694693
free_mm(mm);
695694
}
@@ -1138,6 +1137,7 @@ static inline void __mmput(struct mm_struct *mm)
11381137
if (mm->binfmt)
11391138
module_put(mm->binfmt->module);
11401139
lru_gen_del_mm(mm);
1140+
futex_hash_free(mm);
11411141
mmdrop(mm);
11421142
}
11431143

kernel/futex/core.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,12 +1722,9 @@ int futex_mm_init(struct mm_struct *mm)
17221722
RCU_INIT_POINTER(mm->futex_phash, NULL);
17231723
mm->futex_phash_new = NULL;
17241724
/* futex-ref */
1725+
mm->futex_ref = NULL;
17251726
atomic_long_set(&mm->futex_atomic, 0);
17261727
mm->futex_batches = get_state_synchronize_rcu();
1727-
mm->futex_ref = alloc_percpu(unsigned int);
1728-
if (!mm->futex_ref)
1729-
return -ENOMEM;
1730-
this_cpu_inc(*mm->futex_ref); /* 0 -> 1 */
17311728
return 0;
17321729
}
17331730

@@ -1801,6 +1798,17 @@ static int futex_hash_allocate(unsigned int hash_slots, unsigned int flags)
18011798
}
18021799
}
18031800

1801+
if (!mm->futex_ref) {
1802+
/*
1803+
* This will always be allocated by the first thread and
1804+
* therefore requires no locking.
1805+
*/
1806+
mm->futex_ref = alloc_percpu(unsigned int);
1807+
if (!mm->futex_ref)
1808+
return -ENOMEM;
1809+
this_cpu_inc(*mm->futex_ref); /* 0 -> 1 */
1810+
}
1811+
18041812
fph = kvzalloc(struct_size(fph, queues, hash_slots),
18051813
GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
18061814
if (!fph)

0 commit comments

Comments
 (0)