summaryrefslogtreecommitdiff
path: root/Kernel
AgeCommit message (Collapse)Author
2022-08-22Kernel/x86: Protect the CR3->PD map with a spinlockAndreas Kling
This can be accessed from multiple CPUs at the same time, so relying on the interrupt flag is clearly insufficient.
2022-08-22Kernel: Stop taking MM lock while using regular quickmapsAndreas Kling
You're still required to disable interrupts though, as the mappings are per-CPU. This exposed the fact that our CR3 lookup map is insufficiently protected (but we'll address that in a separate commit.)
2022-08-22Kernel: Stop taking MM lock while using PD/PT quickmapsAndreas Kling
This is no longer required as these quickmaps are now per-CPU. :^)
2022-08-22Kernel: Make the page table quickmaps per-CPUAndreas Kling
While the "regular" quickmap (used to temporarily map a physical page at a known address for quick access) has been per-CPU for a while, we also have the PD (page directory) and PT (page table) quickmaps used by the memory management code to edit page tables. These have been global, which meant that SMP systems had to keep fighting over them. This patch makes *all* quickmaps per-CPU. We reserve virtual addresses for up to 64 CPUs worth of quickmaps for now. Note that all quickmaps are still protected by the MM lock, and we'll have to fix that too, before seeing any real throughput improvements.
2022-08-22Kernel: Make sys$utime() and sys$utimensat() not take the big lockAndreas Kling
2022-08-22Kernel: Update atime/ctime/mtime timestamps atomicallyAndreas Kling
Instead of having three separate APIs (one for each timestamp), there's now only Inode::update_timestamps() and it takes 3x optional timestamps. The non-empty timestamps are updated while holding the inode mutex, and the outside world no longer has to look at intermediate timestamp states.
2022-08-22Kernel: Make sys$mknod() not take the big lockAndreas Kling
2022-08-22Kernel: Use Process::credentials() and remove user ID/group ID helpersAnthony Iacono
Move away from using the group ID/user ID helpers in the process to allow for us to take advantage of the immutable credentials instead.
2022-08-21Kernel: Make sys$recvfrom() with MSG_DONTWAIT not so racyAndreas Kling
Instead of temporary changing the open file description's "blocking" flag while doing a non-waiting recvfrom, we instead plumb the currently wanted blocking behavior all the way through to the underlying socket.
2022-08-21Kernel: Make Socket::connect() take credentials as inputAndreas Kling
2022-08-21Kernel: Make Socket::bind() take credentials as inputAndreas Kling
2022-08-21Kernel: Make LocalSocket do chown/chmod through VFSAndreas Kling
This ensures that all the permissions checks are made against the provided credentials. Previously we were just calling through directly to the inode setters, which did no security checks!
2022-08-21Kernel: Make Inode::resolve_as_link() take credentials as inputAndreas Kling
2022-08-21Kernel: Make File::{chown,chmod} take credentials as inputAndreas Kling
...instead of getting them from Process::current(). :^)
2022-08-21Kernel: Make VirtualFileSystem functions take credentials as inputAndreas Kling
Instead of getting credentials from Process::current(), we now require that they be provided as input to the various VFS functions. This ensures that an atomic set of credentials is used throughout an entire VFS operation.
2022-08-21Kernel: Use credentials object in Socket set_origin/acceptorJames Bellamy
2022-08-21Kernel: Use credentials object in LocalSocket constructorJames Bellamy
2022-08-21Kernel: Use credentials object in VirtualFileSystemJames Bellamy
Use credentials object in mknod, create, mkdir, and symlink
2022-08-21Kernel: Use credentials object in Coredump:try_create_target_fileJames Bellamy
2022-08-21Kernel: Make sys$getppid() not take the big lockAndreas Kling
This only needs to access the process PPID, which is protected by the "protected data" lock.
2022-08-21Kernel: Guard Process "protected data" with a spinlockAndreas Kling
This ensures that both mutable and immutable access to the protected data of a process is serialized. Note that there may still be multiple TOCTOU issues around this, as we have a bunch of convenience accessors that make it easy to introduce them. We'll need to audit those as well.
2022-08-21Kernel: Use RefPtr instead of LockRefPtr for CustodyAndreas Kling
By protecting all the RefPtr<Custody> objects that may be accessed from multiple threads at the same time (with spinlocks), we remove the need for using LockRefPtr<Custody> (which is basically a RefPtr with a built-in spinlock.)
2022-08-21Kernel/Syscall: Make anon_create to not use Process::allocate_fd methodLiav A
Instead, allocate when acquiring the lock on m_fds struct, which is safer to do in terms of safely mutating the m_fds struct, because we don't use the big process lock in this syscall.
2022-08-20Kernel: Get GID from credentials object in sys$setgroups()Andreas Kling
I missed one instance of these. Thanks Anthony Iacono for spotting it!
2022-08-20Kernel+LibC: Enforce a limit on the number of supplementary group IDsAndreas Kling
This patch adds the NGROUPS_MAX constant and enforces it in sys$setgroups() to ensure that no process has more than 32 supplementary group IDs. The number doesn't mean anything in particular, just had to pick a number. Perhaps one day we'll have a reason to change it.
2022-08-20Kernel: Mark syscalls that get/set user/group ID as not needing big lockAndreas Kling
Now that these operate on the neatly atomic and immutable Credentials object, they should no longer require the process big lock for synchronization. :^)
2022-08-20Kernel: Add Credentials to hold a set of user and group IDsAndreas Kling
This patch adds a new object to hold a Process's user credentials: - UID, EUID, SUID - GID, EGID, SGID, extra GIDs Credentials are immutable and child processes initially inherit the Credentials object from their parent. Whenever a process changes one or more of its user/group IDs, a new Credentials object is constructed. Any code that wants to inspect and act on a set of credentials can now do so without worrying about data races.
2022-08-20Kernel: Move InodeMetadata methods out of lineAndreas Kling
2022-08-20Kernel: Make self-contained locking smart pointers their own classesAndreas Kling
Until now, our kernel has reimplemented a number of AK classes to provide automatic internal locking: - RefPtr - NonnullRefPtr - WeakPtr - Weakable This patch renames the Kernel classes so that they can coexist with the original AK classes: - RefPtr => LockRefPtr - NonnullRefPtr => NonnullLockRefPtr - WeakPtr => LockWeakPtr - Weakable => LockWeakable The goal here is to eventually get rid of the Lock* classes in favor of using external locking.
2022-08-20AK+Kernel: Add AK::AtomicRefCounted and use everywhere in the kernelAndreas Kling
Instead of having two separate implementations of AK::RefCounted, one for userspace and one for kernelspace, there is now RefCounted and AtomicRefCounted.
2022-08-19Kernel: Annotate SpinlockProtected<PacketList> in NetworkAdapter classLiav A
2022-08-19Kernel: Require lock rank for Spinlock constructionkleines Filmröllchen
All users which relied on the default constructor use a None lock rank for now. This will make it easier to in the future remove LockRank and actually annotate the ranks by searching for None.
2022-08-19Kernel: Add 8-byte atomics for i686 GCCIdan Horowitz
Unlike Clang, GCC does not support 8-byte atomics on i686 with the -mno-80387 flag set, so until that is fixed, implement a minimal set of atomics that are currently required.
2022-08-19Kernel: Put too small unused network packets back into the listTim Schumacher
2022-08-19Kernel: Protect the list of unused network packets with a SpinlockTim Schumacher
2022-08-19Kernel: Don't take thread lock for signal dispatchAndreas Kling
Signal dispatch is already protected by the global scheduler lock, but in some cases we also took Thread::m_lock for some reason. This led to a number of different deadlocks that started showing up with 4+ CPU's attached to the system. As a first step towards solving this, simply don't take the thread lock and let the scheduler lock cover it. Eventually, we should work in the other direction and break the scheduler lock into much finer-grained locks, but let's get out of the deadlock swamp first.
2022-08-19Kernel/Memory: Use scope guard to remove a region if we failed to map itLiav A
2022-08-19Kernel: Don't lock scheduler in ~Thread()Andreas Kling
This is not necessary, and is a leftover from before Thread started using the ListedRefCounted pattern to be safely removed from lists on the last call to unref().
2022-08-19Kernel: Don't lock scheduler while updating thread scheduling timesAndreas Kling
We can use simple atomic variables with relaxed ordering for this, and avoid locking altogether.
2022-08-19Kernel: Reduce time under VMObject lock while handling zero faultsAndreas Kling
We only need to hold the VMObject lock while inspecting and/or updating the physical page array in the VMObject.
2022-08-19Kernel/x86: Re-enable interrupts ASAP when handling page faultsAndreas Kling
As soon as we've saved CR2 (the faulting address), we can re-enable interrupt processing. This should make the kernel more responsive under heavy fault loads.
2022-08-18Kernel: Make sys$anon_create() allocate physical pages immediatelyAndreas Kling
This fixes an issue where a sharing process would map the "lazy committed page" early and then get stuck with that page even after it had been replaced in the VMObject by a page fault. Regressed in 27c1135d307efde8d9baef2affb26be568d50263, which made it happen every time with the backing bitmaps used for WebContent.
2022-08-18Kernel: Make Region's physical page accessors safer to useAndreas Kling
Region::physical_page() now takes the VMObject lock while accessing the physical pages array, and returns a RefPtr<PhysicalPage>. This ensures that the array access is safe. Region::physical_page_slot() now VERIFY()'s that the VMObject lock is held by the caller. Since we're returning a reference to the physical page slot in the VMObject's physical page array, this is the best we can do here.
2022-08-18Kernel: Schedule threads on all processors when SMP is enabledAndreas Kling
Note that SMP is still off by default, but this basically removes the weird "SMP on but threads don't get scheduled" behavior we had by default. If you pass "smp=on" to the kernel, you now get SMP. :^)
2022-08-18Kernel: Don't hog VMObject lock when remapping a region pageAndreas Kling
We really only need the VMObject lock when accessing the physical pages array, so once we have a strong pointer to the physical page we want to remap, we can give up the VMObject lock. This fixes a deadlock I encountered while building DOOM on SMP.
2022-08-18Kernel: Move Region physical page accessors out of lineAndreas Kling
2022-08-18Kernel: Add a comment about what the MM lock protectsAndreas Kling
2022-08-18Kernel: Don't require MM lock for Region::set_page_directory()Andreas Kling
The MM lock is not required for this, it's just a simple ref-counted pointer assignment.
2022-08-18Kernel: Fix inconsistent lock acquisition order in kmallocAndreas Kling
We always want to grab the page directory lock before the MM lock. This fixes a deadlock I encountered when building DOOM with make -j4.
2022-08-18Kernel: Don't remap all regions from Region::remap_vmobject_page()Andreas Kling
When handling a page fault, we only need to remap the faulting region in the current process. There's no need to traverse *all* regions that map the same VMObject and remap them cross-process as well. Those other regions will get remapped lazily by their own page fault handlers eventually. Or maybe they won't and we avoided some work. :^)