Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5482858rwb; Sun, 4 Dec 2022 22:51:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf7r04F3nJellSSBdGZqetNsdvfRbUsa+d8BSercP7Dy2iVZJoCqH6upPCLM3vrDWxb1N4Jh X-Received: by 2002:a50:ee19:0:b0:46b:51e6:2e69 with SMTP id g25-20020a50ee19000000b0046b51e62e69mr27861722eds.354.1670223106467; Sun, 04 Dec 2022 22:51:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670223106; cv=none; d=google.com; s=arc-20160816; b=uOwfqLFIPDqJA4bgB1eUO34ghphuBdrbD8xzcX1PD6P3Bp0TkbY0peqq3UIGAeKnC7 fg+yiBso+liVsiDiH7IY51Of1wIOmiKT8d2ocgqqaugZB8GvzJHvy5jokZ8HekgpSep4 5XxAvjuvbHQ3ND5g7Yz/PIFnrfwm9heHx1HpIGabPaCXdUlntQd3DEMHkBkJh9Z0e++I PwmJU1VKXfDfkXmPNAHqF69zWi5mHWOtNnB8QYBbt16eVt+7iq+7WHfzkAx0stjtMGQ9 jUmPiRSWNmXj5CVpzASm7umB8IRy6cNOY39ocKqWzLU4+aEjpUUHCeiXHsBU1oiE/qtT 2U3g== 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:mime-version :dkim-signature; bh=cKvnCaTte6OI41/izSASPW8Y7Q9GHM0eeRl020Krw3w=; b=y831VDJq1kIBCHEJWi1IykcB0LPWeiORb+k7oWs/2s5ZJ9FPaQYM0M8I/Li+EcQEMP iKGFaogSIh4AEOPhnAPElkRsA/K6mjflC1SI5JyVptl4vtylvwsh8O3dwvGybdk3iilh gV+kP/U4SVddg4vi8eE2rT04QaIeCQsAwy1AKtIujh0IEe5OwCRcnKN3sTIHVeul0hyy gnl6dB0yKzfdfI580it3bIx5QS3kf1leV6ryTI5/jGikANTBcUIcpOSAlLpQeQpjGNNv zYIp4v4/be53fq4drwqwUPtfThSj/6Axx1i4KUPDSVjlqpdGQz/LrydkWEyg6KAWyeVX TLTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Pe1vVqts; 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 s4-20020a17090699c400b007c0fa8181c4si1014163ejn.567.2022.12.04.22.51.26; Sun, 04 Dec 2022 22:51:46 -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=Pe1vVqts; 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 S231602AbiLEGSy (ORCPT + 84 others); Mon, 5 Dec 2022 01:18:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231270AbiLEGSu (ORCPT ); Mon, 5 Dec 2022 01:18:50 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81ED511816 for ; Sun, 4 Dec 2022 22:18:48 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id bg10so7961411wmb.1 for ; Sun, 04 Dec 2022 22:18:48 -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:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=cKvnCaTte6OI41/izSASPW8Y7Q9GHM0eeRl020Krw3w=; b=Pe1vVqtsReplTWEgs/ey8TAv8VSYF0u9DIAy3IEFzXUzo8Nfm2Sflnz4/E8rTXRZ6l 3O4zGA0TnbDHXc6rP+VQ3jUgG2fubqTPJQT5Tb5DM6DmBVJ8cApotp4iojUDy/iwHF8C sYosFdQYqpsQPglSsrMSs8NQ17JOohB+W3MAkdZdCgqB1aWB5cV8rfGAoPl62kjn+HFA 5H8M4av54+hpbhW6DnkMlrN87GQjYWoKIjDLvz4xIopbsIhlmgUUU4rB12/pZJlhE/if 11qLMZLgWY7b3+Nnx/CEDdmYVL+WFzkJbUyDDeadbZ71i5K/IjUuZ42zhI6Q+Csbg7+P vV3g== 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:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=cKvnCaTte6OI41/izSASPW8Y7Q9GHM0eeRl020Krw3w=; b=KdWIDGYr7EERYiXccJ0eHAXtMwCTQ4Bl4zEajQYge01auyu/kBKAzzKG7wo9mzatcA Cfv/H+0wihidc3NM2prn4LXF1ZuuKtrteuVA4G/LGBSHUA8Wi3zxPuZD/KRbTzBqBJ7t yBjN7pCBS+pExVqNy5Q5qzw74kSsp8osfNSm9ZjG40d4BBHjKolh5hL5zCcs6GROfmr7 sMKHPifPO01GiYGlUPkRHCGFRbGdiSScyaSN8X7Pn4xd4EP/GpJsVrvOwiWdxFwUXFGB 21q7ldPAo7H+FwLemqrTct4vMdsJZnntOPKJ/g/4dtCw0rUvkFZz4yl6EQE/9kXSwdDB kYUQ== X-Gm-Message-State: ANoB5plh4MQ3hREBbGvAE6idfy2qp/+b2PP2X74cFj5CP0sZq+n9+Ymt AFP5VM9/YGPo/j6Z0X6PlZEUMlqvhZfp7SoTlDyNy4QyFKs= X-Received: by 2002:a05:600c:22c4:b0:3cf:71b7:7a41 with SMTP id 4-20020a05600c22c400b003cf71b77a41mr60779636wmg.31.1670221127010; Sun, 04 Dec 2022 22:18:47 -0800 (PST) MIME-Version: 1.0 From: richard clark Date: Mon, 5 Dec 2022 14:18:35 +0800 Message-ID: Subject: 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 Hi Lai and Tejun, Why can the work still be queued to and executed when queueing it to a wq has been destroyed, for instance, the below code snippet in a kernel module: ---------------------->8--------------------- struct workqueue_struct *wq0; #define MAX_ACTIVE_WORKS (3) static void work0_func(struct work_struct *work); static void work1_func(struct work_struct *work); static void work2_func(struct work_struct *work); static DECLARE_WORK(w0, work0_func); static DECLARE_WORK(w1, work1_func); static DECLARE_WORK(w2, work2_func); /* work->func */ static void work0_func(struct work_struct *work) { pr_info("+%s begins to sleep\n", __func__); /* sleep for 10s */ schedule_timeout_interruptible(msecs_to_jiffies(10000)); pr_info("+%s after sleep, begin to queue another work\n", __func__); queue_work_on(1, wq0, &w1); } /* work->func */ static void work1_func(struct work_struct *work) { pr_info("+%s scheduled\n", __func__); } /* work->func */ static void work2_func(struct work_struct *work) { pr_info("+%s scheduled\n", __func__); } static int destroy_init(void) { wq0 = alloc_workqueue("percpu_wq0", 0, MAX_ACTIVE_WORKS); if (!wq0) { pr_err("alloc_workqueue failed\n"); return -1; } queue_work_on(1, wq0, &w0); pr_info("Begin to destroy wq0...\n"); destroy_workqueue(wq0); pr_info("queue w2 to the wq0 after destroyed...\n"); queue_work_on(1, wq0, &w2); return 0; } The output on my x86_64 box is: [344702.734480] +destroy_init+ [344702.734499] Begin to destroy wq0... [344702.734516] +work0_func begins to sleep [344712.791607] +work0_func after sleep, begin to queue another work [344712.791620] +work1_func scheduled [344712.791649] queue w2 to the wq0 after destroyed... [344712.791663] +work2_func scheduled <------------- work 2 still be scheduled?