Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7251555rwb; Wed, 23 Nov 2022 04:21:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf40LB1a0JEHaqIRBFRqe8GRi095IenXJSD5zc/E4dlFygpgMS+0pJFWtFa1ba8DSUMjk0z0 X-Received: by 2002:a17:902:e80f:b0:188:f571:cea2 with SMTP id u15-20020a170902e80f00b00188f571cea2mr11713942plg.146.1669206089752; Wed, 23 Nov 2022 04:21:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669206089; cv=none; d=google.com; s=arc-20160816; b=sWIkjnMv5Yr4uNQ7z+/X8NxRVB6z5QSKWFfaFqyKXi3YUIrcE7w/eca+rSnv700FIg ghVTLzfjivBOFLH1KTxlYtErHcCmC7szGan4obJ1wMT85Z2lbohMGCqbEgCvb5TkveFo cjoKRMCVJd+21cBQrBHK2iGkOG6RiCOtQS6BQksciD8GVxHxfhmDWiHHaeNSps1OPEL9 Umn4mMUfaT77T0eOTXgZ/n+q+M0wsZmWqBMn6aANGCcIqcQqY3Q79jmDDN9cA0djcZOY kRvLFafflBz2/qd5KkllhXSJeXZFZtP4PywFPALcFbXq+iEXnng0iNvfyB0J/CDopxcf c1xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:dkim-signature:dkim-signature:date; bh=GBqote1BzkExg7MDXCmwtPPCsS+a19i+SHqr+lLca80=; b=XbWWn1q5A3y3GVkeaMllNcI0fjWUTN0inmon3BSxhhlDrK/6e8vtNN0W6iMGGG0lfV GH9JROjDh40EYfhyXbungq821fSWV8Uz076MH9HL++YUUdmCIrNlJlP5uySJxZTh4GP5 yih4ELbP0MyjrLw+lCvFXWqSiT6jSEXZpwWYlSc91CGJU41bfkBBJmLCHAOZE4WcbiyJ M2/eMUzcOWaqSI5j68+yD8ZQHeDQx6ZCsDEUyQYuD9ZPvAq9nCp+etMYoyxYTXgBMGVp aVjBI2sOza3KN41YuLViA3z9d4cbNyTEj8B+qNM6so84Vrg1H5zWasObKV7cpMciiJea bfjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=y0HTq8Y1; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m7-20020a656a07000000b004774d8e4894si14933091pgu.747.2022.11.23.04.20.56; Wed, 23 Nov 2022 04:21:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-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=@linutronix.de header.s=2020 header.b=y0HTq8Y1; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236717AbiKWMCf (ORCPT + 99 others); Wed, 23 Nov 2022 07:02:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235568AbiKWMCe (ORCPT ); Wed, 23 Nov 2022 07:02:34 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A63FE60; Wed, 23 Nov 2022 04:02:30 -0800 (PST) Date: Wed, 23 Nov 2022 13:02:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669204948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GBqote1BzkExg7MDXCmwtPPCsS+a19i+SHqr+lLca80=; b=y0HTq8Y1ZNK8Wtx/oprXpMyJ2N9mqtEFNwZt5LxOb1F9SRbDb3Rhf5nS6KvVLSK2yr+chq UAyUIMyIP5VBrhr2JJnGC3jFzBXDOjNtD8ugbm4sj8C/CFYUJFowIFBG8f9BuwC9O+oqlq LWhr8pvgWkG7kZsIIEKSW+d4BuIGoFCa8Qgf4jXlGE1OFJgFrPJBBtd6ww4aXRoKaoNoyo dl/u7FQPSCSzXHWVDTOl+c2uoYrzmGN/gfKHXj4EgtGiHmOa9gtB3YFnQpjugeSpTfRHZK u90AdOsj9cTnYrqs1rXagGk5UviSpZ6RHlUBx5Kb7CQSJU4MdSeyXZBmTM36nQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669204948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GBqote1BzkExg7MDXCmwtPPCsS+a19i+SHqr+lLca80=; b=+dQr51Q/aNU9Zi95upJOwnukC6/3AeHNq7llh46X/GY39Cd4rhXeE02hvdPBokTfSOXfey JuOTX+74Hbe2BNBQ== From: Anna-Maria Behnsen To: Thomas Gleixner cc: LKML , Linus Torvalds , Steven Rostedt , Peter Zijlstra , Stephen Boyd , Guenter Roeck , Andrew Morton , Julia Lawall , Arnd Bergmann , Viresh Kumar , Marc Zyngier , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , linux-bluetooth@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org Subject: Re: [patch V2 15/17] timers: Provide timer_shutdown[_sync]() In-Reply-To: <20221122173648.962476045@linutronix.de> Message-ID: <3779da12-6da5-8f6b-ec93-f8d52e38a40@linutronix.de> References: <20221122171312.191765396@linutronix.de> <20221122173648.962476045@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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-bluetooth@vger.kernel.org On Tue, 22 Nov 2022, Thomas Gleixner wrote: > @@ -1605,6 +1629,48 @@ int timer_delete_sync(struct timer_list > } > EXPORT_SYMBOL(timer_delete_sync); > > +/** > + * timer_shutdown_sync - Shutdown a timer and prevent rearming > + * @timer: The timer to be shutdown > + * > + * When the function returns it is guaranteed that: > + * - @timer is not queued > + * - The callback function of @timer is not running > + * - @timer cannot be enqueued again. Any attempt to rearm > + * @timer is silently ignored. > + * > + * See timer_delete_sync() for synchronization rules. > + * > + * This function is useful for final teardown of an infrastructure where > + * the timer is subject to a circular dependency problem. > + * > + * A common pattern for this is a timer and a workqueue where the timer can > + * schedule work and work can arm the timer. On shutdown the workqueue must > + * be destroyed and the timer must be prevented from rearming. Unless the > + * code has conditionals like 'if (mything->in_shutdown)' to prevent that > + * there is no way to get this correct with timer_delete_sync(). > + * > + * timer_shutdown_sync() is solving the problem. The correct ordering of > + * calls in this case is: > + * > + * timer_shutdown_sync(&mything->timer); > + * workqueue_destroy(&mything->workqueue); > + * > + * After this 'mything' can be safely freed. > + * > + * This obviously requires that the timer is not required to be functional > + * for the rest of the shutdown operation. NIT... Maybe the first requires could be replaced by assumes/expects/presupposes to prevent double use of required? Thanks, Anna-Maria