27
How to port your BSD to run as Xen on ARM guest Julien Grall [email protected] BSDCan 2015

BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Embed Size (px)

Citation preview

Page 1: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

How to port your BSD to run as Xen on ARMguest

Julien [email protected]

BSDCan 2015

Page 2: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Xen

I Type-I hypervisor

I Support for ARM v7 and ARM v8 with virtualization extension

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 2 / 27

Page 3: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Example of hardware supported

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 3 / 27

Page 4: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Xen architecture

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 4 / 27

Page 5: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

ARM architecture

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 5 / 27

Page 6: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Xen on ARM architecture

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 6 / 27

Page 7: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

DOM0

I First guest to startI Nearly every devices are assigned to DOM0

I Serial, IOMMU, Timer and GIC are used by XenI Some devices can be blacklisted by Xen

I DOM0 kernel should use the Device Tree to discover thehardware

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 7 / 27

Page 8: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Requirements

I Guest boot ABI

I Device tree support

I Specific memory attribute

I Xen PV drivers

I Copy of xen/include/public

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 8 / 27

Page 9: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Guest boot ABI

Interface of the virtual machine:I Loaders:

I UEFI imageI Linux zImage/ImageI See xc dom loader structure in libxc to add a new loader

I Use of PSCI to bring up secondary CPUs

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 9 / 27

Page 10: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

UEFI Image

I Only supported for AArch64 guestI Require to build UEFI firmware for DOMU

I tianocore edk III https://wiki.linaro.org/LEG/UEFIforXEN

I No difference with baremetal after the firmware is booted

I Specification http://www.uefi.org/specifications

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 10 / 27

Page 11: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Linux zImage/Image

I Kernel loaded at a 4K aligned-addressI Specific values on some registers

I ARM 32 bitsI r0 = 0I r1 = 0xffffffffI r2 = Device Tree physical address

I ARM 64 bitsI x0 = Device Tree physical addressI x1 ... x4 = 0

I MMU disabled

I Data cache disabled

I Instruction cache in an unknown state

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 11 / 27

Page 12: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Device Tree: What is it?

I Tree data structure with nodes that describes the physicaldevices in a system

I Working group to standardize device core bindingsI [email protected]

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 12 / 27

Page 13: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Device Tree provided by Xen

I Basic Device Tree generated by the toolstack which contains:I CPUsI MemoryI TimerI GICI HypervisorI PSCI

I Guest must support Device Tree in order to run on every Xenversion

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 13 / 27

Page 14: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Memory

I Memory layout not fixedI Differ between Xen 4.4 and Xen 4.5I Documented in xen/include/public/arch-arm.h

I At least one RAM region will be located under 4GB

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 14 / 27

Page 15: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

MMU and Memory

I MMU-less and data cache disabled guests are supportedexcept for hypercall-based IO

I RAM restriction when MMU is enabled:I 3GB when short-descriptor is usedI 1TB when LPAE is used

I RAM attribute should be Write-Through or Write-Back

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 15 / 27

Page 16: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

PV protocol

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 16 / 27

Page 17: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Hypercalls

I Use of HVC instructionI Hypercall tag XEN HYPERCALL TAG = 0xEA1

I xen/public/arch-arm.h provides hypercalls conventionI ARM 32 bits

I r0 ...r4 used to store argumentsI hypercall number is passed in r12I return value is in r0

I ARM 64 bitsI x0 ... x4 used to store argumentsI hypercall number is passed in x16I return value is in x0

I hypercall assembly wrappers provides in LinuxI arch/arm{,64}/xen/hypercall.SI Dual-license GPLv2 and BSD

I memory hypercall based on 4K page granularity

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 17 / 27

Page 18: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Xen PV drivers

I Xen core architectureI XenstoreI Grant-TableI Event-channel

I Xen device driversI ConsoleI BlockI NetworkI Framebuffer

I Drivers already available under:I BSD license in FreeBSD/Mini-OSI Dual-license GPLv2 and BSD in Linux

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 18 / 27

Page 19: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Debugging the guest kernel

I xenctx domid vcpuidI Get the state of a VCPUI To use in DOM0

I Xen consoleI Switch from DOM0 console to Xen console via CTLR-a three

timesI Useful key

q Domains informatione Event channel informationsR Reboot the machine (useful for DOM0 debugging)

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 19 / 27

Page 20: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Using Xen debugging facilities in the kernel

Use of HVC 0xFFxx

I Supported when Xen is compiled with debug=y

I Requires to modify the guest

0xFFEX0xFFFD0xFFFE0xFFFF

Print the register rX/xXPrint the program counterPrint the character stored in r0/x0Dump the state of the VCPU

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 20 / 27

Page 21: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

FreeBSD on Xen

I Support for x86 PVHVM and PVH

I Support for PVH DOM0 on x86

I Support of ARM 32 and ARM 64 architecture

I Device Tree bindings compatible with the Linux onesI On going work to support Xen for ARM

I Less than 500 lines of Xen arch specific codeI PV drivers shared with x86

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 21 / 27

Page 22: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Xen PV drivers

I Update interface headers to Xen 4.4I FreeBSD is based on Xen 4.2 headersI ARM interface was not set in stone

I Drivers common with x86I Use the right xen type (xen pfn t, xen ulong t,...)I Support for HVM in console drivers

I Rework event channel handlingI was x86 specificI still missing features

I suspend/resumeI pirq

I common interrupt framework?

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 22 / 27

Page 23: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

ARM 32

I New kernel config XENHVM created

I Only support for guest with 1 VCPUI Loader:

I Missing support using Device Tree with Linux boot ABII zImage support?

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 23 / 27

Page 24: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

ARM 64

I Xen enabled in the GENERIC kernel config

I Driver to parse Xen DT bindings addedI No modification necessary in the loader

I UEFI based imageI Kernel loaded from the FilesystemI Device Tree provided by UEFI

I Missing SMP bring up based on PSCI

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 24 / 27

Page 25: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

OS supported by Xen

Out-of-box

Future support

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 25 / 27

Page 26: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Questions?

I Xen devel ML: [email protected]

I Xen user ML: [email protected]

I #xenarm on freenode

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 26 / 27

Page 27: BSDCan 2015: How to Port BSD as a Xen on ARM Guest

Intro DOM0 Requirements Debugging FreeBSD Conclusion

Fin

BSDCan 2015 How to port your BSD to run as Xen on ARM guest 27 / 27