All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <frederic@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: linux-tip-commits@vger.kernel.org,
	Anna-Maria Behnsen <anna-maria@linutronix.de>,
	Thomas Gleixner <tglx@linutronix.de>,
	x86@kernel.org
Subject: Re: [tip: timers/urgent] timers/migration: Move hierarchy setup into cpuhotplug prepare callback
Date: Mon, 22 Jul 2024 15:16:20 +0200	[thread overview]
Message-ID: <Zp5bpLJHlYsZinGj@localhost.localdomain> (raw)
In-Reply-To: <172141237277.2215.9152426860884348584.tip-bot2@tip-bot2>

Le Fri, Jul 19, 2024 at 06:06:12PM -0000, tip-bot2 for Anna-Maria Behnsen a écrit :
> @@ -1661,80 +1728,39 @@ static int tmigr_add_cpu(unsigned int cpu)
>  	return ret;
>  }
>  
> -static int tmigr_cpu_online(unsigned int cpu)
> -{
> -	struct tmigr_cpu *tmc = this_cpu_ptr(&tmigr_cpu);
> -	int ret;
> -
> -	/* First online attempt? Initialize CPU data */
> -	if (!tmc->tmgroup) {
> -		raw_spin_lock_init(&tmc->lock);
> -
> -		ret = tmigr_add_cpu(cpu);
> -		if (ret < 0)
> -			return ret;
> -
> -		if (tmc->childmask == 0)
> -			return -EINVAL;
> -
> -		timerqueue_init(&tmc->cpuevt.nextevt);
> -		tmc->cpuevt.nextevt.expires = KTIME_MAX;
> -		tmc->cpuevt.ignore = true;
> -		tmc->cpuevt.cpu = cpu;
> -
> -		tmc->remote = false;
> -		WRITE_ONCE(tmc->wakeup, KTIME_MAX);
> -	}
> -	raw_spin_lock_irq(&tmc->lock);
> -	trace_tmigr_cpu_online(tmc);
> -	tmc->idle = timer_base_is_idle();
> -	if (!tmc->idle)
> -		__tmigr_cpu_activate(tmc);
> -	tmc->online = true;
> -	raw_spin_unlock_irq(&tmc->lock);
> -	return 0;
> -}
> -
> -/*
> - * tmigr_trigger_active() - trigger a CPU to become active again
> - *
> - * This function is executed on a CPU which is part of cpu_online_mask, when the
> - * last active CPU in the hierarchy is offlining. With this, it is ensured that
> - * the other CPU is active and takes over the migrator duty.
> - */
> -static long tmigr_trigger_active(void *unused)
> +static int tmigr_cpu_prepare(unsigned int cpu)
>  {
> -	struct tmigr_cpu *tmc = this_cpu_ptr(&tmigr_cpu);
> -
> -	WARN_ON_ONCE(!tmc->online || tmc->idle);
> +	struct tmigr_cpu *tmc = per_cpu_ptr(&tmigr_cpu, cpu);
> +	int ret = 0;
>  
> -	return 0;
> -}
> +	/*
> +	 * The target CPU must never do the prepare work. Otherwise it may
> +	 * spuriously activate the old top level group inside the new one
> +	 * (nevertheless whether old top level group is active or not) and/or
> +	 * release an uninitialized childmask.
> +	 */
> +	WARN_ON_ONCE(cpu == raw_smp_processor_id());

Silly me! Who else than the boot CPU can do the prepare work for the
boot CPU?

This should be something like:

