All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for 3.12] mutex: Avoid gcc version dependent __builtin_constant_p() usage.
@ 2013-10-17 10:45 Tetsuo Handa
  2013-10-17 10:52 ` Peter Zijlstra
  2013-10-20 19:31 ` [tip:core/urgent] " tip-bot for Tetsuo Handa
  0 siblings, 2 replies; 9+ messages in thread
From: Tetsuo Handa @ 2013-10-17 10:45 UTC (permalink / raw)
  To: mingo
  Cc: peterz, maarten.lankhorst, imirkin, linux-kernel, daniel.vetter,
	robdclark

Commit 040a0a37 "mutex: Add support for wound/wait style locks" used
"!__builtin_constant_p(p == NULL)" but gcc 3.x cannot handle such expression
correctly, leading to boot failure when built with CONFIG_DEBUG_MUTEXES=y.

Fix it by explicitly passing a bool which tells whether p != NULL or not.

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
 kernel/mutex.c |   32 ++++++++++++++++----------------
 1 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/kernel/mutex.c b/kernel/mutex.c
index 6d647ae..d24105b 100644
--- a/kernel/mutex.c
+++ b/kernel/mutex.c
@@ -410,7 +410,7 @@ ww_mutex_set_context_fastpath(struct ww_mutex *lock,
 static __always_inline int __sched
 __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
 		    struct lockdep_map *nest_lock, unsigned long ip,
-		    struct ww_acquire_ctx *ww_ctx)
+		    struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx)
 {
 	struct task_struct *task = current;
 	struct mutex_waiter waiter;
@@ -450,7 +450,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
 		struct task_struct *owner;
 		struct mspin_node  node;
 
-		if (!__builtin_constant_p(ww_ctx == NULL) && ww_ctx->acquired > 0) {
+		if (use_ww_ctx && ww_ctx->acquired > 0) {
 			struct ww_mutex *ww;
 
 			ww = container_of(lock, struct ww_mutex, base);
@@ -480,7 +480,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
 		if ((atomic_read(&lock->count) == 1) &&
 		    (atomic_cmpxchg(&lock->count, 1, 0) == 1)) {
 			lock_acquired(&lock->dep_map, ip);
-			if (!__builtin_constant_p(ww_ctx == NULL)) {
+			if (use_ww_ctx) {
 				struct ww_mutex *ww;
 				ww = container_of(lock, struct ww_mutex, base);
 
@@ -551,7 +551,7 @@ slowpath:
 			goto err;
 		}
 
-		if (!__builtin_constant_p(ww_ctx == NULL) && ww_ctx->acquired > 0) {
+		if (use_ww_ctx && ww_ctx->acquired > 0) {
 			ret = __mutex_lock_check_stamp(lock, ww_ctx);
 			if (ret)
 				goto err;
@@ -575,7 +575,7 @@ skip_wait:
 	lock_acquired(&lock->dep_map, ip);
 	mutex_set_owner(lock);
 
-	if (!__builtin_constant_p(ww_ctx == NULL)) {
+	if (use_ww_ctx) {
 		struct ww_mutex *ww = container_of(lock, struct ww_mutex, base);
 		struct mutex_waiter *cur;
 
@@ -615,7 +615,7 @@ mutex_lock_nested(struct mutex *lock, unsigned int subclass)
 {
 	might_sleep();
 	__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE,
-			    subclass, NULL, _RET_IP_, NULL);
+			    subclass, NULL, _RET_IP_, NULL, 0);
 }
 
 EXPORT_SYMBOL_GPL(mutex_lock_nested);
@@ -625,7 +625,7 @@ _mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest)
 {
 	might_sleep();
 	__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE,
-			    0, nest, _RET_IP_, NULL);
+			    0, nest, _RET_IP_, NULL, 0);
 }
 
 EXPORT_SYMBOL_GPL(_mutex_lock_nest_lock);
@@ -635,7 +635,7 @@ mutex_lock_killable_nested(struct mutex *lock, unsigned int subclass)
 {
 	might_sleep();
 	return __mutex_lock_common(lock, TASK_KILLABLE,
-				   subclass, NULL, _RET_IP_, NULL);
+				   subclass, NULL, _RET_IP_, NULL, 0);
 }
 EXPORT_SYMBOL_GPL(mutex_lock_killable_nested);
 
@@ -644,7 +644,7 @@ mutex_lock_interruptible_nested(struct mutex *lock, unsigned int subclass)
 {
 	might_sleep();
 	return __mutex_lock_common(lock, TASK_INTERRUPTIBLE,
-				   subclass, NULL, _RET_IP_, NULL);
+				   subclass, NULL, _RET_IP_, NULL, 0);
 }
 
 EXPORT_SYMBOL_GPL(mutex_lock_interruptible_nested);
@@ -682,7 +682,7 @@ __ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
 
 	might_sleep();
 	ret =  __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE,
-				   0, &ctx->dep_map, _RET_IP_, ctx);
+				   0, &ctx->dep_map, _RET_IP_, ctx, 1);
 	if (!ret && ctx->acquired > 1)
 		return ww_mutex_deadlock_injection(lock, ctx);
 
