From 41f30679648676d4d62b1ae9026dde77fa9895d5 Mon Sep 17 00:00:00 2001 From: Kunkun Jiang Date: Tue, 14 Feb 2023 20:39:07 +0800 Subject: [PATCH] arm/virt: Correct timing of pause all vcpus for hot-plugged CPUs When dealing with hot-plugging cpus, it may fail when realize cpu. Such a failure would make paused vcpus unrecoverable. So we only pause all vcpus when needed. Add removed some unnecessary checks. Signed-off-by: Kunkun Jiang --- hw/arm/virt.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 7d5b332594..4c876fcf16 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2747,13 +2747,6 @@ static void virt_cpu_pre_plug(HotplugHandler *hotplug_dev, &error_abort); } } - - /* If we use KVM accel, we should pause all vcpus to - * allow hot access of vcpu registers. - */ - if (dev->hotplugged && kvm_enabled()) { - pause_all_vcpus(); - } } static void virt_cpu_plug(HotplugHandler *hotplug_dev, @@ -2773,6 +2766,10 @@ static void virt_cpu_plug(HotplugHandler *hotplug_dev, /* For CPU that is cold/hot plugged */ if (ncpu >= ms->smp.cpus) { + if (dev->hotplugged) { + pause_all_vcpus(); + } + /* Realize GIC related parts of CPU */ assert(vms->gic_version == 3); gicv3 = ARM_GICV3_COMMON(vms->gic); @@ -2803,6 +2800,10 @@ static void virt_cpu_plug(HotplugHandler *hotplug_dev, cpu_hotplug_register_reset(ncpu); cpu_hotplug_reset_manually(ncpu); cpu_synchronize_post_reset(cs); + + if (dev->hotplugged) { + resume_all_vcpus(); + } } if (dev->hotplugged && kvm_enabled()) { -- 2.27.0