Implement CPU hotplug on Arm
v9 cover Implement CPU hotplug on Arm
This series implements support for CPU hotplug/unplug on Arm. To achieve this, several things need to be done:
1. XEN_SYSCTL_CPU_HOTPLUG_* calls implemented on Arm64.
2. Enabled building of xen-hptool.
3. Migration of irqs from dying CPUs implemented.
Tested on QEMU and R-Car Gen5 HW.
v8->v9:
* rebase
* see individual patches
v7->v8:
* see individual patches
v6->v7:
* new patch "Kconfig: Make cpu hotplug configurable
v5->v6:
* see individual patches
v4->v5:
* drop merged patches
* combine "smp: Move cpu_up/down helpers to common code" with "arm/sysctl: Implement cpu hotplug ops"
* see individual patches
v3->v4:
* add irq migration patches
* see individual patches
v2->v3:
* add docs
v1->v2:
* see individual patches
Mykyta Poturai (6):
arm/irq: Keep track of irq affinities
arm/irq: Migrate IRQs during CPU up/down operations
Kconfig: Make cpu hotplug configurable arm/sysctl: Implement cpu hotplug ops
tools: Allow building xen-hptool without CONFIG_MIGRATE
docs: Document CPU hotplug
docs/misc/cpu-hotplug.txt | 98 ++++++++++ tools/misc/Makefile | 9 +- tools/misc/xen-hptool-x86.c | 278 ++++++++++++++++++++++++++++ tools/misc/xen-hptool.c | 293 ++---------------------------- tools/misc/xen-hptool.h | 15 ++ xen/arch/arm/gic-vgic.c | 2 + xen/arch/arm/include/asm/irq.h | 6 + xen/arch/arm/irq.c | 69 ++++++- xen/arch/arm/smp.c | 9 + xen/arch/arm/smpboot.c | 7 + xen/arch/arm/vgic.c | 14 +- xen/arch/arm/vgic/vgic-mmio-v2.c | 11 +- xen/arch/arm/vgic/vgic.c | 21 ++- xen/arch/ppc/stubs.c | 5 + xen/arch/riscv/stubs.c | 5 + xen/arch/x86/include/asm/smp.h | 3 - xen/arch/x86/platform_hypercall.c | 12 ++ xen/arch/x86/smp.c | 35 +--- xen/arch/x86/sysctl.c | 23 ++- xen/common/Kconfig | 8 + xen/common/smp.c | 35 ++++ xen/common/sysctl.c | 34 ++++ xen/include/xen/smp.h | 4 + xen/xsm/flask/hooks.c | 2 +- 24 files changed, 658 insertions(+), 340 deletions(-) create mode 100644 docs/misc/cpu-hotplug.txt create mode 100644 tools/misc/xen-hptool-x86.c create mode 100644 tools/misc/xen-hptool.h
Signature · 1 line
2.55.0
PATCH v9 1/6 arm/irq: Keep track of irq affinities
Currently on Arm the desc->affinity mask of an irq is never updated, which makes it hard to know the actual affinity of an interrupt. Fix this by updating the field in irq_set_affinity. Changing desc->affinity requires desc->lock to be held, so add an assertion to ensure that callers of irq_set_affinity are doing so correctly.
With desc->lock now being required for irq_set_affinity, add locking around calls to it where it was missing.
---v8->v9:
* no changesv7->v8:
* no changesv6->v7:
* update commit message
* fix possible locking on null desc
* collect RBs
v5->v6:
* add missing locking around irq_set_affinity calls
v4->v5:
* add locking
v3->v4:
* patch introduced
--- xen/arch/arm/gic-vgic.c | 2 ++ xen/arch/arm/irq.c | 9 +++++++-- xen/arch/arm/vgic.c | 14 ++++++++++++-- xen/arch/arm/vgic/vgic-mmio-v2.c | 11 +++++------ xen/arch/arm/vgic/vgic.c | 21 +++++++++++++-------- 5 files changed, 39 insertions(+), 18 deletions(-)
xen/arch/arm/gic-vgic.c +2 -0
@@ -232,7 +232,9 @@ static void gic_update_one_lr(struct vcpu *v, int i)if (test_bit (GIC_IRQ_GUEST_MIGRATING , &p->status) ) {struct vcpu *v_target =vgic_get_target_vcpu (v, irq); +spin_lock (&p->desc->lock);irq_set_affinity (p->desc,cpumask_of (v_target->processor)); +spin_unlock (&p->desc->lock);clear_bit (GIC_IRQ_GUEST_MIGRATING , &p->status); } }
xen/arch/arm/irq.c +7 -2
@@ -216,10 +216,15 @@ static inline struct domain *irq_get_domain(struct irq_desc *desc)return irq_get_guest_info (desc)->d; } +/* Must be called with desc->lock held */ void irq_set_affinity (struct irq_desc *desc,const cpumask_t *mask) { -if ( desc !=NULL ) - desc->handler->set_affinity (desc, mask); +if ( desc ==NULL ) +return ; + +ASSERT (spin_is_locked (&desc->lock)); +cpumask_copy (desc->affinity, mask); + desc->handler->set_affinity (desc, mask); } int request_irq(unsigned int irq, unsigned int irqflags,
xen/arch/arm/vgic.c +12 -2
@@ -450,7 +450,9 @@ bool vgic_migrate_irq(struct vcpu *old, struct vcpu *new, unsigned int irq)if (list_empty (&p->inflight) ) { +spin_lock (&p->desc->lock);irq_set_affinity (p->desc,cpumask_of (new->processor)); +spin_unlock (&p->desc->lock);spin_unlock_irqrestore (&old->arch.vgic.lock, flags);return true; }
@@ -458,7 +460,9 @@ bool vgic_migrate_irq(struct vcpu *old, struct vcpu *new, unsigned int irq)if ( !list_empty (&p->lr_queue) ) {vgic_remove_irq_from_queues (old, p); +spin_lock (&p->desc->lock);irq_set_affinity (p->desc,cpumask_of (new->processor)); +spin_unlock (&p->desc->lock);spin_unlock_irqrestore (&old->arch.vgic.lock, flags);vgic_inject_irq (new->domain, new, irq, true);return true;
@@ -478,6 +482,7 @@ void arch_move_irqs(struct vcpu *v)struct domain *d = v->domain;struct pending_irq *p;struct vcpu *v_target; +unsigned long flags;int i;/*
@@ -499,7 +504,13 @@ void arch_move_irqs(struct vcpu *v) p =irq_to_pending (v_target, virq);if ( v_target == v && !test_bit (GIC_IRQ_GUEST_MIGRATING , &p->status) ) + { +if ( !p->desc ) +continue ; +spin_lock_irqsave (&p->desc->lock, flags);irq_set_affinity (p->desc, cpu_mask); +spin_unlock_irqrestore (&p->desc->lock, flags); + } } }
@@ -579,8 +590,8 @@ void vgic_enable_irqs(struct vcpu *v, uint32_t r, unsigned int n)spin_unlock_irqrestore (&v_target->arch.vgic.lock, flags);if ( p->desc !=NULL ) { -irq_set_affinity (p->desc,cpumask_of (v_target->processor));spin_lock_irqsave (&p->desc->lock, flags); +irq_set_affinity (p->desc,cpumask_of (v_target->processor));/* * The irq cannot be a PPI, we only support delivery of SPIs * to guests.
@@ -949,4 +960,3 @@ void vgic_check_inflight_irqs_pending(struct vcpu *v, unsigned int rank, uint32_* indent-tabs-mode: nil * End: */ -
xen/arch/arm/vgic/vgic-mmio-v2.c +5 -6
@@ -159,24 +159,23 @@ static void vgic_mmio_write_target(struct vcpu *vcpu,for ( i =0 ; i < len; i++ ) {struct vgic_irq *irq =vgic_get_irq (vcpu->domain,NULL , intid + i); +struct irq_desc *desc =irq_to_desc (irq->hwintid); -spin_lock_irqsave (&irq->irq_lock, flags); +spin_lock_irqsave (&desc->lock, flags); +spin_lock (&irq->irq_lock); irq->targets = (val >> (i *8 )) & cpu_mask;if ( irq->targets ) { irq->target_vcpu = vcpu->domain->vcpu[ffs (irq->targets) -1 ];if ( irq->hw ) - { -struct irq_desc *desc =irq_to_desc (irq->hwintid); -irq_set_affinity (desc,cpumask_of (irq->target_vcpu->processor)); - } }else irq->target_vcpu =NULL ; -spin_unlock_irqrestore (&irq->irq_lock, flags); +spin_unlock (&irq->irq_lock); +spin_unlock_irqrestore (&desc->lock, flags);vgic_put_irq (vcpu->domain, irq); } }
xen/arch/arm/vgic/vgic.c +13 -8
@@ -812,22 +812,27 @@ void arch_move_irqs(struct vcpu *v) {struct vgic_irq *irq =vgic_get_irq (d,NULL , i +VGIC_NR_PRIVATE_IRQS );unsigned long flags; +irq_desc_t *desc;if ( !irq )continue ; -spin_lock_irqsave (&irq->irq_lock, flags); - -/* Only hardware mapped vIRQs that are targeting this vCPU. */ -if ( irq->hw && irq->target_vcpu == v) +if ( !irq->hw ) { -irq_desc_t *desc =irq_to_desc (irq->hwintid); +vgic_put_irq (d, irq); +continue ; + } + desc =irq_to_desc (irq->hwintid); +spin_lock_irqsave (&desc->lock, flags); +spin_lock (&irq->irq_lock); + +/* Only hardware mapped vIRQs that are targeting this vCPU. */ +if ( irq->target_vcpu == v )irq_set_affinity (desc,cpumask_of (v->processor)); - } -spin_unlock_irqrestore (&irq->irq_lock, flags); -vgic_put_irq (d, irq); +spin_unlock (&irq->irq_lock); +spin_unlock_irqrestore (&desc->lock, flags); } }
Signature · 1 line
2.55.0
PATCH v9 2/6 arm/irq: Migrate IRQs during CPU up/down operations
In reply to Mykyta PoturaiMove IRQs from dying CPU to the online ones when a CPU is getting offlined. When onlining, rebalance all IRQs in a round-robin fashion. Guest-bound IRQs are already handled by scheduler in the process of moving vCPUs to active pCPUs, so we only need to handle IRQs used by Xen itself.
---v8->v9:
* replace CONFIG_CPU_HOTPLUG with CONFIG_CPU_ONLINE_OFFLINE
v7->v8:
* check only existings ESPIs
v6->v7:
* replace ifdef with IS_ENABLED
v5->v6:
* don't do any balancing on boot
* only do balancing when cpu hotplug is enabled
v4->v5:
* handle CPU onlining as well
* more comments
* fix crash when ESPI is disabled
* don't assume CPU 0 is a boot CPU
* use insigned int for irq number
* remove assumption that all irqs a bound to CPU 0 by default from the commit message
v3->v4:
* patch introduced
--- xen/arch/arm/include/asm/irq.h | 6 ++++ xen/arch/arm/irq.c | 60 ++++++++++++++++++++++++++++++++++ xen/arch/arm/smpboot.c | 7 ++++ 3 files changed, 73 insertions(+)
xen/arch/arm/include/asm/irq.h +6 -0
@@ -126,6 +126,12 @@ bool irq_type_set_by_domain(const struct domain *d);void irq_end_none (struct irq_desc *irq);#define irq_end_none irq_end_none +#ifdef CONFIG_CPU_ONLINE_OFFLINE +void rebalance_irqs (unsigned int from,bool up); +#else +static inline void rebalance_irqs (unsigned int from,bool up) {} +#endif +#endif /* _ASM_HW_IRQ_H */ /* * Local variables:
xen/arch/arm/irq.c +60 -0
72 lines not on this page · raw message
xen/arch/arm/smpboot.c +7 -0
@@ -433,6 +433,13 @@ void __cpu_disable(void)smp_mb (); +/* +* Now that the interrupts are cleared and the CPU marked as offline, +* move interrupts out of it +*/ +if (IS_ENABLED (CONFIG_CPU_ONLINE_OFFLINE ) ) +rebalance_irqs (cpu, false); +/* Return to caller; eventually the IPI mechanism will unwind and the * scheduler will drop to the idle loop, which will call stop_cpu(). */ }
Signature · 1 line
2.55.0
Re: [PATCH v9 2/6] arm/irq: Migrate IRQs during CPU up/down operations
Hi Mykyta,
Quoted 138 lines · Mykyta Poturai
Move IRQs from dying CPU to the online ones when a CPU is getting offlined. When onlining, rebalance all IRQs in a round-robin fashion. Guest-bound IRQs are already handled by scheduler in the process of moving vCPUs to active pCPUs, so we only need to handle IRQs used by Xen itself.
Signed-off-by Mykyta Poturai <[email protected]>---
v8->v9:
* replaceCONFIG_CPU_HOTPLUGwithCONFIG_CPU_ONLINE_OFFLINE
v7->v8:
* check only existings ESPIs
v6->v7:
* replace ifdef withIS_ENABLED
v5->v6:
* don't do any balancing on boot
* only do balancing when cpu hotplug is enabled
v4->v5:
* handle CPU onlining as well
* more comments
* fix crash when ESPI is disabled
* don't assume CPU 0 is a boot CPU
* use insigned int for irq number
* remove assumption that all irqs a bound to CPU 0 by default from the commit message
v3->v4:
* patch introduced--- xen/arch/arm/include/asm/irq.h | 6 ++++ xen/arch/arm/irq.c | 60 ++++++++++++++++++++++++++++++++++ xen/arch/arm/smpboot.c | 7 ++++ 3 files changed, 73 insertions(+)xen/arch/arm/include/asm/irq.h +6
-0@@ -126,6 +126,12 @@ bool irq_type_set_by_domain(const struct domain *d);void irq_end_none (struct irq_desc *irq);#define irq_end_none irq_end_none +#ifdef CONFIG_CPU_ONLINE_OFFLINE +void rebalance_irqs (unsigned int from,bool up); +#else +static inline void rebalance_irqs (unsigned int from,bool up) {} +#endif +#endif /* _ASM_HW_IRQ_H */ /* * Local variables: xen/arch/arm/irq.c +60
-0@@ -158,6 +158,61 @@ static int init_local_irq_data(unsigned int cpu)return 0 ; } +#ifdef CONFIG_CPU_ONLINE_OFFLINE +static int cpu_next; + +static void balance_irq (int irq,unsigned int from,bool up) +{ +struct irq_desc *desc =irq_to_desc (irq); +unsigned long flags; + +ASSERT (!cpumask_empty (&cpu_online_map)); + +spin_lock_irqsave (&desc->lock, flags); +if (likely (!desc->action) ) + goto out; + +if (likely (test_bit (_IRQ_GUEST, &desc->status) || +test_bit (_IRQ_MOVE_PENDING, &desc->status)) ) + goto out; + +/* +* Setting affinity to a mask of multiple CPUs causes the GIC drivers to +* select one CPU from that mask. If the dying CPU was included in the IRQ's +* affinity mask, we cannot determine exactly which CPU the interrupt is +* currently routed to, as GIC drivers lack a concrete get_affinity API. So +* to be safe we must reroute it to a new, definitely online, CPU. In the +* case of CPU going down, we move only the interrupt that could reside on +* it. Otherwise, we rearrange all interrupts in a round-robin fashion. +*/ +if ( !up && !cpumask_test_cpu (from, desc->affinity) ) + goto out; + + cpu_next =cpumask_cycle (cpu_next, &cpu_online_map); +irq_set_affinity (desc,cpumask_of (cpu_next)); + +out: +spin_unlock_irqrestore (&desc->lock, flags); +} + +void rebalance_irqs (unsigned int from,bool up) +{ +int irq; + +if (cpumask_empty (&cpu_online_map) ) +return ; + +for ( irq =NR_LOCAL_IRQS ; irq <NR_IRQS ; irq++ ) +balance_irq (irq, from, up); + +#ifdef CONFIG_GICV3_ESPI +for ( irq =ESPI_BASE_INTID ; irq <ESPI_BASE_INTID +gic_number_espis (); + irq++ ) +balance_irq (irq, from, up); +#endif +} +#endif /* CONFIG_CPU_ONLINE_OFFLINE */ +static int cpu_callback (struct notifier_block *nfb,unsigned long action,void *hcpu) {@@ -172,6 +227,11 @@ static int cpu_callback(struct notifier_block *nfb, unsigned long action,printk (XENLOG_ERR "Unable to allocate local IRQ for CPU%u\n" , cpu);break ; +case CPU_ONLINE : +if (IS_ENABLED (CONFIG_CPU_ONLINE_OFFLINE ) && + system_state >= SYS_STATE_active ) +rebalance_irqs (cpu, true); +break ; }return notifier_from_errno (rc);xen/arch/arm/smpboot.c +0
-0
xen/arch/arm/smpboot.c void __cpu_disable(void) · line 439
Quoted 7 lines
xen/arch/arm/smpboot.c +4
-0@@ -433,6 +433,13 @@ void __cpu_disable(void)smp_mb (); +/* +* Now that the interrupts are cleared and the CPU marked as offline, +* move interrupts out of it +*/
You are using CPU notifier for "up" path, but calling rebalance_irqs() directly in "down" path. Is there a particular reason for this? Cursory check of set_affinity() does not show need for alive CPU, unless I am missing something of course.
Quoted 6 lines
xen/arch/arm/smpboot.c +3
-0+if (IS_ENABLED (CONFIG_CPU_ONLINE_OFFLINE ) ) +rebalance_irqs (cpu, false); +/* Return to caller; eventually the IPI mechanism will unwind and the * scheduler will drop to the idle loop, which will call stop_cpu(). */ }
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v9 2/6] arm/irq: Migrate IRQs during CPU up/down operations
In reply to Mykyta PoturaiSorry, forgot to comment one more thing...
Quoted 60 lines · Mykyta Poturai
Move IRQs from dying CPU to the online ones when a CPU is getting offlined. When onlining, rebalance all IRQs in a round-robin fashion. Guest-bound IRQs are already handled by scheduler in the process of moving vCPUs to active pCPUs, so we only need to handle IRQs used by Xen itself.
Signed-off-by Mykyta Poturai <[email protected]>---
v8->v9:
* replaceCONFIG_CPU_HOTPLUGwithCONFIG_CPU_ONLINE_OFFLINE
v7->v8:
* check only existings ESPIs
v6->v7:
* replace ifdef withIS_ENABLED
v5->v6:
* don't do any balancing on boot
* only do balancing when cpu hotplug is enabled
v4->v5:
* handle CPU onlining as well
* more comments
* fix crash when ESPI is disabled
* don't assume CPU 0 is a boot CPU
* use insigned int for irq number
* remove assumption that all irqs a bound to CPU 0 by default from the commit message
v3->v4:
* patch introduced--- xen/arch/arm/include/asm/irq.h | 6 ++++ xen/arch/arm/irq.c | 60 ++++++++++++++++++++++++++++++++++ xen/arch/arm/smpboot.c | 7 ++++ 3 files changed, 73 insertions(+)xen/arch/arm/include/asm/irq.h +6
-0@@ -126,6 +126,12 @@ bool irq_type_set_by_domain(const struct domain *d);void irq_end_none (struct irq_desc *irq);#define irq_end_none irq_end_none +#ifdef CONFIG_CPU_ONLINE_OFFLINE +void rebalance_irqs (unsigned int from,bool up); +#else +static inline void rebalance_irqs (unsigned int from,bool up) {} +#endif +#endif /* _ASM_HW_IRQ_H */ /* * Local variables: xen/arch/arm/irq.c +0
-0
xen/arch/arm/irq.c static int init_local_irq_data(unsigned int cpu) · line 162
Quoted 5 lines
xen/arch/arm/irq.c +2
-0@@ -158,6 +158,61 @@ static int init_local_irq_data(unsigned int cpu)return 0 ; } +#ifdef CONFIG_CPU_ONLINE_OFFLINE +static int cpu_next;
This variable is used only in balance_irq(). Maybe make it static for that function? No need in keeping it global.
Quoted 86 lines
xen/arch/arm/irq.c +58
-0+ +static void balance_irq (int irq,unsigned int from,bool up) +{ +struct irq_desc *desc =irq_to_desc (irq); +unsigned long flags; + +ASSERT (!cpumask_empty (&cpu_online_map)); + +spin_lock_irqsave (&desc->lock, flags); +if (likely (!desc->action) ) + goto out; + +if (likely (test_bit (_IRQ_GUEST, &desc->status) || +test_bit (_IRQ_MOVE_PENDING, &desc->status)) ) + goto out; + +/* +* Setting affinity to a mask of multiple CPUs causes the GIC drivers to +* select one CPU from that mask. If the dying CPU was included in the IRQ's +* affinity mask, we cannot determine exactly which CPU the interrupt is +* currently routed to, as GIC drivers lack a concrete get_affinity API. So +* to be safe we must reroute it to a new, definitely online, CPU. In the +* case of CPU going down, we move only the interrupt that could reside on +* it. Otherwise, we rearrange all interrupts in a round-robin fashion. +*/ +if ( !up && !cpumask_test_cpu (from, desc->affinity) ) + goto out; + + cpu_next =cpumask_cycle (cpu_next, &cpu_online_map); +irq_set_affinity (desc,cpumask_of (cpu_next)); + +out: +spin_unlock_irqrestore (&desc->lock, flags); +} + +void rebalance_irqs (unsigned int from,bool up) +{ +int irq; + +if (cpumask_empty (&cpu_online_map) ) +return ; + +for ( irq =NR_LOCAL_IRQS ; irq <NR_IRQS ; irq++ ) +balance_irq (irq, from, up); + +#ifdef CONFIG_GICV3_ESPI +for ( irq =ESPI_BASE_INTID ; irq <ESPI_BASE_INTID +gic_number_espis (); + irq++ ) +balance_irq (irq, from, up); +#endif +} +#endif /* CONFIG_CPU_ONLINE_OFFLINE */ +static int cpu_callback (struct notifier_block *nfb,unsigned long action,void *hcpu) {@@ -172,6 +227,11 @@ static int cpu_callback(struct notifier_block *nfb, unsigned long action,printk (XENLOG_ERR "Unable to allocate local IRQ for CPU%u\n" , cpu);break ; +case CPU_ONLINE : +if (IS_ENABLED (CONFIG_CPU_ONLINE_OFFLINE ) && + system_state >= SYS_STATE_active ) +rebalance_irqs (cpu, true); +break ; }return notifier_from_errno (rc);xen/arch/arm/smpboot.c +7
-0@@ -433,6 +433,13 @@ void __cpu_disable(void)smp_mb (); +/* +* Now that the interrupts are cleared and the CPU marked as offline, +* move interrupts out of it +*/ +if (IS_ENABLED (CONFIG_CPU_ONLINE_OFFLINE ) ) +rebalance_irqs (cpu, false); +/* Return to caller; eventually the IPI mechanism will unwind and the * scheduler will drop to the idle loop, which will call stop_cpu(). */ }
Signature · 1 line
WBR, Volodymyr
PATCH v9 3/6 Kconfig: Make cpu hotplug configurable
In reply to Mykyta PoturaiFor the purposes of certification, we want as little code as possible to be unconditionally compiled in. Make CPU hotplug and SMT operations configurable to ease the process. This will also help with introducing CPU hotplug on Arm, where it needs to be configurable.
---v8->v9:
* add "if EXPERT"
* add AB
v7->v8:
* fix style
* s/CPU_HOTPLUG/CPU_ONLINE_OFFLINE/
v6->v7:
* new patch
--- xen/arch/x86/platform_hypercall.c | 12 ++++++++++++ xen/arch/x86/smp.c | 3 +++ xen/arch/x86/sysctl.c | 12 ++++++++++++ xen/common/Kconfig | 8 ++++++++ 4 files changed, 35 insertions(+)
xen/arch/x86/platform_hypercall.c +12 -0
@@ -735,6 +735,12 @@ ret_t do_platform_op( {int cpu = op->u.cpu_ol.cpuid; +if ( !IS_ENABLED (CONFIG_CPU_ONLINE_OFFLINE ) ) + { + ret = -EOPNOTSUPP ; +break ; + } +if ( cpu >= nr_cpu_ids || !cpu_present (cpu) ||clocksource_is_tsc () ) {
@@ -757,6 +763,12 @@ ret_t do_platform_op( {int cpu = op->u.cpu_ol.cpuid; +if ( !IS_ENABLED (CONFIG_CPU_ONLINE_OFFLINE ) ) + { + ret = -EOPNOTSUPP ; +break ; + } +if ( cpu ==0 ) { ret = -EOPNOTSUPP ;
xen/arch/x86/smp.c +3 -0
@@ -418,6 +418,7 @@ void cf_check call_function_interrupt(void)smp_call_function_interrupt (); } +#ifdef CONFIG_CPU_ONLINE_OFFLINE long cf_check cpu_up_helper (void *data) {unsigned int cpu = (unsigned long )data;
@@ -445,8 +446,10 @@ 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; } +#endif
xen/arch/x86/sysctl.c +12 -0
@@ -53,6 +53,12 @@ static long cf_check smt_up_down_helper(void *data)unsigned int cpu, sibling_mask = boot_cpu_data.x86_num_siblings -1 ;int ret =0 ; +if ( !IS_ENABLED (CONFIG_CPU_ONLINE_OFFLINE ) ) + { +ASSERT_UNREACHABLE (); +return -EOPNOTSUPP ; + } + opt_smt = up;for_each_present_cpu ( cpu )
@@ -120,6 +126,12 @@ long arch_do_sysctl(long (*fn)(void *data);void *hcpu; +if ( !IS_ENABLED (CONFIG_CPU_ONLINE_OFFLINE ) ) + { + ret = -EOPNOTSUPP ; +break ; + } +switch ( op ) {case XEN_SYSCTL_CPU_HOTPLUG_ONLINE :
xen/common/Kconfig +8 -0
@@ -643,6 +643,14 @@ config SYSTEM_SUSPEND If unsure, say N. +config CPU_ONLINE_OFFLINE + bool "CPU online/offline support" if EXPERT + depends on X86 + default y + help + Enable support for bringing CPUs online and offline at runtime. On + X86 this is required for disabling SMT. + menu "Supported hypercall interfaces" visible if EXPERT
Signature · 1 line
2.55.0
PATCH v9 4/6 arm/sysctl: Implement cpu hotplug ops
In reply to Mykyta PoturaiSMT-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.
---v8->v9:
* simplify dependencies of config CPU_ONLINE_OFFLINE again
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/smp.c | 9 +++++++++ xen/arch/ppc/stubs.c | 5 +++++ xen/arch/riscv/stubs.c | 5 +++++ xen/arch/x86/include/asm/smp.h | 3 --- xen/arch/x86/smp.c | 34 +++------------------------------ xen/arch/x86/sysctl.c | 11 ++++------- xen/common/Kconfig | 4 ++-- xen/common/smp.c | 35 ++++++++++++++++++++++++++++++++++ xen/common/sysctl.c | 34 +++++++++++++++++++++++++++++++++ xen/include/xen/smp.h | 4 ++++ xen/xsm/flask/hooks.c | 2 +- 11 files changed, 102 insertions(+), 44 deletions(-)
xen/arch/arm/smp.c +9 -0
@@ -44,6 +44,15 @@ void smp_send_call_function_mask(const cpumask_t *mask) } } +/* +* We currently don't support SMT on ARM so we don't need any special logic for +* CPU disabling +*/ +inline bool arch_cpu_can_stay_online (unsigned int cpu) +{ +return true; +} +/* * Local variables: * mode: C
xen/arch/ppc/stubs.c +5 -0
@@ -101,6 +101,11 @@ void smp_send_call_function_mask(const cpumask_t *mask)BUG_ON ("unimplemented" ); } +bool arch_cpu_can_stay_online (unsigned int cpu) +{ +BUG_ON ("unimplemented" ); +} +/* irq.c */ void irq_ack_none (struct irq_desc *desc)
xen/arch/riscv/stubs.c +5 -0
@@ -65,6 +65,11 @@ void smp_send_call_function_mask(const cpumask_t *mask)BUG_ON ("unimplemented" ); } +bool arch_cpu_can_stay_online (unsigned int cpu) +{ +BUG_ON ("unimplemented" ); +} +/* irq.c */ void irq_ack_none (struct irq_desc *desc)
xen/arch/x86/include/asm/smp.h +0 -3
@@ -50,9 +50,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 );
xen/arch/x86/smp.c +3 -31
@@ -419,37 +419,9 @@ void cf_check call_function_interrupt(void) }#ifdef CONFIG_CPU_ONLINE_OFFLINE -long cf_check cpu_up_helper (void *data) +bool arch_cpu_can_stay_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
xen/arch/x86/sysctl.c +4 -7
@@ -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 :
xen/common/Kconfig +2 -2
@@ -645,8 +645,8 @@ config SYSTEM_SUSPEND config CPU_ONLINE_OFFLINE bool "CPU online/offline support" if EXPERT - depends on X86 - default y + depends on !ARM || !HAS_ITS + default X86 help Enable support for bringing CPUs online and offline at runtime. On X86 this is required for disabling SMT.
xen/common/smp.c +35 -0
@@ -16,6 +16,7 @@* GNU General Public License for more details. */ +#include <xen/cpu.h> #include <asm/hardirq.h> #include <asm/processor.h> #include <xen/spinlock.h>
@@ -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_can_stay_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
xen/common/sysctl.c +34 -0
@@ -475,6 +475,40 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) copyback =1 ;break ; +case XEN_SYSCTL_cpu_hotplug: + { +unsigned int hp_op = op->u.cpu_hotplug.op; +long (*fn)(void *data); +void *hcpu =_p (op->u.cpu_hotplug.cpu); + + ret = -EOPNOTSUPP ; +if ( !IS_ENABLED (CONFIG_CPU_ONLINE_OFFLINE ) ) +break ; + +switch ( hp_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, hcpu); +break ; + } + } + +/* Use the arch handler for cases not handled here */ + fallthrough;default : ret =arch_do_sysctl (op, u_sysctl); copyback =0 ;
xen/include/xen/smp.h +4 -0
@@ -76,4 +76,8 @@ extern void *stack_base[NR_CPUS];void initialize_cpu_data (unsigned int cpu);int setup_cpu_root_pgt (unsigned int cpu); +bool arch_cpu_can_stay_online (unsigned int cpu); +long cf_check cpu_up_helper (void *data); +long cf_check cpu_down_helper (void *data); +#endif /* __XEN_SMP_H__ */
xen/xsm/flask/hooks.c +1 -1
@@ -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 ) {
Signature · 1 line
2.55.0
Re: [PATCH v9 4/6] arm/sysctl: Implement cpu hotplug ops
Quoted 9 lines · Mykyta Poturai
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.
Quoted 7 lines
Remove ifdef guards for x86 in flask, as cpu hotplug is now supported on more architectures.
Signed-off-by Mykyta Poturai <[email protected]>---
v8->v9:
* simplify dependencies of configCPU_ONLINE_OFFLINEagain
You must also have re-based over XSA-499. As non-trivial re-basing can go wrong, I think at least in those cases it wants noting in the revlog. (Personally I try to remember to always add the remark, even if the re-base was the trivial resolution of e.g. fuzz.)
Quoted 5 lines
xen/common/smp.c +1
-0@@ -104,6 +105,40 @@ void smp_call_function_interrupt(void)irq_exit (); } +#ifdef CONFIG_CPU_ONLINE_OFFLINE
xen/common/smp.c void smp_call_function_interrupt(void) · line 118
Quoted 10 lines
xen/common/smp.c +10
-0+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_can_stay_online (cpu) )
I'm sorry, I should have noticed this already before: This isn't "can", at least on x86. It is a requirement in certain situations that CPUs be kept kind-of- online. Since arch_cpu_must_stay_online() feels clumsy as a name, and since that might also conflict with another arch perhaps really meaning "can", not "must", maybe arch_cpu_keep_online()?
xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 480
Quoted 9 lines
xen/common/sysctl.c +3
-0@@ -475,6 +475,40 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) copyback =1 ;break ; +case XEN_SYSCTL_cpu_hotplug: + { +unsigned int hp_op = op->u.cpu_hotplug.op;
This variable is used ...
xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 488
Quoted 8 lines
xen/common/sysctl.c +8
-0+long (*fn)(void *data); +void *hcpu =_p (op->u.cpu_hotplug.cpu); + + ret = -EOPNOTSUPP ; +if ( !IS_ENABLED (CONFIG_CPU_ONLINE_OFFLINE ) ) +break ; + + switch ( hp_op )
... solely here. Is such a variable really warranted?
Quoted 7 lines
xen/common/sysctl.c +7
-0+ { +case XEN_SYSCTL_CPU_HOTPLUG_ONLINE : + fn = cpu_up_helper; +break ; + +case XEN_SYSCTL_CPU_HOTPLUG_OFFLINE : + fn = cpu_down_helper;
xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 505
Quoted 10 lines
xen/common/sysctl.c +10
-0+break ; + +default : + fn =NULL ; +break ; + } + +if ( fn ) + { + ret =continue_hypercall_on_cpu (0 , fn, hcpu);
Same (maybe to slightly lesser degree) for "hcpu", used solely here.
For both variables, the situation is/was different in the original code.
Jan
PATCH v9 5/6 tools: Allow building xen-hptool without CONFIG_MIGRATE
In reply to Mykyta PoturaiWith CPU hotplug sysctls implemented on Arm it becomes useful to have a tool for calling them.
According to the commit history it seems that putting hptool under config MIGRATE was a measure to fix IA64 build. As IA64 is no longer supported it can now be brought back. So build it unconditionally.
Operations specific to x86 architecture are moved into a separate file and only built on x86.
---v8->v9:
* use CONFIG_X86 instead of CONFIG_MIGRATE
* fix style issues
* add SPDX headers
v7->v8:
* move x86 specific function into a separate file
v6->v7:
* no changes
v5->v6:
* don't change order in Makefile
v4->v5:
* make hptool always build
v3->v4:
* no changes
v2->v3:
* no changes
v1->v2:
* switch to configure from legacy config
--- tools/misc/Makefile | 9 +- tools/misc/xen-hptool-x86.c | 278 ++++++++++++++++++++++++++++++++++ tools/misc/xen-hptool.c | 293 ++---------------------------------- tools/misc/xen-hptool.h | 15 ++ 4 files changed, 314 insertions(+), 281 deletions(-) create mode 100644 tools/misc/xen-hptool-x86.c create mode 100644 tools/misc/xen-hptool.h
tools/misc/Makefile +6 -3
@@ -16,7 +16,7 @@ INSTALL_BIN += xencov_split INSTALL_BIN += $(INSTALL_BIN-y) # Everything to be installed in regular sbin/ -INSTALL_SBIN-$(CONFIG_MIGRATE) += xen-hptool +INSTALL_SBIN += xen-hptool INSTALL_SBIN-$(CONFIG_X86) += xen-hvmcrash INSTALL_SBIN-$(CONFIG_X86) += xen-hvmctx INSTALL_SBIN-$(CONFIG_X86) += xen-lowmemd
@@ -104,8 +104,11 @@ xenhypfs: xenhypfs.o xenlockprof: xenlockprof.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) -xen-hptool: xen-hptool.o - $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS) +hptool-objs-y := xen-hptool.o +hptool-objs-$(CONFIG_X86) += xen-hptool-x86.o + +xen-hptool: $(hptool-objs-y) + $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS) xenhypfs.o: CFLAGS += $(CFLAGS_libxenhypfs)
tools/misc/xen-hptool-x86.c new file +278 -0
278 lines not on this page · raw message
tools/misc/xen-hptool.c +15 -278
373 lines not on this page · raw message
tools/misc/xen-hptool.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __XEN_HPTOOL_H__ +#define __XEN_HPTOOL_H__ + +#if defined(__i386__) || defined(__x86_64__) +int hp_mem_online_func (int argc,char *argv[],xc_interface *xch); +int hp_mem_query_func (int argc,char *argv[],xc_interface *xch); +int hp_mem_offline_func (int argc,char *argv[],xc_interface *xch); +int main_smt_enable (int argc,char *argv[],xc_interface *xch); +int main_smt_disable (int argc,char *argv[],xc_interface *xch); +#endif + +void show_help (void ); + +#endif /* __XEN_HPTOOL_H__ */
Signature · 1 line
2.55.0
Re: [PATCH v9 5/6] tools: Allow building xen-hptool without CONFIG_MIGRATE
Quoted 11 lines · Mykyta Poturai
With CPU hotplug sysctls implemented on Arm it becomes useful to have a tool for calling them.
According to the commit history it seems that putting hptool under config MIGRATE was a measure to fix IA64 build. As IA64 is no longer supported it can now be brought back. So build it unconditionally.
Operations specific to x86 architecture are moved into a separate file and only built on x86.
Signed-off-by Mykyta Poturai <[email protected]>
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH v9 6/6 docs: Document CPU hotplug
In reply to Mykyta Poturai---v8->v9:
* fix typos
v7->v8:
* remove support status update
* update config option name
v6->v7:
* add testing and limitations
v5->v6:
* no changes
v4->v5:
* s/supported/implemented/
* update SUPPORT.md
v3->v4:
* update configuration section
v2->v3:
* patch introduced
--- docs/misc/cpu-hotplug.txt | 98 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 docs/misc/cpu-hotplug.txt
docs/misc/cpu-hotplug.txt new file +98 -0
@@ -0,0 +1,98 @@ +CPU Hotplug +=========== + +CPU hotplug is a feature that allows pCPU cores to be added to or removed from a +running system without requiring a reboot. It is implemented on x86 and Arm64 +architectures. + +Implementation Details +---------------------- + +CPU hotplug is implemented through the `XEN_SYSCTL_CPU_HOTPLUG_*` sysctl calls. +The specific calls are: + +- `XEN_SYSCTL_CPU_HOTPLUG_ONLINE`: Brings a pCPU online +- `XEN_SYSCTL_CPU_HOTPLUG_OFFLINE`: Takes a pCPU offline +- `XEN_SYSCTL_CPU_HOTPLUG_SMT_ENABLE`: Enables SMT threads (x86 only) +- `XEN_SYSCTL_CPU_HOTPLUG_SMT_DISABLE`: Disables SMT threads (x86 only) + +All cores can be disabled, assuming hardware support, except for the boot core. +Sysctl calls are routed to the boot core before doing any actual up/down +operations on other cores. + +If there are Xen-bound interrupts pinned to the pCPU being offlined, they will +be automatically migrated to other online pCPUs. Interrupts used by guest +domains are handled by the scheduler when it reschedules the vCPUs to a new, +online, pCPU. When a pCPU is being onlined, some Xen-bound interrupts will get +redistributed to the newly onlined pCPU to prevent imbalance. + +If pCPU being offlined has some vCPUs pinned to it, they will be automatically +unpinned and migrated to other online pCPUs. + +Limitations +----------- + +On Arm64 cpu hotplug is currently not compatible with ITS, due to an issue with +the redistributor assignment. + +On Arm64 there can be problems with FFA if secure FW supports the notification +ABI, and with TEE, as both use non-static IRQ actions. + +Configuration +------------- + +The presence of the feature is controlled by CONFIG_CPU_ONLINE_OFFLINE option. +It is enabled by default on x86 architecture. On Arm64, the option is disabled +by default and marked as EXPERT. xen-hptool userspace tool is built +unconditionally. + +Usage +----- + +Disable core: + +$ xen-hptool cpu-offline 2 +Prepare to offline CPU 2 +(XEN) Removing cpu 2 from runqueue 0 +CPU 2 offlined successfully + +Enable core: + +$ xen-hptool cpu-online 2 +Prepare to online CPU 2 +(XEN) Bringing up CPU2 +(XEN) GICv3: CPU2: Found redistributor in region 0 @00000a004005c000 +(XEN) CPU2: Guest atomics will try 1 times before pausing the domain +(XEN) CPU 2 booted. +(XEN) Adding cpu 2 to runqueue 0 +CPU 2 onlined successfully + +Disabling a core with pinned vCPUs: + +$ xl vcpu-pin 0 3 3 3 +$ xl vcpu-pin 0 2 3 3 +$ xl vcpu-pin 0 1 3 3 +$ xl vcpu-pin 0 0 3 3 +$ xen-hptool cpu-offline 3 +Prepare to offline CPU 3 +(XEN) Breaking affinity for d0v0 +(XEN) Breaking affinity for d0v1 +(XEN) Breaking affinity for d0v2 +(XEN) Breaking affinity for d0v3 +(XEN) Removing cpu 3 from runqueue 0 +CPU 3 offlined successfully + +Testing +------- + +The CPU hotplug feature has been tested on both x86 and Arm64 QEMU setups and on +R-Car Gen5 (Arm64) hardware. + +The tests included: +- Offlining and onlining cores with no pinned vCPUs +- Offlining cores with pinned vCPUs +- Offlining cores with Xen-bound interrupts +- Offlining all cores except the boot core +- Offlining the boot core (expected to fail) +- Enabling and disabling SMT threads (x86 only) +- Offlining cores to which guests with passthrough devices are pinned
Signature · 1 line
2.55.0
Re: [PATCH v9 6/6] docs: Document CPU hotplug
Hi,
Mykyta Poturai <[email protected]> writes:
I have a couple of questions, please see below
Quoted 61 lines
Signed-off-by Mykyta Poturai <[email protected]>---
v8->v9:
* fix typos
v7->v8:
* remove support status update
* update config option name
v6->v7:
* add testing and limitations
v5->v6:
* no changes
v4->v5:
* s/supported/implemented/
* update SUPPORT.md
v3->v4:
* update configuration section
v2->v3:
* patch introduced--- docs/misc/cpu-hotplug.txt | 98 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 docs/misc/cpu-hotplug.txtdocs/misc/cpu-hotplug.txt new file +26
-0@@ -0,0 +1,98 @@ +CPU Hotplug +=========== + +CPU hotplug is a feature that allows pCPU cores to be added to or removed from a +running system without requiring a reboot. It is implemented on x86 and Arm64 +architectures. + +Implementation Details +---------------------- + +CPU hotplug is implemented through the `XEN_SYSCTL_CPU_HOTPLUG_*` sysctl calls. +The specific calls are: + +- `XEN_SYSCTL_CPU_HOTPLUG_ONLINE`: Brings a pCPU online +- `XEN_SYSCTL_CPU_HOTPLUG_OFFLINE`: Takes a pCPU offline +- `XEN_SYSCTL_CPU_HOTPLUG_SMT_ENABLE`: Enables SMT threads (x86 only) +- `XEN_SYSCTL_CPU_HOTPLUG_SMT_DISABLE`: Disables SMT threads (x86 only) + +All cores can be disabled, assuming hardware support, except for the boot core. +Sysctl calls are routed to the boot core before doing any actual up/down +operations on other cores. + +If there are Xen-bound interrupts pinned to the pCPU being offlined, they will +be automatically migrated to other online pCPUs. Interrupts used by guest +domains are handled by the scheduler when it reschedules the vCPUs to a new, +online, pCPU. When a pCPU is being onlined, some Xen-bound interrupts will get
docs/misc/cpu-hotplug.txt line 36
Quoted 10 lines
docs/misc/cpu-hotplug.txt new file +10
-0+redistributed to the newly onlined pCPU to prevent imbalance. + +If pCPU being offlined has some vCPUs pinned to it, they will be automatically +unpinned and migrated to other online pCPUs. + +Limitations +----------- + +On Arm64 cpu hotplug is currently not compatible with ITS, due to an issue with +the redistributor assignment.
In this case you probably want to make sure that CONFIG_CPU_ONLINE_OFFLINE is incompatible with CONFIG_HAS_ITS
docs/misc/cpu-hotplug.txt line 39
Quoted 3 lines
docs/misc/cpu-hotplug.txt new file +3
-0+ +On Arm64 there can be problems with FFA if secure FW supports the notification +ABI, and with TEE, as both use non-static IRQ actions.
Could you please elaborate on this? AFAIK, OP-TEE has own cpu_up/cpu_down callbacks, so it should know which CPUs are online.
Quoted 59 lines
docs/misc/cpu-hotplug.txt new file +59
-0+ +Configuration +------------- + +The presence of the feature is controlled by CONFIG_CPU_ONLINE_OFFLINE option. +It is enabled by default on x86 architecture. On Arm64, the option is disabled +by default and marked as EXPERT. xen-hptool userspace tool is built +unconditionally. + +Usage +----- + +Disable core: + +$ xen-hptool cpu-offline 2 +Prepare to offline CPU 2 +(XEN) Removing cpu 2 from runqueue 0 +CPU 2 offlined successfully + +Enable core: + +$ xen-hptool cpu-online 2 +Prepare to online CPU 2 +(XEN) Bringing up CPU2 +(XEN) GICv3: CPU2: Found redistributor in region 0 @00000a004005c000 +(XEN) CPU2: Guest atomics will try 1 times before pausing the domain +(XEN) CPU 2 booted. +(XEN) Adding cpu 2 to runqueue 0 +CPU 2 onlined successfully + +Disabling a core with pinned vCPUs: + +$ xl vcpu-pin 0 3 3 3 +$ xl vcpu-pin 0 2 3 3 +$ xl vcpu-pin 0 1 3 3 +$ xl vcpu-pin 0 0 3 3 +$ xen-hptool cpu-offline 3 +Prepare to offline CPU 3 +(XEN) Breaking affinity for d0v0 +(XEN) Breaking affinity for d0v1 +(XEN) Breaking affinity for d0v2 +(XEN) Breaking affinity for d0v3 +(XEN) Removing cpu 3 from runqueue 0 +CPU 3 offlined successfully + +Testing +------- + +The CPU hotplug feature has been tested on both x86 and Arm64 QEMU setups and on +R-Car Gen5 (Arm64) hardware. + +The tests included: +- Offlining and onlining cores with no pinned vCPUs +- Offlining cores with pinned vCPUs +- Offlining cores with Xen-bound interrupts +- Offlining all cores except the boot core +- Offlining the boot core (expected to fail) +- Enabling and disabling SMT threads (x86 only) +- Offlining cores to which guests with passthrough devices are pinned
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v9 6/6] docs: Document CPU hotplug
Quoted 81 lines · Volodymyr Babchuk
Hi,
Mykyta Poturai <[email protected]> writes:
I have a couple of questions, please see below
Quoted 61 lines
Signed-off-by Mykyta Poturai <[email protected]>---
v8->v9:
* fix typos
v7->v8:
* remove support status update
* update config option name
v6->v7:
* add testing and limitations
v5->v6:
* no changes
v4->v5:
* s/supported/implemented/
* update SUPPORT.md
v3->v4:
* update configuration section
v2->v3:
* patch introduced--- docs/misc/cpu-hotplug.txt | 98 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+)create mode 100644
docs/misc/cpu-hotplug.txtdocs/misc/cpu-hotplug.txt new file +26
-0@@ -0,0 +1,98 @@ +CPU Hotplug +=========== + +CPU hotplug is a feature that allows pCPU cores to be added to or removed from a +running system without requiring a reboot. It is implemented on x86 and Arm64 +architectures. + +Implementation Details +---------------------- + +CPU hotplug is implemented through the `XEN_SYSCTL_CPU_HOTPLUG_*` sysctl calls. +The specific calls are: + +- `XEN_SYSCTL_CPU_HOTPLUG_ONLINE`: Brings a pCPU online +- `XEN_SYSCTL_CPU_HOTPLUG_OFFLINE`: Takes a pCPU offline +- `XEN_SYSCTL_CPU_HOTPLUG_SMT_ENABLE`: Enables SMT threads (x86 only) +- `XEN_SYSCTL_CPU_HOTPLUG_SMT_DISABLE`: Disables SMT threads (x86 only) + +All cores can be disabled, assuming hardware support, except for the boot core. +Sysctl calls are routed to the boot core before doing any actual up/down +operations on other cores. + +If there are Xen-bound interrupts pinned to the pCPU being offlined, they will +be automatically migrated to other online pCPUs. Interrupts used by guest +domains are handled by the scheduler when it reschedules the vCPUs to a new, +online, pCPU. When a pCPU is being onlined, some Xen-bound interrupts will getdocs/misc/cpu-hotplug.txt line 36
Quoted 10 lines
docs/misc/cpu-hotplug.txt new file +10
-0+redistributed to the newly onlined pCPU to prevent imbalance. + +If pCPU being offlined has some vCPUs pinned to it, they will be automatically +unpinned and migrated to other online pCPUs. + +Limitations +----------- + +On Arm64 cpu hotplug is currently not compatible with ITS, due to an issue with +the redistributor assignment.In this case you probably want to make sure that
CONFIG_CPU_ONLINE_OFFLINEis incompatible withCONFIG_HAS_ITS
Quoted 6 lines
docs/misc/cpu-hotplug.txt line 39
Quoted 3 lines
docs/misc/cpu-hotplug.txt new file +3
-0+ +On Arm64 there can be problems with FFA if secure FW supports the notification +ABI, and with TEE, as both use non-static IRQ actions.Could you please elaborate on this? AFAIK, OP-TEE has own cpu_up/cpu_down callbacks, so it should know which CPUs are online.
It's more of a problem with the way interrupt handlers are set up in Xen. Mykola already has fixes for it in a separate series, but I'm not how to best sync up our efforts.
Re: [PATCH v9 6/6] docs: Document CPU hotplug
Hi Mykyta,
Quoted 89 lines · Mykyta Poturai
Quoted 81 lines · Volodymyr Babchuk
Hi,
Mykyta Poturai <[email protected]> writes:
I have a couple of questions, please see below
Quoted 61 lines
Signed-off-by Mykyta Poturai <[email protected]>---
v8->v9:
* fix typos
v7->v8:
* remove support status update
* update config option name
v6->v7:
* add testing and limitations
v5->v6:
* no changes
v4->v5:
* s/supported/implemented/
* update SUPPORT.md
v3->v4:
* update configuration section
v2->v3:
* patch introduced--- docs/misc/cpu-hotplug.txt | 98 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+)create mode 100644
docs/misc/cpu-hotplug.txtdocs/misc/cpu-hotplug.txt new file +26
-0@@ -0,0 +1,98 @@ +CPU Hotplug +=========== + +CPU hotplug is a feature that allows pCPU cores to be added to or removed from a +running system without requiring a reboot. It is implemented on x86 and Arm64 +architectures. + +Implementation Details +---------------------- + +CPU hotplug is implemented through the `XEN_SYSCTL_CPU_HOTPLUG_*` sysctl calls. +The specific calls are: + +- `XEN_SYSCTL_CPU_HOTPLUG_ONLINE`: Brings a pCPU online +- `XEN_SYSCTL_CPU_HOTPLUG_OFFLINE`: Takes a pCPU offline +- `XEN_SYSCTL_CPU_HOTPLUG_SMT_ENABLE`: Enables SMT threads (x86 only) +- `XEN_SYSCTL_CPU_HOTPLUG_SMT_DISABLE`: Disables SMT threads (x86 only) + +All cores can be disabled, assuming hardware support, except for the boot core. +Sysctl calls are routed to the boot core before doing any actual up/down +operations on other cores. + +If there are Xen-bound interrupts pinned to the pCPU being offlined, they will +be automatically migrated to other online pCPUs. Interrupts used by guest +domains are handled by the scheduler when it reschedules the vCPUs to a new, +online, pCPU. When a pCPU is being onlined, some Xen-bound interrupts will getdocs/misc/cpu-hotplug.txt line 36
Quoted 10 lines
docs/misc/cpu-hotplug.txt new file +10
-0+redistributed to the newly onlined pCPU to prevent imbalance. + +If pCPU being offlined has some vCPUs pinned to it, they will be automatically +unpinned and migrated to other online pCPUs. + +Limitations +----------- + +On Arm64 cpu hotplug is currently not compatible with ITS, due to an issue with +the redistributor assignment.In this case you probably want to make sure that
CONFIG_CPU_ONLINE_OFFLINEis incompatible withCONFIG_HAS_ITSQuoted 6 lines
docs/misc/cpu-hotplug.txt line 39
Quoted 3 lines
docs/misc/cpu-hotplug.txt new file +3
-0+ +On Arm64 there can be problems with FFA if secure FW supports the notification +ABI, and with TEE, as both use non-static IRQ actions.Could you please elaborate on this? AFAIK, OP-TEE has own cpu_up/cpu_down callbacks, so it should know which CPUs are online.
Quoted 4 lines
It's more of a problem with the way interrupt handlers are set up in Xen. Mykola already has fixes for it in a separate series, but I'm not how to best sync up our efforts.
Ah, okay, got it. I think that in this case you also want to make sure that both these features are not enabled in the same time.
Signature · 1 line
WBR, Volodymyr