Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1115945rdb; Fri, 22 Dec 2023 15:52:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJfA1BsgyXA7FV+41NCqRBorlyRmDSzaXi2KoEsj6pjs/jHtkoE04zplqroxY8LjsK3sBW X-Received: by 2002:a05:6a20:7491:b0:195:2422:cb0e with SMTP id p17-20020a056a20749100b001952422cb0emr2488300pzd.74.1703289149793; Fri, 22 Dec 2023 15:52:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703289149; cv=none; d=google.com; s=arc-20160816; b=c655NseRi7WJeB+G9SRj2TCHYUNENvD961nxILTM8Q2YnAUHuZ0ssgi9IUPLdYt7xq B2goUppfBBPEQIFt32r4NJ6U+lsZFibQqBNQGv+QetrpnOrRGaMg9RxjbxXRm/7SXgEG uM0cOgAFz1heOySdwShcGEkIhqfrnw7AQtzl3DEk/PMrnZGoi09pvpS9ID3rEbiR6zsB BdUfINRYvPbHHCyjUwkb8Eh6zsm0F2R7nWkjsjGkvgcI+sY4PhLElolZrk8YfT1IzT8X gSsz146eXW2k5NKrra4G20+qeP9oNFt3nYvOPXxzPJDEOqBSVQOKmc2XCjNDwYQkdWIw qqqA== ARC-Message-Signature: i=1; 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=2cwgFsL35m9cHr/GxnxY7uCFzaSGymYuHPWXB5iwyH0=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=MWFOs4/8MrCEg9HZaNcdH75vX8pi7W/DnCWnT1smy/fp9aO4mR0oKjoWXiRd4feTuK ADpb21GzGPmxpZ63ec61IBMagBlkp4pI6bch1HpeierRiTiE2NfWWcO2FWxNdT6h+jab 0rQzS0v5XYfhmSjVwRdvKqyOxkBdg9dbsgdyCjOUqqmWU5OqBWjNihKeiwflY1n9smQz wKCczXbmJWe0GYyb6WeyyVkG/K2AURGH6ftx3B0WhjoyWa3zvcF9x0KXJrKFYpfgLv1K ImA+Wi7rCEWqmZHSQkQ4AAJq5QUAKHLRn4qL/j0oxebUc1YjXdTl/Z9qabTB9gm/JWgJ 0P9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=K2Rn8i19; spf=pass (google.com: domain of linux-kernel+bounces-10127-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10127-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h15-20020a63384f000000b005cd7caf17fbsi3943054pgn.408.2023.12.22.15.52.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 15:52:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10127-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=K2Rn8i19; spf=pass (google.com: domain of linux-kernel+bounces-10127-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10127-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 6A840285520 for ; Fri, 22 Dec 2023 23:52:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C85CB35F0C; Fri, 22 Dec 2023 23:52:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="K2Rn8i19" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (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 9C8F135EF0 for ; Fri, 22 Dec 2023 23:52:20 +0000 (UTC) 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.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=1703289140; x=1734825140; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=T8BKWP6fuDFLYxqPc0eo/JEZQ8dEYm6Dve4qyWl3al0=; b=K2Rn8i19WO6hEZQUiA3JlXhUxI8jnP1GhZLQZ485rRECWuyVNwDIzIQW Y/7KdzcnfwELsrKPZxgYJ5PK0Hv/MozAaolq0JIE4NyZKQEgVM/Dz4qf5 lU8powm1nId3rloo0qc0r8LkpIw9rUXOJfo5b7Nzs3+3oxak5shjn041W docULPa975WoQ6Mf+MWfhVhArFOX/i10Ko5vf07Q9t6Wbed9jp0lmAeCz kaDHMy+j3QLKC0bZY8luKSFv/1XeFru1eUpYUl57JkVIGlCkJZhyW0cES /jaOuKvZnhY4ZwY7rpWH3eMKq7jz86YCoiHdIGlHuF1ghYSdDeZ6sYEjX A==; X-IronPort-AV: E=McAfee;i="6600,9927,10932"; a="395063268" X-IronPort-AV: E=Sophos;i="6.04,297,1695711600"; d="scan'208";a="395063268" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 15:52:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10932"; a="900622981" X-IronPort-AV: E=Sophos;i="6.04,297,1695711600"; d="scan'208";a="900622981" Received: from jeroenke-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.35.180]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 15:52:14 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id EC65710A471; Sat, 23 Dec 2023 02:52:11 +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 , "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: [PATCHv5 03/16] cpu/hotplug: Add support for declaring CPU offlining not supported Date: Sat, 23 Dec 2023 02:51:55 +0300 Message-ID: <20231222235209.32143-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231222235209.32143-1-kirill.shutemov@linux.intel.com> References: <20231222235209.32143-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 fc8094419084..46f2e34a0c5e 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -134,6 +134,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); @@ -149,6 +150,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 a86972a91991..a2e17f085079 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -484,6 +484,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); @@ -543,6 +545,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 @@ -1522,7 +1532,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.41.0