From nobody Tue Jun 30 08:09:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21CA4C433EF for ; Fri, 21 Jan 2022 17:47:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381886AbiAURrz (ORCPT ); Fri, 21 Jan 2022 12:47:55 -0500 Received: from mga11.intel.com ([192.55.52.93]:56027 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381822AbiAURrw (ORCPT ); Fri, 21 Jan 2022 12:47:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642787272; x=1674323272; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nR54sbM3jfoKwrWn8S3jngx1W/C1FuURDqkpU392O9Q=; b=ZZDJOWeYgd9HeVMT9YNs/IazsJ7Sp/0yd1DYjiJ8WgW7FjCKOGKmPHGP Xlk+JweIbptkrwkBVY6cn55hLybI61X1AbHVt66AadayikaVooEbuCABn y7Bh3lsP66fVO4Xs62YFkT01quUK8nYWhsAd2m/K5rDPcE176fYia9s8b rmdQgBHYDjG5NEDlSgSgwBu1juDeLHc7V+aChmx1w1UXHnPR+bAfkfqpJ XCq3Tk7T1inhaZBPvVXeAVwxQyLeVMdFn7zdtdMilAne5fScVODcltCAF UEdypCgVUBAeb2sa3hrlXQ7uHgI5gztlg5py4f+1aWFsf9tURYYonQWRQ Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10234"; a="243302301" X-IronPort-AV: E=Sophos;i="5.88,306,1635231600"; d="scan'208";a="243302301" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2022 09:47:51 -0800 X-IronPort-AV: E=Sophos;i="5.88,306,1635231600"; d="scan'208";a="623394788" Received: from agluck-desk2.sc.intel.com ([10.3.52.146]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2022 09:47:51 -0800 From: Tony Luck To: Borislav Petkov Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Smita Koralahalli Channabasappa , Wei Huang , Tom Lendacky , patches@lists.linux.dev, Tony Luck , Ailin Xu Subject: [PATCH v2 1/6] x86/cpu: Add Xeon Icelake-D to list of CPUs that support PPIN Date: Fri, 21 Jan 2022 09:47:38 -0800 Message-Id: <20220121174743.1875294-2-tony.luck@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220121174743.1875294-1-tony.luck@intel.com> References: <20220107225442.1690165-1-tony.luck@intel.com> <20220121174743.1875294-1-tony.luck@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Missed adding the Icelake-D CPU to the list. It uses the same MSRs to control and read the inventory number as all the other models. Reported-by: Ailin Xu Fixes: dc6b025de95b ("x86/mce: Add Xeon Icelake to list of CPUs that suppor= t PPIN") Cc: Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/mce/intel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kernel/cpu/mce/intel.c b/arch/x86/kernel/cpu/mce/inte= l.c index bb9a46a804bf..baafbb37be67 100644 --- a/arch/x86/kernel/cpu/mce/intel.c +++ b/arch/x86/kernel/cpu/mce/intel.c @@ -486,6 +486,7 @@ static void intel_ppin_init(struct cpuinfo_x86 *c) case INTEL_FAM6_BROADWELL_X: case INTEL_FAM6_SKYLAKE_X: case INTEL_FAM6_ICELAKE_X: + case INTEL_FAM6_ICELAKE_D: case INTEL_FAM6_SAPPHIRERAPIDS_X: case INTEL_FAM6_XEON_PHI_KNL: case INTEL_FAM6_XEON_PHI_KNM: --=20 2.31.1 From nobody Tue Jun 30 08:09:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39BCEC433F5 for ; Fri, 21 Jan 2022 17:48:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381906AbiAURr6 (ORCPT ); Fri, 21 Jan 2022 12:47:58 -0500 Received: from mga11.intel.com ([192.55.52.93]:56027 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381835AbiAURrw (ORCPT ); Fri, 21 Jan 2022 12:47:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642787272; x=1674323272; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mZxmPSa3VhcTBkbIIp9oReupJsOi8vaHSepqx3qK7r8=; b=FGjkXVuP73NLRKbaPPWXkcDg2tGZb25fPzjUxfVy0iMXipI4scoOkWxp Bq9YLw/Z7qfvQdOgz6ltgmvYfy0hQwTO1UWBGe3p28pMX4QJpDjItKg4P HWla5VUJWAuMxI1dwT9h94oMZVMVWlbGCXGhp07WAEHdWNVVn123hSThg e7Vh9+ZRQ5VcprTxXahyOSRd5DVGPi4GFlMxiNre48KvKBxpQFhBdin85 88CLpESHTQoY2C3MOUpeXBeMLBfwWUotymTW4U7bsC4G6Hfx9TeZbLpV5 pukfcouznHg1DpsKZM88mQXyZGIx23PP5SyxJ7i79Da/eqZbGwjVUwOxm Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10234"; a="243302303" X-IronPort-AV: E=Sophos;i="5.88,306,1635231600"; d="scan'208";a="243302303" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2022 09:47:51 -0800 X-IronPort-AV: E=Sophos;i="5.88,306,1635231600"; d="scan'208";a="623394791" Received: from agluck-desk2.sc.intel.com ([10.3.52.146]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2022 09:47:51 -0800 From: Tony Luck To: Borislav Petkov Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Smita Koralahalli Channabasappa , Wei Huang , Tom Lendacky , patches@lists.linux.dev, Tony Luck Subject: [PATCH v2 2/6] x86/cpu: Merge Intel and AMD ppin_init() functions Date: Fri, 21 Jan 2022 09:47:39 -0800 Message-Id: <20220121174743.1875294-3-tony.luck@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220121174743.1875294-1-tony.luck@intel.com> References: <20220107225442.1690165-1-tony.luck@intel.com> <20220121174743.1875294-1-tony.luck@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The code to decide whether a system supports the PPIN (Protected Processor Inventory Number) MSR was cloned from the Intel implementation. Apart from the X86_FEATURE bit and the MSR numbers it is identical. Merge the two functions into common x86 code, but use x86_match_cpu() instead of the switch (c->x86_model) that was used by the old Intel code. No functional change. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/amd.c | 30 ------------- arch/x86/kernel/cpu/common.c | 76 +++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/mce/intel.c | 42 ------------------ 3 files changed, 76 insertions(+), 72 deletions(-) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 4edb6f0f628c..bad0fa4c1779 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -394,35 +394,6 @@ static void amd_detect_cmp(struct cpuinfo_x86 *c) per_cpu(cpu_llc_id, cpu) =3D c->cpu_die_id =3D c->phys_proc_id; } =20 -static void amd_detect_ppin(struct cpuinfo_x86 *c) -{ - unsigned long long val; - - if (!cpu_has(c, X86_FEATURE_AMD_PPIN)) - return; - - /* When PPIN is defined in CPUID, still need to check PPIN_CTL MSR */ - if (rdmsrl_safe(MSR_AMD_PPIN_CTL, &val)) - goto clear_ppin; - - /* PPIN is locked in disabled mode, clear feature bit */ - if ((val & 3UL) =3D=3D 1UL) - goto clear_ppin; - - /* If PPIN is disabled, try to enable it */ - if (!(val & 2UL)) { - wrmsrl_safe(MSR_AMD_PPIN_CTL, val | 2UL); - rdmsrl_safe(MSR_AMD_PPIN_CTL, &val); - } - - /* If PPIN_EN bit is 1, return from here; otherwise fall through */ - if (val & 2UL) - return; - -clear_ppin: - clear_cpu_cap(c, X86_FEATURE_AMD_PPIN); -} - u32 amd_get_nodes_per_socket(void) { return nodes_per_socket; @@ -947,7 +918,6 @@ static void init_amd(struct cpuinfo_x86 *c) amd_detect_cmp(c); amd_get_topology(c); srat_detect_node(c); - amd_detect_ppin(c); =20 init_amd_cacheinfo(c); =20 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 7b8382c11788..b7700a47eadd 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -88,6 +88,80 @@ EXPORT_SYMBOL_GPL(get_llc_id); /* L2 cache ID of each logical CPU */ DEFINE_PER_CPU_READ_MOSTLY(u16, cpu_l2c_id) =3D BAD_APICID; =20 +static struct ppin_info { + int feature; + int msr_ppin_ctl; +} ppin_info[] =3D { + [X86_VENDOR_INTEL] =3D { + .feature =3D X86_FEATURE_INTEL_PPIN, + .msr_ppin_ctl =3D MSR_PPIN_CTL, + .msr_ppin =3D MSR_PPIN + }, + [X86_VENDOR_AMD] =3D { + .feature =3D X86_FEATURE_AMD_PPIN, + .msr_ppin_ctl =3D MSR_AMD_PPIN_CTL, + .msr_ppin =3D MSR_AMD_PPIN + }, +}; + +static const struct x86_cpu_id ppin_cpuids[] =3D { + X86_MATCH_FEATURE(X86_FEATURE_AMD_PPIN, &ppin_info[X86_VENDOR_AMD]), + + /* Legacy models without CPUID enumeration */ + X86_MATCH_INTEL_FAM6_MODEL(IVYBRIDGE_X, &ppin_info[X86_VENDOR_INTEL]), + X86_MATCH_INTEL_FAM6_MODEL(HASWELL_X, &ppin_info[X86_VENDOR_INTEL]), + X86_MATCH_INTEL_FAM6_MODEL(BROADWELL_D, &ppin_info[X86_VENDOR_INTEL]), + X86_MATCH_INTEL_FAM6_MODEL(BROADWELL_X, &ppin_info[X86_VENDOR_INTEL]), + X86_MATCH_INTEL_FAM6_MODEL(SKYLAKE_X, &ppin_info[X86_VENDOR_INTEL]), + X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, &ppin_info[X86_VENDOR_INTEL]), + X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D, &ppin_info[X86_VENDOR_INTEL]), + X86_MATCH_INTEL_FAM6_MODEL(SAPPHIRERAPIDS_X, &ppin_info[X86_VENDOR_INTEL]= ), + X86_MATCH_INTEL_FAM6_MODEL(XEON_PHI_KNL, &ppin_info[X86_VENDOR_INTEL]), + X86_MATCH_INTEL_FAM6_MODEL(XEON_PHI_KNM, &ppin_info[X86_VENDOR_INTEL]), + + {} +}; + +static void ppin_init(struct cpuinfo_x86 *c) +{ + const struct x86_cpu_id *id; + unsigned long long val; + struct ppin_info *info; + + id =3D x86_match_cpu(ppin_cpuids); + if (!id) + return; + + /* + * Testing the presence of the MSR is not enough. Need to check + * that the PPIN_CTL allows reading of the PPIN. + */ + info =3D (struct ppin_info *)id->driver_data; + + if (rdmsrl_safe(info->msr_ppin_ctl, &val)) + goto clear_ppin; + + if ((val & 3UL) =3D=3D 1UL) { + /* PPIN locked in disabled mode */ + goto clear_ppin; + } + + /* If PPIN is disabled, try to enable */ + if (!(val & 2UL)) { + wrmsrl_safe(info->msr_ppin_ctl, val | 2UL); + rdmsrl_safe(info->msr_ppin_ctl, &val); + } + + /* Is the enable bit set? */ + if (val & 2UL) { + set_cpu_cap(c, info->feature); + return; + } + +clear_ppin: + clear_cpu_cap(c, info->feature); +} + /* correctly size the local cpu masks */ void __init setup_cpu_local_masks(void) { @@ -1655,6 +1729,8 @@ static void identify_cpu(struct cpuinfo_x86 *c) c->x86_capability[i] |=3D boot_cpu_data.x86_capability[i]; } =20 + ppin_init(c); + /* Init Machine Check Exception if available. */ mcheck_cpu_init(c); =20 diff --git a/arch/x86/kernel/cpu/mce/intel.c b/arch/x86/kernel/cpu/mce/inte= l.c index baafbb37be67..95275a5e57e0 100644 --- a/arch/x86/kernel/cpu/mce/intel.c +++ b/arch/x86/kernel/cpu/mce/intel.c @@ -470,47 +470,6 @@ void intel_clear_lmce(void) wrmsrl(MSR_IA32_MCG_EXT_CTL, val); } =20 -static void intel_ppin_init(struct cpuinfo_x86 *c) -{ - unsigned long long val; - - /* - * Even if testing the presence of the MSR would be enough, we don't - * want to risk the situation where other models reuse this MSR for - * other purposes. - */ - switch (c->x86_model) { - case INTEL_FAM6_IVYBRIDGE_X: - case INTEL_FAM6_HASWELL_X: - case INTEL_FAM6_BROADWELL_D: - case INTEL_FAM6_BROADWELL_X: - case INTEL_FAM6_SKYLAKE_X: - case INTEL_FAM6_ICELAKE_X: - case INTEL_FAM6_ICELAKE_D: - case INTEL_FAM6_SAPPHIRERAPIDS_X: - case INTEL_FAM6_XEON_PHI_KNL: - case INTEL_FAM6_XEON_PHI_KNM: - - if (rdmsrl_safe(MSR_PPIN_CTL, &val)) - return; - - if ((val & 3UL) =3D=3D 1UL) { - /* PPIN locked in disabled mode */ - return; - } - - /* If PPIN is disabled, try to enable */ - if (!(val & 2UL)) { - wrmsrl_safe(MSR_PPIN_CTL, val | 2UL); - rdmsrl_safe(MSR_PPIN_CTL, &val); - } - - /* Is the enable bit set? */ - if (val & 2UL) - set_cpu_cap(c, X86_FEATURE_INTEL_PPIN); - } -} - /* * Enable additional error logs from the integrated * memory controller on processors that support this. @@ -535,7 +494,6 @@ void mce_intel_feature_init(struct cpuinfo_x86 *c) { intel_init_cmci(); intel_init_lmce(); - intel_ppin_init(c); intel_imc_init(c); } =20 --=20 2.31.1 From nobody Tue Jun 30 08:09:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E37BCC433FE for ; Fri, 21 Jan 2022 17:48:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381954AbiAURr7 (ORCPT ); Fri, 21 Jan 2022 12:47:59 -0500 Received: from mga11.intel.com ([192.55.52.93]:56027 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381849AbiAURrw (ORCPT ); Fri, 21 Jan 2022 12:47:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642787272; x=1674323272; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nWX0k/Ycng9nd3KVMoKJdljWJ4mHhaMHhIgKvclEDPw=; b=kQ/PJj7Z/D/AcIgH4i1kuPjw1Z6oqyZaKPUVgBWMZJV8P9cVM6u+KMK7 CxQ5qOXpgjefgDwy8+krF6RHEUjrmEVQ/xkWLcDNcHeVXQxKY7lAMgYTw sBYMhouqzVc1J1jh1Nlj9IO/agKi/VIzAvclyJbH5vY/68kGYZlgPokDL D9eNj0iVHZAL6wHzH+mds7FzU0rIHugjrUlmDHOPiKprBbKXr49tHultT hzuo8IUMqGL8a/t0ExzjhVIecC5Ku1VM+WzYveGBHWoBOV2Dy9tXcfI65 mKfQcBywiFVjY3KqRvxc6QUAGgNAeGZTMeZ2gsZhqMcfBPVM01szWQaUy w==; X-IronPort-AV: E=McAfee;i="6200,9189,10234"; a="243302304" X-IronPort-AV: E=Sophos;i="5.88,306,1635231600"; d="scan'208";a="243302304" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2022 09:47:51 -0800 X-IronPort-AV: E=Sophos;i="5.88,306,1635231600"; d="scan'208";a="623394795" Received: from agluck-desk2.sc.intel.com ([10.3.52.146]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2022 09:47:51 -0800 From: Tony Luck To: Borislav Petkov Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Smita Koralahalli Channabasappa , Wei Huang , Tom Lendacky , patches@lists.linux.dev, Tony Luck Subject: [PATCH v2 3/6] x86/cpu: X86_FEATURE_INTEL_PPIN finally has a CPUID bit Date: Fri, 21 Jan 2022 09:47:40 -0800 Message-Id: <20220121174743.1875294-4-tony.luck@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220121174743.1875294-1-tony.luck@intel.com> References: <20220107225442.1690165-1-tony.luck@intel.com> <20220121174743.1875294-1-tony.luck@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" After nine generations of adding to model specific list of CPUs that support PPIN (Protected Processor Inventory Number) Intel allocated a CPUID bit to enumerate the MSRs. CPUID(EAX=3D7, ECX=3D1).EBX bit 0 enumerates presence of MSR_PPIN_CTL and MSR_PPIN. Add it to the "scattered" CPUID bits and add an entry to the ppin_cpuids[] x86_match_cpu() array to catch Intel CPUs that implement it. Signed-off-by: Tony Luck --- arch/x86/kernel/cpu/common.c | 1 + arch/x86/kernel/cpu/scattered.c | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index b7700a47eadd..8a039d1ea57f 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -106,6 +106,7 @@ static struct ppin_info { =20 static const struct x86_cpu_id ppin_cpuids[] =3D { X86_MATCH_FEATURE(X86_FEATURE_AMD_PPIN, &ppin_info[X86_VENDOR_AMD]), + X86_MATCH_FEATURE(X86_FEATURE_INTEL_PPIN, &ppin_info[X86_VENDOR_INTEL]), =20 /* Legacy models without CPUID enumeration */ X86_MATCH_INTEL_FAM6_MODEL(IVYBRIDGE_X, &ppin_info[X86_VENDOR_INTEL]), diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattere= d.c index 21d1f062895a..4143b1e4c5c6 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -26,6 +26,7 @@ struct cpuid_bit { static const struct cpuid_bit cpuid_bits[] =3D { { X86_FEATURE_APERFMPERF, CPUID_ECX, 0, 0x00000006, 0 }, { X86_FEATURE_EPB, CPUID_ECX, 3, 0x00000006, 0 }, + { X86_FEATURE_INTEL_PPIN, CPUID_EBX, 0, 0x00000007, 1 }, { X86_FEATURE_CQM_LLC, CPUID_EDX, 1, 0x0000000f, 0 }, { X86_FEATURE_CQM_OCCUP_LLC, CPUID_EDX, 0, 0x0000000f, 1 }, { X86_FEATURE_CQM_MBM_TOTAL, CPUID_EDX, 1, 0x0000000f, 1 }, --=20 2.31.1 From nobody Tue Jun 30 08:09:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AD62C433F5 for ; Fri, 21 Jan 2022 17:48:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381822AbiAURsB (ORCPT ); Fri, 21 Jan 2022 12:48:01 -0500 Received: from mga11.intel.com ([192.55.52.93]:56027 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381864AbiAURrw (ORCPT ); Fri, 21 Jan 2022 12:47:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642787272; x=1674323272; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QxJ1Z8BS1hZL8whFuL6RPwtcoEig2y1OhfDG0d4TBGA=; b=NVePwGBIdXl2dpSNudMBLrA0pqQxu9fWJvOTbwCzPFqTA43aJl+E4gNO wnrCAiB6ovqDGpZIWXJU3i+bbZx+JMLpTIRm5HQA+rbAa5OBZl0ik0iR6 JjAm/xuzFFKT4tAknIiZ39Ksc38vHofwzjJCaxvMKyE1LTwPc6o52leC4 YzlmTwZTSzpgZAP8kJOkEAnGu+YiczatPHh44SXjovw+qa2Lnoz2UO2TJ KLcfAHl1+By0emWYUDftqODofl3a5IDOpSMRsbuyk27cdW1xSX303335B 2JsTTaUKzvUbt6J7XnclrsZ70Nfx3S0yUujKCdveCKtYbEGve5ZtXgCzc Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10234"; a="243302305" X-IronPort-AV: E=Sophos;i="5.88,306,1635231600"; d="scan'208";a="243302305" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2022 09:47:52 -0800 X-IronPort-AV: E=Sophos;i="5.88,306,1635231600"; d="scan'208";a="623394799" Received: from agluck-desk2.sc.intel.com ([10.3.52.146]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2022 09:47:51 -0800 From: Tony Luck To: Borislav Petkov Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Smita Koralahalli Channabasappa , Wei Huang , Tom Lendacky , patches@lists.linux.dev, Tony Luck Subject: [PATCH v2 4/6] x86/cpu: Read/save PPIN MSR during initialization Date: Fri, 21 Jan 2022 09:47:41 -0800 Message-Id: <20220121174743.1875294-5-tony.luck@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220121174743.1875294-1-tony.luck@intel.com> References: <20220107225442.1690165-1-tony.luck@intel.com> <20220121174743.1875294-1-tony.luck@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently the PPIN (Protected Processor Inventory Number) MSR is read by every CPU that processes a machine check, CMCI, or just polls machine check banks from a periodic timer. This is not a "fast" MSR, so this adds to overhead of processing errors. Add a new "ppin" field to the cpuinfo_x86 structure. Read and save the PPIN during initialization. Use this copy in mce_setup() instead of reading the MSR. Signed-off-by: Tony Luck --- arch/x86/include/asm/processor.h | 2 ++ arch/x86/kernel/cpu/common.c | 2 ++ arch/x86/kernel/cpu/mce/core.c | 7 +------ 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/proces= sor.h index 2c5f12ae7d04..a87e7c33d5ac 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -119,6 +119,8 @@ struct cpuinfo_x86 { int x86_cache_mbm_width_offset; int x86_power; unsigned long loops_per_jiffy; + /* protected processor identification number */ + u64 ppin; /* cpuid returned max cores value: */ u16 x86_max_cores; u16 apicid; diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 8a039d1ea57f..64deb7727d00 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -91,6 +91,7 @@ DEFINE_PER_CPU_READ_MOSTLY(u16, cpu_l2c_id) =3D BAD_APICI= D; static struct ppin_info { int feature; int msr_ppin_ctl; + int msr_ppin; } ppin_info[] =3D { [X86_VENDOR_INTEL] =3D { .feature =3D X86_FEATURE_INTEL_PPIN, @@ -155,6 +156,7 @@ static void ppin_init(struct cpuinfo_x86 *c) =20 /* Is the enable bit set? */ if (val & 2UL) { + c->ppin =3D __rdmsr(info->msr_ppin); set_cpu_cap(c, info->feature); return; } diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 5818b837fd4d..4f1e825033ce 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -138,12 +138,7 @@ void mce_setup(struct mce *m) m->socketid =3D cpu_data(m->extcpu).phys_proc_id; m->apicid =3D cpu_data(m->extcpu).initial_apicid; m->mcgcap =3D __rdmsr(MSR_IA32_MCG_CAP); - - if (this_cpu_has(X86_FEATURE_INTEL_PPIN)) - m->ppin =3D __rdmsr(MSR_PPIN); - else if (this_cpu_has(X86_FEATURE_AMD_PPIN)) - m->ppin =3D __rdmsr(MSR_AMD_PPIN); - + m->ppin =3D cpu_data(m->extcpu).ppin; m->microcode =3D boot_cpu_data.microcode; } =20 --=20 2.31.1 From nobody Tue Jun 30 08:09:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6A9FC433F5 for ; Fri, 21 Jan 2022 17:48:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382038AbiAURsH (ORCPT ); Fri, 21 Jan 2022 12:48:07 -0500 Received: from mga11.intel.com ([192.55.52.93]:56029 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381866AbiAURrx (ORCPT ); Fri, 21 Jan 2022 12:47:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642787272; x=1674323272; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/1OJfXy/I18emCF3o7qdCGUx0GFDwkCLNiIUahp4qos=; b=kRg3sTx7R8d2VbISrOVpsQB7ztt2iT3laIFwo4GFJjtZxnDUWbzBhzlf hXwb6ph4/caI0faXmjv7pua3HisBTnyDjzDxDwA00xL1imttyWtkUAYh2 Fm3LCAtVEwHZp+KR2aVrGFtrIR68RGxqCDYb4OleUWbHB8+b5I4M0ltfr BbZ314qRNurTf4+4T56326FZw0oNTwM76yyucJJmnCkvPWdkU+ytge2os hMXKAXC0YUoXdTI0+UrwXHGmzavDBNShaFvSi1ZFbaINyJ20+g2Ak0JRo Jt3sIpbmSsLSKrN7LBBehQjO8/2kN6EC+IjDS+dJaZBq2wkuT2JqgYMZ1 g==; X-IronPort-AV: E=McAfee;i="6200,9189,10234"; a="243302306" X-IronPort-AV: E=Sophos;i="5.88,306,1635231600"; d="scan'208";a="243302306" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2022 09:47:52 -0800 X-IronPort-AV: E=Sophos;i="5.88,306,1635231600"; d="scan'208";a="623394801" Received: from agluck-desk2.sc.intel.com ([10.3.52.146]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2022 09:47:52 -0800 From: Tony Luck To: Borislav Petkov Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Smita Koralahalli Channabasappa , Wei Huang , Tom Lendacky , patches@lists.linux.dev, Tony Luck Subject: [PATCH v2 5/6] topology/sysfs: Add format parameter to macro defining "show" functions for proc Date: Fri, 21 Jan 2022 09:47:42 -0800 Message-Id: <20220121174743.1875294-6-tony.luck@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220121174743.1875294-1-tony.luck@intel.com> References: <20220107225442.1690165-1-tony.luck@intel.com> <20220121174743.1875294-1-tony.luck@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" All the simple (non-mask and non-list files in /sys/devices/system/cpu/cpu0/topology/ are currently printed as decimal integers. Refactor the macro that generates the "show" functions to take a format parameter to allow future files to display in other formats. No functional change. Signed-off-by: Tony Luck --- drivers/base/topology.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/base/topology.c b/drivers/base/topology.c index fc24e89f9592..044f3664f8f2 100644 --- a/drivers/base/topology.c +++ b/drivers/base/topology.c @@ -14,11 +14,11 @@ #include #include =20 -#define define_id_show_func(name) \ +#define define_id_show_func(name, fmt) \ static ssize_t name##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \ { \ - return sysfs_emit(buf, "%d\n", topology_##name(dev->id)); \ + return sysfs_emit(buf, fmt "\n", topology_##name(dev->id)); \ } =20 #define define_siblings_read_func(name, mask) \ @@ -42,20 +42,20 @@ static ssize_t name##_list_read(struct file *file, stru= ct kobject *kobj, \ off, count); \ } =20 -define_id_show_func(physical_package_id); +define_id_show_func(physical_package_id, "%d"); static DEVICE_ATTR_RO(physical_package_id); =20 #ifdef TOPOLOGY_DIE_SYSFS -define_id_show_func(die_id); +define_id_show_func(die_id, "%d"); static DEVICE_ATTR_RO(die_id); #endif =20 #ifdef TOPOLOGY_CLUSTER_SYSFS -define_id_show_func(cluster_id); +define_id_show_func(cluster_id, "%d"); static DEVICE_ATTR_RO(cluster_id); #endif =20 -define_id_show_func(core_id); +define_id_show_func(core_id, "%d"); static DEVICE_ATTR_RO(core_id); =20 define_siblings_read_func(thread_siblings, sibling_cpumask); @@ -87,7 +87,7 @@ static BIN_ATTR_RO(package_cpus, 0); static BIN_ATTR_RO(package_cpus_list, 0); =20 #ifdef TOPOLOGY_BOOK_SYSFS -define_id_show_func(book_id); +define_id_show_func(book_id, "%d"); static DEVICE_ATTR_RO(book_id); define_siblings_read_func(book_siblings, book_cpumask); static BIN_ATTR_RO(book_siblings, 0); @@ -95,7 +95,7 @@ static BIN_ATTR_RO(book_siblings_list, 0); #endif =20 #ifdef TOPOLOGY_DRAWER_SYSFS -define_id_show_func(drawer_id); +define_id_show_func(drawer_id, "%d"); static DEVICE_ATTR_RO(drawer_id); define_siblings_read_func(drawer_siblings, drawer_cpumask); static BIN_ATTR_RO(drawer_siblings, 0); --=20 2.31.1 From nobody Tue Jun 30 08:09:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19F31C433FE for ; Fri, 21 Jan 2022 17:48:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381893AbiAURsD (ORCPT ); Fri, 21 Jan 2022 12:48:03 -0500 Received: from mga11.intel.com ([192.55.52.93]:56027 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381874AbiAURrx (ORCPT ); Fri, 21 Jan 2022 12:47:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642787273; x=1674323273; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N+co8tEkQjoAeDjwR0blfw9dvM9PZw/t3tAiJZXmM9c=; b=AMuKdR1EYJZ6nZfOklxbhy5CSdNpZAqLEqEVWkpff58ZIyw/SeWNsI5u QOyGPnnZE6Ds2oEJ4IlQqERNuFQLu6m1yhfJ9lHAgqf2yJAvDB0bPB13q gEdWqr2yl463MNOC6q7e3oh2lDjfqW6APc25l3yOISNuyTikm5FbkNT6c sfiVeGEKPXrM8hyJHch86rT9tXNSj2vTggh1ukAJeCPMQ+HVwnoRNOGIP 1UpbaUSUWDdm77CslT56pFIUI11mRwyva+aaGyOFBAxWtoOzSe93YhDwz ebXapCt5n2P13H7Vh1yzneIbZ520x6Ng2+foeu0cLw6FwXOq/78tBvw56 g==; X-IronPort-AV: E=McAfee;i="6200,9189,10234"; a="243302307" X-IronPort-AV: E=Sophos;i="5.88,306,1635231600"; d="scan'208";a="243302307" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2022 09:47:52 -0800 X-IronPort-AV: E=Sophos;i="5.88,306,1635231600"; d="scan'208";a="623394804" Received: from agluck-desk2.sc.intel.com ([10.3.52.146]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2022 09:47:52 -0800 From: Tony Luck To: Borislav Petkov Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Smita Koralahalli Channabasappa , Wei Huang , Tom Lendacky , patches@lists.linux.dev, Tony Luck Subject: [PATCH v2 6/6] topology/sysfs: Add PPIN in sysfs under cpu topology Date: Fri, 21 Jan 2022 09:47:43 -0800 Message-Id: <20220121174743.1875294-7-tony.luck@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220121174743.1875294-1-tony.luck@intel.com> References: <20220107225442.1690165-1-tony.luck@intel.com> <20220121174743.1875294-1-tony.luck@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" PPIN is the Protected Processor Identification Number. This is used to identify the socket as a Field Replaceable Unit (FRU). Existing code only displays this when reporting errors. But this makes it inconvenient for large clusters to use it for its intended purpose of inventory control. Add ppin to /sys/devices/system/cpu/cpu*/topology to make what is already available using RDMSR more easily accessible. Make the file read only for root in case there are still people concerned about making a unique system "serial number" available. Signed-off-by: Tony Luck --- Documentation/ABI/stable/sysfs-devices-system-cpu | 4 ++++ Documentation/ABI/testing/sysfs-devices-system-cpu | 6 ++++++ arch/x86/include/asm/topology.h | 1 + drivers/base/topology.c | 4 ++++ include/linux/topology.h | 3 +++ 5 files changed, 18 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-devices-system-cpu b/Documentat= ion/ABI/stable/sysfs-devices-system-cpu index 3965ce504484..902392d7eddf 100644 --- a/Documentation/ABI/stable/sysfs-devices-system-cpu +++ b/Documentation/ABI/stable/sysfs-devices-system-cpu @@ -86,6 +86,10 @@ What: /sys/devices/system/cpu/cpuX/topology/di= e_cpus Description: internal kernel map of CPUs within the same die. Values: hexadecimal bitmask. =20 +What: /sys/devices/system/cpu/cpuX/topology/ppin +Description: per-socket protected processor inventory number +Values: hexadecimal. + What: /sys/devices/system/cpu/cpuX/topology/die_cpus_list Description: human-readable list of CPUs within the same die. The format is like 0-3, 8-11, 14,17. diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documenta= tion/ABI/testing/sysfs-devices-system-cpu index 61f5676a7429..74962c200790 100644 --- a/Documentation/ABI/testing/sysfs-devices-system-cpu +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu @@ -73,6 +73,7 @@ What: /sys/devices/system/cpu/cpuX/topology/core_id /sys/devices/system/cpu/cpuX/topology/physical_package_id /sys/devices/system/cpu/cpuX/topology/thread_siblings /sys/devices/system/cpu/cpuX/topology/thread_siblings_list + /sys/devices/system/cpu/cpuX/topology/ppin Date: December 2008 Contact: Linux kernel mailing list Description: CPU topology files that describe a logical CPU's relationship @@ -103,6 +104,11 @@ Description: CPU topology files that describe a logica= l CPU's relationship thread_siblings_list: human-readable list of cpuX's hardware threads within the same core as cpuX =20 + ppin: human-readable Protected Processor Identification + Number of the socket the cpu# belongs to. There should be + one per physical_package_id. File is readable only to + admin. + See Documentation/admin-guide/cputopology.rst for more information. =20 =20 diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topolog= y.h index 2f0b6be8eaab..43a89476a522 100644 --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -110,6 +110,7 @@ extern const struct cpumask *cpu_clustergroup_mask(int = cpu); #define topology_logical_die_id(cpu) (cpu_data(cpu).logical_die_id) #define topology_die_id(cpu) (cpu_data(cpu).cpu_die_id) #define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id) +#define topology_ppin(cpu) (cpu_data(cpu).ppin) =20 extern unsigned int __max_die_per_package; =20 diff --git a/drivers/base/topology.c b/drivers/base/topology.c index 044f3664f8f2..e9d1efcda89b 100644 --- a/drivers/base/topology.c +++ b/drivers/base/topology.c @@ -58,6 +58,9 @@ static DEVICE_ATTR_RO(cluster_id); define_id_show_func(core_id, "%d"); static DEVICE_ATTR_RO(core_id); =20 +define_id_show_func(ppin, "0x%llx"); +static DEVICE_ATTR_ADMIN_RO(ppin); + define_siblings_read_func(thread_siblings, sibling_cpumask); static BIN_ATTR_RO(thread_siblings, 0); static BIN_ATTR_RO(thread_siblings_list, 0); @@ -145,6 +148,7 @@ static struct attribute *default_attrs[] =3D { #ifdef TOPOLOGY_DRAWER_SYSFS &dev_attr_drawer_id.attr, #endif + &dev_attr_ppin.attr, NULL }; =20 diff --git a/include/linux/topology.h b/include/linux/topology.h index a6e201758ae9..f19bc3626297 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -211,6 +211,9 @@ static inline int cpu_to_mem(int cpu) #ifndef topology_drawer_id #define topology_drawer_id(cpu) ((void)(cpu), -1) #endif +#ifndef topology_ppin +#define topology_ppin(cpu) ((void)(cpu), 0ull) +#endif #ifndef topology_sibling_cpumask #define topology_sibling_cpumask(cpu) cpumask_of(cpu) #endif --=20 2.31.1