@@ -697,7 +697,7 @@ __ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
 
 	might_sleep();
 	ret = __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE,
-				  0, &ctx->dep_map, _RET_IP_, ctx);
+				  0, &ctx->dep_map, _RET_IP_, ctx, 1);
 
 	if (!ret && ctx->acquired > 1)
 		return ww_mutex_deadlock_injection(lock, ctx);
@@ -809,28 +809,28 @@ __mutex_lock_slowpath(atomic_t *lock_count)
 	struct mutex *lock = container_of(lock_count, struct mutex, count);
 
 	__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0,
-			    NULL, _RET_IP_, NULL);
+			    NULL, _RET_IP_, NULL, 0);
 }
 
 static noinline int __sched
 __mutex_lock_killable_slowpath(struct mutex *lock)
 {
 	return __mutex_lock_common(lock, TASK_KILLABLE, 0,
-				   NULL, _RET_IP_, NULL);
+				   NULL, _RET_IP_, NULL, 0);
 }
 
 static noinline int __sched
 __mutex_lock_interruptible_slowpath(struct mutex *lock)
 {
 	return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 0,
-				   NULL, _RET_IP_, NULL);
+				   NULL, _RET_IP_, NULL, 0);
 }
 
 static noinline int __sched
 __ww_mutex_lock_slowpath(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
 {
 	return __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE, 0,
-				   NULL, _RET_IP_, ctx);
+				   NULL, _RET_IP_, ctx, 1);
 }
 
 static noinline int __sched
@@ -838,7 +838,7 @@ __ww_mutex_lock_interruptible_slowpath(struct ww_mutex *lock,
 					    struct ww_acquire_ctx *ctx)
 {
 	return __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE, 0,
-				   NULL, _RET_IP_, ctx);
+				   NULL, _RET_IP_, ctx, 1);
 }
 
 #endif
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH for 3.12] mutex: Avoid gcc version dependent __builtin_constant_p() usage.
  2013-10-17 10:45 [PATCH for 3.12] mutex: Avoid gcc version dependent __builtin_constant_p() usage Tetsuo Handa
@ 2013-10-17 10:52 ` Peter Zijlstra
  2013-10-17 10:54   ` Maarten Lankhorst
  2013-10-20 19:31 ` [tip:core/urgent] " tip-bot for Tetsuo Handa
  1 sibling, 1 reply; 9+ messages in thread
From: Peter Zijlstra @ 2013-10-17 10:52 UTC (permalink / raw)
  To: Tetsuo Handa
  Cc: mingo, maarten.lankhorst, imirkin, linux-kernel, daniel.vetter,
	robdclark

On Thu, Oct 17, 2013 at 07:45:29PM +0900, Tetsuo Handa wrote:
> Commit 040a0a37 "mutex: Add support for wound/wait style locks" used
> "!__builtin_constant_p(p == NULL)" but gcc 3.x cannot handle such expression
> correctly, leading to boot failure when built with CONFIG_DEBUG_MUTEXES=y.

So I completely forgot all about this, but wouldn't something like:

 !(__builtin_constant_p(p) && p == NULL)

Not also work and generate the same code?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH for 3.12] mutex: Avoid gcc version dependent __builtin_constant_p() usage.
  2013-10-17 10:52 ` Peter Zijlstra
