运行前需自备 OpenSBI+U-Boot 固件(如 fw_payload.bin)和 guest 镜像,README 未随附;默认内存仅 256M、单核,需用 -m、-smp 显式调整;rvvm 与 rvvm-user 二进制是 GPL 3.0,嵌入商用项目应改用 MPL 2.0 的 librvvm。
git clone https://github.com/LekKit/RVVM
cd RVVM
make
cd release.linux.x86_64
./rvvm_x86_64 -hREADME 未说明显存或 GPU 型号要求;支持 VFIO PCIe 直通(如 GPU),CPU 后端覆盖 x86_64、ARM64、RISC-V。
用 C 写的 RISC-V 虚拟机与模拟器,靠 Tracing JIT 跑得比 QEMU TCG 快,还能当库嵌进项目
用 C 写的 RISC-V 虚拟机,带 JIT 指令译码,能在普通电脑上跑 RISC-V Linux 和裸机程序,适合做指令集模拟和系统开发调试。
核心能力
- Tracing JIT 带 x86_64、ARM64、RISC-V 后端
- 完整 rv64imafdcb 指令集并支持 Zkr、Zicbom 等扩展
- 提供 NVMe 存储、TRIM 与多线程 IO
- 内置用户态网络栈,任意宿主系统可用
- librvvm 库 API 可嵌入并自定义设备
容易踩的坑
- v0.6RVVM v0.6最新正式版2024-03-18 · 2024-03-18 16:39 UTC
NOTE: RVVM nightly builds should be preferred, this release is for historical reference.
Please see https://github.com/LekKit/RVVM/wiki/Running
New features
- Networking is now stable and enabled by default
- Allow port forwarding to the guest with
-portfwd 127.0.0.1:8080=80 - Support relative mouse movement, grabbing the host mouse
- Support international keyboard layouts (I.e. keys specific to Japanese, Korean, German etc keyboards)
- Optional SDL2 GUI backend
- Support Big-endian hosts (MIPS64, PowerPC64) properly
- SiFive GPIO support
- MTD physmap firmware chip
- Dallas DS1742 Real-time clock
- Support (multiple) PTY or UNIX sockets as UART character device with
-serial [file], silent UART with-serial null; - Support explicitly choosing NVMe or ATA with
-ata [img]or-nvme [img] - Support using host block devices (/dev/sda, /dev/mmcblk) as RVVM drives
- Faster threaded IO implementation
- Faster UART console (Especially on Windows, Serenity)
- Optimized Win32 display rendering
- Slightly better RVJIT x86 register allocation
- RVJIT significantly optimizes memory accesses with userland CPU emulation (To the point of near-native perf of user emulation)
- Rework CMake build system to build shared
librvvmproperly - Colorful logger
- Libretro port
- [WIP] Began work on a Linux userspace binary emulator. Many riscv64 glibc binaries work, but threading and JIT caches are flaky.
RVVM API Improvements:
- Character device API
- GPIO API
- Provide a separate
mappingproperty for direct MMIO regions - Omit PC increment for traps in Userland API
- Support non-canonical framebuffer stride
- Return rvvm_mmio_handle_t upon attaching most de-attachable MMIO devices
- Implement RVVM_OPT_MEM_BASE, RVVM_OPT_MEM_SIZE to query RAM configuration of the machine.
- Implement RVVM_OPT_HART_COUNT to query amount of cores
- Java JNI bindings
Fixes, compatibility
- Fix crashes when explicitly unloading librvvm shared library (#97)
- Fix NVMe deadlock reporting when host IO is slow (#99)
- More bullerproof RVJIT cache allocation (#98)
- Implement RT8169 93C56 EEPROM to fix FreeBSD & Haiku OS networking (#118)
- Fix rare keypress loss (#126)
- Fix pending PLIC interrupts not being re-delivered upon writes to prio/enable/threshold
- Fix 0-byte UDP payloads with tap_user backend
- Fix TCP connection tuple lookup
- Improve TCP stability immensely with tap_user backend
- Fix networking on NetBSD
- Implement proper FMA emulation without dual rounding in FPU, advertise FENV_ACCESS
- Fix endianness issues in FPU
- Fix several VMA operations on Win32 hosts
- Support both UTF8 and system locale paths on Win32 hosts
- Use pthread_cond_timedwait_relative_np() on MacOS to fix possible hang upon wall clock change
- Fix MMIO op size validation
- Fix PCI attach failure handling with all the devices
- Fix non-working I2C ocores with FreeBSD guest
- Advertise zicsr, zifencei extensions in CPU DT
- Fix KSM & THP erroneously not being enabled
- Use .dylib extension for MacOS shared lib target
- Fix OpenBSD CMake build due to type naming collisions
- Fix CMake build on arches without a JIT backend
- Fix Serenity build warnings due to macro naming collisions
- Myriad of small fixes
New Contributors
- @mishrasamiksha made their first contribution in https://github.com/LekKit/RVVM/pull/111
- @singodiyashubham87 made their first contribution in https://github.com/LekKit/RVVM/pull/116
- @fish4terrisa-MSDSM made their first contribution in https://github.com/LekKit/RVVM/pull/120
- @OscarL made their first contribution in https://github.com/LekKit/RVVM/pull/129
Full Changelog: https://github.com/LekKit/RVVM/compare/v0.5...v0.6
- v0.5RVVM v0.52023-04-21 · 2023-04-21 12:42 UTC
查看更新说明
This release includes
- Prebuilt
rvvm-cliv0.5 for Linux x86_64/ARM64, Windows x86_64, MacOS x86_64 - More builds will be added later or should build from source
- Prebuilt OpenSBI 1.2
fw_jump.binfor use in the guest - Prebuilt U-Boot 2023.4
u-boot.binkernel,fw_payload.binfirmware; With NVMe & EFIFB support patches - See LekKit/patches-misc for firmware/kernel configs and more
Major features
- RVJIT Von Neumann instruction cache (ifence stalls elimination)
- RVJIT Linker (Direct linkage of translated functions, improves perf)
- NVMe storage devices, TRIM on raw sparse images
- OpenCores I2C, I2C-HID input devices, cursor integration
- Realtek RTL8169 NIC, WIP userspace networking (Build with USE_NET=1)
- ELF Firmware/Kernel loading
RVVM API Improvements:
- Automatic IRQ/Bus/MMIO assignment
- Machine options (CPU limits, etc)
- Framebuffer, HID, Reboot/poweroff APIs
Fixes, compatibility
- MMIO/PCIe Atomics
- ACLINT MSWI, working SMP in U-Boot
- PLIC fixes concerning FreeBSD/OpenBSD guests stability
- Support HaikuOS guests
- WFI fixes for full riscv-tests conformance
- Support UART VT on Windows 10
- Support HaikuOS, SerenityOS hosts
- Support Emscripten
- Support Windows CE
- Better thread/timer implementations on Windows
- Improve idle CPU usage and sleep precision
- Fix vulnerabilities & lockups exposed by LLVM Fuzzer
- Fix issues uncovered by ASAN/UBSAN/TSAN
- Fix MacOS IO issues (#81)
- Fix rare stuttering due to hashmap scaling logic
- Fix rare threadpool lockups
- Myriad of tiny fixes...
New Contributors
- @mjunix made their first contribution in https://github.com/LekKit/RVVM/pull/62
- @X547 made their first contribution in https://github.com/LekKit/RVVM/pull/64
- @kvxmmu made their first contribution in https://github.com/LekKit/RVVM/pull/72
- @iyzsong made their first contribution in https://github.com/LekKit/RVVM/pull/88
Full Changelog: https://github.com/LekKit/RVVM/compare/v0.4...v0.5
- Prebuilt
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
RVVM - The RISC-V Virtual Machine
RVVM is a virtual machine / emulator for RISC-V guests, which emphasizes on performance, security, lean code and portability. It already runs a lot of guest operating systems, including Linux, Haiku, FreeBSD, OpenBSD, etc. It also aims to run RISC-V applications on a foreign-arch host without full OS guest & isolation (Userland emulation).
Main features
- Fully spec-compliant rv64imafdcb instruction set, Zkr/Zicbom/Zicboz/Sstc extensions
- Tracing JIT with x86_64, ARM64, RISC-V backends - Faster than QEMU TCG
- Working OpenSBI & U-Boot, Linux, FreeBSD, OpenBSD, Haiku guests
- Framebuffer display, HID mouse & keyboard, UART terminal
- NVMe storage drives, TRIM support (Deallocate space on host), fast multi-threaded IO
- Networking userland stack (Works on any host OS)
- VFIO PCIe passthrough (For GPUs, etc)
- Kernel-level isolation to prevent and contain vulnerability exploitation
- Library API (librvvm) for machine/userland emulation, implementing new devices
- Userland emulation (WIP)
- Shadow pagetable acceleration (WIP)
- See wiki page for full list of features
📦 Installing
🛠 Building
Currently builds using GNU Make (recommended) or CMake and is extremely portable.
git clone https://github.com/LekKit/RVVM
cd RVVM
make
cd release.linux.x86_64
./rvvm_x86_64 -h
Alternatively, you can use CMake:
git clone https://github.com/LekKit/RVVM
cd RVVM
cmake -S. -Bbuild
cmake --build build --target all
cd build
./rvvm -h
See the wiki page for advanced build manual like cross-compilation.
🚀 Running
Example: Launches a dual-core VM with 2 GiB of RAM, 1280x720 display.
Runs OpenSBI + U-Boot firmware, EFI guest from drive.img. Forwards host 127.0.0.1:2022 into guest SSH port.
rvvm fw_payload.bin -i drive.img -m 2G -smp 2 -res 1280x720 -portfwd tcp/127.0.0.1:2022=22
Argument explanation:
[fw_payload.bin] Initial M-mode firmware, OpenSBI + U-Boot in this case
-i drive.img Attach preferred storage image (Currently as NVMe)
-m 2G Memory amount (may be suffixed by k/M/G), default 256M
-smp 2 Amount of cores, single-core machine by default
-res 1280x720 Set display(s) resolution
-portfwd 8080=80 Port forwarding (Extended: tcp/127.0.0.1:8080=80)
. . .
-rv32 Enable 32-bit RISC-V, 64-bit by default
-v Verbose mode
-h Extended help
See wiki page for recommended guest firmware/images and full argument explanation.
⚖️ License
The librvvm library is licensed under non-viral MPL 2.0 license.
If you wish to use librvvm as a component of a larger, non-GPL compliant project (permissive, etc), you are free to do so in any form (Static linkage, binary distribution, modules) as long as you comply with the MPL 2.0 license. MPL 2.0 licensing applies to Java JNI bindings as well.
The RVVM Manager and Linux userland emulator (rvvm and rvvm-user) binaries are licensed under the copyleft GPL 3.0 license, since they are intended for end-users. All the heavy lifting is done by librvvm anyways.
🎉 Contributions
| Achievements | Working on | |
|---|---|---|
| LekKit | RVVM API & infrastructure RV64IMAFDC interpreter, MMU/IRQs/Priv/etc RVJIT Compiler, X86/RISC-V backends NVMe, RTL8169, VFIO, many tiny devices Userspace networking | Networking, Userspace emulation COW blk-dedup image format New CPU features & JIT optimizations |
| cerg2010cerg2010 | Important fixes, RV64 groundwork, FPU Initial PLIC & PCI, PS2 HID, ATA, OC Ethernet ARM/ARM64 RVJIT backends | Testing, Assistance |
| Mr0maks | Initial C/M/Zicsr extensions, initial UART, VM debugger ARM32 mul/div JIT intrinsics | - |
| 0xCatPKG | Userspace network & API improvements Extended testing & portability fixes Wayland support | HD Audio |
| X547 | Haiku GUI, I2C HID, Userland API assistance | Guest Haiku support, UserlandVM |
| iyzsong | OpenBSD & PLIC fixes, Chardev API | |
| nebulka1 | Relative input mode |
☕️ Support the project
If you'd like to support the project, thank you, here's what you can do:
- Report any encountered issue you may find (Beware to check on staging branch)
- Contribute features listed in issues or TODO
- Give access to, or donate a useful piece of hardware for development (Milk-V Megrez would be very helpful for KVM) - contact at
@lekkit:matrix.org - Monero:
43LXDwciXLhK26tKCKKdqWTSjHusuEGHK7y6s6BWLVKLGtZhgaN4NLLDbQEdvoGdVseq9P6icsiAbab5dGgo1XdCRr6etfS - Bitcoin:
bc1qg02hthvfnrmsz2xd2lrgfgkwcvnt2509ynj4mh
🔍 TODO
- Implement Svpbmt, Svnapot extensions
- Sparse block image format with compression/deduplication [WIP]
- Suspend/resume to file, VM migration
- Linux userspace binary emulation [WIP]
- USB3.0 XHCI, USB passthrough [WIP]
- Sound (HD Audio or else) [WIP]
- More RVJIT optimizations, shared caches
- FPU JIT (Complicated AF to make a conformant one)
- Vector extensions
- Other peripherals from real boards (VisionFive 2: GPIO, SPI, flash...)
- Virtio devices (For better QEMU interoperability; VirGL via Virtio-GPU)
- Free page reporting via virtio-balloon
- A lot more...
- KVM hypervisor? Alternative CPU engines?
The RISC-V trade name is a registered trade mark of RISC-V International.