[RFC patch 1/5] futex: Misc cleanups

2013-11-25 Thread Thomas Gleixner
From: Jason Low 

- Remove unnecessary head variables.
- Delete unused parameter in queue_unlock().

Signed-off-by: Jason Low 
Signed-off-by: Davidlohr Bueso 
Link: http://lkml.kernel.org/r/1385168197-8612-2-git-send-email-davidl...@hp.com
Signed-off-by: Thomas Gleixner 
---
 kernel/futex.c |   40 
 1 file changed, 12 insertions(+), 28 deletions(-)

Index: linux-2.6/kernel/futex.c
===
--- linux-2.6.orig/kernel/futex.c
+++ linux-2.6/kernel/futex.c
@@ -597,13 +597,10 @@ lookup_pi_state(u32 uval, struct futex_h
 {
struct futex_pi_state *pi_state = NULL;
struct futex_q *this, *next;
-   struct plist_head *head;
struct task_struct *p;
pid_t pid = uval & FUTEX_TID_MASK;
 
-   head = >chain;
-
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, >chain, list) {
if (match_futex(>key, key)) {
/*
 * Another waiter already exists - bump up
@@ -985,7 +982,6 @@ futex_wake(u32 __user *uaddr, unsigned i
 {
struct futex_hash_bucket *hb;
struct futex_q *this, *next;
-   struct plist_head *head;
union futex_key key = FUTEX_KEY_INIT;
int ret;
 
@@ -998,9 +994,8 @@ futex_wake(u32 __user *uaddr, unsigned i
 
hb = hash_futex();
spin_lock(>lock);
-   head = >chain;
 
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, >chain, list) {
if (match_futex (>key, )) {
if (this->pi_state || this->rt_waiter) {
ret = -EINVAL;
@@ -1033,7 +1028,6 @@ futex_wake_op(u32 __user *uaddr1, unsign
 {
union futex_key key1 = FUTEX_KEY_INIT, key2 = FUTEX_KEY_INIT;
struct futex_hash_bucket *hb1, *hb2;
-   struct plist_head *head;
struct futex_q *this, *next;
int ret, op_ret;
 
@@ -1081,9 +1075,7 @@ retry_private:
goto retry;
}
 
-   head = >chain;
-
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, >chain, list) {
if (match_futex (>key, )) {
if (this->pi_state || this->rt_waiter) {
ret = -EINVAL;
@@ -1096,10 +1088,8 @@ retry_private:
}
 
if (op_ret > 0) {
-   head = >chain;
-
op_ret = 0;
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, >chain, list) {
if (match_futex (>key, )) {
if (this->pi_state || this->rt_waiter) {
ret = -EINVAL;
@@ -1269,7 +1259,6 @@ static int futex_requeue(u32 __user *uad
int drop_count = 0, task_count = 0, ret;
struct futex_pi_state *pi_state = NULL;
struct futex_hash_bucket *hb1, *hb2;
-   struct plist_head *head1;
struct futex_q *this, *next;
u32 curval2;
 
@@ -1392,8 +1381,7 @@ retry_private:
}
}
 
-   head1 = >chain;
-   plist_for_each_entry_safe(this, next, head1, list) {
+   plist_for_each_entry_safe(this, next, >chain, list) {
if (task_count - nr_wake >= nr_requeue)
break;
 
@@ -1492,8 +1480,7 @@ static inline struct futex_hash_bucket *
return hb;
 }
 
-static inline void
-queue_unlock(struct futex_q *q, struct futex_hash_bucket *hb)
+static inline void queue_unlock(struct futex_hash_bucket *hb)
__releases(>lock)
 {
spin_unlock(>lock);
@@ -1866,7 +1853,7 @@ retry_private:
ret = get_futex_value_locked(, uaddr);
 
if (ret) {
-   queue_unlock(q, *hb);
+   queue_unlock(*hb);
 
ret = get_user(uval, uaddr);
if (ret)
@@ -1880,7 +1867,7 @@ retry_private:
}
 
if (uval != val) {
-   queue_unlock(q, *hb);
+   queue_unlock(*hb);
ret = -EWOULDBLOCK;
}
 
@@ -2028,7 +2015,7 @@ retry_private:
 * Task is exiting and we just wait for the
 * exit to complete.
 */
-   queue_unlock(, hb);
+   queue_unlock(hb);
put_futex_key();
cond_resched();
goto retry;
@@ -2080,7 +2067,7 @@ retry_private:
goto out_put_key;
 
 out_unlock_put_key:
-   queue_unlock(, hb);
+   queue_unlock(hb);
 
 out_put_key:
put_futex_key();
@@ -2090,7 +2077,7 @@ out:
return ret != -EINTR ? ret : -ERESTARTNOINTR;
 
 uaddr_faulted:
-   queue_unlock(, hb);
+   queue_unlock(hb);
 
ret = fault_in_user_writeable(uaddr);
if (ret)
@@ 

[RFC patch 1/5] futex: Misc cleanups

2013-11-25 Thread Thomas Gleixner
From: Jason Low jason.l...@hp.com

- Remove unnecessary head variables.
- Delete unused parameter in queue_unlock().

Signed-off-by: Jason Low jason.l...@hp.com
Signed-off-by: Davidlohr Bueso davidl...@hp.com
Link: http://lkml.kernel.org/r/1385168197-8612-2-git-send-email-davidl...@hp.com
Signed-off-by: Thomas Gleixner t...@linutronix.de
---
 kernel/futex.c |   40 
 1 file changed, 12 insertions(+), 28 deletions(-)

Index: linux-2.6/kernel/futex.c
===
--- linux-2.6.orig/kernel/futex.c
+++ linux-2.6/kernel/futex.c
@@ -597,13 +597,10 @@ lookup_pi_state(u32 uval, struct futex_h
 {
struct futex_pi_state *pi_state = NULL;
struct futex_q *this, *next;
-   struct plist_head *head;
struct task_struct *p;
pid_t pid = uval  FUTEX_TID_MASK;
 
-   head = hb-chain;
-
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, hb-chain, list) {
if (match_futex(this-key, key)) {
/*
 * Another waiter already exists - bump up
@@ -985,7 +982,6 @@ futex_wake(u32 __user *uaddr, unsigned i
 {
struct futex_hash_bucket *hb;
struct futex_q *this, *next;
-   struct plist_head *head;
union futex_key key = FUTEX_KEY_INIT;
int ret;
 
@@ -998,9 +994,8 @@ futex_wake(u32 __user *uaddr, unsigned i
 
hb = hash_futex(key);
spin_lock(hb-lock);
-   head = hb-chain;
 
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, hb-chain, list) {
if (match_futex (this-key, key)) {
if (this-pi_state || this-rt_waiter) {
ret = -EINVAL;
@@ -1033,7 +1028,6 @@ futex_wake_op(u32 __user *uaddr1, unsign
 {
union futex_key key1 = FUTEX_KEY_INIT, key2 = FUTEX_KEY_INIT;
struct futex_hash_bucket *hb1, *hb2;
-   struct plist_head *head;
struct futex_q *this, *next;
int ret, op_ret;
 
@@ -1081,9 +1075,7 @@ retry_private:
goto retry;
}
 
-   head = hb1-chain;
-
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, hb1-chain, list) {
if (match_futex (this-key, key1)) {
if (this-pi_state || this-rt_waiter) {
ret = -EINVAL;
@@ -1096,10 +1088,8 @@ retry_private:
}
 
if (op_ret  0) {
-   head = hb2-chain;
-
op_ret = 0;
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, hb2-chain, list) {
if (match_futex (this-key, key2)) {
if (this-pi_state || this-rt_waiter) {
ret = -EINVAL;
@@ -1269,7 +1259,6 @@ static int futex_requeue(u32 __user *uad
int drop_count = 0, task_count = 0, ret;
struct futex_pi_state *pi_state = NULL;
struct futex_hash_bucket *hb1, *hb2;
-   struct plist_head *head1;
struct futex_q *this, *next;
u32 curval2;
 
@@ -1392,8 +1381,7 @@ retry_private:
}
}
 
-   head1 = hb1-chain;
-   plist_for_each_entry_safe(this, next, head1, list) {
+   plist_for_each_entry_safe(this, next, hb1-chain, list) {
if (task_count - nr_wake = nr_requeue)
break;
 
@@ -1492,8 +1480,7 @@ static inline struct futex_hash_bucket *
return hb;
 }
 
-static inline void
-queue_unlock(struct futex_q *q, struct futex_hash_bucket *hb)
+static inline void queue_unlock(struct futex_hash_bucket *hb)
__releases(hb-lock)
 {
spin_unlock(hb-lock);
@@ -1866,7 +1853,7 @@ retry_private:
ret = get_futex_value_locked(uval, uaddr);
 
if (ret) {
-   queue_unlock(q, *hb);
+   queue_unlock(*hb);
 
ret = get_user(uval, uaddr);
if (ret)
@@ -1880,7 +1867,7 @@ retry_private:
}
 
if (uval != val) {
-   queue_unlock(q, *hb);
+   queue_unlock(*hb);
ret = -EWOULDBLOCK;
}
 
@@ -2028,7 +2015,7 @@ retry_private:
 * Task is exiting and we just wait for the
 * exit to complete.
 */
-   queue_unlock(q, hb);
+   queue_unlock(hb);
put_futex_key(q.key);
cond_resched();
goto retry;
@@ -2080,7 +2067,7 @@ retry_private:
goto out_put_key;
 
 out_unlock_put_key:
-   queue_unlock(q, hb);
+   queue_unlock(hb);
 
 out_put_key:
put_futex_key(q.key);
@@ -2090,7 +2077,7 @@ out:
return ret != -EINTR ? ret : -ERESTARTNOINTR;
 
 

Re: [PATCH 1/5] futex: Misc cleanups

2013-11-22 Thread Darren Hart
On Fri, 2013-11-22 at 16:56 -0800, Davidlohr Bueso wrote:
> From: Jason Low 
> 
> - Remove unnecessary head variables.
> - Delete unused parameter in queue_unlock().
> 
> Cc: Ingo Molnar 
> Cc: Darren Hart 
> Cc: Peter Zijlstra 
> Cc: Thomas Gleixner 
> Cc: Mike Galbraith 
> Cc: Jeff Mahoney 
> Cc: Linus Torvalds 
> Cc: Scott Norton 
> Cc: Tom Vaden 
> Cc: Aswin Chandramouleeswaran 
> Cc: Waiman Long 
> Signed-off-by: Jason Low 
> Signed-off-by: Davidlohr Bueso 

My concern was that we saved off head for a reason, but the hb lock is
held in these cases, and the call is safe against removal, so I don't
see a problem. Thanks.

Reviewed-by: Darren Hart 

-- 
Darren Hart
Intel Open Source Technology Center
Yocto Project - Linux Kernel


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/5] futex: Misc cleanups

2013-11-22 Thread Davidlohr Bueso
From: Jason Low 

- Remove unnecessary head variables.
- Delete unused parameter in queue_unlock().

Cc: Ingo Molnar 
Cc: Darren Hart 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Mike Galbraith 
Cc: Jeff Mahoney 
Cc: Linus Torvalds 
Cc: Scott Norton 
Cc: Tom Vaden 
Cc: Aswin Chandramouleeswaran 
Cc: Waiman Long 
Signed-off-by: Jason Low 
Signed-off-by: Davidlohr Bueso 
---
 kernel/futex.c | 39 ---
 1 file changed, 12 insertions(+), 27 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 80ba086..e6ffe73 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -597,13 +597,10 @@ lookup_pi_state(u32 uval, struct futex_hash_bucket *hb,
 {
struct futex_pi_state *pi_state = NULL;
struct futex_q *this, *next;
-   struct plist_head *head;
struct task_struct *p;
pid_t pid = uval & FUTEX_TID_MASK;
 
-   head = >chain;
-
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, >chain, list) {
if (match_futex(>key, key)) {
/*
 * Another waiter already exists - bump up
@@ -985,7 +982,6 @@ futex_wake(u32 __user *uaddr, unsigned int flags, int 
nr_wake, u32 bitset)
 {
struct futex_hash_bucket *hb;
struct futex_q *this, *next;
-   struct plist_head *head;
union futex_key key = FUTEX_KEY_INIT;
int ret;
 
@@ -998,9 +994,8 @@ futex_wake(u32 __user *uaddr, unsigned int flags, int 
nr_wake, u32 bitset)
 
hb = hash_futex();
spin_lock(>lock);
-   head = >chain;
 
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, >chain, list) {
if (match_futex (>key, )) {
if (this->pi_state || this->rt_waiter) {
ret = -EINVAL;
@@ -1033,7 +1028,6 @@ futex_wake_op(u32 __user *uaddr1, unsigned int flags, u32 
__user *uaddr2,
 {
union futex_key key1 = FUTEX_KEY_INIT, key2 = FUTEX_KEY_INIT;
struct futex_hash_bucket *hb1, *hb2;
-   struct plist_head *head;
struct futex_q *this, *next;
int ret, op_ret;
 
@@ -1081,9 +1075,7 @@ retry_private:
goto retry;
}
 
-   head = >chain;
-
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, >chain, list) {
if (match_futex (>key, )) {
if (this->pi_state || this->rt_waiter) {
ret = -EINVAL;
@@ -1096,10 +1088,8 @@ retry_private:
}
 
if (op_ret > 0) {
-   head = >chain;
-
op_ret = 0;
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, >chain, list) {
if (match_futex (>key, )) {
if (this->pi_state || this->rt_waiter) {
ret = -EINVAL;
@@ -1269,7 +1259,6 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int 
flags,
int drop_count = 0, task_count = 0, ret;
struct futex_pi_state *pi_state = NULL;
struct futex_hash_bucket *hb1, *hb2;
-   struct plist_head *head1;
struct futex_q *this, *next;
u32 curval2;
 
@@ -1392,8 +1381,7 @@ retry_private:
}
}
 
-   head1 = >chain;
-   plist_for_each_entry_safe(this, next, head1, list) {
+   plist_for_each_entry_safe(this, next, >chain, list) {
if (task_count - nr_wake >= nr_requeue)
break;
 
@@ -1493,7 +1481,7 @@ static inline struct futex_hash_bucket *queue_lock(struct 
futex_q *q)
 }
 
 static inline void
-queue_unlock(struct futex_q *q, struct futex_hash_bucket *hb)
+queue_unlock(struct futex_hash_bucket *hb)
__releases(>lock)
 {
spin_unlock(>lock);
@@ -1866,7 +1854,7 @@ retry_private:
ret = get_futex_value_locked(, uaddr);
 
if (ret) {
-   queue_unlock(q, *hb);
+   queue_unlock(*hb);
 
ret = get_user(uval, uaddr);
if (ret)
@@ -1880,7 +1868,7 @@ retry_private:
}
 
if (uval != val) {
-   queue_unlock(q, *hb);
+   queue_unlock(*hb);
ret = -EWOULDBLOCK;
}
 
@@ -2028,7 +2016,7 @@ retry_private:
 * Task is exiting and we just wait for the
 * exit to complete.
 */
-   queue_unlock(, hb);
+   queue_unlock(hb);
put_futex_key();
cond_resched();
goto retry;
@@ -2080,7 +2068,7 @@ retry_private:
goto out_put_key;
 
 out_unlock_put_key:
-   queue_unlock(, hb);
+   queue_unlock(hb);
 
 out_put_key:
put_futex_key();
@@ -2090,7 +2078,7 @@ out:

[PATCH 1/5] futex: Misc cleanups

2013-11-22 Thread Davidlohr Bueso
From: Jason Low jason.l...@hp.com

- Remove unnecessary head variables.
- Delete unused parameter in queue_unlock().

Cc: Ingo Molnar mi...@kernel.org
Cc: Darren Hart dvh...@linux.intel.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Mike Galbraith efa...@gmx.de
Cc: Jeff Mahoney je...@suse.com
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Scott Norton scott.nor...@hp.com
Cc: Tom Vaden tom.va...@hp.com
Cc: Aswin Chandramouleeswaran as...@hp.com
Cc: Waiman Long waiman.l...@hp.com
Signed-off-by: Jason Low jason.l...@hp.com
Signed-off-by: Davidlohr Bueso davidl...@hp.com
---
 kernel/futex.c | 39 ---
 1 file changed, 12 insertions(+), 27 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 80ba086..e6ffe73 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -597,13 +597,10 @@ lookup_pi_state(u32 uval, struct futex_hash_bucket *hb,
 {
struct futex_pi_state *pi_state = NULL;
struct futex_q *this, *next;
-   struct plist_head *head;
struct task_struct *p;
pid_t pid = uval  FUTEX_TID_MASK;
 
-   head = hb-chain;
-
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, hb-chain, list) {
if (match_futex(this-key, key)) {
/*
 * Another waiter already exists - bump up
@@ -985,7 +982,6 @@ futex_wake(u32 __user *uaddr, unsigned int flags, int 
nr_wake, u32 bitset)
 {
struct futex_hash_bucket *hb;
struct futex_q *this, *next;
-   struct plist_head *head;
union futex_key key = FUTEX_KEY_INIT;
int ret;
 
@@ -998,9 +994,8 @@ futex_wake(u32 __user *uaddr, unsigned int flags, int 
nr_wake, u32 bitset)
 
hb = hash_futex(key);
spin_lock(hb-lock);
-   head = hb-chain;
 
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, hb-chain, list) {
if (match_futex (this-key, key)) {
if (this-pi_state || this-rt_waiter) {
ret = -EINVAL;
@@ -1033,7 +1028,6 @@ futex_wake_op(u32 __user *uaddr1, unsigned int flags, u32 
__user *uaddr2,
 {
union futex_key key1 = FUTEX_KEY_INIT, key2 = FUTEX_KEY_INIT;
struct futex_hash_bucket *hb1, *hb2;
-   struct plist_head *head;
struct futex_q *this, *next;
int ret, op_ret;
 
@@ -1081,9 +1075,7 @@ retry_private:
goto retry;
}
 
-   head = hb1-chain;
-
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, hb1-chain, list) {
if (match_futex (this-key, key1)) {
if (this-pi_state || this-rt_waiter) {
ret = -EINVAL;
@@ -1096,10 +1088,8 @@ retry_private:
}
 
if (op_ret  0) {
-   head = hb2-chain;
-
op_ret = 0;
-   plist_for_each_entry_safe(this, next, head, list) {
+   plist_for_each_entry_safe(this, next, hb2-chain, list) {
if (match_futex (this-key, key2)) {
if (this-pi_state || this-rt_waiter) {
ret = -EINVAL;
@@ -1269,7 +1259,6 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int 
flags,
int drop_count = 0, task_count = 0, ret;
struct futex_pi_state *pi_state = NULL;
struct futex_hash_bucket *hb1, *hb2;
-   struct plist_head *head1;
struct futex_q *this, *next;
u32 curval2;
 
@@ -1392,8 +1381,7 @@ retry_private:
}
}
 
-   head1 = hb1-chain;
-   plist_for_each_entry_safe(this, next, head1, list) {
+   plist_for_each_entry_safe(this, next, hb1-chain, list) {
if (task_count - nr_wake = nr_requeue)
break;
 
@@ -1493,7 +1481,7 @@ static inline struct futex_hash_bucket *queue_lock(struct 
futex_q *q)
 }
 
 static inline void
-queue_unlock(struct futex_q *q, struct futex_hash_bucket *hb)
+queue_unlock(struct futex_hash_bucket *hb)
__releases(hb-lock)
 {
spin_unlock(hb-lock);
@@ -1866,7 +1854,7 @@ retry_private:
ret = get_futex_value_locked(uval, uaddr);
 
if (ret) {
-   queue_unlock(q, *hb);
+   queue_unlock(*hb);
 
ret = get_user(uval, uaddr);
if (ret)
@@ -1880,7 +1868,7 @@ retry_private:
}
 
if (uval != val) {
-   queue_unlock(q, *hb);
+   queue_unlock(*hb);
ret = -EWOULDBLOCK;
}
 
@@ -2028,7 +2016,7 @@ retry_private:
 * Task is exiting and we just wait for the
 * exit to complete.
 */
-   queue_unlock(q, hb);
+   queue_unlock(hb);

Re: [PATCH 1/5] futex: Misc cleanups

2013-11-22 Thread Darren Hart
On Fri, 2013-11-22 at 16:56 -0800, Davidlohr Bueso wrote:
 From: Jason Low jason.l...@hp.com
 
 - Remove unnecessary head variables.
 - Delete unused parameter in queue_unlock().
 
 Cc: Ingo Molnar mi...@kernel.org
 Cc: Darren Hart dvh...@linux.intel.com
 Cc: Peter Zijlstra pet...@infradead.org
 Cc: Thomas Gleixner t...@linutronix.de
 Cc: Mike Galbraith efa...@gmx.de
 Cc: Jeff Mahoney je...@suse.com
 Cc: Linus Torvalds torva...@linux-foundation.org
 Cc: Scott Norton scott.nor...@hp.com
 Cc: Tom Vaden tom.va...@hp.com
 Cc: Aswin Chandramouleeswaran as...@hp.com
 Cc: Waiman Long waiman.l...@hp.com
 Signed-off-by: Jason Low jason.l...@hp.com
 Signed-off-by: Davidlohr Bueso davidl...@hp.com

My concern was that we saved off head for a reason, but the hb lock is
held in these cases, and the call is safe against removal, so I don't
see a problem. Thanks.

Reviewed-by: Darren Hart dvh...@linux.intel.com

-- 
Darren Hart
Intel Open Source Technology Center
Yocto Project - Linux Kernel


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/