@ 2013-10-17 10:54   ` Maarten Lankhorst
  2013-10-17 11:02     ` Peter Zijlstra
  0 siblings, 1 reply; 9+ messages in thread
From: Maarten Lankhorst @ 2013-10-17 10:54 UTC (permalink / raw)
  To: Peter Zijlstra, Tetsuo Handa
  Cc: mingo, imirkin, linux-kernel, daniel.vetter, robdclark

op 17-10-13 12:52, Peter Zijlstra schreef:
> On Thu, Oct 17, 2013 at 07:45:29PM +0900, Tetsuo Handa wrote:
>> Commit 040a0a37 "mutex: Add support for wound/wait style locks" used
>> "!__builtin_constant_p(p == NULL)" but gcc 3.x cannot handle such expression
>> correctly, leading to boot failure when built with CONFIG_DEBUG_MUTEXES=y.
> So I completely forgot all about this, but wouldn't something like:
>
>  !(__builtin_constant_p(p) && p == NULL)
>
> Not also work and generate the same code?
>
See earlier discussion. It was already answered why that was undesirable. ;)

~Maarten

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH for 3.12] mutex: Avoid gcc version dependent __builtin_constant_p() usage.
  2013-10-17 10:54   ` Maarten Lankhorst
@ 2013-10-17 11:02     ` Peter Zijlstra
  2013-10-18 12:51       ` [PATCH for 3.12] mutex: Avoid gcc version dependent__builtin_constant_p() usage Tetsuo Handa
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Zijlstra @ 2013-10-17 11:02 UTC (permalink / raw)
  To: Maarten Lankhorst
  Cc: Tetsuo Handa, mingo, imirkin, linux-kernel, daniel.vetter,
	robdclark

On Thu, Oct 17, 2013 at 12:54:21PM +0200, Maarten Lankhorst wrote:
> op 17-10-13 12:52, Peter Zijlstra schreef:
> > On Thu, Oct 17, 2013 at 07:45:29PM +0900, Tetsuo Handa wrote:
> >> Commit 040a0a37 "mutex: Add support for wound/wait style locks" used
> >> "!__builtin_constant_p(p == NULL)" but gcc 3.x cannot handle such expression
> >> correctly, leading to boot failure when built with CONFIG_DEBUG_MUTEXES=y.
> > So I completely forgot all about this, but wouldn't something like:
> >
> >  !(__builtin_constant_p(p) && p == NULL)
> >
> > Not also work and generate the same code?
> >
> See earlier discussion. It was already answered why that was undesirable. ;)

OK; I forgot if we covered that particular option.. I so hate this
patch; but I'm afraid we'll have to take it :-/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH for 3.12] mutex: Avoid gcc version dependent__builtin_constant_p() usage.
  2013-10-17 11:02     ` Peter Zijlstra
@ 2013-10-18 12:51       ` Tetsuo Handa
  2013-10-18 13:13         ` Ingo Molnar
  0 siblings, 1 reply; 9+ messages in thread
From: Tetsuo Handa @ 2013-10-18 12:51 UTC (permalink / raw)
  To: mingo
  Cc: peterz, maarten.lankhorst, imirkin, linux-kernel, daniel.vetter,
	robdclark

Peter Zijlstra wrote:
> On Thu, Oct 17, 2013 at 12:54:21PM +0200, Maarten Lankhorst wrote:
> > op 17-10-13 12:52, Peter Zijlstra schreef:
> > > On Thu, Oct 17, 2013 at 07:45:29PM +0900, Tetsuo Handa wrote:
> > >> Commit 040a0a37 "mutex: Add support for wound/wait style locks" used
> > >> "!__builtin_constant_p(p == NULL)" but gcc 3.x cannot handle such expression
> > >> correctly, leading to boot failure when built with CONFIG_DEBUG_MUTEXES=y.
> > > So I completely forgot all about this, but wouldn't something like:
> > >
> > >  !(__builtin_constant_p(p) && p == NULL)
> > >
> > > Not also work and generate the same code?
> > >
> > See earlier discussion. It was already answered why that was undesirable. ;)
> 
> OK; I forgot if we covered that particular option.. I so hate this
> patch; but I'm afraid we'll have to take it :-/
> 

