All of lore.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>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	intel-gfx@lists.freedesktop.org,
	Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	x86@kernel.org, Jakub Kicinski <kuba@kernel.org>,
	Oliver Hartkopp <socketcan@hartkopp.net>,
	Kalle Valo <kvalo@kernel.org>, Jens Axboe <axboe@kernel.dk>,
	Christian Brauner <brauner@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	John Stultz <jstultz@google.com>
Subject: [PATCH 00/21] hrtimers: Switch to new hrtimer interface functions (1/5)
Date: Mon, 28 Oct 2024 08:29:19 +0100	[thread overview]
Message-ID: <cover.1729864615.git.namcao@linutronix.de> (raw)

This is the first 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: Jani Nikula <jani.nikula@linux.intel.com>
Cc: intel-gfx@lists.freedesktop.org
Cc: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: x86@kernel.org
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Oliver Hartkopp <socketcan@hartkopp.net>
Cc: Kalle Valo <kvalo@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: John Stultz <jstultz@google.com>

Nam Cao (21):
  hrtimers: Add missing hrtimer_init event trace points
  hrtimers: Remove unused hrtimer_init_sleeper()
  drm/i915/request: Remove unnecessary abuse of hrtimer::function
  KVM: x86/xen: Initialize hrtimer in kvm_xen_init_vcpu()
  can: bcm: Don't initialized an unused hrtimer
  wifi: rt2x00: Remove redundant hrtimer_init()
  io_uring: Remove redundant hrtimer's callback function setup
  hrtimers: Introduce hrtimer_setup() to replace hrtimer_init()
  hrtimers: Introduce hrtimer_setup_on_stack()
  hrtimers: Introduce hrtimer_setup_sleeper_on_stack()
  hrtimers: Introduce hrtimer_update_function()
  fs/aio: Switch to use hrtimer_setup_sleeper_on_stack()
  futex: Switch to use hrtimer_setup_sleeper_on_stack()
  net: pktgen: Switch to use hrtimer_setup_sleeper_on_stack()
  timers: Switch to use hrtimer_setup_sleeper_on_stack()
  wait: Switch to use hrtimer_setup_sleeper_on_stack()
  hrtimers: Delete hrtimer_init_sleeper_on_stack()
  sched/idle: Switch to use hrtimer_setup_on_stack()
  io_uring: Switch to use hrtimer_setup_on_stack()
  alarmtimer: Switch to use hrtimer_setup() and hrtimer_setup_on_stack()
  hrtimers: Delete hrtimer_init_on_stack()

 arch/x86/kvm/xen.c                            |   4 +-
 drivers/gpu/drm/i915/i915_request.c           |  17 +--
 .../net/wireless/ralink/rt2x00/rt2x00usb.c    |   2 -
 fs/aio.c                                      |   2 +-
 include/linux/hrtimer.h                       |  51 ++++----
 include/linux/wait.h                          |   4 +-
 io_uring/io_uring.c                           |   7 +-
 io_uring/timeout.c                            |   1 -
 kernel/futex/core.c                           |   6 +-
 kernel/sched/idle.c                           |   4 +-
 kernel/time/alarmtimer.c                      |   9 +-
 kernel/time/hrtimer.c                         | 110 +++++++++++++-----
 kernel/time/sleep_timeout.c                   |   2 +-
 net/can/bcm.c                                 |  19 ++-
 net/core/pktgen.c                             |   2 +-
 15 files changed, 143 insertions(+), 97 deletions(-)

-- 
2.39.5


             reply	other threads:[~2024-10-28 18:29 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-28  7:29 Nam Cao [this message]
2024-10-28  7:29 ` [PATCH 01/21] hrtimers: Add missing hrtimer_init event trace points Nam Cao
2024-10-28  7:29 ` [PATCH 02/21] hrtimers: Remove unused hrtimer_init_sleeper() Nam Cao
2024-10-28  7:29 ` [PATCH 03/21] drm/i915/request: Remove unnecessary abuse of hrtimer::function Nam Cao
2024-10-28  7:29 ` [PATCH 04/21] KVM: x86/xen: Initialize hrtimer in kvm_xen_init_vcpu() Nam Cao
2024-10-28 16:01   ` Sean Christopherson
2024-10-28 22:19     ` Thomas Gleixner
2024-10-30 18:05   ` Sean Christopherson
2024-10-28  7:29 ` [PATCH 05/21] can: bcm: Don't initialized an unused hrtimer Nam Cao
2024-10-30 10:49   ` Oliver Hartkopp
2024-10-30 12:15     ` Nam Cao
2024-10-30 14:51       ` Oliver Hartkopp
2024-10-30 15:01         ` Oliver Hartkopp
2024-10-30 15:18           ` Thomas Gleixner
2024-10-28  7:29 ` [PATCH 06/21] wifi: rt2x00: Remove redundant hrtimer_init() Nam Cao
2024-10-31 14:13   ` Kalle Valo
2024-10-28  7:29 ` [PATCH 07/21] io_uring: Remove redundant hrtimer's callback function setup Nam Cao
2024-10-28  7:29 ` [PATCH 08/21] hrtimers: Introduce hrtimer_setup() to replace hrtimer_init() Nam Cao
2024-10-28  7:29 ` [PATCH 09/21] hrtimers: Introduce hrtimer_setup_on_stack() Nam Cao
2024-10-28  7:29 ` [PATCH 10/21] hrtimers: Introduce hrtimer_setup_sleeper_on_stack() Nam Cao
2024-10-28  7:29 ` [PATCH 11/21] hrtimers: Introduce hrtimer_update_function() Nam Cao
2024-10-28  7:29 ` [PATCH 12/21] fs/aio: Switch to use hrtimer_setup_sleeper_on_stack() Nam Cao
2024-10-28  7:29 ` [PATCH 13/21] futex: " Nam Cao
2024-10-28  7:29 ` [PATCH 14/21] net: pktgen: " Nam Cao
2024-10-28  7:29 ` [PATCH 15/21] timers: " Nam Cao
2024-10-28  7:29 ` [PATCH 16/21] wait: " Nam Cao
2024-10-28  7:29 ` [PATCH 17/21] hrtimers: Delete hrtimer_init_sleeper_on_stack() Nam Cao
2024-10-28  7:29 ` [PATCH 18/21] sched/idle: Switch to use hrtimer_setup_on_stack() Nam Cao
2024-10-28  9:09   ` Peter Zijlstra
2024-10-28 10:50     ` Thomas Gleixner
2024-10-28 10:58       ` Peter Zijlstra
2024-10-28 22:33         ` Thomas Gleixner
2024-10-28  7:29 ` [PATCH 19/21] io_uring: " Nam Cao
2024-10-28  7:29 ` [PATCH 20/21] alarmtimer: Switch to use hrtimer_setup() and hrtimer_setup_on_stack() Nam Cao
2024-10-28  7:29 ` [PATCH 21/21] hrtimers: Delete hrtimer_init_on_stack() Nam Cao
2024-10-28 16:05 ` [PATCH 00/21] hrtimers: Switch to new hrtimer interface functions (1/5) Sean Christopherson
2024-10-29  8:15   ` Thomas Gleixner

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.1729864615.git.namcao@linutronix.de \
    --to=namcao@linutronix.de \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=anna-maria@linutronix.de \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=frederic@kernel.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=jstultz@google.com \
    --cc=kees@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kvalo@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=seanjc@google.com \
    --cc=socketcan@hartkopp.net \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.