lkml.org 
[lkml]   [2021]   [Jul]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC][PATCH 1/4] locking/mutex: Use try_cmpxchg()
On Mon, Jul 05, 2021 at 07:59:12PM +0800, Xu, Yanfei wrote:
>
>
> On 6/30/21 11:35 PM, Peter Zijlstra wrote:
> > For simpler and better code.
> >
> > Signed-off-by: Peter Zijlstra (Intel)<peterz@infradead.org>
> > ---
> > kernel/locking/mutex.c | 27 ++++++---------------------
> > 1 file changed, 6 insertions(+), 21 deletions(-)
>
> Hi Peter,
>
> I read the mutex codes today, and find there seems something wrong for the
> patch. Should we consider the race condition as blow?
>
> From 4035f50c96e17cbe3febab768b64da5c000e5b76 Mon Sep 17 00:00:00 2001
> From: Yanfei Xu <yanfei.xu@windriver.com>
> Date: Mon, 5 Jul 2021 17:56:58 +0800
> Subject: [PATCH] locking/mutex: fix the endless loop when racing against
> mutex.owner
>
> if a race condition happened on mutex.owner after we fetch its value,
> atomic_long_try_cmpxchg_acquire/release invoked on &mutex.owner will
> return false. Then we need to reassign the temporary variable which
> saves mutex.owner value if in loop, or it will lead an endless loop.

No, when try_cmpxchg() fails it will update oldp. This is the reason old
is now a pointer too.

\
 
 \ /
  Last update: 2021-07-05 16:00    [W:1.225 / U:0.192 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site