Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3040060rdb; Wed, 15 Nov 2023 20:13:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IGEbMnt1CY+uagrkR2reRfdvIVY5BMfP9PyQK5bveOnn+JAmOcnBL8IqWMTgJ5RaSCOg2Mi X-Received: by 2002:a17:902:eccb:b0:1cc:50ea:d5db with SMTP id a11-20020a170902eccb00b001cc50ead5dbmr9119349plh.4.1700108023100; Wed, 15 Nov 2023 20:13:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700108023; cv=none; d=google.com; s=arc-20160816; b=dfZhy6/7WtI8qrG1OyUSbbys0TrkTSD7W75+Bd2LhZYwb0ASNqAHWeVVDLR4KRwY4I PfyZI1ouuzPq4868OoS6J1iQCUORPelgbo5zrS+0V4VGimDSfQjci+xLB8mpn4iC+CPB 9mVyOm7KCbXUMFWTXyq4gr3n1geDAqDs/Lt558mcC2teUQeOviDHXgWn5h8O0VLZS8qj KG1k+3y9lUXRJ2+11cD9qmW55eg0Zd+IhCwdggcFRftWTIkbbguYh0epJNt8wZW7HPwf JuU7sIB0OX2a60BdRNs8SJcRXZejLV23b4H2DvfCRBkMX7WRGL948wR5qqp3Sg3dOW3m KYLw== 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=pVRd5GSqQj6Mg+MnJh1+WCve/MxHTZBlVPHFzifOH94=; fh=VabocyWJCqpOCERq4DWKuo2bYGrU2/6SKUrvvFimUls=; b=dfQ4YiyGtXElK3peAC9fxUImBT+PSUXDeX/n1Gq5webnYQG663BH7XpZ27X/6J0RYY ZKxlJaDn+FtAj48pDu5rn8/VkNqSKuBzoT+gnCN+dwyXHsdvB7X04f+teOx5NO5OpEWN lnn/VGVlntIaV8gJJ084kBx0j1gCPw8g27VskQWUQ4jBka6frTm69tkDjC1tUf9sLU5G JesvTM5eJg3L/mZmp8+7HDqvjg+Y0hJGPQvCNVh55PxYSx8IMA5YNIgQFPPjxBUvP1PE Zhxo6PFqt2QKV2pKv2n8CyqqhZRA1OXheX2uth7eS+W0xGzvkI2SPe0oGO69gVjZDAJs qiSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@t-8ch.de header.s=mail header.b=aNlZ3myW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id jk22-20020a170903331600b001c3da86939csi10895127plb.546.2023.11.15.20.13.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 20:13:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@t-8ch.de header.s=mail header.b=aNlZ3myW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 6C07380E0701; Wed, 15 Nov 2023 20:13:41 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344559AbjKPENk (ORCPT + 99 others); Wed, 15 Nov 2023 23:13:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230207AbjKPENi (ORCPT ); Wed, 15 Nov 2023 23:13:38 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1159C196 for ; Wed, 15 Nov 2023 20:13:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=t-8ch.de; s=mail; t=1700108013; bh=NEnY6SAxRFg7P8K2HnfZ5U758JHyx2ErrG4eVqeH6rI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aNlZ3myWaXAcCZTHWRmc24lrSCtMdq1YBwBco/pmyRyyrsq3aOO0bBN24xYGKw+eC JM0/pssP8eybd+fPPaSOwK94CS7O8yeuHP++DcFSGlNpPCfcHmKz77weDCL8t4ew+g tXeEkhjZQcyL9hWiTbRgQVtYTJ7TeSk3i1FGAn7Y= Date: Thu, 16 Nov 2023 05:13:32 +0100 From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: =?utf-8?B?6buE5YaN5ry+KEpveXlvdW5nIEh1YW5nKQ==?= Cc: "tj@kernel.org" , "jiangshanlai@gmail.com" , "linux-kernel@vger.kernel.org" , ZaiYang Huang , Mukesh Ojha Subject: Re: =?utf-8?B?5Zue5aSNOiBbUEFUQ0hdIHdvcmtxdWV1ZQ==?= =?utf-8?Q?=3A?= Make a warning when a pending delay work being re-init Message-ID: References: <20231115113427.1420-1-huangzaiyang@oppo.com> <54af48a0-2d3c-4888-953b-28760f129d33@t-8ch.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 20:13:41 -0800 (PST) On 2023-11-16 01:53:30+0000, 黄再漾(Joyyoung Huang) wrote: > > 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. > > --> The data member in work_struct is a variable of type atomic_long_t, and 0 is the initial value of the atomic variable, right? Please use proper email quoting style, using "> ". Normal integers are not initialized by default when allocated on the stack. I don't think atomic_long_t behaves differently. > --> On the other hand, if a variable of type work_struct is dynamically allocated, an unnecessary warning may be generated randomly; however, it should be a good habit to initialize dynamically allocated variables to 0. It seems surprising having to initialize a variable to 0 only to directly afterwards initialize it again with INIT_DELAYED_WORK(). Also even if there was consensus that it should be done this way, existing users of this macro don't do it, so these would need to be adapted first. > > 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¹«Ë¾µÄ±£ÃÜÐÅÏ¢£¬½öÏÞÓÚÓʼþÖ¸Ã÷µÄÊÕ¼þÈË£¨°üº¬ > > ¸öÈ˼°Èº×飩ʹÓ᣽ûÖ¹ÈκÎÈËÔÚδ¾­ÊÚȨµÄÇé¿öÏÂÒÔÈκÎÐÎʽʹÓá£Èç¹ûÄú´í > > ÊÕÁ˱¾Óʼþ£¬ÇÐÎð´«²¥¡¢·Ö·¢¡¢¸´ÖÆ¡¢Ó¡Ë¢»òʹÓñ¾ÓʼþÖ®Èκβ¿·Ö»òÆäËùÔØÖ® > > ÈκÎÄÚÈÝ£¬²¢ÇëÁ¢¼´ÒÔµç×ÓÓʼþ֪ͨ·¢¼þÈ˲¢É¾³ý±¾Óʼþ¼°Æ丽¼þ¡£ This stuff really needs to go.