From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59997) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZP97x-0004cs-Rs for qemu-devel@nongnu.org; Tue, 11 Aug 2015 08:58:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZP97t-0007T3-Jt for qemu-devel@nongnu.org; Tue, 11 Aug 2015 08:58:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43939) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZP97t-0007Sp-FZ for qemu-devel@nongnu.org; Tue, 11 Aug 2015 08:57:57 -0400 References: <1439220437-23957-1-git-send-email-fred.konrad@greensocs.com> <1439220437-23957-3-git-send-email-fred.konrad@greensocs.com> <55C9D41E.3080405@redhat.com> <55C9D87D.1020005@greensocs.com> From: Paolo Bonzini Message-ID: <55C9F14E.3070208@redhat.com> Date: Tue, 11 Aug 2015 14:57:50 +0200 MIME-Version: 1.0 In-Reply-To: <55C9D87D.1020005@greensocs.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [RFC PATCH V7 02/19] cpus: add tcg_exec_flag. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Frederic Konrad , qemu-devel@nongnu.org, mttcg@greensocs.com Cc: alex.bennee@linaro.org, mark.burton@greensocs.com, a.rigo@virtualopensystems.com, guillaume.delbergue@greensocs.com On 11/08/2015 13:11, Frederic Konrad wrote: > On 11/08/2015 12:53, Paolo Bonzini wrote: >> >> On 10/08/2015 17:27, fred.konrad@greensocs.com wrote: >>> @@ -583,5 +587,6 @@ int cpu_exec(CPUState *cpu) >>> /* fail safe : never use current_cpu outside cpu_exec() */ >>> current_cpu =3D NULL; >>> + tcg_cpu_allow_execution(cpu); >> I don't think this is correct; safe_work_pending() is a much clearer >> test. I'll revert locally to the previous version to play more with t= he >> code. >> >> Paolo >=20 > Yes definitely but we might have a race if we just use safe_work_pendin= g(). The trick is to order the accesses correctly. For example, cpu_exec will check tcg_exit_req, then clear exit_request, then check queued_work_first. On the write side the order is the opposite: queued_work_first must be written first, then exit_request, then tcg_exit_req. Here it is the same. safe_work_pending must be incremented first to prevent threads from entering cpu-exec.c; for those that are already in there you write queued_safe_work_first, then exit_request, then tcg_exit_req. Similarly safe_work_pending must be decremented last. Paolo