Skip to contentSkip to conversation

Atomicity of i386 guest atomic instructions

Qemu-devel Jakub Jermar 4 participants 4 messages Apr 23, 2010 – Apr 28, 2010

lore
Share & tools
lore
#0 lore raw

Hello,

is it at least theoretically possible that the guest atomic instructions (e.g. XCHG, LOCK CMPXCHG) on target-i386 are somehow not atomic when simulated/translated by Qemu?

I am observing a problem with one of my HelenOS/ia32 builds which suggests me that for some reason HelenOS spinlocks are not working as expected, because at one point there are two CPUs in one spinlock-protected critical section. I have been looking into this for several days and could not find anything on the HelenOS side. The assembly code which does the locking looks good and the respective spinlock is not corrupted. The problem shows in about 2/3 of all dual-CPU boots. When it shows, the stack trace is always the same. When it does not show during the boot, the system continues to run stable and I never see the problem after the system started up.

I reproduced this on Qemu 0.11.1 and 0.12.2-3 without kvm, both on ia32 and amd64 hosts.

Any idea appreciated.

Regards,
Jakub

#1 lore raw
Quoted 14 lines · Jakub Jermar

Hello,

is it at least theoretically possible that the guest atomic instructions (e.g. XCHG, LOCK CMPXCHG) on target-i386 are somehow not atomic when simulated/translated by Qemu?

I am observing a problem with one of my HelenOS/ia32 builds which suggests me that for some reason HelenOS spinlocks are not working as expected, because at one point there are two CPUs in one spinlock-protected critical section. I have been looking into this for several days and could not find anything on the HelenOS side. The assembly code which does the locking looks good and the respective spinlock is not corrupted. The problem shows in about 2/3 of all dual-CPU boots. When it shows, the stack trace is always the same. When it does not show during the boot, the system continues to run stable and I never see the problem after the system started up.

Quoted 1 line

I reproduced this on Qemu 0.11.1 and 0.12.2-3 without kvm, both on ia32 and amd64 hosts.

They should be atomic. TCG SMP swaps between different vCPUs only after translation blocks are done. In fact, the only way I'm aware of to stop the execution of a TB mid-way is a page fault.

You can as always check things with the -d parameter.

Alex

#2 lore raw
Quoted 3 lines · Alexander Graf

They should be atomic. TCG SMP swaps between different vCPUs only after translation blocks are done. In fact, the only way I'm aware of to stop the execution of a TB mid-way is a page fault.

A page fault would interrupt it if the atomic is implemented as a read followed by a write, and the write faults.

Quoted 1 line

You can as always check things with the -d parameter.

-- Jamie

#3 lore raw
Quoted 7 lines
Quoted 3 lines · Alexander Graf

They should be atomic. TCG SMP swaps between different vCPUs only after translation blocks are done. In fact, the only way I'm aware of to stop the execution of a TB mid-way is a page fault.

A page fault would interrupt it if the atomic is implemented as a read followed by a write, and the write faults.

Yes, but in that case the whole instruction should be abandoned.

Paul