From patchwork Tue Dec 5 00:44:59 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: 173612 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3133800vqy; Mon, 4 Dec 2023 16:46:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvqM1vvgFZcis0JLDQkwoWrojCcn743agLKzhBuFQWAgU8ethxQVlUvpf5N2vmICTy0Fr9 X-Received: by 2002:a17:90a:e654:b0:286:6cc1:864e with SMTP id ep20-20020a17090ae65400b002866cc1864emr393321pjb.51.1701737183225; Mon, 04 Dec 2023 16:46:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701737183; cv=none; d=google.com; s=arc-20160816; b=uatyI3JAI3mcQNi20fw3GR4PlhO5CIyJySy9dmoqywH4M4vLdmmyEObZZXlHnJJyyA BuBuRhrmRixFxR2l3TvDxhNcvFdItBoidwgYY2H1vs5Yu34C4vGNJ2ACdfowfQFeLBmV cKMxeJ+fkz/nM+TbgkEInxio1RljdXOFxDkovc92y8tOjH5qYRr+ACKzk3dnINJGMd94 aoY7fUAgHvQb1zD/qZ84ZEwlkgw9LeL3KVeH7Lx6lQzWr0QWVjJYFzfzgltu5YhO7XY0 6JSjBIsR4zD7J4iFXtZzpNqHUPe0WpyV1/N1UT1LggpsHCz4A+P5D5CHMojGUZKySq5U wVXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OVW5Lp5qQyOj4PGTBSY+BFDTe38aHrd5PIbvwnwNVfc=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=p9ill9GKMlqduU280+Ok4fk3Fn0tDrT2IVQk96AagnXYwlFGLrLWiyYAVutf8qYMTX LLeuaGt3EXDFPIZ6296pC1CfGztjEs470v1vaHfTGDm4aif4R9aH6/v9CbWwe7uZsM+N SiZEMiStdQdAXwkevfsPhkv9WOKtuniE75jg0Lmh4+oPHFFAI3fnHCm1vnczSbIzzHeT x9guNY4Tk+MuAX9ouDkkKnB1yXPXj0R+LQ7NLtBR5caqK8oLcjNp2u2FbMd0tLlXVGDj Rmx3H/JcRPLsw9Gc6Z8bhJtrjF2ZqC62kFwdlZRM4IenbNW4JMu8X2aL7IUFtjUT/XTn ftCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="J/fVbHYl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id ix14-20020a170902f80e00b001d076ffeecdsi4374128plb.198.2023.12.04.16.46.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 16:46:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="J/fVbHYl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id AFBE98083DBE; Mon, 4 Dec 2023 16:45:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231604AbjLEAp0 (ORCPT + 99 others); Mon, 4 Dec 2023 19:45:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229703AbjLEApY (ORCPT ); Mon, 4 Dec 2023 19:45:24 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09DFAC4 for ; Mon, 4 Dec 2023 16:45:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701737128; x=1733273128; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TlUbH+K6pjEWmV+sTKQ2Oh1pOAL04QaVsgJCWqheRjc=; b=J/fVbHYlQhTEqwyzPnpJW8B6yBFbsBl9U4NtXk69fH6O8ecuHLHtrGk1 Lc3CBUDPI7mNBdM9wdMRcS7ki1j7oSw6H6iHUqbmdS3H2kvXC1yW6HUtl u2noANOHbV0OgyUGSURoIVIswDEzM0wi2OlJZGM4bS0WsU9CUAZHvKGYo mUjLXFpDR4kaMfDvzXnITRmw7hES3pD8/jUiE/B30gAmpgGvhys/AIOnP 6yii4bBysjHmzdQQW7Hg0GARowWtywLBDVfA4/8ZK92v66CXjuOWmOa8Y n/iTV84g7Ma+4cSOVmiHyO3zuJ6FEl33bxHHgIs37g+XFnsgWltXq8oA7 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="392688605" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="392688605" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 16:45:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="888704371" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="888704371" Received: from abijaz-mobl2.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.61.240]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 16:45:22 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 4B55F10A441; Tue, 5 Dec 2023 03:45:20 +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: [PATCHv4 03/14] cpu/hotplug: Add support for declaring CPU offlining not supported Date: Tue, 5 Dec 2023 03:44:59 +0300 Message-ID: <20231205004510.27164-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231205004510.27164-1-kirill.shutemov@linux.intel.com> References: <20231205004510.27164-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 04 Dec 2023 16:45:37 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784400768223665968 X-GMAIL-MSGID: 1784400768223665968 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..af8034ccda8e 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; + 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;