linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frederic Weisbecker <frederic@kernel.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Marco Elver <elver@google.com>,
	syzbot <syzbot+3b14b2ed9b3d06dcaa07@syzkaller.appspotmail.com>,
	linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com,
	Anna-Maria Behnsen <anna-maria@linutronix.de>,
	Jacob Keller <jacob.e.keller@intel.com>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: Re: [PATCH] posix-cpu-timers: Implement the missing timer_wait_running callback
Date: Tue, 18 Apr 2023 18:44:50 +0200	[thread overview]
Message-ID: <ZD7JAppWQCoBEBgN@localhost.localdomain> (raw)
In-Reply-To: <87zg764ojw.ffs@tglx>

Le Mon, Apr 17, 2023 at 03:37:55PM +0200, Thomas Gleixner a écrit :
>  struct cpu_timer {
>  	struct timerqueue_node	node;
> @@ -72,6 +74,7 @@ struct cpu_timer {
>  	struct pid		*pid;
>  	struct list_head	elist;
>  	int			firing;
> +	struct task_struct	*handling;

I guess it can be made __rcu

>  };
>  
>  static inline bool cpu_timer_enqueue(struct timerqueue_head *head,
> @@ -846,6 +846,8 @@ static u64 collect_timerqueue(struct tim
>  			return expires;
>  
>  		ctmr->firing = 1;
> +		/* See posix_cpu_timer_wait_running() */
> +		WRITE_ONCE(ctmr->handling, current);

That can be rcu_assign_pointer()

>  		cpu_timer_dequeue(ctmr);
>  		list_add_tail(&ctmr->elist, firing);
>  	}
> @@ -1161,7 +1163,49 @@ static void handle_posix_cpu_timers(stru
> +static void posix_cpu_timer_wait_running(struct k_itimer *timr)
> +{
> +	struct task_struct *tsk = READ_ONCE(timr->it.cpu.handling);

And rcu_dereference()

> +
> +	/* Has the handling task completed expiry already? */
> +	if (!tsk)
> +		return;
> +
> +	/* Ensure that the task cannot go away */
> +	get_task_struct(tsk);
> +	/* Now drop the RCU protection so the mutex can be locked */
> +	rcu_read_unlock();
> +	/* Wait on the expiry mutex */
> +	mutex_lock(&tsk->posix_cputimers_work.mutex);
> +	/* Release it immediately again. */
> +	mutex_unlock(&tsk->posix_cputimers_work.mutex);
> +	/* Drop the task reference. */
> +	put_task_struct(tsk);
> +	/* Relock RCU so the callsite is balanced */
> +	rcu_read_lock();
> +}
> @@ -1363,6 +1420,8 @@ static void handle_posix_cpu_timers(stru
>  		 */
>  		if (likely(cpu_firing >= 0))
>  			cpu_timer_fire(timer);
> +		/* See posix_cpu_timer_wait_running() */
> +		WRITE_ONCE(timer->it.cpu.handling, NULL);

And rcu_assign_pointer()

Aside the boring details:

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>

  parent reply	other threads:[~2023-04-18 16:45 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-31 17:07 WARNING in timer_wait_running syzbot
2023-04-05 21:07 ` Marco Elver
2023-04-05 22:19   ` Frederic Weisbecker
2023-04-06 19:37     ` Thomas Gleixner
2023-04-07  8:44       ` Thomas Gleixner
2023-04-07 11:50         ` Frederic Weisbecker
2023-04-07 17:47           ` Thomas Gleixner
2023-04-07 18:36             ` Frederic Weisbecker
2023-04-07 19:27               ` Thomas Gleixner
2023-04-07 21:00                 ` Frederic Weisbecker
2023-04-11 14:31                 ` Marco Elver
2023-04-17 13:37                   ` [PATCH] posix-cpu-timers: Implement the missing timer_wait_running callback Thomas Gleixner
2023-04-17 15:34                     ` Sebastian Andrzej Siewior
2023-04-18  6:00                     ` Marco Elver
2023-04-18 16:44                     ` Frederic Weisbecker [this message]
2023-04-19  7:33                       ` Thomas Gleixner
2023-04-19  8:33                     ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2023-04-20  7:51                     ` tip-bot2 for Thomas Gleixner
2023-04-21 13:43                     ` tip-bot2 for Thomas Gleixner
     [not found] ` <20230407134620.1034-1-hdanton@sina.com>
2023-04-07 14:49   ` WARNING in timer_wait_running Frederic Weisbecker

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=ZD7JAppWQCoBEBgN@localhost.localdomain \
    --to=frederic@kernel.org \
    --cc=anna-maria@linutronix.de \
    --cc=bigeasy@linutronix.de \
    --cc=elver@google.com \
    --cc=jacob.e.keller@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=syzbot+3b14b2ed9b3d06dcaa07@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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;
as well as URLs for NNTP newsgroup(s).