Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2531803lqb; Tue, 28 May 2024 02:56:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXTbY5rwDHyZNndMaYhkEUEsTkDWFjMb6m/1G6bchdQZmAiRL8PwR72AQLxNxjbthBFT9N1TS9T+H6Vk93PG17vndoCpcsrNWe+zMu0OQ== X-Google-Smtp-Source: AGHT+IHLWeATJAIiB/TVwW4sISZVXsayqveoJg36m/olTtCDl4yx/fLrjruPpNxMucBuqoQjfI4n X-Received: by 2002:a19:8c07:0:b0:519:5df9:d945 with SMTP id 2adb3069b0e04-529642048d7mr6737085e87.4.1716890162751; Tue, 28 May 2024 02:56:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716890162; cv=pass; d=google.com; s=arc-20160816; b=ako/mtEo+g72rsmcDClUjlmGyA9ekdMoCoN97b2y4m/BnYUX2oYYzfeiVp+/dkR637 0dsBK/x8OT8dQYAERUl/hdRDfnR1e2qbW4O+XL/zRSOzRwajCQYUk0KBr4a4xDD+FcOs T2OjJxSTzltmsZZlKKVDHR9S5VkO2dyZ1ofd7hPU948+pN0Kb6f4ISFcyhcjTIkwfzJN fVUnCCEUozHkQ0MlhNPErKoxDCiM+OTywcH2gGdZu1FvfW6hhOP7qqI69CnvHpIJ9xBh rhpSa5ILQO4O5KSx8yiwDT/otKq3mr6JFROdHEToBiDPmO19wKlUPNav6WcPZkAXzNe5 svDA== 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=mXttbHtwH5DP0jR0R0CfNnAFAdX+mWadH0wP4r2iUfo=; fh=jKzY+IJTxktZ685R93VhJUbGF0rvTl3iTwtLazyIugI=; b=BRqwQLavcO9YeR65afauDopCUZtNhfi4n1VGNv1YzbzN3yxgku9N3ThSPvnJMm/MVg rE5cvXcbg/oaKknHMcURC1uxRApYejM2uJLz036kjfrJoeIGft1BWAqcSUnMKKUdpg2h tmOyw0EhBn314FS029nhYYWwy9hyZ1Gow3kF+tYoSMlvJqFxc8zqBx0tbaCgak0yRysP 5L4IonGmRC/tTasYY32O7WA+cF4+JTYvYC/ywv9uyIyFrPyC1il/Xvvvhj4ZNLkDoZgL AZlR2o1akhww9ZWicizsCGAH2L+oD2JYPN/bKHOZBBaPvyqWuLW7TggeJpDCB1k/3b7x MFew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="m7/ybmW0"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-192040-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192040-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 4fb4d7f45d1cf-579c5bf2a6esi2954317a12.237.2024.05.28.02.56.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 02:56:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192040-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="m7/ybmW0"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-192040-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192040-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 4B5741F239FD for ; Tue, 28 May 2024 09:56:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A0B5716B741; Tue, 28 May 2024 09:55:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="m7/ybmW0" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 5425316ABDE; Tue, 28 May 2024 09:55:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716890138; cv=none; b=ju2cUgBVKDehZa6HaAKtZTUjPeeBHfdByysbtDHsWfdYwx2/NhyLZVaJnf5Fvf77DbQ/uRupSpuFtviMwnus0tqlHuLUbo7OORM4M5I+ew8VBWacJpBYvZUrAG/plzXAWKftypbRKCwF2cs9Ea64n9abKcBikrwWn9Og3ewJpRk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716890138; c=relaxed/simple; bh=W1xBDWeB8dfl4ZPzx4TlsHLEKllNuJJtmLT3yCnOy/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CqVAOO4bc8ICp9g0IXyUVHehIYv10U/gkJNl7SO+9uShETjSuXuEPRlbTOuSuiXWUucIMAnEzhhxPEatnLlHyzifbcsGagD09c/e9xlQRy3PRBiP/mnxMWtbopdJ0E7/KZhESu1ej1j7LOKo/KbA/PmYhsJ8RX+QojqRa9ly+08= 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=m7/ybmW0; arc=none smtp.client-ip=192.198.163.17 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=1716890138; x=1748426138; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W1xBDWeB8dfl4ZPzx4TlsHLEKllNuJJtmLT3yCnOy/w=; b=m7/ybmW08OprdQqvDLpkljiJX1c7kOiN9hhGdW7ppJg+mVeBYiFOdM+C cxFfxqB5a7mm4ns0Md+5GHJ9YfR870sRz8ACFKdDoT5MoJZgj3KhJgBOy ZZgA9Grujnzz3/tROm2qha+oQZQBmfItdbOatwuhsp/6QzBW9aBak7yZo obUMVolE+gZOgTQUjMeENl91bblXlpRX/WQuWF85UG/+c4NcAwgczGVJ0 nSVdBubtVHJZKrBT/fhDZl780BFWGBPJg0C3eH6nbgqQRQoIEWKHZef9P y7XBChHdxs1UcpCiVnd1wSZ0Huy1JYaYldvZ3xgimb2zwVCYsNWWIvWdI g==; X-CSE-ConnectionGUID: N4O5hmLlSUabZzkSIsRMag== X-CSE-MsgGUID: 2+WaBxfjS4Kslb97NvHT7Q== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13097660" X-IronPort-AV: E=Sophos;i="6.08,194,1712646000"; d="scan'208";a="13097660" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 02:55:33 -0700 X-CSE-ConnectionGUID: 3Zgx/G49TAaBh0wSKaB0wQ== X-CSE-MsgGUID: WOa9Jnx0Quutj4Qhanc77A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,194,1712646000"; d="scan'208";a="34951654" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 02:55:27 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 5912843A; Tue, 28 May 2024 12:55:26 +0300 (EEST) 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" , Ard Biesheuvel , Baoquan He , "H. Peter Anvin" , "Kirill A. Shutemov" , "K. Y. Srinivasan" , Haiyang Zhang , kexec@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-acpi@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Tao Liu Subject: [PATCHv11 03/19] cpu/hotplug: Add support for declaring CPU offlining not supported Date: Tue, 28 May 2024 12:55:06 +0300 Message-ID: <20240528095522.509667-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240528095522.509667-1-kirill.shutemov@linux.intel.com> References: <20240528095522.509667-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 Tested-by: Tao Liu --- 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 861c3bfc5f17..6e265b085f95 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 563877d6c28b..4c15b478e2bc 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 @@ -1471,7 +1481,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