Skip to contentSkip to conversation

Small fixes for SMT guests in Power9

PATCH Applied Jose Ricardo Ziviani 2 participants 5 messages Jan 14, 2018 – Jan 15, 2018

lore
Share & tools
lore
#0 lore raw

v2 cover Small fixes for SMT guests in Power9

v2:
- divided in two patches:
(1) enables smt8 mode to P9 guests
(2) checks if host supports the # of threads/core required
limitation: doesn't check guest running in compat mode

This patchset contains 2 changes:

(1) A P9 guest defined like -smp sockets=1,cores=1,threads=8 will be silently changed to threads=4:

(guest) # lscpu

Architecture:          ppc64le
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    4
Core(s) per socket:    1
Socket(s):             1
NUMA node(s):          1

...
(qemu) info cpus
* CPU #0: nip=0xc0000000000db9cc thread_id=9440 CPU #1: nip=0xc0000000000db9cc thread_id=9441 CPU #2: nip=0xc0000000000db9cc thread_id=9442 CPU #3: nip=0xc0000000000db9cc thread_id=9443 CPU #4: nip=0x0000000000000100 (halted) thread_id=9444 CPU #5: nip=0x0000000000000100 (halted) thread_id=9445 CPU #6: nip=0x0000000000000100 (halted) thread_id=9446 CPU #7: nip=0x0000000000000100 (halted) thread_id=9447

This patch enables P9 guests to use emulated smt because KVM supports it:

(guest) # lscpu

Architecture:          ppc64le
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    8
Core(s) per socket:    1
Socket(s):             1
NUMA node(s):          1

(qemu) info cpus
* CPU #0: nip=0xc0000000000d30ac thread_id=68400
CPU #1: nip=0xc0000000000d30ac thread_id=68401
CPU #2: nip=0xc0000000000d30ac thread_id=68402
CPU #3: nip=0xc0000000000d30ac thread_id=68403
CPU #4: nip=0xc0000000000d30ac thread_id=68404
CPU #5: nip=0xc0000000000d30ac thread_id=68405
CPU #6: nip=0xc0000000000d30ac thread_id=68406
CPU #7: nip=0xc0000000000d30ac thread_id=68407

CPU hotplugging also works as expected:

(qemu) device_add host-spapr-cpu-core,id=core8,core-id=8 (qemu) info cpus
* CPU #0: nip=0xc0000000000d30ac thread_id=68400 CPU #1: nip=0xc0000000000d30ac thread_id=68401 CPU #2: nip=0xc0000000000d30ac thread_id=68402 CPU #3: nip=0xc0000000000d30ac thread_id=68403 CPU #4: nip=0xc0000000000d30ac thread_id=68404 CPU #5: nip=0xc0000000000d30ac thread_id=68405 CPU #6: nip=0xc0000000000d30ac thread_id=68406 CPU #7: nip=0xc0000000000d30ac thread_id=68407 CPU #8: nip=0xc0000000000d30ac thread_id=68492 CPU #9: nip=0xc0000000000d30ac thread_id=68493 CPU #10: nip=0xc0000000000d30ac thread_id=68494 CPU #11: nip=0xc0000000000d30ac thread_id=68495 CPU #12: nip=0xc0000000000d30ac thread_id=68496 CPU #13: nip=0xc0000000000d30ac thread_id=68497 CPU #14: nip=0xc0000000000d30ac thread_id=68498 CPU #15: nip=0xc0000000000d30ac thread_id=68499

(guest) # lscpu

Architecture:          ppc64le
Byte Order:            Little Endian
CPU(s):                16
On-line CPU(s) list:   0-15
Thread(s) per core:    8
Core(s) per socket:    2
Socket(s):             1
NUMA node(s):          1

(2) Checks if KVM supports the number of threads required

If users try to pass more threads/core than the host supports it displays an error message and quits:

qemu-system-ppc64: KVM does not support 8 threads/core. Available VSMT modes: 4 2 1.

Jose Ricardo Ziviani (2):
ppc: Change Power9 compat table to support at most 8 threads/core
ppc: spapr: Check if thread argument is supported by host KVM

 hw/ppc/spapr.c       | 10 ++++++++++
 target/ppc/compat.c  |  2 +-
 target/ppc/kvm.c     |  5 +++++
 target/ppc/kvm_ppc.h |  6 ++++++
 4 files changed, 22 insertions(+), 1 deletion(-)
