From patchwork Tue Feb 13 21:05:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 200638 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp813598dyb; Tue, 13 Feb 2024 13:17:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVPXpukN7Bv1Jhudv8aXnbmttB/QZfeasmK/1VlZE1FzZkh8cz1LhBxnLYmDaLZQEu5+E4M5sO3GUh70OFR6usgXW6Reg== X-Google-Smtp-Source: AGHT+IFEdUB0UkQu+r0PcJRSno/wuME9hJxu79tujqO2snYF1lM+jY16W+DX4Ao/PFRRTKVMS9E9 X-Received: by 2002:a05:6870:d889:b0:219:2e4e:f2b7 with SMTP id oe9-20020a056870d88900b002192e4ef2b7mr525841oac.55.1707859064073; Tue, 13 Feb 2024 13:17:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707859064; cv=pass; d=google.com; s=arc-20160816; b=e9fLLuWIu632nuuChbTfLWFlug+uHhdCry+DS6nwEzWU+OzH/pv+mAfTNGd+J9jLKw GTMnXsyaPalwC1TOONtz4xyFRn/MyTyplw8Xmo0XvCNI1mr2q0xHJNspKJL1fTTUYKNH L9RSJkDju5GsVuV78+8gJRadMhB0dKA7Bmbdil6i4I8XHDSEGxRBPwOP+K+s/Er1eh0a qDlV4f3CH0E3Z7XZIHqHaFfvB5cKPJg4xvSi29hFJDtFK6NQf+MamwJ5TAW5QaAMvUD/ VMGxsB4A6AclzTl9lroWN+6FDjKXviZtQl16Jxcij/KIr1Uz4uiSt2whuW8bXvzzWg8l O66Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=3hjSQJVEGCG5vViUjmCCOY+diMogglZD/H0kl7y0KTM=; fh=3WlXcYIgYZyR7II4OnF18TDO0AN1Wgq9+zXXMFST9pU=; b=0qq4C/TzSkevI5h4/EYIKCpdAJZqO36OD7BdIVJtxxGjX5u+n5H4Q4QI00BBuIbu0V U33fE4ipPaKQjpPVgSa3aOpqF8WzwUghAealvmY6QuOfEOjtGABntFwSD/ldKt38nFQ3 fN436pppjthy/GGD/zM7prWrRwmbjMr5xvOmA6ONF9MVMJiKptHmORcRxZRSRDcAwJ6h RQwSMrBPPTnsSPjiH5mi4pgBNOAs7Ng1f1mfy4KludFszynaxXivT384z5PYxSqUGeUn EpKlsWLoZHN9x/qerXXRYorr9pJlQFXyxGtKzv025hwi0xQ75/qfq4wtHizCf4fYS/MG yLzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BFGcof8a; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-64294-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64294-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCUWLqqegYIA6X+ksDt49enITkHg87FYkm6dxDJz5DbJSJHhWEgBhgSDeu3UCWE+ZfBcf/mnK52HjXv4OyiP5nq5/m811Q== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id by39-20020a056a0205a700b005cdab7a395asi2609742pgb.349.2024.02.13.13.17.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:17:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64294-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BFGcof8a; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-64294-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64294-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BC12B289614 for ; Tue, 13 Feb 2024 21:17:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A796A7FBC0; Tue, 13 Feb 2024 21:05:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BFGcof8a"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="9MYtQQII" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61FE67D41D for ; Tue, 13 Feb 2024 21:05:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707858350; cv=none; b=Y3irA3RT68Gg8pqVtZnB9apxjqAttNRcn+v9BlE+3F35aYCQxnkF9wfYkmIZtNvvOGNqWmBTkALsGl1C2ERVGaW6FuwaxYWsdyuT1WkuGoMPkt8uGsy0HntpN1rWSG/TGe+egX1fabhYoz+rmXOlkaSuAM+xBQ+9DdFv3+27VWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707858350; c=relaxed/simple; bh=o725dqFIOZr2sPbP/ZZcIuYm0Aik+XXCE4cbMGhjbD8=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=N4Ev9cj09/yDf6FJT4ZZ708c8Kg2HpY4zQFlLPFd+vcjhEGL01cwRHSy0aEXdFE9GH9TtiEFnYFQmfaWQ47p9E2YgS1W1cd5mxDeqbQxonaXCu1PAXMTYnTmoU4lDNwqu8VHFrUw6fpyahfOkzZ1NcunU2kvLneAgfR2iwnvwmE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=BFGcof8a; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=9MYtQQII; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: <20240213210251.994756960@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707858346; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=3hjSQJVEGCG5vViUjmCCOY+diMogglZD/H0kl7y0KTM=; b=BFGcof8aocKwVc2WSG9Utw44bpX01HqYuvWLIHdLjbONSKS27YbbYMFu9QRdGpCPeeS211 8UnEvsJ2JVPwjEykrF8S7xsMyjKshvJQB1HUI+2w+IAcsxWOWAC44dqi+5dwm6OcREYaP2 Uu6kyej3rTn2U1gWowYCPce8sm7dycYAFNLaathg2jlcQMOQuugKIe2P9tdeh/Nrwkd1GB oOVP09RXxiJzgISRon7V7A91yw/SHYcczFaE5JZjG9/QJXnFF7Y9xcxCrZg9DKbuz5yXVr bhDsqlZV8zyLsAx9kKzRPQU/290e81vLDznfCYjcVaf/DgbCSA1EE7Ls2b0d3Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707858346; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=3hjSQJVEGCG5vViUjmCCOY+diMogglZD/H0kl7y0KTM=; b=9MYtQQIIpJZ4zASSPb0mzdEyZWq6TtzJwgVz11sUg4joCcaLWBpYdF9htmXaCYdq7mkT/a 6mjx1yEEIcV9gHCg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , Huang Rui , Juergen Gross , Dimitri Sivanich , Sohil Mehta , K Prateek Nayak , Kan Liang , Zhang Rui , "Paul E. McKenney" , Feng Tang , Andy Shevchenko , Michael Kelley , "Peter Zijlstra (Intel)" Subject: [patch 09/30] x86/cpu/topology: Confine topology information References: <20240213205415.307029033@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Tue, 13 Feb 2024 22:05:46 +0100 (CET) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790820025910265138 X-GMAIL-MSGID: 1790820025910265138 From: Thomas Gleixner Now that all external fiddling with num_processors and disabled_cpus is gone, move the last user prefill_possible_map() into the topology code too and remove the global visibility of these variables. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/smp.h | 3 - arch/x86/kernel/apic/apic.c | 1 arch/x86/kernel/cpu/topology.c | 76 +++++++++++++++++++++++++++++++++++++++-- arch/x86/kernel/smpboot.c | 72 -------------------------------------- 4 files changed, 74 insertions(+), 78 deletions(-) --- --- a/arch/x86/include/asm/smp.h +++ b/arch/x86/include/asm/smp.h @@ -9,7 +9,6 @@ #include extern int smp_num_siblings; -extern unsigned int num_processors; DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map); DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map); @@ -174,8 +173,6 @@ static inline struct cpumask *cpu_llc_sh } #endif /* CONFIG_SMP */ -extern unsigned disabled_cpus; - #ifdef CONFIG_DEBUG_NMI_SELFTEST extern void nmi_selftest(void); #else --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -2054,7 +2054,6 @@ void __init init_apic_mappings(void) pr_info("APIC: disable apic facility\n"); apic_disable(); } - num_processors = 1; } } --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -29,8 +29,8 @@ u32 cpuid_to_apicid[] __read_mostly = { */ static u32 disabled_cpu_apicid __ro_after_init = BAD_APICID; -unsigned int num_processors; -unsigned disabled_cpus; +static unsigned int num_processors; +static unsigned int disabled_cpus; /* * The number of allocated logical CPU IDs. Since logical CPU IDs are allocated @@ -174,6 +174,71 @@ static int generic_processor_info(int ap return cpu; } +static int __initdata setup_possible_cpus = -1; + +/* + * cpu_possible_mask should be static, it cannot change as cpu's + * are onlined, or offlined. The reason is per-cpu data-structures + * are allocated by some modules at init time, and don't expect to + * do this dynamically on cpu arrival/departure. + * cpu_present_mask on the other hand can change dynamically. + * In case when cpu_hotplug is not compiled, then we resort to current + * behaviour, which is cpu_possible == cpu_present. + * - Ashok Raj + * + * Three ways to find out the number of additional hotplug CPUs: + * - If the BIOS specified disabled CPUs in ACPI/mptables use that. + * - The user can overwrite it with possible_cpus=NUM + * - Otherwise don't reserve additional CPUs. + * We do this because additional CPUs waste a lot of memory. + * -AK + */ +__init void prefill_possible_map(void) +{ + int i, possible; + + i = setup_max_cpus ?: 1; + if (setup_possible_cpus == -1) { + possible = num_processors; +#ifdef CONFIG_HOTPLUG_CPU + if (setup_max_cpus) + possible += disabled_cpus; +#else + if (possible > i) + possible = i; +#endif + } else + possible = setup_possible_cpus; + + total_cpus = max_t(int, possible, num_processors + disabled_cpus); + + /* nr_cpu_ids could be reduced via nr_cpus= */ + if (possible > nr_cpu_ids) { + pr_warn("%d Processors exceeds NR_CPUS limit of %u\n", + possible, nr_cpu_ids); + possible = nr_cpu_ids; + } + +#ifdef CONFIG_HOTPLUG_CPU + if (!setup_max_cpus) +#endif + if (possible > i) { + pr_warn("%d Processors exceeds max_cpus limit of %u\n", + possible, setup_max_cpus); + possible = i; + } + + set_nr_cpu_ids(possible); + + pr_info("Allowing %d CPUs, %d hotplug CPUs\n", + possible, max_t(int, possible - num_processors, 0)); + + reset_cpu_possible_mask(); + + for (i = 0; i < possible; i++) + set_cpu_possible(i, true); +} + /** * topology_register_apic - Register an APIC in early topology maps * @apic_id: The APIC ID to set up @@ -251,6 +316,13 @@ void topology_hotunplug_apic(unsigned in } #endif +static int __init _setup_possible_cpus(char *str) +{ + get_option(&str, &setup_possible_cpus); + return 0; +} +early_param("possible_cpus", _setup_possible_cpus); + static int __init apic_set_disabled_cpu_apicid(char *arg) { if (!arg || !get_option(&arg, &disabled_cpu_apicid)) --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1291,78 +1291,6 @@ void __init native_smp_cpus_done(unsigne cache_aps_init(); } -static int __initdata setup_possible_cpus = -1; -static int __init _setup_possible_cpus(char *str) -{ - get_option(&str, &setup_possible_cpus); - return 0; -} -early_param("possible_cpus", _setup_possible_cpus); - - -/* - * cpu_possible_mask should be static, it cannot change as cpu's - * are onlined, or offlined. The reason is per-cpu data-structures - * are allocated by some modules at init time, and don't expect to - * do this dynamically on cpu arrival/departure. - * cpu_present_mask on the other hand can change dynamically. - * In case when cpu_hotplug is not compiled, then we resort to current - * behaviour, which is cpu_possible == cpu_present. - * - Ashok Raj - * - * Three ways to find out the number of additional hotplug CPUs: - * - If the BIOS specified disabled CPUs in ACPI/mptables use that. - * - The user can overwrite it with possible_cpus=NUM - * - Otherwise don't reserve additional CPUs. - * We do this because additional CPUs waste a lot of memory. - * -AK - */ -__init void prefill_possible_map(void) -{ - int i, possible; - - i = setup_max_cpus ?: 1; - if (setup_possible_cpus == -1) { - possible = num_processors; -#ifdef CONFIG_HOTPLUG_CPU - if (setup_max_cpus) - possible += disabled_cpus; -#else - if (possible > i) - possible = i; -#endif - } else - possible = setup_possible_cpus; - - total_cpus = max_t(int, possible, num_processors + disabled_cpus); - - /* nr_cpu_ids could be reduced via nr_cpus= */ - if (possible > nr_cpu_ids) { - pr_warn("%d Processors exceeds NR_CPUS limit of %u\n", - possible, nr_cpu_ids); - possible = nr_cpu_ids; - } - -#ifdef CONFIG_HOTPLUG_CPU - if (!setup_max_cpus) -#endif - if (possible > i) { - pr_warn("%d Processors exceeds max_cpus limit of %u\n", - possible, setup_max_cpus); - possible = i; - } - - set_nr_cpu_ids(possible); - - pr_info("Allowing %d CPUs, %d hotplug CPUs\n", - possible, max_t(int, possible - num_processors, 0)); - - reset_cpu_possible_mask(); - - for (i = 0; i < possible; i++) - set_cpu_possible(i, true); -} - /* correctly size the local cpu masks */ void __init setup_cpu_local_masks(void) {