public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/12] hrtimers: Switch to new hrtimer interface functions (5/5)
@ 2024-10-28  7:35 Nam Cao
  2024-10-28  7:35 ` [PATCH 01/12] hrtimers: Delete hrtimer_init() Nam Cao
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Nam Cao @ 2024-10-28  7:35 UTC (permalink / raw)
  To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
	Andreas Hindborg, Alice Ryhl, Miguel Ojeda, Kees Cook,
	linux-kernel
  Cc: Nam Cao, Greg Kroah-Hartman, Jens Axboe, Kalle Valo,
	Steven Rostedt

This is the fifth part of a 5-part series (split for convenience). All 5
parts are:

Part 1: https://lore.kernel.org/lkml/cover.1729864615.git.namcao@linutronix.de
Part 2: https://lore.kernel.org/lkml/cover.1729864823.git.namcao@linutronix.de
Part 3: https://lore.kernel.org/lkml/cover.1729865232.git.namcao@linutronix.de
Part 4: https://lore.kernel.org/lkml/cover.1729865485.git.namcao@linutronix.de
Part 5: https://lore.kernel.org/lkml/cover.1729865740.git.namcao@linutronix.de

To use hrtimer, hrtimer_init() (or one of its variant) must be called, and
also the timer's callfack function must be setup separately.

That can cause misuse of hrtimer. For example, because:
  - The callback function is not setup
  - The callback function is setup while it is not safe to do so

To prevent misuse of hrtimer, this series:
  - Introduce new functions hrtimer_setup*(). These new functions are
    similar to hrtimer_init*(), except that they also sanity-check and
    initialize the callback function.
  - Introduce hrtimer_update_function() which checks that it is safe to
    change the callback function. The 'function' field of hrtimer is then
    made private.
  - Convert all users to use the new functions.
  - Some minor cleanups on the way.

Most conversion patches were created using Coccinelle with the sematic
patch below; except for tricky cases that Coccinelle cannot handle, or for
some cases where a Coccinelle's bug regarding 100 column limit is
triggered. Any patches not mentioning Coccinelle were done manually.

virtual patch
@@ expression timer, clock, mode, func; @@
- hrtimer_init(timer, clock, mode);
  ...
- timer->function = func;
+ hrtimer_setup(timer, func, clock, mode);

@@ expression timer, clock, mode, func; @@
- hrtimer_init(&timer, clock, mode);
  ...
- timer.function = func;
+ hrtimer_setup(&timer, func, clock, mode);

@@ expression timer, clock, mode, func; @@
- hrtimer_init_on_stack(&timer, clock, mode);
  ...
- timer.function = func;
+ hrtimer_setup_on_stack(&timer, func, clock, mode);

@@ expression timer, clock, mode; @@
- hrtimer_init_sleeper_on_stack(timer, clock, mode);
+ hrtimer_setup_sleeper_on_stack(timer, clock, mode);

Signed-off-by: Nam Cao <namcao@linutronix.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Kalle Valo <kvalo@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>

Nam Cao (12):
  hrtimers: Delete hrtimer_init()
  hrtimers: Switch to use __htimer_setup()
  hrtimers: Merge __hrtimer_init() into __hrtimer_setup()
  serial: xilinx_uartps: Use helper function hrtimer_update_function()
  io_uring: Use helper function hrtimer_update_function()
  wifi: rt2x00: Switch to use hrtimer_update_function()
  hrtimers: Make callback function pointer private
  hrtimers: Remove unnecessary NULL check in hrtimer_start_range_ns()
  hrtimers: Rename __hrtimer_init_sleeper() to __hrtimer_setup_sleeper()
  hrtimers: Rename debug_init() to debug_setup()
  hrtimers: Rename debug_init_on_stack() to debug_setup_on_stack()
  tracing/timers: Rename hrtimer_init event to hrtimer_setup

 Documentation/trace/ftrace.rst                |  4 +-
 .../net/wireless/ralink/rt2x00/rt2800mmio.c   |  2 +-
 .../net/wireless/ralink/rt2x00/rt2800usb.c    |  2 +-
 drivers/tty/serial/xilinx_uartps.c            |  4 +-
 include/linux/hrtimer.h                       |  4 +-
 include/linux/hrtimer_types.h                 |  4 +-
 include/trace/events/timer.h                  |  8 +--
 io_uring/io_uring.c                           |  2 +-
 kernel/time/hrtimer.c                         | 69 +++++--------------
 kernel/time/timer_list.c                      |  2 +-
 tools/perf/tests/shell/trace_btf_enum.sh      |  2 +-
 11 files changed, 35 insertions(+), 68 deletions(-)

-- 
2.39.5


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

end of thread, other threads:[~2024-10-28  7:36 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-28  7:35 [PATCH 00/12] hrtimers: Switch to new hrtimer interface functions (5/5) Nam Cao
2024-10-28  7:35 ` [PATCH 01/12] hrtimers: Delete hrtimer_init() Nam Cao
2024-10-28  7:35 ` [PATCH 02/12] hrtimers: Switch to use __htimer_setup() Nam Cao
2024-10-28  7:35 ` [PATCH 03/12] hrtimers: Merge __hrtimer_init() into __hrtimer_setup() Nam Cao
2024-10-28  7:35 ` [PATCH 04/12] serial: xilinx_uartps: Use helper function hrtimer_update_function() Nam Cao
2024-10-28  7:35 ` [PATCH 05/12] io_uring: " Nam Cao
2024-10-28  7:35 ` [PATCH 06/12] wifi: rt2x00: Switch to use hrtimer_update_function() Nam Cao
2024-10-28  7:35 ` [PATCH 07/12] hrtimers: Make callback function pointer private Nam Cao
2024-10-28  7:35 ` [PATCH 08/12] hrtimers: Remove unnecessary NULL check in hrtimer_start_range_ns() Nam Cao
2024-10-28  7:35 ` [PATCH 09/12] hrtimers: Rename __hrtimer_init_sleeper() to __hrtimer_setup_sleeper() Nam Cao
2024-10-28  7:35 ` [PATCH 10/12] hrtimers: Rename debug_init() to debug_setup() Nam Cao
2024-10-28  7:35 ` [PATCH 11/12] hrtimers: Rename debug_init_on_stack() to debug_setup_on_stack() Nam Cao
2024-10-28  7:35 ` [PATCH 12/12] tracing/timers: Rename hrtimer_init event to hrtimer_setup Nam Cao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox