Introduction To Bhyve
Introduction To Bhyve
What is bhyve?
What is bhyve?
BSD License
bhyve features
Virtualization in general
Jail is container
bhyve is hypervisor
Container
jail1
proc
ess
proc
ess
Lightweight, less-overhead
jail2
proc
ess
Kernel
NIC
Disk
Hypervisor
vm1
proc
ess
proc
ess
Kernel
Kernel
NI
C
vm2
proc
ess
Disk
Disk
Hypervisor
NI
C
Kernel
NIC
Disk
CPU
I/O
CPU Virtualization:
Emulate entire CPU?
QEMU
CPU
emula
virtual
device IO tor
run
mov
mov
out
dx,3FBh
al,128
dx,al
OS
physica
l device
physic
al
CPU
Like QEMU
CPU Virtualization:
Direct execution?
Perform I/O on VM
GuestOS
Real Display
Virtual CPU
outb
Perform IO on VM
Virtual Display
GuestOS
trap!
Virtual CPU
outb
However, on x86, there are some instructions which are impossible to trap
because these are nonprivileged instructions
Software techniques to
virtualize x86
Hardware assisted
virtualization(Intel VT-x)
VMX
root mode
VMX
non-root
mode
User
(Ring 3)
User
(Ring 3)
Kernel
(Ring 0)
VMEntry
VMExit
Kernel
(Ring 0)
Memory Virtualization
Process A
1
Process B
1
2
Process A
1
Guest A
Page table A
1
2
Page table B
1
1
2
1
2
3
4
1
2
3
4
Guest B
Page table A
1
2
Process B
Page table B
1
5
Guest physical memory
6
7
2
3
4
If GuestB loads Page table A, virtual page 1 translate to Host physical page 1
but you meant Host physical page 5
Shadow Paging
Page table A'
1
2
Page table B'
Process A
1
1
2
3
4
Guest A
Page table A
1
2
2
Process B
1
2
Page table B
1
5
6
7
1
2
3
4
Guest physical memory
Guest A
Page table A
1
2
Process B
1
2
Page table B
1
2
3
4
EPT A
1
2
3
4
2
3
4
6
7
8
1
2
3
4
5
6
7
8
I/O Virtualization
Paravirtual I/O
Guest A
Pagetable A
1
2
Process B
1
2
Physical memory
Pagetable B
1
EPT A
1
2
3
4
Guest physical
memory
2
3
6
7
1
2
3
4
5
6
IOMMU
translation table
5
1
6
7
2
3
DMA!
PCI
Devices
7
8
If you attach a real HW device on a VM, you will have a problem with DMA
Because the device requires physical address for DMA but the guest OS
doesnt know the Host physical address
bhyve internals
bhyve overview
2. Run VM instace
Disk image
tap device
stdin/stdout
1. Create VM instance,
load guest kernel
Guest
bhyveload
H
D
N
I
C
Console
kernel
bhyve
3. Destroy VM
instance
bhyvectl
libvmmapi
mmap/ioctl
/dev/vmm/${vm_name} (vmm.ko)
FreeBSD kernel
bhyveload: loads
guest OS
bhyvectl: a management
tool
vmm.ko
All VT-x features only accessible in kernel
mode, vmm.ko handles it
/dev/vmm/${vmname}
interfaces
create/destroy
read/write/mmap
ioctl
/dev/vmm/${vmname}
ioctls
VM_MAP_MEMORY: Maps guest memory
area at requested size
libvmmapi
vm_set_register(reg, val)
ioctl(VM_SET_REGISTER, reg, val)
bhyveload
Guest machine can starts from kernel entry point, with 64bit mode
bhyve
}
}
Q&A?