I see. Ingo, would you send this patch via your tree?
Then, I'll post a patch for 3.11-stable which differs white spaces.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH for 3.12] mutex: Avoid gcc version dependent__builtin_constant_p() usage.
  2013-10-18 12:51       ` [PATCH for 3.12] mutex: Avoid gcc version dependent__builtin_constant_p() usage Tetsuo Handa
@ 2013-10-18 13:13         ` Ingo Molnar
  2013-10-18 15:51           ` Maarten Lankhorst
  0 siblings, 1 reply; 9+ messages in thread
From: Ingo Molnar @ 2013-10-18 13:13 UTC (permalink / raw)
  To: Tetsuo Handa
  Cc: peterz, maarten.lankhorst, imirkin, linux-kernel, daniel.vetter,
	robdclark


* Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:

> Peter Zijlstra wrote:
> > On Thu, Oct 17, 2013 at 12:54:21PM +0200, Maarten Lankhorst wrote:
> > > op 17-10-13 12:52, Peter Zijlstra schreef:
> > > > On Thu, Oct 17, 2013 at 07:45:29PM +0900, Tetsuo Handa wrote:
> > > >> Commit 040a0a37 "mutex: Add support for wound/wait style locks" used
> > > >> "!__builtin_constant_p(p == NULL)" but gcc 3.x cannot handle such expression
> > > >> correctly, leading to boot failure when built with CONFIG_DEBUG_MUTEXES=y.
> > > > So I completely forgot all about this, but wouldn't something like:
> > > >
> > > >  !(__builtin_constant_p(p) && p == NULL)
> > > >
> > > > Not also work and generate the same code?
> > > >
> > > See earlier discussion. It was already answered why that was undesirable. ;)
> > 
> > OK; I forgot if we covered that particular option.. I so hate this
> > patch; but I'm afraid we'll have to take it :-/
> > 
> 
> I see. Ingo, would you send this patch via your tree?
> Then, I'll post a patch for 3.11-stable which differs white spaces.

If it has Maarten's and PeterZ's Acked-by then sure.

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH for 3.12] mutex: Avoid gcc version dependent__builtin_constant_p() usage.
  2013-10-18 13:13         ` Ingo Molnar
@ 2013-10-18 15:51           ` Maarten Lankhorst
  2013-10-30 13:14             ` [PATCH 3.11-stable] mutex: Avoid gcc version dependent __builtin_constant_p() usage Tetsuo Handa
  0 siblings, 1 reply; 9+ messages in thread
From: Maarten Lankhorst @ 2013-10-18 15:51 UTC (permalink / raw)
  To: Ingo Molnar, Tetsuo Handa
  Cc: peterz, imirkin, linux-kernel, daniel.vetter, robdclark

op 18-10-13 15:13, Ingo Molnar schreef:
> * Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:
>
>> Peter Zijlstra wrote:
>>> On Thu, Oct 17, 2013 at 12:54:21PM +0200, Maarten Lankhorst wrote:
>>>> op 17-10-13 12:52, Peter Zijlstra schreef:
>>>>> On Thu, Oct 17, 2013 at 07:45:29PM +0900, Tetsuo Handa wrote:
>>>>>> Commit 040a0a37 "mutex: Add support for wound/wait style locks" used
>>>>>> "!__builtin_constant_p(p == NULL)" but gcc 3.x cannot handle such expression
>>>>>> correctly, leading to boot failure when built with CONFIG_DEBUG_MUTEXES=y.
>>>>> So I completely forgot all about this, but wouldn't something like:
>>>>>
>>>>>  !(__builtin_constant_p(p) && p == NULL)
>>>>>
>>>>> Not also work and generate the same code?
>>>>>
>>>> See earlier discussion. It was already answered why that was undesirable. ;)
>>> OK; I forgot if we covered that particular option.. I so hate this
>>> patch; but I'm afraid we'll have to take it :-/
>>>
>> I see. Ingo, would you send this patch via your tree?
>> Then, I'll post a patch for 3.11-stable which differs white spaces.
> If it has Maarten's and PeterZ's Acked-by then sure.
>
> Thanks,
>
> 	Ingo
>
Acked. ;-)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [tip:core/urgent] mutex: Avoid gcc version dependent __builtin_constant_p() usage
  2013-10-17 10:45 [PATCH for 3.12] mutex: Avoid gcc version dependent __builtin_constant_p() usage Tetsuo Handa
  2013-10-17 10:52 ` Peter Zijlstra
@ 2013-10-20 19:31 ` tip-bot for Tetsuo Handa
  1 sibling, 0 replies; 9+ messages in thread
