Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/topology: Disable CPU online/offline control for TDX guests

Unlike regular VMs, TDX guests use the firmware hand-off wakeup method
to wake up the APs during the boot process. This wakeup model uses a
mailbox to communicate with firmware to bring up the APs. As per the
design, this mailbox can only be used once for the given AP, which means
after the APs are booted, the same mailbox cannot be used to
offline/online the given AP. More details about this requirement can be
found in Intel TDX Virtual Firmware Design Guide, sec titled "AP
initialization in OS" and in sec titled "Hotplug Device".

Since the architecture does not support any method of offlining the
CPUs, disable CPU hotplug support in the kernel.

Since this hotplug disable feature can be re-used by other VM guests,
add a new CC attribute CC_ATTR_HOTPLUG_DISABLED and use it to disable
the hotplug support.

Attempt to offline CPU will fail with -EOPNOTSUPP.

Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Andi Kleen <ak@linux.intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20220405232939.73860-25-kirill.shutemov@linux.intel.com

authored by

Kuppuswamy Sathyanarayanan and committed by
Dave Hansen
bae1a962 77a512e3

+18
+1
arch/x86/coco/core.c
··· 20 20 { 21 21 switch (attr) { 22 22 case CC_ATTR_GUEST_UNROLL_STRING_IO: 23 + case CC_ATTR_HOTPLUG_DISABLED: 23 24 return true; 24 25 default: 25 26 return false;
+10
include/linux/cc_platform.h
··· 72 72 * Examples include TDX guest & SEV. 73 73 */ 74 74 CC_ATTR_GUEST_UNROLL_STRING_IO, 75 + 76 + /** 77 + * @CC_ATTR_HOTPLUG_DISABLED: Hotplug is not supported or disabled. 78 + * 79 + * The platform/OS is running as a guest/virtual machine does not 80 + * support CPU hotplug feature. 81 + * 82 + * Examples include TDX Guest. 83 + */ 84 + CC_ATTR_HOTPLUG_DISABLED, 75 85 }; 76 86 77 87 #ifdef CONFIG_ARCH_HAS_CC_PLATFORM
+7
kernel/cpu.c
··· 35 35 #include <linux/percpu-rwsem.h> 36 36 #include <linux/cpuset.h> 37 37 #include <linux/random.h> 38 + #include <linux/cc_platform.h> 38 39 39 40 #include <trace/events/power.h> 40 41 #define CREATE_TRACE_POINTS ··· 1187 1186 1188 1187 static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target) 1189 1188 { 1189 + /* 1190 + * If the platform does not support hotplug, report it explicitly to 1191 + * differentiate it from a transient offlining failure. 1192 + */ 1193 + if (cc_platform_has(CC_ATTR_HOTPLUG_DISABLED)) 1194 + return -EOPNOTSUPP; 1190 1195 if (cpu_hotplug_disabled) 1191 1196 return -EBUSY; 1192 1197 return _cpu_down(cpu, 0, target);