serenity/Kernel/Memory
Idan Horowitz 1c2dbed38a Kernel: Extend the lifetime of Regions during page fault handling
Previously we had a race condition in the page fault handling: We were
relying on the affected Region staying alive while handling the page
fault, but this was not actually guaranteed, as an munmap from another
thread could result in the region being removed concurrently.

This commit closes that hole by extending the lifetime of the region
affected by the page fault until the handling of the page fault is
complete. This is achieved by maintaing a psuedo-reference count on the
region which counts the number of in-progress page faults being handled
on this region, and extending the lifetime of the region while this
counter is non zero.
Since both the increment of the counter by the page fault handler and
the spin loop waiting for it to reach 0 during Region destruction are
serialized using the appropriate AddressSpace spinlock, eventual
progress is guaranteed: As soon as the region is removed from the tree
no more page faults on the region can start.
And similarly correctness is ensured: The counter is incremented under
the same lock, so any page faults that are being handled will have
already incremented the counter before the region is deallocated.
2023-04-06 20:30:03 +03:00
..
AddressSpace.cpp Kernel: Store a pointer to the owner process in PageDirectory 2023-04-06 20:30:03 +03:00
AddressSpace.h Kernel: Store a pointer to the owner process in PageDirectory 2023-04-06 20:30:03 +03:00
AllocationStrategy.h
AnonymousVMObject.cpp Everywhere: Remove NonnullRefPtr.h includes 2023-03-06 23:46:35 +01:00
AnonymousVMObject.h Kernel: Turn lock ranks into template parameters 2023-01-02 18:15:27 -05:00
InodeVMObject.cpp Kernel: Use RefPtr instead of LockRefPtr for PhysicalPage 2022-08-24 18:35:41 +02:00
InodeVMObject.h Kernel: Switch LockRefPtr<Inode> to RefPtr<Inode> 2023-03-09 21:54:59 +01:00
MappedROM.h Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
MemoryManager.cpp Kernel: Extend the lifetime of Regions during page fault handling 2023-04-06 20:30:03 +03:00
MemoryManager.h Kernel: Extend the lifetime of Regions during page fault handling 2023-04-06 20:30:03 +03:00
PageFaultResponse.h Kernel: Send SIGBUS to threads that use after valid Inode mmaped range 2022-09-26 20:00:34 +03:00
PhysicalPage.cpp Kernel: Make NNRP<PhysicalPage const> possible 2023-02-21 00:54:04 +01:00
PhysicalPage.h Kernel: Make NNRP<PhysicalPage const> possible 2023-02-21 00:54:04 +01:00
PhysicalRegion.cpp Everywhere: Stop using NonnullOwnPtrVector 2023-03-06 23:46:35 +01:00
PhysicalRegion.h Kernel: Stop using NonnullLockRefPtrVector 2023-03-06 23:46:36 +01:00
PhysicalZone.cpp Kernel: Add implied auto qualifiers in Memory 2022-01-09 23:29:57 -08:00
PhysicalZone.h Kernel: Remove the kmalloc_eternal heap :^) 2021-12-28 21:02:38 +01:00
PrivateInodeVMObject.cpp AK: Rename Bitmap::try_create() to ::create() 2022-12-22 15:48:53 +01:00
PrivateInodeVMObject.h Kernel: Handle mmap requests on zero-length data file inodes safely 2022-09-16 14:55:45 +03:00
Region.cpp Kernel: Extend the lifetime of Regions during page fault handling 2023-04-06 20:30:03 +03:00
Region.h Kernel: Extend the lifetime of Regions during page fault handling 2023-04-06 20:30:03 +03:00
RegionTree.cpp Kernel: Remove i686 support 2022-12-28 11:53:41 +01:00
RegionTree.h Kernel: Wrap process address spaces in SpinlockProtected 2022-08-24 14:57:51 +02:00
RingBuffer.cpp Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
RingBuffer.h Kernel: Turn lock ranks into template parameters 2023-01-02 18:15:27 -05:00
ScatterGatherList.cpp Kernel: Use RefPtr instead of LockRefPtr for PhysicalPage 2022-08-24 18:35:41 +02:00
ScatterGatherList.h Kernel: Use RefPtr instead of LockRefPtr for PhysicalPage 2022-08-24 18:35:41 +02:00
ScopedAddressSpaceSwitcher.cpp Kernel: Fix mispellings of AARCH64 that broke the build 2023-03-08 14:20:29 +01:00
ScopedAddressSpaceSwitcher.h Kernel: Rename ProcessPagingScope => ScopedAddressSpaceSwitcher 2021-09-06 18:56:51 +02:00
SharedFramebufferVMObject.cpp Everywhere: Use ReadonlySpan<T> instead of Span<T const> 2023-02-08 19:15:45 +00:00
SharedFramebufferVMObject.h Everywhere: Use ReadonlySpan<T> instead of Span<T const> 2023-02-08 19:15:45 +00:00
SharedInodeVMObject.cpp AK: Rename Bitmap::try_create() to ::create() 2022-12-22 15:48:53 +01:00
SharedInodeVMObject.h Kernel: Handle mmap requests on zero-length data file inodes safely 2022-09-16 14:55:45 +03:00
TypedMapping.h Everywhere: Run clang-format 2022-12-03 23:52:23 +00:00
VirtualRange.cpp Kernel+LibC: Move name length constants to Kernel/API from limits.h 2023-01-21 10:43:59 -07:00
VirtualRange.h Everywhere: Add sv suffix to strings relying on StringView(char const*) 2022-07-12 23:11:35 +02:00
VMObject.cpp AK: Remove try_ prefix from FixedArray creation functions 2023-01-28 22:41:36 +01:00
VMObject.h Everywhere: Use ReadonlySpan<T> instead of Span<T const> 2023-02-08 19:15:45 +00:00