From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-he1eur01on0104.outbound.protection.outlook.com ([104.47.0.104]:53472 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726569AbeIKQD4 (ORCPT ); Tue, 11 Sep 2018 12:03:56 -0400 Subject: Re: Re: [PATCHv3 2/6] tty/ldsem: Update waiter->task before waking up reader To: Sergey Senozhatsky , Dmitry Safonov Cc: linux-kernel@vger.kernel.org, Dmitry Safonov <0x7f454c46@gmail.com>, Daniel Axtens , Dmitry Vyukov , Michael Neuling , Mikulas Patocka , Nathan March , =?UTF-8?B?UGFzaSBLw6Rya2vDpGluZW4=?= , Peter Hurley , "Rong, Chen" , Tan Xiaojun , Tetsuo Handa , stable@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , Peter Zijlstra , "Paul E. McKenney" References: <20180911014821.26286-1-dima@arista.com> <20180911014821.26286-3-dima@arista.com> <20180911050449.GB4065@jagdpanzerIV> <20180911054129.GC4065@jagdpanzerIV> From: Kirill Tkhai Message-ID: Date: Tue, 11 Sep 2018 14:04:13 +0300 MIME-Version: 1.0 In-Reply-To: <20180911054129.GC4065@jagdpanzerIV> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: stable-owner@vger.kernel.org List-ID: On 9/11/18 8:41 AM, Sergey Senozhatsky wrote: > On (09/11/18 14:04), Sergey Senozhatsky wrote: >>> for (;;) { >>> set_current_state(TASK_UNINTERRUPTIBLE); >> >> I think that set_current_state() also executes memory barrier. Just >> because it accesses task state. >> >>> - if (!waiter.task) >>> + if (!READ_ONCE(waiter.task)) >>> break; >>> if (!timeout) >>> break; > > This READ_ONCE(waiter.task) looks interesting. Maybe could be moved > to a loop condition > > while (!READ_ONCE(waiter.task)) { > ... > } We can't reorder event check and set_current_state(), because this will lead to missing of wakeup: Documentation/memory-barriers.txt Also, it looks like READ_ONCE() is not need. In case of compiler had optimized this, then all wait_event() in kernel w/o READ_ONCE would have not worked like expected, wouldn't they? Kirill