Page MenuHomeFreeBSD

RISC-V: exclude reserved memory regions
ClosedPublic

Authored by mhorne on Mar 22 2020, 6:39 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Apr 17, 1:29 AM
Unknown Object (File)
Sun, Mar 24, 12:14 PM
Unknown Object (File)
Feb 29 2024, 6:02 PM
Unknown Object (File)
Feb 17 2024, 8:45 AM
Unknown Object (File)
Dec 27 2023, 5:31 AM
Unknown Object (File)
Dec 20 2023, 3:01 AM
Unknown Object (File)
Nov 22 2023, 7:53 AM
Unknown Object (File)
Nov 21 2023, 5:24 PM
Subscribers

Details

Summary

Currently, there is no mechanism through which the SBI firmware can
communicate the details of its reserved memory region(s) to a supervisor
payload. There has been some discussion recently on how this can be
achieved [1], and it seems that it will happen via the device-tree, a
new set of SBI calls, or some combination of both.

This hasn't caused any issues for us yet, since we exclude all physical
memory below the kernel's load address from being allocated, and on all
currently supported platforms this covers the SBI firmware region.

OpenSBI has begun specifying its section of memory under the
"reserved-memory" device-tree property [2], which we can parse easily.
If this property is present, we know exactly which region of physical
memory the kernel should ignore.

In the case that no "reserved-memory" property is found, exclude the
lowest 2MB of memory from allocation. This isn't a perfect solution, but
it is consistent with how the currently supported platforms are set up,
allowing us to handle this case with BBL or the current release of
OpenSBI.

[1] https://github.com/riscv/riscv-sbi-doc/pull/37
[2] https://lists.infradead.org/pipermail/opensbi/2020-March/001544.html

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 30046
Build 27857: arc lint + arc unit

Event Timeline

Looks good to me. Thanks for this patch Mitchell!

This revision is now accepted and ready to land.Mar 22 2020, 11:42 PM
markj added inline comments.
sys/riscv/riscv/machdep.c
835

I wouldn't omit braces here, since the if and else bodies span multiple lines.

I think we can name reserved regions, looking for a reserved-memory child node for the bootloader may be a good idea. If someone already has reserved-memory but it's for a non-bootloader purpose I think this will break.

In D24155#537632, @nick wrote:

I think we can name reserved regions, looking for a reserved-memory child node for the bootloader may be a good idea. If someone already has reserved-memory but it's for a non-bootloader purpose I think this will break.

This is intended to handle all reserved regions, not just the bootloader. fdt_get_reserved_mem checks each child node for the no-map property, and only the regions that have it are returned. Any region that has this property must be excluded from general allocations, regardless of purpose.

For reference, here is the documentation of the reserved-memory node.

EDIT: Thinking about it again I see what you mean. We could encounter a situation where we have a reserved region, but not one that marks the SBI. I'm not sure handle this exactly. It seems that the region created by OpenSBI is named mmode_pmp0, but I don't know that I want to hard-code that.

Handle the case where a reserved memory region other than the SBI is specified.

This revision now requires review to proceed.Apr 17 2020, 9:29 PM

Move logic above physmem_init_kernel_globals().

@nick if you see any other problems with this let me know. I plan on committing tonight or tomorrow, but can always follow-up if needed.

Tested on QEMU with BBL, OpenSBI v0.6, OpenSBI master.

This revision was not accepted when it landed; it landed in state Needs Review.Apr 19 2020, 12:33 AM
This revision was automatically updated to reflect the committed changes.