From: Jan Beulich Date: Tue, 2 Mar 2021 11:29:16 +0000 (+0100) Subject: sched: fix build when NR_CPUS == 1 X-Git-Tag: archive/raspbian/4.16.0+51-g0941d6cb-1+rpi1~2^2~42^2~846 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2de43f834ad2d758dd7b3441a6d1398491f18eae;p=xen.git sched: fix build when NR_CPUS == 1 In this case the compiler is recognizing that no valid array indexes remain, and hence e.g. reports: core.c: In function 'cpu_schedule_up': core.c:2769:19: error: array subscript 1 is above array bounds of 'struct vcpu *[1]' [-Werror=array-bounds] 2769 | if ( idle_vcpu[cpu] == NULL ) | ~~~~~~~~~^~~~~ Reported-by: Connor Davis Signed-off-by: Jan Beulich Reviewed-by: Dario Faggioli Release-Acked-by: Ian Jackson --- diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c index 2b974fd6f8..6d34764d38 100644 --- a/xen/common/sched/core.c +++ b/xen/common/sched/core.c @@ -2768,6 +2768,12 @@ static int cpu_schedule_up(unsigned int cpu) if ( cpu == 0 ) return 0; + /* + * Guard in particular against the compiler suspecting out-of-bounds + * array accesses below when NR_CPUS=1. + */ + BUG_ON(cpu >= NR_CPUS); + if ( idle_vcpu[cpu] == NULL ) vcpu_create(idle_vcpu[0]->domain, cpu); else