101 Star 294 Fork 98

泰晓科技/RISCV-Linux

【老师提案】 RISC-V 虚拟化技术调研与分析

已完成
成员
创建于  
2022-06-25 23:30

评论 (41)

walimis 创建了任务 3年前
walimis 负责人设置为walimis 3年前
walimis 修改了描述 3年前
walimis 修改了标题 3年前
falcon 修改了描述 3年前
walimis 修改了描述 3年前
walimis 修改了描述 3年前
walimis 修改了描述 3年前
falcon 修改了标题 3年前
walimis 修改了描述 3年前
walimis 修改了描述 3年前
walimis 修改了描述 3年前
walimis 修改了描述 3年前
walimis 修改了描述 3年前
展开全部操作日志

考核任务,写一份中文指南:

  1. 参考文档:https://github.com/kvm-riscv/howto/wiki
  2. 基于ubuntu 20.04平台,使用最新qemu/spike/kvmtools/linux代码,附上对应的commit
  3. 运行qemu/spike跑起来Host Linux
  4. 加载kvm模块
  5. 运行kvmtools跑起来Guest Linux
  6. 卸载kvm模块(可能需要改代码)

[Daily Update]0705-2022(0706补)

参照wiki boot Host/Guest Linux

  1. 已完成部分(基于WSL2下的Ubuntu20.04发行版)
    • RISCV toolchain, QEMU(commit 409b951ba6621f2f115aebddfb15ce2dd78ec24f), OpenSBI, Linux内核(Linux 5.19-rc5)下载编译
    • 上述流程的文字记录与流程撰写
  2. 正在进行部分
    • kvmtools编译,make lkvm-static出现问题Makefile:357: *** No libfdt found. Please install libfdt-dev package. Stop., 但不论是通过手动编译还是apt下载安装都无法使之检测到libfdt。

[daily update]0706-2022

尝试找出昨天出错的问题,在运行Ubuntu操作系统的机器上进行昨日的步骤。

  • debug: WSL2中运行的发行版不支持虚拟化,昨日No libfdt found.错误或因此导致。
    $ egrep -c '(vmx|svm)' /proc/cpuinfo
    0 
    
  • 尝试解决:在运行Ubuntu的机器上进行实验
    • 进度:代码全部下载完毕,riscv toolchain编译完成
    • 剩余任务
      • 其余编译、运行流程(spike/qemu+kvm run host/guest linux)
      • kvm kernel module uninstall
Bin Meng-lbmeng Bin Meng 成员
回复 XiakaiPan 成员
3年前

WSL2 支持不支持嵌套虚拟化跟 RISC-V 都没有关系。RISC-V 的虚拟化是跑在 QEMU 模拟的带有 H-extension 的硬件上的。

[daily update]0707-2022

  • 进度
    • 成功在Ubuntu20.04 container上用QEMU+KVM boot Host/Guest Linux
    • 修改linux/arch/riscv/kvm/main.c代码支持在虚拟机内以rmmod kvm指令卸载kvm module
  • 当日工作
    • 尝试在WSL2和Ubuntu本机进行整个流程
      • 通过apt install gcc-riscv64-linux-gnu解决了libfdt无法用于kvmtool编译的问题(后续qemu x-h=true问题解决,应该可以正常运行,还未尝试)
      • 在Ubuntu本机环境检验了apt install gcc-riscv64-linux-gnu安装工具链的可用性。推测或许因为桌面环境以及已有配置较为复杂,apt安装和本地编译并不能完全支持后续步骤:
        • 仅使用apt install gcc-riscv64-linux-gnu安装的工具链缺乏ld,无法链接程序
        • 手动编译的riscv64-unknown-linux-gnu-gcc足够齐全,但是头文件配置出现问题(busybox build rootFS step)
    • 成功在docker中创建Ubuntu20.04 container完成所有流程(组件准备、qemu运行(载入、卸载))
  • TODO:文档整理
