Skip to contentSkip to conversation

pc: make sure that guest isn't able to unplug the first cpu

PATCH In review Igor Mammedov 6 participants 13 messages Aug 27, 2018 – Sep 10, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pc: make sure that guest isn't able to unplug the first cpu

The first cpu unplug wasn't ever supported and corresponding monitor/qmp commands refuse to unplug it. However guest is able to issue eject request either using following command:

  # echo 1 >/sys/devices/system/cpu/cpu0/firmware_node/eject
or directly writing to cpu hotplug registers, which makes
qemu crash with SIGSEGV following back trace:

kvm_flush_coalesced_mmio_buffer ()

       while (ring->first != ring->last)

...
qemu_flush_coalesced_mmio_buffer
prepare_mmio_access
flatview_read_continue
flatview_read
address_space_read_full
address_space_rw
kvm_cpu_exec(cpu!0)
qemu_kvm_cpu_thread_fn

the reason for which is that ring == KVMState::coalesced_mmio_ring happens to be a part of 1st CPU that was uplugged by guest.

Fix it by forbidding 1st cpu unplug from guest side and in addition remove CPU0._EJ0 ACPI method to make clear that unplug of the first CPU is not supported.

---
CCing spapr and s390x folks in case targets need to prevent 1st CPU unplug as well

---
 hw/acpi/cpu.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
hw/acpi/cpu.c +6 -4
index 5ae595e..4bb8371 100644
@@ -117,7 +117,7 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data,
             DeviceState *dev = NULL;
             HotplugHandler *hotplug_ctrl = NULL;
 
-            if (!cdev->cpu) {
+            if (!cdev->cpu || cdev->cpu == first_cpu) {
                 trace_cpuhp_acpi_ejecting_invalid_cpu(cpu_st->selector);
                 break;
             }
@@ -541,9 +541,11 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
                 aml_buffer(madt_buf->len, (uint8_t *)madt_buf->data)));
             g_array_free(madt_buf, true);
 
-            method = aml_method("_EJ0", 1, AML_NOTSERIALIZED);
-            aml_append(method, aml_call1(CPU_EJECT_METHOD, uid));
-            aml_append(dev, method);
+            if (CPU(arch_ids->cpus[i].cpu) != first_cpu) {
+                method = aml_method("_EJ0", 1, AML_NOTSERIALIZED);
+                aml_append(method, aml_call1(CPU_EJECT_METHOD, uid));
+                aml_append(dev, method);
+            }
 
             method = aml_method("_OST", 3, AML_SERIALIZED);
             aml_append(method,
Signature · 1 line
2.7.4
#1 lore raw
Quoted 22 lines · Igor Mammedov

The first cpu unplug wasn't ever supported and corresponding monitor/qmp commands refuse to unplug it. However guest is able to issue eject request either using following command:

  # echo 1 >/sys/devices/system/cpu/cpu0/firmware_node/eject
or directly writing to cpu hotplug registers, which makes
qemu crash with SIGSEGV following back trace:
   kvm_flush_coalesced_mmio_buffer ()
       while (ring->first != ring->last)
   ...
   qemu_flush_coalesced_mmio_buffer
   prepare_mmio_access
   flatview_read_continue
   flatview_read
   address_space_read_full
   address_space_rw
   kvm_cpu_exec(cpu!0)
   qemu_kvm_cpu_thread_fn

the reason for which is that ring == KVMState::coalesced_mmio_ring happens to be a part of 1st CPU that was uplugged by guest.

Quoted 7 lines

Fix it by forbidding 1st cpu unplug from guest side and in addition remove CPU0._EJ0 ACPI method to make clear that unplug of the first CPU is not supported.

---
CCing spapr and s390x folks in case targets need to prevent 1st CPU unplug as well

No unplug on s390x, so we're fine.

Quoted 40 lines
---
 hw/acpi/cpu.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
hw/acpi/cpu.c +6 -4
index 5ae595e..4bb8371 100644
@@ -117,7 +117,7 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data,
             DeviceState *dev = NULL;
             HotplugHandler *hotplug_ctrl = NULL;
 
-            if (!cdev->cpu) {
+            if (!cdev->cpu || cdev->cpu == first_cpu) {
                 trace_cpuhp_acpi_ejecting_invalid_cpu(cpu_st->selector);
                 break;
             }
@@ -541,9 +541,11 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
                 aml_buffer(madt_buf->len, (uint8_t *)madt_buf->data)));
             g_array_free(madt_buf, true);
 
