Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp336005rwi; Fri, 14 Oct 2022 02:45:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7iXK+teOA+zExtJFt3QjN6ZgkmXw0D5xlNBJoneaqdpIXik8UuWnUo5BXYe73F0Vdeo9BA X-Received: by 2002:a17:907:1b1e:b0:783:8e33:2d1c with SMTP id mp30-20020a1709071b1e00b007838e332d1cmr2930630ejc.304.1665740713297; Fri, 14 Oct 2022 02:45:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665740713; cv=none; d=google.com; s=arc-20160816; b=Nbb/4teFmgbohVCugzO6EFwrFvr26jDZnuXIVIuPGWOqq5N0k8l2oUUTTaoj5U8vyA TMXDq2HrS6k4MqluNjXC/k+JIPsMbqhC8mtrNapwBqqErFgtiRpuQVrjq/hBZr9G5QsG T4zmoLbDhIkphFEGqfAVvpTPrUHT0fsyqi8SKhKig7uEz0tK/KCwqaMf0b162gPqOTs5 69yVTBG2SGY9DRTFc0CYkoQ16bMfuaj1IO/R9JhNLH7JAJjmRXPleBPjINpYOLDOgNNm ESQs/Mnu+EPz/iFp5c9rhP9phhXkgyLfXZRvWpM/KHa3u3Afwp8bpvj+HQ686o0KAomM HMgA== 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=pI+4OtTrFFgq0X5iL8nqpI+MqkVUkBCH9IZR8gllswY=; b=oqk1vRCLjlkjpsmBml4rNuvg5Jquo/QC5aAfXKXcPLEl8adOvvM2Em9ukG6iyAWFlC Ve2a7RDbM5Y2tRXPiNK1KlEC0z0f5Ec1X4wzIG2qALo/spa9iVmKSV3JivIWNXBa8aPC xigOou7eWzVLhZ0Mgi6QR+7HA9rtH3xSuvQrjIdpSN0UO4jltnPlE7SCx8rxdLvQnt9p cYCfW1ag9FABUFb2iD5Bi21vIySV5rwhuW3rhNGzAIUp8izGkOssYbym7FzbTIMAvb4V O4Hcec0ZY933lKSJA2WhO5A5UZZ/78Mqv+saXL7SpstjtKjZ+kzyV32yBYzLE3BGRLWo 8N2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=W+Jxm+eI; 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 du3-20020a17090772c300b00734be0d7167si1968632ejc.825.2022.10.14.02.44.47; Fri, 14 Oct 2022 02:45:13 -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=W+Jxm+eI; 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 S230129AbiJNI7a (ORCPT + 99 others); Fri, 14 Oct 2022 04:59:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230100AbiJNI7T (ORCPT ); Fri, 14 Oct 2022 04:59:19 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C254C15626F; Fri, 14 Oct 2022 01:59:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665737957; x=1697273957; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=OTbXSwCtr2+jExMCyp3avWcsWjg4MvtgqQG+iqEBjmI=; b=W+Jxm+eITlG7gqsUpl05SFdP4XCb+AQ8nY4tCK+0ErE27cK/bm6Jhfab lYZ8libwBUKnJ414ApFitSSGmW5raAGlBU8qFJFq6vbNxINb9UymBmrz5 1J3WiYXKE5Ddb8nRYKGq+A8cTTJqZ0OsHSi6oda1Dm+BXTn9ZYB2gbiEf HRNlP7YX+V6YOQFQmu/cUOzP+du7l4U+61k4nL1FEq0Pqppzkycg5xBRd Y1EACZXyiyol3Pgbs7DNzILFqNSFC6Dr0NgfaZNbQ48YeM5InR4g+2twB i07YcgBniZOX72BLFYyR5UYjC+w139SocJ2aqCHzcO9wuzAvbpfqJPsHr Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10499"; a="391635386" X-IronPort-AV: E=Sophos;i="5.95,182,1661842800"; d="scan'208";a="391635386" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2022 01:59:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10499"; a="696234537" X-IronPort-AV: E=Sophos;i="5.95,182,1661842800"; d="scan'208";a="696234537" Received: from power-sh.sh.intel.com ([10.239.183.122]) by fmsmga004.fm.intel.com with ESMTP; 14 Oct 2022 01:59:14 -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, peterz@infradead.org, jdelvare@suse.com, linux@roeck-us.net, len.brown@intel.com, rui.zhang@intel.com Subject: [PATCH V4 3/4] x86/topology: Fix multiple packages shown on a single-package system Date: Fri, 14 Oct 2022 17:01:46 +0800 Message-Id: <20221014090147.1836-4-rui.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221014090147.1836-1-rui.zhang@intel.com> References: <20221014090147.1836-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 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 a single package AlderLake-N, there are 2 Ecore Modules with 4 atom cores in each module. Linux does not support the 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. Fixes: 7745f03eb395 ("x86/topology: Add CPUID.1F multi-die/package support") Cc: stable@vger.kernel.org Suggested-by: Len Brown Signed-off-by: Zhang Rui Reviewed-by: Len Brown --- 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