From patchwork Sat Dec 14 17:21:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lijun X-Patchwork-Id: 301272 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 71C5F2C00A0 for ; Sun, 15 Dec 2013 04:22:32 +1100 (EST) Received: from localhost ([::1]:48099 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vrsv6-0008SN-SZ for incoming@patchwork.ozlabs.org; Sat, 14 Dec 2013 12:22:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52012) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vrsuk-0008SF-3y for qemu-devel@nongnu.org; Sat, 14 Dec 2013 12:22:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vrsub-00027h-NA for qemu-devel@nongnu.org; Sat, 14 Dec 2013 12:22:06 -0500 Received: from mail-pb0-x22f.google.com ([2607:f8b0:400e:c01::22f]:40177) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vrsub-00025U-F1 for qemu-devel@nongnu.org; Sat, 14 Dec 2013 12:21:57 -0500 Received: by mail-pb0-f47.google.com with SMTP id um1so3805131pbc.34 for ; Sat, 14 Dec 2013 09:21:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=6Tcdn1Repn3JItrpAXASR7F+TkAwdzPOgymqiL7fqw8=; b=TE23NTyw69pVZp5gXQQ+/k4xuNcgT7gCVQziKorjQ7c8b1s5GM6RDl/9syFwqkoLaK S1vTcpOSFwP75o/piHqz9LGfwfwczjAO8RDm2yPPcK7ViqaoK8wV59z2ooY8Jd3Z2dD3 7Ug+FX3GytmCVsw1csauZBjVe+kB5iKHzkjUUTJ4PFvAQCQgiadxJepEAxq/eeQ4A6Pf o/nxMydXJsUcAB47ob4tGZqbhwvpHArQtnKlffQLw7rrTuAxLerHO8YPZVG1DPYdqgRP JTrr7RoH7mqTzq11oCZIGpKnvu7AWU2eLC3VbCruxxQw+sSrv67qWkQj1LX31xMhLQJE wmhg== X-Received: by 10.66.159.132 with SMTP id xc4mr10397206pab.27.1387041716149; Sat, 14 Dec 2013 09:21:56 -0800 (PST) Received: from localhost.localdomain ([211.155.113.201]) by mx.google.com with ESMTPSA id sx8sm18287710pab.5.2013.12.14.09.21.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 14 Dec 2013 09:21:55 -0800 (PST) Message-ID: <52AC939E.9060706@gmail.com> Date: Sun, 15 Dec 2013 01:21:34 +0800 From: lijun User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: qemu-devel@nongnu.org References: <52A9FC0C.3040509@gmail.com> In-Reply-To: <52A9FC0C.3040509@gmail.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c01::22f Cc: aliguori@amazon.com Subject: Re: [Qemu-devel] [PATCH] qemu will core dump with "-smp 254, sockets=2, cores=3, threads=2" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Hi all, As qemu core dump cause by "sockets=2,cores=3,threads=2", so add this patch to check whether cores and threads is a power of 2. The following is the realization of apicid_from_topo_ids function in file target-i386/topology.h. It uses shift to get the values of pkg_id and core_id. nr_cores and nr_threads is related to this shift. static inline apic_id_t apicid_from_topo_ids(unsigned nr_cores, unsigned nr_threads, unsigned pkg_id, unsigned core_id, unsigned smt_id) { return (pkg_id << apicid_pkg_offset(nr_cores, nr_threads)) | (core_id << apicid_core_offset(nr_cores, nr_threads)) | smt_id; } ---- So should add a check for smp_cores and smp_threads in smp_parse function in file vl.c. Check whether smp_cores and smp_threads is a power of 2, so nr_cores and nr_threads is a power of 2. When return from apicid_from_topo_ids function, apic_id and id could get the correct values(apic_id is in file "hw/i386/acpi-build.c" and id is in file "hw/acpi/piix4.c") . Without this check for smp_cores and smp_threads, specify "-smp 160,sockets=2,cores=3,threads=2", qemu will core dump too. Best Regards, Jun Li --- a/vl.c 2013-12-14 23:46:58.991076467 +0800 +++ b/vl.c 2013-12-15 00:40:31.653800907 +0800 @@ -1384,6 +1384,19 @@ }, }; +/** + * This function will return whether @num is power of 2. + * + * Returns: 1 indicate @num is power of 2, 0 indicate @num is not. + */ +static int is_2_power(int num) +{ + if (num < 0 || num > 256) + return 1; + + return !(num & (num - 1)); +} + static void smp_parse(QemuOpts *opts) { if (opts) { @@ -1418,6 +1431,12 @@ } + /* check whether smp_cores and smp_threads is a power of 2 */ + if (!is_2_power(smp_cores) || !is_2_power(smp_threads)) { + smp_cores = 1; + smp_threads = 1; + } + if (max_cpus == 0) { max_cpus = smp_cpus; }