Skip to contentSkip to conversation

futex: Move drop_futex_key_refs out of spinlock'ed region

PATCH In review Darren Hart 1 participant 2 messages Oct 15, 2009 – Oct 16, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 futex: Move drop_futex_key_refs out of spinlock'ed region

Quoted 1 line

From edd4dea2dfb706d34a42255f424781f9daa79f01 Mon Sep 17 00:00:00 2001

From: Helge Bahmann <[email protected]>
Date: Mon, 12 Oct 2009 11:31:35 +0200
Subject: [PATCH] Move drop_futex_key_refs out of spinlock'ed region

When requeuing tasks from one futex to another, the reference held by the requeued task to the original futex location needs to be dropped eventually. Dropping the reference may ultimately lead to a call to "iput_final" and subsequently call into filesystem- specific code. It is therefore safer to defer this drop operation until after the futex_hash_bucket spinlock has been dropped.

Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
CC Eric Dumazet <[email protected]>
CC Dinakar Guniguntala <[email protected]>
CC John Stultz <[email protected]>
CC Sven-Thorsten Dietrich <[email protected]>
CC John Kacur <[email protected]>

---
kernel/futex.c | 3 ++-

1 files changed, 2 insertions(+), 1 deletions(-)
kernel/futex.c +0 -0
index 4949d33..f49bf07 100644
@@ -1028,7 +1028,6 @@ static inline

void requeue_pi_wake_futex(struct futex_q *q, union futex_key *key,
struct futex_hash_bucket *hb)
{

-	drop_futex_key_refs(&q->key);
	get_futex_key_refs(key);
	q->key = *key;

@@ -1226,6 +1225,7 @@ retry_private:

		 */
		if (ret == 1) {
			WARN_ON(pi_state);
+			drop_count++;
			task_count++;
			ret = get_futex_value_locked(&curval2, uaddr2);
			if (!ret)
@@ -1304,6 +1304,7 @@ retry_private:
			if (ret == 1) {
				/* We got the lock. */
				requeue_pi_wake_futex(this, &key2, hb2);
+				drop_count++;
				continue;
			} else if (ret) {
				/* -EDEADLK */
Signature · 7 lines
1.5.6.5


-- 
Darren Hart
IBM Linux Technology Center
Real-Time Linux Team
#1 lore raw
Commit-ID:  89061d3d58e1f0742139605dc6a7950aa1ecc019
Gitweb:     http://git.kernel.org/tip/89061d3d58e1f0742139605dc6a7950aa1ecc019
Author:     Darren Hart <[email protected]>
AuthorDate: Thu, 15 Oct 2009 15:30:48 -0700
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 16 Oct 2009 10:19:18 +0200

futex: Move drop_futex_key_refs out of spinlock'ed region

When requeuing tasks from one futex to another, the reference held by the requeued task to the original futex location needs to be dropped eventually.

Dropping the reference may ultimately lead to a call to "iput_final" and subsequently call into filesystem- specific code - which may be non-atomic.

It is therefore safer to defer this drop operation until after the futex_hash_bucket spinlock has been dropped.

Originally-From: Helge Bahmann <[email protected]>

Cc Peter Zijlstra <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Dinakar Guniguntala <[email protected]>
Cc John Stultz <[email protected]>
Cc Sven-Thorsten Dietrich <[email protected]>
Cc John Kacur <[email protected]>

LKML-Reference: <[email protected]>

---
 kernel/futex.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/futex.c +2 -1
index 06938e5..642f3bb 100644
@@ -1029,7 +1029,6 @@ static inline
 void requeue_pi_wake_futex(struct futex_q *q, union futex_key *key,
 			   struct futex_hash_bucket *hb)
 {
-	drop_futex_key_refs(&q->key);
 	get_futex_key_refs(key);
 	q->key = *key;
 
@@ -1227,6 +1226,7 @@ retry_private:
 		 */
 		if (ret == 1) {
 			WARN_ON(pi_state);
+			drop_count++;
 			task_count++;
 			ret = get_futex_value_locked(&curval2, uaddr2);
 			if (!ret)
@@ -1305,6 +1305,7 @@ retry_private:
 			if (ret == 1) {
 				/* We got the lock. */
 				requeue_pi_wake_futex(this, &key2, hb2);
+				drop_count++;
 				continue;
 			} else if (ret) {
 				/* -EDEADLK */