From: tip-bot for Tetsuo Handa @ 2013-10-20 19:31 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, torvalds, a.p.zijlstra, penguin-kernel,
	akpm, tglx, maarten.lankhorst

Commit-ID:  b0267507dfd0187fb7840a0ec461a510a7f041c5
Gitweb:     http://git.kernel.org/tip/b0267507dfd0187fb7840a0ec461a510a7f041c5
Author:     Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
AuthorDate: Thu, 17 Oct 2013 19:45:29 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 18 Oct 2013 21:58:54 +0200

mutex: Avoid gcc version dependent __builtin_constant_p() usage

Commit 040a0a37 ("mutex: Add support for wound/wait style locks")
used "!__builtin_constant_p(p == NULL)" but gcc 3.x cannot
handle such expression correctly, leading to boot failure when
built with CONFIG_DEBUG_MUTEXES=y.

Fix it by explicitly passing a bool which tells whether p != NULL
or not.

[ PeterZ: This is a sad patch, but provided it actually generates
          similar code I suppose its the best we can do bar whole
	  sale deprecating gcc-3. ]

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Cc: peterz@infradead.org
Cc: imirkin@alum.mit.edu
Cc: daniel.vetter@ffwll.ch
Cc: robdclark@gmail.com
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Link: http://lkml.kernel.org/r/201310171945.AGB17114.FSQVtHOJFOOFML@I-love.SAKURA.ne.jp
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/mutex.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/kernel/mutex.c b/kernel/mutex.c
index 6d647ae..d24105b 100644
--- a/kernel/mutex.c
+++ b/kernel/mutex.c
@@ -410,7 +410,7 @@ ww_mutex_set_context_fastpath(struct ww_mutex *lock,
 static __always_inline int __sched
 __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
 		    struct lockdep_map *nest_lock, unsigned long ip,
-		    struct ww_acquire_ctx *ww_ctx)
+		    struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx)
 {
 	struct task_struct *task = current;
 	struct mutex_waiter waiter;
@@ -450,7 +450,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
 		struct task_struct *owner;
 		struct mspin_node  node;
 
-		if (!__builtin_constant_p(ww_ctx == NULL) && ww_ctx->acquired > 0) {
+		if (use_ww_ctx && ww_ctx->acquired > 0) {
 			struct ww_mutex *ww;
 
 			ww = container_of(lock, struct ww_mutex, base);
@@ -480,7 +480,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
 		if ((atomic_read(&lock->count) == 1) &&
 		    (atomic_cmpxchg(&lock->count, 1, 0) == 1)) {
 			lock_acquired(&lock->dep_map, ip);
-			if (!__builtin_constant_p(ww_ctx == NULL)) {
+			if (use_ww_ctx) {
 				struct ww_mutex *ww;
 				ww = container_of(lock, struct ww_mutex, base);
 
@@ -551,7 +551,7 @@ slowpath:
 			goto err;
 		}
 
-		if (!__builtin_constant_p(ww_ctx == NULL) && ww_ctx->acquired > 0) {
+		if (use_ww_ctx && ww_ctx->acquired > 0) {
 			ret = __mutex_lock_check_stamp(lock, ww_ctx);
 			if (ret)
 				goto err;
@@ -575,7 +575,7 @@ skip_wait:
 	lock_acquired(&lock->dep_map, ip);
 	mutex_set_owner(lock);
 
-	if (!__builtin_constant_p(ww_ctx == NULL)) {
+	if (use_ww_ctx) {
 		struct ww_mutex *ww = container_of(lock, struct ww_mutex, base);
 		struct mutex_waiter *cur;
 
@@ -615,7 +615,7 @@ mutex_lock_nested(struct mutex *lock, unsigned int subclass)
 {
 	might_sleep();
 	__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE,
-			    subclass, NULL, _RET_IP_, NULL);
+			    subclass, NULL, _RET_IP_, NULL, 0);
 }
 
 EXPORT_SYMBOL_GPL(mutex_lock_nested);
@@ -625,7 +625,7 @@ _mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest)
 {
 	might_sleep();
 	__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE,
-			    0, nest, _RET_IP_, NULL);
+			    0, nest, _RET_IP_, NULL, 0);
 }
 
 EXPORT_SYMBOL_GPL(_mutex_lock_nest_lock);
@@ -635,7 +635,7 @@ mutex_lock_killable_nested(struct mutex *lock, unsigned int subclass)
 {
 	might_sleep();
 	return __mutex_lock_common(lock, TASK_KILLABLE,
-				   subclass, NULL, _RET_IP_, NULL);
+				   subclass, NULL, _RET_IP_, NULL, 0);
 }
 EXPORT_SYMBOL_GPL(mutex_lock_killable_nested);
 
@@ -644,7 +644,7 @@ mutex_lock_interruptible_nested(struct mutex *lock, unsigned int subclass)
 {
 	might_sleep();
 	return __mutex_lock_common(lock, TASK_INTERRUPTIBLE,
-				   subclass, NULL, _RET_IP_, NULL);
+				   subclass, NULL, _RET_IP_, NULL, 0);
 }
 
 EXPORT_SYMBOL_GPL(mutex_lock_interruptible_nested);
@@ -682,7 +682,7 @@ __ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
 
 	might_sleep();
 	ret =  __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE,
-				   0, &ctx->dep_map, _RET_IP_, ctx);
+				   0, &ctx->dep_map, _RET_IP_, ctx, 1);
 	if (!ret && ctx->acquired > 1)
 		return ww_mutex_deadlock_injection(lock, ctx);
 
