Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1783582imn; Sun, 31 Jul 2022 23:01:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sOhiXzOWKiQEivgfEzqsD5+J6cSBmZnqUY1VUdVB8mL+rM2H7d9qJe9eUu4afPi/PcO/iw X-Received: by 2002:a05:6a02:205:b0:41b:96dc:bb2a with SMTP id bh5-20020a056a02020500b0041b96dcbb2amr10626009pgb.116.1659333714692; Sun, 31 Jul 2022 23:01:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659333714; cv=none; d=google.com; s=arc-20160816; b=tN/FcyKH52itC0TFGfq0V1mMOCiTfAFlTK08vDQCgBLPX2pmkLDiQHEpukb9fzpeC2 81k02+tCItObV5Bxq4XnwzHO8epCrCfXywls4txc0QKUY3vBVfICLvRhsS9nlwSqC5Hf ASWliWsFfffLnfFR3KR57++0e9STw5SdQpGhzZ2fTsn1UnPbogeYaiMti6OFFPGTaeYr dvITITeiNPf1unZ16rSHDO1D6bHhmVKpraE/Ev7K+B7zbdg6osRPmsU3MbShEC9wnGB5 bVsvhew452VSVMRHaeSFe8TwGSjTYg7kkfxi5oLqWejze0vxRrC4FUdibeZowoHGb7g0 Vcpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:dkim-signature; bh=FI2slEDL0OuyC3Vag1PYn+ptaAQPjUy3upspXOztAUk=; b=e9NsR4d/9RWOuMtZY3JM7sVjadoEap8/qjmuga8YfKstJt8bLVasTKupr7GbiA0ZRO KAnxSth3E4Td/1mXBSV9MxR/67yM9alr86GVoodlLqM/oKK6uohabdG+5/9IHzYVwyul isQZeaX6Hoz85RgWERxnOmv6q2ybwzncDBuyf1J6HyPl7J7ZZ76C+3l9Llt9Li9kOSZL XdFojxEk8SW7FBQX5Ige+Z3OIivXHaPEM+KX+mxWEghlCpJcogVkyCOtxEOxFDPRdRYE BPXeqmEEwXxiDOxveoQ+kr6LgQJqobGYGMWKAMv9r6QC4geLdhJXlh+oVuPCoz5PdtV/ IuiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gsub5H2r; 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 rj1-20020a17090b3e8100b001eca252a94bsi18504823pjb.175.2022.07.31.23.01.17; Sun, 31 Jul 2022 23:01:54 -0700 (PDT) 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=gsub5H2r; 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 S233109AbiHAFI4 (ORCPT + 99 others); Mon, 1 Aug 2022 01:08:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230126AbiHAFIz (ORCPT ); Mon, 1 Aug 2022 01:08:55 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AEA612ACE for ; Sun, 31 Jul 2022 22:08:54 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id s206so8754290pgs.3 for ; Sun, 31 Jul 2022 22:08:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:from:to:cc; bh=FI2slEDL0OuyC3Vag1PYn+ptaAQPjUy3upspXOztAUk=; b=gsub5H2rhbM2DFZX8x20b8mFjESBS8BmlfMoexLGK2OHt6mCIlS5vGC/7nJk+cwOyP QbB0aBv5uX+qS7z304m6BbcPXQCRAnnlps7v5SNEmU5VWpMgVkWP7WKbQKoMcCvu5Pmh 2IWDiz5M6kFgDKayUbW+llxLGpAHvpvZ9NA/q9cCAD5lw06AJXtwxwH1qoPVIlZMclKU mkUWnq38tBhrTQGTDMFVTyYZHuCAFvouYUEjMCopVXxR4DYOJrvRqD/6dU7UGEH+RFcG c7c7RRXBLRYzrWTHUwCNjWhJUVOj/vSzIRYXwqgf1XfGkxcPo8BGLKSlrNfZBLImdjo6 2v5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc; bh=FI2slEDL0OuyC3Vag1PYn+ptaAQPjUy3upspXOztAUk=; b=PgY0LZZpf+O7BB+TFs+uGWtq/3BzQQ9nIpm0Rb6VHJrTSvRmENkUiLjam4y0Arn0N1 1QKyEYgCAhceMY1LuTasEE7UmxMTCFP2cfdLTWhoFdg3+iomNmhw4RoRGaTgVDMIqxpn NZds2mQsu3gqlX1gAvDCqqiQHAG9YNrZbZBkU+B2r+AwHcxjMsgCqhXzwpaGTTjd7ZeL nQvZuJw++axSmlIolvPzw2v2M9YQTZps4tC6mAD3ko5mw61GebwcWeb/Qj+ikg4+xSFP AeaXRJIEo2nqZRMmLBBtg+/h2K2Ll6zJKDCKRQLa+IpozpfrO7buBokLKcxZALRJIXjc 6swg== X-Gm-Message-State: AJIora+AC2NZ8o1PuDCKBI9D1gBu0JuGVzbmJqQ99zJU3h+4Syhwbovq vQcZoPQ1PnoJRw07G77aLzLdyyRAostXeg== X-Received: by 2002:a05:6a00:230d:b0:52b:1819:3a0 with SMTP id h13-20020a056a00230d00b0052b181903a0mr14463443pfh.53.1659330533464; Sun, 31 Jul 2022 22:08:53 -0700 (PDT) Received: from MBP ([39.170.101.209]) by smtp.gmail.com with ESMTPSA id l9-20020a170903244900b0016dc307aef4sm8467231pls.36.2022.07.31.22.08.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 22:08:52 -0700 (PDT) References: <20220707090501.55483-1-schspa@gmail.com> <0320c5f9-cbda-1652-1f97-24d1a22fb298@gmail.com> User-agent: mu4e 1.6.10; emacs 27.2 From: Schspa Shi To: Lai Jiangshan Cc: Peter Zijlstra , Tejun Heo , LKML Subject: Re: [PATCH] workqueue: Use active mask for new worker when pool is DISASSOCIATED Date: Mon, 01 Aug 2022 12:42:33 +0800 In-reply-to: Message-ID: MIME-Version: 1.0 Content-Type: text/plain 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 Lai Jiangshan writes: > On Sat, Jul 30, 2022 at 12:19 PM Schspa Shi wrote: >> >> >> Peter Zijlstra writes: >> >> > On Wed, Jul 13, 2022 at 05:52:58PM +0800, Lai Jiangshan wrote: >> >> >> >> >> >> CC Peter. >> >> Peter has changed the CPU binding code in workqueue.c. >> > >> > [ 1622.829091] WARNING: CPU: 3 PID: 31 at kernel/sched/core.c:7756 sched_cpu_dying+0x74/0x204 >> > [ 1622.829374] CPU: 3 PID: 31 Comm: migration/3 Tainted: P O 5.10.59-rt52 #2 >> > ^^^^^^^^^^^^^^^^^^^^^ >> > >> > I think we can ignore this as being some ancient kernel. Please try >> > something recent. >> >> Hi peter: >> >> I spent a few days writing a test case and reproduced the problem on >> kernel 5.19. I think it's time for us to review the V3 patch for a fix. >> >> The V3 patch is at >> https://lore.kernel.org/all/20220714031645.28004-1-schspa@gmail.com/ >> Please help to review it. > > Because of the implementation of is_cpu_allowed(), > I am still suspicious about how the newly created worker can be woken > up in the dying cpu since it has no KTHREAD_IS_PER_CPU set. > I think the comments of the V3 patch have explained the problem, the newly created worker runs on the dying CPU because we bind it to the dying CPU via kthread_bind_mask or set_cpus_allowed_ptr. Please refer to the following scenarios. CPU0 CPU1 ------------------------------------------------------------------ sched_cpu_deactivate(cpu_active_mask clear) workqueue_offline_cpu(work pool POOL_DISASSOCIATED) -- all worker will migrate to another cpu -- worker_thread -- will create new worker if pool->worklist is not empty create_worker() -- new kworker will bound to CPU0 (pool->attrs->cpumask will be mask of CPU0). kworker/0:x will running on rq sched_cpu_dying if (rq->nr_running != 1 || rq_has_pinned_tasks(rq)) WARN(true, "Dying CPU not properly vacated!"); ---------OOPS------------- When CPUHP_HRTIMERS_PREPARE < CPU0's state < CPUHP_AP_WORKQUEUE_ONLINE, the CPU0 still can schedule a new work, which will add a new work to pool->worklist of a dying CPU's work pool. > Is it a dying cpu when onlining a CPU fails? I think balance_push > is not set in this case when it fails at some point during online. > But I haven't looked into the details and linked the clues. > Not this case, there is on onlining CPU fails log in my test log. > >> >> Test branch as: >> https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git/tag/?h=v5.19-rc8-rt8 >> > > Can it only be triggered in the rt kernel? > I only test on rt kernel, because of I work on RT kernel now, But I think non-rt kernel have the issues too. >> I think this code is new enough to demonstrate that the problem persists. >> >> The log as fellowing: >> >> [ 3103.198684] ------------[ cut here ]------------ >> [ 3103.198684] Dying CPU not properly vacated! >> [ 3103.198684] WARNING: CPU: 1 PID: 23 at kernel/sched/core.c:9575 sched_cpu_dying.cold+0xc/0xc3 >> [ 3103.198684] Modules linked in: work_test(O) > > Could you give me the code of this module? The module's source code is at https://github.com/schspa/code_snippet/blob/master/kernel_module/workqueue_test/work-test.c Kernel defconfig is at https://github.com/schspa/ktest/blob/main/configs/linux_rt_defconfig I add a hook to the entry of worker_thread, which add extra 50ms delay to make it reproduced faster. -- BRs Schspa Shi