Commit Graph

5474 Commits

Author SHA1 Message Date
Andreas Kling
1ea604adb1 Kernel/ProcFS: Avoid String allocation when traversing /proc/PID/fd/ 2021-08-17 01:21:47 +02:00
Andreas Kling
45a5cf95f9 Kernel: Add a little explainer comment to ListedRefCounted 2021-08-17 01:21:47 +02:00
Andreas Kling
ea09294351 Kernel: Port Inode to ListedRefCounted
This consolidates the lock+list combo into a SpinLockProtectedValue
and closes yet another unref() race. :^)
2021-08-17 01:21:47 +02:00
Andreas Kling
b70b3a9b92 Kernel: Remove unused VMObject::is_contiguous() 2021-08-17 01:21:47 +02:00
Andreas Kling
4226b662cd Kernel+Userland: Remove global futexes
We only ever use private futexes, so it doesn't make sense to carry
around all the complexity required for global (cross-process) futexes.
2021-08-17 01:21:47 +02:00
Andreas Kling
7979b5a8bb Kernel: Port VMObject to ListedRefCounted
The VMObject class now manages its own instance list (it was previously
a member of MemoryManager.) Removal from the list is done safely on the
last unref(), closing a race window in the previous implementation.

Note that VMObject::all_instances() now has its own lock instead of
using the global MM lock.
2021-08-17 01:21:47 +02:00
Andreas Kling
3a2d888913 Kernel/DevPtsFS: Avoid String allocation during directory traversal
Use a StringBuilder to generate a temporary string buffer with the
slave PTY names. (This works because StringBuilder has 128 bytes of
inline stack capacity before it does any heap allocations.)
2021-08-17 01:21:47 +02:00
Andreas Kling
0de8c95d49 Kernel: Convert SlavePTY all-instances HashTable to an IntrusiveList
This simplifies the DevPtsFS implementation somewhat, as it no longer
requires SlavePTY to register itself with it, since it can now simply
use the list of SlavePTY instances.
2021-08-17 01:21:47 +02:00
Andreas Kling
62719b85e0 Kernel: Port Thread to ListedRefCounted 2021-08-17 01:21:47 +02:00
Andreas Kling
c410f08c2b Kernel: Add ListedRefCounted<T> template class
This class implements the emerging "ref-counted object that participates
in a lock-protected list that requires safe removal on unref()" pattern
as a base class that can be inherited in place of RefCounted<T>.
2021-08-17 01:21:47 +02:00
Andreas Kling
641083f3b8 Kernel: Customize File::unref() and make it virtual
Make File inherit from RefCountedBase and provide a custom unref()
implementation. This will allow subclasses that participate in lists to
remove themselves in a safe way when being destroyed.
2021-08-17 01:21:47 +02:00
Andreas Kling
fc0cd8317a Kernel/DevPtsFS: Add tightly typed DevPtsFSInode::fs() 2021-08-17 01:21:47 +02:00
Itamar
f3aa87c436 Kernel: Make makedev()/minor()/major() static
This was originally done in 7274037 and for some reason reverted in
740140a.

This avoids "multiple definitions" link errors and fixes the libuv port.
2021-08-16 23:26:52 +02:00
Ali Mohammad Pur
64bc5f668d Kernel: Avoid enumerating all the fds to find a specific one in procfs 2021-08-16 21:16:14 +02:00
Ali Mohammad Pur
e9feced041 Kernel: Add a Process::FileDescriptions::get_if_valid(index) API
Note that this is not the same as ::at(index), which has a different
precondition ("allocated" vs "valid").
2021-08-16 21:16:14 +02:00
Andreas Kling
c1c12497b5 Kernel: Don't hold thread list lock while invoking ~Thread()
There is no need for this, and it can cause deadlocks if ~Thread()
ends up doing something else that requires a lock (e.g ~Process())
2021-08-16 02:22:42 +02:00
Andreas Kling
29a58459ab Kernel: Use ProtectedValue for VirtualFileSystem::m_mounts
This is what VirtualFileSystem::m_lock was actually guarding, and
wrapping it in a ProtectedValue makes it so much more obvious how it
all works. :^)
2021-08-16 01:41:26 +02:00
Andreas Kling
d6d7d11590 Kernel: Cache Custody objects (weakly) to avoid expensive reconstruction
This patch adds a (spinlock-protected) custody cache. It's a simple
intrusive list containing all currently live custody objects.

