From patchwork Fri Dec 22 23:51:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 182809 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1394123dyi; Fri, 22 Dec 2023 15:53:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6CWMDTg1o3Lnl0SNkJ1jOpuEpj+K9c+o5m1iv6KrAU1Z7GmaUPIaTC/qX4LMm/F/o66Mp X-Received: by 2002:a17:902:d38c:b0:1d0:6ffe:a22 with SMTP id e12-20020a170902d38c00b001d06ffe0a22mr2118637pld.128.1703289188325; Fri, 22 Dec 2023 15:53:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703289188; cv=none; d=google.com; s=arc-20160816; b=bRDuSvLxI5fL8FyQkrSCCLFCss2/OG+IwIr97O0EJ/pkAj7vDjPXfTDyUQOGW2RG6Y b/g0O/Paw+5gvd0pGmtM6n6GYIiXrGtTYtY3sLnmizT2MJxreGZcV2r1uV0L82XxyJON rr8t5kzy4vIex/4Rktn9PgKR//ULP9RKfJFKHXK8eb8Zt8xd/S7P73Gh55P5eSXnjcTd Fv0R3XAmmInHoxHuoMZrXcKctUtB2iX4KXEkiTygqfXifnHk0niYyqN66hQGothRxdTn mphHJeXTyPynwhPvL2paqFEaOyuEl1iyUzsLBxksqA9RxMIAHSPqgNuTwJQhLxuhCRDo /A1g== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10127-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id iz11-20020a170902ef8b00b001d0824216a3si3860110plb.432.2023.12.22.15.53.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 15:53:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10127-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10127-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 80E18B23715 for ; Fri, 22 Dec 2023 23:52:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A9354374C2; Fri, 22 Dec 2023 23:52:24 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786028163866516902 X-GMAIL-MSGID: 1786028163866516902 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;