Received: from eggs.gnu.org ([2001:4830:134:3::10]:36889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKhTY-0002u9-Tl for qemu-devel@nongnu.org; Tue, 04 Mar 2014 00:01:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WKhTR-0008VV-Be for qemu-devel@nongnu.org; Tue, 04 Mar 2014 00:01:08 -0500 Received: from e28smtp02.in.ibm.com ([122.248.162.2]:40777) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKhTQ-0008Uv-LL for qemu-devel@nongnu.org; Tue, 04 Mar 2014 00:01:01 -0500 Received: from /spool/local by e28smtp02.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 4 Mar 2014 10:30:56 +0530 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 3FC8FE0044 for ; Tue, 4 Mar 2014 10:34:31 +0530 (IST) Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s2450Z1W53018778 for ; Tue, 4 Mar 2014 10:30:36 +0530 Received: from d28av01.in.ibm.com (localhost [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s2450caD014923 for ; Tue, 4 Mar 2014 10:30:38 +0530 From: Bharata B Rao Date: Tue, 4 Mar 2014 10:32:54 +0530 Message-Id: <1393909374-25728-1-git-send-email-bharata@linux.vnet.ibm.com> Subject: [Qemu-devel] [RFC PATCH v0] ppc: Force CPU threads count to be a power of 2. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aik@ozlabs.ru, agraf@suse.de, 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 --- target-ppc/translate_init.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c index 445c360..f3eff5e 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 . */ +#include #include "disas/bfd.h" #include "exec/gdbstub.h" #include @@ -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,12 @@ 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", + smp_threads, kvm_enabled() ? "KVM" : "TCG"); + return; + } #endif if (kvm_enabled()) { -- 1.7.11.7