Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

risc-v/spike: reserve memory for SBI #365

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

axel-h
Copy link
Member

@axel-h axel-h commented May 17, 2021

No description provided.

@axel-h
Copy link
Member Author

axel-h commented May 17, 2021

@alistair23: I'd appreciate your feedback also about this patch and any additional thoughts on reserving space for SBI.

@alistair23
Copy link
Contributor

alistair23 commented May 18, 2021

OpenSBI will do the same thing automatically at boot: https://github.com/riscv/opensbi/blob/4ef2f5d3e6b25356a8fab19574bed76ce60edeee/lib/utils/fdt/fdt_fixup.c#L156

From what I can tell seL4 kernel doesn't parse the DT at runtime, in which case this change looks good.

@axel-h axel-h force-pushed the patch-axel-2 branch 2 times, most recently from b0c8844 to c30c6c1 Compare May 28, 2021 14:00
@axel-h
Copy link
Member Author

axel-h commented May 30, 2021

Any objections to merge this? Seem without this spike cannot be used. The automated checks for links fails because of #371

@axel-h axel-h requested a review from oliver-wm May 30, 2021 22:51
Copy link
Member

@lsf37 lsf37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kent-mcleod
Copy link
Member

Any objections to merge this? Seem without this spike cannot be used. The automated checks for links fails because of #371

There are parts of the kernel's riscv tooling scripts that already try and insert this reserved region into the memory space after the device tree is passed: https://github.com/seL4/seL4/blob/master/tools/hardware/config.py#L51

I think adding it into the device tree is better, but that means we should remove the assumptions that it isn't there from elsewhere.

@kent-mcleod
Copy link
Member

This would also likely allow this discussion to be resolved: https://github.com/seL4/seL4/pull/363/files#r633223133

@kent-mcleod
Copy link
Member

I think the treatment of avoiding the SBI firmware is also encoded here (https://github.com/seL4/seL4/blob/master/include/arch/riscv/arch/64/mode/hardware.h#L95)

@axel-h axel-h force-pushed the patch-axel-2 branch 2 times, most recently from 0f10bb2 to 8b00044 Compare June 4, 2021 02:22
@axel-h
Copy link
Member Author

axel-h commented Jun 4, 2021

Thanks for the comments, I will rework this PR to address them. However this turns out as not trivial and needs some more time

@axel-h
Copy link
Member Author

axel-h commented Jun 5, 2021

With all the hacks removed, This works now when I pass FW_PAYLOAD_OFFSET=0x04000000 to the OpenSBI build. All that is missing here now is taking the ElfLoder (calculated) base address here instead of hard-coding it.

@axel-h
Copy link
Member Author

axel-h commented Jun 7, 2021

I'm also removing include/plat/spike/plat/instance/rocket-chip/hardware.h. This file should be obsolete by now, as this "instance hack" has been removed already.

@kent-mcleod
Copy link
Member

@ssrg-bamboo proof

@axel-h axel-h force-pushed the patch-axel-2 branch 5 times, most recently from 526b17b to 3475dbf Compare June 10, 2021 22:57
@axel-h
Copy link
Member Author

axel-h commented Jun 10, 2021

Seem we have to apply the DTS overlay in all RISC-V platform now, otherwise thins will not work. I wonder if we should add DTB parsing code to the ELF-Loder to catch some error. As @alistair23 said, OpenSBI modifies the DTB that is passes to the ELF-Loader and carves out the reserved memory. Since we don't do runtime DTB parsing in the kernel ,as least the ELF-Loader could do this and do a consistency check when it copies around the images. We saw a crash there when to tries to move the kernel image to 0x80000000 on the HiFive, because this was missing the DTS overlay patch.

@axel-h axel-h force-pushed the patch-axel-2 branch 2 times, most recently from 439e85c to e9ad617 Compare November 9, 2021 08:50
@axel-h axel-h force-pushed the patch-axel-2 branch 2 times, most recently from 8f7c3bc to 61b6c50 Compare November 21, 2021 09:43
@axel-h axel-h force-pushed the patch-axel-2 branch 4 times, most recently from 18b6005 to 9381db7 Compare January 4, 2022 16:18
@axel-h axel-h force-pushed the patch-axel-2 branch 5 times, most recently from 8d5f1b8 to b110706 Compare January 25, 2022 12:32
@kent-mcleod
Copy link
Member

Can you give an update of what you're attempting here @axel-h? Adding the reserved region to the device tree should be sufficient to ensure that the kernel doesn't use it as untypeds. Is the rest of the changes to try and ensure that the reserved memory isn't also given to user level as device untypeds? This may not be something the kernel needs to restrict. If you do wish that the kernel restrict this, then hardware.yml is already used to select device nodes in the device tree that are not to be given to user level as untypeds. This would avoid having to make all the code changes for adding new types of reserved regions to the kernel boot code.

@axel-h
Copy link
Member Author

axel-h commented Jan 31, 2022

Yes, this is trying to ensure the kernel does not give any untypeds that cover the memory used by the SBI. Rational is, that this memory should be considered unusable practically, so there is not much point making this avaiable. In the long run, a proper RISC-V S-Mode should have ways to lock this downs somehow (PMP ...), so accesses eventually trap anway. But having a generic mechanism in seL4 to carve out memory region to they don't even become device untypeds seem useful to me, too.

@kent-mcleod
Copy link
Member

But having a generic mechanism in seL4 to carve out memory region to they don't even become device untypeds seem useful to me, too.

What is your threat model in this case? Any policy to restrict access to hardware resources that the kernel doesn't use can already be implemented within the existing access control mechanisms. Adding an extra layer of restrictions doesn't enhance the existing mechanisms unless you are assuming that the roottask is compromised.

Instead of special handling for the SBI region in the kernel, which can
be platform specific, treat it as a reserved memory region in the device
tree which is sufficient to prevent the kernel from turning the reserved
region into kernel untyped caps.

Signed-off-by: Kent McLeod <kent@kry10.com>
axel-h and others added 8 commits September 15, 2022 12:00
Signed-off-by: Axel Heider <axelheider@gmx.de>
Since we have Python 3.7 now, the usage of type hints can be improved
further.

Signed-off-by: Axel Heider <axelheider@gmx.de>
Signed-off-by: Axel Heider <axelheider@gmx.de>
- pass a dict
- add type information for parameters

Signed-off-by: Axel Heider <axelheider@gmx.de>
- merge functions to simplify control flow
- clarify variable names
- add comments
- Improve code readability

Signed-off-by: Axel Heider <axelheider@gmx.de>
Config is already part of the hardware YAML object, take it from there.

Signed-off-by: Axel Heider <axelheider@gmx.de>
Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants