Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2209069rbb; Tue, 27 Feb 2024 14:31:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXk+L9EIO9zm/xcUNrzO4dAoqn1jdXpFahT1spSNJdhKVOJkHq4uE9+uRR7f/Z8okzi0QtsLrtW6E+X8ywuQ8/JAEMP/z5XNst9suohNA== X-Google-Smtp-Source: AGHT+IERADmccyxgdfKXXDkn4JGiJRhuVwTXDzFcElj2agHYw6PLYfcHOGKJ+2oWIEkL2Y3TRIqd X-Received: by 2002:a05:6214:cae:b0:68f:8ddd:aad3 with SMTP id s14-20020a0562140cae00b0068f8dddaad3mr4328736qvs.20.1709073103163; Tue, 27 Feb 2024 14:31:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709073103; cv=pass; d=google.com; s=arc-20160816; b=HYUsOTRTPdhljhjjKxzlIQ+mm5ZBQ1aCr/FXJ5jBV9pHGVcaMyTvtDW4lxwdItgTvM dtqQ352OQp48nVv1kwXxJaC3VR7Rae+ByUWEG3CNEdkxOkqBVru5Chq4hjr0b2NfJ6Qb 3V/YqC5wF1y1YFr7Zbco8rxuNWwAiOzlGVWCyI4tJhKVSJX/y9Sf6+FJ4NQtrzCtS0O9 DVT8+YqA3BdarO0Q5cKXicPBiaZC4m6YJ39BjOxxtiqMGo2spjmL5qrrUz83gDXfUYqr d1dEu4pNoZJzLBb0CwF1Qe4inIcl7ThLQ3Efp+od/DJn4m27ekSrcbyNNNmfzKwuxjMX e1aQ== 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=etMHlUsR1BlqAlrOQjvDNHmUlD8AOOr+8TmindilXy8=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=S8T5BtzlgkTxh0SNx1SuTSBTX/3mIi43tCLxe0nVDI8RK/f476AtlJFMY28Yh2RFSz bswejApUUOfmsrSNl7a/G6nK5+UzkkxfRVKj3cwS4n5JxkRA784Rb0HYk9D+IwnvlL7e q/v9Lx392RTg2ykN0O4Uj+jJ5eTH1CyKDgVp1iNZDGqytoUUtWeRIZp7l+Hlz2sqFZDn kfu3XkbhLtBy5+kcPADS6pxUwhq3FAhGvW3mAmvKOnR+TG6YaqNhEeGXSZOLyMLbff63 lA3FeqFMZR7bmRXiVDXtyvkfuW/BLnA4SNNaEOyrh8HSrnhqBTYiPViVvV0VTuwYi8Zc lX6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Hx2Fp6B3; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84036-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84036-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id fo12-20020ad45f0c000000b0068fd04b360dsi8313302qvb.255.2024.02.27.14.31.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:31:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84036-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Hx2Fp6B3; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84036-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84036-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 38E791C2475F for ; Tue, 27 Feb 2024 21:25:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB85D1534F6; Tue, 27 Feb 2024 21:25:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Hx2Fp6B3" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 8706F14F995 for ; Tue, 27 Feb 2024 21:25:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069107; cv=none; b=EiP81H1VR1khtkZEYgfQ+rR8a/FRulyTPqXQRqzY9AFtDLSu1dJzv5N85ETiP0sH47M25ko/H6W50GdhAQVrPLC3A4jGktKA8q3LzshC9wuAV7WQyLr9Skzeb0pWcXYcjBVVKvgwbDxdcHE9b051MaCaKoogAbT1i6V7eNGBIGw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069107; c=relaxed/simple; bh=G+mf0uc9JWYLESD7E7QcyEIUu6FPmOWbeObWlqzAyE8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KwotWAeUjHngAN72XIugARHMqc/MdQlyPdkkawoNFkD066SmNF2DZy4wC69U+nz2a40Wbw7q0zEWJWEtd/5AZLT2EaPeuK9rQjH1Y6BQwlH03cLbmnjZqPvNUAWHhCp/uGL5FiaYOwm8+ThZ1thOo9XBddb2HvpV3Shwnpqs2xI= 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=Hx2Fp6B3; arc=none smtp.client-ip=198.175.65.16 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=1709069107; x=1740605107; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=G+mf0uc9JWYLESD7E7QcyEIUu6FPmOWbeObWlqzAyE8=; b=Hx2Fp6B3SmLVL70IRNE2JJrQevobxQyEg1tP62AP39RVcgFPTaDsRdI3 2b4AYnIWzKCKKQWE0s945AN2c37yBcyjUl0g0w2WGuL4xnfYzD8Gj7Ak9 bqlHxtHBHjvgSV/5FUeph3MwfSNiR2WD0d47NAwVNw6BUDrfrtfF0DgeE XKj+kJvTRn8eBj5jMj81ixEodGY6BM75QayEsIFaFcear+eTv5xMOcEvy 08i1FXc0URakzCSLI3wmbuL4l79LJaO9h24XGHkQ1AJRHl6XdE3a0meLo wZWl0K8PGr67VI/P8T/RmdcwIHRkPHFsFmoXcOtNtmmlmOsxF1De9Pw04 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3566944" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3566944" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032894" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032894" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:24:57 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 00DFC524; Tue, 27 Feb 2024 23:24:55 +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: [PATCHv8 03/17] cpu/hotplug: Add support for declaring CPU offlining not supported Date: Tue, 27 Feb 2024 23:24:38 +0200 Message-ID: <20240227212452.3228893-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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 dcb89c987164..aa89ef93a884 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -139,6 +139,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); @@ -154,6 +155,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 7b36b3a4e336..ac6af196c6f5 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 @@ -1521,7 +1531,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