Received: by 10.192.165.148 with SMTP id m20csp4778357imm; Tue, 1 May 2018 03:45:40 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpiV7iSwJCbBxRrQ715Kv6YPN5QHPDaUpqhxA4w+CotsllWQKXFNmhYLWBAgxPGwZWIGxGX X-Received: by 10.98.79.12 with SMTP id d12mr15124862pfb.220.1525171540462; Tue, 01 May 2018 03:45:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525171540; cv=none; d=google.com; s=arc-20160816; b=DiiI/MppUXqKIoMnDQo5c8L1Zxua5wzXPFAtfxJdec+huFHW69Yhc36i0+UZfgemgU d80VCYEaC4zu2MWmqqhNG6vYcnS6PSo3y0a1nK/D0hDLeNWMg0TNoTS6/C1o7blMiPgn x/hA+r8G2H1ir3MZRkvvfED+7GcAYGFIzpt9c+HMlcPuQ6WfQ+v04dL8hHpqDBM2JhSm iJUFrBSUSswzslglhDicgktsLivEKOR0cA5mt4rna4N3ha0dCkoPq0XnCYOlUX23+xB2 cMF3+kSNBgzHS009M6rPLzXJnKHixMZIIVExosLxaB/8+51nMAqnjq14DTiio0868Upq pvFA== 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=IpvoV+OFICss47Gez2xSoeXPp4yMCkb3FTl8cgKFrXA=; b=pL4m3OpgRISdo7hUBUzc3WsGUWqcqpyAU6yvBEgg+Qv1ZdokpwY6zvkfohV03PmMZ7 HUKVBiWdoYSKqpR5pIXINELL3l+d3sDgA/SSd3WvAyW6s8b/FP4VbmAxCyrYTfgpNkiv Mr2cpGIwup/r5sWVdgZjOqPYLzhvo0P0jsnPrIWgEHL3XvnOZGj4hBWWTQ6tq2qfjA3a tW4+ZnfUzdtii2LGp7688zqpufXbUs84evG+bT8JZxCa3ctVAQGDW4iOF8njeE8mslNR jNkD/q2yAE8/CHNqKeXNvNgv8t4yGwlVLkvjeuQLjUm72oZ3J/kv+mjVUKZsuPmipC+s x0mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Uv8glNoh; 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 d124si9320444pfc.22.2018.05.01.03.45.25; Tue, 01 May 2018 03:45:40 -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=Uv8glNoh; 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 S1754437AbeEAKpI (ORCPT + 99 others); Tue, 1 May 2018 06:45:08 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:36354 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752009AbeEAKpH (ORCPT ); Tue, 1 May 2018 06:45:07 -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=IpvoV+OFICss47Gez2xSoeXPp4yMCkb3FTl8cgKFrXA=; b=Uv8glNoh5Alecr0rPeoj8hM7U bEov64pLM29mi8i+cwrdFMiV2FfVOqVCBvbeLn4UScV+VrOhlOlUs5qHoGUbOFV3s1KQzWdlkyeuV 1u8yS6MSNzHfPRRVVdZFvehcUe2dIkDyNd79x6sWXqY8/lrTQZbuyOJeqArtbw0os8PjroyXEVHgV ax/sIM2/LESXqho0at5M4Z6/kCyOUQeaKERgKjXnvnJtT8GQEoFB6STrGdm/sV4SN0JrAVGloQzbH hfVsyb0LxUeDhM88MJs44sKtxoofpQDugJ5CpqX9yT6aOOyJvevIH9JIQ6LEu2je9ptcXsjUEmT9z Z3KtEko1w==; 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 1fDSmL-000509-8z; Tue, 01 May 2018 10:45:01 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id BFB302029FA14; Tue, 1 May 2018 12:44:59 +0200 (CEST) Date: Tue, 1 May 2018 12:44:59 +0200 From: Peter Zijlstra To: "Kohli, Gaurav" 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 , Oleg Nesterov Subject: Re: [PATCH v1] kthread/smpboot: Serialize kthread parking against wakeup Message-ID: <20180501104459.GF12235@hirez.programming.kicks-ass.net> References: <1524645199-5596-1-git-send-email-gkohli@codeaurora.org> <20180425200917.GZ4082@hirez.programming.kicks-ass.net> <20180426084131.GV4129@hirez.programming.kicks-ass.net> <20180426085719.GW4129@hirez.programming.kicks-ass.net> <4d3f68f8-e599-6b27-a2e8-9e96b401d57a@codeaurora.org> <20180430111744.GE4082@hirez.programming.kicks-ass.net> <3af3365b-4e3f-e388-8e90-45a3bd4120fd@codeaurora.org> <20180501101845.GE12217@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180501101845.GE12217@hirez.programming.kicks-ass.net> 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, May 01, 2018 at 12:18:45PM +0200, Peter Zijlstra wrote: > Aaaah... I think I've spotted a problem there. We clear SHOULD_PARK > before we rebind, so if the thread lost the first PARKED store, > does the completion, gets migrated, cycles through the loop and now > observes !SHOULD_PARK and bails the wait-loop, then __kthread_bind() > will forever wait. Something like so perhaps... --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -451,6 +451,21 @@ void kthread_unpark(struct task_struct * { struct kthread *kthread = to_kthread(k); + if (test_bit(KTHREAD_IS_PARKED)) { + /* + * Newly created kthread was parked when the CPU was offline. + * The binding was lost and we need to set it again. + */ + if (test_bit(KTHREAD_IS_PER_CPU, &kthread->flags)) + __kthread_bind(k, kthread->cpu, TASK_PARKED); + } + + /* + * Ensures the IS_PARKED load precedes the !SHOULD_PARK store. + * matched by the smp_mb() from test_and_set_bit() in __kthread_parkme(). + */ + smp_mb__before_atomic(); + clear_bit(KTHREAD_SHOULD_PARK, &kthread->flags); /* * We clear the IS_PARKED bit here as we don't wait @@ -458,15 +473,8 @@ void kthread_unpark(struct task_struct * * park before that happens we'd see the IS_PARKED bit * which might be about to be cleared. */ - if (test_and_clear_bit(KTHREAD_IS_PARKED, &kthread->flags)) { - /* - * Newly created kthread was parked when the CPU was offline. - * The binding was lost and we need to set it again. - */ - if (test_bit(KTHREAD_IS_PER_CPU, &kthread->flags)) - __kthread_bind(k, kthread->cpu, TASK_PARKED); + if (test_and_clear_bit(KTHREAD_IS_PARKED, &kthread->flags)) wake_up_state(k, TASK_PARKED); - } } EXPORT_SYMBOL_GPL(kthread_unpark);