This series aims to switch most architectures over to using generic CPU devices rather than arch specific implementations.
James Morse (16): ACPI: scan: Use the acpi_device_is_present() helper in more places ACPI: scan: Rename acpi_scan_device_not_present() to be about enumeration arm64, irqchip/gic-v3, ACPI: Move MADT GICC enabled check into a helper arch_topology: Make register_cpu_capacity_sysctl() tolerant to late CPUs x86: intel_epb: Don't rely on link order ACPI: Move ACPI_HOTPLUG_CPU to be disabled on arm64 and riscv drivers: base: Use present CPUs in GENERIC_CPU_DEVICES drivers: base: Allow parts of GENERIC_CPU_DEVICES to be overridden drivers: base: Implement weak arch_unregister_cpu() drivers: base: Move cpu_dev_init() after node_dev_init() drivers: base: Print a warning instead of panic() when register_cpu() fails arm64: setup: Switch over to GENERIC_CPU_DEVICES using arch_register_cpu() x86/topology: Switch over to GENERIC_CPU_DEVICES LoongArch: Switch over to GENERIC_CPU_DEVICES LoongArch: Use the __weak version of arch_unregister_cpu() riscv: Switch over to GENERIC_CPU_DEVICES
Russell King (Oracle) (8): x86/topology: remove arch_*register_cpu() exports Loongarch: remove arch_*register_cpu() exports drivers: base: add arch_cpu_is_hotpluggable() arm64: convert to arch_cpu_is_hotpluggable() x86/topology: use weak version of arch_unregister_cpu() x86/topology: convert to use arch_cpu_is_hotpluggable() LoongArch: convert to use arch_cpu_is_hotpluggable() riscv: convert to use arch_cpu_is_hotpluggable()
arch/arm64/Kconfig | 1 + arch/arm64/include/asm/cpu.h | 1 - arch/arm64/kernel/setup.c | 13 ++-------- arch/arm64/kernel/smp.c | 2 +- arch/loongarch/Kconfig | 2 ++ arch/loongarch/kernel/topology.c | 42 ++------------------------------ arch/riscv/Kconfig | 1 + arch/riscv/kernel/setup.c | 18 ++------------ arch/x86/Kconfig | 2 ++ arch/x86/include/asm/cpu.h | 4 --- arch/x86/kernel/cpu/intel_epb.c | 2 +- arch/x86/kernel/topology.c | 33 ++----------------------- drivers/acpi/Kconfig | 1 - drivers/acpi/acpi_processor.c | 18 -------------- drivers/acpi/processor_core.c | 2 +- drivers/acpi/scan.c | 12 ++++----- drivers/base/arch_topology.c | 38 ++++++++++++++++++++--------- drivers/base/cpu.c | 39 +++++++++++++++++++++++------ drivers/base/init.c | 2 +- drivers/irqchip/irq-gic-v3.c | 10 +++----- include/linux/acpi.h | 5 ++++ include/linux/cpu.h | 5 ++++ 22 files changed, 95 insertions(+), 158 deletions(-)
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.7-rc1 commit b5bdb60faaaff11bcfc9a90372158bc56e7ff544 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
acpi_device_is_present() checks the present or functional bits from the cached copy of _STA.
A few places open-code this check. Use the helper instead to improve readability.
Signed-off-by: James Morse james.morse@arm.com Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: Russell King (Oracle) rmk+kernel@armlinux.org.uk Reviewed-by: Miguel Luis miguel.luis@oracle.com Signed-off-by: Rafael J. Wysocki rafael.j.wysocki@intel.com Signed-off-by: liwei liwei728@huawei.com --- drivers/acpi/scan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 1d249d0f61ae..81f4b5a9949c 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -304,7 +304,7 @@ static int acpi_scan_device_check(struct acpi_device *adev) int error;
acpi_bus_get_status(adev); - if (adev->status.present || adev->status.functional) { + if (acpi_device_is_present(adev)) { /* * This function is only called for device objects for which * matching scan handlers exist. The only situation in which @@ -338,7 +338,7 @@ static int acpi_scan_bus_check(struct acpi_device *adev, void *not_used) int error;
acpi_bus_get_status(adev); - if (!(adev->status.present || adev->status.functional)) { + if (!acpi_device_is_present(adev)) { acpi_scan_device_not_present(adev); return 0; }
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.7-rc1 commit 8c6fdbd635d4afbcd57243083319a55624d2e168 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
acpi_scan_device_not_present() is called when a device in the hierarchy is not available for enumeration. Historically enumeration was only based on whether the device was present.
To add support for only enumerating devices that are both present and enabled, this helper should be renamed. It was only ever about enumeration, rename it acpi_scan_device_not_enumerated().
No change in behaviour is intended.
Signed-off-by: James Morse james.morse@arm.com Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: Russell King (Oracle) rmk+kernel@armlinux.org.uk Reviewed-by: Miguel Luis miguel.luis@oracle.com Signed-off-by: Rafael J. Wysocki rafael.j.wysocki@intel.com Signed-off-by: liwei liwei728@huawei.com --- drivers/acpi/scan.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 81f4b5a9949c..083467e81415 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -289,10 +289,10 @@ static int acpi_scan_hot_remove(struct acpi_device *device) return 0; }
-static int acpi_scan_device_not_present(struct acpi_device *adev) +static int acpi_scan_device_not_enumerated(struct acpi_device *adev) { if (!acpi_device_enumerated(adev)) { - dev_warn(&adev->dev, "Still not present\n"); + dev_warn(&adev->dev, "Still not enumerated\n"); return -EALREADY; } acpi_bus_trim(adev); @@ -327,7 +327,7 @@ static int acpi_scan_device_check(struct acpi_device *adev) error = -ENODEV; } } else { - error = acpi_scan_device_not_present(adev); + error = acpi_scan_device_not_enumerated(adev); } return error; } @@ -339,7 +339,7 @@ static int acpi_scan_bus_check(struct acpi_device *adev, void *not_used)
acpi_bus_get_status(adev); if (!acpi_device_is_present(adev)) { - acpi_scan_device_not_present(adev); + acpi_scan_device_not_enumerated(adev); return 0; } if (handler && handler->hotplug.scan_dependent)
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.7-rc1 commit c54e52f84d7aa590e90e1f73f462517ac40051e1 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
ACPI, irqchip and the architecture code all inspect the MADT enabled bit for a GICC entry in the MADT.
The addition of an 'online capable' bit means all these sites need updating.
Move the current checks behind a helper to make future updates easier.
Signed-off-by: James Morse james.morse@arm.com Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Acked-by: "Rafael J. Wysocki" rafael.j.wysocki@intel.com Reviewed-by: Sudeep Holla sudeep.holla@arm.com Link: https://lore.kernel.org/r/E1quv5D-00AeNJ-U8@rmk-PC.armlinux.org.uk Signed-off-by: Catalin Marinas catalin.marinas@arm.com Signed-off-by: liwei liwei728@huawei.com --- arch/arm64/kernel/smp.c | 2 +- drivers/acpi/processor_core.c | 2 +- drivers/irqchip/irq-gic-v3.c | 10 ++++------ include/linux/acpi.h | 5 +++++ 4 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 8288549ca5f7..0874834d33ec 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -521,7 +521,7 @@ acpi_map_gic_cpu_interface(struct acpi_madt_generic_interrupt *processor) { u64 hwid = processor->arm_mpidr;
- if (!(processor->flags & ACPI_MADT_ENABLED)) { + if (!acpi_gicc_is_usable(processor)) { pr_debug("skipping disabled CPU entry with 0x%llx MPIDR\n", hwid); return; } diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c index 7dd6dbaa98c3..b203cfe28550 100644 --- a/drivers/acpi/processor_core.c +++ b/drivers/acpi/processor_core.c @@ -90,7 +90,7 @@ static int map_gicc_mpidr(struct acpi_subtable_header *entry, struct acpi_madt_generic_interrupt *gicc = container_of(entry, struct acpi_madt_generic_interrupt, header);
- if (!(gicc->flags & ACPI_MADT_ENABLED)) + if (!acpi_gicc_is_usable(gicc)) return -ENODEV;
/* device_declaration means Device object in DSDT, in the diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c index 874fbc4a2da6..515cbb53dada 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -2393,8 +2393,7 @@ gic_acpi_parse_madt_gicc(union acpi_subtable_headers *header, u32 size = reg == GIC_PIDR2_ARCH_GICv4 ? SZ_64K * 4 : SZ_64K * 2; void __iomem *redist_base;
- /* GICC entry which has !ACPI_MADT_ENABLED is not unusable so skip */ - if (!(gicc->flags & ACPI_MADT_ENABLED)) + if (!acpi_gicc_is_usable(gicc)) return 0;
redist_base = ioremap(gicc->gicr_base_address, size); @@ -2444,7 +2443,7 @@ static int __init gic_acpi_match_gicc(union acpi_subtable_headers *header, * If GICC is enabled and has valid gicr base address, then it means * GICR base is presented via GICC */ - if ((gicc->flags & ACPI_MADT_ENABLED) && gicc->gicr_base_address) { + if (acpi_gicc_is_usable(gicc) && gicc->gicr_base_address) { acpi_data.enabled_rdists++; return 0; } @@ -2453,7 +2452,7 @@ static int __init gic_acpi_match_gicc(union acpi_subtable_headers *header, * It's perfectly valid firmware can pass disabled GICC entry, driver * should not treat as errors, skip the entry instead of probe fail. */ - if (!(gicc->flags & ACPI_MADT_ENABLED)) + if (!acpi_gicc_is_usable(gicc)) return 0;
return -ENODEV; @@ -2512,8 +2511,7 @@ static int __init gic_acpi_parse_virt_madt_gicc(union acpi_subtable_headers *hea int maint_irq_mode; static int first_madt = true;
- /* Skip unusable CPUs */ - if (!(gicc->flags & ACPI_MADT_ENABLED)) + if (!acpi_gicc_is_usable(gicc)) return 0;
maint_irq_mode = (gicc->flags & ACPI_MADT_VGIC_IRQ_MODE) ? diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 1c2bb14975af..b51ecc2619a0 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -256,6 +256,11 @@ acpi_table_parse_cedt(enum acpi_cedt_type id, int acpi_parse_mcfg (struct acpi_table_header *header); void acpi_table_print_madt_entry (struct acpi_subtable_header *madt);
+static inline bool acpi_gicc_is_usable(struct acpi_madt_generic_interrupt *gicc) +{ + return gicc->flags & ACPI_MADT_ENABLED; +} + /* the following numa functions are architecture-dependent */ void acpi_numa_slit_init (struct acpi_table_slit *slit);
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.8-rc1 commit c72bbf200162a3b4b9e1baedec9008d8d710b427 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
register_cpu_capacity_sysctl() adds a property to sysfs that describes the CPUs capacity. This is done from a subsys_initcall() that assumes all possible CPUs are registered.
With CPU hotplug, possible CPUs aren't registered until they become present, (or for arm64 enabled). This leads to messages during boot: | register_cpu_capacity_sysctl: too early to get CPU1 device! and once these CPUs are added to the system, the file is missing.
Move this to a cpuhp callback, so that the file is created once CPUs are brought online. This covers CPUs that are added late by mechanisms like hotplug. One observable difference is the file is now missing for offline CPUs.
Signed-off-by: James Morse james.morse@arm.com Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R2g-00CsyV-Ss@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- drivers/base/arch_topology.c | 38 ++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-)
diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index b741b5ba82bd..9ccb7daee78e 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -220,20 +220,34 @@ static DECLARE_WORK(update_topology_flags_work, update_topology_flags_workfn);
static DEVICE_ATTR_RO(cpu_capacity);
-static int register_cpu_capacity_sysctl(void) +static int cpu_capacity_sysctl_add(unsigned int cpu) { - int i; - struct device *cpu; + struct device *cpu_dev = get_cpu_device(cpu);
- for_each_possible_cpu(i) { - cpu = get_cpu_device(i); - if (!cpu) { - pr_err("%s: too early to get CPU%d device!\n", - __func__, i); - continue; - } - device_create_file(cpu, &dev_attr_cpu_capacity); - } + if (!cpu_dev) + return -ENOENT; + + device_create_file(cpu_dev, &dev_attr_cpu_capacity); + + return 0; +} + +static int cpu_capacity_sysctl_remove(unsigned int cpu) +{ + struct device *cpu_dev = get_cpu_device(cpu); + + if (!cpu_dev) + return -ENOENT; + + device_remove_file(cpu_dev, &dev_attr_cpu_capacity); + + return 0; +} + +static int register_cpu_capacity_sysctl(void) +{ + cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "topology/cpu-capacity", + cpu_capacity_sysctl_add, cpu_capacity_sysctl_remove);
return 0; }
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.8-rc1 commit d87c49377d5bbf3f5e5729c67f3892e1d2e6f661 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
intel_epb_init() is called as a subsys_initcall() to register cpuhp callbacks. The callbacks make use of get_cpu_device() which will return NULL unless register_cpu() has been called. register_cpu() is called from topology_init(), which is also a subsys_initcall().
This is fragile. Moving the register_cpu() to a different subsys_initcall() leads to a NULL dereference during boot.
Make intel_epb_init() a late_initcall(), user-space can't provide a policy before this point anyway.
Signed-off-by: James Morse james.morse@arm.com Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Acked-by: "Rafael J. Wysocki" rafael.j.wysocki@intel.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R2m-00Csyb-2S@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- arch/x86/kernel/cpu/intel_epb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/cpu/intel_epb.c b/arch/x86/kernel/cpu/intel_epb.c index e4c3ba91321c..f18d35fe27a9 100644 --- a/arch/x86/kernel/cpu/intel_epb.c +++ b/arch/x86/kernel/cpu/intel_epb.c @@ -237,4 +237,4 @@ static __init int intel_epb_init(void) cpuhp_remove_state(CPUHP_AP_X86_INTEL_EPB_ONLINE); return ret; } -subsys_initcall(intel_epb_init); +late_initcall(intel_epb_init);
From: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk
mainline inclusion from mainline-v6.8-rc1 commit 9aa9b4fcc311ede18adfe55e721115f7c59e60be category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
arch_register_cpu() and arch_unregister_cpu() are not used by anything that can be a module - they are used by drivers/base/cpu.c and drivers/acpi/acpi_processor.c, neither of which can be a module.
Remove the exports.
Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R2r-00Csyh-7B@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- arch/x86/kernel/topology.c | 2 -- 1 file changed, 2 deletions(-)
diff --git a/arch/x86/kernel/topology.c b/arch/x86/kernel/topology.c index 0bab03130033..fcb62cfdf946 100644 --- a/arch/x86/kernel/topology.c +++ b/arch/x86/kernel/topology.c @@ -45,13 +45,11 @@ int arch_register_cpu(int cpu) xc->cpu.hotpluggable = cpu > 0; return register_cpu(&xc->cpu, cpu); } -EXPORT_SYMBOL(arch_register_cpu);
void arch_unregister_cpu(int num) { unregister_cpu(&per_cpu(cpu_devices, num).cpu); } -EXPORT_SYMBOL(arch_unregister_cpu); #else /* CONFIG_HOTPLUG_CPU */
int __init arch_register_cpu(int num)
From: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk
mainline inclusion from mainline-v6.8-rc1 commit 29d93102fd1e19024fce90995040fb3a46fd91c1 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
arch_register_cpu() and arch_unregister_cpu() are not used by anything that can be a module - they are used by drivers/base/cpu.c and drivers/acpi/acpi_processor.c, neither of which can be a module.
Remove the exports.
Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R2w-00Csyn-E2@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- arch/loongarch/kernel/topology.c | 2 -- 1 file changed, 2 deletions(-)
diff --git a/arch/loongarch/kernel/topology.c b/arch/loongarch/kernel/topology.c index 3fd166006698..ae860fe81536 100644 --- a/arch/loongarch/kernel/topology.c +++ b/arch/loongarch/kernel/topology.c @@ -25,7 +25,6 @@ int arch_register_cpu(int cpu)
return ret; } -EXPORT_SYMBOL(arch_register_cpu);
void arch_unregister_cpu(int cpu) { @@ -34,7 +33,6 @@ void arch_unregister_cpu(int cpu) c->hotpluggable = 0; unregister_cpu(c); } -EXPORT_SYMBOL(arch_unregister_cpu); #endif
static int __init topology_init(void)
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.8-rc1 commit a02f66bb3cf475947b58dd3851b987b8ccd998c1 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
Neither arm64 nor riscv support physical hotadd of CPUs that were not present at boot. For arm64 much of the platform description is in static tables which do not have update methods. arm64 does support HOTPLUG_CPU, which is backed by a firmware interface to turn CPUs on and off.
acpi_processor_hotadd_init() and acpi_processor_remove() are for adding and removing CPUs that were not present at boot. arm64 systems that do this are not supported as there is currently insufficient information in the platform description. (e.g. did the GICR get removed too?)
arm64 currently relies on the MADT enabled flag check in map_gicc_mpidr() to prevent CPUs that were not described as present at boot from being added to the system. Similarly, riscv relies on the same check in map_rintc_hartid(). Both architectures also rely on the weak 'always fails' definitions of acpi_map_cpu() and arch_register_cpu().
Subsequent changes will redefine ACPI_HOTPLUG_CPU as making possible CPUs present. Neither arm64 nor riscv support this.
Disable ACPI_HOTPLUG_CPU for arm64 and riscv by removing 'default y' and selecting it on the other three ACPI architectures. This allows the weak definitions of some symbols to be removed.
Signed-off-by: James Morse james.morse@arm.com Reviewed-by: Shaoqin Huang shahuang@redhat.com Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R31-00Csyt-Jq@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- arch/loongarch/Kconfig | 1 + arch/x86/Kconfig | 1 + drivers/acpi/Kconfig | 1 - drivers/acpi/acpi_processor.c | 18 ------------------ 4 files changed, 2 insertions(+), 19 deletions(-)
diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index f74448967240..54e59e87141e 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -5,6 +5,7 @@ config LOONGARCH select ACPI select ACPI_GENERIC_GSI if ACPI select ACPI_MCFG if ACPI + select ACPI_HOTPLUG_CPU if ACPI_PROCESSOR && HOTPLUG_CPU select ACPI_PPTT if ACPI select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI select ARCH_BINFMT_ELF_STATE diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 9742c1a3c608..59a8b9176c27 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -60,6 +60,7 @@ config X86 # select ACPI_LEGACY_TABLES_LOOKUP if ACPI select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI + select ACPI_HOTPLUG_CPU if ACPI_PROCESSOR && HOTPLUG_CPU select ARCH_32BIT_OFF_T if X86_32 select ARCH_CLOCKSOURCE_INIT select ARCH_CORRECT_STACKTRACE_ON_KRETPROBE diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index cee82b473dc5..8456d48ba702 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -309,7 +309,6 @@ config ACPI_HOTPLUG_CPU bool depends on ACPI_PROCESSOR && HOTPLUG_CPU select ACPI_CONTAINER - default y
config ACPI_PROCESSOR_AGGREGATOR tristate "Processor Aggregator" diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c index 0f5218e361df..4fe2ef54088c 100644 --- a/drivers/acpi/acpi_processor.c +++ b/drivers/acpi/acpi_processor.c @@ -184,24 +184,6 @@ static void __init acpi_pcc_cpufreq_init(void) {}
/* Initialization */ #ifdef CONFIG_ACPI_HOTPLUG_CPU -int __weak acpi_map_cpu(acpi_handle handle, - phys_cpuid_t physid, u32 acpi_id, int *pcpu) -{ - return -ENODEV; -} - -int __weak acpi_unmap_cpu(int cpu) -{ - return -ENODEV; -} - -int __weak arch_register_cpu(int cpu) -{ - return -ENODEV; -} - -void __weak arch_unregister_cpu(int cpu) {} - static int acpi_processor_hotadd_init(struct acpi_processor *pr) { unsigned long long sta;
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.8-rc1 commit b0c69e1214bc20960c2ca68317b968e2a2057ed5 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
Three of the five ACPI architectures create sysfs entries using register_cpu() for present CPUs, whereas arm64, riscv and all GENERIC_CPU_DEVICES do this for possible CPUs.
Registering a CPU is what causes them to show up in sysfs.
It makes very little sense to register all possible CPUs. Registering a CPU is what triggers the udev notifications allowing user-space to react to newly added CPUs.
To allow all five ACPI architectures to use GENERIC_CPU_DEVICES, change it to use for_each_present_cpu().
Making the ACPI architectures use GENERIC_CPU_DEVICES is a pre-requisite step to centralise their register_cpu() logic, before moving it into the ACPI processor driver. When we add support for register CPUs from ACPI in a later patch, we will avoid registering CPUs in this path.
Of the ACPI architectures that register possible CPUs, arm64 and riscv do not support making possible CPUs present as they use the weak 'always fails' version of arch_register_cpu().
Only two of the eight architectures that use GENERIC_CPU_DEVICES have a distinction between present and possible CPUs.
The following architectures use GENERIC_CPU_DEVICES but are not SMP, so possible == present: * m68k * microblaze * nios2
The following architectures use GENERIC_CPU_DEVICES and consider possible == present: * csky: setup_smp() * processor_probe() sets possible for all CPUs and present for all CPUs except the boot cpu, which will have been done by init/main.c::start_kernel().
um appears to be a subarchitecture of x86.
The remaining architecture using GENERIC_CPU_DEVICES are: * openrisc and hexagon: where smp_init_cpus() makes all CPUs < NR_CPUS possible, whereas smp_prepare_cpus() only makes CPUs < setup_max_cpus present.
After this change, openrisc and hexagon systems that use the max_cpus command line argument would not see the other CPUs present in sysfs. This should not be a problem as these CPUs can't be brought online as _cpu_up() checks cpu_present().
After this change, only CPUs which are present appear in sysfs.
Signed-off-by: James Morse james.morse@arm.com Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R36-00Csz0-Px@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- drivers/base/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 548491de818e..13359712e069 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -533,7 +533,7 @@ static void __init cpu_dev_register_generic(void) #ifdef CONFIG_GENERIC_CPU_DEVICES int i;
- for_each_possible_cpu(i) { + for_each_present_cpu(i) { if (register_cpu(&per_cpu(cpu_devices, i), i)) panic("Failed to register CPU device"); }
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.8-rc1 commit 0949dd96dffec39683c6066cf8d0877cebc321ec category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
Architectures often have extra per-cpu work that needs doing before a CPU is registered, often to determine if a CPU is hotpluggable.
To allow the ACPI architectures to use GENERIC_CPU_DEVICES, move the cpu_register() call into arch_register_cpu(), which is made __weak so architectures with extra work can override it. This aligns with the way x86, ia64 and loongarch register hotplug CPUs when they become present.
Signed-off-by: James Morse james.morse@arm.com Reviewed-by: Shaoqin Huang shahuang@redhat.com Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R3B-00Csz6-Uh@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- drivers/base/cpu.c | 14 ++++++++++---- include/linux/cpu.h | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 13359712e069..22625695f310 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -525,19 +525,25 @@ bool cpu_is_hotpluggable(unsigned int cpu) EXPORT_SYMBOL_GPL(cpu_is_hotpluggable);
#ifdef CONFIG_GENERIC_CPU_DEVICES -static DEFINE_PER_CPU(struct cpu, cpu_devices); +DEFINE_PER_CPU(struct cpu, cpu_devices); + +int __weak arch_register_cpu(int cpu) +{ + return register_cpu(&per_cpu(cpu_devices, cpu), cpu); +} #endif
static void __init cpu_dev_register_generic(void) { -#ifdef CONFIG_GENERIC_CPU_DEVICES int i;
+ if (!IS_ENABLED(CONFIG_GENERIC_CPU_DEVICES)) + return; + for_each_present_cpu(i) { - if (register_cpu(&per_cpu(cpu_devices, i), i)) + if (arch_register_cpu(i)) panic("Failed to register CPU device"); } -#endif }
#ifdef CONFIG_GENERIC_CPU_VULNERABILITIES diff --git a/include/linux/cpu.h b/include/linux/cpu.h index eb768a866fe3..e117c06e0c6b 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -88,6 +88,10 @@ extern ssize_t arch_cpu_probe(const char *, size_t); extern ssize_t arch_cpu_release(const char *, size_t); #endif
+#ifdef CONFIG_GENERIC_CPU_DEVICES +DECLARE_PER_CPU(struct cpu, cpu_devices); +#endif + /* * These states are not related to the core CPU hotplug mechanism. They are * used by various (sub)architectures to track internal state
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.8-rc1 commit 866ec3008691ff205b171413c52c5f1f328a2f8b category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
Add arch_unregister_cpu() to allow the ACPI machinery to call unregister_cpu(). This is enough for arm64, riscv and loongarch, but needs to be overridden by x86 and ia64 who need to do more work.
CC: Jean-Philippe Brucker jean-philippe@linaro.org Signed-off-by: James Morse james.morse@arm.com Reviewed-by: Shaoqin Huang shahuang@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Gavin Shan gshan@redhat.com Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R3H-00CszC-2n@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- drivers/base/cpu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 22625695f310..d32f7937f954 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -531,7 +531,14 @@ int __weak arch_register_cpu(int cpu) { return register_cpu(&per_cpu(cpu_devices, cpu), cpu); } -#endif + +#ifdef CONFIG_HOTPLUG_CPU +void __weak arch_unregister_cpu(int num) +{ + unregister_cpu(&per_cpu(cpu_devices, num)); +} +#endif /* CONFIG_HOTPLUG_CPU */ +#endif /* CONFIG_GENERIC_CPU_DEVICES */
static void __init cpu_dev_register_generic(void) {
From: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk
mainline inclusion from mainline-v6.8-rc1 commit bb5e44fb3be685ecb3feb120aca4269a92cc84cf category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
The differences between architecture specific implementations of arch_register_cpu() are down to whether the CPU is hotpluggable or not. Rather than overriding the weak version of arch_register_cpu(), provide a function that can be used to provide this detail instead.
Reviewed-by: Shaoqin Huang shahuang@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Gavin Shan gshan@redhat.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R3M-00CszH-6r@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- drivers/base/cpu.c | 11 ++++++++++- include/linux/cpu.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index d32f7937f954..f12f3bc4a6ca 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -527,9 +527,18 @@ EXPORT_SYMBOL_GPL(cpu_is_hotpluggable); #ifdef CONFIG_GENERIC_CPU_DEVICES DEFINE_PER_CPU(struct cpu, cpu_devices);
+bool __weak arch_cpu_is_hotpluggable(int cpu) +{ + return false; +} + int __weak arch_register_cpu(int cpu) { - return register_cpu(&per_cpu(cpu_devices, cpu), cpu); + struct cpu *c = &per_cpu(cpu_devices, cpu); + + c->hotpluggable = arch_cpu_is_hotpluggable(cpu); + + return register_cpu(c, cpu); }
#ifdef CONFIG_HOTPLUG_CPU diff --git a/include/linux/cpu.h b/include/linux/cpu.h index e117c06e0c6b..875ef5863ff5 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -80,6 +80,7 @@ extern __printf(4, 5) struct device *cpu_device_create(struct device *parent, void *drvdata, const struct attribute_group **groups, const char *fmt, ...); +extern bool arch_cpu_is_hotpluggable(int cpu); extern int arch_register_cpu(int cpu); extern void arch_unregister_cpu(int cpu); #ifdef CONFIG_HOTPLUG_CPU
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.8-rc1 commit d631a881f1ab0091de35ae09ba48193a543666b5 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
NUMA systems require the node descriptions to be ready before CPUs are registered. This is so that the node symlinks can be created in sysfs.
Currently no NUMA platform uses GENERIC_CPU_DEVICES, meaning that CPUs are registered by arch code, instead of cpu_dev_init().
Move cpu_dev_init() after node_dev_init() so that NUMA architectures can use GENERIC_CPU_DEVICES.
Signed-off-by: James Morse james.morse@arm.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Gavin Shan gshan@redhat.com Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R3R-00CszO-C0@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- drivers/base/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/base/init.c b/drivers/base/init.c index 397eb9880cec..c4954835128c 100644 --- a/drivers/base/init.c +++ b/drivers/base/init.c @@ -35,8 +35,8 @@ void __init driver_init(void) of_core_init(); platform_bus_init(); auxiliary_bus_init(); - cpu_dev_init(); memory_dev_init(); node_dev_init(); + cpu_dev_init(); container_dev_init(); }
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.8-rc1 commit ca00f7d999a61383c3e5b2c66537a8e769dd7327 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
loongarch, mips, parisc, riscv and sh all print a warning if register_cpu() returns an error. Architectures that use GENERIC_CPU_DEVICES call panic() instead.
Errors in this path indicate something is wrong with the firmware description of the platform, but the kernel is able to keep running.
Downgrade this to a warning to make it easier to debug this issue.
This will allow architectures that switching over to GENERIC_CPU_DEVICES to drop their warning, but keep the existing behaviour.
Signed-off-by: James Morse james.morse@arm.com Reviewed-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Shaoqin Huang shahuang@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Gavin Shan gshan@redhat.com Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R3W-00CszU-GM@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- drivers/base/cpu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index f12f3bc4a6ca..47de0f140ba6 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -551,14 +551,15 @@ void __weak arch_unregister_cpu(int num)
static void __init cpu_dev_register_generic(void) { - int i; + int i, ret;
if (!IS_ENABLED(CONFIG_GENERIC_CPU_DEVICES)) return;
for_each_present_cpu(i) { - if (arch_register_cpu(i)) - panic("Failed to register CPU device"); + ret = arch_register_cpu(i); + if (ret) + pr_warn("register_cpu %d failed (%d)\n", i, ret); } }
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.8-rc1 commit d127db1a23c94a876557b5bf8ca8bea49e8debb6 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
To allow ACPI's _STA value to hide CPUs that are present, but not available to online right now due to VMM or firmware policy, the register_cpu() call needs to be made by the ACPI machinery when ACPI is in use. This allows it to hide CPUs that are unavailable from sysfs.
Switching to GENERIC_CPU_DEVICES is an intermediate step to allow all five ACPI architectures to be modified at once.
Switch over to GENERIC_CPU_DEVICES, and provide an arch_register_cpu() that populates the hotpluggable flag. arch_register_cpu() is also the interface the ACPI machinery expects.
The struct cpu in struct cpuinfo_arm64 is never used directly, remove it to use the one GENERIC_CPU_DEVICES provides.
This changes the CPUs visible in sysfs from possible to present, but on arm64 smp_prepare_cpus() ensures these are the same.
This patch also has the effect of moving the registration of CPUs from subsys to driver core initialisation, prior to any initcalls running.
Signed-off-by: James Morse james.morse@arm.com Reviewed-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Shaoqin Huang shahuang@redhat.com Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R3b-00Csza-Ku@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/cpu.h | 1 - arch/arm64/kernel/setup.c | 13 ++++--------- 3 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 9568049f36e3..604a63437751 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -133,6 +133,7 @@ config ARM64 select GENERIC_ARCH_TOPOLOGY select GENERIC_CLOCKEVENTS_BROADCAST select GENERIC_CPU_AUTOPROBE + select GENERIC_CPU_DEVICES select GENERIC_CPU_VULNERABILITIES select GENERIC_EARLY_IOREMAP select GENERIC_IDLE_POLL_SETUP diff --git a/arch/arm64/include/asm/cpu.h b/arch/arm64/include/asm/cpu.h index e749838b9c5d..887bd0d992bb 100644 --- a/arch/arm64/include/asm/cpu.h +++ b/arch/arm64/include/asm/cpu.h @@ -38,7 +38,6 @@ struct cpuinfo_32bit { };
struct cpuinfo_arm64 { - struct cpu cpu; struct kobject kobj; u64 reg_ctr; u64 reg_cntfrq; diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 645034e52496..7f661a89a51d 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -451,19 +451,14 @@ static inline bool cpu_can_disable(unsigned int cpu) return false; }
-static int __init topology_init(void) +int arch_register_cpu(int num) { - int i; + struct cpu *cpu = &per_cpu(cpu_devices, num);
- for_each_possible_cpu(i) { - struct cpu *cpu = &per_cpu(cpu_data.cpu, i); - cpu->hotpluggable = cpu_can_disable(i); - register_cpu(cpu, i); - } + cpu->hotpluggable = cpu_can_disable(num);
- return 0; + return register_cpu(cpu, num); } -subsys_initcall(topology_init);
static void dump_kernel_offset(void) {
From: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk
mainline inclusion from mainline-v6.8-rc1 commit 092cfbc6b51143fd216bd55f8811f427d2ef0a0f category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
Convert arm64 to use the arch_cpu_is_hotpluggable() helper rather than arch_register_cpu().
Reviewed-by: Shaoqin Huang shahuang@redhat.com Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R3g-00Cszg-PP@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- arch/arm64/kernel/setup.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 7f661a89a51d..95cb22c083c8 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -451,13 +451,9 @@ static inline bool cpu_can_disable(unsigned int cpu) return false; }
-int arch_register_cpu(int num) +bool arch_cpu_is_hotpluggable(int num) { - struct cpu *cpu = &per_cpu(cpu_devices, num); - - cpu->hotpluggable = cpu_can_disable(num); - - return register_cpu(cpu, num); + return cpu_can_disable(num); }
static void dump_kernel_offset(void)
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.8-rc1 commit 5b95f94c3b9f12adf27e970d411e8a744e95cabf category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
Now that GENERIC_CPU_DEVICES calls arch_register_cpu(), which can be overridden by the arch code, switch over to this to allow common code to choose when the register_cpu() call is made.
x86's struct cpus come from struct x86_cpu, which has no other members or users. Remove this and use the version defined by common code.
This is an intermediate step to the logic being moved to drivers/acpi, where GENERIC_CPU_DEVICES will do the work when booting with acpi=off.
This patch also has the effect of moving the registration of CPUs from subsys to driver core initialisation, prior to any initcalls running.
---- Changes since RFC: * Fixed the second copy of arch_register_cpu() used for non-hotplug Changes since RFC v2: * Remove duplicate of the weak generic arch_register_cpu(), spotted by Jonathan Cameron. Add note about initialisation order change. Changes since RFC v3: * Adapt to removal of EXPORT_SYMBOL()s
Signed-off-by: James Morse james.morse@arm.com Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R3l-00Cszm-UA@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- arch/x86/Kconfig | 1 + arch/x86/include/asm/cpu.h | 4 ---- arch/x86/kernel/topology.c | 27 ++++----------------------- 3 files changed, 5 insertions(+), 27 deletions(-)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 59a8b9176c27..e4059e24445c 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -148,6 +148,7 @@ config X86 select GENERIC_CLOCKEVENTS_MIN_ADJUST select GENERIC_CMOS_UPDATE select GENERIC_CPU_AUTOPROBE + select GENERIC_CPU_DEVICES select GENERIC_CPU_VULNERABILITIES select GENERIC_EARLY_IOREMAP select GENERIC_ENTRY diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h index 25050d953eee..91867a6a9f8e 100644 --- a/arch/x86/include/asm/cpu.h +++ b/arch/x86/include/asm/cpu.h @@ -23,10 +23,6 @@ static inline void prefill_possible_map(void) {}
#endif /* CONFIG_SMP */
-struct x86_cpu { - struct cpu cpu; -}; - #ifdef CONFIG_HOTPLUG_CPU extern void soft_restart_cpu(void); #endif diff --git a/arch/x86/kernel/topology.c b/arch/x86/kernel/topology.c index fcb62cfdf946..c2ed3145a93b 100644 --- a/arch/x86/kernel/topology.c +++ b/arch/x86/kernel/topology.c @@ -35,36 +35,17 @@ #include <asm/io_apic.h> #include <asm/cpu.h>
-static DEFINE_PER_CPU(struct x86_cpu, cpu_devices); - #ifdef CONFIG_HOTPLUG_CPU int arch_register_cpu(int cpu) { - struct x86_cpu *xc = per_cpu_ptr(&cpu_devices, cpu); + struct cpu *c = per_cpu_ptr(&cpu_devices, cpu);
- xc->cpu.hotpluggable = cpu > 0; - return register_cpu(&xc->cpu, cpu); + c->hotpluggable = cpu > 0; + return register_cpu(c, cpu); }
void arch_unregister_cpu(int num) { - unregister_cpu(&per_cpu(cpu_devices, num).cpu); -} -#else /* CONFIG_HOTPLUG_CPU */ - -int __init arch_register_cpu(int num) -{ - return register_cpu(&per_cpu(cpu_devices, num).cpu, num); + unregister_cpu(&per_cpu(cpu_devices, num)); } #endif /* CONFIG_HOTPLUG_CPU */ - -static int __init topology_init(void) -{ - int i; - - for_each_present_cpu(i) - arch_register_cpu(i); - - return 0; -} -subsys_initcall(topology_init);
From: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk
mainline inclusion from mainline-v6.8-rc1 commit b0b26bc580de555a504d7eed3866fca607bf1c1f category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
Since the x86 version of arch_unregister_cpu() is the same as the weak version, drop the x86 specific version.
Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R3r-00Cszs-2R@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- arch/x86/kernel/topology.c | 5 ----- 1 file changed, 5 deletions(-)
diff --git a/arch/x86/kernel/topology.c b/arch/x86/kernel/topology.c index c2ed3145a93b..211863cb5b81 100644 --- a/arch/x86/kernel/topology.c +++ b/arch/x86/kernel/topology.c @@ -43,9 +43,4 @@ int arch_register_cpu(int cpu) c->hotpluggable = cpu > 0; return register_cpu(c, cpu); } - -void arch_unregister_cpu(int num) -{ - unregister_cpu(&per_cpu(cpu_devices, num)); -} #endif /* CONFIG_HOTPLUG_CPU */
From: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk
mainline inclusion from mainline-v6.8-rc1 commit e850a5c406450ae040d09c7b4161d6e75eff2a25 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
Convert x86 to use the arch_cpu_is_hotpluggable() helper rather than arch_register_cpu().
Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R3w-00Cszy-6k@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- arch/x86/kernel/topology.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kernel/topology.c b/arch/x86/kernel/topology.c index 211863cb5b81..d42c28b8bfd8 100644 --- a/arch/x86/kernel/topology.c +++ b/arch/x86/kernel/topology.c @@ -36,11 +36,8 @@ #include <asm/cpu.h>
#ifdef CONFIG_HOTPLUG_CPU -int arch_register_cpu(int cpu) +bool arch_cpu_is_hotpluggable(int cpu) { - struct cpu *c = per_cpu_ptr(&cpu_devices, cpu); - - c->hotpluggable = cpu > 0; - return register_cpu(c, cpu); + return cpu > 0; } #endif /* CONFIG_HOTPLUG_CPU */
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.8-rc1 commit db3ba29a8315d89736b8af5c1ad945c9967d7655 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
Now that GENERIC_CPU_DEVICES calls arch_register_cpu(), which can be overridden by the arch code, switch over to this to allow common code to choose when the register_cpu() call is made.
This allows topology_init() to be removed.
This is an intermediate step to the logic being moved to drivers/acpi, where GENERIC_CPU_DEVICES will do the work when booting with acpi=off.
This is a subtle change. Originally: - on boot, topology_init() would have marked present CPUs that io_master() is true for as hotplug-incapable. - if a CPU is hotplugged that is an io_master(), it can later be hot-unplugged.
The new behaviour is that any CPU that io_master() is true for will now always be marked as hotplug-incapable, thus even if it was hotplugged, it can no longer be hot-unplugged.
This patch also has the effect of moving the registration of CPUs from subsys to driver core initialisation, prior to any initcalls running.
Signed-off-by: James Morse james.morse@arm.com Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R41-00Ct04-Bg@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- arch/loongarch/Kconfig | 1 + arch/loongarch/kernel/topology.c | 29 ++--------------------------- 2 files changed, 3 insertions(+), 27 deletions(-)
diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 54e59e87141e..12f5fcb630a7 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -72,6 +72,7 @@ config LOONGARCH select GENERIC_CLOCKEVENTS select GENERIC_CMOS_UPDATE select GENERIC_CPU_AUTOPROBE + select GENERIC_CPU_DEVICES select GENERIC_ENTRY select GENERIC_GETTIMEOFDAY select GENERIC_IOREMAP if !ARCH_IOREMAP diff --git a/arch/loongarch/kernel/topology.c b/arch/loongarch/kernel/topology.c index ae860fe81536..7dfb46c68f58 100644 --- a/arch/loongarch/kernel/topology.c +++ b/arch/loongarch/kernel/topology.c @@ -10,20 +10,13 @@
#include <acpi/processor.h>
-static DEFINE_PER_CPU(struct cpu, cpu_devices); - #ifdef CONFIG_HOTPLUG_CPU int arch_register_cpu(int cpu) { - int ret; struct cpu *c = &per_cpu(cpu_devices, cpu);
- c->hotpluggable = 1; - ret = register_cpu(c, cpu); - if (ret < 0) - pr_warn("register_cpu %d failed (%d)\n", cpu, ret); - - return ret; + c->hotpluggable = !io_master(cpu); + return register_cpu(c, cpu); }
void arch_unregister_cpu(int cpu) @@ -34,21 +27,3 @@ void arch_unregister_cpu(int cpu) unregister_cpu(c); } #endif - -static int __init topology_init(void) -{ - int i, ret; - - for_each_present_cpu(i) { - struct cpu *c = &per_cpu(cpu_devices, i); - - c->hotpluggable = !io_master(i); - ret = register_cpu(c, i); - if (ret < 0) - pr_warn("topology_init: register_cpu %d failed (%d)\n", i, ret); - } - - return 0; -} - -subsys_initcall(topology_init);
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.8-rc1 commit 0d122fb60046cd888877a6029cc23863d4a1b9e3 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
LoongArch provides its own arch_unregister_cpu(). This clears the hotpluggable flag, then unregisters the CPU.
It isn't necessary to clear the hotpluggable flag when unregistering a cpu. unregister_cpu() writes NULL to the percpu cpu_sys_devices pointer, meaning cpu_is_hotpluggable() will return false, as get_cpu_device() has returned NULL.
Remove arch_unregister_cpu() and use the __weak version.
Signed-off-by: James Morse james.morse@arm.com Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R46-00Ct0A-GJ@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- arch/loongarch/kernel/topology.c | 8 -------- 1 file changed, 8 deletions(-)
diff --git a/arch/loongarch/kernel/topology.c b/arch/loongarch/kernel/topology.c index 7dfb46c68f58..866c2c9ef6ab 100644 --- a/arch/loongarch/kernel/topology.c +++ b/arch/loongarch/kernel/topology.c @@ -18,12 +18,4 @@ int arch_register_cpu(int cpu) c->hotpluggable = !io_master(cpu); return register_cpu(c, cpu); } - -void arch_unregister_cpu(int cpu) -{ - struct cpu *c = &per_cpu(cpu_devices, cpu); - - c->hotpluggable = 0; - unregister_cpu(c); -} #endif
From: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk
mainline inclusion from mainline-v6.8-rc1 commit 13f9f0361c2e64f0dadb7964bfad11bf0a6fb7ab category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
Convert loongarch to use the arch_cpu_is_hotpluggable() helper rather than arch_register_cpu(). Also remove the export as nothing should be using arch_register_cpu() outside of the core kernel/acpi code.
Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R4B-00Ct0G-Kk@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- arch/loongarch/kernel/topology.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/arch/loongarch/kernel/topology.c b/arch/loongarch/kernel/topology.c index 866c2c9ef6ab..75d5c51a7cd3 100644 --- a/arch/loongarch/kernel/topology.c +++ b/arch/loongarch/kernel/topology.c @@ -11,11 +11,8 @@ #include <acpi/processor.h>
#ifdef CONFIG_HOTPLUG_CPU -int arch_register_cpu(int cpu) +bool arch_cpu_is_hotpluggable(int cpu) { - struct cpu *c = &per_cpu(cpu_devices, cpu); - - c->hotpluggable = !io_master(cpu); - return register_cpu(c, cpu); + return !io_master(cpu); } #endif
From: James Morse james.morse@arm.com
mainline inclusion from mainline-v6.8-rc1 commit 96cf2036514acec9bee7c25ca61badc64820d734 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
Now that GENERIC_CPU_DEVICES calls arch_register_cpu(), which can be overridden by the arch code, switch over to this to allow common code to choose when the register_cpu() call is made.
This allows topology_init() to be removed.
This is an intermediate step to the logic being moved to drivers/acpi, where GENERIC_CPU_DEVICES will do the work when booting with acpi=off.
This patch also has the effect of moving the registration of CPUs from subsys to driver core initialisation, prior to any initcalls running.
Signed-off-by: James Morse james.morse@arm.com Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Acked-by: Palmer Dabbelt palmer@rivosinc.com Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Samuel Holland samuel.holland@sifive.com Tested-by: Samuel Holland samuel.holland@sifive.com Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R4G-00Ct0M-PS@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- arch/riscv/Kconfig | 1 + arch/riscv/kernel/setup.c | 19 ++++--------------- 2 files changed, 5 insertions(+), 15 deletions(-)
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 9c48fecc6719..18646dee0f53 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -69,6 +69,7 @@ config RISCV select GENERIC_ARCH_TOPOLOGY select GENERIC_ATOMIC64 if !64BIT select GENERIC_CLOCKEVENTS_BROADCAST if SMP + select GENERIC_CPU_DEVICES select GENERIC_EARLY_IOREMAP select GENERIC_ENTRY select GENERIC_GETTIMEOFDAY if HAVE_GENERIC_VDSO diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index aac853ae4eb7..311e99741cf8 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -62,7 +62,6 @@ atomic_t hart_lottery __section(".sdata") #endif ; unsigned long boot_cpu_hartid; -static DEFINE_PER_CPU(struct cpu, cpu_devices);
/* * Place kernel memory regions on the resource tree so that @@ -307,23 +306,13 @@ void __init setup_arch(char **cmdline_p) riscv_set_dma_cache_alignment(); }
-static int __init topology_init(void) +int arch_register_cpu(int cpu) { - int i, ret; + struct cpu *c = &per_cpu(cpu_devices, cpu);
- for_each_possible_cpu(i) { - struct cpu *cpu = &per_cpu(cpu_devices, i); - - cpu->hotpluggable = cpu_has_hotplug(i); - ret = register_cpu(cpu, i); - if (unlikely(ret)) - pr_warn("Warning: %s: register_cpu %d failed (%d)\n", - __func__, i, ret); - } - - return 0; + c->hotpluggable = cpu_has_hotplug(cpu); + return register_cpu(c, cpu); } -subsys_initcall(topology_init);
void free_initmem(void) {
From: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk
mainline inclusion from mainline-v6.8-rc1 commit 00bf4641201092fc06aa51f7dcf45d1ea4d3d4f7 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8XMTL CVE: NA
----------------------------------
Convert riscv to use the arch_cpu_is_hotpluggable() helper rather than arch_register_cpu().
Acked-by: Palmer Dabbelt palmer@rivosinc.com Reviewed-by: Gavin Shan gshan@redhat.com Signed-off-by: "Russell King (Oracle)" rmk+kernel@armlinux.org.uk Reviewed-by: Jonathan Cameron Jonathan.Cameron@huawei.com Reviewed-by: Samuel Holland samuel.holland@sifive.com Tested-by: Samuel Holland samuel.holland@sifive.com # On HiFive Unmatched Reviewed-by: Thomas Gleixner tglx@linutronix.de Link: https://lore.kernel.org/r/E1r5R4L-00Ct0d-To@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: liwei liwei728@huawei.com --- arch/riscv/kernel/setup.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 311e99741cf8..cbe15b19a36a 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -306,12 +306,9 @@ void __init setup_arch(char **cmdline_p) riscv_set_dma_cache_alignment(); }
-int arch_register_cpu(int cpu) +bool arch_cpu_is_hotpluggable(int cpu) { - struct cpu *c = &per_cpu(cpu_devices, cpu); - - c->hotpluggable = cpu_has_hotplug(cpu); - return register_cpu(c, cpu); + return cpu_has_hotplug(cpu); }
void free_initmem(void)