Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752262AbdGDTtT (ORCPT ); Tue, 4 Jul 2017 15:49:19 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:49922 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752226AbdGDTtS (ORCPT ); Tue, 4 Jul 2017 15:49:18 -0400 Date: Tue, 4 Jul 2017 21:49:10 +0200 (CEST) From: Thomas Gleixner To: Vikram Mulukutla cc: Rusty Russell , Tejun Heo , Andrew Morton , LKML , Peter Zijlstra , Sebastian Sewior Subject: Re: [PATCH] kthread: Atomically set completion and perform dequeue in __kthread_parkme In-Reply-To: <318fac36-66cd-7f90-df61-44042119ee2e@codeaurora.org> Message-ID: References: <1498515483-12743-1-git-send-email-markivx@codeaurora.org> <318fac36-66cd-7f90-df61-44042119ee2e@codeaurora.org> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1974 Lines: 40 On Mon, 26 Jun 2017, Vikram Mulukutla wrote: > On 6/26/2017 3:18 PM, Vikram Mulukutla wrote: > > kthread_park waits for the target kthread to park itself with > > __kthread_parkme using a completion variable. __kthread_parkme - which is > > invoked by the target kthread - sets the completion variable before > > calling schedule() to voluntarily get itself off of the runqueue. > > > > This causes an interesting race in the hotplug path. takedown_cpu() > > invoked for CPU_X attempts to park the cpuhp/X hotplug kthread before > > running the stopper thread on CPU_X. kthread_unpark doesn't guarantee that > > cpuhp/X is off of X's runqueue, only that the thread has executed > > __kthread_parkme and set the completion. cpuhp/X may have been preempted > > out before calling schedule() to voluntarily sleep. takedown_cpu proceeds > > to run the stopper thread on CPU_X which promptly migrates off the > > still-on-rq cpuhp/X thread to another cpu CPU_Y, setting its affinity > > mask to something other than CPU_X alone. > > > > This is OK - cpuhp/X may finally get itself off of CPU_Y's runqueue at > > some later point. But if that doesn't happen (for example, if there's > > an RT thread on CPU_Y), the kthread_unpark in a subsequent cpu_up call > > for CPU_X will race with the still-on-rq condition. Even now we're > > functionally OK because there is a wait_task_inactive in the > > kthread_unpark(), BUT the following happens: > > > > [ 12.472745] BUG: scheduling while atomic: swapper/7/0/0x00000002 Thats not the worst problem. We could simply enable preemption there, but the real issue is that this is the idle task of the upcoming CPU which is not supposed to schedule in the first place. So no, your 'fix' is just papering over the underlying issue. And yes, the moron who did not think about wait_task_inactive() being called via kthread_unpark() -> kthread_bind() is me. I'm testing a proper fix for it right now. Will post later. Thanks, tglx