Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2297946ybl; Thu, 19 Dec 2019 11:11:26 -0800 (PST) X-Google-Smtp-Source: APXvYqw1h5r7gJq9nka3Hi0kfe+mSvhUx6PQbqQNNkJsdM4rr6MoJf+6F2+2eIupmx5c0Hb4Jjy0 X-Received: by 2002:a54:4817:: with SMTP id j23mr2727209oij.152.1576782686587; Thu, 19 Dec 2019 11:11:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576782686; cv=none; d=google.com; s=arc-20160816; b=Di3832rZ+EC2HSk5HcvFbgs27LAJuIbT8o6R0TiFowzz5PZDCOKK1W6SLiD8BnWSJT VHuNEKbcqNsGEVWO1SzpURhU+e2r7Qqws5Yfotgi4KMWzJU02yk69G0FpKOeE2ID+28C i8+zo2ut2s9CESMSppQptRHPQrk8t2isFbThK88hYDFQYsCrqEHFSfocwUsxUstMSplK Y/laxfBHvfikkaAQIvTdMUYWP/DjSpG9HiZzCL8+MTeIVNZItP7MwM4V2aiWdqB8VXqR dmxzNwwQFMJ6wvi3cXIIHrXZo0A3M1noLT5ptSoucK9Oa28G5QMr7FE4DVvBmZc9z6xL Vpjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PBo63hfh6UyLWgE2RSjAZ27Rzvyb0hoOxVzjS1vYJ5s=; b=fqoyksTi0HO4h64qY7j+3jmYSkjEOAQWKIggSFgrB1nJrPwLpfMZHLdHYon1/hbS/E ncIhNSF9w9lIYg5J5dyo+wRyfdLvn4A8rvqnKR2YvI2QvDP54ivxS3OqbAIhOewMgFSn gT+CkPgS2k57l21KEeYVmlXJZI7xNmQxgyh4tpL+b5n+keGftahDizygHZqix4q4mKO+ IB8sa29GqJbYoQpa7121A3EVmxy3nXk/SwfufObYnGqPjcWK92Tpyrqr6y5BaLJUTrVc I6fqb+LlY1NssGxo+xfn5k/OIfzRcBKPab+Ov6R+l0tWLCG4j/qFPAzlW1GW5c+a9Dpf bt9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hGWq9cJB; 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 5si3732197oih.274.2019.12.19.11.11.15; Thu, 19 Dec 2019 11:11:26 -0800 (PST) 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=pass header.i=@kernel.org header.s=default header.b=hGWq9cJB; 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 S1727806AbfLSSjX (ORCPT + 99 others); Thu, 19 Dec 2019 13:39:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:57562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728188AbfLSSjV (ORCPT ); Thu, 19 Dec 2019 13:39:21 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B3EB22467B; Thu, 19 Dec 2019 18:39:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576780761; bh=dSG2LJ7Tp9O2AglKZ3Zr++wyaiLv4v2FLlrtnXHrMnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hGWq9cJBGDsDJ6c4ISmA9hzvOVYwLCBooX4Tbqnn5lkTih+S5BOMJbFDnhIde8aHW IFmOcsNcwSQy2yIP6zLw0r6an5Slrs1D24ukFuRjAauQkijJ+0v2d3wJt9KLbhIJgx ChG3cYaWRT3eWxox+w0FWghmld6acf8PAsSh0xbk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tejun Heo , Marcin Pawlowski , "Williams, Gerald S" Subject: [PATCH 4.4 105/162] workqueue: Fix spurious sanity check failures in destroy_workqueue() Date: Thu, 19 Dec 2019 19:33:33 +0100 Message-Id: <20191219183214.151745308@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183150.477687052@linuxfoundation.org> References: <20191219183150.477687052@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tejun Heo commit def98c84b6cdf2eeea19ec5736e90e316df5206b upstream. Before actually destrying a workqueue, destroy_workqueue() checks whether it's actually idle. If it isn't, it prints out a bunch of warning messages and leaves the workqueue dangling. It unfortunately has a couple issues. * Mayday list queueing increments pwq's refcnts which gets detected as busy and fails the sanity checks. However, because mayday list queueing is asynchronous, this condition can happen without any actual work items left in the workqueue. * Sanity check failure leaves the sysfs interface behind too which can lead to init failure of newer instances of the workqueue. This patch fixes the above two by * If a workqueue has a rescuer, disable and kill the rescuer before sanity checks. Disabling and killing is guaranteed to flush the existing mayday list. * Remove sysfs interface before sanity checks. Signed-off-by: Tejun Heo Reported-by: Marcin Pawlowski Reported-by: "Williams, Gerald S" Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- kernel/workqueue.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -3949,9 +3949,28 @@ void destroy_workqueue(struct workqueue_ struct pool_workqueue *pwq; int node; + /* + * Remove it from sysfs first so that sanity check failure doesn't + * lead to sysfs name conflicts. + */ + workqueue_sysfs_unregister(wq); + /* drain it before proceeding with destruction */ drain_workqueue(wq); + /* kill rescuer, if sanity checks fail, leave it w/o rescuer */ + if (wq->rescuer) { + struct worker *rescuer = wq->rescuer; + + /* this prevents new queueing */ + spin_lock_irq(&wq_mayday_lock); + wq->rescuer = NULL; + spin_unlock_irq(&wq_mayday_lock); + + /* rescuer will empty maydays list before exiting */ + kthread_stop(rescuer->task); + } + /* sanity checks */ mutex_lock(&wq->mutex); for_each_pwq(pwq, wq) { @@ -3981,11 +4000,6 @@ void destroy_workqueue(struct workqueue_ list_del_rcu(&wq->list); mutex_unlock(&wq_pool_mutex); - workqueue_sysfs_unregister(wq); - - if (wq->rescuer) - kthread_stop(wq->rescuer->task); - if (!(wq->flags & WQ_UNBOUND)) { /* * The base ref is never dropped on per-cpu pwqs. Directly