[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YOMQYQr1loxIuZbU@hirez.programming.kicks-ass.net>
Date: Mon, 5 Jul 2021 16:00:01 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: "Xu, Yanfei" <yanfei.xu@...driver.com>
Cc: mingo@...hat.com, longman@...hat.com, boqun.feng@...il.com,
will@...nel.org, linux-kernel@...r.kernel.org
Subject: Re: [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@...radead.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@...driver.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.
Powered by blists - more mailing lists