Signature · 1 line
2.14.3
#1 lore raw

PATCH v2 1/2 ppc: Change Power9 compat table to support at most 8 threads/core

Increases the max smt mode to 8 for Power9. That's because KVM supports smt emulation in this platform so QEMU should allow users to use it as well.

Today if we try to pass -smp ...,threads=8, QEMU will silently truncate it to smt4 mode and may cause a crash if we try to perform a cpu hotplug.

---
 target/ppc/compat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/compat.c +1 -1
index ad8f93c064..d1770cdc6f 100644
@@ -73,7 +73,7 @@ static const CompatInfo compat_table[] = {
         .pvr = CPU_POWERPC_LOGICAL_3_00,
         .pcr = PCR_COMPAT_3_00,
         .pcr_level = PCR_COMPAT_3_00,
-        .max_threads = 4,
+        .max_threads = 8,
     },
 };
 
Signature · 1 line
2.14.3
#3 lore raw

PATCH v2 2/2 ppc: spapr: Check if thread argument is supported by host KVM

In reply to Jose Ricardo Ziviani

QEMU currently checks whether SMT passed is valid or not. However, it doesn't check if KVM supports such mode when kvm is enabled.

This patch relies on KVM_CAP_PPC_SMT_POSSIBLE to make it sure that QEMU will either set a valid SMT mode or warn an error message and quit.

---
 hw/ppc/spapr.c       | 10 ++++++++++
 target/ppc/kvm.c     |  5 +++++
 target/ppc/kvm_ppc.h |  6 ++++++
 3 files changed, 21 insertions(+)
hw/ppc/spapr.c +10 -0
index d1acfe8858..aed4d25fc4 100644
@@ -2261,12 +2261,22 @@ static void spapr_set_vsmt_mode(sPAPRMachineState *spapr, Error **errp)
                      "on a pseries machine");
         goto out;
     }
+
     if (!is_power_of_2(smp_threads)) {
         error_setg(&local_err, "Cannot support %d threads/core on a pseries "
                      "machine because it must be a power of 2", smp_threads);
         goto out;
     }
 
+    if (kvm_enabled() && kvmppc_cap_smt_possible() > 0) {
+        if ((kvmppc_cap_smt_possible() & smp_threads) != smp_threads) {
+            error_setg(&local_err, "KVM does not support %d threads/core.",
+                    smp_threads);
+            kvmppc_hint_smt_possible(&local_err);
+            goto out;
+        }
+    }
+
     /* Detemine the VSMT mode to use: */
     if (vsmt_user) {
         if (spapr->vsmt < smp_threads) {
target/ppc/kvm.c +5 -0
index 914be687e7..4a8ff4d63c 100644
@@ -2456,6 +2456,11 @@ bool kvmppc_has_cap_mmu_hash_v3(void)
     return cap_mmu_hash_v3;
 }
 
+int kvmppc_cap_smt_possible(void)
+{
+    return cap_ppc_smt_possible;
+}
+
 PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void)
 {
     uint32_t host_pvr = mfpvr();
target/ppc/kvm_ppc.h +6 -0
index ecb55493cc..2221850723 100644
@@ -59,6 +59,7 @@ bool kvmppc_has_cap_fixup_hcalls(void);
 bool kvmppc_has_cap_htm(void);
 bool kvmppc_has_cap_mmu_radix(void);
 bool kvmppc_has_cap_mmu_hash_v3(void);
+int kvmppc_cap_smt_possible(void);
 int kvmppc_enable_hwrng(void);
 int kvmppc_put_books_sregs(PowerPCCPU *cpu);
 PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void);
@@ -290,6 +291,11 @@ static inline bool kvmppc_has_cap_mmu_hash_v3(void)
     return false;
 }
 
+static inline int kvmppc_cap_smt_possible(void)
+{
+    return 0;
+}
+
 static inline int kvmppc_enable_hwrng(void)
 {
     return -1;
Signature · 1 line
2.14.3
Applied
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] ppc: Change Power9 compat table to support at most 8 threads/core

In reply to Jose Ricardo Ziviani
Quoted 9 lines · Jose Ricardo Ziviani

Increases the max smt mode to 8 for Power9. That's because KVM supports smt emulation in this platform so QEMU should allow users to use it as well.

Today if we try to pass -smp ...,threads=8, QEMU will silently truncate it to smt4 mode and may cause a crash if we try to perform a cpu hotplug.

