Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp449516rdb; Tue, 23 Jan 2024 04:54:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDMXF819hq6B4voCulRIXU4B/pkBIOoycUR/Kxm7Guqc2oJ3wvpz72bWbZyqh74m/78/JY X-Received: by 2002:ac8:7e94:0:b0:42a:33d8:2994 with SMTP id w20-20020ac87e94000000b0042a33d82994mr700471qtj.52.1706014454204; Tue, 23 Jan 2024 04:54:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706014454; cv=pass; d=google.com; s=arc-20160816; b=SzIWdldvZq/+fEpivAZJJ1RDtT+9EiISYnqJjcmRhoRDMvG3urwj5BhxhFnFFJMZRH S5bkdkgFmB29p9+DAPn+48N9M0j1GxTEn3nvpk0YdU42hFIx/V7JaZyfC5kclEhuXOBU /aLdcvDGiK2wVD/q4frERPpZ40AqGwat5HEC4NEXZKVW2pshhrK4cc6UxLY7hQiSZBve jDFf3gIDhgWiLUXmMDDnfxcGDpLJYL1yY+uF3YWFVCRoZHFFGQ0AEEXfq02rLeYRAvF9 0Ln5r14mzUlc9umb8a2p1Tk19eZV84G/0Iqn/+DdTB+yTFIcs6ccL6g4ATuQpk/vRuSU ukwA== 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=8VUl7pYr590afD01ha6vPyQIe2lBly9mAJe0mtABk/E=; fh=Te0fDPJ/sd+7p881M6fa/oF213lBbJvGdEFWr/TLqNA=; b=SgTIHC45Qh07UnexjonUBX/xcTVCW3fcK6re7QrDbttlNodH7eYJ4yDYob2RsQuUya MAH0kpd4MrC0PAl+zrh/adrYaG1gDjadEupniNuTuBKVriuyHGqoE3hHdNPQVP8l6uCw hg3hkP0/B64L9MfSZJaHbn5BKGKIZ5XCpqjwXqNYSOJ8LbuRWqiVeYNjVTbvlD68KHYA QgTN2aO7VEPmmnrndVinG7xwr+7tfPK2nD05HgvSwljUfTTmFYMNYraO9oj644PadSrR rc7P0ziF541TJjYLFRb7gkTeyhbmGwXFk1ZsjUgx06zT3p0rjBXGhCjceUYk1kaTLyPg H2mg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Gqo8fpm0; 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-35267-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35267-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j13-20020ac85f8d000000b0042a5326b2a7si598459qta.709.2024.01.23.04.54.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 04:54:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35267-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Gqo8fpm0; 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-35267-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35267-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id F02281C22E34 for ; Tue, 23 Jan 2024 12:54:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7240B5F85A; Tue, 23 Jan 2024 12:53:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Gqo8fpm0"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xXX2SZW9" 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 269E65F574 for ; Tue, 23 Jan 2024 12:53:36 +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=1706014418; cv=none; b=CzckxtRKE38oAvqykMMVObZd1RIP5Ae+kO7dNmlOBFy53/u2G4Gk9gtm/iZXBXT5JQLKvKnvjE/EV4H5PKneXlay7dAih8FXPKaGcnloswfcoXbqzcHp3goH/fTYi9zl+MmkbZBGje50y9odGqWErZxTQTibdF8rmMhzOQW8cDc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014418; c=relaxed/simple; bh=V70qJUYY8oyHztXjt5ElJsr4r84LmSynsQcDzBQCb0k=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=OEWbss+5HfDzUPJvJSK+bkh0vyixgRg9hgDnkX7JnGNfuVek2tqhHKIuwAxkDer3yfsw4xVrcIvbH+re0LgDVmHHZevY9T1nvMXrQv9fLUMRbugV7pgToYCbAOSEJtjPyWOSa3Pk2Rq2AvsVYF/RTPI+Isf92FmuWydCy0LCak0= 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=Gqo8fpm0; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xXX2SZW9; 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: <20240117115908.477060795@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014415; 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=8VUl7pYr590afD01ha6vPyQIe2lBly9mAJe0mtABk/E=; b=Gqo8fpm0jQugypsMtvfTEljTWrL5oNDuEgskAbYJsqlQzO9LM5HXrWDGIVXogvTAi+XiRa jOXC0NUfa8rrEuP9pmDKTa1PI6XW1WL7/EXT0hZASAofRhgk0DcOKYmZNHhphnETVNXPtN PP+nhUZViE4938xuDzKSLkIL6Jcwhtb91+41O+0yVjis+7mBoNMH6zphUwCGAxCuQFzUe3 uvoyUQgNvJDuzpXTZE8A/qizUImU+M3ygM8CnRVx8dY+B7sT0S4JEMDum7EaX9uUo6P8K0 oz9T/fkVWh/c2Lb4MxqfWKokO04MaeBnps6JtmNcwqedR4YD7fdtYNz3dziPYg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014415; 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=8VUl7pYr590afD01ha6vPyQIe2lBly9mAJe0mtABk/E=; b=xXX2SZW9BI738ejKEPtAgf3doA5bSGLPZcxPAFtNrfqZt0uQPfYoB+k65P61uGSYDAGvG1 f7LSExxP27tSiPBA== 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 v5 03/19] x86/cpu: Add legacy topology parser References: <20240117115752.863482697@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Tue, 23 Jan 2024 13:53:34 +0100 (CET) From: Thomas Gleixner The legacy topology detection via CPUID leaf 4, which provides the number of cores in the package and CPUID leaf 1 which provides the number of logical CPUs in case that FEATURE_HT is enabled and the CMP_LEGACY feature is not set, is shared for Intel, Centaur amd Zhaoxin CPUs. Lift the code from common.c without the early detection hack and provide it as common fallback mechanism. Will be utilized in later changes. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/kernel/cpu/common.c | 3 ++ arch/x86/kernel/cpu/topology.h | 3 ++ arch/x86/kernel/cpu/topology_common.c | 46 +++++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-) --- --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -891,6 +891,9 @@ void detect_ht(struct cpuinfo_x86 *c) #ifdef CONFIG_SMP int index_msb, core_bits; + if (topo_is_converted(c)) + return; + if (detect_ht_early(c) < 0) return; --- a/arch/x86/kernel/cpu/topology.h +++ b/arch/x86/kernel/cpu/topology.h @@ -6,6 +6,9 @@ struct topo_scan { struct cpuinfo_x86 *c; unsigned int dom_shifts[TOPO_MAX_DOMAIN]; unsigned int dom_ncpus[TOPO_MAX_DOMAIN]; + + // Legacy CPUID[1]:EBX[23:16] number of logical processors + unsigned int ebx1_nproc_shift; }; bool topo_is_converted(struct cpuinfo_x86 *c); --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -24,6 +24,48 @@ void topology_set_dom(struct topo_scan * } } +static unsigned int parse_num_cores(struct cpuinfo_x86 *c) +{ + struct { + u32 cache_type : 5, + unused : 21, + ncores : 6; + } eax; + + if (c->cpuid_level < 4) + return 1; + + cpuid_subleaf_reg(4, 0, CPUID_EAX, &eax); + if (!eax.cache_type) + return 1; + + return eax.ncores + 1; +} + +static void __maybe_unused parse_legacy(struct topo_scan *tscan) +{ + unsigned int cores, core_shift, smt_shift = 0; + struct cpuinfo_x86 *c = tscan->c; + + cores = parse_num_cores(c); + core_shift = get_count_order(cores); + + if (cpu_has(c, X86_FEATURE_HT)) { + if (!WARN_ON_ONCE(tscan->ebx1_nproc_shift < core_shift)) + smt_shift = tscan->ebx1_nproc_shift - core_shift; + /* + * The parser expects leaf 0xb/0x1f format, which means + * the number of logical processors at core level is + * counting threads. + */ + core_shift += smt_shift; + cores <<= smt_shift; + } + + topology_set_dom(tscan, TOPO_SMT_DOMAIN, smt_shift, 1U << smt_shift); + topology_set_dom(tscan, TOPO_CORE_DOMAIN, core_shift, cores); +} + bool topo_is_converted(struct cpuinfo_x86 *c) { /* Temporary until everything is converted over. */ @@ -47,7 +89,7 @@ static bool fake_topology(struct topo_sc * which has useless CPUID information. */ topology_set_dom(tscan, TOPO_SMT_DOMAIN, 0, 1); - topology_set_dom(tscan, TOPO_CORE_DOMAIN, 1, 1); + topology_set_dom(tscan, TOPO_CORE_DOMAIN, 0, 1); return tscan->c->cpuid_level < 1 || xen_pv_domain(); } @@ -88,6 +130,8 @@ static void parse_topology(struct topo_s /* The above is sufficient for UP */ if (!IS_ENABLED(CONFIG_SMP)) return; + + tscan->ebx1_nproc_shift = get_count_order(ebx.nproc); } static void topo_set_ids(struct topo_scan *tscan)