Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2875387rdb; Wed, 15 Nov 2023 13:14:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVAT1LhxUqhauQbM0ZfHB4duNS3pIqyYm7M8ZeK0cMXXQFgaUBSagt6S7eLuwDCCEy+Z76 X-Received: by 2002:a17:902:f541:b0:1cc:644a:2129 with SMTP id h1-20020a170902f54100b001cc644a2129mr9938531plf.32.1700082869289; Wed, 15 Nov 2023 13:14:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700082869; cv=none; d=google.com; s=arc-20160816; b=oyxLx64GOOWySxGL0qBJEspt7GmMOM+APgQboclXCaYEhFMqszoJvjvUQ9NeUucOZ+ YoheAbh2ozxCNihHeMXAVRtgoCnBMH807M7d7daSzDADY63+V7KJVXRbUKzCpO/+nIIA ROuxPMval4hsiCU13L9dNtQQ3m70r4r9pznAE1Q+MIZrBWakh8MSYuxtGx21ZNDPA3Ip t/wkn/49HtPpZO0PbluxwKp+dc1INioeQJQBskd7mXgdRdpuMYX20Y1pbXK3BmAiLA5o /xDcZ40fztSPqSM4ke1GP5axb/TWTSteD499FKqKPvMNLsL0ViFzY1kmKUz5pebD0rVC i2Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gG41S3eRSXDnrtYjpSzCgOouzdDZ6iNFxUsV6TQHjn8=; fh=2GplwVJ9eF0uhW4yvlXNXzEASr95//fDZqrLpqwIYnQ=; b=qOHS0moSbrl8O9OXpsnQj4tAFVe6Jppte45JAobJSLoe+EUkTNv9865JpDZVQFO4BB /FrHXIu/rlZJhOUaEuI5VJsI54l4zho9CDHMJ+/7ep+vHhc/KP9x1dGj8LGMD8d1WIwJ JRRPs3dt9z3nTPhICPLzp5HEnD7oFUyr0J5qSrnYWiz0PEVAA2q/xG1KtlCun7cgqGxs 4tHuRfdQr3C0UwOTTKSysZ3QK6PFrBlI/3tG6rmdi45et37CKHGIUezDqizbvuNy1s2a zMxr1aCsia6Crb8IVgH2wFJDnJqPL0M6YndZG4Vu0ESOo4gwPR736UR/r/MmyVLMnohb LkwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@t-8ch.de header.s=mail header.b=TEDeaIlU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id d10-20020a170903230a00b001cc45fcb81fsi11429853plh.334.2023.11.15.13.14.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 13:14:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@t-8ch.de header.s=mail header.b=TEDeaIlU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id B6D57805090C; Wed, 15 Nov 2023 13:14:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235053AbjKOVOM (ORCPT + 99 others); Wed, 15 Nov 2023 16:14:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229912AbjKOVOL (ORCPT ); Wed, 15 Nov 2023 16:14:11 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD2778F for ; Wed, 15 Nov 2023 13:14:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=t-8ch.de; s=mail; t=1700082845; bh=W9KXgXVjkRP1ZMFtQmwVxTYS6mN2ITCo/XA2zoJqWUA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TEDeaIlUv/PTImbVcF2pLGH1b9d75kSmERFBAXc/E9DVyWLn8Vw7dUiUr7CqgvPru wFm+LQ1G29vuL1LhD4b52lljINYapfc5wyZn6dtZaHUA+utaNfLi/jtC6DwEbGJKn5 v5AXtJBPJbOtwbG38oW+7mA0I1yskSL0ih5agytA= Date: Wed, 15 Nov 2023 22:14:05 +0100 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: huangzaiyang Cc: tj@kernel.org, jiangshanlai@gmail.com, linux-kernel@vger.kernel.org, ZaiYang Huang , Mukesh Ojha Subject: Re: [PATCH] workqueue: Make a warning when a pending delay work being re-init Message-ID: <54af48a0-2d3c-4888-953b-28760f129d33@t-8ch.de> References: <20231115113427.1420-1-huangzaiyang@oppo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231115113427.1420-1-huangzaiyang@oppo.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 15 Nov 2023 13:14:25 -0800 (PST) On 2023-11-15 19:34:27+0800, huangzaiyang wrote: > There is a timer_list race condition if a delay work is queued twice, > this usually won't happen unless someone reinitializes the task before performing the enqueue operation,likeï¼? > https://github.com/torvalds/linux/blob/master/drivers/devfreq/devfreq.c#L487 > A warning message will help developers identify this irregular usage. > > Signed-off-by: ZaiYang Huang > --- > include/linux/workqueue.h | 33 ++++++++++++++++++--------------- > 1 file changed, 18 insertions(+), 15 deletions(-) > > diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h > index 24b1e5070f4d..54102ed794e5 100644 > --- a/include/linux/workqueue.h > +++ b/include/linux/workqueue.h > @@ -266,6 +266,22 @@ static inline void destroy_delayed_work_on_stack(struct delayed_work *work) { } > static inline unsigned int work_static(struct work_struct *work) { return 0; } > #endif > > +/** > + * work_pending - Find out whether a work item is currently pending > + * @work: The work item in question > + */ > +#define work_pending(work) \ > + test_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) > + > +/** > + * delayed_work_pending - Find out whether a delayable work item is currently > + * pending > + * @w: The work item in question > + */ > +#define delayed_work_pending(w) \ > + work_pending(&(w)->work) > + > + > /* > * initialize all of a work item in one go > * > @@ -310,6 +326,7 @@ static inline unsigned int work_static(struct work_struct *work) { return 0; } > > #define __INIT_DELAYED_WORK(_work, _func, _tflags) \ > do { \ > + WARN_ON(delayed_work_pending(_work)); \ How does this work when the data _work points to is not yet initialized? Reading uninitialized data is UB and may spuriously trigger the warning. > INIT_WORK(&(_work)->work, (_func)); \ > __init_timer(&(_work)->timer, \ > delayed_work_timer_fn, \ > @@ -318,6 +335,7 @@ static inline unsigned int work_static(struct work_struct *work) { return 0; } [..] > -- > 2.17.1 > > ________________________________ > OPPO The gunk at the end of the mail will prevent your patch from being considered at all. > > ±¾µç×ÓÓʼþ¼°Æ丽¼þº¬ÓÐOPPO¹«Ë¾µÄ±£ÃÜÐÅÏ¢£¬½öÏÞÓÚÓʼþÖ¸Ã÷µÄÊÕ¼þÈË£¨°üº¬¸öÈ˼°Èº×飩ʹÓ᣽ûÖ¹ÈκÎÈËÔÚδ¾­ÊÚȨµÄÇé¿öÏÂÒÔÈκÎÐÎʽʹÓá£Èç¹ûÄú´íÊÕÁ˱¾Óʼþ£¬ÇÐÎð´«²¥¡¢·Ö·¢¡¢¸´ÖÆ¡¢Ó¡Ë¢»òʹÓñ¾ÓʼþÖ®Èκβ¿·Ö»òÆäËùÔØÖ®ÈκÎÄÚÈÝ£¬²¢ÇëÁ¢¼´ÒÔµç×ÓÓʼþ֪ͨ·¢¼þÈ˲¢É¾³ý±¾Óʼþ¼°Æ丽¼þ¡£ [..]