From patchwork Tue Nov 15 20:28:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 626216 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9107C433FE for ; Tue, 15 Nov 2022 20:31:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232006AbiKOUbT (ORCPT ); Tue, 15 Nov 2022 15:31:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236982AbiKOUaH (ORCPT ); Tue, 15 Nov 2022 15:30:07 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 667FA30F6D; Tue, 15 Nov 2022 12:28:58 -0800 (PST) Message-ID: <20221115202117.792861106@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668544136; 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: references:references; bh=kJsB0B8f0qFmQ81lyDCpvVT7DxA3aerH8vXT9O1XEA4=; b=Pu8SGB0c4W4WMOpJe5pArorCPiSQIfam8L1S5Y3Jy/MOZU7i/qTWWK04Wv2U0sTLgC41vH MHoPL+Jpgxoh8gNyIFsohKaXUFu8JEOSdN2CoBihJFNzVr/Cs4vzi1ETiRfX5m/SuaSEdO TqvCu2TViqhmsdshMLYVdLLWxEGSdQvruEXbDZnSDq301cajJDI0wiYrpvUkZwvizmSo7F ewcKB/ps/v1ulqAQxxuVDXOXyUGghbSDOLSqf2Ip/0chghKDhJp4PaOk9x+zjtrwEPxTBk PY1ZUTY824R52JGJ/hHQ+a4h6/fI3PA8FHtqV1PGOskSVMDBSQhcYgBjKvgQPQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668544136; 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: references:references; bh=kJsB0B8f0qFmQ81lyDCpvVT7DxA3aerH8vXT9O1XEA4=; b=F4IRW1/tgARIGOV4ZTNZkN6R2tHnpA0BWQ7F+t6okMkuF4n/c+Xhc2P3opbia4Q8r/2MGA CVzmleEVKnlNrPCA== From: Thomas Gleixner To: LKML Cc: Linus Torvalds , Steven Rostedt , 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: [patch 14/15] timers: Update the documentation to reflect on the new timer_shutdown() API References: <20221115195802.415956561@linutronix.de> MIME-Version: 1.0 Date: Tue, 15 Nov 2022 21:28:56 +0100 (CET) Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: "Steven Rostedt (Google)" In order to make sure that a timer is not re-armed after it is stopped before freeing, a new shutdown state is added to the timer code. The API timer_shutdown_sync() and timer_shutdown() must be called before the object that holds the timer can be freed. Update the documentation to reflect this new workflow. [ tglx: Updated to the new semantics and removed the bogus claim that del_timer_sync() returns the number of removal attempts ] Signed-off-by: Steven Rostedt (Google) Signed-off-by: Thomas Gleixner Tested-by: Guenter Roeck Link: https://lore.kernel.org/r/20221110064147.712934793@goodmis.org --- Documentation/RCU/Design/Requirements/Requirements.rst | 2 +- Documentation/core-api/local_ops.rst | 2 +- Documentation/kernel-hacking/locking.rst | 13 ++++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) --- a/Documentation/RCU/Design/Requirements/Requirements.rst +++ b/Documentation/RCU/Design/Requirements/Requirements.rst @@ -1858,7 +1858,7 @@ unloaded. After a given module has been one of its functions results in a segmentation fault. The module-unload functions must therefore cancel any delayed calls to loadable-module functions, for example, any outstanding mod_timer() must be dealt -with via del_timer_sync() or similar. +with via timer_shutdown_sync(). Unfortunately, there is no way to cancel an RCU callback; once you invoke call_rcu(), the callback function is eventually going to be --- a/Documentation/core-api/local_ops.rst +++ b/Documentation/core-api/local_ops.rst @@ -191,7 +191,7 @@ Here is a sample module which implements static void __exit test_exit(void) { - del_timer_sync(&test_timer); + timer_shutdown_sync(&test_timer); } module_init(test_init); --- a/Documentation/kernel-hacking/locking.rst +++ b/Documentation/kernel-hacking/locking.rst @@ -1003,11 +1003,14 @@ If 0, it means (in this case) that it is Another common problem is deleting timers which restart themselves (by -calling add_timer() at the end of their timer function). -Because this is a fairly common case which is prone to races, you should -use del_timer_sync() (``include/linux/timer.h``) to -handle this case. It returns the number of times the timer had to be -deleted before we finally stopped it from adding itself back in. +calling add_timer() at the end of their timer function). Because this is a +fairly common case which is prone to races, you should use del_timer_sync() +(``include/linux/timer.h``) to handle this case. + +Before freeing a timer, timer_shutdown() or timer_shutdown_sync() should be +called which will keep it from being rearmed. Any subsequent attempt to +rearm the timer will be silently ignored by the core code. + Locking Speed =============