From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Darren Hart <darren@dvhart.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
Michael Kerrisk <mtk.manpages@googlemail.com>,
Davidlohr Bueso <dave@stgolabs.net>, Chris Mason <clm@fb.com>,
"Carlos O'Donell" <carlos@redhat.com>,
Torvald Riegel <triegel@redhat.com>,
Eric Dumazet <edumazet@google.com>
Subject: [RFC patch 3/7] futex: Make key init a helper function
Date: Sat, 02 Apr 2016 11:09:17 -0000 [thread overview]
Message-ID: <20160402110035.603290841@linutronix.de> (raw)
In-Reply-To: 20160402095108.894519835@linutronix.de
[-- Attachment #1: futex--Make-key-init-a-helper-function.patch --]
[-- Type: text/plain, Size: 4876 bytes --]
Support for attached futexes requires to store information in the futex
key. Make the key init a helper function and let it return the futex uaddr.
At the call sites check the returned uaddr for NULL so the attached mode can
abort the operation when it detects that an attached operation is attempted on
a non attached futex.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
kernel/futex.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 61 insertions(+), 6 deletions(-)
Index: b/kernel/futex.c
===================================================================
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -433,6 +433,21 @@ static inline int match_futex(union fute
&& key1->both.offset == key2->both.offset);
}
+/**
+ * futex_key_init - Initialize a futex key
+ * @key: Pointer to the key to initialize
+ * @uaddr: User space address of the futex
+ * @flags: Flags to check for futex mode. Not yet used
+ *
+ * Returns: @uaddr
+ */
+static u32 __user *futex_key_init(union futex_key *key, u32 __user *uaddr,
+ unsigned int flags)
+{
+ *key = FUTEX_KEY_INIT;
+ return uaddr;
+}
+
/*
* Take a reference to the resource addressed by a key.
* Can be called while holding spinlocks.
@@ -1403,13 +1418,17 @@ futex_wake(u32 __user *uaddr, unsigned i
{
struct futex_hash_bucket *hb;
struct futex_q *this, *next;
- union futex_key key = FUTEX_KEY_INIT;
+ union futex_key key;
int ret;
WAKE_Q(wake_q);
if (!bitset)
return -EINVAL;
+ uaddr = futex_key_init(&key, uaddr, flags);
+ if (!uaddr)
+ return -EINVAL;
+
ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &key, VERIFY_READ);
if (unlikely(ret != 0))
goto out;
@@ -1455,12 +1474,20 @@ static int
futex_wake_op(u32 __user *uaddr1, unsigned int flags, u32 __user *uaddr2,
int nr_wake, int nr_wake2, int op)
{
- union futex_key key1 = FUTEX_KEY_INIT, key2 = FUTEX_KEY_INIT;
struct futex_hash_bucket *hb1, *hb2;
struct futex_q *this, *next;
+ union futex_key key1, key2;
int ret, op_ret;
WAKE_Q(wake_q);
+ uaddr1 = futex_key_init(&key1, uaddr1, flags);
+ if (!uaddr1)
+ return -EINVAL;
+
+ uaddr2 = futex_key_init(&key2, uaddr2, flags);
+ if (!uaddr2)
+ return -EINVAL;
+
retry:
ret = get_futex_key(uaddr1, flags & FLAGS_SHARED, &key1, VERIFY_READ);
if (unlikely(ret != 0))
@@ -1693,11 +1720,11 @@ static int futex_requeue(u32 __user *uad
u32 __user *uaddr2, int nr_wake, int nr_requeue,
u32 *cmpval, int requeue_pi)
{
- union futex_key key1 = FUTEX_KEY_INIT, key2 = FUTEX_KEY_INIT;
int drop_count = 0, task_count = 0, ret;
struct futex_pi_state *pi_state = NULL;
struct futex_hash_bucket *hb1, *hb2;
struct futex_q *this, *next;
+ union futex_key key1, key2;
WAKE_Q(wake_q);
if (requeue_pi) {
@@ -1728,6 +1755,14 @@ static int futex_requeue(u32 __user *uad
return -EINVAL;
}
+ uaddr1 = futex_key_init(&key1, uaddr1, flags);
+ if (!uaddr1)
+ return -EINVAL;
+
+ uaddr2 = futex_key_init(&key2, uaddr2, flags);
+ if (!uaddr2)
+ return -EINVAL;
+
retry:
ret = get_futex_key(uaddr1, flags & FLAGS_SHARED, &key1, VERIFY_READ);
if (unlikely(ret != 0))
@@ -2398,6 +2433,11 @@ static int futex_wait(u32 __user *uaddr,
if (!bitset)
return -EINVAL;
+
+ uaddr = futex_key_init(&q.key, uaddr, flags);
+ if (!uaddr)
+ return -EINVAL;
+
q.bitset = bitset;
if (abs_time) {
@@ -2498,6 +2538,10 @@ static int futex_lock_pi(u32 __user *uad
if (refill_pi_state_cache())
return -ENOMEM;
+ uaddr = futex_key_init(&q.key, uaddr, flags);
+ if (!uaddr)
+ return -EINVAL;
+
if (time) {
to = &timeout;
hrtimer_init_on_stack(&to->timer, CLOCK_REALTIME,
@@ -2617,11 +2661,14 @@ static int futex_lock_pi(u32 __user *uad
static int futex_unlock_pi(u32 __user *uaddr, unsigned int flags)
{
u32 uninitialized_var(curval), uval, vpid = task_pid_vnr(current);
- union futex_key key = FUTEX_KEY_INIT;
struct futex_hash_bucket *hb;
struct futex_q *match;
+ union futex_key key;
int ret;
+ uaddr = futex_key_init(&key, uaddr, flags);
+ if (!uaddr)
+ return -EINVAL;
retry:
if (get_user(uval, uaddr))
return -EFAULT;
@@ -2793,9 +2840,9 @@ static int futex_wait_requeue_pi(u32 __u
struct hrtimer_sleeper timeout, *to = NULL;
struct rt_mutex_waiter rt_waiter;
struct rt_mutex *pi_mutex = NULL;
- struct futex_hash_bucket *hb;
- union futex_key key2 = FUTEX_KEY_INIT;
struct futex_q q = futex_q_init;
+ struct futex_hash_bucket *hb;
+ union futex_key key2;
int res, ret;
if (uaddr == uaddr2)
@@ -2804,6 +2851,14 @@ static int futex_wait_requeue_pi(u32 __u
if (!bitset)
return -EINVAL;
+ uaddr = futex_key_init(&q.key, uaddr, flags);
+ if (!uaddr)
+ return -EINVAL;
+
+ uaddr2 = futex_key_init(&key2, uaddr2, flags);
+ if (!uaddr2)
+ return -EINVAL;
+
if (abs_time) {
to = &timeout;
hrtimer_init_on_stack(&to->timer, (flags & FLAGS_CLOCKRT) ?
next prev parent reply other threads:[~2016-04-02 11:11 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-02 11:09 [RFC patch 0/7] futex: Add support for attached futexes Thomas Gleixner
2016-04-02 11:09 ` [RFC patch 1/7] futex: Provide helpers for hash bucket add/remove Thomas Gleixner
2016-04-02 11:09 ` [RFC patch 2/7] futex: Add some more function commentry Thomas Gleixner
2016-04-02 11:09 ` Thomas Gleixner [this message]
2016-04-02 11:09 ` [RFC patch 4/7] futex: Add support for attached futexes Thomas Gleixner
2016-04-02 16:26 ` Peter Zijlstra
2016-04-02 18:01 ` Thomas Gleixner
2016-04-02 16:29 ` Peter Zijlstra
2016-04-03 9:59 ` Thomas Gleixner
2016-04-02 18:19 ` Andy Lutomirski
2016-04-03 9:57 ` Thomas Gleixner
2016-04-03 13:18 ` Andy Lutomirski
2016-04-03 15:56 ` Thomas Gleixner
2016-04-03 16:11 ` Andy Lutomirski
2016-04-02 23:48 ` Rasmus Villemoes
2016-04-03 10:05 ` Thomas Gleixner
2016-04-03 11:16 ` Ingo Molnar
2016-04-03 11:30 ` Linus Torvalds
2016-04-05 7:44 ` Torvald Riegel
2016-04-05 15:58 ` Carlos O'Donell
2016-04-02 11:09 ` [RFC patch 5/7] perf/bench/futex-hash: Support " Thomas Gleixner
2016-04-02 11:09 ` [RFC patch 6/7] futex.2: Document attached mode Thomas Gleixner
2016-04-02 11:09 ` [RFC patch 7/7] [PATCH] glibc: nptl: Add support for attached pthread_mutexes Thomas Gleixner
2016-04-02 16:30 ` Peter Zijlstra
2016-04-02 16:32 ` Peter Zijlstra
2016-04-03 10:08 ` 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=20160402110035.603290841@linutronix.de \
--to=tglx@linutronix.de \
--cc=bigeasy@linutronix.de \
--cc=carlos@redhat.com \
--cc=clm@fb.com \
--cc=darren@dvhart.com \
--cc=dave@stgolabs.net \
--cc=edumazet@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mtk.manpages@googlemail.com \
--cc=peterz@infradead.org \
--cc=triegel@redhat.com \
/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