Difference between revisions of "R-Car/Virtualization"

From eLinux.org
Jump to: navigation, search
m (fix repo link for arm trusted firmware, old one didn't work for me)
(Reorganize the page in four categories: virtualization with XEN, virtualization with QEMU, managing virtual machines with libvirt and building a custom guest kernel)
Line 10: Line 10:
 
* [https://wiki.xenproject.org/wiki/Xen_ARM_with_Virtualization_Extensions/Lager Xen on Lager board with R-Car H2]
 
* [https://wiki.xenproject.org/wiki/Xen_ARM_with_Virtualization_Extensions/Lager Xen on Lager board with R-Car H2]
  
= Prerequisites =
+
 
 +
= Virtualization with QEMU =
 +
 
 +
== Prerequisites ==
  
 
* [[QEMU]] (e.g. "apt-get install qemu-system-arm"),
 
* [[QEMU]] (e.g. "apt-get install qemu-system-arm"),
 
* A guest image, e.g. "openwrt-arm64-qemu-virt.Image" from [http://archive.openwrt.org/snapshots/trunk/arm64/generic/ OpenWRT].
 
* A guest image, e.g. "openwrt-arm64-qemu-virt.Image" from [http://archive.openwrt.org/snapshots/trunk/arm64/generic/ OpenWRT].
  
 
+
== Running QEMU ==
= Running QEMU =
 
  
 
<pre>
 
<pre>
Line 36: Line 38:
 
</pre>
 
</pre>
  
= Using KVM =
+
== Using KVM ==
  
 
When using an arm64 platform as the host system, guest performance can be improved drastically by making use of the Kernel-based Virtual Machine (KVM).
 
When using an arm64 platform as the host system, guest performance can be improved drastically by making use of the Kernel-based Virtual Machine (KVM).
  
== Host Kernel Configuration ==
+
=== Host Kernel Configuration ===
  
 
Make sure your host kernel has the following options enabled:
 
Make sure your host kernel has the following options enabled:
Line 50: Line 52:
 
"renesas_defconfig" should be fine.
 
"renesas_defconfig" should be fine.
  
 
+
=== Firmware Support ===
== Firmware Support ==
 
  
 
To use KVM, the firmware on your board must start Linux in hypervisor (EL2 / HYP) mode.
 
To use KVM, the firmware on your board must start Linux in hypervisor (EL2 / HYP) mode.
Line 71: Line 72:
 
during bootup, HYP mode is not available, and KVM cannot be used, unless you first replace the firmware of your board with a version that supports HYP mode.
 
during bootup, HYP mode is not available, and KVM cannot be used, unless you first replace the firmware of your board with a version that supports HYP mode.
  
 
+
=== Enabling HYP Support ===
== Enabling HYP Support ==
 
  
 
To build your own ARM Trusted Firmware with hypervisor mode support:
 
To build your own ARM Trusted Firmware with hypervisor mode support:
Line 83: Line 83:
 
Replace the BL2 and BL31 binaries in your firmware package by the generated "build/rcar/release/bl2.srec" and "build/rcar/release/bl31.srec", and follow your normal firmware upgrade procedure.
 
Replace the BL2 and BL31 binaries in your firmware package by the generated "build/rcar/release/bl2.srec" and "build/rcar/release/bl31.srec", and follow your normal firmware upgrade procedure.
  
 
+
=== Running QEMU with KVM ===
== Running QEMU with KVM ==
 
  
 
<pre>
 
<pre>
Line 104: Line 103:
 
'''Note''': The same is true for running with '-cpu cortex-a53', with a53 and a57 exchanged.
 
'''Note''': The same is true for running with '-cpu cortex-a53', with a53 and a57 exchanged.
  
 
+
== Device Pass-Through ==
= Device Pass-Through =
 
  
 
See [[R-Car/Virtualization/VFIO|VFIO]]
 
See [[R-Car/Virtualization/VFIO|VFIO]]
  
  
= Libvirt =
+
= Managing virtual machines with libvirt =
  
 
See [[R-Car/Virtualization/Libvirt|Libvirt]].
 
See [[R-Car/Virtualization/Libvirt|Libvirt]].

Revision as of 13:49, 15 February 2018

Virtualization on Renesas R-Car Platforms

Virtualization with Xen hypervisor

Xen supports R-Car chips out of the box. Example instructions on how to run Xen on R-Car H3/H2 can be found @ XenProject Wiki:


Virtualization with QEMU

Prerequisites

  • QEMU (e.g. "apt-get install qemu-system-arm"),
  • A guest image, e.g. "openwrt-arm64-qemu-virt.Image" from OpenWRT.

Running QEMU

$ qemu-system-aarch64 -m 1024 -cpu cortex-a57 -M virt -nographic -kernel openwrt-arm64-qemu-virt.Image

and press <ENTER> to enjoy your new ARM64 system!

Recent kernels may access ARM64 registers that require a recent version of QEMU. If your kernel crashes with

Code: ........ ........ ........ ........ (d5380740)
Internal error: undefined instruction: 0 [#1] SMP
...
pc : __cpuinfo_store_cpu+0x68/0x1b0

you have to upgrade QEMU, or comment out the following two lines in arch/arm64/kernel/cpuinfo.c:__cpuinfo_store_cpu():

info->reg_id_aa64mmfr2 = read_cpuid(ID_AA64MMFR2_EL1);
info->reg_id_aa64zfr0 = read_cpuid(ID_AA64ZFR0_EL1);

Using KVM

When using an arm64 platform as the host system, guest performance can be improved drastically by making use of the Kernel-based Virtual Machine (KVM).

Host Kernel Configuration

Make sure your host kernel has the following options enabled:

CONFIG_VIRTUALIZATION=y
CONFIG_KVM=y

"renesas_defconfig" should be fine.

Firmware Support

To use KVM, the firmware on your board must start Linux in hypervisor (EL2 / HYP) mode.

If your host kernel prints:

CPU: All CPU(s) started at EL2
...
kvm [1]: Hyp mode initialized successfully

during boot up, everything is fine, and you can skip the next section.

If your host kernel prints:

CPU: All CPU(s) started at EL1
...
kvm [1]: HYP mode not available

during bootup, HYP mode is not available, and KVM cannot be used, unless you first replace the firmware of your board with a version that supports HYP mode.

Enabling HYP Support

To build your own ARM Trusted Firmware with hypervisor mode support:

$ git clone https://github.com/renesas-rcar/arm-trusted-firmware.git
$ cd arm-trusted-firmware
$ make CROSS_COMPILE=aarch64-linux-gnu- PLAT=rcar RCAR_DRAM_SPLIT=3 RCAR_BL33_EXECUTION_EL=1 LSI=H3 # or LSI=M3 

Replace the BL2 and BL31 binaries in your firmware package by the generated "build/rcar/release/bl2.srec" and "build/rcar/release/bl31.srec", and follow your normal firmware upgrade procedure.

Running QEMU with KVM

$ qemu-system-aarch64 -enable-kvm -m 1024 -cpu cortex-a57 -M virt -nographic -kernel openwrt-arm64-qemu-virt.Image

and press <ENTER> to enjoy a faster new ARM64 system!

Note that the above command requires running on a Cortex-A57 CPU core. When running on a Cortex-A53 CPU core in a big.LITTLE configuration, the command will fail with:

kvm_init_vcpu failed: Invalid argument

Just retry, or force your luck by offlining all Cortex-A53 cores first:

for i in $(grep -lr arm,cortex-a53 /sys/bus/cpu/devices/cpu*/of_node/compatible); do
	echo 0 > $(dirname $(dirname $i))/online
done

Note: The same is true for running with '-cpu cortex-a53', with a53 and a57 exchanged.

Device Pass-Through

See VFIO


Managing virtual machines with libvirt

See Libvirt.


Building your own guest kernel

Kernel Config

The kernel config file used for the OpenWRT guest image is a good starting point. You can extract it from '/proc/config.gz' on the running system.

RAM Disk

You can extract the initramfs from an OpenWRT guest image using 'binwalk'. Make sure to truncate the initramfs file after the first 256-byte boundary after "TRAILER!!!", else the kernel will crash with

Kernel panic - not syncing: broken padding