blob: 24644931a77847a6e07916515ff8c949f35e581a [file] [log] [blame] [view]
Andrew Walbranb2be7c62019-08-06 14:55:29 +01001# VM interface
2
3This page provides an overview of the interface Hafnium provides to VMs. Hafnium
4makes a distinction between the 'primary VM', which controls scheduling and has
5more direct access to some hardware, and 'secondary VMs' which exist mostly to
6provide services to the primary VM, and have a more paravirtualised interface.
7The intention is that the primary VM can run a mostly unmodified operating
8system (such as Linux) with the addition of a Hafnium driver, while secondary
9VMs will run more specialised trusted OSes or bare-metal code which is designed
10with Hafnium in mind.
11
12The interface documented here is what is planned for the first release of
13Hafnium, not necessarily what is currently implemented.
14
15## CPU scheduling
16
17The primary VM will have one vCPU for each physical CPU, and control the
18scheduling.
19
20Secondary VMs will have a configurable number of vCPUs, scheduled on arbitrary
21physical CPUs at the whims of the primary VM scheduler.
22
23All VMs will start with a single active vCPU. Subsequent vCPUs can be started
24through PSCI.
25
26## PSCI
27
28The primary VM will be able to control the physical CPUs through the following
29PSCI 1.1 calls, which will be forwarded to the underlying implementation in EL3:
30
31* PSCI_VERSION
32* PSCI_FEATURES
33* PSCI_SYSTEM_OFF
34* PSCI_SYSTEM_RESET
35* PSCI_AFFINITY_INFO
36* PSCI_CPU_SUSPEND
37* PSCI_CPU_OFF
38* PSCI_CPU_ON
39
40All other PSCI calls are unsupported.
41
42Secondary VMs will be able to control their vCPUs through the following PSCI 1.1
43calls, which will be implemented by Hafnium:
44
45* PSCI_VERSION
46* PSCI_FEATURES
47* PSCI_AFFINITY_INFO
48* PSCI_CPU_SUSPEND
49* PSCI_CPU_OFF
50* PSCI_CPU_ON
51
52All other PSCI calls are unsupported.
53
54## Hardware timers
55
56The primary VM will have access to both the physical and virtual EL1 timers
57through the usual control registers (`CNT[PV]_TVAL_EL0` and `CNT[PV]_CTL_EL0`).
58
59Secondary VMs will have access to the virtual timer only, which will be emulated
60with help from the kernel driver in the primary VM.
61
62## Interrupts
63
64The primary VM will have direct access to control the physical GIC, and receive
65all interrupts (other than anything already trapped by TrustZone). It will be
66responsible for forwarding any necessary interrupts to secondary VMs. The
67Interrupt Translation Service (ITS) will be disabled by Hafnium so that it
68cannot be used to circumvent access controls.
69
70Secondary VMs will have access to a simple paravirtualized interrupt controller
71through two hypercalls: one to enable or disable a given virtual interrupt ID,
72and one to get and acknowledge the next pending interrupt. There is no concept
73of interrupt priorities or a distinction between edge and level triggered
74interrupts. Secondary VMs may also inject interrupts into their own vCPUs.
75
76## Performance counters
77
78VMs will be blocked from accessing performance counter registers (for the
79performance monitor extensions described in chapter D5 of the ARMv8-A reference
80manual) in production, to prevent them from being used as a side channel to leak
81data between VMs.
82
83Hafnium may allow VMs to use them in debug builds.
84
85## Debug registers
86
87VMs will be blocked from accessing debug registers in production builds, to
88prevent them from being used to circumvent access controls.
89
90Hafnium may allow VMs to use these registers in debug builds.
91
92## RAS Extension registers
93
94VMs will be blocked from using registers associated with the RAS Extension.
95
96## Asynchronous message passing
97
98VMs will be able to send messages of up to 4 KiB to each other asynchronously,
99with no queueing, as specified by SPCI.
100
101## Memory
102
103VMs will statically be given access to mutually-exclusive regions of the
104physical address space at boot. This includes MMIO space for controlling
105devices, plus a fixed amount of RAM for secondaries, and all remaining address
106space to the primary. Note that this means that only one VM can control any
107given page of MMIO registers for a device.
108
109VMs may choose to donate or share their memory with other VMs at runtime. Any
110given page may be shared with at most 2 VMs at once (including the original
111owning VM). Memory which has been donated or shared may not be forcefully
112reclaimed, but the VM with which it was shared may choose to return it.
113
114## Logging
115
116VMs may send a character to a shared log by means of a hypercall or SMC call.
117These log messages will be buffered per VM to make complete lines, then output
118to a Hafnium-owned UART and saved in a shared ring buffer which may be extracted
119from RAM dumps. VM IDs will be prepended to these logs.
120
121This log API is intended for use in early bringup and low-level debugging. No
122sensitive data should be logged through it. Higher level logs can be sent to the
123primary VM through the asynchronous message passing mechanism described above,
124or through shared memory.
125
126## Configuration
127
128Hafnium will read configuration from a flattened device tree blob (FDT). This
129may either be the same device tree used for the other details of the system or a
130separate minimal one just for Hafnium. This will include at least:
131
132* The available RAM.
133* The number of secondary VMs, how many vCPUs each should have, how much
134 memory to assign to each of them, and where to load their initial images.
135 (Most likely the initial image will be a minimal loader supplied with
136 Hafnium which will validate and load the rest of the image from the primary
137 later on.)
138* Which devices exist on the system, their details (MMIO regions, interrupts
139 and SYSMMU details), and which VM each is assigned to.
140 * A single physical device may be split into multiple logical devices
141 from Hafniums point of view if necessary to have different VMs own
142 different parts of it.
143* A whitelist of which SMC calls each VM is allowed to make.
144
145## Failure handling
146
147If a secondary VM tries to do something it shouldn't, Hafnium will either inject
148a fault or kill it and inform the primary VM. The primary VM may choose to
149restart the system or to continue without the secondary VM.
150
151If the primary VM tries to do something it shouldn't, Hafnium will either inject
152a fault or restart the system.
153
154## TrustZone communication
155
156The primary VM will be able to communicate with a TEE running in TrustZone
157either through SPCI messages or through whitelisted SMC calls, and through
158shared memory.
159
160## Other SMC calls
161
162Other than the PSCI calls described above and those used to communicate with
163Hafnium, all other SMC calls will be blocked by default. Hafnium will allow SMC
164calls to be whitelisted on a per-VM, per-function ID basis, as part of the
165static configuration described above. These whitelisted SMC calls will be
166forwarded to the EL3 handler with the client ID (as described by the SMCCC) set
167to the calling VM's ID.