Thread

  1. Re: [PATCH] Fix ARM64/MSVC atomic memory ordering issues on Win11 by adding explicit DMB ​barriers

    Thomas Munro <thomas.munro@gmail.com> — 2025-11-21T00:08:10Z

    On Fri, Nov 21, 2025 at 9:45 AM Greg Burd <greg@burd.me> wrote:
    > Dave and I have been working together to get ARM64 with MSVC functional.
    >  The attached patches accomplish that. Dave is the author of the first
    > which addresses some build issues and fixes the spin_delay() semantics,
    > I did the second which fixes some atomics in this combination.
    
    A couple of immediate thoughts:
    
    https://learn.microsoft.com/en-us/cpp/intrinsics/interlockedexchangeadd-intrinsic-functions?view=msvc-170
    
    Doesn't seem to match your conclusion.
    
    +  if cc.get_id() == 'msvc'
    +    cdata.set('USE_ARMV8_CRC32C', false)
    +    cdata.set('USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK', 1)
    
    USE_ARMV8_CRC32C_WITH_RUNTIME_CHECK (pg_crc32c_armv8_choose.c) won't
    actually work on Windows, but I don't think we should waste time
    implementing it: vendor-supported versions of Windows 11 require
    ARMv8.1A to boot[1][2], and that has it, so I think we should probably
    just define USE_ARMV8_CRC32C.
    
    +static __forceinline void
    +spin_delay(void)
    +{
    +     /* Reference:
    https://learn.microsoft.com/en-us/cpp/intrinsics/arm64-intrinsics#BarrierRestrictions
    */
    +    __isb(_ARM64_BARRIER_SY);
    +}
    
    I don't doubt that barriers are missing in a few places, but how can
    this be the right place?
    
    If you have an environment set up so it's easy to test, I would also
    be very interested to know if my patch set[3] that nukes all this
    stuff and includes <stdatomic.h> instead, which is green on
    Windows/x86 CI, will just work™ there too.
    
    [1] https://en.wikipedia.org/wiki/Windows_11_version_history
    [2] https://learn.microsoft.com/en-us/lifecycle/products/windows-11-home-and-pro
    [3] https://www.postgresql.org/message-id/flat/CA%2BhUKGKFvu3zyvv3aaj5hHs9VtWcjFAmisOwOc7aOZNc5AF3NA%40mail.gmail.com