Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4962496rwb; Mon, 21 Nov 2022 14:32:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf4G9wXe/z5gmstGGuJLopTyC7ZW6TsSea8q9vCfsy88cdIGvvcfbjkG5nGXrpW9FYpPs2TR X-Received: by 2002:a62:be16:0:b0:56b:676e:1815 with SMTP id l22-20020a62be16000000b0056b676e1815mr1829641pff.66.1669069940759; Mon, 21 Nov 2022 14:32:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669069940; cv=none; d=google.com; s=arc-20160816; b=XOuXOYqVA8zOH6wsGlZooKOMPCFidbYgLSeUSGB3ICB5F8lQ4yGb+lj5M9t/2eaopu UccLrEn3xpDvB7TcXK5T/OwYQJXaMS3myQ2tQLZGAOtl0+qm8zAtYKMdfVANGl/Jg21f rIiuRe7oOQ9h+MBV/GoO0G/Tcw4pNrz77/m+s3iRhaabiQ/1jFhC2FsghXRKl7Znvo1t 3Keh9+F+Sa+EWyjCat8i3lt7hO/eOMO9r2AcRvRix+jxff8ozjOQKPMOID8lEvqQSgQo N3Jy+g0UxF0jSGoFFBNe7qUiSm/RK7b0r4IrC3anC/POoYqLzf3gtR+I5J11KQQiDK2L qaeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=2Mwr8qHdj7IaYxcKqySBniJ0f0+oqf14YBLQzfYLFJc=; b=dG95qg0KB7SeB98g0XYP+6kcachGxD1nO7PivLLfSUN63/UjPr0SWjya1iDGdnH815 Ekne1DoO91r+TpI6RtvhfFFRrhjcK/DsmE+Zsgs6gPpx7P2wmzlrjqS4VyJmL2aXgb5z yJMUw+31Edk1oOnXOjiFoNjBRQpAg48k1BYq9ErSTGnx+p/ul/FsQzbBVhau/VPJBgbF 15TkrJy0gjm3iGBXyK/lJqbwkJjhDA40kqftt661Swl0+IrbijW43mXcNioNbD+eBcWl NdiAc9wqrg+c5fyfuT36NEJJJWcJ/YIiY1u5RFA1GcFPEDDnzKXXl6xjJyrH53WUITt8 U2jg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z13-20020a170903018d00b0018537cc29f9si13461813plg.15.2022.11.21.14.32.01; Mon, 21 Nov 2022 14:32:20 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231939AbiKUWWE (ORCPT + 99 others); Mon, 21 Nov 2022 17:22:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231936AbiKUWWD (ORCPT ); Mon, 21 Nov 2022 17:22:03 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 038AE18B0E; Mon, 21 Nov 2022 14:22:03 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 933A8614D7; Mon, 21 Nov 2022 22:22:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2DD2C43147; Mon, 21 Nov 2022 22:21:59 +0000 (UTC) Date: Mon, 21 Nov 2022 17:21:57 -0500 From: Steven Rostedt To: Thomas Gleixner Cc: LKML , Linus Torvalds , Anna-Maria Behnsen , 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 13/15] timers: Provide timer_shutdown[_sync]() Message-ID: <20221121172157.2457df06@gandalf.local.home> In-Reply-To: <20221115202117.734852797@linutronix.de> References: <20221115195802.415956561@linutronix.de> <20221115202117.734852797@linutronix.de> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,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, 15 Nov 2022 21:28:54 +0100 (CET) Thomas Gleixner wrote: > +/** > + * 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. "See timer_delete_sync() for synchronization and context rules." As where it can be executed is as important as the synchronization that is needed. -- Steve > + * > + * 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. > + * > + * Return: > + * * %0 - The timer was not pending > + * * %1 - The timer was pending > + */ > +int timer_shutdown_sync(struct timer_list *timer) > +{ > + return __timer_delete_sync(timer, true); > +} > +EXPORT_SYMBOL_GPL(timer_shutdown_sync); > +