aboutsummaryrefslogtreecommitdiff
path: root/pk/mmap.c
AgeCommit message (Collapse)AuthorFilesLines
2023-05-01pk: fix __do_brk when new addr is not feasible (#295)xukl1-7/+2
Linux kernel simply return current brk when request brk addr is not feasible. The pk should probably do the same.
2022-01-28pk: thwart an attempt from the compiler to optimizeSaleem Abdulrasool1-1/+2
The memory manager maintains the first free page as the page after the `_end` synthetic emitted by the linker. This value is stored in a translation unit local variable. This value is only ever written to from `init_early_alloc` which is static and only ever invoked from `pk_vm_init`. Furthermore, the value that `first_free_page` is ever set to is computed as a rounding of the _address_ of `_end`. Because the address of the symbol cannot change during execution of a normal program, this is effectively a constant, making the computed value a "constant" which can be re-materialized. Now, with the knowledge that the value is effectively a constant that can be re-materialized and the fact that the value is ever written to at a single position, we can simply re-materialize the value if it was ever changed in `free_page_addr`. This will allow the 8-byte value to be truncated to 1-byte. Now, we can inline `__early_pgalloc_align`, and because the combination of `__early_alloc` and `__early_pgalloc_align` is small, we can inline that again at the two sites locally. This changes the `__augment_page_freelist` to re-materialize the constant when needed for the allocation. The re-materialization however uses a pc-relative addressing, which now computes a different value than expected - the address has become a VA rather than a PA. This results in the address computed by `free_page_addr` (which is the result of the `__early_pgalloc_align`) to be a virtual address after the relocation, which then propagates through `__early_alloc` to the value in `__augment_page_freelist`, which is then consumed by `__page_alloc`, which will treat the now VA as a PA and perform an additional translation to a VA. Mark the value as `volatile` to indicate that the value must be read at all points to thwart the size optimization of the compiler resulting in a mis-compilation resulting in the eventual invalid memory access during the `memset` that follows the allocation. Thanks to @nzmichaelh for the help in tracking this down!
2021-05-18Add __early_pgalloc_align; refactor __early_alloc to use itAndrew Waterman1-3/+11
2021-05-18Fix range checkAndrew Waterman1-2/+3
2021-05-05replace `spbtr` with `satp` (#241)Saleem Abdulrasool1-1/+1
The LLVM IAS currently does not support the older spelling for the CSR. Update the references to the modern name.
2021-03-29pk: vm cleanups; use narrower TLB flushesAndrew Waterman1-9/+15
2021-03-29M-mode code doesn't need access to pk's page tableAndrew Waterman1-0/+2
2021-03-25pk: refactor vm free list managementAndrew Waterman1-58/+100
2021-03-25pk: support >2 GiB of user memory for RV64Andrew Waterman1-14/+21
Previously, the pk would always run from virtual address MEM_START. Instead, remap it into the negative virtual addresses, allowing user processes to expand beyond MEM_START.
2021-03-25pk: avoid assertion failures on brk syscallsAndrew Waterman1-3/+5
Return the old brk if mmap fails, rather than just asserting out
2021-03-25pk: avoid out-of-memory errorsAndrew Waterman1-50/+106
Estimate available memory and return -1 from mmap if not enough is available, rather than assert-failing.
2021-03-25pk: remove linear VA mapping constraintAndrew Waterman1-46/+83
This will improve flexibility going forward.
2021-03-25pk: only access user memory through explicit accessorsAndrew Waterman1-1/+2
Enforced with sstatus.SUM.
2020-11-23use MEM_START, not DRAM_BASE, for pk mappingsAndrew Waterman1-2/+2
2018-07-09Properly license all nontrivial filesAndrew Waterman1-0/+2
2017-12-12Bump encoding.hAndrew Waterman1-1/+1
2017-10-19Order __page_alloc before writing vmrsAndrew Waterman1-2/+6
2017-04-18Increase PK stack size to 3% of memory, up to 8 MiBAndrew Waterman1-1/+1
2017-02-22Fix PK bootAndrew Waterman1-3/+6
2017-02-20Don't block for acks on console writesAndrew Waterman1-6/+6
2016-12-06avoid non-standard predefined macrosAndrew Waterman1-1/+1
2016-11-13Cap pk memory size to 2 GiB for RV32Andrew Waterman1-0/+5
2016-11-02Acquire write permissions before zeroing page in ELF loaderAndrew Waterman1-1/+2
f81b722bf004177eadaf6f1b4b9e699e20257521 is a regression. If a read-only segment does not begin on a page boundary, it would cause the ELF loader to blow up.
2016-09-09Add -p flag to pk to disable demand pagingAndrew Waterman1-2/+2
2016-07-06Udpate to new PTE formatAndrew Waterman1-27/+11
2016-04-30Move DRAM to high addressesAndrew Waterman1-22/+17
2016-03-09Refactor pk, bbl, machine into separate librariesAndrew Waterman1-0/+426
Yuck.