All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: "Nicolai Hähnle" <nhaehnle@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	"Nicolai Hähnle" <Nicolai.Haehnle@amd.com>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Chris Wilson" <chris@chris-wilson.co.uk>,
	"Maarten Lankhorst" <maarten.lankhorst@canonical.com>,
	dri-devel@lists.freedesktop.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/4] locking/ww_mutex: Fix a deadlock affecting ww_mutexes
Date: Wed, 23 Nov 2016 15:03:36 +0100	[thread overview]
Message-ID: <20161123140336.GU3092@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1479900325-28358-1-git-send-email-nhaehnle@gmail.com>

On Wed, Nov 23, 2016 at 12:25:22PM +0100, Nicolai Hähnle wrote:
> @@ -473,7 +476,14 @@ void __sched ww_mutex_unlock(struct ww_mutex *lock)
>  	 */
>  	mutex_clear_owner(&lock->base);
>  #endif
> -	__mutex_fastpath_unlock(&lock->base.count, __mutex_unlock_slowpath);
> +	/*
> +	 * A previously _not_ waiting task may acquire the lock via the fast
> +	 * path during our unlock. In that case, already waiting tasks may have
> +	 * to back off to avoid a deadlock. Wake up all waiters so that they
> +	 * can check their acquire context stamp against the new owner.
> +	 */
> +	__mutex_fastpath_unlock(&lock->base.count,
> +				__mutex_unlock_slowpath_wakeall);
>  }

So doing a wake-all has obvious issues with thundering herd etc.. Also,
with the new mutex, you'd not be able to do hand-off, which would
introduce starvation cases.

Ideally we'd iterate the blocked list and pick the waiter with the
earliest stamp, or we'd maintain the list in stamp order instead of
FIFO, for ww_mutex.

WARNING: multiple messages have this Message-ID (diff)
From: Peter Zijlstra <peterz@infradead.org>
To: "Nicolai Hähnle" <nhaehnle@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	"Nicolai Hähnle" <Nicolai.Haehnle@amd.com>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Chris Wilson" <chris@chris-wilson.co.uk>,
	"Maarten Lankhorst" <maarten.lankhorst@canonical.com>,
	dri-devel@lists.freedesktop.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/4] locking/ww_mutex: Fix a deadlock affecting ww_mutexes
Date: Wed, 23 Nov 2016 15:03:36 +0100	[thread overview]
Message-ID: <20161123140336.GU3092@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1479900325-28358-1-git-send-email-nhaehnle@gmail.com>

On Wed, Nov 23, 2016 at 12:25:22PM +0100, Nicolai H�hnle wrote:
> @@ -473,7 +476,14 @@ void __sched ww_mutex_unlock(struct ww_mutex *lock)
>  	 */
>  	mutex_clear_owner(&lock->base);
>  #endif
> -	__mutex_fastpath_unlock(&lock->base.count, __mutex_unlock_slowpath);
> +	/*
> +	 * A previously _not_ waiting task may acquire the lock via the fast
> +	 * path during our unlock. In that case, already waiting tasks may have
> +	 * to back off to avoid a deadlock. Wake up all waiters so that they
> +	 * can check their acquire context stamp against the new owner.
> +	 */
> +	__mutex_fastpath_unlock(&lock->base.count,
> +				__mutex_unlock_slowpath_wakeall);
>  }

So doing a wake-all has obvious issues with thundering herd etc.. Also,
with the new mutex, you'd not be able to do hand-off, which would
introduce starvation cases.

Ideally we'd iterate the blocked list and pick the waiter with the
earliest stamp, or we'd maintain the list in stamp order instead of
FIFO, for ww_mutex.


WARNING: multiple messages have this Message-ID (diff)
From: Peter Zijlstra <peterz@infradead.org>
To: "Nicolai Hähnle" <nhaehnle@gmail.com>
Cc: "Nicolai Hähnle" <Nicolai.Haehnle@amd.com>,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	"Ingo Molnar" <mingo@redhat.com>,
	stable@vger.kernel.org,
	"Maarten Lankhorst" <maarten.lankhorst@canonical.com>
