Re: [PATCH v7 3/6] x86/topology: Disable CPU online/offline control for TDX guest

From: Thomas Gleixner
Date: Sun Oct 17 2021 - 15:23:51 EST


On Tue, Oct 05 2021 at 16:05, Kuppuswamy Sathyanarayanan wrote:
>
> +static int tdx_cpu_offline_prepare(unsigned int cpu)
> +{
> + /*
> + * Per Intel TDX Virtual Firmware Design Guide,
> + * sec 4.3.5 and sec 9.4, Hotplug is not supported
> + * in TDX platforms. So don't support CPU
> + * offline feature once it is turned on.
> + */
> + return -EOPNOTSUPP;
> +}
> +
> unsigned long tdx_get_ve_info(struct ve_info *ve)
> {
> struct tdx_module_output out = {0};
> @@ -451,5 +464,8 @@ void __init tdx_early_init(void)
> pv_ops.irq.safe_halt = tdx_safe_halt;
> pv_ops.irq.halt = tdx_halt;
>
> + cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "tdx:cpu_hotplug",
> + NULL, tdx_cpu_offline_prepare);

Seriously? This lets the unplug start, which starts to kick off tasks
from the CPU just to make it fail a few steps later?

The obvious place to prevent this is the CPU hotplug code itself, right?

Thanks,

tglx
---
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 192e43a87407..c544eb6c79d3 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1178,6 +1178,8 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,

static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target)
{
+ if (cc_platform_has(CC_HOTPLUG_DISABLED))
+ return -ENOTSUPP;
if (cpu_hotplug_disabled)
return -EBUSY;
return _cpu_down(cpu, 0, target);