From: Ben Hutchings <ben@decadent.org.uk>
To: stable@vger.kernel.org
Cc: Lee Jones <lee.jones@linaro.org>,
"Luis Claudio R. Goncalves" <lgoncalv@redhat.com>
Subject: [PATCH 4.9 2/7] futex: Cleanup refcounting
Date: Mon, 1 Mar 2021 18:31:22 +0100 [thread overview]
Message-ID: <YD0k6ppZS2lYYEqg@decadent.org.uk> (raw)
In-Reply-To: <YD0kv9H996Tkhg2o@decadent.org.uk>
[-- Attachment #1: Type: text/plain, Size: 2456 bytes --]
From: Peter Zijlstra <peterz@infradead.org>
commit bf92cf3a5100f5a0d5f9834787b130159397cb22 upstream.
Add a put_pit_state() as counterpart for get_pi_state() so the refcounting
becomes consistent.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: juri.lelli@arm.com
Cc: bigeasy@linutronix.de
Cc: xlpang@redhat.com
Cc: rostedt@goodmis.org
Cc: mathieu.desnoyers@efficios.com
Cc: jdesfossez@efficios.com
Cc: dvhart@infradead.org
Cc: bristot@redhat.com
Link: http://lkml.kernel.org/r/20170322104151.801778516@infradead.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
kernel/futex.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/kernel/futex.c b/kernel/futex.c
index 1cb5064548d6..bf410a4fab71 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -827,7 +827,7 @@ static int refill_pi_state_cache(void)
return 0;
}
-static struct futex_pi_state * alloc_pi_state(void)
+static struct futex_pi_state *alloc_pi_state(void)
{
struct futex_pi_state *pi_state = current->pi_state_cache;
@@ -860,6 +860,11 @@ static void pi_state_update_owner(struct futex_pi_state *pi_state,
}
}
+static void get_pi_state(struct futex_pi_state *pi_state)
+{
+ WARN_ON_ONCE(!atomic_inc_not_zero(&pi_state->refcount));
+}
+
/*
* Drops a reference to the pi_state object and frees or caches it
* when the last reference is gone.
@@ -901,7 +906,7 @@ static void put_pi_state(struct futex_pi_state *pi_state)
* Look up the task based on what TID userspace gave us.
* We dont trust it.
*/
-static struct task_struct * futex_find_get_task(pid_t pid)
+static struct task_struct *futex_find_get_task(pid_t pid)
{
struct task_struct *p;
@@ -1149,7 +1154,7 @@ static int attach_to_pi_state(u32 __user *uaddr, u32 uval,
goto out_einval;
out_attach:
- atomic_inc(&pi_state->refcount);
+ get_pi_state(pi_state);
raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
*ps = pi_state;
return 0;
@@ -2210,7 +2215,7 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
* refcount on the pi_state and store the pointer in
* the futex_q object of the waiter.
*/
- atomic_inc(&pi_state->refcount);
+ get_pi_state(pi_state);
this->pi_state = pi_state;
ret = rt_mutex_start_proxy_lock(&pi_state->pi_mutex,
this->rt_waiter,
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2021-03-01 17:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-01 17:30 [PATCH 4.9 1/7] futex: Cleanup variable names for futex_top_waiter() Ben Hutchings
2021-03-01 17:31 ` Ben Hutchings [this message]
2021-03-01 17:31 ` [PATCH 4.9 3/7] futex: Pull rt_mutex_futex_unlock() out from under hb->lock Ben Hutchings
2021-03-01 17:31 ` [PATCH 4.9 4/7] futex: Futex_unlock_pi() determinism Ben Hutchings
2021-03-01 17:31 ` [PATCH 4.9 5/7] futex: Fix pi_state->owner serialization Ben Hutchings
2021-03-01 17:31 ` [PATCH 4.9 6/7] futex: Fix more put_pi_state() vs. exit_pi_state_list() races Ben Hutchings
2021-03-01 17:32 ` [PATCH 4.9 7/7] futex: Don't enable IRQs unconditionally in put_pi_state() Ben Hutchings
2021-03-04 13:11 ` [PATCH 4.9 1/7] futex: Cleanup variable names for futex_top_waiter() Greg KH
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=YD0k6ppZS2lYYEqg@decadent.org.uk \
--to=ben@decadent.org.uk \
--cc=lee.jones@linaro.org \
--cc=lgoncalv@redhat.com \
--cc=stable@vger.kernel.org \
/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