Re: [PATCH 0/6] locking/rtmutex: Avoid PI state recursion through sched_submit_work()
From: Peter Zijlstra
Date: Thu Aug 17 2023 - 04:27:28 EST
On Thu, Aug 17, 2023 at 08:59:50AM +0200, Sebastian Andrzej Siewior wrote:
> On 2023-08-16 16:58:18 [+0200], Peter Zijlstra wrote:
> > I've ended up with the below, but it is quite horrible.. but let me go
> > stare at the futex wreckage before trying to clean things up.
>
> What about
Ah, of course, that's much nicer. I got hung up on that
rwbase_rtmutex_lock_state() thing :/
> diff --git a/kernel/locking/rwbase_rt.c b/kernel/locking/rwbase_rt.c
> index f8a194e7ec9e9..b5e881250fec5 100644
> --- a/kernel/locking/rwbase_rt.c
> +++ b/kernel/locking/rwbase_rt.c
> @@ -241,6 +241,8 @@ static int __sched rwbase_write_lock(struct rwbase_rt *rwb,
> /* Force readers into slow path */
> atomic_sub(READER_BIAS, &rwb->readers);
>
> + rt_mutex_pre_schedule();
> +
> raw_spin_lock_irqsave(&rtm->wait_lock, flags);
> if (__rwbase_write_trylock(rwb))
> goto out_unlock;
> @@ -252,6 +254,7 @@ static int __sched rwbase_write_lock(struct rwbase_rt *rwb,
> if (rwbase_signal_pending_state(state, current)) {
> rwbase_restore_current_state();
> __rwbase_write_unlock(rwb, 0, flags);
> + rt_mutex_post_schedule();
> trace_contention_end(rwb, -EINTR);
> return -EINTR;
> }
> @@ -270,6 +273,7 @@ static int __sched rwbase_write_lock(struct rwbase_rt *rwb,
>
> out_unlock:
> raw_spin_unlock_irqrestore(&rtm->wait_lock, flags);
> + rt_mutex_post_schedule();
> return 0;
> }
>
> Sebastian