From patchwork Fri Feb 3 13:50:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 52500 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp850225wrn; Fri, 3 Feb 2023 05:56:09 -0800 (PST) X-Google-Smtp-Source: AK7set9BApNfI8C4/FqBmJzI+PBaWcO6Alp54+zzhPcC0hxXWH5yz2ZInYw0DCOU2ZMcFgxHMBhZ X-Received: by 2002:a50:d593:0:b0:4a2:51db:c7d2 with SMTP id v19-20020a50d593000000b004a251dbc7d2mr10439762edi.15.1675432569507; Fri, 03 Feb 2023 05:56:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675432569; cv=none; d=google.com; s=arc-20160816; b=OHylnISgokqzou8p9sRZCVN9QzXJjChvhvw7QXAPb5YBAFt/2iUTSjuJ0PZ6ZyUZiF 2VNSzqb8UORb5TYyEyZfuxkS3IEEcqzaFu5eZcKkdZrFU3avrrWhikGE5+Puq1S3pLNj g7+LfBgko+lrz0Fpupl48gUYZHMWFO0IKzAlI/6vTCSbdWzX+T3mlDJFqV2LdMOX1GJU 0EyoioPg9thsmfpjhyNISQe3UISSUd3ULTDZwEg+UhR/e3rGv2gfkUSZABB6rKHiD5qX awWYGv9wqjdv/bEEkVGG2Sdb1OLwhuEyt1gLdc87p2Sm3I1G/nsF9o5H30tNzwhlVtYd X9zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=v499N77At2WrgDP0E4q+JKfQ0NOVJNGCg7lbB/rVzTI=; b=b95t2So3J01MfEYsN++KrDl1CY/X1IjkXQTmk0Ylkgvzk50ERT/o7NIj3f9EoTlc36 yDUrsVBfDnyoisC4L4iuolT1asM4f294FxRMFd4Opp1wI86S+IYiEu7lP+B5hTRtCwrY 5fxC71FFjrKizTIKc7CC9SpAodOlf1AgFpdTR54Jypc6WinaCs3K3ytXnbHAL5IMbxbe hhhdcl7J5Ri6NLRlyQ35yfqk7gvThs+bheCpLnff5kx7fknEZCvmTIIF2YcbxZYxUHYy 6JrWbSTsvTOZuBMHxNZ8Tq5gF59g+tpvW8cYn9S644S5n8Sx7nG5a0HlQfNA2LciC4rQ Msiw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z18-20020aa7c652000000b004a2662a697bsi2442488edr.493.2023.02.03.05.55.45; Fri, 03 Feb 2023 05:56:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233217AbjBCNwv (ORCPT + 99 others); Fri, 3 Feb 2023 08:52:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233083AbjBCNwX (ORCPT ); Fri, 3 Feb 2023 08:52:23 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AB7B29EE12; Fri, 3 Feb 2023 05:52:09 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A0F021596; Fri, 3 Feb 2023 05:52:51 -0800 (PST) Received: from eglon.cambridge.arm.com (eglon.cambridge.arm.com [10.1.196.177]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D2BF83F71E; Fri, 3 Feb 2023 05:52:05 -0800 (PST) From: James Morse To: linux-pm@vger.kernel.org, loongarch@lists.linux.dev, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org Cc: Marc Zyngier , Thomas Gleixner , Lorenzo Pieralisi , Mark Rutland , Sudeep Holla , Borislav Petkov , H Peter Anvin , Dave Hansen , Ingo Molnar , Will Deacon , Catalin Marinas , Huacai Chen , James Morse , Suzuki K Poulose , Oliver Upton , Len Brown , Rafael Wysocki , WANG Xuerui , Salil Mehta , Russell King , Jean-Philippe Brucker Subject: [RFC PATCH 04/32] drivers: base: Allow parts of GENERIC_CPU_DEVICES to be overridden Date: Fri, 3 Feb 2023 13:50:15 +0000 Message-Id: <20230203135043.409192-5-james.morse@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230203135043.409192-1-james.morse@arm.com> References: <20230203135043.409192-1-james.morse@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756818382042526151?= X-GMAIL-MSGID: =?utf-8?q?1756818382042526151?= 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 more architectures to use GENERIC_CPU_DEVICES, wrap the call as a __weak arch_register_cpu(). This aligns with the way x86, ia64 and loongarch register hotplug CPUs when they become present. ACPI's acpi_processor.c also has a __weak version of this symbol because arm64 doesn't define one. The duplicate __weak definitions are only a problem if arm64 selects GENERIC_CPU_DEVICES without defining one. This gets fixed up in later patches. Signed-off-by: James Morse --- arch/ia64/include/asm/cpu.h | 1 - arch/loongarch/include/asm/cpu.h | 1 - arch/x86/include/asm/cpu.h | 1 - drivers/base/cpu.c | 14 ++++++++++---- include/linux/cpu.h | 5 +++++ 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/arch/ia64/include/asm/cpu.h b/arch/ia64/include/asm/cpu.h index db125df9e088..a3e690e685e5 100644 --- a/arch/ia64/include/asm/cpu.h +++ b/arch/ia64/include/asm/cpu.h @@ -16,7 +16,6 @@ DECLARE_PER_CPU(struct ia64_cpu, cpu_devices); DECLARE_PER_CPU(int, cpu_state); #ifdef CONFIG_HOTPLUG_CPU -extern int arch_register_cpu(int num); extern void arch_unregister_cpu(int); #endif diff --git a/arch/loongarch/include/asm/cpu.h b/arch/loongarch/include/asm/cpu.h index da79862ff1f3..1e2c7c61dbea 100644 --- a/arch/loongarch/include/asm/cpu.h +++ b/arch/loongarch/include/asm/cpu.h @@ -126,7 +126,6 @@ enum cpu_type_enum { #if !defined(__ASSEMBLY__) #ifdef CONFIG_HOTPLUG_CPU -extern int arch_register_cpu(int num); extern void arch_unregister_cpu(int); #endif #endif /* ! __ASSEMBLY__ */ diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h index 78796b98a544..a0a62ac00e88 100644 --- a/arch/x86/include/asm/cpu.h +++ b/arch/x86/include/asm/cpu.h @@ -28,7 +28,6 @@ struct x86_cpu { }; #ifdef CONFIG_HOTPLUG_CPU -extern int arch_register_cpu(int num); extern void arch_unregister_cpu(int); extern void start_cpu0(void); #ifdef CONFIG_DEBUG_HOTPLUG_CPU0 diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index cf6407c34ede..178936533d87 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -492,19 +492,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 314802f98b9d..86e79e702325 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -75,12 +75,17 @@ extern __printf(4, 5) struct device *cpu_device_create(struct device *parent, void *drvdata, const struct attribute_group **groups, const char *fmt, ...); +extern int arch_register_cpu(int cpu); #ifdef CONFIG_HOTPLUG_CPU extern void unregister_cpu(struct cpu *cpu); 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