diff options
author | Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> | 2013-10-17 06:45:29 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2013-10-18 15:58:54 -0400 |
commit | b0267507dfd0187fb7840a0ec461a510a7f041c5 (patch) | |
tree | 8d17053d2ac87eb4f53120dc8d83cc084819096a /kernel | |
parent | 04919afb85c8f007b7326c4da5eb61c52e91b9c7 (diff) |
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>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/mutex.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/kernel/mutex.c b/kernel/mutex.c index 6d647aedffea..d24105b1b794 100644 --- a/kernel/mutex.c +++ b/kernel/mutex.c | |||
@@ -410,7 +410,7 @@ ww_mutex_set_context_fastpath(struct ww_mutex *lock, | |||
410 | static __always_inline int __sched | 410 | static __always_inline int __sched |
411 | __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, | 411 | __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, |
412 | struct lockdep_map *nest_lock, unsigned long ip, | 412 | struct lockdep_map *nest_lock, unsigned long ip, |
413 | struct ww_acquire_ctx *ww_ctx) | 413 | struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx) |
414 | { | 414 | { |
415 | struct task_struct *task = current; | 415 | struct task_struct *task = current; |
416 | struct mutex_waiter waiter; | 416 | struct mutex_waiter waiter; |
@@ -450,7 +450,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, | |||
450 | struct task_struct *owner; | 450 | struct task_struct *owner; |
451 | struct mspin_node node; | 451 | struct mspin_node node; |
452 | 452 | ||
453 | if (!__builtin_constant_p(ww_ctx == NULL) && ww_ctx->acquired > 0) { | 453 | if (use_ww_ctx && ww_ctx->acquired > 0) { |
454 | struct ww_mutex *ww; | 454 | struct ww_mutex *ww; |
455 | 455 | ||
456 | ww = container_of(lock, struct ww_mutex, base); | 456 | ww = container_of(lock, struct ww_mutex, base); |
@@ -480,7 +480,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, | |||
480 | if ((atomic_read(&lock->count) == 1) && | 480 | if ((atomic_read(&lock->count) == 1) && |
481 | (atomic_cmpxchg(&lock->count, 1, 0) == 1)) { | 481 | (atomic_cmpxchg(&lock->count, 1, 0) == 1)) { |
482 | lock_acquired(&lock->dep_map, ip); | 482 | lock_acquired(&lock->dep_map, ip); |
483 | if (!__builtin_constant_p(ww_ctx == NULL)) { | 483 | if (use_ww_ctx) { |
484 | struct ww_mutex *ww; | 484 | struct ww_mutex *ww; |
485 | ww = container_of(lock, struct ww_mutex, base); | 485 | ww = container_of(lock, struct ww_mutex, base); |
486 | 486 | ||
@@ -551,7 +551,7 @@ slowpath: | |||
551 | goto err; | 551 | goto err; |
552 | } | 552 | } |
553 | 553 | ||
554 | if (!__builtin_constant_p(ww_ctx == NULL) && ww_ctx->acquired > 0) { | 554 | if (use_ww_ctx && ww_ctx->acquired > 0) { |
555 | ret = __mutex_lock_check_stamp(lock, ww_ctx); | 555 | ret = __mutex_lock_check_stamp(lock, ww_ctx); |
556 | if (ret) | 556 | if (ret) |
557 | goto err; | 557 | goto err; |
@@ -575,7 +575,7 @@ skip_wait: | |||
575 | lock_acquired(&lock->dep_map, ip); | 575 | lock_acquired(&lock->dep_map, ip); |
576 | mutex_set_owner(lock); | 576 | mutex_set_owner(lock); |
577 | 577 | ||
578 | if (!__builtin_constant_p(ww_ctx == NULL)) { | 578 | if (use_ww_ctx) { |
579 | struct ww_mutex *ww = container_of(lock, struct ww_mutex, base); | 579 | struct ww_mutex *ww = container_of(lock, struct ww_mutex, base); |
580 | struct mutex_waiter *cur; | 580 | struct mutex_waiter *cur; |
581 | 581 | ||
@@ -615,7 +615,7 @@ mutex_lock_nested(struct mutex *lock, unsigned int subclass) | |||
615 | { | 615 | { |
616 | might_sleep(); | 616 | might_sleep(); |
617 | __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, | 617 | __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, |
618 | subclass, NULL, _RET_IP_, NULL); | 618 | subclass, NULL, _RET_IP_, NULL, 0); |
619 | } | 619 | } |
620 | 620 | ||
621 | EXPORT_SYMBOL_GPL(mutex_lock_nested); | 621 | EXPORT_SYMBOL_GPL(mutex_lock_nested); |
@@ -625,7 +625,7 @@ _mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest) | |||
625 | { | 625 | { |
626 | might_sleep(); | 626 | might_sleep(); |
627 | __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, | 627 | __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, |
628 | 0, nest, _RET_IP_, NULL); | 628 | 0, nest, _RET_IP_, NULL, 0); |
629 | } | 629 | } |
630 | 630 | ||
631 | EXPORT_SYMBOL_GPL(_mutex_lock_nest_lock); | 631 | EXPORT_SYMBOL_GPL(_mutex_lock_nest_lock); |
@@ -635,7 +635,7 @@ mutex_lock_killable_nested(struct mutex *lock, unsigned int subclass) | |||
635 | { | 635 | { |
636 | might_sleep(); | 636 | might_sleep(); |
637 | return __mutex_lock_common(lock, TASK_KILLABLE, | 637 | return __mutex_lock_common(lock, TASK_KILLABLE, |
638 | subclass, NULL, _RET_IP_, NULL); | 638 | subclass, NULL, _RET_IP_, NULL, 0); |
639 | } | 639 | } |
640 | EXPORT_SYMBOL_GPL(mutex_lock_killable_nested); | 640 | EXPORT_SYMBOL_GPL(mutex_lock_killable_nested); |
641 | 641 | ||
@@ -644,7 +644,7 @@ mutex_lock_interruptible_nested(struct mutex *lock, unsigned int subclass) | |||
644 | { | 644 | { |
645 | might_sleep(); | 645 | might_sleep(); |
646 | return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, | 646 | return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, |
647 | subclass, NULL, _RET_IP_, NULL); | 647 | subclass, NULL, _RET_IP_, NULL, 0); |
648 | } | 648 | } |
649 | 649 | ||
650 | EXPORT_SYMBOL_GPL(mutex_lock_interruptible_nested); | 650 | EXPORT_SYMBOL_GPL(mutex_lock_interruptible_nested); |
@@ -682,7 +682,7 @@ __ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) | |||
682 | 682 | ||
683 | might_sleep(); | 683 | might_sleep(); |
684 | ret = __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE, | 684 | ret = __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE, |
685 | 0, &ctx->dep_map, _RET_IP_, ctx); | 685 | 0, &ctx->dep_map, _RET_IP_, ctx, 1); |
686 | if (!ret && ctx->acquired > 1) | 686 | if (!ret && ctx->acquired > 1) |
687 | return ww_mutex_deadlock_injection(lock, ctx); | 687 | return ww_mutex_deadlock_injection(lock, ctx); |
688 | 688 | ||
@@ -697,7 +697,7 @@ __ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) | |||
697 | 697 | ||
698 | might_sleep(); | 698 | might_sleep(); |
699 | ret = __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE, | 699 | ret = __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE, |
700 | 0, &ctx->dep_map, _RET_IP_, ctx); | 700 | 0, &ctx->dep_map, _RET_IP_, ctx, 1); |
701 | 701 | ||
702 | if (!ret && ctx->acquired > 1) | 702 | if (!ret && ctx->acquired > 1) |
703 | return ww_mutex_deadlock_injection(lock, ctx); | 703 | return ww_mutex_deadlock_injection(lock, ctx); |
@@ -809,28 +809,28 @@ __mutex_lock_slowpath(atomic_t *lock_count) | |||
809 | struct mutex *lock = container_of(lock_count, struct mutex, count); | 809 | struct mutex *lock = container_of(lock_count, struct mutex, count); |
810 | 810 | ||
811 | __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0, | 811 | __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0, |
812 | NULL, _RET_IP_, NULL); | 812 | NULL, _RET_IP_, NULL, 0); |
813 | } | 813 | } |
814 | 814 | ||
815 | static noinline int __sched | 815 | static noinline int __sched |
816 | __mutex_lock_killable_slowpath(struct mutex *lock) | 816 | __mutex_lock_killable_slowpath(struct mutex *lock) |
817 | { | 817 | { |
818 | return __mutex_lock_common(lock, TASK_KILLABLE, 0, | 818 | return __mutex_lock_common(lock, TASK_KILLABLE, 0, |
819 | NULL, _RET_IP_, NULL); | 819 | NULL, _RET_IP_, NULL, 0); |
820 | } | 820 | } |
821 | 821 | ||
822 | static noinline int __sched | 822 | static noinline int __sched |
823 | __mutex_lock_interruptible_slowpath(struct mutex *lock) | 823 | __mutex_lock_interruptible_slowpath(struct mutex *lock) |
824 | { | 824 | { |
825 | return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 0, | 825 | return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 0, |
826 | NULL, _RET_IP_, NULL); | 826 | NULL, _RET_IP_, NULL, 0); |
827 | } | 827 | } |
828 | 828 | ||
829 | static noinline int __sched | 829 | static noinline int __sched |
830 | __ww_mutex_lock_slowpath(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) | 830 | __ww_mutex_lock_slowpath(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) |
831 | { | 831 | { |
832 | return __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE, 0, | 832 | return __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE, 0, |
833 | NULL, _RET_IP_, ctx); | 833 | NULL, _RET_IP_, ctx, 1); |
834 | } | 834 | } |
835 | 835 | ||
836 | static noinline int __sched | 836 | static noinline int __sched |
@@ -838,7 +838,7 @@ __ww_mutex_lock_interruptible_slowpath(struct ww_mutex *lock, | |||
838 | struct ww_acquire_ctx *ctx) | 838 | struct ww_acquire_ctx *ctx) |
839 | { | 839 | { |
840 | return __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE, 0, | 840 | return __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE, 0, |
841 | NULL, _RET_IP_, ctx); | 841 | NULL, _RET_IP_, ctx, 1); |
842 | } | 842 | } |
843 | 843 | ||
844 | #endif | 844 | #endif |