From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WL2bs-0002r8-48 for qemu-devel@nongnu.org; Tue, 04 Mar 2014 22:35:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WL2bk-0005f7-H2 for qemu-devel@nongnu.org; Tue, 04 Mar 2014 22:35:08 -0500 Received: from e28smtp04.in.ibm.com ([122.248.162.4]:56104) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WL2bj-0005bw-QT for qemu-devel@nongnu.org; Tue, 04 Mar 2014 22:35:00 -0500 Received: from /spool/local by e28smtp04.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 5 Mar 2014 09:04:35 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 63B32125803E for ; Wed, 5 Mar 2014 09:06:42 +0530 (IST) Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s253YRVC63504394 for ; Wed, 5 Mar 2014 09:04:27 +0530 Received: from d28av04.in.ibm.com (localhost [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s253YV6o010579 for ; Wed, 5 Mar 2014 09:04:31 +0530 From: Bharata B Rao Date: Wed, 5 Mar 2014 09:06:49 +0530 Message-Id: <1393990609-12361-1-git-send-email-bharata@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v1] 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, stewart@linux.vnet.ibm.com, 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 Acked-by: Stewart Smith --- 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 . */ +#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,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