Received: by 10.192.165.148 with SMTP id m20csp1137140imm; Wed, 25 Apr 2018 13:11:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/cOtOdFBQDYGOjDikpaKvMgIUDMkZk5tW7UqkzShiksE2FX7tCTCy//OuoA5WABx7B9t4k X-Received: by 10.98.93.153 with SMTP id n25mr20584847pfj.143.1524687107825; Wed, 25 Apr 2018 13:11:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524687107; cv=none; d=google.com; s=arc-20160816; b=02qDC3MKgdqA4PNnC/rvcmPlB/uBjFmKug327lEbN//wWoc/F+AU9E+H695/SwqWeF pWfN4C9iBbdStZEHoj+SkG2HUhOM09HbphftjGMBKaMzzZJWedb1XWjOxAP3Imeq+C8S sVPTW5CYDHIoWKmbZk//xKooPq3swUsxhERCqOwpojXgP+bkJDtfnTlpz9lkSyn8ORmP P/Dzw2fPAcrvNArx8UOUAykyb/vtHtO53PsTPldg37DHY2qMElCNTF04mwtq/XsLwNXX b5na/MkkVFBkJ48UVoiaTvvuaEXL2ZLSnQaVik8cYbUF2I7cOUEVvAEJH2LfbSbwCdfW Uv+A== 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=CeTSADyI9C/hLkhxg6qHQmRy26UPVWRn9Utz/6Z4GVY=; b=iSasgwDgoy5hZ6rpbPVIsBHBa4BY/grF/CVvAPJpclrxKSnSitUAAOUpgx6luhCUO+ vfErs2+sqU+PBIkhf7rFNbaGJtGKhNNuWH5C3Z3qSHKokvwNOPKreIcehOe14nMdBS3P EqWnD65bkdNNPjp30hMOZLtaEkA+utLJmjU6JxhPC8I0OEljbxlFnkA+S4VTaPFBKT1M kJEomDWsGGGBS2W5vXnBZ2C9LYp6RKr7kZF4EfxR7Hle8YDxRxq6F6BzAU1yojJH26Tr puObjMCcgtCh7/Xm+RzHVhKp3UOwX4UJbErAkYJItHb91DbFix1pHw4lUtIrUj7WJ6u5 2kDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=J04PsYbf; 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 1-v6si13268396ply.464.2018.04.25.13.11.33; Wed, 25 Apr 2018 13:11:47 -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=J04PsYbf; 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 S1753714AbeDYUJ0 (ORCPT + 99 others); Wed, 25 Apr 2018 16:09:26 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:37816 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751151AbeDYUJY (ORCPT ); Wed, 25 Apr 2018 16:09:24 -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=CeTSADyI9C/hLkhxg6qHQmRy26UPVWRn9Utz/6Z4GVY=; b=J04PsYbf2URU0dTS64jZUjkUm Rm536/bEByPllIZuQIr/flFNsFjDAvEQilPyb083mB82L7XgvILVJU2ta8GU5dOXBIc3b9Ssje+ve pK7AMenuWhdrL5hWVNXUD8e9nVxFw6pq+a5if6w/KdIVhRVbyNjYZmi4v50kG8Zo9WM/dPtIG65Ce RhGzOlQS4a/8vbsn0EGnpbUhaSw8GowFLkjAZCqSYykxlt7Kh0EVIiZizNAGU9/spNtEwdIEGQukN OIRHrgHPLzpDJO6F56n4SjGqNCseXWF42fEDWkrED6yds67v/hojlQ1N/NkfU20sDGM+7olGOlbZO Icc97ukeA==; 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 1fBQj9-0000h9-47; Wed, 25 Apr 2018 20:09:19 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5AB042029FD42; Wed, 25 Apr 2018 22:09:17 +0200 (CEST) Date: Wed, 25 Apr 2018 22:09:17 +0200 From: Peter Zijlstra To: Gaurav Kohli Cc: 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: <20180425200917.GZ4082@hirez.programming.kicks-ass.net> References: <1524645199-5596-1-git-send-email-gkohli@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1524645199-5596-1-git-send-email-gkohli@codeaurora.org> User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 25, 2018 at 02:03:19PM +0530, Gaurav Kohli wrote: > diff --git a/kernel/smpboot.c b/kernel/smpboot.c > index 5043e74..c5c5184 100644 > --- a/kernel/smpboot.c > +++ b/kernel/smpboot.c > @@ -122,7 +122,45 @@ static int smpboot_thread_fn(void *data) > } > > if (kthread_should_park()) { > + /* > + * Serialize against wakeup. * * Prior wakeups must complete and later wakeups * will observe TASK_RUNNING. * * This avoids the case where the TASK_RUNNING * store from ttwu() competes with the * TASK_PARKED store from kthread_parkme(). * * If the TASK_PARKED store looses that * competition, kthread_unpark() will go wobbly. > + */ > + raw_spin_lock(¤t->pi_lock); > __set_current_state(TASK_RUNNING); > + raw_spin_unlock(¤t->pi_lock); > preempt_enable(); > if (ht->park && td->status == HP_THREAD_ACTIVE) { > BUG_ON(td->cpu != smp_processor_id()); Does that work for you? But looking at this a bit more; don't we have the exact same problem with the TASK_RUNNING store in the !ht->thread_should_run() case? Suppose a ttwu() happens concurrently there, it can end up competing against the TASK_INTERRUPTIBLE store, no? Of course, that race is not fatal, we'll just end up going around the loop once again I suppose. Maybe a comment there too? /* * A similar race is possible here, but loosing * the TASK_INTERRUPTIBLE store is harmless and * will make us go around the loop once more. */ And of course, I suspect we actually want to use TASK_IDLE, smpboot threads don't want signals do they? But that probably ought to be a separate patch.