Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1051270imm; Tue, 5 Jun 2018 08:23:26 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKKS2ldkwCOg5kuOA2iSs/TM/3kFwgmI0uvtpenH9AngMobxbYHKnFWZfgySu8osBMVfH5k X-Received: by 2002:a17:902:2c01:: with SMTP id m1-v6mr25871283plb.347.1528212206739; Tue, 05 Jun 2018 08:23:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528212206; cv=none; d=google.com; s=arc-20160816; b=RsNRu0qmSgEdghMTP+tS34kvOCGYkZc6dTjaO/U+JDqgv5Am6NLCLdUBwmpsRuGtKm DPTbk3EaFX242e0YtL+eJKfh1Uhzw7muWFJfT8sklsE0EDc1E5q0xR9j+YhTbkOFnfiC pjHC/z9pMXGEMIB04tfxLYLL+I1sbAPxBL9xzt2xfEL0OIC2eKF82V+HJmvudfCq1Tx4 hxTbftcM9LfmCHIRVH4FzDo2FHk7dW2dRUKB3oDkKeUacNa61rBl24gilqlxTSnW8+8R 9LZKFg4lpPTZ1sEBul6CqJJSV4asU+PB89mT3pylqsSW8oQzPrlR0nEhi9EoDm0fkLa0 tkPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=vWmVx+PD6RJ1cIjfIJOmvVgVKmQBBjWhonWRfW1N2fw=; b=rbsSjmZ14a4BCvdFSFnMoRoWLMeQBpoE9JZggjHt++EKlImhI2TZ7VqFB3273f1EjR COWeOraWNM5+P6JMWdwKsZoiyZTSqlwne3HNe7khuDsOIL695qWpYaYl8NWQWopWzHSB CVSNb3zC2NPoV6zTwNq0g0fe4dMCU4BTAlnTIYvcxa/+yhy+YdaEJOUbtEMUXNIg/PE/ hbRdALiFJIoDqXTkLcDei9p/bpXuGUEHkmFBVxm2Q3pE/s/uHpW3RBhenzcuiSaafs2A kzCbAmzr6vJYqkJJvMkJob6rn3h8eQw25NCqU/ktbsCpUvoIV9b5yLfgIXi0l/I4DJ3d myYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=qBTrjrL5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t5-v6si18561678pgu.305.2018.06.05.08.23.12; Tue, 05 Jun 2018 08:23:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=qBTrjrL5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752358AbeFEPWW (ORCPT + 99 others); Tue, 5 Jun 2018 11:22:22 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:45336 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751599AbeFEPWU (ORCPT ); Tue, 5 Jun 2018 11:22:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=vWmVx+PD6RJ1cIjfIJOmvVgVKmQBBjWhonWRfW1N2fw=; b=qBTrjrL5GktvV2ln3gWqB09nN pZ1+iBpGDJ8YGAQ/NYhgiVraQPJxbKW4T5SNxLxzaY3uPYo0PJ5hnyrTbCxWbkCfnB2ytc14QVRvO Kl+M6LkHrzjEMp78HWI36gb0Ipvwi/30cGMILhOJhDivNlr67Oc3LYcGjxuOiplLHm03kJZnouiNf xnj8sr1sx2vZwHSQnzj5YiTxeMmItgMVM+Myey81H9ystvVe0M6AhlIEinJI8GmS2nLQL9ew9Cr3r hI9R8u+Q2+cU34KlDfWF9uN8LN+PZnRRhEvgbmTiJNqM159o7XSMWY0i4mLXKQAneWgOpyQI/t3ru 0xUrUbpog==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fQDmn-00082Y-Mp; Tue, 05 Jun 2018 15:22:13 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 30DE4201EA7A5; Tue, 5 Jun 2018 17:22:12 +0200 (CEST) Date: Tue, 5 Jun 2018 17:22:12 +0200 From: Peter Zijlstra To: Oleg Nesterov Cc: "Kohli, Gaurav" , tglx@linutronix.de, mpe@ellerman.id.au, mingo@kernel.org, bigeasy@linutronix.de, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Neeraj Upadhyay , Will Deacon Subject: Re: [PATCH v1] kthread/smpboot: Serialize kthread parking against wakeup Message-ID: <20180605152212.GY12180@hirez.programming.kicks-ass.net> References: <20180501113132.GF12217@hirez.programming.kicks-ass.net> <745d762d-9ab3-0749-9b87-9bb03d913071@codeaurora.org> <20180501131904.GG12217@hirez.programming.kicks-ass.net> <9b289790-9b3a-73bd-7166-bf39f32cefd8@codeaurora.org> <20180502082011.GB12180@hirez.programming.kicks-ass.net> <830d7225-af90-a55a-991a-bb2023d538f1@codeaurora.org> <55221a5b-dd52-3359-f582-86830dd9f205@codeaurora.org> <20180605150841.GA24053@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180605150841.GA24053@redhat.com> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 05, 2018 at 05:08:41PM +0200, Oleg Nesterov wrote: > On 06/05, Kohli, Gaurav wrote: > > > > As last mentioned on mail, we are still seeing issue with the latest > > approach and below is the susceptible race as mentioned earlier.. > > controller Thread CPUHP Thread > > takedown_cpu > > kthread_park > > kthread_parkme > > Set KTHREAD_SHOULD_PARK > > smpboot_thread_fn > > set Task interruptible > > > > > > wake_up_process > > if (!(p->state & state)) > > goto out; > > > > Kthread_parkme > > SET TASK_PARKED > > schedule > > raw_spin_lock(&rq->lock) > > ttwu_remote > > waiting for __task_rq_lock > > context_switch > > > > finish_lock_switch > > > > > > > > Case TASK_PARKED > > kthread_park_complete > > > > > > SET Running > > I think you are right. > > And, now that I look at 85f1abe0019fcb3ea10df7029056cf42702283a8 > ("kthread, sched/wait: Fix kthread_parkme() completion issue") I see this note > int the changelog: > > The alternative is to promote TASK_PARKED to a special state, this > guarantees wait_task_inactive() cannot observe a 'stale' TASK_RUNNING > and we'll end up doing the right thing, but this preserves the whole > icky business of potentially migating the still runnable thing. > > OK, but __kthread_parkme() can be preempted before it calls schedule(), so the > caller still can be migrated? Plus kthread_park_complete() can be called twice. Argh... I forgot TASK_DEAD does the whole thing with preempt_disable(). Let me stare at that a bit.