Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7207413rwb; Tue, 6 Dec 2022 02:40:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf6N/1J8Z7DLlh9P3T8kFfu5hDtAnGiJHjiB0mlHfa9PXEmZD/myA7umHojG/hhdC42Xo2N8 X-Received: by 2002:a17:906:3488:b0:7c1:d49:d06d with SMTP id g8-20020a170906348800b007c10d49d06dmr1447711ejb.440.1670323219187; Tue, 06 Dec 2022 02:40:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670323219; cv=none; d=google.com; s=arc-20160816; b=xVOVyVGDWnG7hs1gltHj7gLXwd+hFsaxwGcacx0HbV3znElbEFFXZLcEs6nwI+Eye6 so/Pi6KcMVDPVVru4kacBnAb4zDzbdXxu6m91xvLJrba8JucfEWiCJ8GYt2cT/d/lwnT CEVPbFlVWAO5VRMrmaR5EBJTVvvIahRh3kv7RiTemC/rsfLoYOPi3rHqsUAJbfbA+4bd IrZcC+lHKYmZwbgIhPMVqtIr71/gYsC+Xq+eZYTIKkWFJgFtrWTUnN5N+1VXo0FU/rc9 Jl62R1zmY2Svfwzjh5IJG4H3hn3wgKrK7amKRQGcFqBN1El7dWLL7o8U1zkyngTuc5Nn Roww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=jinBcPSkEbBkoDxJN/eRyhQV/jBZKLuC/Y4mXEJDUBw=; b=WXxj5YQlhhvF/GOOolsEgLfFzgWnTT7x8r4umOzWJ4DqkydGECxgbq9HfoTxHd5pZe ovVksBQA7JXGQ5ww7qzW5FbaAnfc41pUMZ5rnFKiF4Bf+45pcWA4+5zo4diiRfIpWXY5 rRoK7Kunkcve8Y83A1Vu6xdho8KEuL2cKEhjdiw3vlVj7IgsDBfHN0QuyW5nXBNB4S/o O6fp7/uTS6yiDQFLCtQfUENi4cYvldQ6+kHj0ZvgVHkZcRKg8mEs3s1plOrnNJLK9quC i4gaX2afUz0GTnzSCqqX83l6CzQ7AGZpEKZKK/P1T/NYvCGpqOWHpyaDDXnazWFlVgzf +xEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dxWlUGme; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb3-20020a1709071c8300b007c0abf0760fsi13829743ejc.54.2022.12.06.02.40.00; Tue, 06 Dec 2022 02:40:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dxWlUGme; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235054AbiLFJXW (ORCPT + 79 others); Tue, 6 Dec 2022 04:23:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234987AbiLFJWv (ORCPT ); Tue, 6 Dec 2022 04:22:51 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 781DA220D3 for ; Tue, 6 Dec 2022 01:20:30 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id w15so22544178wrl.9 for ; Tue, 06 Dec 2022 01:20:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=jinBcPSkEbBkoDxJN/eRyhQV/jBZKLuC/Y4mXEJDUBw=; b=dxWlUGmeupuPuJkU7adI5ygpuordIPTUDXDz2xfn0beqgCIkzmpPYT8uVff6LliFa9 rTphtRnpNutX79xC3H+iE8Z80DmQvF58B95YvBuNFIVOd9KBQXHmXUhAcKoJMNMZMUwJ IDFRUQ2rVk7rKma1ZcbkPrJ8fbMQdDn4RCjkS7wgf3dqLglOUYVKm3o7O7NcthjB/BuU 8UZPVjD1Rz9HAQSiV8z8aG+IMOmtU7Qkom/5Ng+5RPyMxIp4RSnKnirtXDKWKY9WGulN fIYHpA2HB6UDHnsROebpYGGfEobK27qQDZPDDNrhI4mRnPLDjsTKpxm3YHMq27n+1l2f tShQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jinBcPSkEbBkoDxJN/eRyhQV/jBZKLuC/Y4mXEJDUBw=; b=4pFQrTN26hRKrOLpklOEZpZAiYEssQoTCykuTTDPXTHipuRH8yVkCOIEDAVHFcjarG eEGAcsP+g3cnaYgXWI7r+3BMRmNu6xGL2UEohw7rMOKOTyJSvkB5TnjJuLT1LfARZL8o W/Yp4Nz3I1M+nBZ2eu7VkCt2tGTvdkJQPK0Vf/pxbnXtdvdckfO0HbH5ZvpCOaj65aBf 2m6eDOncoUxOxvHJ24QbCdOexptskBmqaMtIWoZNa3bDrZY9mVtubZILdvfK3xBOA78N CIQFQ00zxVcnI1sm+nJnk8Lhhm9GzVLqVGNwtLFtBEKruAewJGRQxqoC7MP0ib308mpD YjZw== X-Gm-Message-State: ANoB5pmUwk1pHnaay2Xiir2PlyodMFHqCIIobd6xokNRlTgTDb6wWWBI F/2GqKhIhz4Ima3vtG6otBGf7tvcOQr9busydxd/uTUO90E= X-Received: by 2002:a5d:58e6:0:b0:242:5562:6d6 with SMTP id f6-20020a5d58e6000000b00242556206d6mr7111642wrd.541.1670318428890; Tue, 06 Dec 2022 01:20:28 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: richard clark Date: Tue, 6 Dec 2022 17:20:17 +0800 Message-ID: Subject: Re: work item still be scheduled to execute after destroy_workqueue? To: Lai Jiangshan Cc: tj@kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 6, 2022 at 2:23 PM Lai Jiangshan wrote: > > On Tue, Dec 6, 2022 at 12:35 PM richard clark > wrote: > > > > > > A WARN is definitely reasonable and has its benefits. Can I try to > > submit the patch and you're nice to review as maintainer? > > > > Thanks, > > Richard > > > > > Sure, go ahead. > > What's in my mind is that the following code is wrapped in a new function: > > mutex_lock(&wq->mutex); > if (!wq->nr_drainers++) > wq->flags |= __WQ_DRAINING; > mutex_unlock(&wq->mutex); > > > and the new function replaces the open code drain_workqueue() and > is also called in destroy_workqueue() (before calling drain_workqueue()). > Except that, do we need to defer the __WQ_DRAINING clean to the rcu_call, thus we still have a close-loop of the drainer's count, like this? --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -3528,6 +3526,9 @@ static void rcu_free_wq(struct rcu_head *rcu) else free_workqueue_attrs(wq->unbound_attrs); + if (!--wq->nr_drainers) + wq->flags &= ~__WQ_DRAINING; + kfree(wq); > > __WQ_DRAINING will cause the needed WARN on illegally queuing items on > destroyed workqueue. I will re-test it if there are no concerns about the above fix... > > Thanks > Lai