From patchwork Wed Nov 2 07:47:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 14063 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3470118wru; Wed, 2 Nov 2022 00:53:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4o7cVmu/RsvuVmzol5m3nByX8DM2Oqazy2qYdISrVjhcHBtqSxe6UvoH7ubxPItJsmMIDD X-Received: by 2002:a17:906:5a4b:b0:7ad:ba84:faf0 with SMTP id my11-20020a1709065a4b00b007adba84faf0mr18722287ejc.753.1667375607306; Wed, 02 Nov 2022 00:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667375607; cv=none; d=google.com; s=arc-20160816; b=lHsTqu6IGPufOfO1vwwSRzDwYtkIphb5DHdEdJUcQ0m4EMY9OJhHGNWSkDCD52NZA6 0Ngblg+wdyuyd5GyDxADJW3kPem91rBynqWW3zdSdE2mqV1GHqLuTzK953XF2hxtVmgi SoSusX87UpcbovRg+Uq0u792Ched7gKF18PgvDtPOZm0wR8v0yZY+Fg4BNkaz5kyln++ qnoDkbWxUsp9EdQ2DdYiaA03Y4lzM1tkuTD16KoNNaeWxzbX1ov3YCNHgCtYl4X+bwh2 tVXA/mpnGEwUcBYky9THlfOeY+mM1POFPYjPMKsu/nHOWgYASBctVjms0Y4ODp2JlkWg 93IA== 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 :dkim-signature; bh=8mPWpLwJy7yzhex6eU7j5tLklymwcAzwe+PPdkowDuM=; b=DZLmZNUGcZXiiEWfmam57qmRam+17CiR/62g9ZZvdtcY6Pr8OzN59qO9T/Qr2WnpQG nwDBB1VRON3aZHKL5yD0VTP5JU5n4K/a0aFEGA6gzT8b2hdYhv+I64WkmftEmRZ4WG7G EyXmKaZRVrDfSr/RNjaQF8ZsNk+aRPCzH5T4NOUksja1pXHEAYn1W/eaaaXFnAW9dMIQ 2cHUyxjdhup+NMgeLpXDDoEIf9gTcZhyF6/bM7cBJ/mgZ2i+fY9g27cYjzC7tj2ssJ7N 5LA00PcTCoeir44H1c4DPTovOKJgDM5I4w1U1y6MA6IzSycQItFE2sdss3zcGsUlAjdO eCGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=jK+xtRHu; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g8-20020a056402090800b0045f5118c39fsi17251595edz.367.2022.11.02.00.53.03; Wed, 02 Nov 2022 00:53:27 -0700 (PDT) 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; dkim=pass header.i=@suse.com header.s=susede1 header.b=jK+xtRHu; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230520AbiKBHtI (ORCPT + 99 others); Wed, 2 Nov 2022 03:49:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230502AbiKBHsi (ORCPT ); Wed, 2 Nov 2022 03:48:38 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CB2D275E7 for ; Wed, 2 Nov 2022 00:48:36 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 236111F8D0; Wed, 2 Nov 2022 07:48:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667375315; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8mPWpLwJy7yzhex6eU7j5tLklymwcAzwe+PPdkowDuM=; b=jK+xtRHuGxgvIkpvOFSz7r4XQb0A4BZmX2KszjLMCulWag7FTQL5eJPNj8vloNmCtmUGAR VD6ozlxoai+mtixWWex89re4ODBn3w+t6Si82LwdfzTxwfv9MLOyQuOKiL0IJmCbI0saFh neFoGFASCrsQr0TiitJCiVMjDmtHjd8= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CDD681376E; Wed, 2 Nov 2022 07:48:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id VZ/XMNIgYmNIcwAAMHmgww (envelope-from ); Wed, 02 Nov 2022 07:48:34 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Juergen Gross , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH v5 14/16] x86: switch cache_ap_init() to hotplug callback Date: Wed, 2 Nov 2022 08:47:11 +0100 Message-Id: <20221102074713.21493-15-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221102074713.21493-1-jgross@suse.com> References: <20221102074713.21493-1-jgross@suse.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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?1748370045243228663?= X-GMAIL-MSGID: =?utf-8?q?1748370045243228663?= Instead of explicitly calling cache_ap_init() in identify_secondary_cpu() use a CPU hotplug callback instead. By registering the callback only after having started the non-boot CPUs and initializing cache_aps_delayed_init with "true", calling set_cache_aps_delayed_init() at boot time can be dropped. It should be noted that this change results in cache_ap_init() being called a little bit later when hotplugging CPUs. By using a new hotplug slot right at the start of the low level bringup this is not problematic, as no operations requiring a specific caching mode are performed that early in CPU initialization. Suggested-by: Borislav Petkov Signed-off-by: Juergen Gross --- V4: - new patch --- arch/x86/include/asm/cacheinfo.h | 1 - arch/x86/kernel/cpu/cacheinfo.c | 18 +++++++++++++++--- arch/x86/kernel/cpu/common.c | 1 - arch/x86/kernel/smpboot.c | 2 -- include/linux/cpuhotplug.h | 1 + 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/cacheinfo.h b/arch/x86/include/asm/cacheinfo.h index a0ef46e9f453..ce9685fc78d8 100644 --- a/arch/x86/include/asm/cacheinfo.h +++ b/arch/x86/include/asm/cacheinfo.h @@ -16,7 +16,6 @@ void set_cache_aps_delayed_init(bool val); bool get_cache_aps_delayed_init(void); void cache_bp_init(void); void cache_bp_restore(void); -void cache_ap_init(void); void cache_aps_init(void); #endif /* _ASM_X86_CACHEINFO_H */ diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c index 1aaf830254df..231cf1ff0641 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -1139,7 +1140,7 @@ static void cache_cpu_init(void) local_irq_restore(flags); } -static bool cache_aps_delayed_init; +static bool cache_aps_delayed_init = true; void set_cache_aps_delayed_init(bool val) { @@ -1174,10 +1175,10 @@ void cache_bp_restore(void) cache_cpu_init(); } -void cache_ap_init(void) +static int cache_ap_init(unsigned int cpu) { if (!memory_caching_control || get_cache_aps_delayed_init()) - return; + return 0; /* * Ideally we should hold mtrr_mutex here to avoid MTRR entries @@ -1194,6 +1195,8 @@ void cache_ap_init(void) */ stop_machine_from_inactive_cpu(cache_rendezvous_handler, NULL, cpu_callout_mask); + + return 0; } /* @@ -1207,3 +1210,12 @@ void cache_aps_init(void) stop_machine(cache_rendezvous_handler, NULL, cpu_online_mask); set_cache_aps_delayed_init(false); } + +static int __init cache_ap_register(void) +{ + cpuhp_setup_state_nocalls(CPUHP_AP_CACHECTRL_STARTING, + "x86/cachectrl:starting", + cache_ap_init, NULL); + return 0; +} +core_initcall(cache_ap_register); diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index fd058b547f8d..bf4ac1cb93d7 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1949,7 +1949,6 @@ void identify_secondary_cpu(struct cpuinfo_x86 *c) #ifdef CONFIG_X86_32 enable_sep_cpu(); #endif - cache_ap_init(); validate_apic_and_package_id(c); x86_spec_ctrl_setup_ap(); update_srbds_msr(); diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 1b61a480c966..82b311c718bc 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1429,8 +1429,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus) uv_system_init(); - set_cache_aps_delayed_init(true); - smp_quirk_init_udelay(); speculative_store_bypass_ht_init(); diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index f61447913db9..0d277b4b025a 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -140,6 +140,7 @@ enum cpuhp_state { */ CPUHP_AP_IDLE_DEAD, CPUHP_AP_OFFLINE, + CPUHP_AP_CACHECTRL_STARTING, CPUHP_AP_SCHED_STARTING, CPUHP_AP_RCUTREE_DYING, CPUHP_AP_CPU_PM_STARTING,