From: Haakon Bugge <haakon.bugge@oracle.com>
To: John Stultz <jstultz@google.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Boqun Feng <boqun@kernel.org>, Waiman Long <longman@redhat.com>,
Chris Wilson <chris@chris-wilson.co.uk>,
Guenter Roeck <linux@roeck-us.net>,
Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH 3/4] test-ww_mutex: Handle transient -EDEADLK in test_cycle_work
Date: Mon, 22 Jun 2026 13:21:59 +0000 [thread overview]
Message-ID: <EEDAEE3C-FF42-455F-803F-4A599C281D39@oracle.com> (raw)
In-Reply-To: <CANDhNCpqorzwLCiTKD5N0TsbvCs0BgbjETRB0fkPCNjoteXoxg@mail.gmail.com>
Hi John,
> On 18 Jun 2026, at 21:04, John Stultz <jstultz@google.com> wrote:
>
>> On Wed, Jun 17, 2026 at 5:13 AM Håkon Bugge <haakon.bugge@oracle.com> wrote:
>>
>>
>> There is a timing issue in test_cycle_work(), in the sense that
>> acquiring *a_mutex* after deadlock has been detected on the *b_mutex*,
>> may not succeed immediately. This may lead to false negatives, which
>> shows up in the log as:
>>
>> cyclic deadlock not resolved, ret[77/93] = -35
>>
>> We fix that by re-trying until the lock is acquired.
>>
>
> I definitely have seen this error in testing previously.
>
> But is this fix right? When getting an EDEADLK I thought the ww_mutex
> protocol requires the task drop all its locks and re-try acquiring
> them all again.
This is true for deadlocks. But my main point is that this is *not* a
deadlock which requires one of the WW resolution methods. Put it
another way, if it *is* a deadlock, my do-while loop would loop
forever. It doesn't, and therefore, it isn't a deadlock.
Another question is of course why ww_mutex_lock() returns -EDEADLK
when it isn't the case.
>> Fixes: d1b42b800e5d ("locking/ww_mutex: Add kselftests for resolving ww_mutex cyclic deadlocks")
>> Fixes: e4a02ed2aaf4 ("locking/ww_mutex: Fix runtime warning in the WW mutex selftest")
>> Signed-off-by: Håkon Bugge <haakon.bugge@oracle.com>
>> ---
>> kernel/locking/test-ww_mutex.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c
>> index 5a4c92801bdfb..6b29a7a8f5fba 100644
>> --- a/kernel/locking/test-ww_mutex.c
>> +++ b/kernel/locking/test-ww_mutex.c
>> @@ -306,7 +306,9 @@ static void test_cycle_work(struct work_struct *work)
>> err = 0;
>> ww_mutex_unlock(&cycle->a_mutex);
>> ww_mutex_lock_slow(cycle->b_mutex, &ctx);
>> - erra = ww_mutex_lock(&cycle->a_mutex, &ctx);
>> + do {
>> + erra = ww_mutex_lock(&cycle->a_mutex, &ctx);
>> + } while (erra == -EDEADLK);
>> }
>>
> I don't have a clear example in mind, but just trying to grab the same
> lock again (especially in a loop with no timeout) seems like it could
> open up other problems here.
The do { ... } while (erra == -EDEADLK) loop in test_cycle_work() is
terminating under the ww-mutex progress guarantee. The test builds a
finite circular dependency where worker N waits on worker N+1’s
a_mutex. On -EDEADLK, the worker releases its own a_mutex, acquires
b_mutex through the slow path, and retries. Thus each deadlock
encounter removes one hold from the cycle before retrying. Since the
cycle is finite and every participant follows the same backoff rule,
the deadlock chain must eventually collapse; once the conflicting
owner releases its lock, the retry of a_mutex returns success and the
loop exits.
Thxs, Håkon
next prev parent reply other threads:[~2026-06-22 13:22 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 12:13 [PATCH 0/4] test-ww_mutex: Miscellaneous fixes Håkon Bugge
2026-06-17 12:13 ` [PATCH 1/4] test-ww_mutex: Fix module cleanup Håkon Bugge
2026-06-18 17:49 ` John Stultz
2026-06-17 12:13 ` [PATCH 2/4] test-ww_mutex: Report errors from stress workers Håkon Bugge
2026-06-18 17:52 ` John Stultz
2026-07-09 0:03 ` John Stultz
2026-07-09 16:51 ` Haakon Bugge
2026-06-17 12:13 ` [PATCH 3/4] test-ww_mutex: Handle transient -EDEADLK in test_cycle_work Håkon Bugge
2026-06-18 19:04 ` John Stultz
2026-06-22 13:21 ` Haakon Bugge [this message]
2026-07-08 19:55 ` John Stultz
2026-07-09 17:05 ` Haakon Bugge
2026-06-17 12:13 ` [PATCH 4/4] test-ww_mutex: Retry lock acquisition after timeout if deadlocked Håkon Bugge
2026-06-18 18:55 ` John Stultz
2026-06-22 13:47 ` Haakon Bugge
2026-07-06 9:01 ` Haakon Bugge
2026-07-06 9:02 ` Haakon Bugge
2026-07-08 20:01 ` John Stultz
2026-07-09 16:56 ` Haakon Bugge
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=EEDAEE3C-FF42-455F-803F-4A599C281D39@oracle.com \
--to=haakon.bugge@oracle.com \
--cc=boqun@kernel.org \
--cc=chris@chris-wilson.co.uk \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=longman@redhat.com \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®