From: <zhongjinji@honor.com>
To: <linux-mm@kvack.org>
Cc: <akpm@linux-foundation.org>, <mhocko@suse.com>,
<rientjes@google.com>, <shakeel.butt@linux.dev>,
<npache@redhat.com>, <linux-kernel@vger.kernel.org>,
<tglx@linutronix.de>, <mingo@redhat.com>, <peterz@infradead.org>,
<dvhart@infradead.org>, <dave@stgolabs.net>,
<andrealmeid@igalia.com>, <liulu.liu@honor.com>,
<feng.han@honor.com>
Subject: [[PATCH v2] 1/2] futex: Add check_robust_futex to verify process usage of robust_futex
Date: Fri, 1 Aug 2025 23:36:48 +0800 [thread overview]
Message-ID: <20250801153649.23244-1-zhongjinji@honor.com> (raw)
From: zhongjinji <zhongjinji@honor.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@honor.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
next reply other threads:[~2025-08-01 15:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-01 15:36 zhongjinji [this message]
2025-08-01 15:36 ` [[PATCH v2] 2/2] futex: Only delay OOM reaper for processes using robust futex zhongjinji
2025-08-04 5:52 ` Michal Hocko
2025-08-04 11:50 ` zhongjinji
2025-08-04 12:01 ` Michal Hocko
2025-08-05 6:18 ` Michal Hocko
2025-08-05 14:55 ` zhongjinji
2025-08-05 13:19 ` zhongjinji
2025-08-05 16:02 ` [[PATCH v2] 1/2] futex: Add check_robust_futex to verify process usage of robust_futex Thomas Gleixner
2025-08-12 13:21 ` zhongjinji
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250801153649.23244-1-zhongjinji@honor.com \
--to=zhongjinji@honor.com \
--cc=akpm@linux-foundation.org \
--cc=andrealmeid@igalia.com \
--cc=dave@stgolabs.net \
--cc=dvhart@infradead.org \
--cc=feng.han@honor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liulu.liu@honor.com \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=npache@redhat.com \
--cc=peterz@infradead.org \
--cc=rientjes@google.com \
--cc=shakeel.butt@linux.dev \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox