lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87pmtcdr6a.ffs@tglx>
Date:   Tue, 14 Sep 2021 00:52:29 +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 Tue, Sep 14 2021 at 00:08, Thomas Gleixner wrote:

> 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(&current->pi_lock);			\
>> +		unsigned long flags; /* may shadow */			\
>> +									\
>> +		raw_spin_lock_irqsave(&current->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(&current->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.

If your reasoning would be correct, then set_special_state() would be
broken as well.

Thanks,

        tglx

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