Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752454AbdI2I2s (ORCPT ); Fri, 29 Sep 2017 04:28:48 -0400 Received: from merlin.infradead.org ([205.233.59.134]:38710 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752159AbdI2I2q (ORCPT ); Fri, 29 Sep 2017 04:28:46 -0400 Date: Fri, 29 Sep 2017 10:28:38 +0200 From: Peter Zijlstra To: Thomas Gleixner Cc: Junaid Shahid , linux-kernel@vger.kernel.org, Andres Lagar-Cavilla , Greg Thelen , Rusty Russell Subject: Re: [PATCH] kthread: Fix race condition between kthread_parkme() and kthread_unpark() Message-ID: <20170929082838.z2eyp67hbdfcpibj@hirez.programming.kicks-ass.net> References: <20170429023236.60452-1-junaids@google.com> <20170927121706.g5qydxv3v2usmdd5@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1025 Lines: 22 On Fri, Sep 29, 2017 at 09:59:55AM +0200, Thomas Gleixner wrote: > On Thu, 28 Sep 2017, Junaid Shahid wrote: > > > Hi Peter, > > > > It looks like try_cmpxchg is not available on non-x86 archs, but other than > > that the version that you proposed looks good. > > > > One thing that I am a bit curious about is that the original code, before > > either patch, had a test_and_set_bit for KTHREAD_IS_PARKED rather than just > > a set_bit. I can't think of any reason why that was needed, since it > > doesn't look like TASK_PARKED tasks are susceptible to spurious wakeups. Do > > you by any chance happen to know if there was any specific reason for it? > > Everything is susceptible to spurious wakeups and has to deal with it. Right, we should code as if they are at all times possible. Currently, for TASK_PARKED, I don't think they can happen, but I've had patches that introduce them on purpose (regardless the state) just to stress the code. IIRC only TASK_STOPPED and/or TASK_TRACED hard rely on not getting any.