[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <871r5sf7s1.ffs@tglx>
Date: Tue, 14 Sep 2021 00:08:30 +0200
From: Thomas Gleixner <tglx@...utronix.de>
To: Peter Zijlstra <peterz@...radead.org>, boqun.feng@...il.com
Cc: linux-kernel@...r.kernel.org, peterz@...radead.org,
Ingo Molnar <mingo@...nel.org>,
Juri Lelli <juri.lelli@...hat.com>,
Steven Rostedt <rostedt@...dmis.org>,
Davidlohr Bueso <dave@...olabs.net>,
Will Deacon <will@...nel.org>,
Waiman Long <longman@...hat.com>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
Mike Galbraith <efault@....de>,
Daniel Bristot de Oliveira <bristot@...hat.com>
Subject: Re: [PATCH 1/4] sched/wakeup: Strengthen
current_save_and_set_rtlock_wait_state()
On Thu, Sep 09 2021 at 12:59, Peter Zijlstra wrote:
> While looking at current_save_and_set_rtlock_wait_state() I'm thinking
> it really ought to use smp_store_mb(), because something like:
>
> current_save_and_set_rtlock_wait_state();
> for (;;) {
> if (try_lock())
> break;
>
> raw_spin_unlock_irq(&lock->wait_lock);
> schedule();
> raw_spin_lock_irq(&lock->wait_lock);
>
> set_current_state(TASK_RTLOCK_WAIT);
> }
> current_restore_rtlock_saved_state();
>
> which is the advertised usage in the comment, is actually broken,
> since trylock() will only need a load-acquire in general and that
> could be re-ordered against the state store, which could lead to a
> missed wakeup -> BAD (tm).
I don't think so because both the state store and the wakeup are
serialized via tsk->pi_lock.
> While there, make them consistent with the IRQ usage in
> set_special_state().
>
> Fixes: 5f220be21418 ("sched/wakeup: Prepare for RT sleeping spin/rwlocks")
> Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
> ---
> include/linux/sched.h | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -245,7 +245,8 @@ struct task_group;
> * if (try_lock())
> * break;
> * raw_spin_unlock_irq(&lock->wait_lock);
> - * schedule_rtlock();
> + * if (!cond)
> + * schedule_rtlock();
cond is not really relevant here.
> * raw_spin_lock_irq(&lock->wait_lock);
> * set_current_state(TASK_RTLOCK_WAIT);
> * }
> @@ -253,22 +254,24 @@ struct task_group;
> */
> #define current_save_and_set_rtlock_wait_state() \
> do { \
> - lockdep_assert_irqs_disabled(); \
> - raw_spin_lock(¤t->pi_lock); \
> + unsigned long flags; /* may shadow */ \
> + \
> + raw_spin_lock_irqsave(¤t->pi_lock, flags); \
Why? This is solely for the rtlock use case which invokes this with
interrupts disabled. So why do we need that irqsave() overhead here?
> current->saved_state = current->__state; \
> debug_rtlock_wait_set_state(); \
> - WRITE_ONCE(current->__state, TASK_RTLOCK_WAIT); \
> - raw_spin_unlock(¤t->pi_lock); \
> + smp_store_mb(current->__state, TASK_RTLOCK_WAIT); \
The try_lock() does not matter at all here, really. All what matters is
that the unlocker cannot observe the wrong state and that's fully
serialized via tsk::pi_lock.
Thanks,
tglx
Powered by blists - more mailing lists