5069540 wuzhangjin 1594531572 falcon 拥有者
回复 XiakaiPan 成员
3年前

ld 在 binutils 中,可以试试:apt install binutils-riscv64-linux-gnu

5069540 wuzhangjin 1594531572 falcon 拥有者
回复 falcon 拥有者
3年前

Linux Lab 中已经完整支持所有的工具链的,也是一种候选的方式,一开始就是推荐搭建统一使用这个环境,对齐后续实验的环境。Ubuntu 20.04 + Qemu v6.2.0 + RISC-V toolchains + Linux Kernel 源码 + riscv64/virt 虚拟开发板,全部是一应俱全的。Linux Lab Disk 则连安装都不需要,直接可用。

walimis-walimis walimis 成员
回复 falcon 拥有者
3年前

好的,后续可以让xiakai再使用linux Lab来做一下。

walimis-walimis walimis 成员
回复 XiakaiPan 成员
3年前

如下是我ubuntu上安装的riscv相关的编译软件:
binutils-riscv64-linux-gnu
cpp-9-riscv64-linux-gnu
cpp-riscv64-linux-gnu
gcc-9-riscv64-linux-gnu
gcc-9-riscv64-linux-gnu-base:amd64
gcc-riscv64-linux-gnu
libatomic1-riscv64-cross
libc6-dev-riscv64-cross
libc6-riscv64-cross
libgcc-9-dev-riscv64-cross
libgcc-s1-riscv64-cross
libgomp1-riscv64-cross
linux-libc-dev-riscv64-cross

[daily update]0708-2022(0709 补)

  • 进度
    • docker 环境下完成全部运行任务
    • 产出文档已经提交 RP

[daily update]0711-2022(0712 补)

  • 阅读《QEMU/KVM 源码解析与应用》第一章:QEMU 与 KVM 概述

[daily update]0712-2022

  • 阅读《QEMU/KVM 源码解析与应用》第二、三章
    • QEMU 基本组件:内部运行机制(事件循环、线程模型、CPU 等模型的 OO 的 C 实现)
    • 主板与固件模拟:主板、BIOS 的模拟与初始化
walimis 修改了描述 3年前
walimis 修改了描述 3年前
walimis 修改了描述 3年前
walimis 修改了描述 3年前
walimis 修改了描述 3年前
walimis 修改了描述 3年前
walimis 修改了描述 3年前
walimis 修改了描述 3年前
walimis 修改了描述 3年前

[daily update]0713-2022

  • 阅读《QEMU/KVM 源码解析与应用》第4,5章(至5.4)

[daily update]0714-2022

  • 阅读《QEMU/KVM 源码解析与应用》第 5-8 章(5.4-8.4)
    • KVM 对于内存虚拟化的实现
    • QEMU 终端虚拟化的机制与实现
    • 略读(7,8 章):设备虚拟化、虚拟机迁移、虚拟化安全等

[daily update]0717-2022

  • 阅读riscv-privileged8.1-8.2.1

[daily update]0719-2022(0720 补)

  • 进度:RISC-V 如何进行虚拟化模式切换[Half Done]
    • 整理特权指令级规范中关于虚拟模式切换的论述(特权级对应的虚拟化模式、特殊 CSR、trap 如何触发特权级切换及其具体行为)
    • 阅读如下代码,初步捋清代码内部虚拟化模式切换机制及其对应寄存器(mstatus, hstatus, sstatus),产出原始文档
      • qemu/target/riscv/op_helper.c
      • spike: riscv-isa-sim/riscv/insns/sret.h
      • linux/arch/riscv/kvm/vcpu.c, linux/arch/riscv/kvm/vcpu_switch.S

[daily update]0724-2022

提交分析文章 20220723-virt-mode.md Pull Request.

