From patchwork Wed Nov 23 20:18:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 2140 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3008314wrr; Wed, 23 Nov 2022 12:21:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf4eQ4Ez+6nM9UBBHPmxcfnTgMtPEKTjKqGxYGvXuEb1dIlR6LE0s3o2V1H9GZekpe2+6d8o X-Received: by 2002:a65:4607:0:b0:477:31bc:348f with SMTP id v7-20020a654607000000b0047731bc348fmr11473250pgq.72.1669234860395; Wed, 23 Nov 2022 12:21:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669234860; cv=none; d=google.com; s=arc-20160816; b=oBmI0llP998c25w1QSZn7We3kQJJAO1jh4Xp2vwULsHJI5FfEJm1L/2ir8xIi4ecYE 7fgILQF/b2KuNClxuWyAQdXX7jidOnx12HjFZ8aMrN4UshAWCaWe1LwQ2TcPU4s+GF0g E1JpB7upv2XFLARmaw7dtWeSObw3DQKtJtfLgBAXgwBvbpOMa/kuP7/6lxBPh6wNGVOD 09QJ08td+sqUMvrSf8KOOpa4coXvO4xDeZxHIAinVlvabKM6ye4N+7wE95s2Dv538AeI JTpp08TQVywbANbmg2oeaho8UuYqYO/55qK4vIFl4/Y8QQ0I/Gvr4I9/gI/cbfSr7P7A 42ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=o8uOQEGEwvYxhWAaMgeou6hbxri/lpOsubwv/Uf38Z0=; b=NfH274PS77DqMGacXk4xKSFNhfqrWOe+dR8p42LrK86d9d4gx9hn9Y4xzhiep5hFGR oPQ2+h7BbVGHVyp57MZ30zvV/1KXTIkVKKw/JVpncEpvBgOhD2tria+S2z1Q66dNaSMb Kk5EQZ6dE6KN4NTH8suW86EynNZsiAZzASR3r5N/SEPPVlCoJyol1+0QRhM+Fc+zKHyQ LrAKn2CbMD0+uGM9YpBCKBVaRFIxUg8lO9cfC9QPZHP6WEyk8zmey0pHbPJtqbWA7Nj/ rPXXbxHFdCP8IxMSFNz12yA5//10tAC+tdPAq9mccT5XtWIqHGJ3Url96knWSfpiIuNv yhjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=COYcMAmI; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j3-20020a170903028300b0018930d070bdsi3336932plr.72.2022.11.23.12.20.47; Wed, 23 Nov 2022 12:21:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=COYcMAmI; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S239337AbiKWUTB (ORCPT + 99 others); Wed, 23 Nov 2022 15:19:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239170AbiKWUSl (ORCPT ); Wed, 23 Nov 2022 15:18:41 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 486248CB8A; Wed, 23 Nov 2022 12:18:32 -0800 (PST) Message-ID: <20221123201306.823305113@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669234710; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=o8uOQEGEwvYxhWAaMgeou6hbxri/lpOsubwv/Uf38Z0=; b=COYcMAmIbivJBidbwe5beja4+qO+a8aJL86E1O0/FC6ijE5U4SgaE/VYSfjK4v7VfrER/J M4MstFRQiuExyavyhsazBJbyu+2tFMasg5J6K2w6oi/OsbbAzRgb8qMwL5wU68MrHpcypC a/Nvi55H+MhuHqZkybiRUsEzuljxPjl3ERCezh2xJQVERdFWebqYjomIfazUdve5gRYFSA RiN2gkIN3/kB08rJU/bbijrSpJxM9kNP8ihnMFPOZpdhFPMsUPm7i//XZUbTY1fAPNqhy7 La6O7XCVTG67CO/ivKTpbhr744TC66Yj9zAp0GAQxonXXREmYwdutqyDhNHt5w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669234710; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=o8uOQEGEwvYxhWAaMgeou6hbxri/lpOsubwv/Uf38Z0=; b=tWkPr6RffzWLQkTR/NQ0KmNfRRYOB5CnJ78EApPCdOd2hKEEecFYpI3ioY7Zg39XeXnDkQ gfsHlazd7+HNAdAQ== 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, Jacob Keller Subject: [patch V3 00/17] timers: Provide timer_shutdown[_sync]() Date: Wed, 23 Nov 2022 21:18:29 +0100 (CET) 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750219305144532877?= X-GMAIL-MSGID: =?utf-8?q?1750319612980491613?= This is the third version of the timer shutdown work. The second version can be found here: https://lore.kernel.org/all/20221122171312.191765396@linutronix.de Tearing down timers can be tedious when there are circular dependencies to other things which need to be torn down. A prime example is timer and workqueue where the timer schedules work and the work arms the timer. Steven and the Google Chromebook team ran into such an issue in the Bluetooth HCI code. Steven suggested to create a new function del_timer_free() which marks the timer as shutdown. Rearm attempts of shutdown timers are discarded and he wanted to emit a warning for that case: https://lore.kernel.org/all/20220407161745.7d6754b3@gandalf.local.home This resulted in a lengthy discussion and suggestions how this should be implemented. The patch series went through several iterations and during the review of the last version it turned out that this approach is suboptimal: https://lore.kernel.org/all/20221110064101.429013735@goodmis.org The warning is not really helpful because it's entirely unclear how it should be acted upon. The only way to address such a case is to add 'if (in_shutdown)' conditionals all over the place. This is error prone and in most cases of teardown like the HCI one which started this discussion not required all. What needs to prevented is that pending work which is drained via destroy_workqueue() does not rearm the previously shutdown timer. Nothing in that shutdown sequence relies on the timer being functional. The conclusion was that the semantics of timer_shutdown_sync() should be: - timer is not enqueued - timer callback is not running - timer cannot be rearmed Preventing the rearming of shutdown timers is done by discarding rearm attempts silently. As Steven is short of cycles, I made some spare cycles available and reworked the patch series to follow the new semantics and plugged the races which were discovered during review. The patches have been split up into small pieces to make review easier and I took the liberty to throw a bunch of overdue cleanups into the picture instead of proliferating the existing state further. The last patch in the series addresses the HCI teardown issue for real. The series is also available from git: git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git timers Changes vs. V2: - Fixed up change logs and comments (Anna-Maria) - Picked up Reviewed-by tags Thanks, tglx Reviewed-by: Anna-Maria Behnsen --- Documentation/RCU/Design/Requirements/Requirements.rst | 2 Documentation/core-api/local_ops.rst | 2 Documentation/kernel-hacking/locking.rst | 17 Documentation/timers/hrtimers.rst | 2 Documentation/translations/it_IT/kernel-hacking/locking.rst | 14 Documentation/translations/zh_CN/core-api/local_ops.rst | 2 arch/arm/mach-spear/time.c | 8 drivers/bluetooth/hci_qca.c | 10 drivers/char/tpm/tpm-dev-common.c | 4 drivers/clocksource/arm_arch_timer.c | 12 drivers/clocksource/timer-sp804.c | 6 drivers/staging/wlan-ng/hfa384x_usb.c | 4 drivers/staging/wlan-ng/prism2usb.c | 6 include/linux/timer.h | 35 kernel/time/timer.c | 425 +++++++++--- net/sunrpc/xprt.c | 2 16 files changed, 405 insertions(+), 146 deletions(-)