From patchwork Fri Feb 24 11:20:57 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: 94435 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp646817qgi; Fri, 24 Feb 2017 03:32:13 -0800 (PST) X-Received: by 10.237.44.229 with SMTP id g92mr1971539qtd.204.1487935933438; Fri, 24 Feb 2017 03:32:13 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 33si1369503qth.121.2017.02.24.03.32.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 24 Feb 2017 03:32:13 -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]:36344 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chE6c-0001EK-Tt for patch@linaro.org; Fri, 24 Feb 2017 06:32:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45534) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chDwF-0007Gh-0t for qemu-devel@nongnu.org; Fri, 24 Feb 2017 06:21:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chDwC-0000Lo-Vp for qemu-devel@nongnu.org; Fri, 24 Feb 2017 06:21:26 -0500 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]:36551) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1chDwC-0000KH-QI for qemu-devel@nongnu.org; Fri, 24 Feb 2017 06:21:24 -0500 Received: by mail-wm0-x235.google.com with SMTP id v77so11956428wmv.1 for ; Fri, 24 Feb 2017 03:21:24 -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=Np7jEMd4dsgbM0PZPBdusu8F9UILv3JCBp1ER7dx1oM=; b=VIjT3hSudnzrNJEV8dZwb5J+Q2e2lSWYGuFpYmXSvSD3RN/zuBwPMan4VVlbkJ/uEA m802KahGF+5jd5K2aP6m5ZjouPVe9a/+0ZIpbptGb3RXNaucjkNZ1dl+3Ia8r6iz1gey IHvTO5qQIGa5k+K8tKotHftLLIGmhaiy+FlHs= 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=Np7jEMd4dsgbM0PZPBdusu8F9UILv3JCBp1ER7dx1oM=; b=G4kxzlEPsBHrpZklwymVk8D5BS+Mwgi6nPNnZvFj5UNhMyTV4Zjtt7R/op1R9KRjcW N/IFnkCo6wyrjbP4mgjeX1T/HJ7cu4AxuP5HCycUov/VxhEXkxUSqW4MUxoLQW7LASze C3evdhAeAy+UkDV5XJk+cjWHmMuEqnN70QMmzzx2vY+L7+6HC5XlLP6CdAUSpyIyDR0S QLV0z768Hs56rWlPgF5XU1mFU6HszBBKSvN4gXlGJjBuU0iN8WtzOlDrfNdBerCqIPh9 JNxvVvtNFk5BRxVyevXwlWOCVOCz8shZsXhnqKHKqP0dxmStBcO1SacEk7KEsT776UPh h1zA== X-Gm-Message-State: AMke39nmve5wEctvLaOBTxrdwHN/AGT2G017sYXNS0Hm2/2T+5MXC6pqD0bCYWuUKKiQtV14 X-Received: by 10.28.27.69 with SMTP id b66mr2124943wmb.50.1487935283796; Fri, 24 Feb 2017 03:21:23 -0800 (PST) Received: from zen.linaro.local (host5-81-235-77.range5-81.btcentralplus.com. [5.81.235.77]) by smtp.gmail.com with ESMTPSA id j18sm9948662wrb.33.2017.02.24.03.21.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Feb 2017 03:21:16 -0800 (PST) Received: from zen.home (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 1C4A03E0817; Fri, 24 Feb 2017 11:21:10 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Fri, 24 Feb 2017 11:20:57 +0000 Message-Id: <20170224112109.3147-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170224112109.3147-1-alex.bennee@linaro.org> References: <20170224112109.3147-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:c09::235 Subject: [Qemu-devel] [PULL 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: Peter Crosthwaite , qemu-devel@nongnu.org, Paolo Bonzini , Pranith Kumar , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson 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, add mmap_lock] Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson CC: Paolo Bonzini --- cpu-exec.c | 43 +++++++++++++++++++++++++++++++------------ cpus.c | 9 +++++++++ 2 files changed, 40 insertions(+), 12 deletions(-) -- 2.11.0 diff --git a/cpu-exec.c b/cpu-exec.c index 2edd26e823..1a5ad4889d 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -228,24 +228,43 @@ 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; uint32_t flags; cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags); - tb_lock(); - tb = tb_gen_code(cpu, pc, cs_base, flags, - 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); - tb_lock(); - tb_phys_invalidate(tb, -1); - tb_free(tb); - tb_unlock(); + if (sigsetjmp(cpu->jmp_env, 0) == 0) { + mmap_lock(); + tb_lock(); + tb = tb_gen_code(cpu, pc, cs_base, flags, + 1 | CF_NOCACHE | CF_IGNORE_ICOUNT); + tb->orig_tb = NULL; + tb_unlock(); + mmap_unlock(); + + cc->cpu_exec_enter(cpu); + /* 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); + tb_unlock(); + } else { + /* We may have exited due to another problem here, so we need + * to reset any tb_locks we may have taken but didn't release. + * The mmap_lock is dropped by tb_gen_code if it runs out of + * memory. + */ +#ifndef CONFIG_SOFTMMU + tcg_debug_assert(!have_mmap_lock()); +#endif + tb_lock_reset(); + } } void cpu_exec_step_atomic(CPUState *cpu) diff --git a/cpus.c b/cpus.c index bfee326d30..8200ac6b75 100644 --- a/cpus.c +++ b/cpus.c @@ -1348,6 +1348,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) { @@ -1458,6 +1463,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;