From: Frederic Weisbecker <frederic@kernel.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
Anna-Maria Behnsen <anna-maria@linutronix.de>,
Benjamin Segall <bsegall@google.com>,
Eric Dumazet <edumazet@google.com>,
Andrey Vagin <avagin@openvz.org>,
Pavel Tikhomirov <ptikhomirov@virtuozzo.com>,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: [patch V2 04/17] posix-timers: Remove a few paranoid warnings
Date: Wed, 5 Mar 2025 23:11:18 +0100 [thread overview]
Message-ID: <Z8jMBqI0tuQBou4I@pavilion.home> (raw)
In-Reply-To: <20250302193627.167378648@linutronix.de>
Le Sun, Mar 02, 2025 at 08:36:49PM +0100, Thomas Gleixner a écrit :
> Warnings about a non-initialized timer or non-existing callbacks are just
> useful for implementing new posix clocks, but there a NULL pointer
> dereference is expected anyway. :)
>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
> V2: New patch
> ---
> kernel/time/posix-timers.c | 37 ++++++++-----------------------------
> 1 file changed, 8 insertions(+), 29 deletions(-)
>
> --- a/kernel/time/posix-timers.c
> +++ b/kernel/time/posix-timers.c
> @@ -675,7 +675,6 @@ void common_timer_get(struct k_itimer *t
>
> static int do_timer_gettime(timer_t timer_id, struct itimerspec64 *setting)
> {
> - const struct k_clock *kc;
> struct k_itimer *timr;
> unsigned long flags;
> int ret = 0;
> @@ -685,11 +684,7 @@ static int do_timer_gettime(timer_t time
> return -EINVAL;
>
> memset(setting, 0, sizeof(*setting));
> - kc = timr->kclock;
> - if (WARN_ON_ONCE(!kc || !kc->timer_get))
> - ret = -EINVAL;
> - else
> - kc->timer_get(timr, setting);
> + timr->kclock->timer_get(timr, setting);
>
> unlock_timer(timr, flags);
> return ret;
> @@ -817,7 +812,6 @@ static void common_timer_wait_running(st
> static struct k_itimer *timer_wait_running(struct k_itimer *timer,
> unsigned long *flags)
> {
> - const struct k_clock *kc = READ_ONCE(timer->kclock);
> timer_t timer_id = READ_ONCE(timer->it_id);
>
> /* Prevent kfree(timer) after dropping the lock */
> @@ -828,8 +822,7 @@ static struct k_itimer *timer_wait_runni
> * kc->timer_wait_running() might drop RCU lock. So @timer
> * cannot be touched anymore after the function returns!
> */
> - if (!WARN_ON_ONCE(!kc->timer_wait_running))
> - kc->timer_wait_running(timer);
> + timer->kclock->timer_wait_running(timer);
>
> rcu_read_unlock();
> /* Relock the timer. It might be not longer hashed. */
> @@ -892,7 +885,6 @@ static int do_timer_settime(timer_t time
> struct itimerspec64 *new_spec64,
> struct itimerspec64 *old_spec64)
> {
> - const struct k_clock *kc;
> struct k_itimer *timr;
> unsigned long flags;
> int error;
> @@ -915,11 +907,7 @@ static int do_timer_settime(timer_t time
> /* Prevent signal delivery and rearming. */
> timr->it_signal_seq++;
>
> - kc = timr->kclock;
> - if (WARN_ON_ONCE(!kc || !kc->timer_set))
> - error = -EINVAL;
> - else
> - error = kc->timer_set(timr, tmr_flags, new_spec64, old_spec64);
> + error = timr->kclock->timer_set(timr, tmr_flags, new_spec64, old_spec64);
>
> if (error == TIMER_RETRY) {
> // We already got the old time...
> @@ -1001,18 +989,6 @@ static inline void posix_timer_cleanup_i
> }
> }
>
> -static inline int timer_delete_hook(struct k_itimer *timer)
> -{
> - const struct k_clock *kc = timer->kclock;
> -
> - /* Prevent signal delivery and rearming. */
> - timer->it_signal_seq++;
> -
> - if (WARN_ON_ONCE(!kc || !kc->timer_del))
> - return -EINVAL;
> - return kc->timer_del(timer);
> -}
> -
> /* Delete a POSIX.1b interval timer. */
> SYSCALL_DEFINE1(timer_delete, timer_t, timer_id)
> {
> @@ -1025,7 +1001,10 @@ SYSCALL_DEFINE1(timer_delete, timer_t, t
> if (!timer)
> return -EINVAL;
>
> - if (unlikely(timer_delete_hook(timer) == TIMER_RETRY)) {
> + /* Prevent signal delivery and rearming. */
> + timer->it_signal_seq++;
> +
> + if (unlikely(timer->kclock->timer_del(timer) == TIMER_RETRY)) {
> /* Unlocks and relocks the timer if it still exists */
> timer = timer_wait_running(timer, &flags);
> goto retry_delete;
> @@ -1071,7 +1050,7 @@ static void itimer_delete(struct k_itime
> * mechanism. Worse, that timer mechanism might run the expiry
> * function concurrently.
> */
> - if (timer_delete_hook(timer) == TIMER_RETRY) {
> + if (timer->kclock->timer_del(timer) == TIMER_RETRY) {
And itimer_delete() doesn't need ->it_signal_seq++ since the task is exiting
and signals are going to be flushed anyway, right...
Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
> /*
> * Timer is expired concurrently, prevent livelocks
> * and pointless spinning on RT.
>
next prev parent reply other threads:[~2025-03-05 22:11 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-02 19:36 [patch V2 00/17] posix-timers: Rework the global hash table and provide a sane mechanism for CRIU Thomas Gleixner
2025-03-02 19:36 ` [patch V2 01/17] posix-timers: Initialise timer before adding it to the hash table Thomas Gleixner
2025-03-05 17:25 ` Frederic Weisbecker
2025-03-06 8:10 ` Thomas Gleixner
2025-03-06 8:47 ` Frederic Weisbecker
2025-03-07 13:46 ` Frederic Weisbecker
2025-03-02 19:36 ` [patch V2 02/17] posix-timers: Add cond_resched() to posix_timer_add() search loop Thomas Gleixner
2025-03-05 20:54 ` Frederic Weisbecker
2025-03-02 19:36 ` [patch V2 03/17] posix-timers: Cleanup includes Thomas Gleixner
2025-03-05 20:57 ` Frederic Weisbecker
2025-03-02 19:36 ` [patch V2 04/17] posix-timers: Remove a few paranoid warnings Thomas Gleixner
2025-03-05 22:11 ` Frederic Weisbecker [this message]
2025-03-02 19:36 ` [patch V2 05/17] posix-timers: Remove SLAB_PANIC from kmem cache Thomas Gleixner
2025-03-07 14:05 ` Frederic Weisbecker
2025-03-02 19:36 ` [patch V2 06/17] posix-timers: Use guards in a few places Thomas Gleixner
2025-03-07 14:16 ` Frederic Weisbecker
2025-03-02 19:36 ` [patch V2 07/17] posix-timers: Simplify lock/unlock_timer() Thomas Gleixner
2025-03-07 22:16 ` Frederic Weisbecker
2025-03-02 19:36 ` [patch V2 08/17] posix-timers: Rework timer removal Thomas Gleixner
2025-03-04 10:10 ` Pavel Tikhomirov
2025-03-04 10:20 ` Pavel Tikhomirov
2025-03-04 14:06 ` Thomas Gleixner
2025-03-07 23:03 ` Frederic Weisbecker
2025-03-08 8:34 ` Thomas Gleixner
2025-03-08 22:48 ` Frederic Weisbecker
2025-03-09 8:21 ` Thomas Gleixner
2025-03-02 19:36 ` [patch V2 09/17] posix-timers: Make lock_timer() use guard() Thomas Gleixner
2025-03-04 14:08 ` [patch V2a " Thomas Gleixner
2025-03-02 19:36 ` [patch V2 10/17] posix-timers: Make signal_struct::next_posix_timer_id an atomic_t Thomas Gleixner
2025-03-03 20:21 ` Cyrill Gorcunov
2025-03-03 21:24 ` Thomas Gleixner
2025-03-04 17:56 ` Cyrill Gorcunov
2025-03-04 20:30 ` Thomas Gleixner
2025-03-04 22:16 ` Cyrill Gorcunov
2025-03-05 7:31 ` Thomas Gleixner
2025-03-05 8:28 ` Cyrill Gorcunov
2025-03-02 19:37 ` [patch V2 11/17] posix-timers: Improve hash table performance Thomas Gleixner
2025-03-02 19:37 ` [patch V2 12/17] posix-timers: Switch to jhash32() Thomas Gleixner
2025-03-02 19:37 ` [patch V2 13/17] posix-timers: Avoid false cacheline sharing Thomas Gleixner
2025-03-02 19:37 ` [patch V2 14/17] posix-timers: Make per process list RCU safe Thomas Gleixner
2025-03-02 19:37 ` [patch V2 15/17] posix-timers: Dont iterate /proc/$PID/timers with sighand::siglock held Thomas Gleixner
2025-03-02 19:37 ` [patch V2 16/17] posix-timers: Provide a mechanism to allocate a given timer ID Thomas Gleixner
2025-03-02 19:37 ` [patch V2 17/17] selftests/timers/posix-timers: Add a test for exact allocation mode 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=Z8jMBqI0tuQBou4I@pavilion.home \
--to=frederic@kernel.org \
--cc=anna-maria@linutronix.de \
--cc=avagin@openvz.org \
--cc=bsegall@google.com \
--cc=edumazet@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=ptikhomirov@virtuozzo.com \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®