Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2266616ybl; Thu, 19 Dec 2019 10:41:47 -0800 (PST) X-Google-Smtp-Source: APXvYqzPn+P4eKdFPVWDuR/sgp7e6hD31DUJToevqXzboWyYlCK31eC2Zumdo0n4A8+YBImWwVQB X-Received: by 2002:a9d:c02:: with SMTP id 2mr10522775otr.183.1576780907752; Thu, 19 Dec 2019 10:41:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576780907; cv=none; d=google.com; s=arc-20160816; b=MjM58x3AHwBmq/BpDb1dwVgoWLl88YdktPnuJu+vkNbAJBpcntmXfil5PnFoZxYOF9 lbatwzcyB/o4JEDFbgIEWUBS+M7Nf8uuU63wvNTkXVtiUaQK6T4EQCPiV1to04pZyNvQ PztOdVj0WbOYh92V16KO3Rnx0XFUwWZ+bdAXGXzzKUrTQ49Gwxj2IfvSez2K18Zch5T4 4pAPN0vqcasa0EwdD1Jg90Fo6CVMiMxG91sgxvi9t9btTjU52sUgQPvAstit/JotKzww HWRRio6MTYn4dDbg42Efe9/TohJf8B60wv9GGzvwG0uzZjjJ3wvW2LJWUDCmt4ciMj8Z Um4Q== 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=UbZMWVD8hylukS8QFz+hFGmeG5lCh3eK2yXvp1po3kc=; b=G9ZQbNMQo+Rkoi6MXpb/mR3vUpinB2Ui4Dy/MPRBG20eAp8+31wEUKyVuZmdoy8mYW 1QXJ5dZp3cisDhfwEEKlzmb617szJ1eNKDweI0i2c4ekpp132L0ny2qgEZTBNWXWyOUb FuamSeh6cweR3E6FSednIYZ3BwgcCLsh+cF35g+dLrcIgO4b2HLqiZaG75fH1b06GR1u 211VEH7FVzDXHqu0fqUo28xFewd8dys/xRqPUekNxrT3TskDmpunDO26u+kNVzs3zrOp fSYjuQr879RmNqIScVKBNPr61PdsbD+h0dkt2WbTa1gPiZf6Qo3vOikLq895yYzzeK7R XdjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ut3DddeG; 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 s129si3482438oig.177.2019.12.19.10.41.36; Thu, 19 Dec 2019 10:41:47 -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=Ut3DddeG; 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 S1728216AbfLSSj2 (ORCPT + 99 others); Thu, 19 Dec 2019 13:39:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:57638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728208AbfLSSjY (ORCPT ); Thu, 19 Dec 2019 13:39:24 -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 2BEA524680; Thu, 19 Dec 2019 18:39:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576780763; bh=uvsaijxYpRjyoi0SSPDf3V+k4x8A1Zu1hj/7bXUk2MQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ut3DddeGrTH3oGLvXklTrRgMIYzMenvv7c7PmapRzuoQWu5xhptS6f7OMqGUz0FGC Kmejrgy4HURuR8yI0yovZY4jewi4uim1/4c1Bn6nKAGhe0BV2QAlzOSkGFMbxeRop4 6I60isxVK055xntMFtkmSbzn3Ukelq6Ie+XW1EsA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tejun Heo , "Williams, Gerald S" , NeilBrown Subject: [PATCH 4.4 106/162] workqueue: Fix pwq ref leak in rescuer_thread() Date: Thu, 19 Dec 2019 19:33:34 +0100 Message-Id: <20191219183214.208412906@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 e66b39af00f426b3356b96433d620cb3367ba1ff upstream. 008847f66c3 ("workqueue: allow rescuer thread to do more work.") made the rescuer worker requeue the pwq immediately if there may be more work items which need rescuing instead of waiting for the next mayday timer expiration. Unfortunately, it doesn't check whether the pwq is already on the mayday list and unconditionally gets the ref and moves it onto the list. This doesn't corrupt the list but creates an additional reference to the pwq. It got queued twice but will only be removed once. This leak later can trigger pwq refcnt warning on workqueue destruction and prevent freeing of the workqueue. Signed-off-by: Tejun Heo Cc: "Williams, Gerald S" Cc: NeilBrown Cc: stable@vger.kernel.org # v3.19+ Signed-off-by: Greg Kroah-Hartman --- kernel/workqueue.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -2308,8 +2308,14 @@ repeat: */ if (need_to_create_worker(pool)) { spin_lock(&wq_mayday_lock); - get_pwq(pwq); - list_move_tail(&pwq->mayday_node, &wq->maydays); + /* + * Queue iff we aren't racing destruction + * and somebody else hasn't queued it already. + */ + if (wq->rescuer && list_empty(&pwq->mayday_node)) { + get_pwq(pwq); + list_add_tail(&pwq->mayday_node, &wq->maydays); + } spin_unlock(&wq_mayday_lock); } } @@ -4276,7 +4282,8 @@ static void show_pwq(struct pool_workque pr_info(" pwq %d:", pool->id); pr_cont_pool_info(pool); - pr_cont(" active=%d/%d%s\n", pwq->nr_active, pwq->max_active, + pr_cont(" active=%d/%d refcnt=%d%s\n", + pwq->nr_active, pwq->max_active, pwq->refcnt, !list_empty(&pwq->mayday_node) ? " MAYDAY" : ""); hash_for_each(pool->busy_hash, bkt, worker, hentry) {