From patchwork Thu Jul 14 07:57:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 9229161 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 88A7D607D0 for ; Thu, 14 Jul 2016 07:58:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B22528178 for ; Thu, 14 Jul 2016 07:58:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FB872817F; Thu, 14 Jul 2016 07:58:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 00B1228178 for ; Thu, 14 Jul 2016 07:58:36 +0000 (UTC) Received: from localhost ([::1]:52124 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNbXX-0007R7-Cr for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Jul 2016 03:58:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNbUS-0004Tx-Rz for qemu-devel@nongnu.org; Thu, 14 Jul 2016 03:55:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNbUQ-00086c-Lp for qemu-devel@nongnu.org; Thu, 14 Jul 2016 03:55:23 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:46225) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNbUQ-000868-9Y for qemu-devel@nongnu.org; Thu, 14 Jul 2016 03:55:22 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3rqp081kjZz9sCy; Thu, 14 Jul 2016 17:55:20 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1468482920; bh=fCfALYzep1scC06PRY6nO3ZpYhzY8gpYCNNApM33fZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a2amRrGyHJQuT52t+JI1YkzpbTqiPnKf9YeQoRqDxVhWKkaT28OS3QeWQrlQL+DBR uZ30G4JELNpkp7TW26Tez4khlH+KjZVta0tbZC/xyXlYDEqT/gMPCYesIojtwWLK1O 1rAqVvX3JWR3GDvJPsAPasSTndjenilOQBE3PiJE= From: David Gibson To: riku.voipio@iki.fi, imammedo@redhat.com Date: Thu, 14 Jul 2016 17:57:05 +1000 Message-Id: <1468483025-1084-3-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468483025-1084-1-git-send-email-david@gibson.dropbear.id.au> References: <1468483025-1084-1-git-send-email-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [RFC 2/2] linux-user: Fix cpu_index generation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP With CONFIG_USER_ONLY, generation of cpu_index values is done differently than for full system targets. This method turns out to be broken, since it can fairly easily result in duplicate cpu_index values for simultaneously active cpus (i.e. threads in the emulated process). Consider this sequence: Create thread 1 Create thread 2 Exit thread 1 Create thread 3 With the current logic thread 1 will get cpu_index 1, thread 2 will get cpu_index 2 and thread 3 will also get cpu_index 2 (because there are 2 threads in the cpus list at the point of its creation). We mostly get away with this because cpu_index values aren't that important for userspace emulation. Still, it can't be good, so this patch fixes it by making CONFIG_USER_ONLY use the same bitmap based allocation that full system targets already use. Signed-off-by: David Gibson --- exec.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/exec.c b/exec.c index 011babd..e410dab 100644 --- a/exec.c +++ b/exec.c @@ -596,7 +596,6 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx) } #endif -#ifndef CONFIG_USER_ONLY static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS); static int cpu_get_free_index(Error **errp) @@ -617,24 +616,6 @@ static void cpu_release_index(CPUState *cpu) { bitmap_clear(cpu_index_map, cpu->cpu_index, 1); } -#else - -static int cpu_get_free_index(Error **errp) -{ - CPUState *some_cpu; - int cpu_index = 0; - - CPU_FOREACH(some_cpu) { - cpu_index++; - } - return cpu_index; -} - -static void cpu_release_index(CPUState *cpu) -{ - return; -} -#endif void cpu_exec_exit(CPUState *cpu) {