From nobody Sat Apr 20 04:02:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486691188108468.7528566182543; Thu, 9 Feb 2017 17:46:28 -0800 (PST) Received: from localhost ([::1]:41248 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cc0I5-0004ej-Hg for importer@patchew.org; Thu, 09 Feb 2017 20:46:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cc0H8-0004Mm-4H for qemu-devel@nongnu.org; Thu, 09 Feb 2017 20:45:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cc0H5-0006ip-2R for qemu-devel@nongnu.org; Thu, 09 Feb 2017 20:45:26 -0500 Received: from mail-yb0-x241.google.com ([2607:f8b0:4002:c09::241]:35543) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cc0H4-0006iB-TA for qemu-devel@nongnu.org; Thu, 09 Feb 2017 20:45:22 -0500 Received: by mail-yb0-x241.google.com with SMTP id j82so853275ybg.2 for ; Thu, 09 Feb 2017 17:45:21 -0800 (PST) Received: from localhost.localdomain (c-73-207-178-95.hsd1.ga.comcast.net. [73.207.178.95]) by smtp.gmail.com with ESMTPSA id x26sm76177ywj.42.2017.02.09.17.45.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Feb 2017 17:45:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=h1vvV+xlpAuKTe+CDsQCHKGj6X9d9LFJW++0E789g34=; b=P7UiqK0rTQYUkEk39135Hd1E5DebqJgSvI2dEWcqzHiGJ+CTIYCjoi97W8fIrQVAPR b6vlNGcl4kitIVW0lpxoP4Z0Wx1oBJ6hwCZXStzs4i8EwqUQ6dRmtuD84TQNLfZCxxU0 YsZ3FwJl9YcZuABuUPQffhzD+zEuDX9QBRNRDIOFiSUqI+PdNhMoKcSs2o92vldoOAnh ogtqKFTY6DTRXOkK37M+eN8NMu8kH0xqF/nZliS+syWPgJjZd6xX/dWjo+23I4c/5KQe w633QgS651KcO8Vquxe84d4FXPIVuQtw3ZjEnzckjElHRBXD6pqOmRD7pN9enXhuYFo3 Fw4g== 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:mime-version :content-transfer-encoding; bh=h1vvV+xlpAuKTe+CDsQCHKGj6X9d9LFJW++0E789g34=; b=AlKZCxQWbq7Wf6+5WY0/h8BhTdKWT80NStKLhyv8nYI0XvSewHqaTiqQYHtNMz74Lc U+84oVybdTW5fc+4vBw1b7swEytzoIKmx7+359/FauPxxK8lO6IFd62sNjYo2UYyP8C7 18/nmldiwiLUiepqs2Pwhaz1J13w03y2mbcQPVHvZgD6wpq5ln6MMBW7UkXfFN897vCt rodeSeBAvtA9skO01sgwcsClxKsU5GGc1f+UTidcIg/M0CYqVmhwe09pPzSUWwk808Ud dIWaupLK1UdGobxuWDOih56zxln/Hun7ZMiRffM/NGwemCuti0NPs68HtMDY9FhFIYNy 94Qg== X-Gm-Message-State: AMke39kURI0+N12J/wUX1xxw+C4dcPDMPeGk2uSN6W31RZ8hu2O+uauhmmfVbYSKvvppWA== X-Received: by 10.37.219.193 with SMTP id g184mr4724258ybf.19.1486691120506; Thu, 09 Feb 2017 17:45:20 -0800 (PST) From: Pranith Kumar To: Paolo Bonzini , Peter Crosthwaite , Richard Henderson , qemu-devel@nongnu.org (open list:Overall) Date: Thu, 9 Feb 2017 20:45:19 -0500 Message-Id: <20170210014519.12413-1-bobby.prani@gmail.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c09::241 Subject: [Qemu-devel] [PATCH] tcg: handle EXCP_ATOMIC exception properly 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 The current method of executing atomic code in a guest uses cpu_exec_step_atomic() from the outermost loop. This causes an abort() when single stepping over atomic code since debug exception longjmp will point to the the setlongjmp in cpu_exec(). Another issue with this mechanism is that the flags which were set in atomic execution will be lost since we do not call cpu_exec_enter(). The following patch moves atomic exception handling to the exception handler where all these issues are taken care of. The change in start_exclusive() is necessary since now the cpu in atomic execution will have its running flag set, but we do not want to count it as pending. Thanks to Alex for helping me debug the issue. CC: Alex Benn=C3=A9e CC: Richard Henderson CC: Paolo Bonzini Signed-off-by: Pranith Kumar --- cpu-exec.c | 2 ++ cpus-common.c | 2 +- cpus.c | 4 ---- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index b0ddada8c1..dceacfc5dd 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -427,6 +427,8 @@ static inline bool cpu_handle_exception(CPUState *cpu, = int *ret) *ret =3D cpu->exception_index; if (*ret =3D=3D EXCP_DEBUG) { cpu_handle_debug_exception(cpu); + } else if (*ret =3D=3D EXCP_ATOMIC) { + cpu_exec_step_atomic(cpu); } cpu->exception_index =3D -1; return true; diff --git a/cpus-common.c b/cpus-common.c index 59f751ecf9..7b859752ea 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -192,7 +192,7 @@ void start_exclusive(void) smp_mb(); running_cpus =3D 0; CPU_FOREACH(other_cpu) { - if (atomic_read(&other_cpu->running)) { + if (atomic_read(&other_cpu->running) && !qemu_cpu_is_self(other_cp= u)) { other_cpu->has_waiter =3D true; running_cpus++; qemu_cpu_kick(other_cpu); diff --git a/cpus.c b/cpus.c index e1b82bcd49..981f23d52b 100644 --- a/cpus.c +++ b/cpus.c @@ -1461,10 +1461,6 @@ 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; --=20 2.11.0