Skip to contentSkip to conversation

s390x: kvm: Fix number of cpu reports for stsi 3.2.2

PATCH Superseded Janosch Frank 3 participants 6 messages Mar 30, 2020 – Mar 31, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390x: kvm: Fix number of cpu reports for stsi 3.2.2

The cpu number reporting is handled by KVM and QEMU only fills in the VM name, uuid and other values.

Unfortuantely KVM doesn't report reserved cpus and doesn't even know they exist until the are created via the ioctl.

So let's fix up the cpu values after KVM has written its values to the 3.2.2 sysib.

---
 target/s390x/kvm.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
target/s390x/kvm.c +17 -1
index 3630c15f45a48864..a1c4890bdf0c65e4 100644
@@ -1819,8 +1819,10 @@ static int handle_tsch(S390CPU *cpu)
 
 static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)
 {
+    const MachineState *ms = MACHINE(qdev_get_machine());
+    uint16_t total_cpus = 0, conf_cpus = 0, reserved_cpus = 0;
     SysIB_322 sysib;
-    int del;
+    int del, i;
 
     if (s390_is_pv()) {
         s390_cpu_pv_mem_read(cpu, 0, &sysib, sizeof(sysib));
@@ -1842,6 +1844,20 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)
         memset(sysib.ext_names[del], 0,
                sizeof(sysib.ext_names[0]) * (sysib.count - del));
     }
+
+    /* count the cpus and split them into configured and reserved ones */
+    for (i = 0; i < ms->possible_cpus->len; i++) {
+        total_cpus++;
+        if (ms->possible_cpus->cpus[i].cpu) {
+            conf_cpus++;
+        } else {
+            reserved_cpus++;
+        }
+    }
+    sysib.vm[0].total_cpus = total_cpus;
+    sysib.vm[0].conf_cpus = conf_cpus;
+    sysib.vm[0].reserved_cpus = reserved_cpus;
+
     /* Insert short machine name in EBCDIC, padded with blanks */
     if (qemu_name) {
         memset(sysib.vm[0].name, 0x40, sizeof(sysib.vm[0].name));
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Janosch Frank

The cpu number reporting is handled by KVM and QEMU only fills in the VM name, uuid and other values.

Unfortuantely KVM doesn't report reserved cpus and doesn't even know

s/Unfortuantely/Unfortunately/

Quoted 4 lines

they exist until the are created via the ioctl.

So let's fix up the cpu values after KVM has written its values to the 3.2.2 sysib.

Maybe mention "similar to TCG in target/s390x/misc_helper.c:HELPER(stsi)".

Quoted 26 lines
---
 target/s390x/kvm.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
target/s390x/kvm.c +3 -1
index 3630c15f45a48864..a1c4890bdf0c65e4 100644
@@ -1819,8 +1819,10 @@ static int handle_tsch(S390CPU *cpu)
 
 static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)
 {
+    const MachineState *ms = MACHINE(qdev_get_machine());
+    uint16_t total_cpus = 0, conf_cpus = 0, reserved_cpus = 0;
     SysIB_322 sysib;
-    int del;
+    int del, i;
 
     if (s390_is_pv()) {
         s390_cpu_pv_mem_read(cpu, 0, &sysib, sizeof(sysib));
@@ -1842,6 +1844,20 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)
         memset(sysib.ext_names[del], 0,
                sizeof(sysib.ext_names[0]) * (sysib.count - del));
     }

target/s390x/kvm.c static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar) · line 1856

Quoted 10 lines
target/s390x/kvm.c +10 -0
+
+    /* count the cpus and split them into configured and reserved ones */
+    for (i = 0; i < ms->possible_cpus->len; i++) {
+        total_cpus++;
+        if (ms->possible_cpus->cpus[i].cpu) {
+            conf_cpus++;
+        } else {
+            reserved_cpus++;
+        }
+    }

We could of course factor this calculation out :)

(and one could shrink the variables from 3 to 2)

target/s390x/kvm.c static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar) · line 1863

