mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-04-27 00:36:00 +03:00
[PR #3956] [MERGED] Kernel.Vmm: Attempt to address race conditions involving ClampRangeSize, CopySparseMemory, and TryWriteBacking #3824
Labels
No labels
Bloodborne
bug
contributor wanted
documentation
enhancement
frontend
good first issue
help wanted
linux
pull-request
question
release
verification progress
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/shadPS4#3824
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/shadps4-emu/shadPS4/pull/3956
Author: @StevenMiller123
Created: 1/24/2026
Status: ✅ Merged
Merged: 1/27/2026
Merged by: @georgemoralis
Base:
main← Head:attempt-2📝 Commits (7)
5f4e9b8no619d2a6Adjust locking strategye058391Clange976445Always GPU unmap5881d95Fixupsca6f48bUpdate memory.cppffef6d7Rename mutex📊 Changes
5 files changed (+145 additions, -98 deletions)
View changed files
📝
src/common/shared_first_mutex.h(+9 -0)📝
src/core/address_space.cpp(+2 -6)📝
src/core/address_space.h(+2 -1)📝
src/core/memory.cpp(+127 -87)📝
src/core/memory.h(+5 -4)📄 Description
This PR makes ClampRangeSize, CopySparseMemory, and TryWriteBacking thread safe to fix some issues caused by #3954, and in doing so, makes a variety of changes to unmap-related logic to prevent deadlocking.
Specifically, I've adjusted all functions with GPU unmaps to perform their GPU unmaps as soon as possible, while locking a separate mutex I've added. When that operation is done, I attempt to lock for writing before these functions will modify vma_map.
The extra mutex is also now locked for all functions that modify vma_map, since we don't want vma_map modifications occurring while maps/unmaps are performing validity checks.
By using a separate mutex instead of locking reader locks, I can avoid race conditions with trying to transition from reader to writer locks, and ensure we don't have multiple threads trying to perform maps at the same time (and potentially invalidating the results of another thread's validity checks).
Also some smaller changes: I've cleaned up unmap code a bit, removing some unused variables that got left behind in my prior PRs, and I've added a try_lock to SharedFirstMutex to enable using some extra standard library lock types with it.
While I've tested locally with some of my heavily multi-threaded games, I'm willing to bet there are a plethora of bugs that need fixing here, so I'm opening this as a draft.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.