From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751969AbcFWLTa (ORCPT ); Thu, 23 Jun 2016 07:19:30 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:38425 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751734AbcFWLT2 (ORCPT ); Thu, 23 Jun 2016 07:19:28 -0400 Date: Thu, 23 Jun 2016 13:19:20 +0200 From: Peter Zijlstra To: Yuyang Du , Ingo Molnar , linux-kernel , Mike Galbraith , Benjamin Segall , Paul Turner , Morten Rasmussen , Dietmar Eggemann , Matt Fleming , Vincent Guittot Subject: Re: [PATCH 4/4] sched,fair: Fix PELT integrity for new tasks Message-ID: <20160623111920.GJ30154@twins.programming.kicks-ass.net> References: <20160617120136.064100812@infradead.org> <20160617120454.150630859@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160617120454.150630859@infradead.org> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 17, 2016 at 02:01:40PM +0200, Peter Zijlstra wrote: > @@ -8219,6 +8254,19 @@ static int cpu_cgroup_can_attach(struct > if (task->sched_class != &fair_sched_class) > return -EINVAL; > #endif > + /* > + * Serialize against wake_up_new_task() such > + * that if its running, we're sure to observe > + * its full state. > + */ > + raw_spin_unlock_wait(&task->pi_lock); > + /* > + * Avoid calling sched_move_task() before wake_up_new_task() > + * has happened. This would lead to problems with PELT. See > + * XXX. > + */ > + if (task->state == TASK_NEW) > + return -EINVAL; > } > return 0; > } So I think that's backwards; we want: if (task->state == TASK_NEW) return -EINVAL; raw_spin_unlock_wait(&task->pi_lock); Because failing the attach is 'safe', but if we do not observe NEW we must be absolutely sure to observe the full wakeup_new. But since its not critical I'll change it to more obvious code: raw_spin_lock_irq(&task->pi_lock); if (task->state == TASK_NEW) ret = -EINVAL; raw_spin_unlock_irq(&task->pi_lock);