public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nam Cao <namcao@linutronix.de>
To: Anna-Maria Behnsen <anna-maria@linutronix.de>,
	Frederic Weisbecker <frederic@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Andreas Hindborg <a.hindborg@kernel.org>,
	Alice Ryhl <aliceryhl@google.com>,
	Miguel Ojeda <ojeda@kernel.org>, Kees Cook <kees@kernel.org>,
	linux-kernel@vger.kernel.org
Cc: Nam Cao <namcao@linutronix.de>,
	Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Sean Christopherson <seanjc@google.com>,
	Marc Zyngier <maz@kernel.org>,
	Huacai Chen <chenhuacai@kernel.org>,
	Anup Patel <anup@brainfault.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Russell King <linux@armlinux.org.uk>,
	Peter Zijlstra <peterz@infradead.org>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jens Axboe <axboe@kernel.dk>, Oleg Nesterov <oleg@redhat.com>,
	Christian Brauner <brauner@kernel.org>,
	John Stultz <jstultz@google.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Richard Weinberger <richard@nod.at>,
	Wim Van Sebroeck <wim@linux-watchdog.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Damien Le Moal <dlemoal@kernel.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Heiko Stuebner <heiko@sntech.de>,
	Herbert Xu <herbert@gondor.apana.org.au>
Subject: [PATCH 00/31] hrtimers: Switch to new hrtimer interface functions (2/5)
Date: Mon, 28 Oct 2024 08:31:33 +0100	[thread overview]
Message-ID: <cover.1729864823.git.namcao@linutronix.de> (raw)

This is the second 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: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Anup Patel <anup@brainfault.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: John Stultz <jstultz@google.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Richard Weinberger <richard@nod.at>
Cc: Wim Van Sebroeck <wim@linux-watchdog.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Damien Le Moal <dlemoal@kernel.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Herbert Xu <herbert@gondor.apana.org.au>


Nam Cao (31):
  KVM: MIPS: Switch to use hrtimer_setup()
  KVM: PPC: Switch to use hrtimer_setup()
  KVM: s390: Switch to use hrtimer_setup()
  KVM: x86: Switch to use hrtimer_setup()
  KVM: arm64: Switch to use hrtimer_setup()
  LoongArch: KVM: Switch to use hrtimer_setup()
  riscv: kvm: Switch to use hrtimer_setup()
  ARM: imx: Switch to use hrtimer_setup()
  ARM: 8611/1: l2x0: Switch to use hrtimer_setup()
  powerpc/watchdog: Switch to use hrtimer_setup()
  perf/x86: Switch to use hrtimer_setup()
  s390/ap_bus: Switch to use hrtimer_setup()
  sched: Switch to use hrtimer_setup()
  rcu: Switch to use hrtimer_setup()
  lib: test_objpool: Switch to use hrtimer_setup()
  io_uring/timeout: Switch to use hrtimer_setup()
  fork: Switch to use hrtimer_setup()
  perf: Switch to use hrtimer_setup()
  timerfd: Switch to use hrtimer_setup()
  time: Switch to hrtimer_setup()
  bpf: Switch to use hrtimer_setup()
  ubifs: Switch to use hrtimer_setup()
  watchdog: Switch to use hrtimer_setup()
  tracing/osnoise: Switch to use hrtimer_setup()
  block, bfq: Switch to use hrtimer_setup()
  ata: pata_octeon_cf: Switch to use hrtimer_setup()
  blk_iocost: Switch to use hrtimer_setup()
  PM: runtime: Switch to use hrtimer_setup()
  PM / devfreq: rockchip-dfi: Switch to use hrtimer_setup()
  null_blk: Switch to use hrtimer_setup()
  hwrng: timeriomem: Switch to use hrtimer_setup()

 arch/arm/mach-imx/mmdc.c                       |  5 ++---
 arch/arm/mm/cache-l2x0-pmu.c                   |  3 +--
 arch/arm64/kvm/arch_timer.c                    |  7 +++----
 arch/loongarch/kvm/vcpu.c                      |  4 ++--
 arch/mips/kvm/mips.c                           |  5 ++---
 arch/powerpc/kernel/watchdog.c                 |  3 +--
 arch/powerpc/kvm/powerpc.c                     |  4 ++--
 arch/riscv/kvm/vcpu_timer.c                    |  7 ++++---
 arch/s390/kvm/interrupt.c                      |  3 +--
 arch/s390/kvm/kvm-s390.c                       |  4 ++--
 arch/x86/events/intel/uncore.c                 |  3 +--
 arch/x86/events/rapl.c                         |  3 +--
 arch/x86/kvm/hyperv.c                          |  3 +--
 arch/x86/kvm/i8254.c                           |  3 +--
 arch/x86/kvm/lapic.c                           |  5 ++---
 arch/x86/kvm/vmx/nested.c                      |  5 ++---
 arch/x86/kvm/xen.c                             |  5 ++---
 block/bfq-iosched.c                            |  5 ++---
 block/blk-iocost.c                             |  3 +--
 drivers/ata/pata_octeon_cf.c                   |  5 ++---
 drivers/base/power/runtime.c                   |  4 ++--
 drivers/block/null_blk/main.c                  |  7 +++----
 drivers/char/hw_random/timeriomem-rng.c        |  3 +--
 drivers/devfreq/event/rockchip-dfi.c           |  3 +--
 drivers/s390/crypto/ap_bus.c                   |  3 +--
 drivers/watchdog/softdog.c                     |  8 +++-----
 drivers/watchdog/watchdog_dev.c                |  4 ++--
 drivers/watchdog/watchdog_hrtimer_pretimeout.c |  4 ++--
 fs/timerfd.c                                   |  5 ++---
 fs/ubifs/io.c                                  |  3 +--
 io_uring/timeout.c                             | 13 ++++++-------
 kernel/bpf/helpers.c                           |  3 +--
 kernel/events/core.c                           |  7 +++----
 kernel/fork.c                                  |  3 +--
 kernel/rcu/tree.c                              |  4 ++--
 kernel/sched/core.c                            |  3 +--
 kernel/sched/deadline.c                        |  6 ++----
 kernel/sched/fair.c                            |  8 ++++----
 kernel/sched/rt.c                              |  5 ++---
 kernel/time/ntp.c                              |  3 +--
 kernel/time/posix-timers.c                     |  7 +++----
 kernel/time/sched_clock.c                      |  3 +--
 kernel/time/tick-broadcast-hrtimer.c           |  3 +--
 kernel/time/tick-sched.c                       |  6 ++----
 kernel/trace/trace_osnoise.c                   |  6 ++----
 kernel/watchdog.c                              |  3 +--
 lib/test_objpool.c                             |  3 +--
 47 files changed, 87 insertions(+), 128 deletions(-)

