Skip to contentSkip to conversation

ppc: Force CPU threads count to be a power of 2.

PATCH In review Bharata B Rao 4 participants 5 messages Mar 5, 2014 – Mar 19, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ppc: Force CPU threads count to be a power of 2.

PowerPC kernel expects the number of SMT threads in a core to be a power of 2. Since QEMU doesn't enforce this, it leads to an early guest kernel crash if invalid threads count is specified.

Prevent this crash and make it a graceful exit from QEMU itself by validating the user supplied threads count.

---
Changes in v2: Use is_power_of_2() from QEMU itself instead of depending on libm.
v1: https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg00660.html
v0: https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg00355.html

 target-ppc/translate_init.c | 6 ++++++
 1 file changed, 6 insertions(+)
target-ppc/translate_init.c +6 -0
index 445c360..5628248 100644
@@ -7987,6 +7987,12 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp)
                    max_smt, kvm_enabled() ? "KVM" : "TCG");
         return;
     }
+    if (!is_power_of_2(smp_threads)) {
+        error_setg(errp, "Cannot support %d threads on PPC with %s, "
+                   "threads count must be a power of 2.",
+                   smp_threads, kvm_enabled() ? "KVM" : "TCG");
+        return;
+    }
 #endif
 
     if (kvm_enabled()) {
Signature · 1 line
1.7.11.7
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Bharata B Rao

PowerPC kernel expects the number of SMT threads in a core to be a power of 2. Since QEMU doesn't enforce this, it leads to an early guest kernel crash if invalid threads count is specified.

Prevent this crash and make it a graceful exit from QEMU itself by validating the user supplied threads count.

Quoted 6 lines

---
Changes in v2: Use is_power_of_2() from QEMU itself instead of depending on libm.
v1: https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg00660.html
v0: https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg00355.html

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on v2 1/1
#4 lore raw
In reply to Bharata B Rao
Quoted 8 lines · Bharata B Rao

PowerPC kernel expects the number of SMT threads in a core to be a power of 2. Since QEMU doesn't enforce this, it leads to an early guest kernel crash if invalid threads count is specified.

Prevent this crash and make it a graceful exit from QEMU itself by validating the user supplied threads count.

#2 lore raw
In reply to Eric Blake
Quoted 15 lines · Eric Blake
Quoted 7 lines · Bharata B Rao

PowerPC kernel expects the number of SMT threads in a core to be a power of 2. Since QEMU doesn't enforce this, it leads to an early guest kernel crash if invalid threads count is specified.

Prevent this crash and make it a graceful exit from QEMU itself by validating the user supplied threads count.

Quoted 6 lines

---
Changes in v2: Use is_power_of_2() from QEMU itself instead of depending on libm.
v1: https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg00660.html
v0: https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg00355.html

Quoted 3 lines

Alexander/Andreas,

Could you take this patch into your tree ?

Regards,
Bharata.

#3 lore raw

Am 19.03.2014 03:47, schrieb Bharata B Rao:

Quoted 16 lines · Eric Blake
Quoted 15 lines · Bharata B Rao
Quoted 13 lines

PowerPC kernel expects the number of SMT threads in a core to be a power of 2. Since QEMU doesn't enforce this, it leads to an early guest kernel crash if invalid threads count is specified.

Prevent this crash and make it a graceful exit from QEMU itself by validating the user supplied threads count.

---
Changes in v2: Use is_power_of_2() from QEMU itself instead of depending on libm.
v1: https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg00660.html
v0: https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg00355.html

Quoted 7 lines
Quoted 3 lines

Alexander/Andreas,

Could you take this patch into your tree ?

Thanks for the reminder.

Didn't apply cleanly any more. Applied to my ppc-next with fixups:
https://github.com/afaerber/qemu-cpu/commits/ppc-next

Andreas

target-ppc/translate_init.c +0 -0
diff --cc target-ppc/translate_init.c
index 3269c3e,5628248..0000000
@@@ -7848,12 -7987,20 +7848,18 @@@ static void ppc_cpu_realizefn(DeviceSta
                     max_smt, kvm_enabled() ? "KVM" : "TCG");
          return;
      }
+     if (!is_power_of_2(smp_threads)) {
+         error_setg(errp, "Cannot support %d threads on PPC with %s, "
+                    "threads count must be a power of 2.",
+                    smp_threads, kvm_enabled() ? "KVM" : "TCG");
+         return;
+     }
 +
 +    cpu->cpu_dt_id = (cs->cpu_index / smp_threads) * max_smt
 +        + (cs->cpu_index % smp_threads);
  #endif

- if (kvm_enabled()) {
- if (kvmppc_fixup_cpu(cpu) != 0) {
- error_setg(errp, "Unable to virtualize selected CPU with
KVM");
- return;
- }
- } else if (tcg_enabled()) {

 +    if (tcg_enabled()) {
          if (ppc_fixup_cpu(cpu) != 0) {
              error_setg(errp, "Unable to emulate selected CPU with TCG");
              return;
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg