From patchwork Wed Aug 26 00:17:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 510691 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 930B31401EF for ; Wed, 26 Aug 2015 10:23:22 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=XDwn7hsq; dkim-atps=neutral Received: from localhost ([::1]:35476 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUOUq-0002GN-OV for incoming@patchwork.ozlabs.org; Tue, 25 Aug 2015 20:23:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41386) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUOPh-0002bt-Nc for qemu-devel@nongnu.org; Tue, 25 Aug 2015 20:18:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUOPg-0000Oc-Px for qemu-devel@nongnu.org; Tue, 25 Aug 2015 20:18:01 -0400 Received: from mail-wi0-x229.google.com ([2a00:1450:400c:c05::229]:38278) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUOPg-0000OD-J3 for qemu-devel@nongnu.org; Tue, 25 Aug 2015 20:18:00 -0400 Received: by wicja10 with SMTP id ja10so205226wic.1 for ; Tue, 25 Aug 2015 17:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=UZy32a3WkUgVQVlZsdp7Ojr3DjWyH+DygBoFRbq5Gv8=; b=XDwn7hsqGpTeGV+QJLfLKMG4gr4RH6VcC6/EHYZo5L8DDMAAUSX090iBn1ZBV3rEOv uhjUJqSesKT9NIGT8u1WAUf+V9/o8aIWu3BMMJuvkFGK/hdbqvdmb61JzMz+zheKnjrl KJ7cuHN47xBLqDhB/vgsIbMdTr5K9eqW6gbUFO3mg7Do7cjHIjumLxe0arsa3G3HD0L3 mQ42JGzwFF/tpUVxK3GSrljHRDpTtkApulQRKp1nhsN18G1xdALdMRRmX+smrz7pwM+P QquBd4tCSAB5/rTrAXNPnvXlEZ4EjbFBL1LCT+PZ90fA9XwsxJkGstqVItgn++T29n1z mxrg== X-Received: by 10.194.85.163 with SMTP id i3mr54209892wjz.75.1440548279790; Tue, 25 Aug 2015 17:17:59 -0700 (PDT) Received: from localhost.localdomain (tdwnet161-109.tecnotn.net. [213.21.161.109]) by smtp.gmail.com with ESMTPSA id s7sm4909925wix.23.2015.08.25.17.17.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Aug 2015 17:17:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 26 Aug 2015 02:17:43 +0200 Message-Id: <1440548265-4755-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1440548265-4755-1-git-send-email-pbonzini@redhat.com> References: <1440548265-4755-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::229 Cc: mttcg@greensocs.com, cota@braap.org, rth@twiddle.net Subject: [Qemu-devel] [PATCH 7/9] tcg: synchronize exit_request and tcg_current_cpu accesses 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 Synchronize the remaining pair of accesses in cpu_signal. The wrongly-ordered accesses in cpu_signal are currently not an issue on Windows because they execute atomically between SuspendProcess and ResumeProcess. Only cpu_exec can be split (and the newly introduced atomic_mb_read would be needed on Windows too, but the compiler must not be doing strange optimizations). Signed-off-by: Paolo Bonzini --- cpu-exec.c | 2 +- cpus.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index 2128bf1..b337506 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -409,7 +409,7 @@ int cpu_exec(CPUState *cpu) atomic_mb_set(&tcg_current_cpu, cpu); rcu_read_lock(); - if (unlikely(exit_request)) { + if (unlikely(atomic_mb_read(&exit_request))) { cpu->exit_request = 1; } diff --git a/cpus.c b/cpus.c index ec8168c..783ef00 100644 --- a/cpus.c +++ b/cpus.c @@ -663,11 +663,15 @@ static void cpu_handle_guest_debug(CPUState *cpu) static void cpu_signal(int sig) { - CPUState *cpu = atomic_mb_read(&tcg_current_cpu); + CPUState *cpu; + /* Ensure whatever caused the exit has reached the CPU threads before + * writing exit_request. + */ + atomic_mb_set(&exit_request, 1); + cpu = atomic_mb_read(&tcg_current_cpu); if (cpu) { cpu_exit(cpu); } - exit_request = 1; } #ifdef CONFIG_LINUX @@ -1074,7 +1078,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) } /* process any pending work */ - exit_request = 1; + atomic_mb_set(&exit_request, 1); while (1) { tcg_exec_all(); @@ -1453,7 +1457,9 @@ static void tcg_exec_all(void) break; } } - exit_request = 0; + + /* Pairs with smp_wmb in qemu_cpu_kick. */ + atomic_mb_set(&exit_request, 0); } void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg)