Say I have a x86 machine. It's easy to create a x86 VM through Linux KVM API.
See: vm_init()
in kvm-host:
if ((v->kvm_fd = open("/dev/kvm", O_RDWR)) < 0)
return throw_err("Failed to open /dev/kvm");
if ((v->vm_fd = ioctl(v->kvm_fd, KVM_CREATE_VM, 0)) < 0)
return throw_err("Failed to create vm");
if (ioctl(v->vm_fd, KVM_SET_TSS_ADDR, 0xffffd000) < 0)
return throw_err("Failed to set TSS addr");
...
if ((v->vcpu_fd = ioctl(v->vm_fd, KVM_CREATE_VCPU, 0)) < 0)
return throw_err("Failed to create vcpu");
In this project, it's easy to create a x86 VM on a x86 machine.
My question is, however, what if i want that VM to be a ARM architecture?
I believe that is applicable because we have qemu-system-arm
, and what I try to achieve is exactly what it does.
What you are asking for is not possible. KVM cannot run virtual machines for different architectures than the one the kernel was built for and runs on. If you want to run an ARM VM using KVM you will have to do that on an ARM processor. KVM merely takes advantage of the hardware capabilities of the underlying CPU for virtualization, which means that instructions are effectively ran by the host CPU, so you cannot run ARM code on an x86 machine.
What qemu-system-arm
does on an x86 machine is emulate all the instructions in software and in userspace, without any help from the host kernel/CPU. You will be able to use KVM with qemu-system-arm
only if you are on an ARM machine which supports KVM. For more info see KVM Processor Support.