Skip to content

Commit

Permalink
xen: fix for_each_cpu when NR_CPUS=1
Browse files Browse the repository at this point in the history
When running an hypervisor build with NR_CPUS=1 for_each_cpu does not
take into account whether the bit of the CPU is set or not in the
provided mask.

This means that whatever we have in the bodies of these loops is always
done once, even if the mask was empty and it should never be done. This
is clearly a bug and was in fact causing an assert to trigger in credit2
code.

Removing the special casing of NR_CPUS == 1 makes things work again.

Reported-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: Dario Faggioli <dfaggioli@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>
  • Loading branch information
dfaggioli authored and jbeulich committed Mar 12, 2021
1 parent 04181c6 commit aa50f45
Showing 1 changed file with 0 additions and 5 deletions.
5 changes: 0 additions & 5 deletions xen/include/xen/cpumask.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,10 @@ static inline void free_cpumask_var(cpumask_var_t mask)
#define FREE_CPUMASK_VAR(m) free_cpumask_var(m)
#endif

#if NR_CPUS > 1
#define for_each_cpu(cpu, mask) \
for ((cpu) = cpumask_first(mask); \
(cpu) < nr_cpu_ids; \
(cpu) = cpumask_next(cpu, mask))
#else /* NR_CPUS == 1 */
#define for_each_cpu(cpu, mask) \
for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)(mask))
#endif /* NR_CPUS */

/*
* The following particular system cpumasks and operations manage
Expand Down

0 comments on commit aa50f45

Please sign in to comment.