diff options
| author | Andrew Turner <andrew@FreeBSD.org> | 2024-01-09 15:22:27 +0000 |
|---|---|---|
| committer | Andrew Turner <andrew@FreeBSD.org> | 2024-02-21 18:55:32 +0000 |
| commit | 47e073941f4e7ca6e9bde3fa65abbfcfed6bfa2b (patch) | |
| tree | 12952882180198ce097077e4b86efa2440229635 /sys/modules | |
| parent | 0f4071978e3dae6637d4988212661164115f6be8 (diff) | |
Import the kernel parts of bhyve/arm64
To support virtual machines on arm64 add the vmm code. This is based on
earlier work by Mihai Carabas and Alexandru Elisei at University
Politehnica of Bucharest, with further work by myself and Mark Johnston.
All AArch64 CPUs should work, however only the GICv3 interrupt
controller is supported. There is initial support to allow the GICv2
to be supported in the future. Only pure Armv8.0 virtualisation is
supported, the Virtualization Host Extensions are not currently used.
With a separate userspace patch and U-Boot port FreeBSD guests are able
to boot to multiuser mode, and the hypervisor can be tested with the
kvm unit tests. Linux partially boots, but hangs before entering
userspace. Other operating systems are untested.
Sponsored by: Arm Ltd
Sponsored by: Innovate UK
Sponsored by: The FreeBSD Foundation
Sponsored by: University Politehnica of Bucharest
Differential Revision: https://reviews.freebsd.org/D37428
Diffstat (limited to 'sys/modules')
| -rw-r--r-- | sys/modules/Makefile | 2 | ||||
| -rw-r--r-- | sys/modules/vmm/Makefile | 78 |
2 files changed, 67 insertions, 13 deletions
diff --git a/sys/modules/Makefile b/sys/modules/Makefile index 606ab4cb0536..dcd9e25b1cb3 100644 --- a/sys/modules/Makefile +++ b/sys/modules/Makefile @@ -841,7 +841,9 @@ _sgx= sgx _sgx_linux= sgx_linux _smartpqi= smartpqi _p2sb= p2sb +.endif +.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "amd64" .if ${MK_BHYVE} != "no" || defined(ALL_MODULES) .if ${KERN_OPTS:MSMP} _vmm= vmm diff --git a/sys/modules/vmm/Makefile b/sys/modules/vmm/Makefile index a950c5a82d13..a67797276bae 100644 --- a/sys/modules/vmm/Makefile +++ b/sys/modules/vmm/Makefile @@ -3,31 +3,79 @@ KMOD= vmm -SRCS= opt_acpi.h opt_bhyve_snapshot.h opt_ddb.h -SRCS+= device_if.h bus_if.h pci_if.h pcib_if.h acpi_if.h vnode_if.h -DPSRCS+= vmx_assym.h svm_assym.h -DPSRCS+= vmx_genassym.c svm_genassym.c offset.inc +SRCS= opt_acpi.h opt_ddb.h device_if.h bus_if.h pci_if.h pcib_if.h acpi_if.h CFLAGS+= -DVMM_KEEP_STATS -CFLAGS+= -I${SRCTOP}/sys/amd64/vmm -CFLAGS+= -I${SRCTOP}/sys/amd64/vmm/io -CFLAGS+= -I${SRCTOP}/sys/amd64/vmm/intel -CFLAGS+= -I${SRCTOP}/sys/amd64/vmm/amd +CFLAGS+= -I${SRCTOP}/sys/${MACHINE}/vmm +CFLAGS+= -I${SRCTOP}/sys/${MACHINE}/vmm/io # generic vmm support -.PATH: ${SRCTOP}/sys/amd64/vmm +.PATH: ${SRCTOP}/sys/${MACHINE}/vmm SRCS+= vmm.c \ vmm_dev.c \ - vmm_host.c \ vmm_instruction_emul.c \ + vmm_stat.c + +.if ${MACHINE_CPUARCH} == "aarch64" +DPSRCS+= assym.inc + +# TODO: Add the new EL2 code +SRCS+= vmm_arm64.c \ + vmm_reset.c \ + vmm_call.S \ + vmm_mmu.c \ + vmm_hyp_el2.S + +.PATH: ${SRCTOP}/sys/${MACHINE}/vmm/io +SRCS+= vgic.c \ + vgic_if.h \ + vgic_if.c \ + vgic_v3.c \ + vtimer.c + +SRCS+= vmm_hyp_exception.S vmm_hyp.c + +CLEANFILES+= vmm_hyp_blob.elf.full +CLEANFILES+= vmm_hyp_blob.elf vmm_hyp_blob.bin + +vmm_hyp_exception.o: vmm_hyp_exception.S + ${CC} -c -x assembler-with-cpp -DLOCORE \ + ${CFLAGS:N-fsanitize*:N-mbranch-protection*} \ + ${.IMPSRC} -o ${.TARGET} -fpie + +vmm_hyp.o: vmm_hyp.c + ${CC} -c ${CFLAGS:N-fsanitize*:N-mbranch-protection*} \ + ${.IMPSRC} -o ${.TARGET} -fpie + +vmm_hyp_blob.elf.full: vmm_hyp_exception.o vmm_hyp.o + ${LD} -m ${LD_EMULATION} -Bdynamic -T ${SYSDIR}/conf/ldscript.arm64 \ + ${_LDFLAGS} --no-warn-mismatch --warn-common --export-dynamic \ + --dynamic-linker /red/herring -X -o ${.TARGET} ${.ALLSRC} \ + --defsym=text_start='0x0' + +vmm_hyp_blob.elf: vmm_hyp_blob.elf.full + ${OBJCOPY} --strip-debug ${.ALLSRC} ${.TARGET} + +vmm_hyp_blob.bin: vmm_hyp_blob.elf + ${OBJCOPY} --output-target=binary ${.ALLSRC} ${.TARGET} + +vmm_hyp_el2.o: vmm_hyp_blob.bin + +.elif ${MACHINE_CPUARCH} == "amd64" +DPSRCS+= vmx_assym.h svm_assym.h +DPSRCS+= vmx_genassym.c svm_genassym.c offset.inc + +CFLAGS+= -I${SRCTOP}/sys/amd64/vmm/intel +CFLAGS+= -I${SRCTOP}/sys/amd64/vmm/amd + +SRCS+= vmm_host.c \ vmm_ioport.c \ vmm_lapic.c \ vmm_mem.c \ - vmm_stat.c \ vmm_util.c \ x86.c -.PATH: ${SRCTOP}/sys/amd64/vmm/io +.PATH: ${SRCTOP}/sys/${MACHINE}/vmm/io SRCS+= iommu.c \ ppt.c \ vatpic.c \ @@ -62,10 +110,11 @@ SRCS+= vmcb.c \ SRCS.BHYVE_SNAPSHOT= vmm_snapshot.c -CLEANFILES= vmx_assym.h vmx_genassym.o svm_assym.h svm_genassym.o +CLEANFILES+= vmx_assym.h vmx_genassym.o svm_assym.h svm_genassym.o OBJS_DEPEND_GUESS.vmx_support.o+= vmx_assym.h OBJS_DEPEND_GUESS.svm_support.o+= svm_assym.h +.endif vmx_assym.h: vmx_genassym.o sh ${SYSDIR}/kern/genassym.sh vmx_genassym.o > ${.TARGET} @@ -81,6 +130,9 @@ svm_support.o: ${CC} -c -x assembler-with-cpp -DLOCORE ${CFLAGS} \ ${.IMPSRC} -o ${.TARGET} +hyp_genassym.o: offset.inc + ${CC} -c ${CFLAGS:N-flto:N-fno-common} -fcommon ${.IMPSRC} + vmx_genassym.o: offset.inc ${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} \ -fcommon ${.IMPSRC} |
