X-Received: by 2002:a17:90a:ab08:b0:1b9:c59:82c3 with SMTP id m8-20020a17090aab0800b001b90c5982c3mr15245344pjq.95.1645721040333; Thu, 24 Feb 2022 08:44:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645721040; cv=none; d=google.com; s=arc-20160816; b=lwg4VR3Hmg7LK1J1uP/SjhdkZYK+vAujUREfaALxtMmO1tedWqiOK/h3hlnfkLDjKh OsHGdh+Igw0FICf9rHWo3wnIynzrki1t+MCI7PzoUMjbz1hzUnzjtUb5e/fiVUylz6ha 4jJVucDaSTSldhYZexis502FF6EGM1j8HFlniRjss8u0TsIOnT5ZrW1ulxOLR4nh5zVg 2l+p6mJOibZrrFwFx47m/wf7Ytcz/qd4ItENt2BB1NLLrWCeAOAnU9FFTmsNBgOloX1g EoETcQ+yaluaMbBF/WIvHZrumv2PlUMgquq6I2A+YtUOuOKSuj8DHskw0Xx3JSdO5Mrb F06Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zIont4trCL+ZHXA4ZSt9ZmNDlCEzm2F8AYMTFiAUUMA=; b=U4YU2GAWxzPAIYmlFc29dL432oi5POQcMGloQD1KD/dT+9iqPC8DGnihAhFWfnUWZp G9GnBx7wOv2PMR97i0EzX5LKCTPCY8/TsIbq82EI02OJoXmZRQlWrlWTDbsIgtFg3D7e /XnPRAhaeL/PfS1alUD4q5Wiu2wshOb0FMzigy4Xcjn1hQixMlfbOaMwzizn3caYlTOx EMw3UQFBIVU1XSdXv8ifjaL2aidRhveqyOsbmntAt5iet+bhKd32DAG9oR0zhaeHdETN iSJzIZn5qYj1Nb2qk0ZVR06BvkOXfWooncJ5JOYsI8W0CUCpp4gLJb7n876e+UYffVQd Dt5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Nv6d/Dyy"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id g140si2303226pfb.344.2022.02.24.08.44.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 08:44:00 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Nv6d/Dyy"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E653C1D2B4E; Thu, 24 Feb 2022 08:23:24 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236226AbiBXP6M (ORCPT + 99 others); Thu, 24 Feb 2022 10:58:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236748AbiBXP5Q (ORCPT ); Thu, 24 Feb 2022 10:57:16 -0500 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D40264DB for ; Thu, 24 Feb 2022 07:56:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645718199; x=1677254199; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q7UkitiuT+GdBLhgi9ovK3JIVhbOcenWO7329OdQmvk=; b=Nv6d/Dyyt2LP9RlvlxOT9poaM0VSDGZa02nQFrc9o435u29zB6y9UKcw s+yki9cotfDQXj4oTTt/+uCmpSREn2W9NLk85SihLnjMows8NO2QhPHt9 MkzqOthk0a/K5vg0r/QzwqZTwmFEQxIakOPhxHMct78dmwE2F73I3QVgi nR243i6iw9m4AkWWn3AxSH1OsONTLpDPWecTOvEgmlzp9jk2BCoIZIlPT 4m0Lo9q1vV5aAwuAGuwIe4TqFNjAAc92Ewu/GU1eNHoODs16dR4Ps64Q9 JzcvSNQe/2MuzEpDfEzDwyuvD7neqfAlN/2dBSjzea9LkU3473VGAaJYn A==; X-IronPort-AV: E=McAfee;i="6200,9189,10268"; a="312983032" X-IronPort-AV: E=Sophos;i="5.90,134,1643702400"; d="scan'208";a="312983032" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2022 07:56:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,134,1643702400"; d="scan'208";a="506362100" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 24 Feb 2022 07:56:32 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 707DDB30; Thu, 24 Feb 2022 17:56:35 +0200 (EET) From: "Kirill A. Shutemov" To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@intel.com, luto@kernel.org, peterz@infradead.org Cc: sathyanarayanan.kuppuswamy@linux.intel.com, aarcange@redhat.com, ak@linux.intel.com, dan.j.williams@intel.com, david@redhat.com, hpa@zytor.com, jgross@suse.com, jmattson@google.com, joro@8bytes.org, jpoimboe@redhat.com, knsathya@kernel.org, pbonzini@redhat.com, sdeep@vmware.com, seanjc@google.com, tony.luck@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, x86@kernel.org, linux-kernel@vger.kernel.org, "Kirill A . Shutemov" Subject: [PATCHv4 24/30] x86/topology: Disable CPU online/offline control for TDX guests Date: Thu, 24 Feb 2022 18:56:24 +0300 Message-Id: <20220224155630.52734-25-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220224155630.52734-1-kirill.shutemov@linux.intel.com> References: <20220224155630.52734-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Kuppuswamy Sathyanarayanan 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. With hotplug disabled, /sys/devices/system/cpu/cpuX/online sysfs option will not exist for TDX guests. Signed-off-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andi Kleen Reviewed-by: Tony Luck Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/core.c | 1 + include/linux/cc_platform.h | 10 ++++++++++ kernel/cpu.c | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c index 5615b75e6fc6..54344122e2fe 100644 --- a/arch/x86/coco/core.c +++ b/arch/x86/coco/core.c @@ -20,6 +20,7 @@ static bool intel_cc_platform_has(enum cc_attr attr) { switch (attr) { case CC_ATTR_GUEST_UNROLL_STRING_IO: + case CC_ATTR_HOTPLUG_DISABLED: return true; default: return false; diff --git a/include/linux/cc_platform.h b/include/linux/cc_platform.h index efd8205282da..691494bbaf5a 100644 --- a/include/linux/cc_platform.h +++ b/include/linux/cc_platform.h @@ -72,6 +72,16 @@ enum cc_attr { * Examples include TDX guest & SEV. */ CC_ATTR_GUEST_UNROLL_STRING_IO, + + /** + * @CC_ATTR_HOTPLUG_DISABLED: Hotplug is not supported or disabled. + * + * The platform/OS is running as a guest/virtual machine does not + * support CPU hotplug feature. + * + * Examples include TDX Guest. + */ + CC_ATTR_HOTPLUG_DISABLED, }; #ifdef CONFIG_ARCH_HAS_CC_PLATFORM diff --git a/kernel/cpu.c b/kernel/cpu.c index f39eb0b52dfe..c94f00fa34d3 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #define CREATE_TRACE_POINTS @@ -1185,6 +1186,12 @@ 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 the platform does not support hotplug, report it explicitly to + * differentiate it from a transient offlining failure. + */ + if (cc_platform_has(CC_ATTR_HOTPLUG_DISABLED)) + return -EOPNOTSUPP; if (cpu_hotplug_disabled) return -EBUSY; return _cpu_down(cpu, 0, target); -- 2.34.1