@@ -697,7 +697,7 @@ __ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
 
 	might_sleep();
 	ret = __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE,
-				  0, &ctx->dep_map, _RET_IP_, ctx);
+				  0, &ctx->dep_map, _RET_IP_, ctx, 1);
 
 	if (!ret && ctx->acquired > 1)
 		return ww_mutex_deadlock_injection(lock, ctx);
@@ -809,28 +809,28 @@ __mutex_lock_slowpath(atomic_t *lock_count)
 	struct mutex *lock = container_of(lock_count, struct mutex, count);
 
 	__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0,
-			    NULL, _RET_IP_, NULL);
+			    NULL, _RET_IP_, NULL, 0);
 }
 
 static noinline int __sched
 __mutex_lock_killable_slowpath(struct mutex *lock)
 {
 	return __mutex_lock_common(lock, TASK_KILLABLE, 0,
-				   NULL, _RET_IP_, NULL);
+				   NULL, _RET_IP_, NULL, 0);
 }
 
 static noinline int __sched
 __mutex_lock_interruptible_slowpath(struct mutex *lock)
 {
 	return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 0,
-				   NULL, _RET_IP_, NULL);
+				   NULL, _RET_IP_, NULL, 0);
 }
 
 static noinline int __sched
 __ww_mutex_lock_slowpath(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
 {
 	return __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE, 0,
-				   NULL, _RET_IP_, ctx);
+				   NULL, _RET_IP_, ctx, 1);
 }
 
 static noinline int __sched
@@ -838,7 +838,7 @@ __ww_mutex_lock_interruptible_slowpath(struct ww_mutex *lock,
 					    struct ww_acquire_ctx *ctx)
 {
 	return __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE, 0,
-				   NULL, _RET_IP_, ctx);
+				   NULL, _RET_IP_, ctx, 1);
 }
 
 #endif

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3.11-stable] mutex: Avoid gcc version dependent __builtin_constant_p() usage
  2013-10-18 15:51           ` Maarten Lankhorst
@ 2013-10-30 13:14             ` Tetsuo Handa
  0 siblings, 0 replies; 9+ messages in thread