This allows us to re-use existing custodies instead of creating them
again and again.

This gives a pretty decent performance improvement on "find /" :^)
2021-08-15 23:30:52 +02:00
Andreas Kling
a412fd2ed8 Kernel/ProcFS: Avoid two unnecessary number-to-string conversions
We don't need to create a new string from a number in order to compare
an existing string to that number. Converting the existing string to a
number is much cheaper, since it does not require any heap allocations.

Ran into this while profiling "find /" :^)
2021-08-15 23:30:52 +02:00
Andreas Kling
9c373b646b Kernel/SysFS: Don't compute exact size of PCI files
There's no need for generated files in SysFS to tell you their precise
file size when you stat() them.

I noticed when profiling "find /" that we were spending a chunk of time
generating and throwing away SysFS content just so we could tell you
exactly how large it would be. :^)
2021-08-15 23:30:52 +02:00
brapru
f633ef2af7 Kernel: Move ARP debug information to ARP_DEBUG
Previously when trying to debug the system's routing, the ARP
information would clutter the output and make it difficult to focus on
the routing decisions. It would be better to specify these
debug messages under ARP_DEBUG.
2021-08-15 21:53:29 +02:00
Andreas Kling
cda69704dc Kernel: Remove unused FIFO::all_fifos() table 2021-08-15 16:53:03 +02:00
Andreas Kling
6a20733fcd Kernel: Convert TCP retransmit queue from HashTable to IntrusiveList 2021-08-15 16:53:03 +02:00
Andreas Kling
7063303022 Kernel: Convert IPv4 socket list from HashTable to IntrusiveList
There was no reason whatsoever to use a HashTable here. IntrusiveList
removes all the heap allocations and does everything more efficiently.
2021-08-15 16:53:03 +02:00
Andreas Kling
a154faebb7 Kernel: Use NonnullRefPtr<PhysicalPage> in PageDirectory::m_page_tables
We don't care to store null page pointers in the page table map.
2021-08-15 16:53:03 +02:00
sin-ack
0a18425cbb Kernel: Make Memory::Region allocation functions return KResultOr
This makes for some nicer handling of errors compared to checking an
OwnPtr for null state.
2021-08-15 15:41:02 +02:00
sin-ack
4bfd6e41b9 Kernel: Make Kernel::VMObject allocation functions return KResultOr
This makes for nicer handling of errors compared to checking whether a
RefPtr is null. Additionally, this will give way to return different
types of errors in the future.
2021-08-15 15:41:02 +02:00
sin-ack
61c0e3ca92 Kernel: Simplify OOM handling in ISO9660FileSystem 2021-08-15 15:41:02 +02:00
sin-ack
8d90ecb280 Kernel: Simplify OOM handling in ProcessProcFSTraits 2021-08-15 15:41:02 +02:00
Andreas Kling
5416fa252a Kernel: Add tightly typed ISO9660Inode::fs() overload
We know the fs() is always an ISO9660FS, so let's be nice and make fs()
return that when called on an ISO9660Inode. :^)
2021-08-15 12:50:22 +02:00
Andreas Kling
37304203dd Kernel: Lock thread list while in Thread::unref()
This patch does three things:

- Convert the global thread list from a HashMap to an IntrusiveList
- Combine the thread list and its lock into a SpinLockProtectedValue
- Customize Thread::unref() so it locks the list while unreffing

This closes the same race window for Thread as @sin-ack's recent changes
did for Process.

Note that the HashMap->IntrusiveList conversion means that we lose O(1)
lookups, but the majority of clients of this list are doing traversal,
not lookup. Once we have an intrusive hashing solution, we should port
this to use that, but for now, this gets rid of heap allocations during
a sensitive time.
2021-08-15 12:44:35 +02:00
Andreas Kling
1b739a72c2 Kernel+Userland: Remove chroot functionality
We are not using this for anything and it's just been sitting there
gathering dust for well over a year, so let's stop carrying all this
complexity around for no good reason.
2021-08-15 12:44:35 +02:00
Andreas Kling
96d5d017b7 Kernel: Remove copy_string_from_user() as it's no longer used 2021-08-15 12:44:35 +02:00
Andreas Kling
0f6f863382 Kernel: Convert remaining users of copy_string_from_user()
This patch replaces the remaining users of this API with the new
try_copy_kstring_from_user() instead. Note that we still convert to a
String for continued processing, and I've added FIXME about continuing
work on using KString all the way.
2021-08-15 12:44:35 +02:00
sin-ack
98408b8920 Kernel: Don't hold the process list lock while destructing the process
Once we remove the process from the process list, we're free to do
whatever we want without any locks.
2021-08-15 12:17:29 +02:00
sin-ack
24fcff45ae Kernel: Make Process final
This silences a clangd diagnostic about Process holding virtual
functions but having a non-virtual destructor.
2021-08-15 02:27:13 +02:00
sin-ack
18f260b78b Kernel: Handle removal of Process from list before unref
This makes the following scenario impossible with an SMP setup:

