All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] ppc: Force CPU threads count to be a power of 2.
@ 2014-03-05  8:32 Bharata B Rao
  2014-03-05 13:59 ` Eric Blake
  2014-03-05 22:51 ` Stewart Smith
  0 siblings, 2 replies; 5+ messages in thread
From: Bharata B Rao @ 2014-03-05  8:32 UTC (permalink / raw)
  To: qemu-devel; +Cc: aik, stewart, agraf, 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.

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
---
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(+)

diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index 445c360..5628248 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -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()) {
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v2] ppc: Force CPU threads count to be a power of 2.
  2014-03-05  8:32 [Qemu-devel] [PATCH v2] ppc: Force CPU threads count to be a power of 2 Bharata B Rao
@ 2014-03-05 13:59 ` Eric Blake
  2014-03-19  2:47   ` Bharata B Rao
  2014-03-05 22:51 ` Stewart Smith
  1 sibling, 1 reply; 5+ messages in thread
From: Eric Blake @ 2014-03-05 13:59 UTC (permalink / raw)
  To: Bharata B Rao, qemu-devel; +Cc: aik, stewart, agraf

[-- Attachment #1: Type: text/plain, Size: 835 bytes --]

On 03/05/2014 01:32 AM, Bharata B Rao wrote:
> 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.
> 
> Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
> ---
> 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

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v2] ppc: Force CPU threads count to be a power of 2.
  2014-03-05  8:32 [Qemu-devel] [PATCH v2] ppc: Force CPU threads count to be a power of 2 Bharata B Rao
  2014-03-05 13:59 ` Eric Blake
@ 2014-03-05 22:51 ` Stewart Smith
  1 sibling, 0 replies; 5+ messages in thread
From: Stewart Smith @ 2014-03-05 22:51 UTC (permalink / raw)
  To: Bharata B Rao, qemu-devel; +Cc: aik, agraf

Bharata B Rao <bharata@linux.vnet.ibm.com> writes:

> 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.
>
> Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>

Reviewed-by: Stewart Smith <stewart@linux.vnet.ibm.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v2] ppc: Force CPU threads count to be a power of 2.
  2014-03-05 13:59 ` Eric Blake
@ 2014-03-19  2:47   ` Bharata B Rao
  2014-03-19 22:58     ` Andreas Färber
  0 siblings, 1 reply; 5+ messages in thread
From: Bharata B Rao @ 2014-03-19  2:47 UTC (permalink / raw)
  To: Eric Blake; +Cc: aik, stewart, qemu-devel, Andreas Färber, agraf

On Wed, Mar 05, 2014 at 06:59:29AM -0700, Eric Blake wrote:
> On 03/05/2014 01:32 AM, Bharata B Rao wrote:
> > 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.
> > 
> > Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
> > ---
> > 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
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>

> Reviewed-by: Stewart Smith <stewart@linux.vnet.ibm.com>

Alexander/Andreas,

Could you take this patch into your tree ?

Regards,
Bharata.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v2] ppc: Force CPU threads count to be a power of 2.
  2014-03-19  2:47   ` Bharata B Rao
@ 2014-03-19 22:58     ` Andreas Färber
  0 siblings, 0 replies; 5+ messages in thread
From: Andreas Färber @ 2014-03-19 22:58 UTC (permalink / raw)
  To: bharata; +Cc: aik, stewart, qemu-devel, agraf

Am 19.03.2014 03:47, schrieb Bharata B Rao:
> On Wed, Mar 05, 2014 at 06:59:29AM -0700, Eric Blake wrote:
>> On 03/05/2014 01:32 AM, Bharata B Rao wrote:
>>> 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.
>>>
>>> Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
>>> ---
>>> 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
>>
>> Reviewed-by: Eric Blake <eblake@redhat.com>
> 
>> Reviewed-by: Stewart Smith <stewart@linux.vnet.ibm.com>
> 
> 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

diff --cc target-ppc/translate_init.c
index 3269c3e,5628248..0000000
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@@ -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;

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-03-19 22:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-05  8:32 [Qemu-devel] [PATCH v2] ppc: Force CPU threads count to be a power of 2 Bharata B Rao
2014-03-05 13:59 ` Eric Blake
2014-03-19  2:47   ` Bharata B Rao
2014-03-19 22:58     ` Andreas Färber
2014-03-05 22:51 ` Stewart Smith

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.