sleirsgoevy / exynos-kvm-patch

Kernel patch to enable KVM/ARM on Samsung Exynos phones.
40 stars 11 forks source link

KVM patch for Samsung SM-A600FN (exynos7870)

This repository contains a patch for Samsung's official kernel sources that provides KVM support on exynos boards. This can probably be applied to other Samsung exynos kernels with minor changes.

How to use

  1. Download official kernel sources from opensource.samsung.com.
  2. Apply the patch
  3. Copy /proc/config.gz from your device, and unzip to .config
  4. Install and configure a cross-compiler (not documented here).
  5. In make menuconfig disable everything about TIMA (?) and RKP under "Boot Options" (they are incompatible with KVM), and enable KVM under "Virtualization".
  6. Build and flash your shiny KVM-enabled kernel!

Known bugs

Technical details

Normally Linux needs to be booted in EL2 (HYP mode in ARM terminology) to be able to utilize the virtualization extensions. SBOOT boots the Linux kernel in EL1, but fortunately for us they implemented a backdoor in TrustZone to load and execute custom code in EL2. This interface is utilized by init/vmm.c in Samsung's kernel to load the proprietary RKP hypervisor, and looks as follows:

#define VMM_64BIT_SMC_CALL_MAGIC 0xC2000400
#define VMM_STACK_OFFSET 4096
#define VMM_MODE_AARCH64 1
status = _vmm_goto_EL2(VMM_64BIT_SMC_CALL_MAGIC, entry_point, VMM_STACK_OFFSET, VMM_MODE_AARCH64, vmm, vmm_size);

Here _vmm_goto_EL2 is a simple wrapper around smc #0, entry_point is a physical address of the initialization routine, and the last two parameters are passed to it in x0 and x1 registers. To return, the initialization routine calls smc #0 with x0=0xc2000401, x1=status (the only piece of information that was obtained by disassembling the proprietary hypervisor).

The semantics of this interface are as follows:

Normal KVM/ARM bootstrap process:

KVM/ARM bootstrap process with this patch:

What did not work: