[PATCH v2] timer: fix NR_CPUS=1 build with gcc13

Jan Beulich posted 1 patch 7 months, 2 weeks ago
Failed in applying to current master (apply log)
[PATCH v2] timer: fix NR_CPUS=1 build with gcc13
Posted by Jan Beulich 7 months, 2 weeks ago
Gcc13 apparently infers from "if ( old_cpu < new_cpu )" that "new_cpu"
is >= 1, and then (on x86) complains about "per_cpu(timers, new_cpu)"
exceeding __per_cpu_offset[]'s bounds (being an array of 1 in such a
configuration). Make the code conditional upon there being at least 2
CPUs configured (otherwise there simply is nothing to migrate [to]).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
v2: Warn if it looks like an actual migration was (bogusly) requested.

--- a/xen/common/timer.c
+++ b/xen/common/timer.c
@@ -357,6 +357,7 @@ bool timer_expires_before(struct timer *
 void migrate_timer(struct timer *timer, unsigned int new_cpu)
 {
     unsigned int old_cpu;
+#if CONFIG_NR_CPUS > 1
     bool_t active;
     unsigned long flags;
 
@@ -404,6 +405,11 @@ void migrate_timer(struct timer *timer,
 
     spin_unlock(&per_cpu(timers, old_cpu).lock);
     spin_unlock_irqrestore(&per_cpu(timers, new_cpu).lock, flags);
+#else /* CONFIG_NR_CPUS == 1 */
+    old_cpu = read_atomic(&timer->cpu);
+    if ( old_cpu != TIMER_CPU_status_killed )
+        WARN_ON(new_cpu != old_cpu);
+#endif /* CONFIG_NR_CPUS */
 }
Re: [PATCH v2] timer: fix NR_CPUS=1 build with gcc13
Posted by George Dunlap 7 months, 2 weeks ago
On Thu, Sep 14, 2023 at 3:32 PM Jan Beulich <jbeulich@suse.com> wrote:
>
> Gcc13 apparently infers from "if ( old_cpu < new_cpu )" that "new_cpu"
> is >= 1, and then (on x86) complains about "per_cpu(timers, new_cpu)"
> exceeding __per_cpu_offset[]'s bounds (being an array of 1 in such a
> configuration). Make the code conditional upon there being at least 2
> CPUs configured (otherwise there simply is nothing to migrate [to]).
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

I would still have preferred the code be more robust for the NR_CPUS >
1 case, but this is an improvement, so in any case:

Acked-by: George Dunlap <george.dunlap@cloud.com>