Implement XEN_SYSCTL_CPU_HOTPLUG_{ONLINE,OFFLINE} calls to allow for
enabling/disabling CPU cores in runtime.
Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
v2->v3:
* no changes
v1->v2:
* remove SMT ops
* remove cpu == 0 checks
* add XSM hooks
* only implement for 64bit Arm
---
xen/arch/arm/sysctl.c | 45 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/xen/arch/arm/sysctl.c b/xen/arch/arm/sysctl.c
index 32cab4feff..fecd649db1 100644
--- a/xen/arch/arm/sysctl.c
+++ b/xen/arch/arm/sysctl.c
@@ -12,6 +12,8 @@
#include <xen/dt-overlay.h>
#include <xen/errno.h>
#include <xen/hypercall.h>
+#include <xen/cpu.h>
+#include <xsm/xsm.h>
#include <asm/arm64/sve.h>
#include <public/sysctl.h>
@@ -23,6 +25,42 @@ void arch_do_physinfo(struct xen_sysctl_physinfo *pi)
XEN_SYSCTL_PHYSCAP_ARM_SVE_MASK);
}
+#ifdef CONFIG_ARM_64
+static long cpu_up_helper(void *data)
+{
+ unsigned long cpu = (unsigned long) data;
+ return cpu_up(cpu);
+}
+
+static long cpu_down_helper(void *data)
+{
+ unsigned long cpu = (unsigned long) data;
+ return cpu_down(cpu);
+}
+
+static long cpu_hotplug_sysctl(struct xen_sysctl_cpu_hotplug *hotplug)
+{
+ int ret;
+
+ switch (hotplug->op) {
+ case XEN_SYSCTL_CPU_HOTPLUG_ONLINE:
+ ret = xsm_resource_plug_core(XSM_HOOK);
+ if ( ret )
+ return ret;
+ return continue_hypercall_on_cpu(0, cpu_up_helper, _p(hotplug->cpu));
+
+ case XEN_SYSCTL_CPU_HOTPLUG_OFFLINE:
+ ret = xsm_resource_unplug_core(XSM_HOOK);
+ if ( ret )
+ return ret;
+ return continue_hypercall_on_cpu(0, cpu_down_helper, _p(hotplug->cpu));
+
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+#endif
+
long arch_do_sysctl(struct xen_sysctl *sysctl,
XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
{
@@ -34,6 +72,13 @@ long arch_do_sysctl(struct xen_sysctl *sysctl,
ret = dt_overlay_sysctl(&sysctl->u.dt_overlay);
break;
+/* CPU Hotplug only implemented for 64-bit Arm */
+#ifdef CONFIG_ARM_64
+ case XEN_SYSCTL_cpu_hotplug:
+ ret = cpu_hotplug_sysctl(&sysctl->u.cpu_hotplug);
+ break;
+#endif
+
default:
ret = -ENOSYS;
break;
--
2.34.1
Hi,
On 10/10/2025 10:21, Mykyta Poturai wrote:
> Implement XEN_SYSCTL_CPU_HOTPLUG_{ONLINE,OFFLINE} calls to allow for
> enabling/disabling CPU cores in runtime.
>
> Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
>
> v2->v3:
> * no changes
>
> v1->v2:
> * remove SMT ops
> * remove cpu == 0 checks
> * add XSM hooks
> * only implement for 64bit Arm
Can you add some details in the commit message explaining why the
feature is only enabled for 32-bit Arm?
> ---
> xen/arch/arm/sysctl.c | 45 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
>
> diff --git a/xen/arch/arm/sysctl.c b/xen/arch/arm/sysctl.c
> index 32cab4feff..fecd649db1 100644
> --- a/xen/arch/arm/sysctl.c
> +++ b/xen/arch/arm/sysctl.c
> @@ -12,6 +12,8 @@
> #include <xen/dt-overlay.h>
> #include <xen/errno.h>
> #include <xen/hypercall.h>
> +#include <xen/cpu.h>
> +#include <xsm/xsm.h>
> #include <asm/arm64/sve.h>
> #include <public/sysctl.h>
>
> @@ -23,6 +25,42 @@ void arch_do_physinfo(struct xen_sysctl_physinfo *pi)
> XEN_SYSCTL_PHYSCAP_ARM_SVE_MASK);
> }
>
> +#ifdef CONFIG_ARM_64
> +static long cpu_up_helper(void *data)
> +{
> + unsigned long cpu = (unsigned long) data;
> + return cpu_up(cpu);
> +}
> +
> +static long cpu_down_helper(void *data)
> +{
> + unsigned long cpu = (unsigned long) data;
> + return cpu_down(cpu);
> +}
> +
> +static long cpu_hotplug_sysctl(struct xen_sysctl_cpu_hotplug *hotplug)
> +{
> + int ret;
> +
> + switch (hotplug->op) {
> + case XEN_SYSCTL_CPU_HOTPLUG_ONLINE:
> + ret = xsm_resource_plug_core(XSM_HOOK);
> + if ( ret )
> + return ret;
> + return continue_hypercall_on_cpu(0, cpu_up_helper, _p(hotplug->cpu));
> +
> + case XEN_SYSCTL_CPU_HOTPLUG_OFFLINE:
> + ret = xsm_resource_unplug_core(XSM_HOOK);
> + if ( ret )
> + return ret;
> + return continue_hypercall_on_cpu(0, cpu_down_helper, _p(hotplug->cpu));
> +
> + default:
> + return -EOPNOTSUPP;
> + }
> +}
> +#endif
The logic seems to be very similar to the x86 code. There are some
slight differences in cpu_up_helper() and cpu_down_helper() but:
* For cpu_up_helper(), we could create an arch specific helper for the
second if check.
* For cpu_down_helper(), it would be ok to call cpu_down() a second time
on Arm.
Can you look at consolidating the code?
Cheers,
--
Julien Grall
© 2016 - 2026 Red Hat, Inc.