Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1911525lqe; Tue, 9 Apr 2024 04:30:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVn82CUwVUU0AajmMZSvFOzlqDBLl65fBktzWe/U0hPwtYRBF0I6p+jmouUtd4nOtKqXBHQuohzdEWdz8cIQPKDDmdOzAPaClRO+yKPcw== X-Google-Smtp-Source: AGHT+IFieFxYUiXPzlyK2tgjLLtL5pDJ3T6CEweOjD7oqJ17Mdqs1OXSLMP1UCo5iWTI3IUfmpze X-Received: by 2002:a05:6e02:3397:b0:369:943c:d38 with SMTP id bn23-20020a056e02339700b00369943c0d38mr14763165ilb.2.1712662242879; Tue, 09 Apr 2024 04:30:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712662242; cv=pass; d=google.com; s=arc-20160816; b=QxcapRVYd2Cd9PEMF5eIapFH79oIayJlQ7rvFz4ivUXl8/uHodRPAGa1SoA+yVk6E6 4bJW0LRS6xgxUs74CXz4HFaSl0ivMD56VWb2IhnViC81E2ofu3gn7rmkqWy+SEEM0diU PDOW3n4jSzN7UDJRtrxHJtqcsPzXWNbGoAkSgeVq8pRxKOLIX4/DHtrC9sYuu+1BT7qb f545ESWxpIJ7oTC/ETdi0rqwSR0EXmO03tLg60BjVwC6TYEgBoL2LFiRWLm7kf0VB3/A dfQVYBXAPdqKUjDjJWAdafoP7gt7luFhnSY9+qSAmcECXDogtF+M8negID0+59IhavSM t7RA== 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=dzDD/fh85E6+JpP1s3e80aFR84QSD2sE+g2ijHgcWc8=; fh=Yw2S7s1ZcF7+jfnU9Zy13ghDfPt/cQWqfRpyK6FQAJQ=; b=mhOQCDZZ6Q6LTtcSlaq7TSbe2NupsHsoGTjnKP2fzFNvONMnVffRSTu1OaxqpySOHV 6e3jDm2mvHa/P3hXuFLwE72W455XKjiT2YPPde2ZyLZ2ThK6AV5ityYdr0RroUzFFJgF CQcD9m5RMBkMO107BXyTSCZPHFmpXzv2XDqFwd50QmEwZFubVaT5mCZOORSrH9Bf2l9/ GPqmIyJKMTNak8L1PcFHiyHaHrBlBcrZE9KZFwPTd3GVPW3kdnt4hZJyt9+rBHXuAlgw /n2fRTIcWUlmYy4d2WaJXURo9MTDKVQW2D6W1Yc8lCcMpH78WkV3JDJwOctfC0RwsPiD u2+Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QHQDDjh3; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-136748-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136748-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. [139.178.88.99]) by mx.google.com with ESMTPS id v1-20020a632f01000000b005f063f658fbsi8083830pgv.750.2024.04.09.04.30.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 04:30:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136748-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QHQDDjh3; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-136748-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136748-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 DA568285DF3 for ; Tue, 9 Apr 2024 11:30:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 66957129A7B; Tue, 9 Apr 2024 11:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QHQDDjh3" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 1428386651 for ; Tue, 9 Apr 2024 11:30:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712662227; cv=none; b=umRdEdAYUiGru2vydrn2Rm3yTgOluu8fPbsET/ENB+UOIHvM0mpiNwlxciwGOj1hYtKyIsDBcen1Eu/OEF10OV3xNiuB0FOjyc/eQhRu9FNsZTDrJwNxm0a26DYQyndJEtrFd9UHMG1uqX9MNZ7jB1VdQb8UtqN+4xmpdB7AAJg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712662227; c=relaxed/simple; bh=PcGW20f9JUfyIYDmdaZjLxpufn1UsRTL7qIDtM0mrrc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gG2o4ssBvakhgH/PH1+c/6Llc+0PUciizF9EcDarxO2S2wZBISUyJT/BW5+dv/kc4QyxIBb68JWC0+ezuDKxaO6EAOPdHPB0Fg3GNjz7PG7zSCtcjw4lfD+fYnFVxLEjuuy9GBUy3f5rBNH6IlXv9XrqFioktqBqi7VbMjvgLMk= 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=QHQDDjh3; arc=none smtp.client-ip=198.175.65.9 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=1712662227; x=1744198227; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PcGW20f9JUfyIYDmdaZjLxpufn1UsRTL7qIDtM0mrrc=; b=QHQDDjh3nFsRO/80sXLwHYY+L/QeuFUQK0LJWrfD1vyAUW8DhvmBVkEn 8O1iBmB42qi7a4kgFPizOa6YleL7GMA+j9xiCTsv/w5fB8ZHCTsmCYQFi DtJf/G4dIiVLJbacOiZqYotbp6wrITxC2pIkJZ4C3HzJqsGbriHTg7OFg GyPg9a16gRx3dMtF8aLa8ZDftKctLHBE2xUwa3Op2I29Ot/rInRXcWtPr bXrNMbMN+C36y0g1joKmb5VruG9q7818+cqOGqhIiNDCMZAVU2PE08mr2 JmYWSpjwKjmUKqftvOf5GFGmSR+H45V3BPNoBLovKEHGY7H0TQIAuS8F4 g==; X-CSE-ConnectionGUID: 7BLg5ohtTPCOBunpRUxrTg== X-CSE-MsgGUID: sW/zlbclTM6TSVNuAqSZVw== X-IronPort-AV: E=McAfee;i="6600,9927,11038"; a="30460313" X-IronPort-AV: E=Sophos;i="6.07,189,1708416000"; d="scan'208";a="30460313" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2024 04:30:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11038"; a="937093309" X-IronPort-AV: E=Sophos;i="6.07,189,1708416000"; d="scan'208";a="937093309" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 09 Apr 2024 04:30:18 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 900688C9; Tue, 9 Apr 2024 14:30:17 +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" , Baoquan He , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Tao Liu Subject: [PATCHv10 03/18] cpu/hotplug: Add support for declaring CPU offlining not supported Date: Tue, 9 Apr 2024 14:29:55 +0300 Message-ID: <20240409113010.465412-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240409113010.465412-1-kirill.shutemov@linux.intel.com> References: <20240409113010.465412-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 272e4e79e15c..cfe29e52ce84 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 8f6affd051f7..08860baa6ce0 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 @@ -1518,7 +1528,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