From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97079606A681 for ; Thu, 3 Dec 2026 00:04:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=X0fS3mbP Received: from list by lists.xenproject.org with outflank-mailman.1511227.1703665 (Exim 4.92) (envelope-from ) id 1xYuIm-0004WC-5O; Thu, 03 Dec 2026 00:03:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1511227.1703665; Thu, 03 Dec 2026 00:03:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xYuIm-0004W5-2o; Thu, 03 Dec 2026 00:03:56 +0000 Received: by outflank-mailman (input) for mailman id 1511227; Thu, 03 Dec 2026 00:03:54 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xYuIk-0004UP-QC for xen-devel@lists.xenproject.org; Thu, 03 Dec 2026 00:03:54 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xYuIj-00ADMq-QC for xen-devel@lists.xenproject.org; Thu, 03 Dec 2026 01:03:53 +0100 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b10b1e1-2eae-0a2a0a5409dd-0a2a4507de3e-14 for ; Thu, 03 Dec 2026 01:03:53 +0100 Received: from [172.234.252.31] (helo=sea.source.kernel.org) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b10b1e8-b4ea-0a2a45070019-aceafc1fbc8c-3 for ; Thu, 03 Dec 2026 01:03:53 +0100 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 5565842DE9; Thu, 3 Dec 2026 00:03:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4527F1F0089C; Thu, 3 Dec 2026 00:03:48 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Post: List-Help: List-Subscribe: , Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=k20260515 header.d=kernel.org header.i="@kernel.org" header.h="Date:From:To:cc:Subject:In-Reply-To:References" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796256230; bh=eBWO/sK4vHa0ECpDJk07lc+hqGUIArx+ch5R+Gcgaf8=; h=Date:From:To:cc:Subject:In-Reply-To:References; b=X0fS3mbPnCyLG4d/Pbt/8nkTsBQjepcI4inCbBQgaxQ5XvP/qApprXlhyqhr/GwGx JVlLFvrg+ZxQbHhjzwKT0H6bwZ8xdXXpHGyJK86Eg16aaA8GHJRfHPTGkPWOWw/6bJ LiCBhAL1V34fSyqBhOYD7dubPK1WCT1hTpjcrPMltF4uoln3MiVq/BsnhMbByA/wy7 tXKOs4qW8MVvKRFARernDz0YfRNKX5COcqtWrAf5K3pRKezk3z8itLWuzHAfjgQDJ8 cZf/ztI9RRXKDzLmkNKM+xlL92sSeBOdg0hZSzk6nvuyJl8PItk1D6YTsxOus66CVN Uf4z6FZc+Jt5Q== Date: Wed, 2 Dec 2026 16:03:47 -0800 (PST) From: Stefano Stabellini To: Mykyta Poturai cc: "xen-devel@lists.xenproject.org" , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , Jan Beulich , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Teddy Astie , "Daniel P. Smith" , Volodymyr Babchuk Subject: Re: [PATCH v12 4/6] arm/sysctl: Implement cpu hotplug ops In-Reply-To: Message-ID: <2e8fea5e-d4f3-74ca-bbec-42ef96c02bd6@kernel.org> References: X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-purgate-ID: tlsNG-ef75cf/1796256233-A52CCAE4-8B6FD1D8/0/0 X-purgate-type: clean X-purgate-size: 11542 X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Fri, 27 Nov 2026, Mykyta Poturai wrote: > SMT-disable enforcement check is moved into a separate > architecture-specific function. > > For now this operations only support Arm64. For proper Arm32 support, > there needs to be a mechanism to free per-cpu page tables, allocated in > init_domheap_mappings. Also, hotplug is not supported if ITS enabled, > and partially supported FFA, or TEE is enabled, as they use non-static > IRQ actions. > > Remove ifdef guards for x86 in flask, as cpu hotplug is now > supported on more architectures. > > Signed-off-by: Mykyta Poturai > Acked-by: Jan Beulich > Reviewed-by: Volodymyr Babchuk Acked-by: Stefano Stabellini > --- > v11->v12: > * collect tags > > v10->v11: > * add HAS_CPU_ONLINE_OFFLINE knob > > v9->v10: > * rename arch_cpu_can_stay_online to arch_cpu_keep_online > * drop the single-use hp_op and hcpu variables > * make CPU_ONLINE_OFFLINE depend on !TEE, as FFA and TEE use non-static > IRQ actions > > v8->v9: > * simplify dependencies of config CPU_ONLINE_OFFLINE again > * rebased ove XSA-499 > > v7->v8: > * simplify dependencies of config CPU_ONLINE_OFFLINE > > v6->v7: > * use IS_ENABLED istead of ifdef in more places > * remove unneded variables > * more explicit fallthrough in do_sysctl > > v5->v6: > * fix style issues > * rename arch_smt_cpu_disable -> arch_cpu_can_stay_online and invert the > logic > * use IS_ENABLED istead of ifdef > * remove explicit list af arch-specific SYSCTL_CPU_HOTPLUG_* options > from the common handler > * fix flask issue > > v4->v5: > * move handling to common code > * rename config to CPU_HOTPUG > * merge with "smp: Move cpu_up/down helpers to common code" > > v3->v4: > * don't reimplement cpu_up/down helpers > * add Kconfig option > * fixup formatting > > v2->v3: > * no changes > > v1->v2: > * remove SMT ops > * remove cpu == 0 checks > * add XSM hooks > * only implement for 64bit Arm > --- > xen/arch/arm/Kconfig | 1 + > xen/arch/arm/smp.c | 11 +++++++++++ > xen/arch/x86/Kconfig | 1 + > xen/arch/x86/include/asm/smp.h | 3 --- > xen/arch/x86/smp.c | 34 +++------------------------------ > xen/arch/x86/sysctl.c | 11 ++++------- > xen/common/Kconfig | 7 +++++-- > xen/common/smp.c | 35 ++++++++++++++++++++++++++++++++++ > xen/common/sysctl.c | 32 +++++++++++++++++++++++++++++++ > xen/include/xen/smp.h | 6 ++++++ > xen/xsm/flask/hooks.c | 2 +- > 11 files changed, 99 insertions(+), 44 deletions(-) > > diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig > index b9c5c40678..4569c76615 100644 > --- a/xen/arch/arm/Kconfig > +++ b/xen/arch/arm/Kconfig > @@ -7,6 +7,7 @@ config ARM_64 > def_bool y > depends on !ARM_32 > select 64BIT > + select HAS_CPU_ONLINE_OFFLINE if !HAS_ITS && !TEE > select HAS_DOMAIN_TYPE > select HAS_FAST_MULTIPLY > select HAS_VPCI_GUEST_SUPPORT if PCI_PASSTHROUGH > diff --git a/xen/arch/arm/smp.c b/xen/arch/arm/smp.c > index b372472188..f84f217359 100644 > --- a/xen/arch/arm/smp.c > +++ b/xen/arch/arm/smp.c > @@ -44,6 +44,17 @@ void smp_send_call_function_mask(const cpumask_t *mask) > } > } > > +#ifdef CONFIG_CPU_ONLINE_OFFLINE > +/* > + * We currently don't support SMT on ARM so we don't need any special logic for > + * CPU disabling > + */ > +bool arch_cpu_keep_online(unsigned int cpu) > +{ > + return true; > +} > +#endif > + > /* > * Local variables: > * mode: C > diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig > index 170b4d63dc..6b5562173b 100644 > --- a/xen/arch/x86/Kconfig > +++ b/xen/arch/x86/Kconfig > @@ -18,6 +18,7 @@ config X86 > select HAS_BRK_ALLOCATOR > select HAS_COMPAT > select HAS_CPUFREQ > + select HAS_CPU_ONLINE_OFFLINE > select HAS_DIT > select HAS_EHCI > select HAS_EX_TABLE > diff --git a/xen/arch/x86/include/asm/smp.h b/xen/arch/x86/include/asm/smp.h > index 572b39b01c..6c33567cb5 100644 > --- a/xen/arch/x86/include/asm/smp.h > +++ b/xen/arch/x86/include/asm/smp.h > @@ -44,9 +44,6 @@ int cpu_add(uint32_t apic_id, uint32_t acpi_id, uint32_t pxm); > > void __stop_this_cpu(void); > > -long cf_check cpu_up_helper(void *data); > -long cf_check cpu_down_helper(void *data); > - > long cf_check core_parking_helper(void *data); > bool core_parking_remove(unsigned int cpu); > uint32_t get_cur_idle_nums(void); > diff --git a/xen/arch/x86/smp.c b/xen/arch/x86/smp.c > index e3c4c0d5e0..b56d8dfd36 100644 > --- a/xen/arch/x86/smp.c > +++ b/xen/arch/x86/smp.c > @@ -417,37 +417,9 @@ void cf_check call_function_interrupt(void) > } > > #ifdef CONFIG_CPU_ONLINE_OFFLINE > -long cf_check cpu_up_helper(void *data) > +bool arch_cpu_keep_online(unsigned int cpu) > { > - unsigned int cpu = (unsigned long)data; > - int ret = cpu_up(cpu); > - > - /* Have one more go on EBUSY. */ > - if ( ret == -EBUSY ) > - ret = cpu_up(cpu); > - > - if ( !ret && !opt_smt && > - cpu_data[cpu].compute_unit_id == INVALID_CUID && > - cpumask_weight(per_cpu(cpu_sibling_mask, cpu)) > 1 ) > - { > - ret = cpu_down_helper(data); > - if ( ret ) > - printk("Could not re-offline CPU%u (%d)\n", cpu, ret); > - else > - ret = -EPERM; > - } > - > - return ret; > -} > - > -long cf_check cpu_down_helper(void *data) > -{ > - int cpu = (unsigned long)data; > - int ret = cpu_down(cpu); > - > - /* Have one more go on EBUSY. */ > - if ( ret == -EBUSY ) > - ret = cpu_down(cpu); > - return ret; > + return opt_smt || cpu_data[cpu].compute_unit_id != INVALID_CUID || > + cpumask_weight(per_cpu(cpu_sibling_mask, cpu)) <= 1; > } > #endif > diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c > index 10d485e633..a4254beabb 100644 > --- a/xen/arch/x86/sysctl.c > +++ b/xen/arch/x86/sysctl.c > @@ -121,13 +121,13 @@ long arch_do_sysctl( > > case XEN_SYSCTL_cpu_hotplug: > { > - unsigned int cpu = sysctl->u.cpu_hotplug.cpu; > unsigned int op = sysctl->u.cpu_hotplug.op; > long (*fn)(void *data); > void *hcpu; > > if ( !IS_ENABLED(CONFIG_CPU_ONLINE_OFFLINE) ) > { > + ASSERT_UNREACHABLE(); > ret = -EOPNOTSUPP; > break; > } > @@ -135,13 +135,10 @@ long arch_do_sysctl( > switch ( op ) > { > case XEN_SYSCTL_CPU_HOTPLUG_ONLINE: > - fn = cpu_up_helper; > - hcpu = _p(cpu); > - break; > - > case XEN_SYSCTL_CPU_HOTPLUG_OFFLINE: > - fn = cpu_down_helper; > - hcpu = _p(cpu); > + /* Handled by common code */ > + ASSERT_UNREACHABLE(); > + ret = -EOPNOTSUPP; > break; > > case XEN_SYSCTL_CPU_HOTPLUG_SMT_ENABLE: > diff --git a/xen/common/Kconfig b/xen/common/Kconfig > index 207959a7d5..b203a4f12a 100644 > --- a/xen/common/Kconfig > +++ b/xen/common/Kconfig > @@ -124,6 +124,9 @@ config HAS_BRK_ALLOCATOR > config HAS_COMPAT > bool > > +config HAS_CPU_ONLINE_OFFLINE > + bool > + > config HAS_DEVICE_TREE_DISCOVERY > bool > select DEVICE_TREE_PARSE > @@ -651,8 +654,8 @@ config SYSTEM_SUSPEND > > config CPU_ONLINE_OFFLINE > bool "CPU online/offline support" if EXPERT > - depends on X86 > - default y > + depends on HAS_CPU_ONLINE_OFFLINE > + default X86 > help > Enable support for bringing CPUs online and offline at runtime. On > X86 this is required for disabling SMT. > diff --git a/xen/common/smp.c b/xen/common/smp.c > index a011f541f1..af532d4873 100644 > --- a/xen/common/smp.c > +++ b/xen/common/smp.c > @@ -16,6 +16,7 @@ > * GNU General Public License for more details. > */ > > +#include > #include > #include > #include > @@ -104,6 +105,40 @@ void smp_call_function_interrupt(void) > irq_exit(); > } > > +#ifdef CONFIG_CPU_ONLINE_OFFLINE > +long cf_check cpu_up_helper(void *data) > +{ > + unsigned int cpu = (unsigned long)data; > + int ret = cpu_up(cpu); > + > + /* Have one more go on EBUSY. */ > + if ( ret == -EBUSY ) > + ret = cpu_up(cpu); > + > + if ( !ret && !arch_cpu_keep_online(cpu) ) > + { > + ret = cpu_down_helper(data); > + if ( ret ) > + printk("Could not re-offline CPU%u (%d)\n", cpu, ret); > + else > + ret = -EPERM; > + } > + > + return ret; > +} > + > +long cf_check cpu_down_helper(void *data) > +{ > + unsigned int cpu = (unsigned long)data; > + int ret = cpu_down(cpu); > + > + /* Have one more go on EBUSY. */ > + if ( ret == -EBUSY ) > + ret = cpu_down(cpu); > + return ret; > +} > +#endif /* CONFIG_CPU_ONLINE_OFFLINE */ > + > /* > * Local variables: > * mode: C > diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c > index 8fb5ff0af3..dd21b6ff7e 100644 > --- a/xen/common/sysctl.c > +++ b/xen/common/sysctl.c > @@ -475,6 +475,38 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) > copyback = 1; > break; > > + case XEN_SYSCTL_cpu_hotplug: > + { > + long (*fn)(void *data); > + > + ret = -EOPNOTSUPP; > + if ( !IS_ENABLED(CONFIG_CPU_ONLINE_OFFLINE) ) > + break; > + > + switch ( op->u.cpu_hotplug.op ) > + { > + case XEN_SYSCTL_CPU_HOTPLUG_ONLINE: > + fn = cpu_up_helper; > + break; > + > + case XEN_SYSCTL_CPU_HOTPLUG_OFFLINE: > + fn = cpu_down_helper; > + break; > + > + default: > + fn = NULL; > + break; > + } > + > + if ( fn ) > + { > + ret = continue_hypercall_on_cpu(0, fn, _p(op->u.cpu_hotplug.cpu)); > + break; > + } > + } > + > + /* Use the arch handler for cases not handled here */ > + fallthrough; > default: > ret = arch_do_sysctl(op, u_sysctl); > copyback = 0; > diff --git a/xen/include/xen/smp.h b/xen/include/xen/smp.h > index 2ca9ff1bfc..6c011d73ef 100644 > --- a/xen/include/xen/smp.h > +++ b/xen/include/xen/smp.h > @@ -76,4 +76,10 @@ extern void *stack_base[NR_CPUS]; > void initialize_cpu_data(unsigned int cpu); > int setup_cpu_root_pgt(unsigned int cpu); > > +#ifdef CONFIG_CPU_ONLINE_OFFLINE > +bool arch_cpu_keep_online(unsigned int cpu); > +#endif > +long cf_check cpu_up_helper(void *data); > +long cf_check cpu_down_helper(void *data); > + > #endif /* __XEN_SMP_H__ */ > diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c > index d65ba0aeae..a1eed309b4 100644 > --- a/xen/xsm/flask/hooks.c > +++ b/xen/xsm/flask/hooks.c > @@ -957,7 +957,7 @@ static int cf_check flask_sysctl(const struct xen_sysctl *op) > case XEN_SYSCTL_getdomaininfolist: > return flask_getdomaininfo(dom_xen); > > -#ifdef CONFIG_X86 > +#ifdef CONFIG_CPU_ONLINE_OFFLINE > case XEN_SYSCTL_cpu_hotplug: > switch ( op->u.cpu_hotplug.op ) > { > -- > 2.56.1 >