Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2718878lqp; Mon, 25 Mar 2024 07:28:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVFBAeE5ERyo2FgVGgdr4w++a27/fY0AikvKS2GXUzwjplx98mqJyJ/fH14SDDHP88dw+NDMC89kp9aiw0UrzS02s/UgTW9lBrI57zsVw== X-Google-Smtp-Source: AGHT+IHpNY8D2dbEv9AmMZhgbuoqQtr7RS/TzPefMOspDuKttDox3x9VrnYMc2kYAkKFQEoLd9fa X-Received: by 2002:a2e:6a04:0:b0:2d4:8d75:7a64 with SMTP id f4-20020a2e6a04000000b002d48d757a64mr5621531ljc.13.1711376930778; Mon, 25 Mar 2024 07:28:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711376930; cv=pass; d=google.com; s=arc-20160816; b=ATeCcl8kOeUZwO9GTgsrulhc40Bcvxwu6h7infQYEhaFXGnuF14Xut7LSHDd6w8Tib XMCEnob//dH7FFNQAiiGi5fENdwP4Gvkq3+VigNEcI5LzjXu8uZfCOMU2oAxk+TapVD0 +JqvnraBM0sVTNqcgtvvwHolH2ciboMd3WsMTOPEkFvpa3mhJeDRQsOmy+1qZIS2I1eK peHoqoTtBoRU6S2Q3Y7PFURf1/YrVR0lRsgJpCPb+JP0kd7eP5srfV3T0+umqegxP8rT Js/iFGxAJrEBwz7rnN/xCf8iHucIz3dUKLD05vLRYlUx59xvU9JKhEejq93cffkpfC3N Dt8w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=SUBsmbumuHVQRMcCzz7bWDgBejG9HMlrY+COfp29WsQ=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=xBH+D+GAICq5raZXJYL4b5z6WBHZCv5F9GxB59mqSYK2pzYrWtEoY/fDsZ4sl3JBD4 gyfLwtcVtofs5PDyQaciIXYd46E6RbMSWiJ122J25MgsN8Jxkb4XmV7daKH8+BYPrkPV RnZHZLSx8a/JG2bnB0etdejbwm2IcDdbwnV2KHlZ8po4/j4ADTZg7ypcxoKwktZq24Yy aPGP4lprP9RUnNkIGhJpJyWi/rWNqfx2Y4Syez8DXdxNfl9jb5QzgfV+WXXjLB6Th//s FQiBv6Qy9sJLWjqFtZDWsFxFOy+FZ/73F0rVpzsZBQDleqolp/fTjB0firlL2nZUq9I2 sHZQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=j09jTwUY; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-116854-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116854-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id jz14-20020a170906bb0e00b00a46bcd6b654si2622760ejb.433.2024.03.25.07.28.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 07:28:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116854-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=j09jTwUY; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-116854-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116854-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 511921F62509 for ; Mon, 25 Mar 2024 14:28:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2527B1856DB; Mon, 25 Mar 2024 11:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="j09jTwUY" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCF2A14A4C6 for ; Mon, 25 Mar 2024 10:40:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363217; cv=none; b=bnkcjs2PE8xPZTObAnTpc2lMzyV6sNUPeldY4V/00S6fDe4bukuVdgbzvABAht8XICT2OybTURp5hOqg3t8H/r7AyL8Oj8T6Idjk/As09IWlUJeGm0pQZRXO9nMSPWRXLDS1moff/a53HKVShV1enDmDav/Y91z7oDahUhOj29U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711363217; c=relaxed/simple; bh=8vFnr3Q3IphY3txxegY5cysnm69dmjkFAnV1L+0G+mg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=szwQNwkQcGHi97pifSA1K+2+sl1Wnl7PylNUduLlN4skXLUuW+9KQKDcowWK/AcZ91Z0BlQDVaC2HYwRLP9nb5344RRRV1fbkIa9s3XhQ/1rvBafMchiS4wbstfpLXG5Eua98fsoasNxPQ0WW7IDnh39Ht9pk8j4qLdxsmGmAVE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.helo=mgamail.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=j09jTwUY; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.helo=mgamail.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711363216; x=1742899216; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8vFnr3Q3IphY3txxegY5cysnm69dmjkFAnV1L+0G+mg=; b=j09jTwUY9vzDUvQuGKpRFHzd0q1k9R/BLHqsOFjWOW0dbBAK3Fgq1BMe 0/hjsNqpFtvCXQ4IM097NtOS75KcS4JyXeN7L1U5Pyw2gjcxFHOcI2DpS CN5XvE4BmiYDRBSc0xqKS4/oQO6ixVrJyFYKX9/Tz3D9OjJxQ0L3edzTT gWM+qNTH2glFFBbErlcAUbWtWcokJxmEl29v13CoWNAjIfJfECYMF5QY3 k+b8vJBQ+4jL+BRDCQolyPYBWvOlILJxuU5Iskx3wdW23Y3S2Jowqe82R NozLJBNDQSMoXh1o5ASeetP2TjbyFKjgc3f40N5+Rh2pC6isXSdmOFTIq Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="6561320" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="6561320" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 03:40:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070133" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="937070133" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 03:40:05 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id EF22C484; Mon, 25 Mar 2024 12:40:04 +0200 (EET) From: "Kirill A. Shutemov" To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , "Huang, Kai" , Baoquan He , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv9 03/17] cpu/hotplug: Add support for declaring CPU offlining not supported Date: Mon, 25 Mar 2024 12:38:57 +0200 Message-ID: <20240325103911.2651793-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> References: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The ACPI MADT mailbox wakeup method doesn't allow to offline CPU after it got woke up. Currently offlining hotplug is prevented based on the confidential computing attribute which is set for Intel TDX. But TDX is not the only possible user of the wake up method. The MADT wakeup can be implemented outside of a confidential computing environment. Offline support is a property of the wakeup method, not the CoCo implementation. Introduce cpu_hotplug_disable_offlining() that can be called to indicate that CPU offlining should be disabled. This function is going to replace CC_ATTR_HOTPLUG_DISABLED for ACPI MADT wakeup method. Signed-off-by: Kirill A. Shutemov Reviewed-by: Thomas Gleixner --- include/linux/cpu.h | 2 ++ kernel/cpu.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/linux/cpu.h b/include/linux/cpu.h index ae5a20cf2f9c..2dd47d203d36 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -141,6 +141,7 @@ extern void cpus_read_lock(void); extern void cpus_read_unlock(void); extern int cpus_read_trylock(void); extern void lockdep_assert_cpus_held(void); +extern void cpu_hotplug_disable_offlining(void); extern void cpu_hotplug_disable(void); extern void cpu_hotplug_enable(void); void clear_tasks_mm_cpumask(int cpu); @@ -156,6 +157,7 @@ static inline void cpus_read_lock(void) { } static inline void cpus_read_unlock(void) { } static inline int cpus_read_trylock(void) { return true; } static inline void lockdep_assert_cpus_held(void) { } +static inline void cpu_hotplug_disable_offlining(void) { } static inline void cpu_hotplug_disable(void) { } static inline void cpu_hotplug_enable(void) { } static inline int remove_cpu(unsigned int cpu) { return -EPERM; } diff --git a/kernel/cpu.c b/kernel/cpu.c index 8f6affd051f7..08860baa6ce0 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -483,6 +483,8 @@ static int cpu_hotplug_disabled; DEFINE_STATIC_PERCPU_RWSEM(cpu_hotplug_lock); +static bool cpu_hotplug_offline_disabled __ro_after_init; + void cpus_read_lock(void) { percpu_down_read(&cpu_hotplug_lock); @@ -542,6 +544,14 @@ static void lockdep_release_cpus_lock(void) rwsem_release(&cpu_hotplug_lock.dep_map, _THIS_IP_); } +/* Declare CPU offlining not supported */ +void cpu_hotplug_disable_offlining(void) +{ + cpu_maps_update_begin(); + cpu_hotplug_offline_disabled = true; + cpu_maps_update_done(); +} + /* * Wait for currently running CPU hotplug operations to complete (if any) and * disable future CPU hotplug (from sysfs). The 'cpu_add_remove_lock' protects @@ -1518,7 +1528,8 @@ 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)) + if (cc_platform_has(CC_ATTR_HOTPLUG_DISABLED) || + cpu_hotplug_offline_disabled) return -EOPNOTSUPP; if (cpu_hotplug_disabled) return -EBUSY; -- 2.43.0