[daily update]0726-2022

  • 根据审阅意见修改文章 (20220723-virt-mode.md)
  • 阅读《QEMU/KVM 源码解析与应用》及如下网络文章,理清 kvm 整体的虚拟化的架构
  • 澄清了一个个人疑点:虚拟机维护的寄存器数据仅用于保存独立的数据,方便后续恢复运行;各种 CSR 均对应硬件中的寄存器单元(QEMU 等仿真器除外)。虚拟机与硬件的寄存器并不是互相补全的关系,而是数据备份与物理载体的关系。

[daily update]0729-2022

提交 20220729-kvm-hello-world.md

Upload an introduction about Risc-V virtualization plans

5069540 wuzhangjin 1594531572 falcon 拥有者 3年前

[daily update]0812-2022

Update 20220729-kvm-user-app.md with kvmtool and QEMU analysis.

Commit PR.

[daily update]0815-2022

DONE:

  • RISC-V 两级地址转换机制解析
  • SFENCE, HFENCE 指令解析
  • mstatus, hstatus, sstatus, vsstatus 对应关系解析

HALF DONE:

  • status CSR 比较(field 划分及其在两级地址转换中的功能)
  • atp CSR 比较(satphgatp, vsatp对应关系)
S Status H Status INVAL Status CSRs Status
SFENCE DONE HFENCE DONE INVAL... TODO status Ongoing
Basic Page-Based Address Translation TODO 2-Stage Ongoing atp Ongoing
Simulator Implementation TODO Simulator Implementation TODO Simulator Implementation TODO trap TODO
interrupt TODO
exception TODO
time TODO
config/performance/security TODO

[daily update]0816-2022

RISC-V 虚拟化调研

Half Done:Basic Page-Based Address Translation in S-Mode

[daily update]0817-2022

DONE:CSR xstatus
Ongoing: Basic Page-Based Address Translation, 2-Stage AT

[daily update]0822-2022

Reviewed 20220802-kvm-user-app.md.
PR of 20220812-mem-virt-rv-1.md.
Half done 20220812-mem-virt-rv-2.md

Status Address Translation 2-Stage AT
Done Mechanism Flowchart
Ongoing Spike implementation analysis G-Stage

[daily update]0823-2022

Collaboration

Update 20220802-kvm-user-app.md and 20220812-mem-virt-rv-1.md.

Verify the method of inserting URL.

Optimize the commit log of PR.

Virtualization

Ongoing: Implementation of PTW in Spike.

Done: Sinval extension.

5069540 wuzhangjin 1594531572 falcon 拥有者 3年前

这个虚拟化的专栏可以关注一下:https://zhuanlan.zhihu.com/p/565787442

[daily update]0922-2022

Modify last article about memory management.

Finish part of h-extension trap mechanism analysis (basic CSR, instructions).

TODO:

  1. How extra H-extension CSRs provide trap handling functions based on S-Extension.
  2. How Spike accomplish H trap handling.

[daily update]0923-2022

Figure out the function of MIP/MIE, SIP/SIE, HVIP/HIP/HIE and HGEIP/HGEIE.

Analyse how H-Ext. CSR HIP/HIE work with SIP/SIE to finish S-level trap handling.

TODO:

The hardware difference between machines that have H-Support and not. (QEMU)

Simulator implementation of extra hypervisor related trap. (Spike)

[daily update]0925-2022

Done

Figure out the function of hardware, OS (including KVM module), kvmtool and guest OS in the process of 2-stage address translation.

TODO

Figure out the function of hardware, OS (including KVM module), kvmtool and guest OS in the process of trap handling.

  1. Where trap can be brought in, what about the types?
  2. Which mode should the trap be processed (CSR read/write privilege of hypervisor, guest OS)?

[daily update]0927-2022

Done

Modification of last article about Memory Management of H-Mode. Submit PR.

Finish an analysis article of trap handling. Submit PR.

[daily update]0929-2022

