Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2374873rdb; Mon, 12 Feb 2024 02:47:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX07GwUNaDbC4f3ukmOS1+i2gnkrgWt+g1LUArIkVe7tZzEusP+ajEM1kxoH667kyIp5G+1NcvuyPu7DwwgIuFHuDY3ankjuPLMyRolQQ== X-Google-Smtp-Source: AGHT+IEoaE3w+C9x4uDV9BpKx3qi2r0NXd9g7ONXaNZd+V5I8u0yeaHif6lsCqgQ5PSRGayKewAk X-Received: by 2002:ac8:5915:0:b0:42c:6e6b:2d75 with SMTP id 21-20020ac85915000000b0042c6e6b2d75mr7566550qty.44.1707734830282; Mon, 12 Feb 2024 02:47:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707734830; cv=pass; d=google.com; s=arc-20160816; b=xSTpP9ufPWMABnTozhxqG/dYjRDj/LXL2soJN6bmmdVfGQ/r6JSvl/QrVG/QPVNHW9 ULay1SKW2rQ6w0AnU1+r29rUJwtFQvbKmeRI1o/FKwDITBRg5VW/T/4jhr449ObnrLvx vvGQ618sPeKQQX4ht26vE2lHwYioQyRrcJ3IX9co/g8ti6KPH2E8uvf3eB+QPBo4psmz 2uckvGqz1CKxyHZs7pLwc7dpIbVc7XxONrZuHCU0GY0Kz87ADGiko0fd1q1+8StLv8c6 J3KYAVlshsQ+WNBSf4mmwK5eLm7x+uIPFKtDo/A9C7jCu+DGynSW2IG1Nz8Qzj6BHI/H ntqQ== 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=S26fjaDFAIJ37+8snV1yUJ/yjYua3qMKaCxClShx9iY=; fh=BOqRSMyz70JhSCbD0utGnFJ2GQx0K2pOjDx4gHnSeKs=; b=nOQGMoxtsMoOZTreAoQhCI9H3ENrcYa5XraR5WPAs505E4FnA5P15NCKb26zfM/BwV pZWUbxhESi6Bshhk3z/1kpK62UfkVgnGYgJm/5FpDoDGhmyzLkIqQ6Fn91JuN1ajbzyz mEnONTqA8zeX1L6pLvECTQ2fwhlJrPNVDbD8rGwizD9isBB5/vJxMqZNHePuz+wb4m12 MEN5Kr+qX+q8JYqBDyzn/VSSJKpT6TvXR63Af9IlqeriG0kDFwgSaTErK+1vWFSuDr0h crSwFi/5iCr75MtvN7S9jUOs5oaaipkIKmpf5JwqRlEo7MSrZUtu+213lNDnrgtpUUbM m/8g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PnwV2c1v; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61353-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61353-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCXvLaMxve8fs5MlZ3Sx6puZDqwbT+svuzWCZlXWSIc0UgmRGG3ZQgLJsXWDArt+90ZdAQkWFIqkP8q1O4lgxCSNGXiT/2tXwGIiFzCjQg== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b15-20020ac844cf000000b0042c5f480416si93535qto.22.2024.02.12.02.47.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 02:47:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61353-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=PnwV2c1v; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61353-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61353-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 F14B31C21F93 for ; Mon, 12 Feb 2024 10:47:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9EEA23A8E0; Mon, 12 Feb 2024 10:45:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="PnwV2c1v" 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 2221738FAA for ; Mon, 12 Feb 2024 10:45:04 +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=1707734705; cv=none; b=j5Yy8Es01cZJRuMF1XLQ0iUkcNxxF6nCeQWzxYPBt4rFCv5utT08SBikP/CslBI9NkTdxHXO1iLsK8hLMfqSijfLfe3J+kEr0wweFsa+pHR57rQ7Ak/AzMjgJ8lz2dLiv5BmmstnIHVR9mQZh3wWBdTOn2I3/3ZradUWLK8OB/0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734705; c=relaxed/simple; bh=yc+q4KsjIiSfEwY6TeHFKJsFn5r2uXtVujdyv1Did04=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rLsHg5UAdybKQSd6VHcS/saMJKm7BccfoJ0zcEgQQfhQYdW7/R5Xe07JW9OuozVvR5q6fusFpKWN5iuwy8PDyY8Z+OxGMAc5zZ5zX87G+W08SJEN5Hfabs+1TGJ1fT8oZIHwk2/1VtLSNVLIjHb2yfC3qRS1g50a1Pl/3dH+ueQ= 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=PnwV2c1v; 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=1707734703; x=1739270703; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yc+q4KsjIiSfEwY6TeHFKJsFn5r2uXtVujdyv1Did04=; b=PnwV2c1vqqNAGFTXwNIWSW1zTdKI2UKDKpN8cyOIat7J0OtP8ow8Og/n 6EkxwcWvQgwhuDQVjjSpq8Hvz4jwMbK4bPtno3QoHJ5MCDsyqdyQgWORX ZV0gBjZrAFTRDOEL0F03ezN1z5pDnBqY9JqE2gg6SXARA4geHP2X2jVnv bZgidVt5/mVDzlYEGb3poJ6FAKez+hcmMRyJW3tVYz27uFdkxqcaF280C BnSlMTwFL1GYuR2vnzXDGSCRxX/yNMplzYojnKbQcRk8u3biM1X0QEFCP T410lM0QQ2bMkdvqF89WZ+dFNn513r6E3PF4Zd9wIk6LaL4LlucXAGTMA Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1584976" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1584976" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:44:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035569" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035569" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:44:54 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 0E7EE487; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 03/16] cpu/hotplug: Add support for declaring CPU offlining not supported Date: Mon, 12 Feb 2024 12:44:35 +0200 Message-ID: <20240212104448.2589568-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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 e6ec3ba4950b..7c28a07afe8b 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.43.0