Commit Graph

31 Commits

Author SHA1 Message Date
Nico Weber
430b265cd4 AK: Rename KB, MB, GB to KiB, MiB, GiB
The SI prefixes "k", "M", "G" mean "10^3", "10^6", "10^9".
The IEC prefixes "Ki", "Mi", "Gi" mean "2^10", "2^20", "2^30".

Let's use the correct name, at least in code.

Only changes the name of the constants, no other behavior change.
2020-08-16 16:33:28 +02:00
Tom
bc107d0b33 Kernel: Add SMP IPI support
We can now properly initialize all processors without
crashing by sending SMP IPI messages to synchronize memory
between processors.

We now initialize the APs once we have the scheduler running.
This is so that we can process IPI messages from the other
cores.

Also rework interrupt handling a bit so that it's more of a
1:1 mapping. We need to allocate non-sharable interrupts for
IPIs.

This also fixes the occasional hang/crash because all
CPUs now synchronize memory with each other.
2020-07-06 17:07:44 +02:00
Tom
3cc0e86cd8 Kernel: Change kmalloc lock to be recursive
If the heap code dumps a stack trace (e.g. out of memory) then
it may recursively call into it. Rather than deadlocking, allow
recursion.
2020-07-03 19:32:34 +02:00
Tom
3ac6d31b45 Kernel: Serialize debug output 2020-07-01 12:07:01 +02:00
Andreas Kling
723f4e5ee6 Meta: Scale back overly informal user-facing strings
We were getting a little overly memey in some places, so let's scale
things back to business-casual.

Informal language is fine in comments, commits and debug logs,
but let's keep the runtime nice and presentable. :^)
2020-06-17 18:35:49 +02:00
Andreas Kling
0c5e441a0b Revert "Kernel: Add implementation of operator new and delete to kmalloc.cpp"
This reverts commit 6d0d848720.
2020-05-20 16:24:26 +02:00
Andrew Kaster
6d0d848720 Kernel: Add implementation of operator new and delete to kmalloc.cpp
This was missing before, we were getting it for free from libstdc++
2020-05-20 08:37:50 +02:00
Andreas Kling
21d5f4ada1 Kernel: Absorb LibBareMetal back into the kernel
This was supposed to be the foundation for some kind of pre-kernel
environment, but nobody is working on it right now, so let's move
everything back into the kernel and remove all the confusion.
2020-05-16 12:00:04 +02:00
Andreas Kling
ca4f714d68 Kernel: Use consistent names for kmalloc globals and remove volatile 2020-05-16 10:55:54 +02:00
Andreas Kling
dc7340332d Kernel: Update cryptically-named functions related to symbolication 2020-04-08 17:19:46 +02:00
nimelehin
c0a4cf5e8d Kernel: Support best fit allocation policy in kmalloc()
Add find_best_fit() which implements best fit allocation algorithm.
Kmalloc now uses a best fit allocation policy for large allocations.
2020-04-06 08:33:13 +02:00
nimelehin
0d08ed2693 Kernel: Implement kmalloc() using AK::Bitmap
kmalloc's bitmap is wrapped with AK::Bitmap to access AK::Bitmap's
functions.
2020-04-06 08:31:48 +02:00
Andreas Kling
b1058b33fb AK: Add global FlatPtr typedef. It's u32 or u64, based on sizeof(void*)
Use this instead of uintptr_t throughout the codebase. This makes it
possible to pass a FlatPtr to something that has u32 and u64 overloads.
2020-03-08 13:06:51 +01:00
Liav A
0fc60e41dd Kernel: Use klog() instead of kprintf()
Also, duplicate data in dbg() and klog() calls were removed.
In addition, leakage of virtual address to kernel log is prevented.
This is done by replacing kprintf() calls to dbg() calls with the
leaked data instead.
Also, other kprintf() calls were replaced with klog().
2020-03-02 22:23:39 +01:00
Liav A
900865e87c Kernel: Run clang-format on Heap/kmalloc.cpp 2020-02-27 13:05:12 +01:00
Liav A
46a7ee97ac Heap kmalloc: Use dbg() instead of dbgprintf() 2020-02-27 13:05:12 +01:00
Andreas Kling
e334c36757 Kernel: Remove unnecessary allocation metadata from kmalloc() chunks
Each allocation header was tracking its index into the chunk bitmap,
but that index can be computed from the allocation address anyway.

Removing this means that each allocation gets 4 more bytes of memory
and this avoids allocating an extra chunk in many cases. :^)
2020-02-22 15:11:31 +01:00
Andreas Kling
ba83bf8a0d Kernel: Increase kmalloc chunk size from 8 bytes to 32 bytes
This gives a huge speedup when running "git status" in a SerenityOS
repository directory. Most of the time was spent allocating strings.
2020-02-22 14:18:34 +01:00
Andreas Kling
48f7c28a5c Kernel: Replace "current" with Thread::current and Process::current
Suggested by Sergey. The currently running Thread and Process are now
Thread::current and Process::current respectively. :^)
2020-02-17 15:04:27 +01:00
Andreas Kling
a356e48150 Kernel: Move all code into the Kernel namespace 2020-02-16 01:27:42 +01:00
Liav A
e559af2008 Kernel: Apply changes to use LibBareMetal definitions 2020-02-09 19:38:17 +01:00
Andreas Kling
8d51352b96 Kernel: Add crash logging heuristic for uninitialized kmalloc()/kfree()
Since we scrub both kmalloc() and kfree() with predictable values, we
can log a helpful message when hitting a crash that looks like it might
be a dereference of such scrubbed data.
2020-02-01 10:56:17 +01:00
Andreas Kling
c1f74bf327 Kernel: Never validate access to the kmalloc memory range
Memory validation is used to verify that user syscalls are allowed to
access a given memory range. Ring 0 threads never make syscalls, and
so will never end up in validation anyway.

The reason we were allowing kmalloc memory accesses is because kernel
thread stacks used to be allocated in kmalloc memory. Since that's no
longer the case, we can stop making exceptions for kmalloc in the
validation code.
2020-01-27 12:43:21 +01:00
Andreas Kling
603bf6fb4a Build: Remove -fno-sized-deallocation -Wno-sized-deallocation
Add sized variants of the global operator delete functions so we don't
have to use these GCC options anymore.
2020-01-25 16:59:21 +01:00
Andreas Kling
94ca55cefd Meta: Add license header to source files
As suggested by Joshua, this commit adds the 2-clause BSD license as a
comment block to the top of every source file.

For the first pass, I've just added myself for simplicity. I encourage
everyone to add themselves as copyright holders of any file they've
added or modified in some significant way. If I've added myself in
error somewhere, feel free to replace it with the appropriate copyright
holder instead.

Going forward, all new source files should include a license header.
2020-01-18 09:45:54 +01:00
Andreas Kling
e362b56b4f Kernel: Move kernel above the 3GB virtual address mark
The kernel and its static data structures are no longer identity-mapped
in the bottom 8MB of the address space, but instead move above 3GB.

The first 8MB above 3GB are pseudo-identity-mapped to the bottom 8MB of
the physical address space. But things don't have to stay this way!

Thanks to Jesse who made an earlier attempt at this, it was really easy
to get device drivers working once the page tables were in place! :^)

Fixes #734.
2020-01-17 22:34:26 +01:00
Andreas Kling
0adbacf59e Kernel: Demangle userspace ELF symbols in backtraces
Turns out we can use abi::__cxa_demangle() for this, and all we need to
provide is sprintf(), realloc() and free(), so this patch exposes them.

We now have fully demangled C++ backtraces :^)
2019-11-27 14:06:24 +01:00
Andreas Kling
9a157b5e81 Revert "Kernel: Move Kernel mapping to 0xc0000000"
This reverts commit bd33c66273.

This broke the network card drivers, since they depended on kmalloc
addresses being identity-mapped.
2019-11-23 17:27:09 +01:00
Jesse Buhagiar
bd33c66273 Kernel: Move Kernel mapping to 0xc0000000
The kernel is now no longer identity mapped to the bottom 8MiB of
memory, and is now mapped at the higher address of `0xc0000000`.

The lower ~1MiB of memory (from GRUB's mmap), however is still
identity mapped to provide an easy way for the kernel to get
physical pages for things such as DMA etc. These could later be
mapped to the higher address too, as I'm not too sure how to
go about doing this elegantly without a lot of address subtractions.
2019-11-22 16:23:23 +01:00
Andreas Kling
19398cd7d5 Kernel: Reorganize memory layout a bit
Move the kernel image to the 1 MB physical mark. This prevents it from
colliding with stuff like the VGA memory. This was causing us to end
up with the BIOS screen contents sneaking into kernel memory sometimes.

This patch also bumps the kmalloc heap size from 1 MB to 3 MB. It's not
the perfect permanent solution (obviously) but it should get the OOM
monkey off our backs for a while.
2019-11-04 12:04:35 +01:00
Andreas Kling
1c692e87a6 Kernel: Move kmalloc() into a Kernel/Heap/ directory 2019-09-16 09:01:44 +02:00