Quoted 8 lines
target/s390x/kvm.c +4 -0
+    sysib.vm[0].total_cpus = total_cpus;
+    sysib.vm[0].conf_cpus = conf_cpus;
+    sysib.vm[0].reserved_cpus = reserved_cpus;
+
     /* Insert short machine name in EBCDIC, padded with blanks */
     if (qemu_name) {
         memset(sysib.vm[0].name, 0x40, sizeof(sysib.vm[0].name));

Looks sane to me

Signature · 3 lines
Thanks,

David / dhildenb
#2 lore raw
Quoted 54 lines · On Mon, 30 Mar 2020 18:04:09 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 4 lines · Janosch Frank

The cpu number reporting is handled by KVM and QEMU only fills in the VM name, uuid and other values.

Unfortuantely KVM doesn't report reserved cpus and doesn't even know

s/Unfortuantely/Unfortunately/

Quoted 4 lines

they exist until the are created via the ioctl.

So let's fix up the cpu values after KVM has written its values to the 3.2.2 sysib.

Maybe mention "similar to TCG in target/s390x/misc_helper.c:HELPER(stsi)".

Quoted 26 lines
---
 target/s390x/kvm.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
target/s390x/kvm.c +3 -1
index 3630c15f45a48864..a1c4890bdf0c65e4 100644
@@ -1819,8 +1819,10 @@ static int handle_tsch(S390CPU *cpu)
 
 static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)
 {
+    const MachineState *ms = MACHINE(qdev_get_machine());
+    uint16_t total_cpus = 0, conf_cpus = 0, reserved_cpus = 0;
     SysIB_322 sysib;
-    int del;
+    int del, i;
 
     if (s390_is_pv()) {
         s390_cpu_pv_mem_read(cpu, 0, &sysib, sizeof(sysib));
@@ -1842,6 +1844,20 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)
         memset(sysib.ext_names[del], 0,
                sizeof(sysib.ext_names[0]) * (sysib.count - del));
     }

target/s390x/kvm.c static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar) · line 1856

Quoted 10 lines
target/s390x/kvm.c +10 -0
+
+    /* count the cpus and split them into configured and reserved ones */
+    for (i = 0; i < ms->possible_cpus->len; i++) {
+        total_cpus++;
+        if (ms->possible_cpus->cpus[i].cpu) {
+            conf_cpus++;
+        } else {
+            reserved_cpus++;
+        }
+    }  

We could of course factor this calculation out :)

Quoted 1 line

(and one could shrink the variables from 3 to 2)

I'd vote for queuing this one on s390-fixes now (with the patch description tweaks) and doing any cleanup on top for the next release. Ok?

Quoted 14 lines

target/s390x/kvm.c static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar) · line 1863

Quoted 9 lines
target/s390x/kvm.c +4 -0
+    sysib.vm[0].total_cpus = total_cpus;
+    sysib.vm[0].conf_cpus = conf_cpus;
+    sysib.vm[0].reserved_cpus = reserved_cpus;
+
     /* Insert short machine name in EBCDIC, padded with blanks */
     if (qemu_name) {
         memset(sysib.vm[0].name, 0x40, sizeof(sysib.vm[0].name));

Looks sane to me

#3 lore raw
Quoted 57 lines · Cornelia Huck
Quoted 54 lines · On Mon, 30 Mar 2020 18:04:09 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 4 lines · Janosch Frank

The cpu number reporting is handled by KVM and QEMU only fills in the VM name, uuid and other values.

Unfortuantely KVM doesn't report reserved cpus and doesn't even know

s/Unfortuantely/Unfortunately/

Quoted 4 lines

they exist until the are created via the ioctl.

So let's fix up the cpu values after KVM has written its values to the 3.2.2 sysib.

Maybe mention "similar to TCG in target/s390x/misc_helper.c:HELPER(stsi)".

Quoted 26 lines
---
 target/s390x/kvm.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
target/s390x/kvm.c +3 -1
index 3630c15f45a48864..a1c4890bdf0c65e4 100644
@@ -1819,8 +1819,10 @@ static int handle_tsch(S390CPU *cpu)
 
 static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)
 {
+    const MachineState *ms = MACHINE(qdev_get_machine());
+    uint16_t total_cpus = 0, conf_cpus = 0, reserved_cpus = 0;
     SysIB_322 sysib;
-    int del;
+    int del, i;
 
     if (s390_is_pv()) {
         s390_cpu_pv_mem_read(cpu, 0, &sysib, sizeof(sysib));
@@ -1842,6 +1844,20 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)
         memset(sysib.ext_names[del], 0,
                sizeof(sysib.ext_names[0]) * (sysib.count - del));
     }

target/s390x/kvm.c static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar) · line 1856