Applied, with the addition of a comment explaining why we want this despite the hardware limit.

Quoted 17 lines
---
 target/ppc/compat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/compat.c +1 -1
index ad8f93c064..d1770cdc6f 100644
@@ -73,7 +73,7 @@ static const CompatInfo compat_table[] = {
         .pvr = CPU_POWERPC_LOGICAL_3_00,
         .pcr = PCR_COMPAT_3_00,
         .pcr_level = PCR_COMPAT_3_00,
-        .max_threads = 4,
+        .max_threads = 8,
     },
 };
 
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
#4 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ppc: spapr: Check if thread argument is supported by host KVM

In reply to Jose Ricardo Ziviani
Quoted 2 lines · Jose Ricardo Ziviani

QEMU currently checks whether SMT passed is valid or not. However, it doesn't check if KVM supports such mode when kvm is enabled.

That's not really true - the attempt to actually set the vsmt mode in KVM later on in spapr_set_vsmt_mode() will fail if KVM can't support the number of threads.

The error added here might be a bit easier to understand, since it doesn't refer to vsmt modes, which might just confuse the issue.

The change isn't urgent, though.

Quoted 23 lines

This patch relies on KVM_CAP_PPC_SMT_POSSIBLE to make it sure that QEMU will either set a valid SMT mode or warn an error message and quit.

---
 hw/ppc/spapr.c       | 10 ++++++++++
 target/ppc/kvm.c     |  5 +++++
 target/ppc/kvm_ppc.h |  6 ++++++
 3 files changed, 21 insertions(+)
hw/ppc/spapr.c +1 -0
index d1acfe8858..aed4d25fc4 100644
@@ -2261,12 +2261,22 @@ static void spapr_set_vsmt_mode(sPAPRMachineState *spapr, Error **errp)
                      "on a pseries machine");
         goto out;
     }
+
     if (!is_power_of_2(smp_threads)) {
         error_setg(&local_err, "Cannot support %d threads/core on a pseries "
                      "machine because it must be a power of 2", smp_threads);
         goto out;

hw/ppc/spapr.c static void spapr_set_vsmt_mode(sPAPRMachineState *spapr, Error **errp) · line 2278

Quoted 10 lines
hw/ppc/spapr.c +8 -0
     }
 
+    if (kvm_enabled() && kvmppc_cap_smt_possible() > 0) {
+        if ((kvmppc_cap_smt_possible() & smp_threads) != smp_threads) {
+            error_setg(&local_err, "KVM does not support %d threads/core.",
+                    smp_threads);
+            kvmppc_hint_smt_possible(&local_err);
+            goto out;
+        }
+    }

I'd like to see a fallback for kernels that don't support the smt_possible cap and vsmt mode setting (for those, we must have smp_threads <= kvm_smt).

Quoted 44 lines
hw/ppc/spapr.c +1 -0
+
     /* Detemine the VSMT mode to use: */
     if (vsmt_user) {
         if (spapr->vsmt < smp_threads) {
target/ppc/kvm.c +5 -0
index 914be687e7..4a8ff4d63c 100644
@@ -2456,6 +2456,11 @@ bool kvmppc_has_cap_mmu_hash_v3(void)
     return cap_mmu_hash_v3;
 }
 
+int kvmppc_cap_smt_possible(void)
+{
+    return cap_ppc_smt_possible;
+}
+
 PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void)
 {
     uint32_t host_pvr = mfpvr();
target/ppc/kvm_ppc.h +6 -0
index ecb55493cc..2221850723 100644
@@ -59,6 +59,7 @@ bool kvmppc_has_cap_fixup_hcalls(void);
 bool kvmppc_has_cap_htm(void);
 bool kvmppc_has_cap_mmu_radix(void);
 bool kvmppc_has_cap_mmu_hash_v3(void);
+int kvmppc_cap_smt_possible(void);
 int kvmppc_enable_hwrng(void);
 int kvmppc_put_books_sregs(PowerPCCPU *cpu);
 PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void);
@@ -290,6 +291,11 @@ static inline bool kvmppc_has_cap_mmu_hash_v3(void)
     return false;
 }
 
+static inline int kvmppc_cap_smt_possible(void)
+{
+    return 0;
+}
+
 static inline int kvmppc_enable_hwrng(void)
 {
     return -1;
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