microsoft/openvmm
Publicmirrored fromhttps://github.com/microsoft/openvmmAvailable
.github/copilot-instructions.md
116lines · modecode
| 1 | # OpenVMM Repository |
| 2 | |
| 3 | ## Project Overview |
| 4 | OpenVMM is a modular, cross-platform Virtual Machine Monitor (VMM) written in Rust. This repository is home to both OpenVMM and OpenHCL (a paravisor). The project focuses on creating secure, high-performance virtualization infrastructure. |
| 5 | |
| 6 | ## Technology Stack |
| 7 | - **Language**: Rust (using Cargo build system) |
| 8 | - **Build Tool**: Cargo with custom xtask automation |
| 9 | - **Package Management**: Cargo + custom flowey pipeline tools |
| 10 | - **Testing Framework**: Rust unit tests + cargo-nextest (recommended) |
| 11 | - **Documentation**: mdBook (in `Guide/` folder) |
| 12 | |
| 13 | ## Project Structure |
| 14 | - `openvmm/` - Core OpenVMM VMM implementation |
| 15 | - `openhcl/` - OpenHCL paravisor implementation |
| 16 | - `vmm_tests/` - Integration tests using the petri framework |
| 17 | - `support/` - Shared support libraries and utilities |
| 18 | - `vm/` - VM components (devices, chipset, etc.) |
| 19 | - `Guide/` - Documentation source (published at https://openvmm.dev) |
| 20 | - `xtask/` - Custom build and automation tasks |
| 21 | - `flowey/` - Pipeline and build automation framework |
| 22 | |
| 23 | ## Build Commands |
| 24 | |
| 25 | ### Initial Setup |
| 26 | Before building for the first time, restore required dependencies: |
| 27 | ```bash |
| 28 | cargo xflowey restore-packages |
| 29 | ``` |
| 30 | |
| 31 | ### Building |
| 32 | Build the project using standard Cargo: |
| 33 | ```bash |
| 34 | cargo build |
| 35 | ``` |
| 36 | |
| 37 | For release builds: |
| 38 | ```bash |
| 39 | cargo build --release |
| 40 | ``` |
| 41 | |
| 42 | ### Cross-compilation |
| 43 | The project supports cross-compilation for `x86_64` and `aarch64` architectures. Note: |
| 44 | - Some components (like OpenHCL) can only be built from Linux (WSL2 counts as Linux) |
| 45 | - For cross-compilation from WSL2 to Windows, see `Guide/src/dev_guide/getting_started/cross_compile.md` and source `. ./build_support/setup_windows_cross.sh` |
| 46 | |
| 47 | ## Testing |
| 48 | |
| 49 | ### Unit Tests |
| 50 | Use cargo-nextest (recommended) or cargo test: |
| 51 | ```bash |
| 52 | # Recommended - install with: cargo install cargo-nextest --locked |
| 53 | # Run tests in specific packages you are modifying (default won't run anything) |
| 54 | cargo nextest run -p <package-name> |
| 55 | |
| 56 | # Or use standard cargo test |
| 57 | cargo test -p <package-name> |
| 58 | ``` |
| 59 | |
| 60 | Configure test runs using `.config/nextest.toml` for resource management and timeouts. |
| 61 | |
| 62 | ### Test Types |
| 63 | - **Unit tests**: Spread throughout crates, marked by `#[cfg(test)]` blocks |
| 64 | - **VMM tests**: Integration tests in `vmm_tests/` using the petri framework for Hyper-V and OpenVMM VMs (requires additional setup) |
| 65 | - **Fuzz tests**: Nondeterministic tests ensuring no panics across trust boundaries |
| 66 | |
| 67 | ## Linting and Formatting |
| 68 | |
| 69 | ### Required Before Each Commit |
| 70 | Always run formatting and documentation checks before committing: |
| 71 | ```bash |
| 72 | cargo xtask fmt --fix |
| 73 | cargo doc |
| 74 | ``` |
| 75 | |
| 76 | This ensures: |
| 77 | - All source code follows rustfmt standards |
| 78 | - Generated pipeline files maintain consistent style |
| 79 | - Code follows project-specific "house rules" (copyright headers, naming conventions, etc.) |
| 80 | - No errors in rustdoc comments |
| 81 | |
| 82 | ### Available Checks |
| 83 | Run specific formatting passes: |
| 84 | ```bash |
| 85 | cargo xtask fmt --help # See all available passes |
| 86 | cargo xtask fmt --pass rustfmt |
| 87 | cargo xtask fmt --pass house-rules |
| 88 | ``` |
| 89 | |
| 90 | ## Code Standards |
| 91 | |
| 92 | ### Key Guidelines |
| 93 | 1. Follow Rust best practices and idiomatic patterns |
| 94 | 2. Maintain existing code structure and organization |
| 95 | 3. Write unit tests for new functionality |
| 96 | 4. Document public APIs and complex logic |
| 97 | 5. Update documentation in `Guide/` folder when adding features or changing behavior |
| 98 | |
| 99 | ### Domain-specific Guidelines |
| 100 | Both OpenVMM and OpenHCL process data from untrusted sources. OpenHCL runs in a constrained environment. |
| 101 | |
| 102 | **Trust Boundaries** (critical for security): |
| 103 | - **OpenVMM does not trust the VTL0 guest** - code must not panic on any guest input |
| 104 | - **OpenHCL does not trust the root** - code must not panic on any root input |
| 105 | - **OpenHCL does not trust the VTL0 guest** - less critical than OpenVMM, but the attack surface is subtle and needs human review |
| 106 | |
| 107 | When possible: |
| 108 | 1. Avoid `unsafe` code |
| 109 | 2. Avoid taking new external dependencies, especially those that significantly increase binary size |
| 110 | 3. Ensure code doesn't panic across trust boundaries |
| 111 | |
| 112 | ## Testing Best Practices |
| 113 | - Thoroughly test code with unit tests whenever possible |
| 114 | - Add VMM test cases for interesting integration points |
| 115 | - Unit tests should be fast, isolated, and not require root/administrator access |
| 116 | - Mark tests requiring special setup with `#[ignore]` for manual testing |
| 117 | |