From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) (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 3E70719BC0 for ; Thu, 5 Oct 2023 13:16:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hc6OGXnB" Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696511796; x=1728047796; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qwslEXpVpdjmSlqhv7KA+43haihOLBSreW4A7xlGLmo=; b=hc6OGXnBT56ngKted3U5B2OITJH8+QG9Bwb7ybJkgAcoa42G+/1cQxKh t8W2fc4DsRO6uKlK9CW6sjVCEH1+1vyXK5u5JXDNHXfPvkRr8npMkIX9b w7vWswtwYMmJtTYoLszOWDfoE8wqfsxmyCoQTmUxVN3FnfhaaRnBZtiQH FYOTar6JSBzy964wNkLLg4BEz+zry98zNJRr7u1NwQv0ycC17MRo/Ifz+ 3HfjkA7qkdAjxOeE86cXyU2QHINixSvAXrEJN+tCB+5V36BKdsMT91pzY KxPikbPbYF2SMmqS9qBdLr5q0BPWPJ/J4O8BKm73Ts1FyyIOche3V/pdW Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="380767063" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="380767063" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 06:14:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="728449205" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="728449205" Received: from skwasnia-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.222.71]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 06:14:16 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 2144510A12F; Thu, 5 Oct 2023 16:14:14 +0300 (+03) 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 , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCH 02/13] kernel/cpu: Add support for declaring CPU hotplug not supported Date: Thu, 5 Oct 2023 16:13:51 +0300 Message-ID: <20231005131402.14611-3-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231005131402.14611-1-kirill.shutemov@linux.intel.com> References: <20231005131402.14611-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The function cpu_hotplug_not_supported() can be called to indicate that CPU hotplug should be disabled. It does not prevent the initial bring up of the CPU, but it stops subsequent offlining. This function is intended to replace CC_ATTR_HOTPLUG_DISABLED. Signed-off-by: Kirill A. Shutemov --- include/linux/cpu.h | 2 ++ kernel/cpu.c | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/linux/cpu.h b/include/linux/cpu.h index f19f56501809..aab3887cadbc 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -132,6 +132,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_not_supported(void); extern void cpu_hotplug_disable(void); extern void cpu_hotplug_enable(void); void clear_tasks_mm_cpumask(int cpu); @@ -147,6 +148,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_not_supported(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 6de7c6bb74ee..cf536fe1a88a 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -484,6 +484,9 @@ static int cpu_hotplug_disabled; DEFINE_STATIC_PERCPU_RWSEM(cpu_hotplug_lock); +/* Cleared if platform declares CPU hotplug not supported */ +static bool cpu_hotplug_supported = true; + void cpus_read_lock(void) { percpu_down_read(&cpu_hotplug_lock); @@ -543,6 +546,18 @@ static void lockdep_release_cpus_lock(void) rwsem_release(&cpu_hotplug_lock.dep_map, _THIS_IP_); } +/* + * Declare CPU hotplug not supported. + * + * It doesn't prevent initial bring up of the CPU, but stops offlining. + */ +void cpu_hotplug_not_supported(void) +{ + cpu_maps_update_begin(); + cpu_hotplug_supported = false; + 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 @@ -1507,7 +1522,7 @@ 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_supported) return -EOPNOTSUPP; if (cpu_hotplug_disabled) return -EBUSY; -- 2.41.0