-            method = aml_method("_EJ0", 1, AML_NOTSERIALIZED);
-            aml_append(method, aml_call1(CPU_EJECT_METHOD, uid));
-            aml_append(dev, method);
+            if (CPU(arch_ids->cpus[i].cpu) != first_cpu) {
+                method = aml_method("_EJ0", 1, AML_NOTSERIALIZED);
+                aml_append(method, aml_call1(CPU_EJECT_METHOD, uid));
+                aml_append(dev, method);
+            }
 
             method = aml_method("_OST", 3, AML_SERIALIZED);
             aml_append(method,
Signature · 3 lines
Thanks,

David / dhildenb
#2 lore raw
In reply to Igor Mammedov
Quoted 4 lines · On Mon, 27 Aug 2018 13:07:10 +0200 Igor Mammedov <[email protected]> wrote:

The first cpu unplug wasn't ever supported and corresponding monitor/qmp commands refuse to unplug it. However guest is able to issue eject request either using following command:

  # echo 1 >/sys/devices/system/cpu/cpu0/firmware_node/eject

I can't reproduce the issue with a pc guest and current master...

All I seem to get is an error in dmesg:

[   97.435446] processor cpu0: Offline failed.
Quoted 18 lines

or directly writing to cpu hotplug registers, which makes qemu crash with SIGSEGV following back trace:

   kvm_flush_coalesced_mmio_buffer ()
       while (ring->first != ring->last)
   ...
   qemu_flush_coalesced_mmio_buffer
   prepare_mmio_access
   flatview_read_continue
   flatview_read
   address_space_read_full
   address_space_rw
   kvm_cpu_exec(cpu!0)
   qemu_kvm_cpu_thread_fn

the reason for which is that ring == KVMState::coalesced_mmio_ring happens to be a part of 1st CPU that was uplugged by guest.

Quoted 8 lines

Fix it by forbidding 1st cpu unplug from guest side and in addition remove CPU0._EJ0 ACPI method to make clear that unplug of the first CPU is not supported.

---
CCing spapr and s390x folks in case targets need to prevent 1st CPU unplug as well

A spapr guest can _release_ the first cpu by doing something like:

# echo -n "/cpus/PowerPC,POWER8@0" > /sys/devices/system/cpu/release

But AFAIK, this doesn't unplug the cpu from a QEMU standpoint.

Quoted 38 lines
---
 hw/acpi/cpu.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
hw/acpi/cpu.c +6 -4
index 5ae595e..4bb8371 100644
@@ -117,7 +117,7 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data,
             DeviceState *dev = NULL;
             HotplugHandler *hotplug_ctrl = NULL;
 
-            if (!cdev->cpu) {
+            if (!cdev->cpu || cdev->cpu == first_cpu) {
                 trace_cpuhp_acpi_ejecting_invalid_cpu(cpu_st->selector);
                 break;
             }
@@ -541,9 +541,11 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
                 aml_buffer(madt_buf->len, (uint8_t *)madt_buf->data)));
             g_array_free(madt_buf, true);
 