-- 
2.39.5


             reply	other threads:[~2024-10-28  7:32 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-28  7:31 Nam Cao [this message]
2024-10-28  7:31 ` [PATCH 01/31] KVM: MIPS: Switch to use hrtimer_setup() Nam Cao
2024-10-28  7:31 ` [PATCH 02/31] KVM: PPC: " Nam Cao
2024-10-28  7:31 ` [PATCH 03/31] KVM: s390: " Nam Cao
2024-10-28  7:31 ` [PATCH 04/31] KVM: x86: " Nam Cao
2024-10-28 13:53   ` kernel test robot
2024-10-28 19:17   ` kernel test robot
2024-10-28  7:31 ` [PATCH 05/31] KVM: arm64: " Nam Cao
2024-10-28 10:56   ` Marc Zyngier
2024-10-28  7:31 ` [PATCH 06/31] LoongArch: KVM: " Nam Cao
2024-10-28  7:31 ` [PATCH 07/31] riscv: kvm: " Nam Cao
2024-10-28  7:31 ` [PATCH 08/31] ARM: imx: " Nam Cao
2024-10-28  7:31 ` [PATCH 09/31] ARM: 8611/1: l2x0: " Nam Cao
2024-10-28  7:31 ` [PATCH 10/31] powerpc/watchdog: " Nam Cao
2024-10-28  7:31 ` [PATCH 11/31] perf/x86: " Nam Cao
2024-10-28  7:31 ` [PATCH 12/31] s390/ap_bus: " Nam Cao
2024-10-28  7:31 ` [PATCH 13/31] sched: " Nam Cao
2024-10-28 12:51   ` kernel test robot
2024-10-28  7:31 ` [PATCH 14/31] rcu: " Nam Cao
2024-10-28 13:52   ` Paul E. McKenney
2024-10-28  7:31 ` [PATCH 15/31] lib: test_objpool: " Nam Cao
2024-10-28  7:31 ` [PATCH 16/31] io_uring/timeout: " Nam Cao
2025-05-02  8:50   ` Pavel Begunkov
2024-10-28  7:31 ` [PATCH 17/31] fork: " Nam Cao
2024-10-28  7:31 ` [PATCH 18/31] perf: " Nam Cao
2024-10-28  7:31 ` [PATCH 19/31] timerfd: " Nam Cao
2024-10-28  7:31 ` [PATCH 20/31] time: Switch to hrtimer_setup() Nam Cao
2024-10-28  7:31 ` [PATCH 21/31] bpf: Switch to use hrtimer_setup() Nam Cao
2024-10-28  7:31 ` [PATCH 22/31] ubifs: " Nam Cao
2024-10-28  7:31 ` [PATCH 23/31] watchdog: " Nam Cao
2024-10-28  7:31 ` [PATCH 24/31] tracing/osnoise: " Nam Cao
2024-10-28  7:52   ` Steven Rostedt
2024-10-28  7:31 ` [PATCH 25/31] block, bfq: " Nam Cao
2024-10-28  7:31 ` [PATCH 26/31] ata: pata_octeon_cf: " Nam Cao
2024-10-29 23:41   ` Damien Le Moal
2024-10-28  7:32 ` [PATCH 27/31] blk_iocost: " Nam Cao
2024-10-28  7:32 ` [PATCH 28/31] PM: runtime: " Nam Cao
2024-10-28 11:43   ` Rafael J. Wysocki
2024-10-28  7:32 ` [PATCH 29/31] PM / devfreq: rockchip-dfi: " Nam Cao
2024-12-08 12:39   ` Chanwoo Choi
2024-10-28  7:32 ` [PATCH 30/31] null_blk: " Nam Cao
2024-10-28  7:32 ` [PATCH 31/31] hwrng: timeriomem: " Nam Cao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1729864823.git.namcao@linutronix.de \
    --to=namcao@linutronix.de \
    --cc=a.hindborg@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=aliceryhl@google.com \
    --cc=anna-maria@linutronix.de \
    --cc=anup@brainfault.org \
    --cc=ast@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=borntraeger@linux.ibm.com \
    --cc=brauner@kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=frederic@kernel.org \
    --cc=heiko@sntech.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=jstultz@google.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=maz@kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=ojeda@kernel.org \
    --cc=oleg@redhat.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rafael@kernel.org \
    --cc=richard@nod.at \
    --cc=rostedt@goodmis.org \
    --cc=s.hauer@pengutronix.de \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=tsbogend@alpha.franken.de \
    --cc=wim@linux-watchdog.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox