On 09/15/2017 03:20 AM, Marc Zyngier wrote: > On Thu, Sep 14 2017 at 1:15:14 pm BST, zijun_hu <zijun...@zoho.com> wrote: >> From: zijun_hu <zijun...@htc.com> >> >> get_cpu_number() doesn't use existing helper to iterate over possible >> CPUs, so error happens in case of discontinuous @cpu_possible_mask >> such as 0b11110001. > > Do you have an example of such a situation? Your patch is definitely an > improvement, but I'd like to understand how you get there... > > Thanks, > > M. > a few conditions which maybe result in discontiguous @cpu_possible_mask are noticed and considered of by ARM64 init code as indicated by bellow code segments: in arch/arm64/kernel/smp.c : void __init smp_init_cpus(void) { ...... /* * We need to set the cpu_logical_map entries before enabling * the cpus so that cpu processor description entries (DT cpu nodes * and ACPI MADT entries) can be retrieved by matching the cpu hwid * with entries in cpu_logical_map while initializing the cpus. * If the cpu set-up fails, invalidate the cpu_logical_map entry. */ for (i = 1; i < nr_cpu_ids; i++) { if (cpu_logical_map(i) != INVALID_HWID) { if (smp_cpu_setup(i)) cpu_logical_map(i) = INVALID_HWID; } } ...... }
/* * Initialize cpu operations for a logical cpu and * set it in the possible mask on success */ static int __init smp_cpu_setup(int cpu) { if (cpu_read_ops(cpu)) return -ENODEV; if (cpu_ops[cpu]->cpu_init(cpu)) return -ENODEV; set_cpu_possible(cpu, true); return 0; } i browses GICv3 drivers code and notice that a little weird code segments