From patchwork Mon Feb 13 12:10:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 93870 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1074397qgi; Mon, 13 Feb 2017 04:37:56 -0800 (PST) X-Received: by 10.200.45.144 with SMTP id p16mr19540766qta.141.1486989476433; Mon, 13 Feb 2017 04:37:56 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id l23si7132458qtb.40.2017.02.13.04.37.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 13 Feb 2017 04:37:56 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56312 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdFtB-000567-Up for patch@linaro.org; Mon, 13 Feb 2017 07:37:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdFSS-0005QB-7r for qemu-devel@nongnu.org; Mon, 13 Feb 2017 07:10:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdFSP-0002db-LB for qemu-devel@nongnu.org; Mon, 13 Feb 2017 07:10:16 -0500 Received: from mail-wr0-x22c.google.com ([2a00:1450:400c:c0c::22c]:34090) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cdFSP-0002cv-FR for qemu-devel@nongnu.org; Mon, 13 Feb 2017 07:10:13 -0500 Received: by mail-wr0-x22c.google.com with SMTP id o16so149174400wra.1 for ; Mon, 13 Feb 2017 04:10:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OVSuwgMHywA36i1audKW6FDcqD/f0bpKHaKXiTJxEXA=; b=LtCqa5gkdYxo+hEdDnKxVtljvQmPCkbh8MFJOfLQiCbzkjFYVWeM71gHGmkEN7SnkJ OkXbzrjkMeomOlRcIlC54OUnkCv0rUOKmgqvBAevank68qW7JKeiZKW092C3nAIk5f1i qkqlR1d/AJUv4tY5A583dtDsYdecaJijHeNE8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OVSuwgMHywA36i1audKW6FDcqD/f0bpKHaKXiTJxEXA=; b=LAu0x+tleRntRE5fmj2L+GbeltKk3E46Vg+h1Un9fJ8QgIwNPMWnXkkJ4Dyfd6XUGJ W6ZAMcuBLFSceFEvpTfiT6vr8c+56L8NQWULFWro5tm5/ytJf35J8gIHuWFqwlG7hngL PL9b3tsL4kzeD3Da12VDTAY+WvWomTmvc/p+XZn7ECC7vjaazNkeQqJK/uSjkTdVxGVf jctedGKDqWdbH2socHdaMVUKH41lfD8RLySdb+e5cbUVO66rA+YdXTejgaNoJngLGGlC 9XdCZGLk38T4I0hD6FlusXK0BwmUjit/Sscq0E4Jk+TIncnVEYv9jzjfRSOjYtH9lyVE z+7Q== X-Gm-Message-State: AMke39lwVIWx87DzWpvu3rsRK5RqkLHJbtjIgQXL0RAfGkOzQ9USjoiG6eO+4VV9ayQXKYCC X-Received: by 10.223.138.172 with SMTP id y41mr19235494wry.118.1486987812443; Mon, 13 Feb 2017 04:10:12 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id s18sm5115434wmb.18.2017.02.13.04.10.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Feb 2017 04:10:07 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 205213E0BE6; Mon, 13 Feb 2017 12:10:18 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org, rth@twiddle.net Date: Mon, 13 Feb 2017 12:10:05 +0000 Message-Id: <20170213121017.12907-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170213121017.12907-1-alex.bennee@linaro.org> References: <20170213121017.12907-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c0c::22c Subject: [Qemu-devel] [PATCH v12 12/24] tcg: handle EXCP_ATOMIC exception for system emulation 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: mttcg@listserver.greensocs.com, nikunj@linux.vnet.ibm.com, Peter Crosthwaite , jan.kiszka@siemens.com, mark.burton@greensocs.com, a.rigo@virtualopensystems.com, qemu-devel@nongnu.org, cota@braap.org, serge.fdrv@gmail.com, pbonzini@redhat.com, bobby.prani@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , bamvor.zhangjian@linaro.org, fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Pranith Kumar The patch enables handling atomic code in the guest. This should be preferably done in cpu_handle_exception(), but the current assumptions regarding when we can execute atomic sections cause a deadlock. The current mechanism discards the flags which were set in atomic execution. We ensure they are properly saved by calling the cc->cpu_exec_enter/leave() functions around the loop. As we are running cpu_exec_step_atomic() from the outermost loop we need to avoid an abort() when single stepping over atomic code since debug exception longjmp will point to the the setlongjmp in cpu_exec(). We do this by setting a new jmp_env so that it jumps back here on an exception. Signed-off-by: Pranith Kumar [AJB: tweak title, merge with new patches] Signed-off-by: Alex Bennée [PENDING, CHANGES] Reviewed-by: Richard Henderson CC: Richard Henderson CC: Paolo Bonzini --- cpu-exec.c | 14 +++++++++++--- cpus.c | 9 +++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) -- 2.11.0 Reviewed-by: Richard Henderson diff --git a/cpu-exec.c b/cpu-exec.c index b0ddada8c1..e61f5747c8 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -228,6 +228,7 @@ static void cpu_exec_nocache(CPUState *cpu, int max_cycles, static void cpu_exec_step(CPUState *cpu) { + CPUClass *cc = CPU_GET_CLASS(cpu); CPUArchState *env = (CPUArchState *)cpu->env_ptr; TranslationBlock *tb; target_ulong cs_base, pc; @@ -239,9 +240,16 @@ static void cpu_exec_step(CPUState *cpu) 1 | CF_NOCACHE | CF_IGNORE_ICOUNT); tb->orig_tb = NULL; tb_unlock(); - /* execute the generated code */ - trace_exec_tb_nocache(tb, pc); - cpu_tb_exec(cpu, tb); + + cc->cpu_exec_enter(cpu); + + if (sigsetjmp(cpu->jmp_env, 0) == 0) { + /* execute the generated code */ + trace_exec_tb_nocache(tb, pc); + cpu_tb_exec(cpu, tb); + } + + cc->cpu_exec_exit(cpu); tb_lock(); tb_phys_invalidate(tb, -1); tb_free(tb); diff --git a/cpus.c b/cpus.c index 25897edbd3..cb44544fcf 100644 --- a/cpus.c +++ b/cpus.c @@ -1347,6 +1347,11 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) if (r == EXCP_DEBUG) { cpu_handle_guest_debug(cpu); break; + } else if (r == EXCP_ATOMIC) { + qemu_mutex_unlock_iothread(); + cpu_exec_step_atomic(cpu); + qemu_mutex_lock_iothread(); + break; } } else if (cpu->stop) { if (cpu->unplug) { @@ -1457,6 +1462,10 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) */ g_assert(cpu->halted); break; + case EXCP_ATOMIC: + qemu_mutex_unlock_iothread(); + cpu_exec_step_atomic(cpu); + qemu_mutex_lock_iothread(); default: /* Ignore everything else? */ break;