Try tinycorrect to auto review articles, find out several shortcuts:

  1. Maybe some environment configuration tutorial should be provided, especially for beginner whose experience is almost not related to Web, such as nodejs. I met this problem on my Windows machine, I try to use docker, Git bash and WSL to run tinycorrect.sh, but failed because of:
    1. endline format (dos2unix): solved
    2. terminate /bin/bash when execute cd path/to/tico && . tinycorrect.sh: to be solved
  2. Flowchart image generation:
    1. Only links of generated images from flowcharts are inserted into articles, but no images are converted and saved into images/ directory: to be solved.
    2. About the saving place of generated images, I assume it is images/riscv-kvm/mem-virt-2/mermaid-riscv-kvm-mem-virt-2-1.png for article named riscv-kvm-mem-virt-2.md. I think it's necessary to validate the specific partition mechanism: to be solved.

[daily update]1011-2022

Future work plan: KVM Implementation of

  1. G-Stage Address Translation.
  2. Trap Handling between Guests and Hypervisor.
  3. Timer and MMIO management in KVM.

Today update:

  1. Comb through code related to G-Stage memory allocation for VMs.

[daily update]1012-2022

  • Today Update:

Go through the inner function calling situation in KVM.

  • Tomorrow:

Refer to memory allocation implementation of Linux Buddy memory manager.

[daily update]1013-1016

  • Update:
    • Memory deallocation/free in Buddy System
    • G-Stage Page Fault Handling
      • gstage remap process

[daily update]1017-1018

  • Update
    • Finish code analysis of page fault handling in KVM.
  • Next
    • HGATP update logic.

[daily update]1030-2022

  • Done: KVM implementation of memory virtualization in H-Ext.
  • Half Done: KVM implementation of exception handling in H-Ext.
  • Others: analysis towards interrupt handling will be delayed due to many related content about VFIO, VIRTIO, PCI, PLIC, etc., which is out of my current knowledge and needs further study.

[Month Plan] November

RISC-V 中断虚拟化在 KVM 中的实现

  • KVM 对 RISC-V Specification 中有关 Guest 中断判断与处理机制的一般实现(arch/riscv/kvm/)
    • RISC-V Interrupt Definition: include/asm/csr.h
    • WFI: vcpu_insn.c
    • set/unset/has/flush/sync/_interrupt: vcpu.c
  • Timer 虚拟化及其中断处理
    • Guest Timer: vcpu.c, vcpu_timer.c, include/asm/kvm_vcpu_timer.h
    • Kernel Timer: kernel/sbi.c, include/linux/hrtimer.h, etc.
  • 外部中断:MMIO(Memory-Mapped Input/Output)
    • caller: vcpu_exit.c, vcpu.c
    • callee: kvm_riscv_vcpu_mmio_load/store/return in vcpu_insn.c

kvmtool 中断注入

kvmtool/riscv/

  • PLIC: plic.c
  • PCI: pci.c
  • virtio: virtio_console__inject_interrupt in virtio/console.c
  • IRQ: irq.c, include/kvm/irq.h
walimis 修改了描述 3年前

[daily update]1113-2022

Week Update

  • Framework of interrupts handling in KVM and kvmtool has been figured out.
  • The outline of the article is already listed.
walimis 修改了描述 3年前
falcon 负责人walimis 修改为XiakaiPan 3年前
walimis 修改了描述 3年前
5069540 wuzhangjin 1594531572 falcon 拥有者 2年前
XiakaiPan 任务状态进行中 修改为已完成 2年前

登录 后才可以发表评论

状态
负责人
里程碑
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(5)
XiakaiPan-xiakaipan 5069540 wuzhangjin 1594531572 walimis-walimis Bin Meng-lbmeng trueptolemy-trueptolemy
1
https://gitee.com/tinylab/riscv-linux.git
git@gitee.com:tinylab/riscv-linux.git
tinylab
riscv-linux
RISCV-Linux

搜索帮助