Re: [3.11-rc1] CONFIG_DEBUG_MUTEXES=y using gcc 3.x makesunbootablekernel.

From: Peter Zijlstra
Date: Mon Sep 09 2013 - 08:58:56 EST


On Mon, Sep 09, 2013 at 08:56:53PM +0900, Tetsuo Handa wrote:
> From: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>
> Date: Mon, 9 Sep 2013 20:48:13 +0900
> Subject: [PATCH] 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.
>
> Signed-off-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>
> Cc: <stable@xxxxxxxxxx> [3.11+]
> ---
> kernel/mutex.c | 32 ++++++++++++++++----------------
> 1 files changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/kernel/mutex.c b/kernel/mutex.c
> index a52ee7bb..a2b80f1 100644
> --- a/kernel/mutex.c
> +++ b/kernel/mutex.c
> @@ -408,7 +408,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;
> @@ -448,7 +448,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);
> @@ -478,7 +478,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);
>
> @@ -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, 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);

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