Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1135807imm; Tue, 5 Jun 2018 09:36:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIaCVSh1wloXXUEH1nSeL1JfqEP/9oQ122FxrgKTFX11KS5xe9DIPgoXW1Oi59hFukvcQJa X-Received: by 2002:a63:ab45:: with SMTP id k5-v6mr21199722pgp.192.1528216562606; Tue, 05 Jun 2018 09:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528216562; cv=none; d=google.com; s=arc-20160816; b=CBS8lKJ7Aa85BZ7QFT0JkZPNY4Uv+pwgMdvdY9lvxvUcy+oKri5UQXLGoEfMBGToE6 kVYQdQmTWPU1kUMI9tuI2Y/OeUmyni+er902GObeT0Qg6T1vaUwcAN+3wgSjVyugSH2U 3LBwrON89Z/zWNyx9YSUxs1NS+UI/MmaWxd9kuPa9y41sMTfMu9djPsjJy6lz0l87EMJ t1+O14OybPsrdJIRx+k1DqdDeZDuZuxz36N71fPAX/TS/rhtjNMs/u2hzU9HlvgfoZdq F8vxoRNwtRFyiD0gHzv+r/vrbS8H//G0u4gbK2f9GK8PR9aMXEYdTd216cFBLq0X7FA1 sWrA== 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:arc-authentication-results; bh=laTcc8I3TiDRD1v9/5i7ths5ReNsfFYeqLSo+mRcoDE=; b=A34Tib09qFMs27Kixs9kzm7gOdYqmkuesSbF+sjJd/5ZTALpqIl7Ca0oy67NT0BBhy t9HV1n6LLD9Yj6UJZNk6UrMH7NByVvzhl1mjAWeIN5w7IvhAJxcCT+fsaVdLVj1/ICos BI6sTrPwnmCqcovRIhrsNz2bIqnolpZoYwtmeLngJUW4BTPoAYiXpO59CzDl/AGjb1Er OryeRR+NBk6vy1WA1aLKsc+TLSTh/adJeZIs92rfrAWP0i3/YGrdB1bVDuhq5SbbpxsH 4z3lPLqao+dHY41JFUZdk6CHFAQ/vweb5G+nlW9yHxCwuUP/0lMr50EcaTrglx2RiXTR Stag== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i25-v6si22076852pgn.638.2018.06.05.09.35.48; Tue, 05 Jun 2018 09:36:02 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752030AbeFEQfU (ORCPT + 99 others); Tue, 5 Jun 2018 12:35:20 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41586 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751748AbeFEQfT (ORCPT ); Tue, 5 Jun 2018 12:35:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A1A1B4075E40; Tue, 5 Jun 2018 16:35:18 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.34.27.30]) by smtp.corp.redhat.com (Postfix) with SMTP id 013A5111AF3C; Tue, 5 Jun 2018 16:35:16 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 5 Jun 2018 18:35:18 +0200 (CEST) Date: Tue, 5 Jun 2018 18:35:16 +0200 From: Oleg Nesterov To: Peter Zijlstra 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: <20180605163515.GB24053@redhat.com> References: <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> <20180605152212.GY12180@hirez.programming.kicks-ass.net> <20180605154053.GB12235@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180605154053.GB12235@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 05 Jun 2018 16:35:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 05 Jun 2018 16:35:18 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'oleg@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/05, Peter Zijlstra wrote: > > On Tue, Jun 05, 2018 at 05:22:12PM +0200, Peter Zijlstra wrote: > > > > 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. > > This should ensure we only ever complete when we read PARKED, right? > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 8d59b259af4a..e513b4600796 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -2641,7 +2641,7 @@ prepare_task_switch(struct rq *rq, struct task_struct *prev, > * past. prev == current is still correct but we need to recalculate this_rq > * because prev may have moved to another CPU. > */ > -static struct rq *finish_task_switch(struct task_struct *prev) > +static struct rq *finish_task_switch(struct task_struct *prev, bool preempt) > __releases(rq->lock) > { > struct rq *rq = this_rq(); > @@ -2674,7 +2674,7 @@ static struct rq *finish_task_switch(struct task_struct *prev) > * > * We must observe prev->state before clearing prev->on_cpu (in > * finish_task), otherwise a concurrent wakeup can get prev > - * running on another CPU and we could rave with its RUNNING -> DEAD > + * running on another CPU and we could race with its RUNNING -> DEAD > * transition, resulting in a double drop. > */ > prev_state = prev->state; > @@ -2720,7 +2720,8 @@ static struct rq *finish_task_switch(struct task_struct *prev) > break; > > case TASK_PARKED: > - kthread_park_complete(prev); > + if (!preempt) > + kthread_park_complete(prev); Yes, but this won't fix the race decribed by Kohli... Plus this complicates the schedule() paths for the very special case, and to me it seems that all this kthread_park/unpark logic needs some serious cleanups... Not that I can suggest something better right now. Oleg.