From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-f67.google.com ([209.85.208.67]:42739 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726950AbeIKRsM (ORCPT ); Tue, 11 Sep 2018 13:48:12 -0400 Received: by mail-ed1-f67.google.com with SMTP id l5so19133790edw.9 for ; Tue, 11 Sep 2018 05:49:01 -0700 (PDT) Message-ID: <1536670138.2710.20.camel@arista.com> Subject: Re: [PATCHv3 2/6] tty/ldsem: Update waiter->task before waking up reader From: Dmitry Safonov To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Dmitry Safonov <0x7f454c46@gmail.com>, Daniel Axtens , Dmitry Vyukov , Michael Neuling , Mikulas Patocka , Nathan March , Pasi =?ISO-8859-1?Q?K=E4rkk=E4inen?= , Peter Hurley , "Rong, Chen" , Sergey Senozhatsky , Tan Xiaojun , Tetsuo Handa , stable@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , "Paul E. McKenney" Date: Tue, 11 Sep 2018 13:48:58 +0100 In-Reply-To: <20180911114043.GR24106@hirez.programming.kicks-ass.net> References: <20180911014821.26286-1-dima@arista.com> <20180911014821.26286-3-dima@arista.com> <20180911114043.GR24106@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: stable-owner@vger.kernel.org List-ID: On Tue, 2018-09-11 at 13:40 +0200, Peter Zijlstra wrote: > On Tue, Sep 11, 2018 at 02:48:17AM +0100, Dmitry Safonov wrote: > > There is a couple of reports about lockup in ldsem_down_read() > > without > > anyone holding write end of ldisc semaphore: > > lkml.kernel.org/r/<20171121132855.ajdv4k6swzhvktl6@wfg-t540p.sh.int > > el.com> > > lkml.kernel.org/r/<20180907045041.GF1110@shao2-debian> > > > > They all looked like a missed wake up. > > I wasn't lucky enough to reproduce it, but it seems like reader on > > another CPU can miss waiter->task update and schedule again, > > resulting > > in indefinite (MAX_SCHEDULE_TIMEOUT) sleep. > > > > Make sure waked up reader will see waiter->task == NULL. > > --- a/drivers/tty/tty_ldsem.c > > +++ b/drivers/tty/tty_ldsem.c > > @@ -118,6 +118,8 @@ static void __ldsem_wake_readers(struct > > ld_semaphore *sem) > > tsk = waiter->task; > > smp_mb(); > > waiter->task = NULL; > > + /* Make sure down_read_failed() will see !waiter- > > >task update */ > > + smp_wmb(); > > wake_up_process(tsk); > > This is 'wrong', wake_up_process() should imply sufficient for this > to > already be true. Yeah, thanks. It was stupid of me not to check that.. Saw the smoke that would describe the reports and made too long-going conjectures. Need more covfefe and staring into that code. > > > put_task_struct(tsk); > > } -- Thanks, Dmitry