Demindiro wrote:
xeyes wrote:
Now, as in the title, the question is, is it okay to perform MMIO accesses to the same register in parallel?
If you use volatile accesses it
should be fine (
it's target dependent for LLVM, at least). AFAIK it is fine on all major platforms,
especially on x86 where regular load/stores are always atomic.
In short:
xeyes wrote:
Now, as in the title, the question is, is it okay to perform MMIO accesses to the same register in parallel?
Yes, provided you use volatile accesses (or maybe atomic, though volatile is the defacto way to do it).
(Of course, like Octocontrabass said, if the order matters you should use some synchronization primitive. Some hardware even provide dedicated bits in MMIO registers for that purpose).
Yes I'm using volatile pointers and yes virtualbox is used as a x86 VMM in this case, compiler explorer seems like a really interesting site.
Demindiro wrote:
xeyes wrote:
In virtualbox's DevAHCI.cpp, access to the CI register is handled by the following code (only copied the relavent parts):
I'm pretty sure that's a bug and potentially a security hole in VirtualBox if there really is a race condition. I assume that VirtualBox does have some protection against that though.
If parallel accesses are okay to perform, this code does look buggy. I didn't need the lock for other VMMs either. However, mainstream OSes don't seem to have any issue with this though, maybe they don't access this register in parallel?
Hopefully VirtualBox have protections against anyone trying to use this or other race conditions in their device code. That said, virtualbox isn't typically used on servers to run untrusted VMs either.