Quoted 10 lines
target/s390x/kvm.c +10 -0
+
+    /* count the cpus and split them into configured and reserved ones */
+    for (i = 0; i < ms->possible_cpus->len; i++) {
+        total_cpus++;
+        if (ms->possible_cpus->cpus[i].cpu) {
+            conf_cpus++;
+        } else {
+            reserved_cpus++;
+        }
+    }  

We could of course factor this calculation out :)

Quoted 5 lines
Quoted 1 line

(and one could shrink the variables from 3 to 2)

I'd vote for queuing this one on s390-fixes now (with the patch description tweaks) and doing any cleanup on top for the next release. Ok?

Fine with me.

Signature · 3 lines
Thanks,

David / dhildenb
#4 lore raw

PATCH v2 1/1 s390x: kvm: Fix number of cpu reports for stsi 3.2.2

In reply to David Hildenbrand

The cpu number reporting is handled by KVM and QEMU only fills in the VM name, uuid and other values.

Unfortunately KVM doesn't report reserved cpus and doesn't even know they exist until the are created via the ioctl.

So let's fix up the cpu values after KVM has written its values to the 3.2.2 sysib. To be consistent We use the same code to retrieve the cpu numbers as the STSI TCG code in target/s390x/misc_helper.c:HELPER(stsi).

---

* Fixed commit message and add rev-by
* Calculating total_cpus from configured + reserved

---
 target/s390x/kvm.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
target/s390x/kvm.c +16 -1
index 3630c15f45a48864..69881a0da0b31f72 100644
@@ -1819,8 +1819,10 @@ static int handle_tsch(S390CPU *cpu)
 
 static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)
 {
+    const MachineState *ms = MACHINE(qdev_get_machine());
+    uint16_t conf_cpus = 0, reserved_cpus = 0;
     SysIB_322 sysib;
-    int del;
+    int del, i;
 
     if (s390_is_pv()) {
         s390_cpu_pv_mem_read(cpu, 0, &sysib, sizeof(sysib));
@@ -1842,6 +1844,19 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)
         memset(sysib.ext_names[del], 0,
                sizeof(sysib.ext_names[0]) * (sysib.count - del));
     }
+
+    /* count the cpus and split them into configured and reserved ones */
+    for (i = 0; i < ms->possible_cpus->len; i++) {
+        if (ms->possible_cpus->cpus[i].cpu) {
+            conf_cpus++;
+        } else {
+            reserved_cpus++;
+        }
+    }
+    sysib.vm[0].total_cpus = conf_cpus + reserved_cpus;
+    sysib.vm[0].conf_cpus = conf_cpus;
+    sysib.vm[0].reserved_cpus = reserved_cpus;
+
     /* Insert short machine name in EBCDIC, padded with blanks */
     if (qemu_name) {
         memset(sysib.vm[0].name, 0x40, sizeof(sysib.vm[0].name));
Signature · 1 line
2.25.1
#5 lore raw
Quoted 8 lines · On Tue, 31 Mar 2020 07:01:23 -0400 Janosch Frank <[email protected]> wrote:

The cpu number reporting is handled by KVM and QEMU only fills in the VM name, uuid and other values.

Unfortunately KVM doesn't report reserved cpus and doesn't even know they exist until the are created via the ioctl.

So let's fix up the cpu values after KVM has written its values to the 3.2.2 sysib. To be consistent We use the same code to retrieve the cpu

"...consistent, we..." (fixed up while applying)

Quoted 19 lines

numbers as the STSI TCG code in target/s390x/misc_helper.c:HELPER(stsi).

---

* Fixed commit message and add rev-by
* Calculating total_cpus from configured + reserved

---
 target/s390x/kvm.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
target/s390x/kvm.c +0 -0
index 3630c15f45a48864..69881a0da0b31f72 100644
@@ -1819,8 +1819,10 @@ static int handle_tsch(S390CPU *cpu)
 

target/s390x/kvm.c static int handle_tsch(S390CPU *cpu) · line 1828

Quoted 10 lines
target/s390x/kvm.c +3 -1
 static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)
 {
+    const MachineState *ms = MACHINE(qdev_get_machine());
+    uint16_t conf_cpus = 0, reserved_cpus = 0;
     SysIB_322 sysib;
-    int del;
+    int del, i;
 
     if (s390_is_pv()) {
         s390_cpu_pv_mem_read(cpu, 0, &sysib, sizeof(sysib));

This is against s390-next; rebased and applied to s390-fixes (please double check).

[I'm holding off rebasing s390-next on top of s390-fixes resp. master; I'll rather do that once after all pieces including the headers update are in place.]