* [Qemu-devel] [PATCH v1] ppc: Force CPU threads count to be a power of 2.
@ 2014-03-05 3:36 Bharata B Rao
2014-03-05 4:13 ` Eric Blake
0 siblings, 1 reply; 3+ messages in thread
From: Bharata B Rao @ 2014-03-05 3:36 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>
Acked-by: Stewart Smith <stewart@linux.vnet.ibm.com>
---
Changes in v1: Make error message more descriptive as per Stewart's suggestion.
v0: https://lists.gnu.org/archive/html/qemu-devel/2014-03/msg00355.html
target-ppc/translate_init.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index 445c360..9ed22bb 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -18,6 +18,7 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
+#include <math.h>
#include "disas/bfd.h"
#include "exec/gdbstub.h"
#include <sysemu/kvm.h>
@@ -7979,6 +7980,7 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp)
Error *local_err = NULL;
#if !defined(CONFIG_USER_ONLY)
int max_smt = kvm_enabled() ? kvmppc_smt_threads() : 1;
+ int threads_shift;
#endif
#if !defined(CONFIG_USER_ONLY)
@@ -7987,6 +7989,13 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp)
max_smt, kvm_enabled() ? "KVM" : "TCG");
return;
}
+ threads_shift = log2(smp_threads);
+ if (smp_threads != (1 << threads_shift)) {
+ 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] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v1] ppc: Force CPU threads count to be a power of 2.
2014-03-05 3:36 [Qemu-devel] [PATCH v1] ppc: Force CPU threads count to be a power of 2 Bharata B Rao
@ 2014-03-05 4:13 ` Eric Blake
2014-03-05 6:39 ` Bharata B Rao
0 siblings, 1 reply; 3+ messages in thread
From: Eric Blake @ 2014-03-05 4:13 UTC (permalink / raw)
To: Bharata B Rao, qemu-devel; +Cc: aik, stewart, agraf
[-- Attachment #1: Type: text/plain, Size: 706 bytes --]
On 03/04/2014 08:36 PM, 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.
>
>
> +#include <math.h>
> }
> + threads_shift = log2(smp_threads);
Overkill. qemu-common.h gives you is_power_of_2() that uses just
integer math rather than dragging in floating-point overhead of libm.
--
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] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v1] ppc: Force CPU threads count to be a power of 2.
2014-03-05 4:13 ` Eric Blake
@ 2014-03-05 6:39 ` Bharata B Rao
0 siblings, 0 replies; 3+ messages in thread
From: Bharata B Rao @ 2014-03-05 6:39 UTC (permalink / raw)
To: Eric Blake; +Cc: aik, stewart, qemu-devel, agraf
On Tue, Mar 04, 2014 at 09:13:38PM -0700, Eric Blake wrote:
> On 03/04/2014 08:36 PM, 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.
> >
>
> >
> > +#include <math.h>
>
> > }
> > + threads_shift = log2(smp_threads);
>
> Overkill. qemu-common.h gives you is_power_of_2() that uses just
> integer math rather than dragging in floating-point overhead of libm.
Nice. Using is_power_of_2() in v2.
Regards,
Bharata.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-03-05 6:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-05 3:36 [Qemu-devel] [PATCH v1] ppc: Force CPU threads count to be a power of 2 Bharata B Rao
2014-03-05 4:13 ` Eric Blake
2014-03-05 6:39 ` Bharata B Rao
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.