git clone --recursive https://github.com/XinlaiWan/Keystone-HE.git
or
git submodule update --init --recursive
after cloning it.
Note:
- If submodules of
keystone-bench
using SSH URLs encounter cloning issues, replace the SSH URLs inkeystone-bench/.gitmodules
with HTTP URLs, deinit all these submodules inkeystone-bench
directory, and try submodule update again. - All the following steps can be stably performed in Ubuntu 22.04.4 LTS system.
- Please check if all the submodules have been really initialized.
- If not, run
git submodule deinit -f <submodule-name>
and trygit submodule update --init --recursive
again.
- If not, run
- Run
sh ./apply_all_patches.sh
.- It will apply patches to
keystone
,xvisor
,musl-riscv-toolchain
, andkeystone-bench
with all its submodules automatically.
- It will apply patches to
- Apply the patch on Keystone (only if not yet).
> cd keystone
> git apply ../patches/keystone.patch
- Follow this section of the Keystone documentation.
- Generally we can type
make -j$(nproc)
to build all Keystone components. - In WSL, we should use
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin make -j$(nproc)
instead to avoid spaces in PATH. - To avoid
wget
issues during buildroot building, we may create~/.wgetrc
for proxy setting:https_proxy = http://<proxy_ip>:<proxy_port>/ http_proxy = http://<proxy_ip>:<proxy_port>/ use_proxy = on
- Note: if encountering the dependency issue between
keystone-examples
andopensbi
, runBUILDROOT_TARGET=keystone-examples-dirclean make -j$(nproc)
andmake -j$(nproc)
again.
- Generally we can type
- In the project root directory, run:
> mkdir rootfs; tar -xf keystone/build-generic64/buildroot.build/images/rootfs.tar -C rootfs
> cd rootfs; find ./ | cpio -o -H newc > ../rootfs.img; cd -; rm -rf rootfs
- Apply the patch on Xvisor (only if not yet).
> cd xvisor
> git apply ../patches/xvisor.patch
- Follow
xvisor/docs/riscv/riscv64-qemu.txt
to build Xvisor VMM and disk image.- Generally we can go through the steps of 2, 3, 4, 5, 13.
- In Step 4 and 5, add
CROSS_COMPILE=riscv64-unknown-linux-gnu-
in front of themake
commands. - In Step 13, use
../rootfs.img
as rootfs image and../keystone/build-generic64/buildroot.build/images/Image
as Linux kernel image. - In Step 13, delete
-B 1024
in the lastgenext2fs
command and replaceb 32768
withb 65536
.
- In the Keystone directory, use
make run
to start the modified Keystone boot flow in QEMU. - In the initialized Xvisor terminal, run:
> vdisk attach guest0/virtio-blk0 vda
Then, run vdisk list
and we should see:
--------------------------------------------------------------------------------
Name Block Size Attached Block Device
--------------------------------------------------------------------------------
guest0/virtio-blk0 512 vda
--------------------------------------------------------------------------------
After that, run:
> guest kick guest0
> vserial bind guest0/uart0
- Next, in the initialized
guest0/uart0
terminal, run:
> linux_memory_size 0x80000000
> linux_cmdline root=/dev/vda ro console=ttyS0 cma=1G nokaslr
> autoexec
- When the Linux booting has been started, follow the rest of 1.2.1.4.1. Launching Keystone in QEMU in the Keystone documentation to run the test enclaves.
> modprobe keystone-driver
> /usr/share/keystone/examples/hello.ke
-
Device trees used in Xvisor:
- Replace
virt64-guest.dts
andvirt64.dts
withvirt64-guest_two_guests.dts
andvirt64_two_guests.dts
. - Do not modify the DTB name in the disk.
- Replace
-
Boot script used in Xvisor:
- Replace
one_guest_virt64.xscript
withtwo_guest_virt64.xscript
.
- Replace
-
Prepare a new Xvisor initrd with the above changes.
-
Run Keystone:
- Use
QEMU_FLAGS_TWO_GUESTS
instead ofQEMU_FLAGS
inkeystone/mkutils/plat/generic/run.mk
- Use
-
In Xvisor:
> vdisk attach guest0/virtio-blk0 vda
> vdisk attach guest1/virtio-blk1 vdb
> guest kick guest0
> guest kick guest1
- Bind terminal:
vserial bind guest0/uart0
or
vserial bind guest1/uart0
and switch between guests by Esc-x-q
- Linux boot
For guest0:
> linux_memory_size 0x80000000
> linux_cmdline root=/dev/vda ro console=ttyS0 nokaslr
> autoexec
For guest1:
> linux_memory_size 0x80000000
> linux_cmdline root=/dev/vdb ro console=ttyS0 nokaslr
> autoexec
- Apply patches (only if not yet).
> cd keystone-bench
> git apply ../patches/keystone-bench.patch
And keystone-bench
also has some submodules:
In beebs
directory:
> git apply ../../patches/beebs.patch
In coremark
directory:
> git apply ../../patches/coremark.patch
In iozone
directory:
> git apply ../../patches/iozone.patch
In rv8-bench
directory:
> git apply ../../patches/rv8-bench.patch
- Refer to
keystone-bench/README.md
(patched version) for details of building the benchmarks. It will:- Build all the subdirectories and copy test binaries and running scripts into
keystone-bench/staging
. - Copy the
staging
directory into Keystone rootfs at/usr/share/keystone/staging
with the help ofqemu-nbd
. - Then we can boot Keystone system as usual and run
./run_all_tests.sh
in it.
- Build all the subdirectories and copy test binaries and running scripts into