Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757739AbcJXQks (ORCPT ); Mon, 24 Oct 2016 12:40:48 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:40790 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754095AbcJXQkr (ORCPT ); Mon, 24 Oct 2016 12:40:47 -0400 Date: Mon, 24 Oct 2016 18:40:43 +0200 From: Peter Zijlstra To: Roman Pen Cc: Andy Lutomirski , Oleg Nesterov , Thomas Gleixner , Ingo Molnar , Tejun Heo , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] workqueue: ignore dead tasks in a workqueue sleep hook Message-ID: <20161024164043.GS3102@twins.programming.kicks-ass.net> References: <20161024160814.3126-1-roman.penyaev@profitbricks.com> <20161024160814.3126-2-roman.penyaev@profitbricks.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161024160814.3126-2-roman.penyaev@profitbricks.com> 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 Content-Length: 1399 Lines: 45 On Mon, Oct 24, 2016 at 06:08:14PM +0200, Roman Pen wrote: > --- a/kernel/workqueue.c > +++ b/kernel/workqueue.c > @@ -875,9 +875,31 @@ void wq_worker_waking_up(struct task_struct *task, int cpu) > */ > struct task_struct *wq_worker_sleeping(struct task_struct *task) > { > - struct worker *worker = kthread_data(task), *to_wakeup = NULL; > + struct worker *worker, *to_wakeup = NULL; > struct worker_pool *pool; > > + > + if (task->state == TASK_DEAD) > + /* Here we try to catch the following path before > + * accessing NULL kthread->vfork_done ptr thru > + * kthread_data(): > + * > + * oops_end() > + * do_exit() > + * schedule() > + * > + * If panic_on_oops is not set and oops happens on > + * a workqueue execution path, thread will be killed. > + * That is definitly sad, but not to make the situation > + * even worse we have to ignore dead tasks in order not > + * to step on zeroed out members (e.g. t->vfork_done is > + * already NULL on that path, since we were called by > + * do_exit())). > + */ > + return NULL; https://lkml.kernel.org/r/CA+55aFyQYJerovMsSoSKS7PessZBr4vNp-3QUUwhqk4A4_jcbg@mail.gmail.com Also, that misses { }. > + > + worker = kthread_data(task); > + > /* > * Rescuers, which may not have all the fields set up like normal > * workers, also reach here, let's not access anything before > -- > 2.9.3 >