topology/sysfs: Add PPIN in sysfs under cpu topology
authorTony Luck <tony.luck@intel.com>
Mon, 31 Jan 2022 23:01:11 +0000 (15:01 -0800)
committerBorislav Petkov <bp@suse.de>
Tue, 1 Feb 2022 15:36:42 +0000 (16:36 +0100)
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 <tony.luck@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20220131230111.2004669-6-tony.luck@intel.com
Documentation/ABI/stable/sysfs-devices-system-cpu
Documentation/ABI/testing/sysfs-devices-system-cpu
arch/x86/include/asm/topology.h
drivers/base/topology.c
include/linux/topology.h

index 3965ce504484a2ef8e2e01fcb1feda008a4699fa..902392d7eddf03e84e1e7cd420e715d2e0239898 100644 (file)
@@ -86,6 +86,10 @@ What:           /sys/devices/system/cpu/cpuX/topology/die_cpus
 Description:    internal kernel map of CPUs within the same die.
 Values:         hexadecimal bitmask.
 
+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.
index 61f5676a7429a440dd9bc0d6e919f5750ba2aa12..74962c2007902dc295424291429a1542676fa573 100644 (file)
@@ -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 <linux-kernel@vger.kernel.org>
 Description:   CPU topology files that describe a logical CPU's relationship
@@ -103,6 +104,11 @@ Description:       CPU topology files that describe a logical CPU's relationship
                thread_siblings_list: human-readable list of cpuX's hardware
                threads within the same core as cpuX
 
+               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.
 
 
index 2f0b6be8eaabcf14c9aa8e4a770e17cd104445bb..43a89476a5222f43ed0b33f5e4abf698c090e28f 100644 (file)
@@ -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)
 
 extern unsigned int __max_die_per_package;
 
index 044f3664f8f22e0c52af3f13662664adf8efbb16..e9d1efcda89b3be1c4d8f12509c170b8957cb470 100644 (file)
@@ -58,6 +58,9 @@ static DEVICE_ATTR_RO(cluster_id);
 define_id_show_func(core_id, "%d");
 static DEVICE_ATTR_RO(core_id);
 
+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[] = {
 #ifdef TOPOLOGY_DRAWER_SYSFS
        &dev_attr_drawer_id.attr,
 #endif
+       &dev_attr_ppin.attr,
        NULL
 };
 
index a6e201758ae9e8c3d4f4fc265dda84768e3e7a99..f19bc3626297ad76c113a5f492032dfb6b7d9856 100644 (file)
@@ -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