mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: peterz@infradead.org, tglx@kernel.org, mingo@redhat.com,
	linux-kernel@vger.kernel.org, will@kernel.org, boqun@kernel.org,
	longman@redhat.com, rostedt@goodmis.org, clrkwllms@kernel.org,
	dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com,
	shuah@kernel.org, juri.lelli@redhat.com,
	linux-rt-devel@lists.linux.dev, linux-kselftest@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 3/5] locking/rtmutex: Clone the sort keys in rt_mutex_enqueue_pi()
Date: Mon, 16 Nov 2026 16:11:52 +0100	[thread overview]
Message-ID: <20261116151152.vDbnofKe@linutronix.de> (raw)
In-Reply-To: <20261108141347.1525532-4-mathieu.desnoyers@efficios.com>

On 2026-11-08 09:13:45 [-0500], Mathieu Desnoyers wrote:
> An rt_mutex waiter has two copies of its sort keys. waiter->tree sorts
> the waiters of its lock. waiter->pi_tree sorts the pi_waiters of the
> lock owner. Only the top waiter of each lock is in pi_waiters.
> 
> When the priority of a waiter changes, the chain walk updates
> waiter->tree. It copies waiter->tree to waiter->pi_tree for the top
> waiter only. A waiter that is not the top waiter keeps its old pi_tree
> keys.
> 
> Such a waiter can become the top waiter later. remove_waiter() does this
> when the top waiter leaves. try_to_take_rt_mutex() does it when the lock
> changes owner. Both put the new top waiter in pi_waiters without a new
> copy. So pi_waiters sorts it by a priority it no longer has. The owner
> then inherits from the wrong waiter, at that waiter's current priority.
> 
> In this example, O is the owner, a SCHED_OTHER task. L1 and L2 are two
> rt_mutexes. W1, W2 and W3 are waiters. Their SCHED_FIFO priority is
> under their name. T is any other task. It changes the priority of W2:
> 
>   T                         O                W1                            W2           W3
>                                              FIFO 80                       FIFO 70      FIFO 50
> 
>                             locks L1, L2
>                                                                                         blocks on L2
>                                              blocks on L1 (timed)
>                                                                            blocks on L1
>   sched_setscheduler(W2)
>     W2 now at FIFO 10
>     rt_mutex_adjust_pi(W2)
>       W2->tree: FIFO 10
>       W2 not top: no copy
>       W2->pi_tree: FIFO 70
>                                              <timeout>
>                                              remove_waiter()
>                                                rt_mutex_enqueue_pi(O, W2)
>                                                  W2 sorted as FIFO 70,
>                                                  ahead of W3
>                                                rt_mutex_adjust_prio(O)
>                                                  O inherits W2's FIFO 10
>                             runs at FIFO 10                                             still waits
> 
> The owner runs at SCHED_FIFO 10 while a SCHED_FIFO 50 task waits for
> it. This needs no race. Each step can come long after the one before.
> 
> Fix this by copying the keys in rt_mutex_enqueue_pi(). All callers hold
> the wait_lock and the owner's pi_lock, as waiter_clone_prio() requires.
> Remove the three copies the callers made.
> 
> With this patch, the owner runs at SCHED_FIFO 50. The
> futex_lock_pi_inherit selftest added later in this series tests this
> case (promoted_waiter).
> 
> Fixes: f7853c342418 ("locking/rtmutex: Fix task->pi_waiters integrity")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

For this case, we miss one waiter_clone_prio() in remove_waiter(). Given
how this is used, I don't see nothing wrong with moving before it is
actually used. It might otherwise race in task_blocks_on_rt_mutex()
since the pi-lock is dropped. I somehow assumed the adjust-prio will fix
this.

Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Sebastian

  reply	other threads:[~2026-11-16 15:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-08 14:13 [PATCH v2 0/5] locking/rtmutex: priority inheritance fixes and tests Mathieu Desnoyers
2026-11-08 14:13 ` [PATCH v2 1/5] locking/rtmutex: Stop spinning on the owner when the waiter is woken Mathieu Desnoyers
2026-11-16 12:06   ` Sebastian Andrzej Siewior
2026-11-08 14:13 ` [PATCH v2 2/5] locking/rtmutex: Initialize the ww_mutex context of a waiter Mathieu Desnoyers
2026-11-16 13:58   ` Sebastian Andrzej Siewior
2026-11-08 14:13 ` [PATCH v2 3/5] locking/rtmutex: Clone the sort keys in rt_mutex_enqueue_pi() Mathieu Desnoyers
2026-11-16 15:11   ` Sebastian Andrzej Siewior [this message]
2026-11-08 14:13 ` [PATCH v2 4/5] selftests/futex: Test priority inheritance on PI futexes Mathieu Desnoyers
2026-11-08 14:13 ` [PATCH v2 5/5] locking/ww_mutex/test: Time an ABBA with both owners running Mathieu Desnoyers

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=20261116151152.vDbnofKe@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=andrealmeid@igalia.com \
    --cc=boqun@kernel.org \
    --cc=clrkwllms@kernel.org \
    --cc=dave@stgolabs.net \
    --cc=dvhart@infradead.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=longman@redhat.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=shuah@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@kernel.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®