Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3111697rwb; Mon, 7 Aug 2023 08:24:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4N7z9CbGDeGsaEBnR1zdp1unsSq6TT3cmFusLn2NDFhRzz4jcZK2qMlugp63qlWL9bTip X-Received: by 2002:a05:6a20:4418:b0:13f:9b98:c416 with SMTP id ce24-20020a056a20441800b0013f9b98c416mr10701528pzb.55.1691421850879; Mon, 07 Aug 2023 08:24:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691421850; cv=none; d=google.com; s=arc-20160816; b=gEPYosyt3UQcFQ62HrfDe7/tKpFDg76Oz1Q7Lba8YdKGyD0H5oce6XtFf378iSTSrg DSY2pGNxojsIhxrQeww1pa5Q/F5LVZ2RH6gsWIs2mCwTG9Uwa1FKFyD/cyNzdkI8sQfJ QRHKfm9hES7FVSoQdu7SfQEiPDpMZQrPBz4GXUUwWV+AC0c5RMA4JZXprbNjCprnqKXv ZG6HQdmyKox/kU6yM+WBiyZ8M196zETZERClE5ZOvoDpTX3tPSIlYpKZBvu24KOYHlR6 suNTEjfFAoWTWr5QIOT5G9/OW3HXzBD/dYy6Wir5MlyILWSmVUZ4swAR/zpqeOd2sg4N MgsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=lEJAM6lSEYnamHvy/pM3gmY344lRoNlxzC3YlBMWnmA=; fh=/92WVKYrcN3rA268QXyKzVtm/UtxHeI2lnbU295XDiQ=; b=TYP+sTTe1SaKEDu/GAy2Q1DdPAlZsjNd+ffu+lfS12TXxobs1phpYnE7hNC4HStNO/ dvk/nXBUwi3v5XhyrG5bCgdzxkNvoHYQtluc/E/ztm7deRs9UVkqQwdLHK4231bi/AX9 ZZwkAbKFPs4PLxNev28QlN9aEpiVKy5ici99e0Z9Z71esyIOnGY7Dl8npZ7CNPpZpgDh APqmry7+afmiF8W3D/gnfeE0gRK8fXxx8pouVaLbpdwadqD/wIOuB8rnZk2a4rh75kJB n2Xx9J7ziEkMCb8dybBpVkr14w7p/6KfZxZqKB+aQpGTAksVa7oBPRb+O5K5y1T8jD/e EIew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ETtcYkCF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b7-20020a633407000000b00551bb2b99besi5500613pga.85.2023.08.07.08.23.58; Mon, 07 Aug 2023 08:24:10 -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=@linutronix.de header.s=2020 header.b=ETtcYkCF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234590AbjHGNzd (ORCPT + 99 others); Mon, 7 Aug 2023 09:55:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234689AbjHGNyZ (ORCPT ); Mon, 7 Aug 2023 09:54:25 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B114210C for ; Mon, 7 Aug 2023 06:53:38 -0700 (PDT) Message-ID: <20230807135028.538458200@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1691416416; 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=lEJAM6lSEYnamHvy/pM3gmY344lRoNlxzC3YlBMWnmA=; b=ETtcYkCFrSbFl0znfhjYUotU5DP8+kA+1D4ue1kZJamGsOntPw2n8RS/1U4jA4nvldKqlz NzCli0ZDDmh9ksl03VtpnZCBoQAKG6F/F8XwWOL32hm4QP1ClWXslbDtI559xXBv0BOZ8p HTIyFj5SNGQY0KtHfjHwFEZP0Q0DR30ykm1eaVZ2iqjfmdAdy+VsRrYeWXDok5gCHoXi4Y HCJIRYcXiyqn7Z1aDeAzZEkA/1cfeyr29j/H3kmMg5lFKp2zRPKGMukU1nAwaQ1KW/jBF+ rW2HlA7oz3SqrQPjDCGp+qNlt0ysSUMtUjhtT2dRxirgWEIeMXAr9SODu0jhEg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1691416416; 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=lEJAM6lSEYnamHvy/pM3gmY344lRoNlxzC3YlBMWnmA=; b=NSuebcMVp9x5AsXQoWpMIxO89mNbQXxraBRBoC3sF3EUEebdEi5yMQl8LiWzPYIJndMHey xeyJZANDEw66CZAQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , Huang Rui , Juergen Gross , Dimitri Sivanich , Michael Kelley , Sohil Mehta , K Prateek Nayak , Kan Liang , Zhang Rui , "Paul E. McKenney" , Feng Tang , Andy Shevchenko Subject: [patch 40/53] x86/cpu/topology: Assign hotpluggable CPUIDs during init References: <20230807130108.853357011@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Mon, 7 Aug 2023 15:53:36 +0200 (CEST) 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 There is no point in assigning the CPU numbers during ACPI physical hotplug. The number of possible hotplug CPUs is known when the possible map is initialized, so the CPU numbers can be associated to the registered non-present APIC IDs right there. This allows to put more code into the __init section and makes the related data __ro_after_init. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/topology.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -45,7 +45,7 @@ EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_a DECLARE_BITMAP(phys_cpu_present_map, MAX_LOCAL_APIC) __read_mostly; /* Used for CPU number allocation and parallel CPU bringup */ -u32 cpuid_to_apicid[] __read_mostly = { [0 ... NR_CPUS - 1] = BAD_APICID, }; +u32 cpuid_to_apicid[] __ro_after_init = { [0 ... NR_CPUS - 1] = BAD_APICID, }; /* Bitmaps to mark registered APICs at each topology domain */ static struct { DECLARE_BITMAP(map, MAX_LOCAL_APIC); } apic_maps[TOPO_MAX_DOMAIN] __ro_after_init; @@ -60,7 +60,7 @@ struct { unsigned int nr_rejected_cpus; u32 boot_cpu_apic_id; u32 real_bsp_apic_id; -} topo_info __read_mostly = { +} topo_info __ro_after_init = { .nr_assigned_cpus = 1, .boot_cpu_apic_id = BAD_APICID, .real_bsp_apic_id = BAD_APICID, @@ -143,7 +143,7 @@ static int topo_lookup_cpuid(u32 apic_id return -ENODEV; } -static int topo_assign_cpunr(u32 apic_id) +static __init int topo_assign_cpunr(u32 apic_id) { int cpu = topo_lookup_cpuid(apic_id); @@ -159,8 +159,6 @@ static void topo_set_cpuids(unsigned int early_per_cpu(x86_cpu_to_apicid, cpu) = apic_id; early_per_cpu(x86_cpu_to_acpiid, cpu) = acpi_id; #endif - cpuid_to_apicid[cpu] = apic_id; - set_cpu_possible(cpu, true); set_cpu_present(cpu, true); @@ -205,6 +203,8 @@ void __init topology_register_apic(u32 a cpu = 0; else cpu = topo_assign_cpunr(apic_id); + + cpuid_to_apicid[cpu] = apic_id; topo_set_cpuids(cpu, apic_id, acpi_id); } else { topo_info.nr_disabled_cpus++; @@ -247,12 +247,9 @@ int topology_hotplug_apic(u32 apic_id, u return -ENODEV; cpu = topo_lookup_cpuid(apic_id); - if (cpu < 0) { - if (topo_info.nr_assigned_cpus >= nr_cpu_ids) - return -ENOSPC; + if (cpu < 0) + return -ENOSPC; - cpu = topo_assign_cpunr(apic_id); - } set_bit(apic_id, phys_cpu_present_map); topo_set_cpuids(cpu, apic_id, acpi_id); return cpu; @@ -352,6 +349,7 @@ void __init topology_init_possible_cpus( unsigned int disabled = topo_info.nr_disabled_cpus; unsigned int total = assigned + disabled; unsigned int cpu, dom, allowed = 1; + u32 apicid; if (!restrict_to_up()) { if (total > 1) @@ -386,8 +384,16 @@ void __init topology_init_possible_cpus( init_cpu_present(cpumask_of(0)); init_cpu_possible(cpumask_of(0)); + for (apicid = 0; disabled; disabled--, apicid++) { + apicid = find_next_andnot_bit(apic_maps[TOPO_SMT_DOMAIN].map, phys_cpu_present_map, + MAX_LOCAL_APIC, apicid); + if (apicid >= MAX_LOCAL_APIC) + break; + cpuid_to_apicid[topo_info.nr_assigned_cpus++] = apicid; + } + for (cpu = 0; cpu < allowed; cpu++) { - u32 apicid = cpuid_to_apicid[cpu]; + apicid = cpuid_to_apicid[cpu]; /* * In case of a kdump() kernel, don't mark the real BSP in