From: Tetsuo Handa @ 2013-10-30 13:14 UTC (permalink / raw)
  To: stable; +Cc: linux-kernel

Commit b0267507dfd0187fb7840a0ec461a510a7f041c5 upstream.

Commit 040a0a37 ("mutex: Add support for wound/wait style locks")
used "!__builtin_constant_p(p == NULL)" but gcc 3.x cannot
handle such expression correctly, leading to boot failure when
built with CONFIG_DEBUG_MUTEXES=y.

Fix it by explicitly passing a bool which tells whether p != NULL
or not.

[ PeterZ: This is a sad patch, but provided it actually generates
          similar code I suppose its the best we can do bar whole
          sale deprecating gcc-3. ]

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Cc: peterz@infradead.org
Cc: imirkin@alum.mit.edu
Cc: daniel.vetter@ffwll.ch
Cc: robdclark@gmail.com
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Link: http://lkml.kernel.org/r/201310171945.AGB17114.FSQVtHOJFOOFML@I-love.SAKURA.ne.jp
Signed-off-by: Ingo Molnar <mingo@kernel.org>

---
 kernel/mutex.c |   32 ++++++++++++++++----------------
 1 files changed, 16 insertions(+), 16 deletions(-)

--- linux-3.11.6.orig/kernel/mutex.c
+++ linux-3.11.6/kernel/mutex.c
@@ -408,7 +408,7 @@ ww_mutex_set_context_fastpath(struct ww_
 static __always_inline int __sched
 __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
 		    struct lockdep_map *nest_lock, unsigned long ip,
-		    struct ww_acquire_ctx *ww_ctx)
+		    struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx)
 {
 	struct task_struct *task = current;
 	struct mutex_waiter waiter;
@@ -448,7 +448,7 @@ __mutex_lock_common(struct mutex *lock, 
 		struct task_struct *owner;
 		struct mspin_node  node;
 
-		if (!__builtin_constant_p(ww_ctx == NULL) && ww_ctx->acquired > 0) {
+		if (use_ww_ctx && ww_ctx->acquired > 0) {
 			struct ww_mutex *ww;
 
 			ww = container_of(lock, struct ww_mutex, base);
@@ -478,7 +478,7 @@ __mutex_lock_common(struct mutex *lock, 
 		if ((atomic_read(&lock->count) == 1) &&
 		    (atomic_cmpxchg(&lock->count, 1, 0) == 1)) {
 			lock_acquired(&lock->dep_map, ip);
-			if (!__builtin_constant_p(ww_ctx == NULL)) {
+			if (use_ww_ctx) {
 				struct ww_mutex *ww;
 				ww = container_of(lock, struct ww_mutex, base);
 
@@ -548,7 +548,7 @@ slowpath:
 			goto err;
 		}
 
-		if (!__builtin_constant_p(ww_ctx == NULL) && ww_ctx->acquired > 0) {
+		if (use_ww_ctx && ww_ctx->acquired > 0) {
 			ret = __mutex_lock_check_stamp(lock, ww_ctx);
 			if (ret)
 				goto err;
@@ -568,7 +568,7 @@ done:
 	mutex_remove_waiter(lock, &waiter, current_thread_info());
 	mutex_set_owner(lock);
 
-	if (!__builtin_constant_p(ww_ctx == NULL)) {
+	if (use_ww_ctx) {
 		struct ww_mutex *ww = container_of(lock,
 						      struct ww_mutex,
 						      base);
@@ -618,7 +618,7 @@ mutex_lock_nested(struct mutex *lock, un
 {
 	might_sleep();
 	__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE,
-			    subclass, NULL, _RET_IP_, NULL);
+			    subclass, NULL, _RET_IP_, NULL, 0);
 }
 
 EXPORT_SYMBOL_GPL(mutex_lock_nested);
@@ -628,7 +628,7 @@ _mutex_lock_nest_lock(struct mutex *lock
 {
 	might_sleep();
 	__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE,
-			    0, nest, _RET_IP_, NULL);
+			    0, nest, _RET_IP_, NULL, 0);
 }
 
 EXPORT_SYMBOL_GPL(_mutex_lock_nest_lock);
@@ -638,7 +638,7 @@ mutex_lock_killable_nested(struct mutex 
 {
 	might_sleep();
 	return __mutex_lock_common(lock, TASK_KILLABLE,
-				   subclass, NULL, _RET_IP_, NULL);
+				   subclass, NULL, _RET_IP_, NULL, 0);
 }
 EXPORT_SYMBOL_GPL(mutex_lock_killable_nested);
 
@@ -647,7 +647,7 @@ mutex_lock_interruptible_nested(struct m
 {
 	might_sleep();
 	return __mutex_lock_common(lock, TASK_INTERRUPTIBLE,
-				   subclass, NULL, _RET_IP_, NULL);
+				   subclass, NULL, _RET_IP_, NULL, 0);
 }
 
 EXPORT_SYMBOL_GPL(mutex_lock_interruptible_nested);
@@ -685,7 +685,7 @@ __ww_mutex_lock(struct ww_mutex *lock, s
 
 	might_sleep();
 	ret =  __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE,
-				   0, &ctx->dep_map, _RET_IP_, ctx);
+				   0, &ctx->dep_map, _RET_IP_, ctx, 1);
 	if (!ret && ctx->acquired > 1)
 		return ww_mutex_deadlock_injection(lock, ctx);
 
@@ -700,7 +700,7 @@ __ww_mutex_lock_interruptible(struct ww_
 
 	might_sleep();
 	ret = __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE,
-				  0, &ctx->dep_map, _RET_IP_, ctx);
+				  0, &ctx->dep_map, _RET_IP_, ctx, 1);
 
 	if (!ret && ctx->acquired > 1)
 		return ww_mutex_deadlock_injection(lock, ctx);
@@ -812,28 +812,28 @@ __mutex_lock_slowpath(atomic_t *lock_cou
 	struct mutex *lock = container_of(lock_count, struct mutex, count);
 
 	__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0,
-			    NULL, _RET_IP_, NULL);
+			    NULL, _RET_IP_, NULL, 0);
 }
 
 static noinline int __sched
 __mutex_lock_killable_slowpath(struct mutex *lock)
 {
 	return __mutex_lock_common(lock, TASK_KILLABLE, 0,
-				   NULL, _RET_IP_, NULL);
+				   NULL, _RET_IP_, NULL, 0);
 }
 
 static noinline int __sched
 __mutex_lock_interruptible_slowpath(struct mutex *lock)
 {
 	return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 0,
-				   NULL, _RET_IP_, NULL);
+				   NULL, _RET_IP_, NULL, 0);
 }
 
 static noinline int __sched
 __ww_mutex_lock_slowpath(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
 {
 	return __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE, 0,
-				   NULL, _RET_IP_, ctx);
+				   NULL, _RET_IP_, ctx, 1);
 }
 
 static noinline int __sched
@@ -841,7 +841,7 @@ __ww_mutex_lock_interruptible_slowpath(s
 					    struct ww_acquire_ctx *ctx)
 {
 	return __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE, 0,
-				   NULL, _RET_IP_, ctx);
+				   NULL, _RET_IP_, ctx, 1);
 }
 
 #endif

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-10-30 13:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-17 10:45 [PATCH for 3.12] mutex: Avoid gcc version dependent __builtin_constant_p() usage Tetsuo Handa
2013-10-17 10:52 ` Peter Zijlstra
2013-10-17 10:54   ` Maarten Lankhorst
2013-10-17 11:02     ` Peter Zijlstra
2013-10-18 12:51       ` [PATCH for 3.12] mutex: Avoid gcc version dependent__builtin_constant_p() usage Tetsuo Handa
2013-10-18 13:13         ` Ingo Molnar
2013-10-18 15:51           ` Maarten Lankhorst
2013-10-30 13:14             ` [PATCH 3.11-stable] mutex: Avoid gcc version dependent __builtin_constant_p() usage Tetsuo Handa
2013-10-20 19:31 ` [tip:core/urgent] " tip-bot for Tetsuo Handa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.