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

Cleanup code and remove unsupported dependencies #31

Merged
merged 9 commits into from
Mar 2, 2020

Conversation

josephlr
Copy link
Contributor

For more information see each commit. I'm rebasing all my other changes (#24 #26) on top of this.

The spin crate is unsupported and cpuio hasn't been updated in 4 years. There are better crates for our use cases.

For x86 primitives, we can use x86_64. This crate provides structures and functions for Control Registers, Paging Structures, and miscellaneous instructions. This means we can now have much cleaner Rust code for paging, setting up the XMM registers, Port IO, halting, etc...

For replacing the spin crate, we use the atomic_refcell crate. Spin locks have issues, and we don't actually need them here. We just need to check that we aren't violating the borrowing rules. It's fine for us to panic if we are violating them (as it indicates a bug).

This PR puts certain global resources inside an AtomicRefCell, namely:

  • The EFI allocator
  • The Serial Port
  • The Ports used for Reading the PCI configuration space
  • The Global Page Tables

Copy link
Member

@rbradford rbradford left a comment

Choose a reason for hiding this comment

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

With the exception of my concerns over deleting the rust-toolchain file very happy with this PR. Thanks.

rust-toolchain Show resolved Hide resolved
@rbradford rbradford changed the title Cleanup code and remove unsupported dependancies Cleanup code and remove unsupported dependencies Feb 29, 2020
josephlr added 9 commits March 1, 2020 15:09
I confirmed that this toolchain has all the necessary components.
See: https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu.html

Signed-off-by: Joe Richey <joerichey@google.com>
Make sure that we consistently use the tree import syntax.

Also, consistently order code like:

- Global attributes/comments
- `use` from `core`
- `use` from external crates
- `mod` declarations (if applicable)
- `use` from current crate
- Rest of code

This makes the code easier to read/edit.

Signed-off-by: Joe Richey <joerichey@google.com>
- The `spin` crate is unmaintained
  - Replace it with `atomic_refcell`
  - We don't need spin locks, just a checked refcount
- Use `x86_64` instead of `cpuio`
  - It has better abstractions
  - It has more functionality that we can user later
- Fixup existing port usage

Signed-off-by: Joe Richey <joerichey@google.com>
Signed-off-by: Joe Richey <joerichey@google.com>
Now that we are using the x86_64 crate, we don't need ASM to set the
flags on the CR0 and CR4 registers. This also makes the code much more
readable.

Signed-off-by: Joe Richey <joerichey@google.com>
Like PortIO the page tables are a fundamentally global structure. By
moving the paging logic to a separate file, the requirement for
exclusive access is now correctly modeled with Rust types.

Signed-off-by: Joe Richey <joerichey@google.com>
This allows for less complex linking and less `unsafe` code. It also
frees up Rust to place the page tables wherever it wants.

Signed-off-by: Joe Richey <joerichey@google.com>
Adding a bss section reduces binary size by ~30%. We also only use a
single Program Header. This better reflects the fact that the entire
firmware is loaded as a single Read/Write/Execute blob.

Right now, the hypervisor's loader does not read PHDR types:
    https://github.com/rust-vmm/linux-loader/blob/e5c6d66d3121421672c9b25b02e8954f0ed5f58d/src/loader/mod.rs#L248-L274

Signed-off-by: Joe Richey <joerichey@google.com>
This makes the directory/module structure more consistent.
It also avoids cluttering `main.rs`.

Signed-off-by: Joe Richey <joerichey@google.com>
@rbradford rbradford merged commit efd9748 into cloud-hypervisor:master Mar 2, 2020
@josephlr josephlr deleted the cleanup branch March 2, 2020 19:18
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.

2 participants