diff --git a/kernel/time/timer_migration.c b/kernel/time/timer_migration.c
index fae04950487f..8d57f7686bb0 100644
--- a/kernel/time/timer_migration.c
+++ b/kernel/time/timer_migration.c
@@ -1673,6 +1673,15 @@ static int tmigr_setup_groups(unsigned int cpu, unsigned int node)
 
 		lvllist = &tmigr_level_list[top];
 		if (group->num_children == 1 && list_is_singular(lvllist)) {
+			/*
+			 * The target CPU must never do the prepare work, except
+			 * on early boot when the boot CPU is the target. Otherwise
+			 * it may spuriously activate the old top level group inside
+			 * the new one (nevertheless whether old top level group is
+			 * active or not) and/or release an uninitialized childmask.
+			 */
+			WARN_ON_ONCE(cpu == raw_smp_processor_id());
+
 			lvllist = &tmigr_level_list[top - 1];
 			list_for_each_entry(child, lvllist, list) {
 				if (child->parent)
@@ -1705,14 +1714,6 @@ static int tmigr_cpu_prepare(unsigned int cpu)
 	struct tmigr_cpu *tmc = per_cpu_ptr(&tmigr_cpu, cpu);
 	int ret = 0;
 
-	/*
-	 * The target CPU must never do the prepare work. Otherwise it may
-	 * spuriously activate the old top level group inside the new one
-	 * (nevertheless whether old top level group is active or not) and/or
-	 * release an uninitialized childmask.
-	 */
-	WARN_ON_ONCE(cpu == raw_smp_processor_id());
-
 	/* Not first online attempt? */
 	if (tmc->tmgroup)
 		return ret;



  reply	other threads:[~2024-07-22 13:16 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-16 14:19 [PATCH v4 0/8] timers/migration: Fix three possible races and some improvements Anna-Maria Behnsen
2024-07-16 14:19 ` [PATCH v4 1/8] timers/migration: Do not rely always on group->parent Anna-Maria Behnsen
2024-07-19 18:06   ` [tip: timers/urgent] " tip-bot2 for Anna-Maria Behnsen
2024-07-22 19:35   ` tip-bot2 for Anna-Maria Behnsen
2024-07-16 14:19 ` [PATCH v4 2/8] timers/migration: Move hierarchy setup into cpuhotplug prepare callback Anna-Maria Behnsen
2024-07-16 23:01   ` Frederic Weisbecker
2024-07-17  9:49   ` [PATCH v5 " Anna-Maria Behnsen
2024-07-17 12:53     ` Frederic Weisbecker
2024-07-19 18:06     ` [tip: timers/urgent] " tip-bot2 for Anna-Maria Behnsen
2024-07-22 13:16       ` Frederic Weisbecker [this message]
2024-07-24 10:22         ` Borislav Petkov
2024-07-22 19:35     ` tip-bot2 for Anna-Maria Behnsen
2024-07-16 14:19 ` [PATCH v4 3/8] timers/migration: Improve tracing Anna-Maria Behnsen
2024-07-19 18:06   ` [tip: timers/urgent] " tip-bot2 for Anna-Maria Behnsen
2024-07-22 19:35   ` tip-bot2 for Anna-Maria Behnsen
2024-07-16 14:19 ` [PATCH v4 4/8] timers/migration: Use a single struct for hierarchy walk data Anna-Maria Behnsen
2024-07-19 18:06   ` [tip: timers/urgent] " tip-bot2 for Anna-Maria Behnsen
2024-07-22 19:35   ` tip-bot2 for Anna-Maria Behnsen
2024-07-16 14:19 ` [PATCH v4 5/8] timers/migration: Read childmask and parent pointer in a single place Anna-Maria Behnsen
2024-07-16 23:05   ` Frederic Weisbecker
2024-07-19 18:06   ` [tip: timers/urgent] " tip-bot2 for Anna-Maria Behnsen
2024-07-22 19:35   ` tip-bot2 for Anna-Maria Behnsen
2024-07-16 14:19 ` [PATCH v4 6/8] timers/migration: Rename childmask by groupmask to make naming more obvious Anna-Maria Behnsen
2024-07-16 23:10   ` Frederic Weisbecker
2024-07-19 18:06   ` [tip: timers/urgent] " tip-bot2 for Anna-Maria Behnsen
2024-07-22 19:35   ` tip-bot2 for Anna-Maria Behnsen
2024-07-16 14:19 ` [PATCH v4 7/8] timers/migration: Spare write when nothing changed Anna-Maria Behnsen
2024-07-19 18:06   ` [tip: timers/urgent] " tip-bot2 for Anna-Maria Behnsen
2024-07-22 19:35   ` tip-bot2 for Anna-Maria Behnsen
2024-07-16 14:19 ` [PATCH v4 8/8] timers/migration: Fix grammar in comment Anna-Maria Behnsen
2024-07-19 18:06   ` [tip: timers/urgent] " tip-bot2 for Anna-Maria Behnsen
2024-07-22 19:35   ` tip-bot2 for Anna-Maria Behnsen

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=Zp5bpLJHlYsZinGj@localhost.localdomain \
    --to=frederic@kernel.org \
    --cc=anna-maria@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --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.