1

Suppose I have two pages that map to the same physical memory. Would an acquire operation (or fence) on a virtual address in one page properly synchronize with a release operation (or fence) on a virtual address in the other? Secondly, would cache maintenance operations (dc, ic), too, work with such multiply-mapped memory?

In other words...

  • ...would a stlr (or dmb ishst if fence) on one core to one page properly synchronize with ldar (or dmb ishld if fence) on another core to the other page?
  • ...would a dc whatever on one virtual address have the same effect as a dc whatever on the other?
Mona the Monad
  • 2,265
  • 3
  • 19
  • 30
  • I'm pretty sure yes; otherwise AArch64 would get mentioned as an example of C++ `std::atomic` being "address-free" when `is_always_lock_free` is true. AFAIK, mainstream ISAs generally synchronize on physical address, not virtual. (And this applies even when the same thread is accessing both mapping, at least on x86 but I think on most ISAs.) – Peter Cordes Jul 15 '22 at 16:48
  • data cache uses physical tagging, while instruction cache uses virtual tagging on AArch64 if I remember correctly. If you are trying to sync multiple cores it's commonly done with 'spinlock'. Also depending on chip you are using cache coherence might be implemented in hardware, therefore eliminating need in cache maintenance. – user3124812 Jul 17 '22 at 01:52

1 Answers1

2

As to memory ordering, yes, this is fine. The ARMv8 memory model is defined in terms of reads and writes of a Location, which is defined as "a byte that is associated with an address in the physical address space". See B2.3.1 in the Architecture Reference Manual, version H.a. (Older versions left out the "physical" part so it seems someone noticed that this was ambiguous.)

Likewise, an exclusive load ldxr says in the manual that it marks the physical address as an exclusive access.

Note that if this weren't the case, then on typical OSes, shared memory between processes (e.g. shmget, mmap(MAP_SHARED), etc) would be unusable, as the shared mappings are normally at different virtual addresses in the different processes.

I can't answer the part about cache right now.

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82