From: Gabriel Krisman Bertazi <krisman@collabora.com>
To: tglx@linutronix.de
Cc: mingo@redhat.com, peterz@infradead.org, dvhart@infradead.org,
linux-kernel@vger.kernel.org,
Gabriel Krisman Bertazi <krisman@collabora.com>,
kernel@collabora.com
Subject: [PATCH RFC 1/2] futex: Split key setup from key queue locking and read
Date: Tue, 30 Jul 2019 18:06:01 -0400 [thread overview]
Message-ID: <20190730220602.28781-1-krisman@collabora.com> (raw)
split the futex key setup from the queue locking and key reading. This
is useful to support the setup of multiple keys at the same time, like
what is done in futex_requeue() and what will be done for the
FUTEX_WAIT_MULTIPLE command.
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
---
kernel/futex.c | 71 +++++++++++++++++++++++++++++---------------------
1 file changed, 42 insertions(+), 29 deletions(-)
diff --git a/kernel/futex.c b/kernel/futex.c
index 6d50728ef2e7..91f3db335c57 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -2631,6 +2631,39 @@ static void futex_wait_queue_me(struct futex_hash_bucket *hb, struct futex_q *q,
__set_current_state(TASK_RUNNING);
}
+static int __futex_wait_setup(u32 __user *uaddr, u32 val, unsigned int flags,
+ struct futex_q *q, struct futex_hash_bucket **hb)
+{
+
+ u32 uval;
+ int ret;
+
+retry_private:
+ *hb = queue_lock(q);
+
+ ret = get_futex_value_locked(&uval, uaddr);
+
+ if (ret) {
+ queue_unlock(*hb);
+
+ ret = get_user(uval, uaddr);
+ if (ret)
+ return ret;
+
+ if (!(flags & FLAGS_SHARED))
+ goto retry_private;
+
+ return 1;
+ }
+
+ if (uval != val) {
+ queue_unlock(*hb);
+ ret = -EWOULDBLOCK;
+ }
+
+ return ret;
+}
+
/**
* futex_wait_setup() - Prepare to wait on a futex
* @uaddr: the futex userspace address
@@ -2651,7 +2684,6 @@ static void futex_wait_queue_me(struct futex_hash_bucket *hb, struct futex_q *q,
static int futex_wait_setup(u32 __user *uaddr, u32 val, unsigned int flags,
struct futex_q *q, struct futex_hash_bucket **hb)
{
- u32 uval;
int ret;
/*
@@ -2672,38 +2704,19 @@ static int futex_wait_setup(u32 __user *uaddr, u32 val, unsigned int flags,
* absorb a wakeup if *uaddr does not match the desired values
* while the syscall executes.
*/
-retry:
- ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q->key, FUTEX_READ);
- if (unlikely(ret != 0))
- return ret;
-
-retry_private:
- *hb = queue_lock(q);
+ do {
+ ret = get_futex_key(uaddr, flags & FLAGS_SHARED,
+ &q->key, FUTEX_READ);
+ if (unlikely(ret != 0))
+ return ret;
- ret = get_futex_value_locked(&uval, uaddr);
+ ret = __futex_wait_setup(uaddr, val, flags, q, hb);
- if (ret) {
- queue_unlock(*hb);
-
- ret = get_user(uval, uaddr);
+ /* Drop key reference if retry or error. */
if (ret)
- goto out;
+ put_futex_key(&q->key);
+ } while (ret > 0);
- if (!(flags & FLAGS_SHARED))
- goto retry_private;
-
- put_futex_key(&q->key);
- goto retry;
- }
-
- if (uval != val) {
- queue_unlock(*hb);
- ret = -EWOULDBLOCK;
- }
-
-out:
- if (ret)
- put_futex_key(&q->key);
return ret;
}
--
2.20.1
next reply other threads:[~2019-07-30 22:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-30 22:06 Gabriel Krisman Bertazi [this message]
2019-07-30 22:06 ` [PATCH RFC 2/2] futex: Implement mechanism to wait on any of several futexes Gabriel Krisman Bertazi
2019-07-31 12:06 ` Peter Zijlstra
2019-07-31 15:15 ` Zebediah Figura
2019-07-31 22:39 ` Thomas Gleixner
2019-07-31 23:02 ` Zebediah Figura
2019-08-06 6:26 ` Gabriel Krisman Bertazi
2019-08-06 10:13 ` Peter Zijlstra
2019-08-01 0:45 ` Thomas Gleixner
2019-08-01 1:22 ` Zebediah Figura
2019-08-01 1:32 ` Zebediah Figura
2019-08-01 1:42 ` Pierre-Loup A. Griffais
2019-07-31 23:33 ` [PATCH RFC 1/2] futex: Split key setup from key queue locking and read Thomas Gleixner
2019-08-01 0:07 ` Gabriel Krisman Bertazi
2019-08-01 0:22 ` Gabriel Krisman Bertazi
2019-08-01 0:41 ` Thomas Gleixner
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=20190730220602.28781-1-krisman@collabora.com \
--to=krisman@collabora.com \
--cc=dvhart@infradead.org \
--cc=kernel@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--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