All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] core-parking: fix build with gcc12 and NR_CPUS=1
@ 2022-09-09 10:18 Jan Beulich
  2022-09-09 11:00 ` Julien Grall
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Beulich @ 2022-09-09 10:18 UTC (permalink / raw)
  To: xen-devel@lists.xenproject.org
  Cc: Andrew Cooper, George Dunlap, Julien Grall, Stefano Stabellini,
	Wei Liu

Gcc12 takes issue with core_parking_remove()'s

    for ( ; i < cur_idle_nums; ++i )
        core_parking_cpunum[i] = core_parking_cpunum[i + 1];

complaining that the right hand side array access is past the bounds of
1. Clearly the compiler can't know that cur_idle_nums can only ever be
zero in this case (as the sole CPU cannot be parked).

Beyond addressing the immediate issue also adjust core_parking_init():
There's no point registering any policy when there's no CPU to park.
Since this still doesn't result in the compiler spotting that
core_parking_policy is never written (and hence is continuously NULL),
also amend core_parking_helper() to avoid eventual similar issues there
(minimizing generated code at the same time).

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/common/core_parking.c
+++ b/xen/common/core_parking.c
@@ -175,7 +175,7 @@ long cf_check core_parking_helper(void *
     unsigned int cpu;
     int ret = 0;
 
-    if ( !core_parking_policy )
+    if ( !core_parking_policy || CONFIG_NR_CPUS == 1 )
         return -EINVAL;
 
     while ( cur_idle_nums < idle_nums )
@@ -213,8 +213,9 @@ long cf_check core_parking_helper(void *
 
 bool core_parking_remove(unsigned int cpu)
 {
-    unsigned int i;
     bool found = false;
+#if CONFIG_NR_CPUS > 1
+    unsigned int i;
 
     spin_lock(&accounting_lock);
 
@@ -230,6 +231,7 @@ bool core_parking_remove(unsigned int cp
         core_parking_cpunum[i] = core_parking_cpunum[i + 1];
 
     spin_unlock(&accounting_lock);
+#endif /* CONFIG_NR_CPUS > 1 */
 
     return found;
 }
@@ -260,9 +262,11 @@ static int __init register_core_parking_
 
 static int __init cf_check core_parking_init(void)
 {
-    int ret = 0;
+    int ret;
 
-    if ( core_parking_controller == PERFORMANCE_FIRST )
+    if ( CONFIG_NR_CPUS == 1 )
+        ret = 0;
+    else if ( core_parking_controller == PERFORMANCE_FIRST )
         ret = register_core_parking_policy(&performance_first);
     else
         ret = register_core_parking_policy(&power_first);


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-09 14:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-09 10:18 [PATCH] core-parking: fix build with gcc12 and NR_CPUS=1 Jan Beulich
2022-09-09 11:00 ` Julien Grall
2022-09-09 12:14   ` Jan Beulich
2022-09-09 12:27     ` Julien Grall
2022-09-09 14:21       ` Jan Beulich

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.