Skip to contentSkip to conversation

s390x/kvm: Set default cpu model for all machine classes

PATCH Superseded David Hildenbrand 3 participants 6 messages Oct 21, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390x/kvm: Set default cpu model for all machine classes

We have to set the default model of all machine classes, not just for the active one. Otherwise, "query-machines" will indicate the wrong CPU model ("qemu-s390x-cpu" instead of "host-s390x-cpu") as "default-cpu-type".

Doing a

    {"execute":"query-machines"}
under KVM now results in
    {"return": [
        {
            "hotpluggable-cpus": true,
            "name": "s390-ccw-virtio-4.0",
            "numa-mem-supported": false,
            "default-cpu-type": "host-s390x-cpu",
            "cpu-max": 248,
            "deprecated": false},
        {
            "hotpluggable-cpus": true,
            "name": "s390-ccw-virtio-2.7",
            "numa-mem-supported": false,
            "default-cpu-type": "host-s390x-cpu",
            "cpu-max": 248,
            "deprecated": false
        } ...
Fixes b6805e127c6b ("s390x: use generic cpu_model parsing")
Cc Igor Mammedov <[email protected]>
---
 target/s390x/kvm.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
target/s390x/kvm.c +8 -2
index c24c869e77..5966ab0d37 100644
@@ -320,11 +320,17 @@ void kvm_s390_set_max_pagesize(uint64_t pagesize, Error **errp)
     cap_hpage_1m = 1;
 }
 
-int kvm_arch_init(MachineState *ms, KVMState *s)
+static void ccw_machine_class_foreach(ObjectClass *klass, void *opaque)
 {
-    MachineClass *mc = MACHINE_GET_CLASS(ms);
+    MachineClass *mc = MACHINE_CLASS(klass);
 
     mc->default_cpu_type = S390_CPU_TYPE_NAME("host");
+}
+
+int kvm_arch_init(MachineState *ms, KVMState *s)
+{
+    object_class_foreach(ccw_machine_class_foreach, TYPE_S390_CCW_MACHINE,
+                         false, NULL);
 
     if (!kvm_check_extension(kvm_state, KVM_CAP_DEVICE_CTRL)) {
         error_report("KVM is missing capability KVM_CAP_DEVICE_CTRL - "
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 38 lines · David Hildenbrand

We have to set the default model of all machine classes, not just for the active one. Otherwise, "query-machines" will indicate the wrong CPU model ("qemu-s390x-cpu" instead of "host-s390x-cpu") as "default-cpu-type".

Doing a

    {"execute":"query-machines"}
under KVM now results in
    {"return": [
        {
            "hotpluggable-cpus": true,
            "name": "s390-ccw-virtio-4.0",
            "numa-mem-supported": false,
            "default-cpu-type": "host-s390x-cpu",
            "cpu-max": 248,
            "deprecated": false},
        {
            "hotpluggable-cpus": true,
            "name": "s390-ccw-virtio-2.7",
            "numa-mem-supported": false,
            "default-cpu-type": "host-s390x-cpu",
            "cpu-max": 248,
            "deprecated": false
        } ...
Fixes b6805e127c6b ("s390x: use generic cpu_model parsing")
Cc Igor Mammedov <[email protected]>
---
 target/s390x/kvm.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
target/s390x/kvm.c +0 -0
index c24c869e77..5966ab0d37 100644

target/s390x/kvm.c void kvm_s390_set_max_pagesize(uint64_t pagesize, Error **errp) · line 325

Quoted 8 lines
target/s390x/kvm.c +2 -2
@@ -320,11 +320,17 @@ void kvm_s390_set_max_pagesize(uint64_t pagesize, Error **errp)
     cap_hpage_1m = 1;
 }
 
-int kvm_arch_init(MachineState *ms, KVMState *s)
+static void ccw_machine_class_foreach(ObjectClass *klass, void *opaque)
 {
-    MachineClass *mc = MACHINE_GET_CLASS(ms);
+    MachineClass *mc = MACHINE_CLASS(klass);

I think we rather wanted to avoid using "klass" in new code... maybe use "oc" instead of "klass" ?

target/s390x/kvm.c void kvm_s390_set_max_pagesize(uint64_t pagesize, Error **errp)

Quoted 11 lines
target/s390x/kvm.c +6 -0
     mc->default_cpu_type = S390_CPU_TYPE_NAME("host");
+}
+
+int kvm_arch_init(MachineState *ms, KVMState *s)
+{
+    object_class_foreach(ccw_machine_class_foreach, TYPE_S390_CCW_MACHINE,
+                         false, NULL);
 
     if (!kvm_check_extension(kvm_state, KVM_CAP_DEVICE_CTRL)) {
         error_report("KVM is missing capability KVM_CAP_DEVICE_CTRL - "
 

Weird, if you start an older machine, you still get the "host" CPU without your patch, too:

echo -e "info qom-tree \n quit" | \
qemu-system-s390x -display none -monitor stdio -no-shutdown \
-accel kvm -M s390-ccw-virtio-3.0 | grep s390x-cpu

Results in:

    /device[0] (host-s390x-cpu)

... so I wonder why that differs from the "query-machines" command?

Anyway, your patch sounds fine, so (with "klass" replaced by "oc"):

#2 lore raw
Quoted 42 lines · Thomas Huth
Quoted 41 lines · David Hildenbrand

We have to set the default model of all machine classes, not just for the active one. Otherwise, "query-machines" will indicate the wrong CPU model ("qemu-s390x-cpu" instead of "host-s390x-cpu") as "default-cpu-type".

Doing a

     {"execute":"query-machines"}
under KVM now results in
     {"return": [
         {
             "hotpluggable-cpus": true,
             "name": "s390-ccw-virtio-4.0",
             "numa-mem-supported": false,
             "default-cpu-type": "host-s390x-cpu",
             "cpu-max": 248,
             "deprecated": false},
         {
             "hotpluggable-cpus": true,
             "name": "s390-ccw-virtio-2.7",
             "numa-mem-supported": false,
             "default-cpu-type": "host-s390x-cpu",
             "cpu-max": 248,
             "deprecated": false
         } ...
Fixes b6805e127c6b ("s390x: use generic cpu_model parsing")
Cc Igor Mammedov <[email protected]>
---
  target/s390x/kvm.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
target/s390x/kvm.c +0 -0
index c24c869e77..5966ab0d37 100644
@@ -320,11 +320,17 @@ void kvm_s390_set_max_pagesize(uint64_t pagesize, Error **errp)
      cap_hpage_1m = 1;
  }
 
Quoted 8 lines

target/s390x/kvm.c void kvm_s390_set_max_pagesize(uint64_t pagesize, Error **errp) · line 325

Quoted 5 lines
target/s390x/kvm.c +2 -2
-int kvm_arch_init(MachineState *ms, KVMState *s)
+static void ccw_machine_class_foreach(ObjectClass *klass, void *opaque)
  {
-    MachineClass *mc = MACHINE_GET_CLASS(ms);
+    MachineClass *mc = MACHINE_CLASS(klass);

I think we rather wanted to avoid using "klass" in new code... maybe use "oc" instead of "klass" ?

Can do, this was a copy and paste :)

Quoted 17 lines

target/s390x/kvm.c void kvm_s390_set_max_pagesize(uint64_t pagesize, Error **errp)

Quoted 12 lines
target/s390x/kvm.c +6 -0
      mc->default_cpu_type = S390_CPU_TYPE_NAME("host");
+}
+
+int kvm_arch_init(MachineState *ms, KVMState *s)
+{
+    object_class_foreach(ccw_machine_class_foreach, TYPE_S390_CCW_MACHINE,
+                         false, NULL);
 
      if (!kvm_check_extension(kvm_state, KVM_CAP_DEVICE_CTRL)) {
          error_report("KVM is missing capability KVM_CAP_DEVICE_CTRL - "
 

Weird, if you start an older machine, you still get the "host" CPU without your patch, too:

echo -e "info qom-tree \n quit" | \

Quoted 8 lines
  qemu-system-s390x -display none -monitor stdio -no-shutdown \
    -accel kvm -M s390-ccw-virtio-3.0 | grep s390x-cpu

Results in:

     /device[0] (host-s390x-cpu)

... so I wonder why that differs from the "query-machines" command?

query-machines probes with the "none" machine all other machines. Current code only fixes up the active machine.

(that's why you won't notice when starting a machine - you will always get "host" for the active one)

Quoted 5 lines

Anyway, your patch sounds fine, so (with "klass" replaced by "oc"):

Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw
Quoted 79 lines · David Hildenbrand
Quoted 34 lines · Thomas Huth
Quoted 33 lines · David Hildenbrand

We have to set the default model of all machine classes, not just for the active one. Otherwise, "query-machines" will indicate the wrong CPU model ("qemu-s390x-cpu" instead of "host-s390x-cpu") as "default-cpu-type".

Doing a
     {"execute":"query-machines"}
under KVM now results in
     {"return": [
         {
             "hotpluggable-cpus": true, "name": "s390-ccw-virtio-4.0", "numa-mem-supported": false, "default-cpu-type": "host-s390x-cpu", "cpu-max": 248,
             "deprecated": false},
         {
             "hotpluggable-cpus": true, "name": "s390-ccw-virtio-2.7", "numa-mem-supported": false, "default-cpu-type": "host-s390x-cpu", "cpu-max": 248,
             "deprecated": false
         } ...

Fixes b6805e127c6b ("s390x: use generic cpu_model parsing")
Cc Igor Mammedov <[email protected]>

---
  target/s390x/kvm.c | 10 ++++++++--

  1 file changed, 8 insertions(+), 2 deletions(-)
Quoted 16 lines

target/s390x/kvm.c void kvm_s390_set_max_pagesize(uint64_t · line 326

Quoted 13 lines
target/s390x/kvm.c +2 -1
index c24c869e77..5966ab0d37 100644
@@ -320,11 +320,17 @@ void kvm_s390_set_max_pagesize(uint64_t
 pagesize, Error **errp)
       cap_hpage_1m = 1;
   }
   -int kvm_arch_init(MachineState *ms, KVMState *s)
+static void ccw_machine_class_foreach(ObjectClass *klass, void *opaque)
   {
-    MachineClass *mc = MACHINE_GET_CLASS(ms);
+    MachineClass *mc = MACHINE_CLASS(klass);

I think we rather wanted to avoid using "klass" in new code... maybe use "oc" instead of "klass" ?

Can do, this was a copy and paste :)

Quoted 25 lines
Quoted 10 lines
target/s390x/kvm.c +6 -0
       mc->default_cpu_type = S390_CPU_TYPE_NAME("host");
+}
+
+int kvm_arch_init(MachineState *ms, KVMState *s)
+{
+    object_class_foreach(ccw_machine_class_foreach,
 TYPE_S390_CCW_MACHINE,
+                         false, NULL);
         if (!kvm_check_extension(kvm_state, KVM_CAP_DEVICE_CTRL)) {
Quoted 3 lines

          error_report("KVM is missing capability KVM_CAP_DEVICE_CTRL
- "

Weird, if you start an older machine, you still get the "host" CPU without your patch, too:

echo -e "info qom-tree \n quit" | \
  qemu-system-s390x -display none -monitor stdio -no-shutdown \
    -accel kvm -M s390-ccw-virtio-3.0 | grep s390x-cpu

Results in:

     /device[0] (host-s390x-cpu)

Quoted 7 lines
Quoted 1 line

... so I wonder why that differs from the "query-machines" command?

query-machines probes with the "none" machine all other machines. Current code only fixes up the active machine.

(that's why you won't notice when starting a machine - you will always get "host" for the active one)

Ah, right, thanks for the explanation. I somehow read the patch description that it is only fixed for the latest one (I should really read more closely) ... but now it makes perfect sense.

Thomas

#4 lore raw
In reply to David Hildenbrand
Quoted 4 lines

query-machines probes with the "none" machine all other machines. Current code only fixes up the active machine.

To be more precise, libvirt probes with "-machine none,accel=kvm:tcg" all other machines.

Quoted 10 lines

(that's why you won't notice when starting a machine - you will always get "host" for the active one)

Quoted 5 lines

Anyway, your patch sounds fine, so (with "klass" replaced by "oc"):

Signature · 3 lines
Thanks,

David / dhildenb
#5 lore raw
Quoted 6 lines · On Mon, 21 Oct 2019 11:58:35 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 3 lines

query-machines probes with the "none" machine all other machines. Current code only fixes up the active machine.

To be more precise, libvirt probes with "-machine none,accel=kvm:tcg" all other machines.

Add that to the patch description?

Quoted 6 lines
Quoted 6 lines

(that's why you won't notice when starting a machine - you will always get "host" for the active one)

Quoted 2 lines

Anyway, your patch sounds fine, so (with "klass" replaced by "oc"):

Respin with that? Makes it easier to pick up :)

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines