Commit ecd7f5e
authored
Memory management overhaul (#50)
* Standardize the capitalization of Devicetree.
Signed-off-by: Amy Ringo <me@remexre.com>
* Move zalloc to the header, so the optimizer can see it.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds logging to generate_bootstub.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds documentation for the new memory-management code.
Signed-off-by: Amy Ringo <me@remexre.com>
* Update generate_bootstub for memory management changes.
Signed-off-by: Amy Ringo <me@remexre.com>
* Enables stack checking.
Signed-off-by: Amy Ringo <me@remexre.com>
* Move the stdckdint.h functions into compiler.h.
Signed-off-by: Amy Ringo <me@remexre.com>
* Use uaddr as the bits type of paddr.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds bounds checking to paddr_offset.
Signed-off-by: Amy Ringo <me@remexre.com>
* Reimplement physical memory access with the new physical memory APIs.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds a bit of entropy early in boot.
Right now, just the cycle time and timestamp for boot. These are
pretty attacker-guessable, but better than nothing.
This will be used to generate XOR cookies to initialize the heap with.
We usually get better entropy from U-Boot once we process the
Devicetree, so the RNG will reseed at that point.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds a revamped Devicetree parser.
This heap-allocates the Devicetree, so we don't need to keep the FDT
structure reserved.
It also includes the memory reservations block in the Devicetree proper,
under the /reserved-memory node.
This still needs to be fully integrated; e.g. by:
- Adding RAM to the allocators.
- Adding /chosen/rng-seed to the entropy pool.
- Creating devices from nodes.
This has been tested and works on the Milk-V Duo S.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds entropy from the Devicetree to the entropy pool.
It gets removed from the Devicetree to reduce the chances that an
attacker could discover it later. This is maybe kinda moot though,
because of how resistant the entropy pool is to attacks based on that.
Signed-off-by: Amy Ringo <me@remexre.com>
* Implements the new, drastically simpler, physical allocator.
Signed-off-by: Amy Ringo <me@remexre.com>
* Marks the kernel as reserved in the Devicetree.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds utility methods for dealing with the reg prop.
Signed-off-by: Amy Ringo <me@remexre.com>
* Finishes initialization of the new physical memory allocator.
Tested in QEMU and the Milk-V Duo S.
Signed-off-by: Amy Ringo <me@remexre.com>
* Implements mm_free_physical.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds random functions for generating u32 and u64.
These are for use in a treap implementation; arguably there should be a
"fast but lower-quality" RNG for this kind of usecase, but we really
don't want people e.g. using it when it would introduce a DoS attack.
Signed-off-by: Amy Ringo <me@remexre.com>
* Data structure definitions for the new virtual allocator.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds vma_alloc_by_addr, uses it to reserve the initial mappings.
Signed-off-by: Amy Ringo <me@remexre.com>
* Moves out treap rotation to a helper.
Signed-off-by: Amy Ringo <me@remexre.com>
* Expose vma_bounds.
The page fault handler, among other things, will need it.
Signed-off-by: Amy Ringo <me@remexre.com>
* Fixes a bug in treap rotation, finishes VMA allocation.
Signed-off-by: Amy Ringo <me@remexre.com>
* More debug printing in main.
Signed-off-by: Amy Ringo <me@remexre.com>
* Implements vma_free.
Signed-off-by: Amy Ringo <me@remexre.com>
* Removes the boothart_heap_segment that wasn't allocated in the bootstub.
Signed-off-by: Amy Ringo <me@remexre.com>
* Fix some allocator problems.
- More consistently XORs linked lists, though this still needs to be done
to the remote list.
- Properly maintains pages_direct.
Signed-off-by: Amy Ringo <me@remexre.com>
* Fix more silly oversights.
Signed-off-by: Amy Ringo <me@remexre.com>
* Makes the kernel virtual allocator a global.
Signed-off-by: Amy Ringo <me@remexre.com>
* Wire up small object allocation.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds is_aligned.
Signed-off-by: Amy Ringo <me@remexre.com>
* Uses is_aligned() where applicable.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds vma_alloc_aligned.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds bzero_physical.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds support for mapping pages.
This currently only supports 4KiB pages with Sv39.
Signed-off-by: Amy Ringo <me@remexre.com>
* Reverses the order mm_alloc_physical hands out pages in.
This results in more readable output from the `info mem` command in
QEMU, since allocations are more often contiguous.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds the ARRAY_SIZE macro.
This is like Linux's, but uses static_assert to give a better compile
error when the given field is not an array.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds support for pointer types to is_aligned.
Signed-off-by: Amy Ringo <me@remexre.com>
* Fixes a crash on OOM.
Signed-off-by: Amy Ringo <me@remexre.com>
* Fixes vma_alloc sometimes not splitting a VMA it should.
Signed-off-by: Amy Ringo <me@remexre.com>
* Splits up the allocator, improving consistency and fixing bugs.
At this point, allocation works but freeing is a no-op.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds mm_paging_unmap.
Signed-off-by: Amy Ringo <me@remexre.com>
* Makes vma_find public.
Signed-off-by: Amy Ringo <me@remexre.com>
* Implements freeing.
Signed-off-by: Amy Ringo <me@remexre.com>
* Implements realloc.
Signed-off-by: Amy Ringo <me@remexre.com>
* Makes the doc-serve Makefile target serve on all IPs.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds a simple note on the implementation of each allocator.
Signed-off-by: Amy Ringo <me@remexre.com>
* Fixes allocator heap corruption bug and assertion failure.
- page_collect shouldn't assume that the page has an empty free list,
but neither should it do O(n) work when it does not.
- After page_free, alloc_generic should not refer to the page anymore.
Signed-off-by: Amy Ringo <me@remexre.com>
* Add bootstub_generated.ld to gitignore and defcleanable.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds comments about zero-size allocs.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds log2_size_of_size_class helper to get rid of a magic number.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds a constant for the sentinel size class value used by huge pages.
Signed-off-by: Amy Ringo <me@remexre.com>
* Use decrement as a statement, not an expression.
Signed-off-by: Amy Ringo <me@remexre.com>
* Get rid of a magic number.
Signed-off-by: Amy Ringo <me@remexre.com>
* Clarify that the VMA allocator stores the VMAs in multiple different data structures.
Signed-off-by: Amy Ringo <me@remexre.com>
* Use assignment as a statement, not an expression.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds some comments to explain clearing needs_delayed_free.
Signed-off-by: Amy Ringo <me@remexre.com>
* Improves the comment about the treap priority being non-zero.
Signed-off-by: Amy Ringo <me@remexre.com>
* Adds mailmap.
Signed-off-by: Amy Ringo <me@remexre.com>
* Gets rid of some magic numbers.
Signed-off-by: Amy Ringo <me@remexre.com>
---------
Signed-off-by: Amy Ringo <me@remexre.com>1 parent f7239a7 commit ecd7f5e
File tree
48 files changed
+3764
-1785
lines changed- doc
- kernel/mm
- src/kernel
- arch/riscv64
- crypto/subtle
- include
- arch/riscv64
- mm
- mm
- alloc
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
48 files changed
+3764
-1785
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
| 20 | + | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
| |||
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | 40 | | |
46 | 41 | | |
47 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | 39 | | |
48 | 40 | | |
49 | 41 | | |
50 | 42 | | |
51 | 43 | | |
| 44 | + | |
52 | 45 | | |
53 | 46 | | |
54 | 47 | | |
| |||
57 | 50 | | |
58 | 51 | | |
59 | 52 | | |
| 53 | + | |
60 | 54 | | |
61 | 55 | | |
62 | 56 | | |
| |||
65 | 59 | | |
66 | 60 | | |
67 | 61 | | |
68 | | - | |
| 62 | + | |
69 | 63 | | |
70 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
71 | 70 | | |
72 | | - | |
73 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
74 | 81 | | |
75 | 82 | | |
76 | 83 | | |
| 84 | + | |
| 85 | + | |
77 | 86 | | |
0 commit comments