From: Waiman Long <Waiman.Long@hpe.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Jonathan Corbet <corbet@lwn.net>
Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Davidlohr Bueso <dave@stgolabs.net>,
Mike Galbraith <umgwanakikbuti@gmail.com>,
Jason Low <jason.low2@hpe.com>,
Scott J Norton <scott.norton@hpe.com>,
Douglas Hatch <doug.hatch@hpe.com>,
Waiman Long <Waiman.Long@hpe.com>
Subject: [PATCH v3 05/13] futex: Add a new futex type field into futex_state
Date: Fri, 30 Sep 2016 17:26:14 -0400 [thread overview]
Message-ID: <1475270782-51720-6-git-send-email-Waiman.Long@hpe.com> (raw)
In-Reply-To: <1475270782-51720-1-git-send-email-Waiman.Long@hpe.com>
As the futex_state structure will be overloaded in later patches
to be used by non-PI futexes, it is necessary to add a type field to
distinguish among different types of futexes.
Signed-off-by: Waiman Long <Waiman.Long@hpe.com>
---
kernel/futex.c | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/kernel/futex.c b/kernel/futex.c
index 0d1b1be..a496c01 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -191,6 +191,10 @@ int __read_mostly futex_cmpxchg_enabled;
#define FLAGS_CLOCKRT 0x02
#define FLAGS_HAS_TIMEOUT 0x04
+enum futex_type {
+ TYPE_PI = 0,
+};
+
/*
* Futex state object:
* - Priority Inheritance state
@@ -210,6 +214,7 @@ struct futex_state {
struct task_struct *owner;
atomic_t refcount;
+ enum futex_type type;
union futex_key key;
};
@@ -897,10 +902,10 @@ static void put_futex_state(struct futex_state *state)
return;
/*
- * If state->owner is NULL, the owner is most probably dying
- * and has cleaned up the futex state already
+ * If state->owner is NULL and the type is TYPE_PI, the owner is
+ * most probably dying and has cleaned up the futex state already
*/
- if (state->owner) {
+ if (state->owner && (state->type == TYPE_PI)) {
task_pi_list_del(state->owner, state, false);
rt_mutex_proxy_unlock(&state->pi_mutex, state->owner);
@@ -1056,7 +1061,7 @@ static int attach_to_pi_state(u32 uval, struct futex_state *pi_state,
/*
* Userspace might have messed up non-PI and PI futexes [3]
*/
- if (unlikely(!pi_state))
+ if (unlikely(!pi_state || (pi_state->type != TYPE_PI)))
return -EINVAL;
WARN_ON(!atomic_read(&pi_state->refcount));
@@ -1174,6 +1179,7 @@ static int attach_to_pi_owner(u32 uval, union futex_key *key,
/* Store the key for possible exit cleanups: */
pi_state->key = *key;
+ pi_state->type = TYPE_PI;
WARN_ON(!list_empty(&pi_state->list));
list_add(&pi_state->list, &p->pi_state_list);
--
1.7.1
next prev parent reply other threads:[~2016-09-30 21:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-30 21:26 [PATCH v3 00/13] futex: Introducing throughput-optimized futexes Waiman Long
2016-09-30 21:26 ` [PATCH v3 01/13] futex: Consolidate duplicated timer setup code Waiman Long
2016-09-30 21:26 ` [PATCH v3 02/13] futex: Rename futex_pi_state to futex_state Waiman Long
2016-09-30 21:26 ` [PATCH v3 03/13] futex: Add helpers to get & cmpxchg futex value without lock Waiman Long
2016-09-30 21:26 ` [PATCH v3 04/13] futex: Consolidate pure pi_state_list add & delete codes to helpers Waiman Long
2016-09-30 21:26 ` Waiman Long [this message]
2016-09-30 21:26 ` [PATCH v3 06/13] futex: Allow direct attachment of futex_state objects to hash bucket Waiman Long
2016-09-30 21:26 ` [PATCH v3 07/13] futex: Throughput-optimized (TP) futexes Waiman Long
2016-10-01 6:47 ` Thomas Gleixner
2016-10-02 1:12 ` Waiman Long
2016-09-30 21:26 ` [PATCH v3 08/13] futex: Enable robust handling of TP futexes Waiman Long
2016-09-30 21:26 ` [PATCH v3 09/13] futex: Implement lock handoff for TP futexes to prevent lock starvation Waiman Long
2016-09-30 21:26 ` [PATCH v3 10/13] futex: Inform FUTEX_LOCK callers on how the lock is acquired Waiman Long
2016-09-30 21:26 ` [PATCH v3 11/13] futex: Add timeout support to TP futexes Waiman Long
2016-09-30 21:26 ` [PATCH v3 12/13] futex, doc: TP futexes document Waiman Long
2016-09-30 21:26 ` [PATCH v3 13/13] perf bench: New microbenchmark for userspace mutex performance Waiman Long
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=1475270782-51720-6-git-send-email-Waiman.Long@hpe.com \
--to=waiman.long@hpe.com \
--cc=acme@kernel.org \
--cc=corbet@lwn.net \
--cc=dave@stgolabs.net \
--cc=doug.hatch@hpe.com \
--cc=jason.low2@hpe.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=scott.norton@hpe.com \
--cc=tglx@linutronix.de \
--cc=umgwanakikbuti@gmail.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
all inboxes | Powered by JetHome®