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.kon...@greensocs.com wrote:
>>> @@ -583,5 +587,6 @@ int cpu_exec(CPUState *cpu)
>>>         /* fail safe : never use current_cpu outside cpu_exec() */
>>>       current_cpu = 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 the
>> code.
>>
>> Paolo
> 
> Yes definitely but we might have a race if we just use safe_work_pending().

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

Reply via email to