[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250801153649.23244-1-zhongjinji@honor.com>
Date: Fri, 1 Aug 2025 23:36:48 +0800
From: <zhongjinji@...or.com>
To: <linux-mm@...ck.org>
CC: <akpm@...ux-foundation.org>, <mhocko@...e.com>, <rientjes@...gle.com>,
<shakeel.butt@...ux.dev>, <npache@...hat.com>,
<linux-kernel@...r.kernel.org>, <tglx@...utronix.de>, <mingo@...hat.com>,
<peterz@...radead.org>, <dvhart@...radead.org>, <dave@...olabs.net>,
<andrealmeid@...lia.com>, <liulu.liu@...or.com>, <feng.han@...or.com>
Subject: [[PATCH v2] 1/2] futex: Add check_robust_futex to verify process usage of robust_futex
From: zhongjinji <zhongjinji@...or.com>
The check_robust_futex function is added to detect whether a process uses
robust_futex.
According to the patch discussion
(https://lore.kernel.org/all/20220414144042.677008-1-npache@redhat.com/T/#u),
executing the OOM reaper too early on processes using robust_futex may cause
the lock holder to wait indefinitely.
Therefore, this patch introduces check_robust_futex to identify such
processes during OOM reaper execution, and delays the OOM reaper specifically
for processes using robust_futex.
Signed-off-by: zhongjinji <zhongjinji@...or.com>
---
include/linux/futex.h | 11 ++++++++++-
kernel/futex/core.c | 25 +++++++++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/include/linux/futex.h b/include/linux/futex.h
index 9e9750f04980..b3ce7424609d 100644
--- a/include/linux/futex.h
+++ b/include/linux/futex.h
@@ -81,7 +81,8 @@ void futex_exec_release(struct task_struct *tsk);
long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
u32 __user *uaddr2, u32 val2, u32 val3);
int futex_hash_prctl(unsigned long arg2, unsigned long arg3, unsigned long arg4);
-
+bool check_robust_futex(struct task_struct *p);
+bool __check_robust_futex(struct task_struct *p);
#ifdef CONFIG_FUTEX_PRIVATE_HASH
int futex_hash_allocate_default(void);
void futex_hash_free(struct mm_struct *mm);
@@ -108,6 +109,14 @@ static inline int futex_hash_prctl(unsigned long arg2, unsigned long arg3, unsig
{
return -EINVAL;
}
+static inline bool check_robust_futex(struct task_struct *p)
+{
+ return false;
+}
+static inline bool __check_robust_futex(struct task_struct *p)
+{
+ return false;
+}
static inline int futex_hash_allocate_default(void)
{
return 0;
diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index d9bb5567af0c..6cd385a62455 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -1513,6 +1513,31 @@ void futex_exit_release(struct task_struct *tsk)
futex_cleanup_end(tsk, FUTEX_STATE_DEAD);
}
+bool __check_robust_futex(struct task_struct *p)
+{
+ struct task_struct *t;
+
+ for_each_thread(p, t) {
+ if (unlikely(t->robust_list))
+ return true;
+#ifdef CONFIG_COMPAT
+ if (unlikely(t->compat_robust_list))
+ return true;
+#endif
+ }
+ return false;
+}
+
+bool check_robust_futex(struct task_struct *p)
+{
+ bool has_robust;
+
+ rcu_read_lock();
+ has_robust = __check_robust_futex(p);
+ rcu_read_unlock();
+ return has_robust;
+}
+
static void futex_hash_bucket_init(struct futex_hash_bucket *fhb,
struct futex_private_hash *fph)
{
--
2.17.1
Powered by blists - more mailing lists