]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
futex: Remove support for IMMUTABLE
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Thu, 10 Jul 2025 11:00:09 +0000 (13:00 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 11 Jul 2025 14:02:01 +0000 (16:02 +0200)
The FH_FLAG_IMMUTABLE flag was meant to avoid the reference counting on
the private hash and so to avoid the performance regression on big
machines.
With the switch to per-CPU counter this is no longer needed. That flag
was never useable on any released kernel.

Remove any support for IMMUTABLE while preserve the flags argument and
enforce it to be zero.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250710110011.384614-5-bigeasy@linutronix.de
include/uapi/linux/prctl.h
kernel/futex/core.c

index 43dec6eed559a68685fb03e659859bd2c4ee3395..3b93fb906e3c51a963e16f8fa60b072285d62473 100644 (file)
@@ -367,8 +367,6 @@ struct prctl_mm_map {
 /* FUTEX hash management */
 #define PR_FUTEX_HASH                  78
 # define PR_FUTEX_HASH_SET_SLOTS       1
-# define FH_FLAG_IMMUTABLE             (1ULL << 0)
 # define PR_FUTEX_HASH_GET_SLOTS       2
-# define PR_FUTEX_HASH_GET_IMMUTABLE   3
 
 #endif /* _LINUX_PRCTL_H */
index 1981574a459d5916390cbbbcd0bc98a235fd1abd..d9bb5567af0c5c350fb7724928bb7a4c2b37a7f6 100644 (file)
@@ -69,7 +69,6 @@ struct futex_private_hash {
        struct rcu_head rcu;
        void            *mm;
        bool            custom;
-       bool            immutable;
        struct futex_hash_bucket queues[];
 };
 
@@ -145,15 +144,11 @@ static inline bool futex_key_is_private(union futex_key *key)
 
 static bool futex_private_hash_get(struct futex_private_hash *fph)
 {
-       if (fph->immutable)
-               return true;
        return futex_ref_get(fph);
 }
 
 void futex_private_hash_put(struct futex_private_hash *fph)
 {
-       if (fph->immutable)
-               return;
        if (futex_ref_put(fph))
                wake_up_var(fph->mm);
 }
@@ -1530,7 +1525,6 @@ static void futex_hash_bucket_init(struct futex_hash_bucket *fhb,
 }
 
 #define FH_CUSTOM      0x01
-#define FH_IMMUTABLE   0x02
 
 #ifdef CONFIG_FUTEX_PRIVATE_HASH
 
@@ -1800,7 +1794,7 @@ static int futex_hash_allocate(unsigned int hash_slots, unsigned int flags)
         */
        scoped_guard(rcu) {
                fph = rcu_dereference(mm->futex_phash);
-               if (fph && (!fph->hash_mask || fph->immutable)) {
+               if (fph && !fph->hash_mask) {
                        if (custom)
                                return -EBUSY;
                        return 0;
@@ -1814,7 +1808,6 @@ static int futex_hash_allocate(unsigned int hash_slots, unsigned int flags)
 
        fph->hash_mask = hash_slots ? hash_slots - 1 : 0;
        fph->custom = custom;
-       fph->immutable = !!(flags & FH_IMMUTABLE);
        fph->mm = mm;
 
        for (i = 0; i < hash_slots; i++)
@@ -1838,7 +1831,7 @@ again:
                mm->futex_phash_new = NULL;
 
                if (fph) {
-                       if (cur && (!cur->hash_mask || cur->immutable)) {
+                       if (cur && !cur->hash_mask) {
                                /*
                                 * If two threads simultaneously request the global
                                 * hash then the first one performs the switch,
@@ -1931,19 +1924,6 @@ static int futex_hash_get_slots(void)
        return 0;
 }
 
-static int futex_hash_get_immutable(void)
-{
-       struct futex_private_hash *fph;
-
-       guard(rcu)();
-       fph = rcu_dereference(current->mm->futex_phash);
-       if (fph && fph->immutable)
-               return 1;
-       if (fph && !fph->hash_mask)
-               return 1;
-       return 0;
-}
-
 #else
 
 static int futex_hash_allocate(unsigned int hash_slots, unsigned int flags)
@@ -1956,10 +1936,6 @@ static int futex_hash_get_slots(void)
        return 0;
 }
 
-static int futex_hash_get_immutable(void)
-{
-       return 0;
-}
 #endif
 
 int futex_hash_prctl(unsigned long arg2, unsigned long arg3, unsigned long arg4)
@@ -1969,10 +1945,8 @@ int futex_hash_prctl(unsigned long arg2, unsigned long arg3, unsigned long arg4)
 
        switch (arg2) {
        case PR_FUTEX_HASH_SET_SLOTS:
-               if (arg4 & ~FH_FLAG_IMMUTABLE)
+               if (arg4)
                        return -EINVAL;
-               if (arg4 & FH_FLAG_IMMUTABLE)
-                       flags |= FH_IMMUTABLE;
                ret = futex_hash_allocate(arg3, flags);
                break;
 
@@ -1980,10 +1954,6 @@ int futex_hash_prctl(unsigned long arg2, unsigned long arg3, unsigned long arg4)
                ret = futex_hash_get_slots();
                break;
 
-       case PR_FUTEX_HASH_GET_IMMUTABLE:
-               ret = futex_hash_get_immutable();
-               break;
-
        default:
                ret = -EINVAL;
                break;