Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3361736rwb; Tue, 16 Aug 2022 01:14:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR6yxqpBC+KPk11s+zYteVQacPNB1lYJFS6yqoYEoEu+7KllB/OS4HqtBjpw3w1iJ0KRnXps X-Received: by 2002:a17:907:781a:b0:730:cd06:3572 with SMTP id la26-20020a170907781a00b00730cd063572mr12678051ejc.487.1660637684870; Tue, 16 Aug 2022 01:14:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660637684; cv=none; d=google.com; s=arc-20160816; b=eN286hcLUzacR+s9/aoUbJBwsBw6qMYyIJErJMsopNw/d7HbI4TrNw0rno8XmlPSG9 axqCWCir5sUp8KK5TwLAFr1XgIXfSgkVvcrow9BRzrKhufdx8vRdey2QGdmo//k9lh35 DxiiS3e1Vzs/eLLpSj7nrwVUNg4Q9OdFp0ds/xM8Lgyf3VEZJG4cn7yVov09agQD30T1 tjsvzPLP5/Way5Qe0aprp7P5//DhziUtlLpHuAJ7gXV6a5wuisEtDhVu4faAFPnJtTKo TMmx8on8eOQzbXIHoIn3Swa7YOZ4HDFK6jcbeFBTccTwyPQU81tEfc0r28ejrVQiWTe4 8Czg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=+vnygnuopldILqK+o8P8TSxuk7EMohEBvZwQrrdmG7k=; b=dZ5Ao4WeH2LKQgk6s9gD+wXq5WM6e0AyzX5NwtvF2B9IRLBiFro4OMW0andIFgl44K vMkGm92V19CFpmsBjtsV6lsOL64Cpj5zR8hHZDIDfXVCfNF4QV9L7fCVHO9K+/Smg/ZX MP/lgwydSQbIRNnxwXUqxPH+ibvcOAIQZ46CtBFRa8Q0mbgrVYlDJxu+5VYKH0HLQvwB YOnuaWY09nGRwbpWIbJxFLwVKjUm9lKWYe0/FeTtFi1+bKimtV61bPl5xS4EnlIKHcOx FJNY/KyhWnoSqJr22U12BUQKgE3uFhDhSKmIUDDRIkqk+BLuYdqkhmckVtwMSs8tn9sZ W/oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XVArvnoM; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g8-20020a056402428800b004437a9fcc07si7007874edc.361.2022.08.16.01.14.19; Tue, 16 Aug 2022 01:14:44 -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=@intel.com header.s=Intel header.b=XVArvnoM; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231375AbiHPH5n (ORCPT + 99 others); Tue, 16 Aug 2022 03:57:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbiHPH4n (ORCPT ); Tue, 16 Aug 2022 03:56:43 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A486E5881; Mon, 15 Aug 2022 22:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660626781; x=1692162781; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=MSrdbnyHwDKJWzacOswQdOazPsUhPsZ/gQdv7Bzjyis=; b=XVArvnoM/ajPDEcgD93O0atoQ5tz3o0UXl8v98D6MIkd+jiG+Gp2dsmj tErOhJNSL6lY+mCZ5MGsWYBJ/URLfKfKLiFhAMVKz8aSR1eC1CJsNrey5 RMWThfpDDX7fyyDK1qcJQhZm/ydevz0MunDZcWMUCIFXtFm0oQIBSS3KA CyIdSoLzex7cvWmnatvf+iriRkOvkGr4D9qgpUt2eNyUEDIp4Vw4KySL0 Qubh6f90uomLrLpiM/diyR8sKQ4CD7uFAW4ErkR7bQEjyPQVOU12SicBM MQtn1/8mXmR+d/r4DLWdHVTeN7fRnX6WfolX1LCIpwmqMjC211uCOkURi Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10440"; a="356130163" X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="356130163" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Aug 2022 22:13:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="666953473" Received: from power-sh.sh.intel.com ([10.239.183.122]) by fmsmga008.fm.intel.com with ESMTP; 15 Aug 2022 22:12:57 -0700 From: Zhang Rui To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-hwmon@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, corbet@lwn.net, fenghua.yu@intel.com, jdelvare@suse.com, linux@roeck-us.net, len.brown@intel.com, rui.zhang@intel.com Subject: [PATCH V2 4/8] x86/topology: Fix multiple packages shown on a single-package system Date: Tue, 16 Aug 2022 13:16:29 +0800 Message-Id: <20220816051633.17775-5-rui.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220816051633.17775-1-rui.zhang@intel.com> References: <20220816051633.17775-1-rui.zhang@intel.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 CPUID.1F/B does not emumerate Package level explicitly, instead, all the APIC-ID bits above the enumerated levels are assumed to be package ID bits. Current code gets package ID by shifting out all the APIC-ID bits that Linux supports, rather than shifting out all the APIC-ID bits that CPUID.1F enumerates. This introduces problems when CPUID.1F enumerates a level that Linux does not support. For example, on an AlderLake-N platform, there are 2 Ecore Modules, which has 4 atom cores in each module, in a single package. Linux does not support Module level and interprets the Module ID bits as package ID and erroneously reports a multi module system as a multi-package system. Fix this by using APIC-ID bits above all the CPUID.1F enumerated levels as package ID. Suggested-and-reviewed-by: Len Brown Signed-off-by: Zhang Rui --- arch/x86/kernel/cpu/topology.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/topology.c b/arch/x86/kernel/cpu/topology.c index 132a2de44d2f..f7592814e5d5 100644 --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -96,6 +96,7 @@ int detect_extended_topology(struct cpuinfo_x86 *c) unsigned int ht_mask_width, core_plus_mask_width, die_plus_mask_width; unsigned int core_select_mask, core_level_siblings; unsigned int die_select_mask, die_level_siblings; + unsigned int pkg_mask_width; bool die_level_present = false; int leaf; @@ -111,10 +112,10 @@ int detect_extended_topology(struct cpuinfo_x86 *c) core_level_siblings = smp_num_siblings = LEVEL_MAX_SIBLINGS(ebx); core_plus_mask_width = ht_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); die_level_siblings = LEVEL_MAX_SIBLINGS(ebx); - die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); + pkg_mask_width = die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); sub_index = 1; - do { + while (true) { cpuid_count(leaf, sub_index, &eax, &ebx, &ecx, &edx); /* @@ -132,8 +133,13 @@ int detect_extended_topology(struct cpuinfo_x86 *c) die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); } + if (LEAFB_SUBTYPE(ecx) != INVALID_TYPE) + pkg_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); + else + break; + sub_index++; - } while (LEAFB_SUBTYPE(ecx) != INVALID_TYPE); + } core_select_mask = (~(-1 << core_plus_mask_width)) >> ht_mask_width; die_select_mask = (~(-1 << die_plus_mask_width)) >> @@ -148,7 +154,7 @@ int detect_extended_topology(struct cpuinfo_x86 *c) } c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, - die_plus_mask_width); + pkg_mask_width); /* * Reinit the apicid, now that we have extended initial_apicid. */ -- 2.25.1