[PATCHv2 2/4] x86/apic: record capped cpu in generic_processor_info()
From: Pingfan Liu
Date: Mon Aug 26 2019 - 23:03:07 EST
No matter the cpu is capped by nr_cpus option, recording the mapping
between all cpus' id and apic id
Later this mapping will be used by BSP to sent SIPI to bring capped cpu to
stable state
Signed-off-by: Pingfan Liu <kernelfans@xxxxxxxxx>
To: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
To: Andy Lutomirski <luto@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Borislav Petkov <bp@xxxxxxxxx>
Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
Cc: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
To: x86@xxxxxxxxxx
Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
Cc: Qian Cai <cai@xxxxxx>
Cc: Vlastimil Babka <vbabka@xxxxxxx>
Cc: Daniel Drake <drake@xxxxxxxxxxxx>
Cc: Jacob Pan <jacob.jun.pan@xxxxxxxxxxxxxxx>
Cc: Michal Hocko <mhocko@xxxxxxxx>
Cc: Eric Biederman <ebiederm@xxxxxxxxxxxx>
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: Dave Young <dyoung@xxxxxxxxxx>
Cc: Baoquan He <bhe@xxxxxxxxxx>
Cc: kexec@xxxxxxxxxxxxxxxxxxx
---
arch/x86/include/asm/smp.h | 2 ++
arch/x86/kernel/apic/apic.c | 21 +++++++++++++++------
arch/x86/kernel/cpu/common.c | 4 ++++
3 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index e1356a3..5f63399 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -196,5 +196,7 @@ extern void nmi_selftest(void);
#define nmi_selftest() do { } while (0)
#endif
+extern struct cpumask *cpu_capped_mask;
+
#endif /* __ASSEMBLY__ */
#endif /* _ASM_X86_SMP_H */
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index f4f603a..6a57bad3 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -2296,9 +2296,10 @@ static int allocate_logical_cpuid(int apicid)
int generic_processor_info(int apicid, int version)
{
- int cpu, max = nr_cpu_ids;
+ int thiscpu, cpu, max = nr_cpu_ids;
bool boot_cpu_detected = physid_isset(boot_cpu_physical_apicid,
phys_cpu_present_map);
+ bool capped = false;
/*
* boot_cpu_physical_apicid is designed to have the apicid
@@ -2322,7 +2323,7 @@ int generic_processor_info(int apicid, int version)
if (disabled_cpu_apicid != BAD_APICID &&
disabled_cpu_apicid != read_apic_id() &&
disabled_cpu_apicid == apicid) {
- int thiscpu = num_processors + disabled_cpus;
+ thiscpu = num_processors + disabled_cpus;
pr_warning("APIC: Disabling requested cpu."
" Processor %d/0x%x ignored.\n",
@@ -2338,7 +2339,7 @@ int generic_processor_info(int apicid, int version)
*/
if (!boot_cpu_detected && num_processors >= nr_cpu_ids - 1 &&
apicid != boot_cpu_physical_apicid) {
- int thiscpu = max + disabled_cpus - 1;
+ thiscpu = max + disabled_cpus - 1;
pr_warning(
"APIC: NR_CPUS/possible_cpus limit of %i almost"
@@ -2346,20 +2347,28 @@ int generic_processor_info(int apicid, int version)
" Processor %d/0x%x ignored.\n", max, thiscpu, apicid);
disabled_cpus++;
- return -EINVAL;
+ capped = true;
}
if (num_processors >= nr_cpu_ids) {
- int thiscpu = max + disabled_cpus;
+ thiscpu = max + disabled_cpus;
pr_warning("APIC: NR_CPUS/possible_cpus limit of %i "
"reached. Processor %d/0x%x ignored.\n",
max, thiscpu, apicid);
disabled_cpus++;
- return -EINVAL;
+ capped = true;
}
+ if (capped) {
+ /* record the mapping between capped cpu and apicid */
+ if (thiscpu < NR_CPUS && cpu_capped_mask != NULL) {
+ cpuid_to_apicid[thiscpu] = apicid;
+ cpumask_set_cpu(thiscpu, cpu_capped_mask);
+ }
+ return -EINVAL;
+ }
if (apicid == boot_cpu_physical_apicid) {
/*
* x86_bios_cpu_apicid is required to have processors listed
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 1147217..b95721e 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -66,6 +66,9 @@ u32 elf_hwcap2 __read_mostly;
cpumask_var_t cpu_initialized_mask;
cpumask_var_t cpu_callout_mask;
cpumask_var_t cpu_callin_mask;
+/* size of NR_CPUS is required. */
+static struct cpumask __cpu_capped_mask __initdata;
+struct cpumask *cpu_capped_mask;
/* representing cpus for which sibling maps can be computed */
cpumask_var_t cpu_sibling_setup_mask;
@@ -84,6 +87,7 @@ void __init setup_cpu_local_masks(void)
alloc_bootmem_cpumask_var(&cpu_callin_mask);
alloc_bootmem_cpumask_var(&cpu_callout_mask);
alloc_bootmem_cpumask_var(&cpu_sibling_setup_mask);
+ cpu_capped_mask = &__cpu_capped_mask;
}
static void default_init(struct cpuinfo_x86 *c)
--
2.7.5