From nobody Tue Dec 2 01:54:37 2025 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFCEA248898 for ; Fri, 21 Nov 2025 14:53:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763736821; cv=none; b=OgQSvF9UsGq2yVqmLlZtjlOfLo1qNKatc97fEJD4ZUq9JvuxXXh2H9a5Umg5vE0spU2NB8+uR6f9qH7x2W5guW2o6uAiWpthWX2m8vuF4kLCHw5xkn6LnhT3Vzz6DTtNcJ9CJrWottC2w5xK8DWjONPobW/cfJZ4L5xLm7B4tN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763736821; c=relaxed/simple; bh=k9iZ2DgdKU/18GNdd2pJu0GViMRNc3S/1SMZlUWB/eI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s6tpYbUrGCMU416lCkTxY9BFaTb9pLdBX23od8cl9cOzVNmmKDe3MVZ87ZWlu5vcRoGfEOyfO85RglJq1SuGT1VicSPjnw+hUnjFjhOKBdGQfDngLjAgifcq5EgJiVraw70YA5Y8iN46dV2t2j7c6/DK3sCvuLBcTBwRnkwNTOA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eGLt6m/6; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eGLt6m/6" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-298456bb53aso25993655ad.0 for ; Fri, 21 Nov 2025 06:53:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763736819; x=1764341619; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rQ7Sd+AEjcf6Y3lyv8l7R72b7jJab1Ykn2VcIHqlJ4g=; b=eGLt6m/65BYa5SbQ/xB5umwK+q2artLH5VBmSbmm0xoAxd0PbQkGki6UUzpwRQeksQ 6g+tnLox8yS2PclDkTPO1WezDCcpeC8Okd3qES8WY0uokGekfA5TJuljQqw5uMI1+2iq FNhPLMw3WhJQ7fkTktHkaiEjEOoMZkNi83/npT0dPFuKpA/KBoHEut0AzMor8t8h6yKL vc2MPB4jhoVTM9RWLecaNunYMgNg0XQ/h0wR46DFJ7NP6RuQQZoJZlHqvINhp3rhSiNG jxX8lKDAWFpIEaEersvaT6pFGibBHhYDCq9iOeg1b+D0J/gNaAkFH/rYeAYxVQE5mf+0 XUig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763736819; x=1764341619; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=rQ7Sd+AEjcf6Y3lyv8l7R72b7jJab1Ykn2VcIHqlJ4g=; b=ZCTPm8f97NvJ5mw2fcJhYjGO0+eaU8o2i2RBVvnc8+IEAtoxCc5qF+zga8SagHedfr /58f4N4igIcX140wosBjQpk4knyfwOZcd2fWZjiSPWaENvZiyjTFrMmJbgzm18HxDon3 CposAIqmypZryD3F2BOIGeAzAgVYjKgzhNpcw7khbcE4C/VfC0yWcRZxprkP6MewEju5 WUCnDAqbSBvztGOprH29UaEjpeENQo3YFFOLjEjJIF2VIBJMfOUcmEuLMUKgH+HiEYi/ rzZ2yLOBENLev8Aj2cWldVLNnEMKxKRxxPgDXRLQw6QiVR3gIgD1sbOB+ResrTMXOVbp uDrg== X-Gm-Message-State: AOJu0YzrcBhudUafVOJzUJt8+XLZueuTv8mBHMifGX/8a1YFI4+P+vzY HSL8HrIXZW3VlI+itHKKMA5Gu8K2InD/rxpuf3MbKfzUiyaqqSEUhBFdzUYMaEkk X-Gm-Gg: ASbGncshUGfXwtR/y0J6bkKl9ez6n/p3j8ClSasaYdlheKD6+hSI5q3sDG456xF5uwr ER5IEpkKjDVMMU42Lal00eMi94Xi0Rmxu14N9ILdllx65XtP02lSSrD1p2xWqk6jcyiAoO/OIXn Oal9jKLcNCZ5Oi82uVTI+TSihG0IYF9KCnbxNWnXUm/TI0hm2I7+CdNAmYa5QZ7VP5dEyySOsoK JHKPs0teyKKXA98Nm1Vf4HZ4yClP6zSgSv4UffPG2Gf5xH80upMw4A/PXUjvhjRBbpvOPfyxP8r DJ5RhHFkfxtC9qV3vExAgFw/3Hk2MN4s1yPcco4C1RtDc7XKfdBOG6uQEe9dn/jaNeKKTyV9NUE k7B11qWbNyRsSqeXLnA85n/dbmDs7Qs2SkMvNJ49CvHrG9ULJd4HJI3+2Xx9NblOdhvHTUndPW0 wwwnNCcCAh3qG5 X-Google-Smtp-Source: AGHT+IH1hZqJxv9HyD/4d0WjqaAItNa2SouO+A/T3wt/60WciJKs4wVY01X97Y72dBzkQFNMGkqtWw== X-Received: by 2002:a17:902:ce05:b0:26c:2e56:ec27 with SMTP id d9443c01a7336-29b6c404f19mr29979155ad.19.1763736818585; Fri, 21 Nov 2025 06:53:38 -0800 (PST) Received: from localhost ([240b:4000:bb:1701:388a:b68c:56c7:adeb]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29b5b107cc2sm60541535ad.16.2025.11.21.06.53.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Nov 2025 06:53:38 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Tejun Heo , ying chen , Lai Jiangshan , Lai Jiangshan Subject: [PATCH V3 3/7] workqueue: Don't rely on wq->rescuer to stop rescuer Date: Fri, 21 Nov 2025 22:57:16 +0800 Message-Id: <20251121145720.342467-4-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20251121145720.342467-1-jiangshanlai@gmail.com> References: <20251121145720.342467-1-jiangshanlai@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Lai Jiangshan The commit1 def98c84b6cd ("workqueue: Fix spurious sanity check failures in destroy_workqueue()") tries to fix spurious sanity check failures by stopping send_mayday() via setting wq->rescuer to NULL. But it fails to stop the pwq->mayday_node requeuing in the rescuer, and the commit2 e66b39af00f4 ("workqueue: Fix pwq ref leak in rescuer_thread()") fixes it by checking wq->rescuer which is the result of commit1. Both commits together really fix spurious sanity check failures caused by the rescuer, but they both use a convoluted method by relying on wq->rescuer state rather than the real count of work items. Actually __WQ_DESTROYING and drain_workqueue() together already stop send_mayday() by draining all the work items and ensuring no new work item requeuing. And the more proper fix to stop the pwq->mayday_node requeuing in the rescuer is from commit3 4f3f4cf388f8 ("workqueue: avoid unneeded requeuing the pwq in rescuer thread") and renders the checking of wq->rescuer in commit2 unnecessary. So __WQ_DESTROYING, drain_workqueue() and commit3 together fix spurious sanity check failures introduced by the rescuer. Just remove the convoluted code of using wq->rescuer. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 932581d93edb..943fa27e272b 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -3541,10 +3541,9 @@ static int rescuer_thread(void *__rescuer) if (pwq->nr_active && need_to_create_worker(pool)) { raw_spin_lock(&wq_mayday_lock); /* - * Queue iff we aren't racing destruction - * and somebody else hasn't queued it already. + * Queue iff somebody else hasn't queued it already. */ - if (wq->rescuer && list_empty(&pwq->mayday_node)) { + if (list_empty(&pwq->mayday_node)) { get_pwq(pwq); list_add_tail(&pwq->mayday_node, &wq->maydays); } @@ -5903,16 +5902,10 @@ void destroy_workqueue(struct workqueue_struct *wq) =20 /* kill rescuer, if sanity checks fail, leave it w/o rescuer */ if (wq->rescuer) { - struct worker *rescuer =3D wq->rescuer; - - /* this prevents new queueing */ - raw_spin_lock_irq(&wq_mayday_lock); - wq->rescuer =3D NULL; - raw_spin_unlock_irq(&wq_mayday_lock); - /* rescuer will empty maydays list before exiting */ - kthread_stop(rescuer->task); - kfree(rescuer); + kthread_stop(wq->rescuer->task); + kfree(wq->rescuer); + wq->rescuer =3D NULL; } =20 /* --=20 2.19.1.6.gb485710b