Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp202105rwb; Tue, 6 Dec 2022 19:38:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf53EittNUAdlXw5EQsHIWhNdA791jmdMalVqewMrXstgCiK3Ev2vLv1p/4l80waE6hV5BL4 X-Received: by 2002:a17:906:3ad8:b0:7a8:dddc:7ec6 with SMTP id z24-20020a1709063ad800b007a8dddc7ec6mr25590734ejd.734.1670384334665; Tue, 06 Dec 2022 19:38:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670384334; cv=none; d=google.com; s=arc-20160816; b=FhPgNdvttI+dwWgoNC/y6eXEJ42goJREWUMnH8VA51U5EMRZMxW/5fLdxnj8eefqS8 kSjKAnmP1TWT4wsS1NTmXa9C8wjielLHAE3iDuFkRLb0Ml/zE5md32y18mybmepVr0hx AaRwRipfldtIfez5+695RrWMNLa6/00bHAoBeBxvBkkAcGY+Rsdxz3AhP1C875potetu 8RYB9j7JWYaTpfqE/dfo6nB3V8SXmTh3OaNqj/421jDLXRO26J6lJnjq7yz49u6UmrYi dsqZDKMDaa1QsEF97nx37UdXBqoAHV8Zpw13bm4xoC67SPq3OGr8LbfLka1rFi3e2Fhp R8Qw== 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=nRN1WWpUuq4+/5SU9doiYyFO0GUK6IB6DN8Sn4Whmpo=; b=nuI1YXLBw/9OkDHMZ74s0oqBucGcvQXBrW3WaAksV6cTg6JprDvL+RYw/ZxlrTnJ4J F61U5guoUWEXSEVPe0m4XtVD/cmGS6dhEDWD+sFjLAuOukn8YaGU1KQ25C1NEdoVMxM1 Vu11zpcuN+6vr1q93UtpPp0amxT/MmWKS6CqQt/8b9UnqPC9+W+b0Lww0OdmLpbaQ+3u iUI9fMCv8+nzuBAc5hgAeVZhcIt/stUFa8gVSmiCQhtHlB280lI0k4uA8H31+WeqP0b6 E7npMuUpGza1q+ocAffIqkjw78FETtjE4pP4rO2N/Cs+QCozFbjXt4I3v28WUVBYQ5/q 8sNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=G4VLwxAv; 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 r16-20020a05640251d000b0046906b7a5c8si3745992edd.559.2022.12.06.19.38.36; Tue, 06 Dec 2022 19:38:54 -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=G4VLwxAv; 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 S229564AbiLGCiD (ORCPT + 77 others); Tue, 6 Dec 2022 21:38:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbiLGCiC (ORCPT ); Tue, 6 Dec 2022 21:38:02 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05EAB31DF2 for ; Tue, 6 Dec 2022 18:38:02 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id t17so16264226pjo.3 for ; Tue, 06 Dec 2022 18:38:01 -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=nRN1WWpUuq4+/5SU9doiYyFO0GUK6IB6DN8Sn4Whmpo=; b=G4VLwxAv1r/l8/kyBABDU0pzTFs7RbdCFmbRYeAtoEoyMG1c3upwv84xA/O7qziQc+ cbrtIAy9Hmkc8cbSDQEq3+A/ypaK0vjs+7cTvk3yE3WApKtpkTpVjtioDkkARKo4upPv znB8RDih92yjButlZQXqe0J60cmjBFSu9KDu3cLXBuWuAwv5c/KFa5EINNhLcFsqO9YK Muarc8x3k3r2C/HRSYZK6O4CpHVmPO76taihyWiwIgPhQd5l2igslUOaJgbVAkBwvI6q kP8p3Dk67OYRibfdWSlxUMIwGrDxyMlfHkwewjDvbFzpbIY8M+xRjKZgIW9Lh4uMnB/x YWdw== 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=nRN1WWpUuq4+/5SU9doiYyFO0GUK6IB6DN8Sn4Whmpo=; b=T+zIqNzHZ0rIghHm4KYpCz5cJoBY0wenkf1bEBxN0vIVzORKAp9/ERWg6eT7Ejrocz nvv8K1qK1XiSVMgrM3SBEMhNxXcK6UXqDnIiB0+S/LxEw8C10a213fzoR+2BFRubacjP jOUF9R5vs03Di9VnojfIY28ILBRW0JBEVsXLRFX9jPDRf30mhlN+mduPX/0TzIqF7+lG 1uM0jioqZ27CKShUzRZlfhpGI9QvVREgYdJrCMaFySpYORSmumbT6w2ZQZFSWHKgSq3G MhEmF0BcmEIRZmIMczFAG4ix/mI3RYIPP0TzltyoqFpEILXJyzofazprvsm3ZnTBRHi4 WN7A== X-Gm-Message-State: ANoB5pkbj6Z2DlH/S3bg/rdQm6izjoHye4c4bnA11ioMEKVG0LpVtBBn xPeQUhxCXiQtAKqwLG9lTZoX0hTBl/wH+rkTAwQ= X-Received: by 2002:a17:90a:1d5:b0:219:55d5:f30e with SMTP id 21-20020a17090a01d500b0021955d5f30emr38519920pjd.107.1670380681537; Tue, 06 Dec 2022 18:38:01 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Lai Jiangshan Date: Wed, 7 Dec 2022 10:37:49 +0800 Message-ID: Subject: Re: work item still be scheduled to execute after destroy_workqueue? To: richard clark 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 5:20 PM richard clark wrote: > > 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? No, I don't think we need it. The wq is totally freed in rcu_free_wq. Or we can just introduce __WQ_DESTROYING. It seems using __WQ_DESTROYING is better. > > --- 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