linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch V2 00/17] timers: Provide timer_shutdown[_sync]()
@ 2022-11-22 17:44 Thomas Gleixner
  2022-11-22 17:44 ` [patch V2 01/17] Documentation: Remove bogus claim about del_timer_sync() Thomas Gleixner
                   ` (17 more replies)
  0 siblings, 18 replies; 36+ messages in thread
From: Thomas Gleixner @ 2022-11-22 17:44 UTC (permalink / raw)
  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, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev

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(-)


^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2022-11-23 18:46 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22 17:44 [patch V2 00/17] timers: Provide timer_shutdown[_sync]() Thomas Gleixner
2022-11-22 17:44 ` [patch V2 01/17] Documentation: Remove bogus claim about del_timer_sync() Thomas Gleixner
2022-11-22 17:44 ` [patch V2 02/17] ARM: spear: Do not use timer namespace for timer_shutdown() function Thomas Gleixner
2022-11-22 17:44 ` [patch V2 03/17] clocksource/drivers/arm_arch_timer: " Thomas Gleixner
2022-11-22 17:44 ` [patch V2 04/17] clocksource/drivers/sp804: " Thomas Gleixner
2022-11-22 17:44 ` [patch V2 05/17] timers: Get rid of del_singleshot_timer_sync() Thomas Gleixner
2022-11-22 17:44 ` [patch V2 06/17] timers: Replace BUG_ON()s Thomas Gleixner
2022-11-22 17:44 ` [patch V2 07/17] timers: Update kernel-doc for various functions Thomas Gleixner
2022-11-23 10:23   ` Anna-Maria Behnsen
2022-11-23 17:09     ` Thomas Gleixner
2022-11-22 17:44 ` [patch V2 08/17] timers: Use del_timer_sync() even on UP Thomas Gleixner
2022-11-22 17:44 ` [patch V2 09/17] timers: Rename del_timer_sync() to timer_delete_sync() Thomas Gleixner
2022-11-22 22:23   ` David Laight
2022-11-22 22:45     ` Steven Rostedt
2022-11-23  0:08       ` Thomas Gleixner
2022-11-23  0:28         ` Steven Rostedt
2022-11-22 17:45 ` [patch V2 10/17] timers: Rename del_timer() to timer_delete() Thomas Gleixner
2022-11-22 17:45 ` [patch V2 11/17] Documentation: Replace del_timer/del_timer_sync() Thomas Gleixner
2022-11-22 17:45 ` [patch V2 12/17] timers: Silently ignore timers with a NULL function Thomas Gleixner
2022-11-23  9:22   ` Anna-Maria Behnsen
2022-11-23 10:39   ` Anna-Maria Behnsen
2022-11-23 11:06   ` Anna-Maria Behnsen
2022-11-23 17:08     ` Thomas Gleixner
2022-11-22 17:45 ` [patch V2 13/17] timers: Split [try_to_]del_timer[_sync]() to prepare for shutdown mode Thomas Gleixner
2022-11-22 23:04   ` Jacob Keller
2022-11-23 17:05     ` Thomas Gleixner
2022-11-23 18:45       ` Jacob Keller
2022-11-23 11:23   ` Anna-Maria Behnsen
2022-11-23 11:24     ` Anna-Maria Behnsen
2022-11-22 17:45 ` [patch V2 14/17] timers: Add shutdown mechanism to the internal functions Thomas Gleixner
2022-11-22 17:45 ` [patch V2 15/17] timers: Provide timer_shutdown[_sync]() Thomas Gleixner
2022-11-23 12:02   ` Anna-Maria Behnsen
2022-11-23 17:06     ` Thomas Gleixner
2022-11-22 17:45 ` [patch V2 16/17] timers: Update the documentation to reflect on the new timer_shutdown() API Thomas Gleixner
2022-11-22 17:45 ` [patch V2 17/17] Bluetooth: hci_qca: Fix the teardown problem for real Thomas Gleixner
2022-11-22 23:09 ` [patch V2 00/17] timers: Provide timer_shutdown[_sync]() Jacob Keller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).