-            method = aml_method("_EJ0", 1, AML_NOTSERIALIZED);
-            aml_append(method, aml_call1(CPU_EJECT_METHOD, uid));
-            aml_append(dev, method);
+            if (CPU(arch_ids->cpus[i].cpu) != first_cpu) {
+                method = aml_method("_EJ0", 1, AML_NOTSERIALIZED);
+                aml_append(method, aml_call1(CPU_EJECT_METHOD, uid));
+                aml_append(dev, method);
+            }
 
             method = aml_method("_OST", 3, AML_SERIALIZED);
             aml_append(method,
#3 lore raw
Quoted 8 lines · On Mon, 27 Aug 2018 16:02:39 +0200 Greg Kurz <[email protected]> wrote:
Quoted 4 lines · On Mon, 27 Aug 2018 13:07:10 +0200 Igor Mammedov <[email protected]> wrote:

The first cpu unplug wasn't ever supported and corresponding monitor/qmp commands refuse to unplug it. However guest is able to issue eject request either using following command:

  # echo 1 >/sys/devices/system/cpu/cpu0/firmware_node/eject  
Quoted 5 lines

I can't reproduce the issue with a pc guest and current master...

All I seem to get is an error in dmesg:

[   97.435446] processor cpu0: Offline failed.

To be able to unplug CPU0 one need to set CONFIG_BOOTPARAM_HOTPLUG_CPU0=y (I've tested it with a RHLE7 kernel)

Quoted 27 lines
Quoted 18 lines

or directly writing to cpu hotplug registers, which makes qemu crash with SIGSEGV following back trace:

   kvm_flush_coalesced_mmio_buffer ()
       while (ring->first != ring->last)
   ...
   qemu_flush_coalesced_mmio_buffer
   prepare_mmio_access
   flatview_read_continue
   flatview_read
   address_space_read_full
   address_space_rw
   kvm_cpu_exec(cpu!0)
   qemu_kvm_cpu_thread_fn

the reason for which is that ring == KVMState::coalesced_mmio_ring happens to be a part of 1st CPU that was uplugged by guest.

Quoted 8 lines

Fix it by forbidding 1st cpu unplug from guest side and in addition remove CPU0._EJ0 ACPI method to make clear that unplug of the first CPU is not supported.

---
CCing spapr and s390x folks in case targets need to prevent 1st CPU unplug as well

Quoted 5 lines

A spapr guest can _release_ the first cpu by doing something like:

# echo -n "/cpus/PowerPC,POWER8@0" > /sys/devices/system/cpu/release

But AFAIK, this doesn't unplug the cpu from a QEMU standpoint.

Good,
so only x86 fix should be fixed.

Quoted 39 lines
Quoted 38 lines
---
 hw/acpi/cpu.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
hw/acpi/cpu.c +6 -4
index 5ae595e..4bb8371 100644
@@ -117,7 +117,7 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data,
             DeviceState *dev = NULL;
             HotplugHandler *hotplug_ctrl = NULL;
 
-            if (!cdev->cpu) {
+            if (!cdev->cpu || cdev->cpu == first_cpu) {
                 trace_cpuhp_acpi_ejecting_invalid_cpu(cpu_st->selector);
                 break;
             }
@@ -541,9 +541,11 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
                 aml_buffer(madt_buf->len, (uint8_t *)madt_buf->data)));
             g_array_free(madt_buf, true);
 
-            method = aml_method("_EJ0", 1, AML_NOTSERIALIZED);
-            aml_append(method, aml_call1(CPU_EJECT_METHOD, uid));
-            aml_append(dev, method);
+            if (CPU(arch_ids->cpus[i].cpu) != first_cpu) {
+                method = aml_method("_EJ0", 1, AML_NOTSERIALIZED);
+                aml_append(method, aml_call1(CPU_EJECT_METHOD, uid));
+                aml_append(dev, method);
+            }
 
             method = aml_method("_OST", 3, AML_SERIALIZED);
             aml_append(method,  
#4 lore raw
In reply to Greg Kurz
Quoted 41 lines · Greg Kurz
Quoted 4 lines · On Mon, 27 Aug 2018 13:07:10 +0200 Igor Mammedov <[email protected]> wrote:

The first cpu unplug wasn't ever supported and corresponding monitor/qmp commands refuse to unplug it. However guest is able to issue eject request either using following command:

  # echo 1 >/sys/devices/system/cpu/cpu0/firmware_node/eject

I can't reproduce the issue with a pc guest and current master...

All I seem to get is an error in dmesg:

[   97.435446] processor cpu0: Offline failed.
Quoted 18 lines

or directly writing to cpu hotplug registers, which makes qemu crash with SIGSEGV following back trace:

   kvm_flush_coalesced_mmio_buffer ()
       while (ring->first != ring->last)
   ...
   qemu_flush_coalesced_mmio_buffer
   prepare_mmio_access
   flatview_read_continue
   flatview_read
   address_space_read_full
   address_space_rw
   kvm_cpu_exec(cpu!0)
   qemu_kvm_cpu_thread_fn

the reason for which is that ring == KVMState::coalesced_mmio_ring happens to be a part of 1st CPU that was uplugged by guest.

Quoted 8 lines

Fix it by forbidding 1st cpu unplug from guest side and in addition remove CPU0._EJ0 ACPI method to make clear that unplug of the first CPU is not supported.

---
CCing spapr and s390x folks in case targets need to prevent 1st CPU unplug as well

Quoted 5 lines

A spapr guest can _release_ the first cpu by doing something like:

# echo -n "/cpus/PowerPC,POWER8@0" > /sys/devices/system/cpu/release

But AFAIK, this doesn't unplug the cpu from a QEMU standpoint.

Unplugging CPU 0 with device_del should be ok too.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#5 lore raw
Quoted 42 lines · On Tue, 28 Aug 2018 10:52:37 +1000 David Gibson <[email protected]>…
Quoted 41 lines · Greg Kurz
Quoted 4 lines · On Mon, 27 Aug 2018 13:07:10 +0200 Igor Mammedov <[email protected]> wrote:

The first cpu unplug wasn't ever supported and corresponding monitor/qmp commands refuse to unplug it. However guest is able to issue eject request either using following command:

  # echo 1 >/sys/devices/system/cpu/cpu0/firmware_node/eject  

I can't reproduce the issue with a pc guest and current master...

All I seem to get is an error in dmesg:

[   97.435446] processor cpu0: Offline failed.
Quoted 26 lines

or directly writing to cpu hotplug registers, which makes qemu crash with SIGSEGV following back trace:

   kvm_flush_coalesced_mmio_buffer ()
       while (ring->first != ring->last)
   ...
   qemu_flush_coalesced_mmio_buffer
   prepare_mmio_access
   flatview_read_continue
   flatview_read
   address_space_read_full
   address_space_rw
   kvm_cpu_exec(cpu!0)
   qemu_kvm_cpu_thread_fn

the reason for which is that ring == KVMState::coalesced_mmio_ring happens to be a part of 1st CPU that was uplugged by guest.

Fix it by forbidding 1st cpu unplug from guest side and in addition remove CPU0._EJ0 ACPI method to make clear that unplug of the first CPU is not supported.

---
CCing spapr and s390x folks in case targets need to prevent 1st CPU unplug as well

Quoted 7 lines
Quoted 5 lines

A spapr guest can _release_ the first cpu by doing something like:

# echo -n "/cpus/PowerPC,POWER8@0" > /sys/devices/system/cpu/release

But AFAIK, this doesn't unplug the cpu from a QEMU standpoint.

Unplugging CPU 0 with device_del should be ok too.

Do you mean real unplugging (cpu0 object freed) or just remove request?

#6 lore raw
Quoted 45 lines · Igor Mammedov
Quoted 42 lines · On Tue, 28 Aug 2018 10:52:37 +1000 David Gibson <[email protected]>…
Quoted 41 lines · Greg Kurz
Quoted 4 lines · On Mon, 27 Aug 2018 13:07:10 +0200 Igor Mammedov <[email protected]> wrote:

The first cpu unplug wasn't ever supported and corresponding monitor/qmp commands refuse to unplug it. However guest is able to issue eject request either using following command:

  # echo 1 >/sys/devices/system/cpu/cpu0/firmware_node/eject  

I can't reproduce the issue with a pc guest and current master...

All I seem to get is an error in dmesg:

[   97.435446] processor cpu0: Offline failed.
Quoted 26 lines

or directly writing to cpu hotplug registers, which makes qemu crash with SIGSEGV following back trace:

   kvm_flush_coalesced_mmio_buffer ()
       while (ring->first != ring->last)
   ...
   qemu_flush_coalesced_mmio_buffer
   prepare_mmio_access
   flatview_read_continue
   flatview_read
   address_space_read_full
   address_space_rw
   kvm_cpu_exec(cpu!0)
   qemu_kvm_cpu_thread_fn

the reason for which is that ring == KVMState::coalesced_mmio_ring happens to be a part of 1st CPU that was uplugged by guest.

Fix it by forbidding 1st cpu unplug from guest side and in addition remove CPU0._EJ0 ACPI method to make clear that unplug of the first CPU is not supported.

---
CCing spapr and s390x folks in case targets need to prevent 1st CPU unplug as well

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

A spapr guest can _release_ the first cpu by doing something like:

# echo -n "/cpus/PowerPC,POWER8@0" > /sys/devices/system/cpu/release

But AFAIK, this doesn't unplug the cpu from a QEMU standpoint.

Unplugging CPU 0 with device_del should be ok too.

Do you mean real unplugging (cpu0 object freed) or just remove request?

Real unplugging should be possible. I'm not sure how thorougly it's been tested, though.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#7 lore raw
Quoted 50 lines · On Wed, 29 Aug 2018 12:54:40 +1000 David Gibson <[email protected]>…
Quoted 49 lines · Igor Mammedov
Quoted 46 lines · On Tue, 28 Aug 2018 10:52:37 +1000 David Gibson <[email protected]>…
Quoted 45 lines · Greg Kurz
Quoted 4 lines · On Mon, 27 Aug 2018 13:07:10 +0200 Igor Mammedov <[email protected]> wrote:

The first cpu unplug wasn't ever supported and corresponding monitor/qmp commands refuse to unplug it. However guest is able to issue eject request either using following command:

  # echo 1 >/sys/devices/system/cpu/cpu0/firmware_node/eject    

I can't reproduce the issue with a pc guest and current master...

All I seem to get is an error in dmesg:

[   97.435446] processor cpu0: Offline failed.
Quoted 18 lines

or directly writing to cpu hotplug registers, which makes qemu crash with SIGSEGV following back trace:

   kvm_flush_coalesced_mmio_buffer ()
       while (ring->first != ring->last)
   ...
   qemu_flush_coalesced_mmio_buffer
   prepare_mmio_access
   flatview_read_continue
   flatview_read
   address_space_read_full
   address_space_rw
   kvm_cpu_exec(cpu!0)
   qemu_kvm_cpu_thread_fn

the reason for which is that ring == KVMState::coalesced_mmio_ring happens to be a part of 1st CPU that was uplugged by guest.

Quoted 8 lines

Fix it by forbidding 1st cpu unplug from guest side and in addition remove CPU0._EJ0 ACPI method to make clear that unplug of the first CPU is not supported.

---
CCing spapr and s390x folks in case targets need to prevent 1st CPU unplug as well

A spapr guest can _release_ the first cpu by doing something like:

# echo -n "/cpus/PowerPC,POWER8@0" > /sys/devices/system/cpu/release
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

But AFAIK, this doesn't unplug the cpu from a QEMU standpoint.

Unplugging CPU 0 with device_del should be ok too.

Do you mean real unplugging (cpu0 object freed) or just remove request?

Real unplugging should be possible. I'm not sure how thorougly it's been tested, though.

Well, common kvm code in qemu seems to be in disagreement with it as backtrace in this patch shows also usage of first_cpu macro won't survive such unplug.

#8 lore raw
Quoted 55 lines · Igor Mammedov
Quoted 52 lines · On Wed, 29 Aug 2018 12:54:40 +1000 David Gibson <[email protected]>…
Quoted 51 lines · Igor Mammedov
Quoted 48 lines · On Tue, 28 Aug 2018 10:52:37 +1000 David Gibson <[email protected]>…
Quoted 46 lines · Greg Kurz
Quoted 4 lines · On Mon, 27 Aug 2018 13:07:10 +0200 Igor Mammedov <[email protected]> wrote:

The first cpu unplug wasn't ever supported and corresponding monitor/qmp commands refuse to unplug it. However guest is able to issue eject request either using following command:

  # echo 1 >/sys/devices/system/cpu/cpu0/firmware_node/eject    

I can't reproduce the issue with a pc guest and current master...

All I seem to get is an error in dmesg:

[   97.435446] processor cpu0: Offline failed.
Quoted 18 lines

or directly writing to cpu hotplug registers, which makes qemu crash with SIGSEGV following back trace:

   kvm_flush_coalesced_mmio_buffer ()
       while (ring->first != ring->last)
   ...
   qemu_flush_coalesced_mmio_buffer
   prepare_mmio_access
   flatview_read_continue
   flatview_read
   address_space_read_full
   address_space_rw
   kvm_cpu_exec(cpu!0)
   qemu_kvm_cpu_thread_fn

the reason for which is that ring == KVMState::coalesced_mmio_ring happens to be a part of 1st CPU that was uplugged by guest.

Quoted 8 lines

Fix it by forbidding 1st cpu unplug from guest side and in addition remove CPU0._EJ0 ACPI method to make clear that unplug of the first CPU is not supported.

---
CCing spapr and s390x folks in case targets need to prevent 1st CPU unplug as well

A spapr guest can _release_ the first cpu by doing something like:

# echo -n "/cpus/PowerPC,POWER8@0" > /sys/devices/system/cpu/release

But AFAIK, this doesn't unplug the cpu from a QEMU standpoint.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Quoted 1 line

Unplugging CPU 0 with device_del should be ok too.

Do you mean real unplugging (cpu0 object freed) or just remove request?

Real unplugging should be possible. I'm not sure how thorougly it's been tested, though.

Well, common kvm code in qemu seems to be in disagreement with it as backtrace in this patch shows also usage of first_cpu macro won't survive such unplug.

Paolo - any take on this? Do we need to make cpu 0 special like this?

Signature · 1 line
MST
#9 lore raw
Quoted 59 lines · On Wed, 29 Aug 2018 09:15:53 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 58 lines · Igor Mammedov
Quoted 55 lines · On Wed, 29 Aug 2018 12:54:40 +1000 David Gibson <[email protected]>…
Quoted 53 lines · Igor Mammedov
Quoted 42 lines · On Tue, 28 Aug 2018 10:52:37 +1000 David Gibson <[email protected]>…
Quoted 41 lines · Greg Kurz
Quoted 4 lines · On Mon, 27 Aug 2018 13:07:10 +0200 Igor Mammedov <[email protected]> wrote:

The first cpu unplug wasn't ever supported and corresponding monitor/qmp commands refuse to unplug it. However guest is able to issue eject request either using following command:

  # echo 1 >/sys/devices/system/cpu/cpu0/firmware_node/eject      

I can't reproduce the issue with a pc guest and current master...

All I seem to get is an error in dmesg:

[   97.435446] processor cpu0: Offline failed.
Quoted 26 lines

or directly writing to cpu hotplug registers, which makes qemu crash with SIGSEGV following back trace:

   kvm_flush_coalesced_mmio_buffer ()
       while (ring->first != ring->last)
   ...
   qemu_flush_coalesced_mmio_buffer
   prepare_mmio_access
   flatview_read_continue
   flatview_read
   address_space_read_full
   address_space_rw
   kvm_cpu_exec(cpu!0)
   qemu_kvm_cpu_thread_fn

the reason for which is that ring == KVMState::coalesced_mmio_ring happens to be a part of 1st CPU that was uplugged by guest.

Fix it by forbidding 1st cpu unplug from guest side and in addition remove CPU0._EJ0 ACPI method to make clear that unplug of the first CPU is not supported.

---
CCing spapr and s390x folks in case targets need to prevent 1st CPU unplug as well

Quoted 7 lines
Quoted 5 lines

A spapr guest can _release_ the first cpu by doing something like:

# echo -n "/cpus/PowerPC,POWER8@0" > /sys/devices/system/cpu/release

But AFAIK, this doesn't unplug the cpu from a QEMU standpoint.

Unplugging CPU 0 with device_del should be ok too.

Do you mean real unplugging (cpu0 object freed) or just remove request?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Real unplugging should be possible. I'm not sure how thorougly it's been tested, though.

Well, common kvm code in qemu seems to be in disagreement with it as backtrace in this patch shows also usage of first_cpu macro won't survive such unplug.

Paolo - any take on this? Do we need to make cpu 0 special like this?

It probably would take a bunch of refactoring to get rid of first_cpu&co dependencies and besides of experimenting with cpu0 unplug in guest kernel there isn't any other value in it, so it probably not worth the effort.

On top of that, for pc/q35 machine we would need to select boot cpu in some other way (right now it's hardwired to first_cpu).

It seems that seabios might work if cpu0 isn't present, don't know about OVMF.

#10 lore raw
Quoted 69 lines · Igor Mammedov
Quoted 59 lines · On Wed, 29 Aug 2018 09:15:53 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 58 lines · Igor Mammedov
Quoted 55 lines · On Wed, 29 Aug 2018 12:54:40 +1000 David Gibson <[email protected]>…
Quoted 53 lines · Igor Mammedov
Quoted 42 lines · On Tue, 28 Aug 2018 10:52:37 +1000 David Gibson <[email protected]>…
Quoted 41 lines · Greg Kurz
Quoted 4 lines · On Mon, 27 Aug 2018 13:07:10 +0200 Igor Mammedov <[email protected]> wrote:

The first cpu unplug wasn't ever supported and corresponding monitor/qmp commands refuse to unplug it. However guest is able to issue eject request either using following command:

  # echo 1 >/sys/devices/system/cpu/cpu0/firmware_node/eject      

I can't reproduce the issue with a pc guest and current master...

All I seem to get is an error in dmesg:

[   97.435446] processor cpu0: Offline failed.
Quoted 26 lines

or directly writing to cpu hotplug registers, which makes qemu crash with SIGSEGV following back trace:

   kvm_flush_coalesced_mmio_buffer ()
       while (ring->first != ring->last)
   ...
   qemu_flush_coalesced_mmio_buffer
   prepare_mmio_access
   flatview_read_continue
   flatview_read
   address_space_read_full
   address_space_rw
   kvm_cpu_exec(cpu!0)
   qemu_kvm_cpu_thread_fn

the reason for which is that ring == KVMState::coalesced_mmio_ring happens to be a part of 1st CPU that was uplugged by guest.

Fix it by forbidding 1st cpu unplug from guest side and in addition remove CPU0._EJ0 ACPI method to make clear that unplug of the first CPU is not supported.

---
CCing spapr and s390x folks in case targets need to prevent 1st CPU unplug as well

Quoted 7 lines
Quoted 5 lines

A spapr guest can _release_ the first cpu by doing something like:

# echo -n "/cpus/PowerPC,POWER8@0" > /sys/devices/system/cpu/release

But AFAIK, this doesn't unplug the cpu from a QEMU standpoint.

Unplugging CPU 0 with device_del should be ok too.

Do you mean real unplugging (cpu0 object freed) or just remove request?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Real unplugging should be possible. I'm not sure how thorougly it's been tested, though.

Well, common kvm code in qemu seems to be in disagreement with it as backtrace in this patch shows also usage of first_cpu macro won't survive such unplug.

Paolo - any take on this? Do we need to make cpu 0 special like this?

Quoted 9 lines

It probably would take a bunch of refactoring to get rid of first_cpu&co dependencies and besides of experimenting with cpu0 unplug in guest kernel there isn't any other value in it, so it probably not worth the effort.

On top of that, for pc/q35 machine we would need to select boot cpu in some other way (right now it's hardwired to first_cpu).

It seems that seabios might work if cpu0 isn't present, don't know about OVMF.

Sorry, I have no idea. I'm not aware of any OVMF testing with partially populated VCPU topologies.

Thanks
Laszlo

#11 lore raw
In reply to Igor Mammedov
Quoted 69 lines · Igor Mammedov
Quoted 59 lines · On Wed, 29 Aug 2018 09:15:53 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 58 lines · Igor Mammedov
Quoted 55 lines · On Wed, 29 Aug 2018 12:54:40 +1000 David Gibson <[email protected]>…
Quoted 53 lines · Igor Mammedov
Quoted 42 lines · On Tue, 28 Aug 2018 10:52:37 +1000 David Gibson <[email protected]>…
Quoted 41 lines · Greg Kurz
Quoted 4 lines · On Mon, 27 Aug 2018 13:07:10 +0200 Igor Mammedov <[email protected]> wrote:

The first cpu unplug wasn't ever supported and corresponding monitor/qmp commands refuse to unplug it. However guest is able to issue eject request either using following command:

  # echo 1 >/sys/devices/system/cpu/cpu0/firmware_node/eject      

I can't reproduce the issue with a pc guest and current master...

All I seem to get is an error in dmesg:

[   97.435446] processor cpu0: Offline failed.
Quoted 26 lines

or directly writing to cpu hotplug registers, which makes qemu crash with SIGSEGV following back trace:

   kvm_flush_coalesced_mmio_buffer ()
       while (ring->first != ring->last)
   ...
   qemu_flush_coalesced_mmio_buffer
   prepare_mmio_access
   flatview_read_continue
   flatview_read
   address_space_read_full
   address_space_rw
   kvm_cpu_exec(cpu!0)
   qemu_kvm_cpu_thread_fn

the reason for which is that ring == KVMState::coalesced_mmio_ring happens to be a part of 1st CPU that was uplugged by guest.

Fix it by forbidding 1st cpu unplug from guest side and in addition remove CPU0._EJ0 ACPI method to make clear that unplug of the first CPU is not supported.

---
CCing spapr and s390x folks in case targets need to prevent 1st CPU unplug as well

Quoted 7 lines
Quoted 5 lines

A spapr guest can _release_ the first cpu by doing something like:

# echo -n "/cpus/PowerPC,POWER8@0" > /sys/devices/system/cpu/release

But AFAIK, this doesn't unplug the cpu from a QEMU standpoint.

Unplugging CPU 0 with device_del should be ok too.

Do you mean real unplugging (cpu0 object freed) or just remove request?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Real unplugging should be possible. I'm not sure how thorougly it's been tested, though.

Well, common kvm code in qemu seems to be in disagreement with it as backtrace in this patch shows also usage of first_cpu macro won't survive such unplug.

Paolo - any take on this? Do we need to make cpu 0 special like this?

Quoted 8 lines

It probably would take a bunch of refactoring to get rid of first_cpu&co dependencies and besides of experimenting with cpu0 unplug in guest kernel there isn't any other value in it, so it probably not worth the effort.

On top of that, for pc/q35 machine we would need to select boot cpu in some other way (right now it's hardwired to first_cpu).

It seems that seabios might work if cpu0 isn't present, don't know about OVMF.

OK, I queued this, but can you please add some code comments so we remember why it is like this if someone changes the code? Even better maybe to add an API along the lines of:

    cpu_is_hotpluggable
        return cpu != first_cpu
Signature · 1 line
MST
#12 lore raw
Quoted 77 lines · On Fri, 7 Sep 2018 16:52:17 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 76 lines · Igor Mammedov
Quoted 59 lines · On Wed, 29 Aug 2018 09:15:53 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 58 lines · Igor Mammedov
Quoted 55 lines · On Wed, 29 Aug 2018 12:54:40 +1000 David Gibson <[email protected]>…
Quoted 53 lines · Igor Mammedov
Quoted 42 lines · On Tue, 28 Aug 2018 10:52:37 +1000 David Gibson <[email protected]>…
Quoted 41 lines · Greg Kurz
Quoted 4 lines · On Mon, 27 Aug 2018 13:07:10 +0200 Igor Mammedov <[email protected]> wrote:

The first cpu unplug wasn't ever supported and corresponding monitor/qmp commands refuse to unplug it. However guest is able to issue eject request either using following command:

  # echo 1 >/sys/devices/system/cpu/cpu0/firmware_node/eject        

I can't reproduce the issue with a pc guest and current master...

All I seem to get is an error in dmesg:

[   97.435446] processor cpu0: Offline failed.
Quoted 26 lines

or directly writing to cpu hotplug registers, which makes qemu crash with SIGSEGV following back trace:

   kvm_flush_coalesced_mmio_buffer ()
       while (ring->first != ring->last)
   ...
   qemu_flush_coalesced_mmio_buffer
   prepare_mmio_access
   flatview_read_continue
   flatview_read
   address_space_read_full
   address_space_rw
   kvm_cpu_exec(cpu!0)
   qemu_kvm_cpu_thread_fn

the reason for which is that ring == KVMState::coalesced_mmio_ring happens to be a part of 1st CPU that was uplugged by guest.

Fix it by forbidding 1st cpu unplug from guest side and in addition remove CPU0._EJ0 ACPI method to make clear that unplug of the first CPU is not supported.

---
CCing spapr and s390x folks in case targets need to prevent 1st CPU unplug as well

Quoted 7 lines
Quoted 5 lines

A spapr guest can _release_ the first cpu by doing something like:

# echo -n "/cpus/PowerPC,POWER8@0" > /sys/devices/system/cpu/release

But AFAIK, this doesn't unplug the cpu from a QEMU standpoint.

Unplugging CPU 0 with device_del should be ok too.

Do you mean real unplugging (cpu0 object freed) or just remove request?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Real unplugging should be possible. I'm not sure how thorougly it's been tested, though.

Well, common kvm code in qemu seems to be in disagreement with it as backtrace in this patch shows also usage of first_cpu macro won't survive such unplug.

Paolo - any take on this? Do we need to make cpu 0 special like this?

It probably would take a bunch of refactoring to get rid of first_cpu&co dependencies and besides of experimenting with cpu0 unplug in guest kernel there isn't any other value in it, so it probably not worth the effort.

On top of that, for pc/q35 machine we would need to select boot cpu in some other way (right now it's hardwired to first_cpu).

Quoted 7 lines
Quoted 1 line

It seems that seabios might work if cpu0 isn't present, don't know about OVMF.

OK, I queued this, but can you please add some code comments so we remember why it is like this if someone changes the code? Even better maybe to add an API along the lines of:

    cpu_is_hotpluggable
        return cpu != first_cpu

I like an API idea,
I'll try to look into how to use use it in a generic way.