From c7bbc9cd675494c7464bb83a82bf92a8aeb5dde3 Mon Sep 17 00:00:00 2001 From: rponeawa Date: Wed, 11 Nov 2026 00:00:00 +0800 Subject: [PATCH] fix(memory): keep the pool's zero fill out of the driver's lock A BoAlloc prepares its pages before it takes the driver's lock, and the pool's allocation runs there with its zero fill, which maps the run in the kernel map. When the preparation gave nothing, allocateSystem asked the pool a second time under the lock, so a VM mapping, a zero fill and an unmap ran while every other client's submit, map and wait queued behind. The lock path now always offers its (possibly empty) prepared pages, and allocateSystem leaves the pool alone when it was offered any: the VM's pages take the request there, as they did before the pool. Not run on hardware. --- NativeAdrenoMemory.cpp | 4 +++- NativeAdrenoPublish.cpp | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/NativeAdrenoMemory.cpp b/NativeAdrenoMemory.cpp index 37c417a..e6145c0 100644 --- a/NativeAdrenoMemory.cpp +++ b/NativeAdrenoMemory.cpp @@ -280,7 +280,9 @@ IOReturn NativeAdrenoMemory::allocateSystem(size_t bytes,unsigned bits,size_t bu bool cleaned=false; if(prepared && prepared->held() && prepared->bytes==bytes && prepared->write_combined==write_combined) { descriptor_=prepared->descriptor;grant_=prepared->grant;cleaned=prepared->cleaned;*prepared=NativeAdrenoSystemPages{}; - } else if(NativeAdrenoPoolAllocate(bytes,UINT64_C(1)<live_)connection->core_->offerSystemPages(pages.held()?&pages:nullptr); + /* Offered for every BoAlloc, held or not: allocateSystem then knows it runs under the lock and leaves the pool alone. */ + if(connection->live_)connection->core_->offerSystemPages(alloc?&pages:nullptr); if(connection->live_ && freeing)connection->core_->collectFreedPages(&freed); status=connection->live_?connection->core_->dispatch(method,input,input_size,output,output_size,&g.clock):kIOReturnNotReady; if(connection->live_)connection->core_->offerSystemPages(nullptr);