Message ID | 20221122171312.191765396@linutronix.de |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2353004wrr; Tue, 22 Nov 2022 09:46:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf7naVXFO42avg8gOvBLNCQlEg8jq+Hm2XaFCb34hGQNtgTVC934sJONaRzHYjclcKQeoiZV X-Received: by 2002:a63:140e:0:b0:477:b461:3a3b with SMTP id u14-20020a63140e000000b00477b4613a3bmr1253147pgl.623.1669139199012; Tue, 22 Nov 2022 09:46:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669139199; cv=none; d=google.com; s=arc-20160816; b=wXXewagZriK6UY6Su66GYxunKJgGSVDZv/EcRz1ScbgrS3TjiSIh0DGZn8Y1lgJLfg qWje5V/nhMsGQ1Vmc+inzUU+LJwOfgr7DvRH8j/OpDEykuLB3qZCa7pZBAd3+lYeq9gi 9Ir+Jjq2HkAbr5xreE/TE6Nxuz7Al7o7+IN9kR2oj3LR67T0NHCldt8Y/ENzSxe5ZKR0 rmGKtoB5ooex1GPlb6Bj8R3EYYmFE7hKquz1fOGeD+Zixdo8L4X7edcCrtcAPFMgZIsT dnBGHuFzwHj2lX2h/HfHaix6Jzb5INnqf1CxH2V57ysCniSATfiE4hGKDK/VJ8nP4Na7 v0pg== 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=POzOynlARSCDWGTOOqHnlCYCC6vCHB34Df8+dSsmA8w=; b=HqRKR8zI1+N6kCPpTl7evhAUWMFKm+qFXKuVIqHPsiTwppCQqnvO90QjGd40MBcUOS WvX1jhvicKoU/JDneouckye2MAHkBZ01AAbkTcARxHtR/SApyG5CGTtm38Gm8IswqIxX dhgSZg24GTmZTTqKX5D318uE6bRKjjPmXwR/UbH/CRXNy+ka+XjvjSbaPiLKoTLGP3hN FJWt+8bC9dj9REEHm9aeXQxeT6YhTKdho+7+PZ3Ro6x/HLlun2qVHGqg2jBlyPzpo/VS Tm/cuc/l0ISU4REPKi9AGQxs2xG6k5hDySuhrSpfuOrxTUbLCtqRAkanvdJpeOEptYuM t4Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=n4d8ksAi; 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 s35-20020a635263000000b00460f2778437si14541885pgl.366.2022.11.22.09.46.22; Tue, 22 Nov 2022 09:46:38 -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=n4d8ksAi; 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 S233868AbiKVRot (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Tue, 22 Nov 2022 12:44:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231808AbiKVRor (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 22 Nov 2022 12:44:47 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DBA0D9F; Tue, 22 Nov 2022 09:44:46 -0800 (PST) Message-ID: <20221122171312.191765396@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669139084; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=POzOynlARSCDWGTOOqHnlCYCC6vCHB34Df8+dSsmA8w=; b=n4d8ksAiiBOB/GiR6goaaHimi7sHyXMi9NrCbE5iQSzoOQkNnPW3npgeuXLOY1LNkZdv+5 /miK6EuKmhbFkWBh5AXzRkus5gVDfJPrnXj+iVOMNOeI0W6Z+azDx9gH50MDlVa/2aiNaw X4AROGyxUrfk3KAYYlto7xQiSvNWXfa3t9leNIcT+UdA2Dv6+pg2nW/JqtX0iuc2GJQyHv hD+LRAU5Zjg1R1isaWh4DyIR17k7sTS9kivki+zk+p8tnpC0SLNec4QkD8wftVHQdjMidZ 1Begitcm/eVIzhCdBhfqaZ8D3dZQlzqeXcs3s1OJBKt1xC08RYnQ4eAsatOv2Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669139084; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=POzOynlARSCDWGTOOqHnlCYCC6vCHB34Df8+dSsmA8w=; b=rvixnL7+gnPzgGtSHp+QMSlFli6vU24L4I6ICdNCiY6IxhqE4flOOpILGRvcdmkVIchlrf M8a+5IF6MY//wFCA== From: Thomas Gleixner <tglx@linutronix.de> To: LKML <linux-kernel@vger.kernel.org> Cc: Linus Torvalds <torvalds@linuxfoundation.org>, Steven Rostedt <rostedt@goodmis.org>, Anna-Maria Behnsen <anna-maria@linutronix.de>, Peter Zijlstra <peterz@infradead.org>, Stephen Boyd <sboyd@kernel.org>, Guenter Roeck <linux@roeck-us.net>, Andrew Morton <akpm@linux-foundation.org>, Julia Lawall <Julia.Lawall@inria.fr>, Arnd Bergmann <arnd@arndb.de>, Viresh Kumar <viresh.kumar@linaro.org>, Marc Zyngier <maz@kernel.org>, Marcel Holtmann <marcel@holtmann.org>, Johan Hedberg <johan.hedberg@gmail.com>, Luiz Augusto von Dentz <luiz.dentz@gmail.com>, linux-bluetooth@vger.kernel.org, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, netdev@vger.kernel.org Subject: [patch V2 00/17] timers: Provide timer_shutdown[_sync]() Date: Tue, 22 Nov 2022 18:44:44 +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: <linux-kernel.vger.kernel.org> 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?1750219305144532877?= |
Series |
timers: Provide timer_shutdown[_sync]()
|
|
Message
Thomas Gleixner
Nov. 22, 2022, 5:44 p.m. UTC
This is the second version of the timer shutdown work. The first version can be found here: https://lore.kernel.org/all/20221115195802.415956561@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. V1: - Fixed the return vs. continue bug in the timer expiration code (Steven) - Addressed the review vs. function documentation (Steven) - Fixed up the del_timer*() references in documentation (Steven) - Split out the 'remove bogus claims about del_timer_sync()' change - Picked up Reviewed/Tested-by tags where appropriate Thanks, tglx --- 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 | 424 +++++++++--- net/sunrpc/xprt.c | 2 16 files changed, 404 insertions(+), 146 deletions(-)
Comments
On 11/22/2022 9:44 AM, Thomas Gleixner wrote: > This is the second version of the timer shutdown work. The first version > can be found here: > > https://lore.kernel.org/all/20221115195802.415956561@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. V1: > > - Fixed the return vs. continue bug in the timer expiration code (Steven) > > - Addressed the review vs. function documentation (Steven) > > - Fixed up the del_timer*() references in documentation (Steven) > > - Split out the 'remove bogus claims about del_timer_sync()' change > > - Picked up Reviewed/Tested-by tags where appropriate > > Thanks, > > tglx > --- > 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 | 424 +++++++++--- > net/sunrpc/xprt.c | 2 > 16 files changed, 404 insertions(+), 146 deletions(-) > I read through the series! Really appreciate breaking things up and cleaning up a bunch of the docs. A thorough explanation of the problem is great. I noticed that we still left some timer functions outside the timer_* namespace, but nothing was made worse as these functions already existed. Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>