Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752671AbdI2U6g (ORCPT ); Fri, 29 Sep 2017 16:58:36 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:52570 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752003AbdI2U6a (ORCPT ); Fri, 29 Sep 2017 16:58:30 -0400 X-Google-Smtp-Source: AOwi7QBUpzTuewCecAcY8sC4gvvsc759KwuE5Ob+e8fYFGvFNhiKWw6aaoER/j4tmad/LkxZizumNg== From: Junaid Shahid To: Peter Zijlstra Cc: Thomas Gleixner , 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() Date: Fri, 29 Sep 2017 13:58:28 -0700 Message-ID: <1906007.YVkLUJZ5jy@js-desktop.svl.corp.google.com> Organization: Google User-Agent: KMail/4.13.3 (Linux/4.4.0-93-generic; KDE/4.13.3; x86_64; ; ) In-Reply-To: <20170929082838.z2eyp67hbdfcpibj@hirez.programming.kicks-ass.net> References: <20170429023236.60452-1-junaids@google.com> <20170929082838.z2eyp67hbdfcpibj@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id v8TKweEg020265 Content-Length: 1472 Lines: 28 Thanks for the clarification. But in that case, shouldn’t the patch check whether IS_PARKED was already set before calling complete(&self->parked)? Otherwise, the completion count for self->parked could be more than 1 as a result of spurious wakeups, which could make a future call to kthread_park complete prematurely. Thanks, Junaid On Friday, September 29, 2017 10:28:38 AM Peter Zijlstra wrote: > 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.