From 2dfdbe1df5cf9494becea86bd1b0637464ea8b52 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Mon, 9 Nov 2026 05:33:42 -0800 Subject: [PATCH] :bug: Order the region's stores before a register store on arm64 A doorbell names what the guest wrote to the region before it. Each writer publishes with a release store and a full fence. On x86-64 that keeps every store in order, the register's included. On arm64 those barriers (DMB ISH) order the stores for the guest's CPUs alone, the inner-shareable domain. The device is no CPU of the guest's. Both of the kext's register writes, the display's and the accelerator's, now take a DMB OSHST before the store on arm64, as Linux's writel does before a doorbell. The doorbell a process rings reaches the device through the accelerator's writeRegister, so it is covered too. The function is empty on x86-64. --- guest/kext/src/ReimsGraphics.cpp | 2 ++ guest/kext/src/RgfxAccelerator.cpp | 2 ++ guest/kext/src/RgfxRegionMapping.hpp | 12 ++++++++++++ 3 files changed, 16 insertions(+) diff --git a/guest/kext/src/ReimsGraphics.cpp b/guest/kext/src/ReimsGraphics.cpp index e54681d25..6476e92b3 100644 --- a/guest/kext/src/ReimsGraphics.cpp +++ b/guest/kext/src/ReimsGraphics.cpp @@ -8,6 +8,7 @@ #include "RgfxBootConsole.hpp" #include "RgfxFeatures.hpp" #include "RgfxPipeColor.hpp" +#include "RgfxRegionMapping.hpp" #include #include @@ -169,6 +170,7 @@ UInt32 ReimsGraphics::readRegister(UInt32 offset) const void ReimsGraphics::writeRegister(UInt32 offset, UInt32 value) { + rgfxRegisterWriteBarrier(); *reinterpret_cast(registers + offset) = value; } diff --git a/guest/kext/src/RgfxAccelerator.cpp b/guest/kext/src/RgfxAccelerator.cpp index 19b08e43d..990e516c3 100644 --- a/guest/kext/src/RgfxAccelerator.cpp +++ b/guest/kext/src/RgfxAccelerator.cpp @@ -22,6 +22,7 @@ #include "RgfxFeatures.hpp" #include "RgfxIOSurfaceKPI.hpp" #include "RgfxPciClass.hpp" +#include "RgfxRegionMapping.hpp" #include "RgfxSurfaceRows.hpp" #include "RgfxTrace.hpp" #include "RgfxVideoCodecs.hpp" @@ -295,6 +296,7 @@ UInt32 RgfxAccelerator::readRegister(UInt32 offset) const void RgfxAccelerator::writeRegister(UInt32 offset, UInt32 value) { + rgfxRegisterWriteBarrier(); *reinterpret_cast(registers + offset) = value; } diff --git a/guest/kext/src/RgfxRegionMapping.hpp b/guest/kext/src/RgfxRegionMapping.hpp index a46e81278..ab57bc87d 100644 --- a/guest/kext/src/RgfxRegionMapping.hpp +++ b/guest/kext/src/RgfxRegionMapping.hpp @@ -38,4 +38,16 @@ constexpr bool kRgfxRegionWriteCombines = true; constexpr uint64_t kRgfxKextFeatureRegionWriteCombined = kRgfxRegionWriteCombines ? kRgfxKextFeatureWriteCombined : 0; +// Before a store to the device's registers (a doorbell, a status): orders every store before it, +// the region's among them, before the register's store for the device. On arm64 the region's +// release stores and fences order them for the guest's CPUs alone (inner shareable), and the +// device is no CPU of the guest's, so the register's store takes a DMB OSHST first, as Linux's +// writel does. x86-64 keeps every store in order, and takes nothing. +inline void rgfxRegisterWriteBarrier() +{ +#if RGFX_GUEST_ARM64 + __builtin_arm_dmb(2); // DMB OSHST +#endif +} + #endif // RGFX_REGION_MAPPING_HPP_