All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Gerum <rpm@xenomai.org>
To: Luc Montier <luc.montier@etu.unistra.fr>
Cc: xenomai@lists.linux.dev
Subject: Re: [libevl][PATCH] lib/mutex: init recursion count after trylock via the core
Date: Fri, 30 Oct 2026 10:19:01 +0100	[thread overview]
Message-ID: <877bizwnp6.fsf@xenomai.org> (raw)
In-Reply-To: <87cxsrwof0.fsf@xenomai.org> (Philippe Gerum's message of "Fri, 30 Oct 2026 10:03:31 +0100")

Philippe Gerum <rpm@xenomai.org> writes:

> Luc Montier <luc.montier@etu.unistra.fr> writes:
>
>> evl_trylock_mutex() takes the slow path to the core when try_lock()
>> returns -ENODATA, e.g. for a thread running in-band. Unlike
>> evl_timedlock_mutex(), it does not initialize gate.nesting once
>> EVL_MONIOC_TRYENTER succeeds.
>>
>> For a recursive mutex, nesting then stays at 0 after the first lock
>> instead of 1. After N successful lock calls by the owner, nesting is
>> N - 1, so the (N - 1)th unlock releases the mutex and the last one
>> fails with -EPERM.
>>
>> Set nesting to 1 after a successful TRYENTER, as evl_timedlock_mutex()
>> does after EVL_MONIOC_ENTER.
>>
>> Signed-off-by: Luc Montier <luc.montier@etu.unistra.fr>
>> ---
>> Hello,
>>
>> This patch is against libevl r50-5 (e7dc1af, Jan 2025), the version
>> that matches my kernel (6.6.74, EVL ABI level 37, Raspberry Pi 5).
>> I could not test it on master, which requires ABI 47.
>>
>> Reproducer: a recursive mutex, a thread running in-band when it calls
>> evl_trylock_mutex() three times, then three evl_unlock_mutex() calls.
>> The last unlock fails with -EPERM, and gate.nesting reads 0, 1, 2 after
>> the locks. With the patch it reads 1, 2, 3 and all unlocks succeed.
>>
>> On master, this code now seems to live in lib/intrinsics/gate.c. Is
>> this already fixed there, and where would the fix belong?
>>
>> I just want to if it is an issue from libevl or a misuse on my part.
>>
>> Best regards,
>> Luc Montier
>>
>>
>>  lib/mutex.c | 8 +++++++-
>>  1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/lib/mutex.c b/lib/mutex.c
>> index 276e77f..832268f 100644
>> --- a/lib/mutex.c
>> +++ b/lib/mutex.c
>> @@ -332,6 +332,7 @@ int evl_lock_mutex(struct evl_mutex *mutex)
>>  
>>  int evl_trylock_mutex(struct evl_mutex *mutex)
>>  {
>> +	struct evl_monitor_state *gst;
>>  	int ret;
>>  
>>  	ret = try_lock(mutex);
>> @@ -341,7 +342,12 @@ int evl_trylock_mutex(struct evl_mutex *mutex)
>>  	do
>>  		ret = oob_ioctl(mutex->u.active.efd, EVL_MONIOC_TRYENTER);
>>  	while (ret && errno == EINTR);
>>
>> +	if (ret == 0) {
>> +		gst = mutex->u.active.state;
>> +		gst->u.gate.nesting = 1;
>> +	}
>> +
>>  	return ret ? -errno : 0;
>>  }
>
> Thanks for looking into this. I don't know about libevl r50{-5}, since
> we are not adding any patch sequence to libevl releases. This said, this
> issue was already fixed by commit 189e496e (ABI 44).
>

Note: this is a kernel-side commit in branch rebase/v6.12.y-cip-evl
available from all kernel releases we maintain as well.

-- 
Philippe.

      reply	other threads:[~2026-10-30  9:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29  8:28 [libevl][PATCH] lib/mutex: init recursion count after trylock via the core Luc Montier
2026-10-30  9:03 ` Philippe Gerum
2026-10-30  9:19   ` Philippe Gerum [this message]

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=877bizwnp6.fsf@xenomai.org \
    --to=rpm@xenomai.org \
    --cc=luc.montier@etu.unistra.fr \
    --cc=xenomai@lists.linux.dev \
    /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.