Subject: Re: [PATCH 1/4] locking/ww_mutex: Fix a deadlock affecting ww_mutexes
Date: Wed, 23 Nov 2016 15:03:36 +0100	[thread overview]
Message-ID: <20161123140336.GU3092@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1479900325-28358-1-git-send-email-nhaehnle@gmail.com>

On Wed, Nov 23, 2016 at 12:25:22PM +0100, Nicolai Hähnle wrote:
> @@ -473,7 +476,14 @@ void __sched ww_mutex_unlock(struct ww_mutex *lock)
>  	 */
>  	mutex_clear_owner(&lock->base);
>  #endif
> -	__mutex_fastpath_unlock(&lock->base.count, __mutex_unlock_slowpath);
> +	/*
> +	 * A previously _not_ waiting task may acquire the lock via the fast
> +	 * path during our unlock. In that case, already waiting tasks may have
> +	 * to back off to avoid a deadlock. Wake up all waiters so that they
> +	 * can check their acquire context stamp against the new owner.
> +	 */
> +	__mutex_fastpath_unlock(&lock->base.count,
> +				__mutex_unlock_slowpath_wakeall);
>  }

So doing a wake-all has obvious issues with thundering herd etc.. Also,
with the new mutex, you'd not be able to do hand-off, which would
introduce starvation cases.

Ideally we'd iterate the blocked list and pick the waiter with the
earliest stamp, or we'd maintain the list in stamp order instead of
FIFO, for ww_mutex.

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2016-11-23 15:19 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-23 11:25 [PATCH 1/4] locking/ww_mutex: Fix a deadlock affecting ww_mutexes Nicolai Hähnle
2016-11-23 11:25 ` [PATCH 2/4] locking/ww_mutex: Remove redundant wakeups in ww_mutex_set_context_slowpath Nicolai Hähnle
2016-11-23 11:25   ` Nicolai Hähnle
2016-11-23 11:25 ` [PATCH 3/4] locking/Documentation: fix a typo Nicolai Hähnle
2016-11-23 11:25   ` Nicolai Hähnle
2016-11-23 11:25 ` [PATCH 4/4] locking/ww_mutex: Fix a comment typo Nicolai Hähnle
2016-11-23 11:25   ` Nicolai Hähnle
2016-11-23 12:50 ` [PATCH 1/4] locking/ww_mutex: Fix a deadlock affecting ww_mutexes Daniel Vetter
2016-11-23 12:50   ` Daniel Vetter
2016-11-23 13:00 ` Peter Zijlstra
2016-11-23 13:00   ` Peter Zijlstra
2016-11-23 13:00   ` Peter Zijlstra
2016-11-23 13:08   ` Daniel Vetter
2016-11-23 13:08     ` Daniel Vetter
2016-11-23 13:11     ` Daniel Vetter
2016-11-23 13:11       ` Daniel Vetter
2016-11-23 13:11       ` Daniel Vetter
2016-11-23 13:33       ` Maarten Lankhorst
2016-11-23 13:33         ` Maarten Lankhorst
2016-11-23 14:03 ` Peter Zijlstra [this message]
2016-11-23 14:03   ` Peter Zijlstra
2016-11-23 14:03   ` Peter Zijlstra
2016-11-23 14:25   ` Daniel Vetter
2016-11-23 14:25     ` Daniel Vetter
2016-11-23 14:25     ` Daniel Vetter
2016-11-23 14:32     ` Peter Zijlstra
2016-11-23 14:32       ` Peter Zijlstra
2016-11-24 11:26     ` Nicolai Hähnle
2016-11-24 11:26       ` Nicolai Hähnle
2016-11-24 11:40       ` Peter Zijlstra
2016-11-24 11:40         ` Peter Zijlstra
2016-11-24 11:40         ` Peter Zijlstra
2016-11-24 11:52         ` Daniel Vetter
2016-11-24 11:52           ` Daniel Vetter
2016-11-24 11:56           ` Peter Zijlstra
2016-11-24 11:56             ` Peter Zijlstra
2016-11-24 12:05             ` Nicolai Hähnle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161123140336.GU3092@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=Nicolai.Haehnle@amd.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@canonical.com \
    --cc=mingo@redhat.com \
    --cc=nhaehnle@gmail.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.