1) CPU A enters unref() and decrements the link count to 0.
2) CPU B sees the process in the process list and ref()s it.
3) CPU A removes the process from the list and continues destructing.
4) CPU B is now holding a destructed Process object.

By holding the process list lock before doing anything with it, we
ensure that other CPUs can't find this process in the middle of it being
destructed.
2021-08-15 02:27:13 +02:00
sin-ack
2830a0ecda Kernel: Move ProcFS related overrides in Process to ProcessProcFSTraits
This allows us to 1) let go of the Process when an inode is ref'ing for
ProcFSExposedComponent related reasons, and 2) change our ref/unref
implementation.
2021-08-15 02:27:13 +02:00
sin-ack
748938ea59 Kernel: Handle allocation failure in ProcFS and friends
There were many places in which allocation failure was noticed but
ignored.
2021-08-15 02:27:13 +02:00
Kenneth Myhra
cb10c62327 LibC: Add SOCK_RDM and SOCK_SEQPACKET to socket.h 2021-08-14 22:32:00 +01:00
Kenneth Myhra
3875e8bd4b LibC: Add IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP to netin/in.h 2021-08-14 22:32:00 +01:00
Luke
51b6bd8d95 Kernel/USB: Remove UAF in device removal
I was using a raw pointer instead of a RefPtr to keep the device alive
during removal.
2021-08-14 23:14:56 +02:00
Luke
4b4525dfc7 Kernel/USB: Update SysFS from the generic hub instead of from UHCI 2021-08-14 21:22:44 +02:00
Luke
872c75ac44 Kernel/USB: Split SysFS code into its own file
This makes it controller agnostic and allows us to access it from the
USB hub code.

The copyright says "Liav A." because git blame says he wrote this.
2021-08-14 21:22:44 +02:00
Luke
b6a2bbba3b Kernel/USB: Replace PortNumber enum with a raw u8
A hub can technically have up to 255 ports, given that bNbrPorts is a
u8 and the DeviceRemovable field is a VLA to support up to 255 ports.

Source: USB 2.0 Specification Section 11.23.2.1

That means this enum is not going to scale well in terms of size.
Replacing it with a raw u8 allows me to remove the two port assumption
and a cast.
2021-08-14 21:22:44 +02:00
Luke
86ccacf6b5 Kernel/USB: Remove get_device_{at_port,from_address}
Nothing was using these. These can be put back in the future if
required. This also allows removing the devices array in UHCI.
2021-08-14 21:22:44 +02:00
Luke
da0a1068e9 Kernel/USB: Add Hubs and the UHCI Root Hub 2021-08-14 21:22:44 +02:00
Luke
9dcd146ab4 Kernel/USB: Add the USB 1.x/2.0 hub descriptor
There is a different hub descriptor for USB 3.0, but this isn't
included here.
2021-08-14 21:22:44 +02:00
Luke
14da080dcf Kernel/USB: Use allocate_kernel_region in Transfer buffer allocations
Previously it would create a contiguous AVMO manually and pass it to
MM. This uses supervisor pages that quickly run out as they never get
returned and crash the system.

Instead, use allocate_kernel_region as we're only allocating a page so
it will be contiguous and will be returned when destroyed.

A potentially better solution would be to use a pool of transfers to
avoid all the allocations. This just prevents the system from crashing
within ~5 seconds from the continuous hub polling.
2021-08-14 21:22:44 +02:00
Luke
1ca5b6caa9 Kernel/USB: Pass in device address as last argument to Pipe constructor
The order of poll_interval and device_address was flipped.
2021-08-14 21:22:44 +02:00