blob: 6694ecc525ea8425aeaaa72eafab38ac7f7ed5d0 [file] [log] [blame]
Olivier Deprez8c4cb2d2023-10-27 16:07:11 +02001Foreword
2========
3
4- This document describes the FF-A implementation from `[1]`_ for the
5 configuration where the SPMC resides at S-EL2 on platforms implementing the
6 FEAT_SEL2 architecture extension.
7- It is not an architecture specification and it might provide assumptions on
8 sections mandated as implementation-defined in the specification.
9- It covers the implications of TF-A used as a bootloader, and Hafnium used as a
10 reference code base for an SPMC.
11
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020012Terminology
J-Alvesf7490db2023-10-19 17:57:22 +010013===========
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020014
15- The term Hypervisor refers to the NS-EL2 component managing Virtual Machines
16 (or partitions) in the normal world.
17- The term SPMC refers to the S-EL2 component managing secure partitions in
18 the secure world when the FEAT_SEL2 architecture extension is implemented.
19- Alternatively, SPMC can refer to an S-EL1 component, itself being a secure
20 partition and implementing the FF-A ABI on platforms not implementing the
21 FEAT_SEL2 architecture extension.
22- The term VM refers to a normal world Virtual Machine managed by an Hypervisor.
23- The term SP refers to a secure world "Virtual Machine" managed by an SPMC.
24
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020025Sample reference stack
26======================
27
28The following diagram illustrates a possible configuration when the
J-Alves5eafd222023-10-26 14:19:21 +010029FEAT_SEL2 architecture extension is implemented, showing the |SPMD|
30and |SPMC|, one or multiple secure partitions, with an optional
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020031Hypervisor:
32
J-Alvesc1693772023-10-26 12:41:53 +010033.. image:: ../resources/diagrams/Hafnium_overview_SPMD.png
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020034
J-Alves5eafd222023-10-26 14:19:21 +010035Integration with TF-A (Bootloader and SPMD)
36===========================================
37
38The `TF-A project`_ provides the reference implementation for the secure monitor
39for Arm A class devices, executing at EL3. It includes the implementation of the
40|SPMD|, which manages the world-switch, to relay the FF-A calls to the |SPMC|.
41
42TF-A also serves as the system bootlader, and it was used in the reference
43implemenation for the SPMC and SPs.
44SPs may be signed by different parties (SiP, OEM/ODM, TOS vendor, etc.).
45Thus they are supplied as distinct signed entities within the FIP flash
46image. The FIP image itself is not signed hence this provides the ability
47to upgrade SPs in the field.
48
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020049TF-A build options
J-Alves5eafd222023-10-26 14:19:21 +010050------------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020051
J-Alvesd8094162023-10-26 12:44:33 +010052This section explains the TF-A build options for an FF-A based SPM, in which SPMD
53is located at EL3.
54
55This is a step needed for integrating Hafnium as the S-EL2 SPMC and
56the TF-A as SPMD, together making the SPM component.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020057
58- **SPD=spmd**: this option selects the SPMD component to relay the FF-A
59 protocol from NWd to SWd back and forth. It is not possible to
60 enable another Secure Payload Dispatcher when this option is chosen.
61- **SPMD_SPM_AT_SEL2**: this option adjusts the SPMC exception
62 level to being at S-EL2. It defaults to enabled (value 1) when
J-Alvesd8094162023-10-26 12:44:33 +010063 SPD=spmd is chosen.The context save/restore routine and exhaustive list
64 of registers is visible at `[4]`_. When set the reference software stack
65 assumes enablement of FEAT_PAuth, FEAT_BTI and FEAT_MTE architecture
66 extensions.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020067- **SP_LAYOUT_FILE**: this option specifies a text description file
68 providing paths to SP binary images and manifests in DTS format
J-Alves5eafd222023-10-26 14:19:21 +010069 (see `Secure Partitions Layout File`_). It is required when ``SPMD_SPM_AT_SEL2``
J-Alvesd8094162023-10-26 12:44:33 +010070 is enabled, i.e. when multiple secure partitions are to be loaded by BL2 on
71 behalf of the SPMC.
72- **BL32** option is re-purposed to specify the SPMC image. It can specify either
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020073 the Hafnium binary path (built for the secure world) or the path to a TEE
74 binary implementing FF-A interfaces.
J-Alvesd8094162023-10-26 12:44:33 +010075- **BL33** option to specify normal world loader such as U-Boot or the UEFI
76 framework payload, which would use FF-A calls during runtime to interact with
77 Hafnium as the SPMC.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020078
J-Alvesd8094162023-10-26 12:44:33 +010079As a result of configuring ``SPD=spmd`` and ``SPMD_SPM_AT_SEL2`` TF-A provides
80context save/restore operations when entering/exiting an EL2 execution context.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020081
J-Alvesd8094162023-10-26 12:44:33 +010082There are other build options that relate support other valid FF-A
83system configurations where the SPMC is implemented at S-EL1 and EL3.
84Note that they conflict with those needed to integrate with Hafnium as the SPMC.
85For more details refer to |TF-A| build options `[10]`_.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020086
87Sample TF-A build command line when FEAT_SEL2 architecture extension is
J-Alvesd8094162023-10-26 12:44:33 +010088implemented and the SPMC is located at S-EL2, for Arm's FVP platform:
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020089
90.. code:: shell
91
92 make \
93 CROSS_COMPILE=aarch64-none-elf- \
94 PLAT=fvp \
95 SPD=spmd \
96 ARM_ARCH_MINOR=5 \
97 BRANCH_PROTECTION=1 \
98 CTX_INCLUDE_PAUTH_REGS=1 \
99 CTX_INCLUDE_MTE_REGS=1 \
100 BL32=<path-to-hafnium-binary> \
101 BL33=<path-to-bl33-binary> \
102 SP_LAYOUT_FILE=sp_layout.json \
103 all fip
104
105Sample TF-A build command line when FEAT_SEL2 architecture extension is
106implemented, the SPMC is located at S-EL2, and enabling secure boot:
107
108.. code:: shell
109
110 make \
111 CROSS_COMPILE=aarch64-none-elf- \
112 PLAT=fvp \
113 SPD=spmd \
114 ARM_ARCH_MINOR=5 \
115 BRANCH_PROTECTION=1 \
116 CTX_INCLUDE_PAUTH_REGS=1 \
117 CTX_INCLUDE_MTE_REGS=1 \
118 BL32=<path-to-hafnium-binary> \
119 BL33=<path-to-bl33-binary> \
120 SP_LAYOUT_FILE=sp_layout.json \
121 MBEDTLS_DIR=<path-to-mbedtls-lib> \
122 TRUSTED_BOARD_BOOT=1 \
123 COT=dualroot \
124 ARM_ROTPK_LOCATION=devel_rsa \
125 ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem \
126 GENERATE_COT=1 \
127 all fip
128
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200129FVP model invocation
J-Alves5eafd222023-10-26 14:19:21 +0100130--------------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200131
132The FVP command line needs the following options to exercise the S-EL2 SPMC:
133
134+---------------------------------------------------+------------------------------------+
135| - cluster0.has_arm_v8-5=1 | Implements FEAT_SEL2, FEAT_PAuth, |
136| - cluster1.has_arm_v8-5=1 | and FEAT_BTI. |
137+---------------------------------------------------+------------------------------------+
138| - pci.pci_smmuv3.mmu.SMMU_AIDR=2 | Parameters required for the |
139| - pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B | SMMUv3.2 modeling. |
140| - pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 | |
141| - pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 | |
142| - pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472 | |
143| - pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 | |
144| - pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 | |
145| - pci.pci_smmuv3.mmu.SMMU_S_IDR3=0 | |
146+---------------------------------------------------+------------------------------------+
147| - cluster0.has_branch_target_exception=1 | Implements FEAT_BTI. |
148| - cluster1.has_branch_target_exception=1 | |
149+---------------------------------------------------+------------------------------------+
150| - cluster0.has_pointer_authentication=2 | Implements FEAT_PAuth |
151| - cluster1.has_pointer_authentication=2 | |
152+---------------------------------------------------+------------------------------------+
153| - cluster0.memory_tagging_support_level=2 | Implements FEAT_MTE2 |
154| - cluster1.memory_tagging_support_level=2 | |
155| - bp.dram_metadata.is_enabled=1 | |
156+---------------------------------------------------+------------------------------------+
157
158Sample FVP command line invocation:
159
160.. code:: shell
161
162 <path-to-fvp-model>/FVP_Base_RevC-2xAEMvA -C pctl.startup=0.0.0.0 \
163 -C cluster0.NUM_CORES=4 -C cluster1.NUM_CORES=4 -C bp.secure_memory=1 \
164 -C bp.secureflashloader.fname=trusted-firmware-a/build/fvp/debug/bl1.bin \
165 -C bp.flashloader0.fname=trusted-firmware-a/build/fvp/debug/fip.bin \
166 -C bp.pl011_uart0.out_file=fvp-uart0.log -C bp.pl011_uart1.out_file=fvp-uart1.log \
167 -C bp.pl011_uart2.out_file=fvp-uart2.log \
168 -C cluster0.has_arm_v8-5=1 -C cluster1.has_arm_v8-5=1 \
169 -C cluster0.has_pointer_authentication=2 -C cluster1.has_pointer_authentication=2 \
170 -C cluster0.has_branch_target_exception=1 -C cluster1.has_branch_target_exception=1 \
171 -C cluster0.memory_tagging_support_level=2 -C cluster1.memory_tagging_support_level=2 \
172 -C bp.dram_metadata.is_enabled=1 \
173 -C pci.pci_smmuv3.mmu.SMMU_AIDR=2 -C pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B \
174 -C pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 -C pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 \
175 -C pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472 -C pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 \
176 -C pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 -C pci.pci_smmuv3.mmu.SMMU_S_IDR3=0
177
J-Alves5eafd222023-10-26 14:19:21 +0100178SPMC Configuration
179==================
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200180
J-Alves5eafd222023-10-26 14:19:21 +0100181This section details the configuration files required to deploy Hafnium as the SPMC,
182along with those required to configure each secure partion.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200183
J-Alves5eafd222023-10-26 14:19:21 +0100184SPMC Manifest
185-------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200186
J-Alves5eafd222023-10-26 14:19:21 +0100187This manifest contains the SPMC *attribute* node consumed by the SPMD at boot
188time. It implements `[1]`_ (SP manifest at physical FF-A instance) and serves
189two different cases:
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200190
J-Alves5eafd222023-10-26 14:19:21 +0100191The SPMC manifest is used by the SPMD to setup the environment required by the
192SPMC to run at S-EL2. SPs run at S-EL1 or S-EL0.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200193
J-Alves5eafd222023-10-26 14:19:21 +0100194.. code:: shell
195
196 attribute {
197 spmc_id = <0x8000>;
198 maj_ver = <0x1>;
199 min_ver = <0x1>;
200 exec_state = <0x0>;
201 load_address = <0x0 0x6000000>;
202 entrypoint = <0x0 0x6000000>;
203 binary_size = <0x60000>;
204 };
205
206- *spmc_id* defines the endpoint ID value that SPMC can query through
207 ``FFA_ID_GET``.
208- *maj_ver/min_ver*. SPMD checks provided FF-A version versus its internal
209 version and aborts if not matching.
210- *exec_state* defines the SPMC execution state (AArch64 or AArch32).
211 Notice Hafnium used as a SPMC only supports AArch64.
212- *load_address* and *binary_size* are mostly used to verify secondary
213 entry points fit into the loaded binary image.
214- *entrypoint* defines the cold boot primary core entry point used by
215 SPMD (currently matches ``BL32_BASE``) to enter the SPMC.
216
217Other nodes in the manifest are consumed by Hafnium in the secure world.
218A sample can be found at `[7]`_:
219
220- The *hypervisor* node describes SPs. *is_ffa_partition* boolean attribute
221 indicates a FF-A compliant SP. The *load_address* field specifies the load
222 address at which BL2 loaded the SP package.
223- The *cpus* node provides the platform topology and allows MPIDR to VMPIDR mapping.
224 Note the primary core is declared first, then secondary cores are declared
225 in reverse order.
226- The *memory* nodes provide platform information on the ranges of memory
227 available for use by SPs at runtime. These ranges relate to either
228 secure or non-secure memory, depending on the *device_type* field.
229 If the field specifies "memory" the range is secure, else if it specifies
230 "ns-memory" the memory is non-secure. The system integrator must exclude
231 the memory used by other components that are not SPs, such as the monitor,
232 or the SPMC itself, the OS Kernel/Hypervisor, or other NWd VMs.
233 The SPMC limits the SP's address space such that they can only refer to memory
234 inside of those ranges, either by defining memory region nodes in their manifest
235 as well as memory starting at the load address until the limit defined by the memory
236 size. Thus, the SPMC prevents rogue SPs from tampering with memory from other
237 components.
238
J-Alvesc143a342023-11-07 12:17:44 +0000239.. code:: shell
240
241 memory@0 {
242 device_type = "memory";
243 reg = <0x0 0x6000000 0x2000000 0x0 0xff000000 0x1000000>;
244 };
245
246 memory@1 {
247 device_type = "ns-memory";
248 reg = <0x0 0x90010000 0x70000000>;
249 };
250
251Above find an example representation of the referred memory description. The
252ranges are described in a list of unsigned 32-bit values, in which the first
253two addresses relate to the based physical address, followed by the respective
254page size. The first secure range defined in the node below has base address
255`0x0 0x6000000` and size `0x2000000`; following there is another range with
256base address `0x0 0xff000000` and size `0x1000000`.
257
J-Alves5eafd222023-10-26 14:19:21 +0100258Secure Partitions Configuration
259-------------------------------
260
261SP Manifests
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200262~~~~~~~~~~~~
263
264An SP manifest describes SP attributes as defined in `[1]`_
265(partition manifest at virtual FF-A instance) in DTS format. It is
266represented as a single file associated with the SP. A sample is
267provided by `[5]`_. A binding document is provided by `[6]`_.
268
J-Alves5eafd222023-10-26 14:19:21 +0100269Platform topology
270~~~~~~~~~~~~~~~~~
271
272The *execution-ctx-count* SP manifest field can take the value of one or the
273total number of PEs. The FF-A specification `[1]`_ recommends the
274following SP types:
275
276- Pinned MP SPs: an execution context matches a physical PE. MP SPs must
277 implement the same number of ECs as the number of PEs in the platform.
278- Migratable UP SPs: a single execution context can run and be migrated on any
279 physical PE. Such SP declares a single EC in its SP manifest. An UP SP can
280 receive a direct message request originating from any physical core targeting
281 the single execution context.
282
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200283Secure Partition packages
284~~~~~~~~~~~~~~~~~~~~~~~~~
285
286Secure partitions are bundled as independent package files consisting
287of:
288
289- a header
290- a DTB
291- an image payload
292
293The header starts with a magic value and offset values to SP DTB and
294image payload. Each SP package is loaded independently by BL2 loader
295and verified for authenticity and integrity.
296
297The SP package identified by its UUID (matching FF-A uuid property) is
298inserted as a single entry into the FIP at end of the TF-A build flow
299as shown:
300
301.. code:: shell
302
303 Trusted Boot Firmware BL2: offset=0x1F0, size=0x8AE1, cmdline="--tb-fw"
304 EL3 Runtime Firmware BL31: offset=0x8CD1, size=0x13000, cmdline="--soc-fw"
305 Secure Payload BL32 (Trusted OS): offset=0x1BCD1, size=0x15270, cmdline="--tos-fw"
306 Non-Trusted Firmware BL33: offset=0x30F41, size=0x92E0, cmdline="--nt-fw"
307 HW_CONFIG: offset=0x3A221, size=0x2348, cmdline="--hw-config"
308 TB_FW_CONFIG: offset=0x3C569, size=0x37A, cmdline="--tb-fw-config"
309 SOC_FW_CONFIG: offset=0x3C8E3, size=0x48, cmdline="--soc-fw-config"
310 TOS_FW_CONFIG: offset=0x3C92B, size=0x427, cmdline="--tos-fw-config"
311 NT_FW_CONFIG: offset=0x3CD52, size=0x48, cmdline="--nt-fw-config"
312 B4B5671E-4A90-4FE1-B81F-FB13DAE1DACB: offset=0x3CD9A, size=0xC168, cmdline="--blob"
313 D1582309-F023-47B9-827C-4464F5578FC8: offset=0x48F02, size=0xC168, cmdline="--blob"
314
315.. uml:: ../resources/diagrams/plantuml/fip-secure-partitions.puml
316
J-Alves5eafd222023-10-26 14:19:21 +0100317Secure Partitions Layout File
318~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200319
320A json-formatted description file is passed to the build flow specifying paths
321to the SP binary image and associated DTS partition manifest file. The latter
322is processed by the dtc compiler to generate a DTB fed into the SP package.
Karl Meakin82593ce2023-08-30 16:38:28 +0100323Each partition can be configured with the following fields:
324
325:code:`image`
326 - Specifies the filename and offset of the image within the SP package.
327 - Can be written as :code:`"image": { "file": "path", "offset": 0x1234 }` to
328 give both :code:`image.file` and :code:`image.offset` values explicitly, or
329 can be written as :code:`"image": "path"` to give :code:`image.file` and value
330 and leave :code:`image.offset` absent.
331
332 :code:`image.file`
333 - Specifies the filename of the image.
334
335 :code:`image.offset`
336 - Specifies the offset of the image within the SP package.
337 - Must be 4KB aligned, because that is the translation granule supported by Hafnium SPMC.
338 - Optional. Defaults to :code:`0x4000`.
339
340:code:`pm`
341 - Specifies the filename and offset of the partition manifest within the SP package.
342 - Can be written as :code:`"pm": { "file": "path", "offset": 0x1234 }` to
343 give both :code:`pm.file` and :code:`pm.offset` values explicitly, or
344 can be written as :code:`"pm": "path"` to give :code:`pm.file` and value
345 and leave :code:`pm.offset` absent.
346
347 :code:`pm.file`
348 - Specifies the filename of the partition manifest.
349
350 :code:`pm.offset`
351 - Specifies the offset of the partition manifest within the SP package.
352 - Must be 4KB aligned, because that is the translation granule supported by Hafnium SPMC.
353 - Optional. Defaults to :code:`0x1000`.
354
355:code:`image.offset` and :code:`pm.offset` can be leveraged to support SPs with
356S1 translation granules that differ from 4KB, and to configure the regions
357allocated within the SP package, as well as to comply with the requirements for
358the implementation of the boot information protocol (see `Passing boot data to
359the SP`_ for more details).
360
361:code:`owner`
362 - Specifies the SP owner, identifying the signing domain in case of dual root CoT.
363 - Possible values are :code:`SiP` (silicon owner) or :code:`Plat` (platform owner).
364 - Optional. Defaults to :code:`SiP`.
365
366:code:`uuid`
367 - Specifies the UUID of the partition.
368 - Optional. Defaults to the value of the :code:`uuid` field from the DTS partition manifest.
369
370:code:`physical-load-address`
371 - Specifies the :code:`load_address` field of the generated DTS fragment.
372 - Optional. Defaults to the value of the :code:`load-address` from the DTS partition manifest.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200373
374.. code:: shell
375
376 {
377 "tee1" : {
378 "image": "tee1.bin",
379 "pm": "tee1.dts",
380 "owner": "SiP",
381 "uuid": "1b1820fe-48f7-4175-8999-d51da00b7c9f"
382 },
383
384 "tee2" : {
385 "image": "tee2.bin",
386 "pm": "tee2.dts",
387 "owner": "Plat"
388 },
389
390 "tee3" : {
391 "image": {
392 "file": "tee3.bin",
393 "offset":"0x2000"
394 },
395 "pm": {
396 "file": "tee3.dts",
397 "offset":"0x6000"
398 },
399 "owner": "Plat"
400 },
401 }
402
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200403SPMC boot
J-Alves5eafd222023-10-26 14:19:21 +0100404=========
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200405
406The SPMC is loaded by BL2 as the BL32 image.
407
408The SPMC manifest is loaded by BL2 as the ``TOS_FW_CONFIG`` image `[9]`_.
409
410BL2 passes the SPMC manifest address to BL31 through a register.
411
412At boot time, the SPMD in BL31 runs from the primary core, initializes the core
413contexts and launches the SPMC (BL32) passing the following information through
414registers:
415
416- X0 holds the ``TOS_FW_CONFIG`` physical address (or SPMC manifest blob).
417- X1 holds the ``HW_CONFIG`` physical address.
418- X4 holds the currently running core linear id.
419
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200420Secure boot
J-Alves5eafd222023-10-26 14:19:21 +0100421-----------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200422
423The SP content certificate is inserted as a separate FIP item so that BL2 loads SPMC,
424SPMC manifest, secure partitions and verifies them for authenticity and integrity.
425Refer to TBBR specification `[3]`_.
426
427The multiple-signing domain feature (in current state dual signing domain `[8]`_) allows
428the use of two root keys namely S-ROTPK and NS-ROTPK:
429
430- SPMC (BL32) and SPMC manifest are signed by the SiP using the S-ROTPK.
431- BL33 may be signed by the OEM using NS-ROTPK.
432- An SP may be signed either by SiP (using S-ROTPK) or by OEM (using NS-ROTPK).
433- A maximum of 4 partitions can be signed with the S-ROTPK key and 4 partitions
434 signed with the NS-ROTPK key.
435
J-Alves5eafd222023-10-26 14:19:21 +0100436Also refer to `Secure Partitions Configuration`_ and `TF-A build options`_ sections.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200437
438Boot phases
439-----------
440
441Primary core boot-up
442~~~~~~~~~~~~~~~~~~~~
443
444Upon boot-up, BL31 hands over to the SPMC (BL32) on the primary boot physical
445core. The SPMC performs its platform initializations and registers the SPMC
446secondary physical core entry point physical address by the use of the
447`FFA_SECONDARY_EP_REGISTER`_ interface (SMC invocation from the SPMC to the SPMD
448at secure physical FF-A instance).
449
J-Alvesc143a342023-11-07 12:17:44 +0000450The SPMC then creates secure partitions base on SP packages and manifests. Each
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200451secure partition is launched in sequence (`SP Boot order`_) on their "primary"
452execution context. If the primary boot physical core linear id is N, an MP SP is
453started using EC[N] on PE[N] (see `Platform topology`_). If the partition is a
454UP SP, it is started using its unique EC0 on PE[N].
455
456The SP primary EC (or the EC used when the partition is booted as described
457above):
458
459- Performs the overall SP boot time initialization, and in case of a MP SP,
460 prepares the SP environment for other execution contexts.
461- In the case of a MP SP, it invokes the FFA_SECONDARY_EP_REGISTER at secure
462 virtual FF-A instance (SMC invocation from SP to SPMC) to provide the IPA
463 entry point for other execution contexts.
464- Exits through ``FFA_MSG_WAIT`` to indicate successful initialization or
465 ``FFA_ERROR`` in case of failure.
466
467Secondary cores boot-up
468~~~~~~~~~~~~~~~~~~~~~~~
469
470Once the system is started and NWd brought up, a secondary physical core is
471woken up by the ``PSCI_CPU_ON`` service invocation. The TF-A SPD hook mechanism
472calls into the SPMD on the newly woken up physical core. Then the SPMC is
473entered at the secondary physical core entry point.
474
475In the current implementation, the first SP is resumed on the coresponding EC
476(the virtual CPU which matches the physical core). The implication is that the
477first SP must be a MP SP.
478
479In a linux based system, once secure and normal worlds are booted but prior to
480a NWd FF-A driver has been loaded:
481
482- The first SP has initialized all its ECs in response to primary core boot up
483 (at system initialization) and secondary core boot up (as a result of linux
484 invoking PSCI_CPU_ON for all secondary cores).
485- Other SPs have their first execution context initialized as a result of secure
486 world initialization on the primary boot core. Other ECs for those SPs have to
487 be run first through ffa_run to complete their initialization (which results
488 in the EC completing with FFA_MSG_WAIT).
489
490Refer to `Power management`_ for further details.
491
J-Alves5eafd222023-10-26 14:19:21 +0100492Loading of SPs
493--------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200494
J-Alves5eafd222023-10-26 14:19:21 +0100495At boot time, BL2 loads SPs sequentially in addition to the SPMC as depicted
496below:
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200497
J-Alves5eafd222023-10-26 14:19:21 +0100498.. uml:: ../resources/diagrams/plantuml/bl2-loading-sp.puml
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200499
J-Alves5eafd222023-10-26 14:19:21 +0100500Note this boot flow is an implementation sample on Arm's FVP platform.
501Platforms not using TF-A's *Firmware CONFiguration* framework would adjust to a
502different boot flow. The flow restricts to a maximum of 8 secure partitions.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200503
J-Alves5eafd222023-10-26 14:19:21 +0100504SP Boot order
505~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200506
J-Alves5eafd222023-10-26 14:19:21 +0100507SP manifests provide an optional boot order attribute meant to resolve
508dependencies such as an SP providing a service required to properly boot
509another SP. SPMC boots the SPs in accordance to the boot order attribute,
510lowest to the highest value. If the boot order attribute is absent from the FF-A
511manifest, the SP is treated as if it had the highest boot order value
512(i.e. lowest booting priority). The FF-A specification mandates this field
513is unique to each SP.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200514
J-Alves5eafd222023-10-26 14:19:21 +0100515It is possible for an SP to call into another SP through a direct request
516provided the latter SP has already been booted.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200517
J-Alves5eafd222023-10-26 14:19:21 +0100518Passing boot data to the SP
519~~~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200520
J-Alves5eafd222023-10-26 14:19:21 +0100521In `[1]`_ , the section "Boot information protocol" defines a method for passing
522data to the SPs at boot time. It specifies the format for the boot information
523descriptor and boot information header structures, which describe the data to be
524exchanged between SPMC and SP.
525The specification also defines the types of data that can be passed.
526The aggregate of both the boot info structures and the data itself is designated
527the boot information blob, and is passed to a Partition as a contiguous memory
528region.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200529
J-Alves5eafd222023-10-26 14:19:21 +0100530Currently, the SPM implementation supports the FDT type which is used to pass the
531partition's DTB manifest.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200532
J-Alves5eafd222023-10-26 14:19:21 +0100533The region for the boot information blob is allocated through the SP package.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200534
J-Alves5eafd222023-10-26 14:19:21 +0100535.. image:: ../resources/diagrams/partition-package.png
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200536
J-Alves5eafd222023-10-26 14:19:21 +0100537To adjust the space allocated for the boot information blob, the json description
538of the SP (see section `Secure Partitions Layout File`_) shall be updated to contain
539the manifest offset. If no offset is provided the manifest offset defaults to 0x1000,
540which is the page size in the Hafnium SPMC.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200541
J-Alves5eafd222023-10-26 14:19:21 +0100542The configuration of the boot protocol is done in the SPs manifest. As defined by
543the specification, the manifest field 'gp-register-num' configures the GP register
544which shall be used to pass the address to the partitions boot information blob when
545booting the partition.
546In addition, the Hafnium SPMC implementation requires the boot information arguments
547to be listed in a designated DT node:
548
549.. code:: shell
550
551 boot-info {
552 compatible = "arm,ffa-manifest-boot-info";
553 ffa_manifest;
554 };
555
556The whole secure partition package image (see `Secure Partition packages`_) is
557mapped to the SP secure EL1&0 Stage-2 translation regime. As such, the SP can
558retrieve the address for the boot information blob in the designated GP register,
559process the boot information header and descriptors, access its own manifest
560DTB blob and extract its partition manifest properties.
561
562SPMC Runtime
563============
564
565Parsing SP partition manifests
566------------------------------
567
568Hafnium consumes SP manifests as defined in `[1]`_ and `SP manifests`_.
569Note the current implementation may not implement all optional fields.
570
571The SP manifest may contain memory and device regions nodes:
572
573- Memory regions are mapped in the SP EL1&0 Stage-2 translation regime at
574 load time (or EL1&0 Stage-1 for an S-EL1 SPMC). A memory region node can
575 specify RX/TX buffer regions in which case it is not necessary for an SP
576 to explicitly invoke the ``FFA_RXTX_MAP`` interface. The memory referred
577 shall be contained within the memory ranges defined in SPMC manifest. The
578 NS bit in the attributes field should be consistent with the security
579 state of the range that it relates to. I.e. non-secure memory shall be
580 part of a non-secure memory range, and secure memory shall be contained
581 in a secure memory range of a given platform.
582- Device regions are mapped in the SP EL1&0 Stage-2 translation regime (or
583 EL1&0 Stage-1 for an S-EL1 SPMC) as peripherals and possibly allocate
584 additional resources (e.g. interrupts).
585
586For the SPMC, base addresses for memory and device region nodes are IPAs provided
587the SPMC identity maps IPAs to PAs within SP EL1&0 Stage-2 translation regime.
588
589Note: in the current implementation both VTTBR_EL2 and VSTTBR_EL2 point to the
590same set of page tables. It is still open whether two sets of page tables shall
591be provided per SP. The memory region node as defined in the specification
592provides a memory security attribute hinting to map either to the secure or
593non-secure EL1&0 Stage-2 table if it exists.
594
595Secure partitions scheduling
596----------------------------
597
Olivier Deprez8c4cb2d2023-10-27 16:07:11 +0200598The FF-A specification `[1]`_ provides two ways to allocate CPU cycles to
J-Alves5eafd222023-10-26 14:19:21 +0100599secure partitions. For this a VM (Hypervisor or OS kernel), or SP invokes one of:
600
601- the FFA_MSG_SEND_DIRECT_REQ interface.
602- the FFA_RUN interface.
603
604Additionally a secure interrupt can pre-empt the normal world execution and give
605CPU cycles by transitioning to EL3 and S-EL2.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200606
607Mandatory interfaces
608--------------------
609
610The following interfaces are exposed to SPs:
611
612- ``FFA_VERSION``
613- ``FFA_FEATURES``
614- ``FFA_RX_RELEASE``
615- ``FFA_RXTX_MAP``
616- ``FFA_RXTX_UNMAP``
617- ``FFA_PARTITION_INFO_GET``
618- ``FFA_ID_GET``
619- ``FFA_MSG_WAIT``
620- ``FFA_MSG_SEND_DIRECT_REQ``
621- ``FFA_MSG_SEND_DIRECT_RESP``
622- ``FFA_MEM_DONATE``
623- ``FFA_MEM_LEND``
624- ``FFA_MEM_SHARE``
625- ``FFA_MEM_RETRIEVE_REQ``
626- ``FFA_MEM_RETRIEVE_RESP``
627- ``FFA_MEM_RELINQUISH``
628- ``FFA_MEM_FRAG_RX``
629- ``FFA_MEM_FRAG_TX``
630- ``FFA_MEM_RECLAIM``
631- ``FFA_RUN``
632
633As part of the FF-A v1.1 support, the following interfaces were added:
634
635 - ``FFA_NOTIFICATION_BITMAP_CREATE``
636 - ``FFA_NOTIFICATION_BITMAP_DESTROY``
637 - ``FFA_NOTIFICATION_BIND``
638 - ``FFA_NOTIFICATION_UNBIND``
639 - ``FFA_NOTIFICATION_SET``
640 - ``FFA_NOTIFICATION_GET``
641 - ``FFA_NOTIFICATION_INFO_GET``
642 - ``FFA_SPM_ID_GET``
643 - ``FFA_SECONDARY_EP_REGISTER``
644 - ``FFA_MEM_PERM_GET``
645 - ``FFA_MEM_PERM_SET``
646 - ``FFA_MSG_SEND2``
647 - ``FFA_RX_ACQUIRE``
648
Raghu Krishnamurthy4a793e92023-08-09 10:10:23 -0700649As part of the FF-A v1.2 support, the following interfaces were added:
650- ``FFA_PARTITION_INFO_GET_REGS``
651
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200652FFA_VERSION
653~~~~~~~~~~~
654
655``FFA_VERSION`` requires a *requested_version* parameter from the caller.
656The returned value depends on the caller:
657
658- Hypervisor or OS kernel in NS-EL1/EL2: the SPMD returns the SPMC version
659 specified in the SPMC manifest.
660- SP: the SPMC returns its own implemented version.
661- SPMC at S-EL1/S-EL2: the SPMD returns its own implemented version.
662
663FFA_FEATURES
664~~~~~~~~~~~~
665
666FF-A features supported by the SPMC may be discovered by secure partitions at
667boot (that is prior to NWd is booted) or run-time.
668
669The SPMC calling FFA_FEATURES at secure physical FF-A instance always get
670FFA_SUCCESS from the SPMD.
671
672The request made by an Hypervisor or OS kernel is forwarded to the SPMC and
673the response relayed back to the NWd.
674
675FFA_RXTX_MAP/FFA_RXTX_UNMAP
676~~~~~~~~~~~~~~~~~~~~~~~~~~~
677
678When invoked from a secure partition FFA_RXTX_MAP maps the provided send and
679receive buffers described by their IPAs to the SP EL1&0 Stage-2 translation
680regime as secure buffers in the MMU descriptors.
681
682When invoked from the Hypervisor or OS kernel, the buffers are mapped into the
683SPMC EL2 Stage-1 translation regime and marked as NS buffers in the MMU
684descriptors. The provided addresses may be owned by a VM in the normal world,
685which is expected to receive messages from the secure world. The SPMC will in
686this case allocate internal state structures to facilitate RX buffer access
687synchronization (through FFA_RX_ACQUIRE interface), and to permit SPs to send
688messages.
689
690The FFA_RXTX_UNMAP unmaps the RX/TX pair from the translation regime of the
691caller, either it being the Hypervisor or OS kernel, as well as a secure
692partition.
693
694FFA_PARTITION_INFO_GET
695~~~~~~~~~~~~~~~~~~~~~~
696
697Partition info get call can originate:
698
699- from SP to SPMC
700- from Hypervisor or OS kernel to SPMC. The request is relayed by the SPMD.
701
Raghu Krishnamurthy4a793e92023-08-09 10:10:23 -0700702FFA_PARTITION_INFO_GET_REGS
703~~~~~~~~~~~~~~~~~~~~~~~~~~~
704
705This call can originate:
706
707- from SP to SPMC
708- from SPMC to SPMD
709- from Hypervsior or OS kernel to SPMC. The request is relayed by the SPMD.
710
711The primary use of this ABI is to return partition information via registers
712as opposed to via RX/TX buffers and is useful in cases where sharing memory is
713difficult.
714
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200715FFA_ID_GET
716~~~~~~~~~~
717
718The FF-A id space is split into a non-secure space and secure space:
719
720- FF-A ID with bit 15 clear relates to VMs.
721- FF-A ID with bit 15 set related to SPs.
722- FF-A IDs 0, 0xffff, 0x8000 are assigned respectively to the Hypervisor, SPMD
723 and SPMC.
724
725The SPMD returns:
726
727- The default zero value on invocation from the Hypervisor.
728- The ``spmc_id`` value specified in the SPMC manifest on invocation from
729 the SPMC (see `SPMC manifest`_)
730
731This convention helps the SPMC to determine the origin and destination worlds in
732an FF-A ABI invocation. In particular the SPMC shall filter unauthorized
733transactions in its world switch routine. It must not be permitted for a VM to
734use a secure FF-A ID as origin world by spoofing:
735
736- A VM-to-SP direct request/response shall set the origin world to be non-secure
737 (FF-A ID bit 15 clear) and destination world to be secure (FF-A ID bit 15
738 set).
739- Similarly, an SP-to-SP direct request/response shall set the FF-A ID bit 15
740 for both origin and destination IDs.
741
742An incoming direct message request arriving at SPMD from NWd is forwarded to
743SPMC without a specific check. The SPMC is resumed through eret and "knows" the
744message is coming from normal world in this specific code path. Thus the origin
745endpoint ID must be checked by SPMC for being a normal world ID.
746
747An SP sending a direct message request must have bit 15 set in its origin
748endpoint ID and this can be checked by the SPMC when the SP invokes the ABI.
749
750The SPMC shall reject the direct message if the claimed world in origin endpoint
751ID is not consistent:
752
753- It is either forwarded by SPMD and thus origin endpoint ID must be a "normal
754 world ID",
755- or initiated by an SP and thus origin endpoint ID must be a "secure world ID".
756
757
758FFA_MSG_SEND_DIRECT_REQ/FFA_MSG_SEND_DIRECT_RESP
759~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
760
761This is a mandatory interface for secure partitions consisting in direct request
762and responses with the following rules:
763
764- An SP can send a direct request to another SP.
765- An SP can receive a direct request from another SP.
766- An SP can send a direct response to another SP.
767- An SP cannot send a direct request to an Hypervisor or OS kernel.
768- An Hypervisor or OS kernel can send a direct request to an SP.
769- An SP can send a direct response to an Hypervisor or OS kernel.
770
771FFA_NOTIFICATION_BITMAP_CREATE/FFA_NOTIFICATION_BITMAP_DESTROY
772~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
773
774The secure partitions notifications bitmap are statically allocated by the SPMC.
775Hence, this interface is not to be issued by secure partitions.
776
777At initialization, the SPMC is not aware of VMs/partitions deployed in the
778normal world. Hence, the Hypervisor or OS kernel must use both ABIs for SPMC
779to be prepared to handle notifications for the provided VM ID.
780
781FFA_NOTIFICATION_BIND/FFA_NOTIFICATION_UNBIND
782~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
783
784Pair of interfaces to manage permissions to signal notifications. Prior to
785handling notifications, an FF-A endpoint must allow a given sender to signal a
786bitmap of notifications.
787
788If the receiver doesn't have notification support enabled in its FF-A manifest,
789it won't be able to bind notifications, hence forbidding it to receive any
790notifications.
791
792FFA_NOTIFICATION_SET/FFA_NOTIFICATION_GET
793~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
794
795FFA_NOTIFICATION_GET retrieves all pending global notifications and
796per-vCPU notifications targeted to the current vCPU.
797
798Hafnium maintains a global count of pending notifications which gets incremented
799and decremented when handling FFA_NOTIFICATION_SET and FFA_NOTIFICATION_GET
800respectively. A delayed SRI is triggered if the counter is non-zero when the
801SPMC returns to normal world.
802
803FFA_NOTIFICATION_INFO_GET
804~~~~~~~~~~~~~~~~~~~~~~~~~
805
806Hafnium maintains a global count of pending notifications whose information
807has been retrieved by this interface. The count is incremented and decremented
808when handling FFA_NOTIFICATION_INFO_GET and FFA_NOTIFICATION_GET respectively.
809It also tracks notifications whose information has been retrieved individually,
810such that it avoids duplicating returned information for subsequent calls to
811FFA_NOTIFICATION_INFO_GET. For each notification, this state information is
812reset when receiver called FFA_NOTIFICATION_GET to retrieve them.
813
814FFA_SPM_ID_GET
815~~~~~~~~~~~~~~
816
817Returns the FF-A ID allocated to an SPM component which can be one of SPMD
818or SPMC.
819
820At initialization, the SPMC queries the SPMD for the SPMC ID, using the
821FFA_ID_GET interface, and records it. The SPMC can also query the SPMD ID using
822the FFA_SPM_ID_GET interface at the secure physical FF-A instance.
823
824Secure partitions call this interface at the virtual FF-A instance, to which
825the SPMC returns the priorly retrieved SPMC ID.
826
827The Hypervisor or OS kernel can issue the FFA_SPM_ID_GET call handled by the
828SPMD, which returns the SPMC ID.
829
830FFA_SECONDARY_EP_REGISTER
831~~~~~~~~~~~~~~~~~~~~~~~~~
832
833When the SPMC boots, all secure partitions are initialized on their primary
834Execution Context.
835
836The FFA_SECONDARY_EP_REGISTER interface is to be used by a secure partition
837from its first execution context, to provide the entry point address for
838secondary execution contexts.
839
840A secondary EC is first resumed either upon invocation of PSCI_CPU_ON from
841the NWd or by invocation of FFA_RUN.
842
843FFA_RX_ACQUIRE/FFA_RX_RELEASE
844~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
845
846The RX buffers can be used to pass information to an FF-A endpoint in the
847following scenarios:
848
849 - When it was targetted by a FFA_MSG_SEND2 invokation from another endpoint.
850 - Return the result of calling ``FFA_PARTITION_INFO_GET``.
851 - In a memory share operation, as part of the ``FFA_MEM_RETRIEVE_RESP``,
852 with the memory descriptor of the shared memory.
853
854If a normal world VM is expected to exchange messages with secure world,
855its RX/TX buffer addresses are forwarded to the SPMC via FFA_RXTX_MAP ABI,
856and are from this moment owned by the SPMC.
857The hypervisor must call the FFA_RX_ACQUIRE interface before attempting
858to use the RX buffer, in any of the aforementioned scenarios. A successful
859call to FFA_RX_ACQUIRE transfers ownership of RX buffer to hypervisor, such
860that it can be safely used.
861
862The FFA_RX_RELEASE interface is used after the FF-A endpoint is done with
863processing the data received in its RX buffer. If the RX buffer has been
864acquired by the hypervisor, the FFA_RX_RELEASE call must be forwarded to
865the SPMC to reestablish SPMC's RX ownership.
866
867An attempt from an SP to send a message to a normal world VM whose RX buffer
868was acquired by the hypervisor fails with error code FFA_BUSY, to preserve
869the RX buffer integrity.
870The operation could then be conducted after FFA_RX_RELEASE.
871
872FFA_MSG_SEND2
873~~~~~~~~~~~~~
874
875Hafnium copies a message from the sender TX buffer into receiver's RX buffer.
876For messages from SPs to VMs, operation is only possible if the SPMC owns
877the receiver's RX buffer.
878
879Both receiver and sender need to enable support for indirect messaging,
880in their respective partition manifest. The discovery of support
881of such feature can be done via FFA_PARTITION_INFO_GET.
882
883On a successful message send, Hafnium pends an RX buffer full framework
884notification for the receiver, to inform it about a message in the RX buffer.
885
886The handling of framework notifications is similar to that of
887global notifications. Binding of these is not necessary, as these are
888reserved to be used by the hypervisor or SPMC.
889
Madhukar Pappireddy0b2304b2023-08-15 18:05:21 -0500890Paravirtualized interfaces
891--------------------------
892
893Hafnium SPMC implements the following implementation-defined interface(s):
894
895HF_INTERRUPT_ENABLE
896~~~~~~~~~~~~~~~~~~~
897
898Enables or disables the given virtual interrupt for the calling execution
899context. Returns 0 on success, or -1 if the interrupt id is invalid.
900
901HF_INTERRUPT_GET
902~~~~~~~~~~~~~~~~
903
904Returns the ID of the next pending virtual interrupt for the calling execution
905context, and acknowledges it (i.e. marks it as no longer pending). Returns
906HF_INVALID_INTID if there are no pending interrupts.
907
908HF_INTERRUPT_DEACTIVATE
909~~~~~~~~~~~~~~~~~~~~~~~
910
911Drops the current interrupt priority and deactivates the given virtual and
912physical interrupt ID for the calling execution context. Returns 0 on success,
913or -1 otherwise.
914
915HF_INTERRUPT_RECONFIGURE
916~~~~~~~~~~~~~~~~~~~~~~~~
917
918An SP specifies the list of interrupts it owns through its partition manifest.
919This paravirtualized interface allows an SP to reconfigure a physical interrupt
920in runtime. It accepts three arguments, namely, interrupt ID, command and value.
921The command & value pair signify what change is being requested by the current
922Secure Partition for the given interrupt.
923
924SPMC returns 0 to indicate that the command was processed successfully or -1 if
925it failed to do so. At present, this interface only supports the following
926commands:
927
928 - ``INT_RECONFIGURE_TARGET_PE``
929 - Change the target CPU of the interrupt.
930 - Value represents linear CPU index in the range 0 to (MAX_CPUS - 1).
931
932 - ``INT_RECONFIGURE_SEC_STATE``
933 - Change the security state of the interrupt.
934 - Value must be either 0 (Non-secure) or 1 (Secure).
935
936 - ``INT_RECONFIGURE_ENABLE``
937 - Enable or disable the physical interrupt.
938 - Value must be either 0 (Disable) or 1 (Enable).
939
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200940SPMC-SPMD direct requests/responses
941-----------------------------------
942
943Implementation-defined FF-A IDs are allocated to the SPMC and SPMD.
944Using those IDs in source/destination fields of a direct request/response
945permits SPMD to SPMC communication and either way.
946
947- SPMC to SPMD direct request/response uses SMC conduit.
948- SPMD to SPMC direct request/response uses ERET conduit.
949
950This is used in particular to convey power management messages.
951
J-Alves5eafd222023-10-26 14:19:21 +0100952Notifications
953-------------
954
955The FF-A v1.1 specification `[1]`_ defines notifications as an asynchronous
956communication mechanism with non-blocking semantics. It allows for one FF-A
957endpoint to signal another for service provision, without hindering its current
958progress.
959
960Hafnium currently supports 64 notifications. The IDs of each notification define
961a position in a 64-bit bitmap.
962
963The signaling of notifications can interchangeably happen between NWd and SWd
964FF-A endpoints.
965
966The SPMC is in charge of managing notifications from SPs to SPs, from SPs to
967VMs, and from VMs to SPs. An hypervisor component would only manage
968notifications from VMs to VMs. Given the SPMC has no visibility of the endpoints
969deployed in NWd, the Hypervisor or OS kernel must invoke the interface
970FFA_NOTIFICATION_BITMAP_CREATE to allocate the notifications bitmap per FF-A
971endpoint in the NWd that supports it.
972
973A sender can signal notifications once the receiver has provided it with
974permissions. Permissions are provided by invoking the interface
975FFA_NOTIFICATION_BIND.
976
977Notifications are signaled by invoking FFA_NOTIFICATION_SET. Henceforth
978they are considered to be in a pending sate. The receiver can retrieve its
979pending notifications invoking FFA_NOTIFICATION_GET, which, from that moment,
980are considered to be handled.
981
982Per the FF-A v1.1 spec, each FF-A endpoint must be associated with a scheduler
983that is in charge of donating CPU cycles for notifications handling. The
984FF-A driver calls FFA_NOTIFICATION_INFO_GET to retrieve the information about
985which FF-A endpoints have pending notifications. The receiver scheduler is
986called and informed by the FF-A driver, and it should allocate CPU cycles to the
987receiver.
988
989There are two types of notifications supported:
990
991- Global, which are targeted to a FF-A endpoint and can be handled within any of
992 its execution contexts, as determined by the scheduler of the system.
993- Per-vCPU, which are targeted to a FF-A endpoint and to be handled within a
994 a specific execution context, as determined by the sender.
995
996The type of a notification is set when invoking FFA_NOTIFICATION_BIND to give
997permissions to the sender.
998
999Notification signaling resorts to two interrupts:
1000
1001- Schedule Receiver Interrupt: non-secure physical interrupt to be handled by
1002 the FF-A driver within the receiver scheduler. At initialization the SPMC
1003 donates an SGI ID chosen from the secure SGI IDs range and configures it as
1004 non-secure. The SPMC triggers this SGI on the currently running core when
1005 there are pending notifications, and the respective receivers need CPU cycles
1006 to handle them.
1007- Notifications Pending Interrupt: virtual interrupt to be handled by the
1008 receiver of the notification. Set when there are pending notifications for the
1009 given secure partition. The NPI is pended when the NWd relinquishes CPU cycles
1010 to an SP.
1011
1012The notifications receipt support is enabled in the partition FF-A manifest.
1013
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001014Memory Sharing
1015--------------
1016
1017Hafnium implements the following memory sharing interfaces:
1018
1019 - ``FFA_MEM_SHARE`` - for shared access between lender and borrower.
1020 - ``FFA_MEM_LEND`` - borrower to obtain exclusive access, though lender
1021 retains ownership of the memory.
1022 - ``FFA_MEM_DONATE`` - lender permanently relinquishes ownership of memory
1023 to the borrower.
1024
1025The ``FFA_MEM_RETRIEVE_REQ`` interface is for the borrower to request the
1026memory to be mapped into its address space: for S-EL1 partitions the SPM updates
1027their stage 2 translation regime; for S-EL0 partitions the SPM updates their
1028stage 1 translation regime. On a successful call, the SPMC responds back with
1029``FFA_MEM_RETRIEVE_RESP``.
1030
1031The ``FFA_MEM_RELINQUISH`` interface is for when the borrower is done with using
1032a memory region.
1033
1034The ``FFA_MEM_RECLAIM`` interface is for the owner of the memory to reestablish
1035its ownership and exclusive access to the memory shared.
1036
1037The memory transaction descriptors are transmitted via RX/TX buffers. In
1038situations where the size of the memory transaction descriptor exceeds the
1039size of the RX/TX buffers, Hafnium provides support for fragmented transmission
1040of the full transaction descriptor. The ``FFA_MEM_FRAG_RX`` and ``FFA_MEM_FRAG_TX``
1041interfaces are for receiving and transmitting the next fragment, respectively.
1042
1043If lender and borrower(s) are SPs, all memory sharing operations are supported.
1044
1045Hafnium also supports memory sharing operations between the normal world and the
1046secure world. If there is an SP involved, the SPMC allocates data to track the
1047state of the operation.
1048
1049The SPMC is also the designated allocator for the memory handle. The hypervisor
1050or OS kernel has the possibility to rely on the SPMC to maintain the state
1051of the operation, thus saving memory.
J-Alvesda82a1a2023-10-17 11:45:49 +01001052An SP can not share, lend or donate memory to the NWd.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001053
1054The SPMC supports the hypervisor retrieve request, as defined by the FF-A
1055v1.1 EAC0 specification, in section 16.4.3. The intent is to aid with operations
1056that the hypervisor must do for a VM retriever. For example, when handling
1057an FFA_MEM_RECLAIM, if the hypervisor relies on SPMC to keep the state
1058of the operation, the hypervisor retrieve request can be used to obtain
1059that state information, do the necessary validations, and update stage 2
1060memory translation.
1061
1062Hafnium also supports memory lend and share targetting multiple borrowers.
1063This is the case for a lender SP to multiple SPs, and for a lender VM to
1064multiple endpoints (from both secure world and normal world). If there is
1065at least one borrower VM, the hypervisor is in charge of managing its
1066stage 2 translation on a successful memory retrieve.
1067The semantics of ``FFA_MEM_DONATE`` implies ownership transmission,
1068which should target only one partition.
1069
1070The memory share interfaces are backwards compatible with memory transaction
1071descriptors from FF-A v1.0. These get translated to FF-A v1.1 descriptors for
1072Hafnium's internal processing of the operation. If the FF-A version of a
1073borrower is v1.0, Hafnium provides FF-A v1.0 compliant memory transaction
1074descriptors on memory retrieve response.
1075
J-Alvesffc82062023-11-07 14:19:00 +00001076In the section :ref:`SPMC Configuration` there is a mention of non-secure memory
1077range, that limit the memory region nodes the SP can define. Whatever is left of
1078the memory region node carve-outs, the SPMC utilizes the memory to create a set of
1079page tables it associates with the NWd. The memory sharing operations incoming from
1080the NWd should refer to addresses belonging to these page tables. The intent
1081is for SPs not to be able to get access to regions they are not intended to access.
1082This requires special care from the system integrator to configure the memory ranges
1083correctly, such that any SP can't be given access and interfere with execution of
1084other components. More information in the :ref:`Threat Model`.
1085
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001086PE MMU configuration
1087--------------------
1088
1089With secure virtualization enabled (``HCR_EL2.VM = 1``) and for S-EL1
1090partitions, two IPA spaces (secure and non-secure) are output from the
1091secure EL1&0 Stage-1 translation.
1092The EL1&0 Stage-2 translation hardware is fed by:
1093
1094- A secure IPA when the SP EL1&0 Stage-1 MMU is disabled.
1095- One of secure or non-secure IPA when the secure EL1&0 Stage-1 MMU is enabled.
1096
1097``VTCR_EL2`` and ``VSTCR_EL2`` provide configuration bits for controlling the
1098NS/S IPA translations. The following controls are set up:
1099``VSTCR_EL2.SW = 0`` , ``VSTCR_EL2.SA = 0``, ``VTCR_EL2.NSW = 0``,
1100``VTCR_EL2.NSA = 1``:
1101
1102- Stage-2 translations for the NS IPA space access the NS PA space.
1103- Stage-2 translation table walks for the NS IPA space are to the secure PA space.
1104
1105Secure and non-secure IPA regions (rooted to by ``VTTBR_EL2`` and ``VSTTBR_EL2``)
1106use the same set of Stage-2 page tables within a SP.
1107
1108The ``VTCR_EL2/VSTCR_EL2/VTTBR_EL2/VSTTBR_EL2`` virtual address space
1109configuration is made part of a vCPU context.
1110
1111For S-EL0 partitions with VHE enabled, a single secure EL2&0 Stage-1 translation
1112regime is used for both Hafnium and the partition.
1113
1114Schedule modes and SP Call chains
1115---------------------------------
1116
1117An SP execution context is said to be in SPMC scheduled mode if CPU cycles are
1118allocated to it by SPMC. Correspondingly, an SP execution context is said to be
1119in Normal world scheduled mode if CPU cycles are allocated by the normal world.
1120
1121A call chain represents all SPs in a sequence of invocations of a direct message
1122request. When execution on a PE is in the secure state, only a single call chain
1123that runs in the Normal World scheduled mode can exist. FF-A v1.1 spec allows
1124any number of call chains to run in the SPMC scheduled mode but the Hafnium
1125SPMC restricts the number of call chains in SPMC scheduled mode to only one for
1126keeping the implementation simple.
1127
1128Partition runtime models
1129------------------------
1130
1131The runtime model of an endpoint describes the transitions permitted for an
1132execution context between various states. These are the four partition runtime
1133models supported (refer to `[1]`_ section 7):
1134
1135 - RTM_FFA_RUN: runtime model presented to an execution context that is
1136 allocated CPU cycles through FFA_RUN interface.
1137 - RTM_FFA_DIR_REQ: runtime model presented to an execution context that is
1138 allocated CPU cycles through FFA_MSG_SEND_DIRECT_REQ interface.
1139 - RTM_SEC_INTERRUPT: runtime model presented to an execution context that is
1140 allocated CPU cycles by SPMC to handle a secure interrupt.
1141 - RTM_SP_INIT: runtime model presented to an execution context that is
1142 allocated CPU cycles by SPMC to initialize its state.
1143
1144If an endpoint execution context attempts to make an invalid transition or a
1145valid transition that could lead to a loop in the call chain, SPMC denies the
1146transition with the help of above runtime models.
1147
1148Interrupt management
1149--------------------
1150
1151GIC ownership
1152~~~~~~~~~~~~~
1153
1154The SPMC owns the GIC configuration. Secure and non-secure interrupts are
1155trapped at S-EL2. The SPMC manages interrupt resources and allocates interrupt
1156IDs based on SP manifests. The SPMC acknowledges physical interrupts and injects
1157virtual interrupts by setting the use of vIRQ/vFIQ bits before resuming a SP.
1158
1159Abbreviations:
1160
1161 - NS-Int: A non-secure physical interrupt. It requires a switch to the normal
1162 world to be handled if it triggers while execution is in secure world.
1163 - Other S-Int: A secure physical interrupt targeted to an SP different from
1164 the one that is currently running.
1165 - Self S-Int: A secure physical interrupt targeted to the SP that is currently
1166 running.
1167
1168Non-secure interrupt handling
1169~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1170
1171This section documents the actions supported in SPMC in response to a non-secure
1172interrupt as per the guidance provided by FF-A v1.1 EAC0 specification.
1173An SP specifies one of the following actions in its partition manifest:
1174
1175 - Non-secure interrupt is signaled.
1176 - Non-secure interrupt is signaled after a managed exit.
1177 - Non-secure interrupt is queued.
1178
1179An SP execution context in a call chain could specify a less permissive action
1180than subsequent SP execution contexts in the same call chain. The less
1181permissive action takes precedence over the more permissive actions specified
1182by the subsequent execution contexts. Please refer to FF-A v1.1 EAC0 section
11838.3.1 for further explanation.
1184
1185Secure interrupt handling
1186~~~~~~~~~~~~~~~~~~~~~~~~~
1187
1188This section documents the support implemented for secure interrupt handling in
1189SPMC as per the guidance provided by FF-A v1.1 EAC0 specification.
1190The following assumptions are made about the system configuration:
1191
1192 - In the current implementation, S-EL1 SPs are expected to use the para
1193 virtualized ABIs for interrupt management rather than accessing the virtual
1194 GIC interface.
1195 - Unless explicitly stated otherwise, this support is applicable only for
1196 S-EL1 SPs managed by SPMC.
1197 - Secure interrupts are configured as G1S or G0 interrupts.
1198 - All physical interrupts are routed to SPMC when running a secure partition
1199 execution context.
1200 - All endpoints with multiple execution contexts have their contexts pinned
1201 to corresponding CPUs. Hence, a secure virtual interrupt cannot be signaled
1202 to a target vCPU that is currently running or blocked on a different
1203 physical CPU.
1204
1205A physical secure interrupt could trigger while CPU is executing in normal world
1206or secure world.
1207The action of SPMC for a secure interrupt depends on: the state of the target
1208execution context of the SP that is responsible for handling the interrupt;
1209whether the interrupt triggered while execution was in normal world or secure
1210world.
1211
1212Secure interrupt signaling mechanisms
1213~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1214
1215Signaling refers to the mechanisms used by SPMC to indicate to the SP execution
1216context that it has a pending virtual interrupt and to further run the SP
1217execution context, such that it can handle the virtual interrupt. SPMC uses
1218either the FFA_INTERRUPT interface with ERET conduit or vIRQ signal for signaling
1219to S-EL1 SPs. When normal world execution is preempted by a secure interrupt,
1220the SPMD uses the FFA_INTERRUPT ABI with ERET conduit to signal interrupt to SPMC
1221running in S-EL2.
1222
1223+-----------+---------+---------------+---------------------------------------+
1224| SP State | Conduit | Interface and | Description |
1225| | | parameters | |
1226+-----------+---------+---------------+---------------------------------------+
1227| WAITING | ERET, | FFA_INTERRUPT,| SPMC signals to SP the ID of pending |
1228| | vIRQ | Interrupt ID | interrupt. It pends vIRQ signal and |
1229| | | | resumes execution context of SP |
1230| | | | through ERET. |
1231+-----------+---------+---------------+---------------------------------------+
1232| BLOCKED | ERET, | FFA_INTERRUPT | SPMC signals to SP that an interrupt |
1233| | vIRQ | | is pending. It pends vIRQ signal and |
1234| | | | resumes execution context of SP |
1235| | | | through ERET. |
1236+-----------+---------+---------------+---------------------------------------+
1237| PREEMPTED | vIRQ | NA | SPMC pends the vIRQ signal but does |
1238| | | | not resume execution context of SP. |
1239+-----------+---------+---------------+---------------------------------------+
1240| RUNNING | ERET, | NA | SPMC pends the vIRQ signal and resumes|
1241| | vIRQ | | execution context of SP through ERET. |
1242+-----------+---------+---------------+---------------------------------------+
1243
1244Secure interrupt completion mechanisms
1245~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1246
1247A SP signals secure interrupt handling completion to the SPMC through the
1248following mechanisms:
1249
1250 - ``FFA_MSG_WAIT`` ABI if it was in WAITING state.
1251 - ``FFA_RUN`` ABI if its was in BLOCKED state.
1252
1253This is a remnant of SPMC implementation based on the FF-A v1.0 specification.
1254In the current implementation, S-EL1 SPs use the para-virtualized HVC interface
1255implemented by SPMC to perform priority drop and interrupt deactivation (SPMC
1256configures EOImode = 0, i.e. priority drop and deactivation are done together).
1257The SPMC performs checks to deny the state transition upon invocation of
1258either FFA_MSG_WAIT or FFA_RUN interface if the SP didn't perform the
1259deactivation of the secure virtual interrupt.
1260
1261If the current SP execution context was preempted by a secure interrupt to be
1262handled by execution context of target SP, SPMC resumes current SP after signal
1263completion by target SP execution context.
1264
1265Actions for a secure interrupt triggered while execution is in normal world
1266~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1267
1268+-------------------+----------+-----------------------------------------------+
1269| State of target | Action | Description |
1270| execution context | | |
1271+-------------------+----------+-----------------------------------------------+
1272| WAITING | Signaled | This starts a new call chain in SPMC scheduled|
1273| | | mode. |
1274+-------------------+----------+-----------------------------------------------+
1275| PREEMPTED | Queued | The target execution must have been preempted |
1276| | | by a non-secure interrupt. SPMC queues the |
1277| | | secure virtual interrupt now. It is signaled |
1278| | | when the target execution context next enters |
1279| | | the RUNNING state. |
1280+-------------------+----------+-----------------------------------------------+
1281| BLOCKED, RUNNING | NA | The target execution context is blocked or |
1282| | | running on a different CPU. This is not |
1283| | | supported by current SPMC implementation and |
1284| | | execution hits panic. |
1285+-------------------+----------+-----------------------------------------------+
1286
1287If normal world execution was preempted by a secure interrupt, SPMC uses
1288FFA_NORMAL_WORLD_RESUME ABI to indicate completion of secure interrupt handling
1289and further returns execution to normal world.
1290
1291The following figure describes interrupt handling flow when a secure interrupt
1292triggers while execution is in normal world:
1293
1294.. image:: ../resources/diagrams/ffa-secure-interrupt-handling-nwd.png
1295
1296A brief description of the events:
1297
1298 - 1) Secure interrupt triggers while normal world is running.
1299 - 2) FIQ gets trapped to EL3.
1300 - 3) SPMD signals secure interrupt to SPMC at S-EL2 using FFA_INTERRUPT ABI.
1301 - 4) SPMC identifies target vCPU of SP and injects virtual interrupt (pends
1302 vIRQ).
1303 - 5) Assuming SP1 vCPU is in WAITING state, SPMC signals virtual interrupt
1304 using FFA_INTERRUPT with interrupt id as an argument and resumes the SP1
1305 vCPU using ERET in SPMC scheduled mode.
1306 - 6) Execution traps to vIRQ handler in SP1 provided that the virtual
1307 interrupt is not masked i.e., PSTATE.I = 0
1308 - 7) SP1 queries for the pending virtual interrupt id using a paravirtualized
1309 HVC call. SPMC clears the pending virtual interrupt state management
1310 and returns the pending virtual interrupt id.
1311 - 8) SP1 services the virtual interrupt and invokes the paravirtualized
1312 de-activation HVC call. SPMC de-activates the physical interrupt,
1313 clears the fields tracking the secure interrupt and resumes SP1 vCPU.
1314 - 9) SP1 performs secure interrupt completion through FFA_MSG_WAIT ABI.
1315 - 10) SPMC returns control to EL3 using FFA_NORMAL_WORLD_RESUME.
1316 - 11) EL3 resumes normal world execution.
1317
1318Actions for a secure interrupt triggered while execution is in secure world
1319~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1320
1321+-------------------+----------+------------------------------------------------+
1322| State of target | Action | Description |
1323| execution context | | |
1324+-------------------+----------+------------------------------------------------+
1325| WAITING | Signaled | This starts a new call chain in SPMC scheduled |
1326| | | mode. |
1327+-------------------+----------+------------------------------------------------+
1328| PREEMPTED by Self | Signaled | The target execution context reenters the |
1329| S-Int | | RUNNING state to handle the secure virtual |
1330| | | interrupt. |
1331+-------------------+----------+------------------------------------------------+
1332| PREEMPTED by | Queued | SPMC queues the secure virtual interrupt now. |
1333| NS-Int | | It is signaled when the target execution |
1334| | | context next enters the RUNNING state. |
1335+-------------------+----------+------------------------------------------------+
1336| BLOCKED | Signaled | Both preempted and target execution contexts |
1337| | | must have been part of the Normal world |
1338| | | scheduled call chain. Refer scenario 1 of |
1339| | | Table 8.4 in the FF-A v1.1 EAC0 spec. |
1340+-------------------+----------+------------------------------------------------+
1341| RUNNING | NA | The target execution context is running on a |
1342| | | different CPU. This scenario is not supported |
1343| | | by current SPMC implementation and execution |
1344| | | hits panic. |
1345+-------------------+----------+------------------------------------------------+
1346
1347The following figure describes interrupt handling flow when a secure interrupt
1348triggers while execution is in secure world. We assume OS kernel sends a direct
1349request message to SP1. Further, SP1 sends a direct request message to SP2. SP1
1350enters BLOCKED state and SPMC resumes SP2.
1351
1352.. image:: ../resources/diagrams/ffa-secure-interrupt-handling-swd.png
1353
1354A brief description of the events:
1355
1356 - 1) Secure interrupt triggers while SP2 is running.
1357 - 2) SP2 gets preempted and execution traps to SPMC as IRQ.
1358 - 3) SPMC finds the target vCPU of secure partition responsible for handling
1359 this secure interrupt. In this scenario, it is SP1.
1360 - 4) SPMC pends vIRQ for SP1 and signals through FFA_INTERRUPT interface.
1361 SPMC further resumes SP1 through ERET conduit. Note that SP1 remains in
1362 Normal world schedule mode.
1363 - 6) Execution traps to vIRQ handler in SP1 provided that the virtual
1364 interrupt is not masked i.e., PSTATE.I = 0
1365 - 7) SP1 queries for the pending virtual interrupt id using a paravirtualized
1366 HVC call. SPMC clears the pending virtual interrupt state management
1367 and returns the pending virtual interrupt id.
1368 - 8) SP1 services the virtual interrupt and invokes the paravirtualized
1369 de-activation HVC call. SPMC de-activates the physical interrupt and
1370 clears the fields tracking the secure interrupt and resumes SP1 vCPU.
1371 - 9) Since SP1 direct request completed with FFA_INTERRUPT, it resumes the
1372 direct request to SP2 by invoking FFA_RUN.
1373 - 9) SPMC resumes the pre-empted vCPU of SP2.
1374
1375EL3 interrupt handling
1376~~~~~~~~~~~~~~~~~~~~~~
1377
1378In GICv3 based systems, EL3 interrupts are configured as Group0 secure
1379interrupts. Execution traps to SPMC when a Group0 interrupt triggers while an
1380SP is running. Further, SPMC running at S-EL2 uses FFA_EL3_INTR_HANDLE ABI to
1381request EL3 platform firmware to handle a pending Group0 interrupt.
1382Similarly, SPMD registers a handler with interrupt management framework to
1383delegate handling of Group0 interrupt to the platform if the interrupt triggers
1384in normal world.
1385
1386 - Platform hook
1387
1388 - plat_spmd_handle_group0_interrupt
1389
1390 SPMD provides platform hook to handle Group0 secure interrupts. In the
1391 current design, SPMD expects the platform not to delegate handling to the
1392 NWd (such as through SDEI) while processing Group0 interrupts.
1393
1394Power management
1395----------------
1396
1397In platforms with or without secure virtualization:
1398
1399- The NWd owns the platform PM policy.
1400- The Hypervisor or OS kernel is the component initiating PSCI service calls.
1401- The EL3 PSCI library is in charge of the PM coordination and control
1402 (eventually writing to platform registers).
1403- While coordinating PM events, the PSCI library calls backs into the Secure
1404 Payload Dispatcher for events the latter has statically registered to.
1405
1406When using the SPMD as a Secure Payload Dispatcher:
1407
1408- A power management event is relayed through the SPD hook to the SPMC.
1409- In the current implementation only cpu on (svc_on_finish) and cpu off
1410 (svc_off) hooks are registered.
1411- The behavior for the cpu on event is described in `Secondary cores boot-up`_.
1412 The SPMC is entered through its secondary physical core entry point.
1413- The cpu off event occurs when the NWd calls PSCI_CPU_OFF. The PM event is
1414 signaled to the SPMC through a power management framework message.
1415 It consists in a SPMD-to-SPMC direct request/response (`SPMC-SPMD direct
1416 requests/responses`_) conveying the event details and SPMC response.
1417 The SPMD performs a synchronous entry into the SPMC. The SPMC is entered and
1418 updates its internal state to reflect the physical core is being turned off.
1419 In the current implementation no SP is resumed as a consequence. This behavior
1420 ensures a minimal support for CPU hotplug e.g. when initiated by the NWd linux
1421 userspace.
1422
1423Arm architecture extensions for security hardening
J-Alves5eafd222023-10-26 14:19:21 +01001424--------------------------------------------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001425
1426Hafnium supports the following architecture extensions for security hardening:
1427
1428- Pointer authentication (FEAT_PAuth): the extension permits detection of forged
1429 pointers used by ROP type of attacks through the signing of the pointer
1430 value. Hafnium is built with the compiler branch protection option to permit
1431 generation of a pointer authentication code for return addresses (pointer
1432 authentication for instructions). The APIA key is used while Hafnium runs.
1433 A random key is generated at boot time and restored upon entry into Hafnium
1434 at run-time. APIA and other keys (APIB, APDA, APDB, APGA) are saved/restored
1435 in vCPU contexts permitting to enable pointer authentication in VMs/SPs.
1436- Branch Target Identification (FEAT_BTI): the extension permits detection of
1437 unexpected indirect branches used by JOP type of attacks. Hafnium is built
1438 with the compiler branch protection option, inserting land pads at function
1439 prologues that are reached by indirect branch instructions (BR/BLR).
1440 Hafnium code pages are marked as guarded in the EL2 Stage-1 MMU descriptors
1441 such that an indirect branch must always target a landpad. A fault is
1442 triggered otherwise. VMs/SPs can (independently) mark their code pages as
1443 guarded in the EL1&0 Stage-1 translation regime.
1444- Memory Tagging Extension (FEAT_MTE): the option permits detection of out of
1445 bound memory array accesses or re-use of an already freed memory region.
1446 Hafnium enables the compiler option permitting to leverage MTE stack tagging
1447 applied to core stacks. Core stacks are marked as normal tagged memory in the
1448 EL2 Stage-1 translation regime. A synchronous data abort is generated upon tag
1449 check failure on load/stores. A random seed is generated at boot time and
1450 restored upon entry into Hafnium. MTE system registers are saved/restored in
1451 vCPU contexts permitting MTE usage from VMs/SPs.
1452
1453SMMUv3 support in Hafnium
J-Alves5eafd222023-10-26 14:19:21 +01001454-------------------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001455
1456An SMMU is analogous to an MMU in a CPU. It performs address translations for
1457Direct Memory Access (DMA) requests from system I/O devices.
1458The responsibilities of an SMMU include:
1459
1460- Translation: Incoming DMA requests are translated from bus address space to
1461 system physical address space using translation tables compliant to
1462 Armv8/Armv7 VMSA descriptor format.
1463- Protection: An I/O device can be prohibited from read, write access to a
1464 memory region or allowed.
1465- Isolation: Traffic from each individial device can be independently managed.
1466 The devices are differentiated from each other using unique translation
1467 tables.
1468
1469The following diagram illustrates a typical SMMU IP integrated in a SoC with
1470several I/O devices along with Interconnect and Memory system.
1471
1472.. image:: ../resources/diagrams/MMU-600.png
1473
1474SMMU has several versions including SMMUv1, SMMUv2 and SMMUv3. Hafnium provides
1475support for SMMUv3 driver in both normal and secure world. A brief introduction
1476of SMMUv3 functionality and the corresponding software support in Hafnium is
1477provided here.
1478
1479SMMUv3 features
J-Alves5eafd222023-10-26 14:19:21 +01001480~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001481
1482- SMMUv3 provides Stage1, Stage2 translation as well as nested (Stage1 + Stage2)
1483 translation support. It can either bypass or abort incoming translations as
1484 well.
1485- Traffic (memory transactions) from each upstream I/O peripheral device,
1486 referred to as Stream, can be independently managed using a combination of
1487 several memory based configuration structures. This allows the SMMUv3 to
1488 support a large number of streams with each stream assigned to a unique
1489 translation context.
1490- Support for Armv8.1 VMSA where the SMMU shares the translation tables with
1491 a Processing Element. AArch32(LPAE) and AArch64 translation table format
1492 are supported by SMMUv3.
1493- SMMUv3 offers non-secure stream support with secure stream support being
1494 optional. Logically, SMMUv3 behaves as if there is an indepdendent SMMU
1495 instance for secure and non-secure stream support.
1496- It also supports sub-streams to differentiate traffic from a virtualized
1497 peripheral associated with a VM/SP.
1498- Additionally, SMMUv3.2 provides support for PEs implementing Armv8.4-A
1499 extensions. Consequently, SPM depends on Secure EL2 support in SMMUv3.2
1500 for providing Secure Stage2 translation support to upstream peripheral
1501 devices.
1502
1503SMMUv3 Programming Interfaces
J-Alves5eafd222023-10-26 14:19:21 +01001504~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001505
1506SMMUv3 has three software interfaces that are used by the Hafnium driver to
1507configure the behaviour of SMMUv3 and manage the streams.
1508
1509- Memory based data strutures that provide unique translation context for
1510 each stream.
1511- Memory based circular buffers for command queue and event queue.
1512- A large number of SMMU configuration registers that are memory mapped during
1513 boot time by Hafnium driver. Except a few registers, all configuration
1514 registers have independent secure and non-secure versions to configure the
1515 behaviour of SMMUv3 for translation of secure and non-secure streams
1516 respectively.
1517
1518Peripheral device manifest
J-Alves5eafd222023-10-26 14:19:21 +01001519~~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001520
1521Currently, SMMUv3 driver in Hafnium only supports dependent peripheral devices.
1522These devices are dependent on PE endpoint to initiate and receive memory
1523management transactions on their behalf. The acccess to the MMIO regions of
1524any such device is assigned to the endpoint during boot. Moreover, SMMUv3 driver
1525uses the same stage 2 translations for the device as those used by partition
1526manager on behalf of the PE endpoint. This ensures that the peripheral device
1527has the same visibility of the physical address space as the endpoint. The
1528device node of the corresponding partition manifest (refer to `[1]`_ section 3.2
1529) must specify these additional properties for each peripheral device in the
1530system :
1531
1532- smmu-id: This field helps to identify the SMMU instance that this device is
1533 upstream of.
1534- stream-ids: List of stream IDs assigned to this device.
1535
1536.. code:: shell
1537
1538 smmuv3-testengine {
1539 base-address = <0x00000000 0x2bfe0000>;
1540 pages-count = <32>;
1541 attributes = <0x3>;
1542 smmu-id = <0>;
1543 stream-ids = <0x0 0x1>;
1544 interrupts = <0x2 0x3>, <0x4 0x5>;
1545 exclusive-access;
1546 };
1547
1548SMMUv3 driver limitations
J-Alves5eafd222023-10-26 14:19:21 +01001549~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001550
1551The primary design goal for the Hafnium SMMU driver is to support secure
1552streams.
1553
1554- Currently, the driver only supports Stage2 translations. No support for
1555 Stage1 or nested translations.
1556- Supports only AArch64 translation format.
1557- No support for features such as PCI Express (PASIDs, ATS, PRI), MSI, RAS,
1558 Fault handling, Performance Monitor Extensions, Event Handling, MPAM.
1559- No support for independent peripheral devices.
1560
1561S-EL0 Partition support
J-Alves5eafd222023-10-26 14:19:21 +01001562-----------------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001563The SPMC (Hafnium) has limited capability to run S-EL0 FF-A partitions using
1564FEAT_VHE (mandatory with ARMv8.1 in non-secure state, and in secure world
1565with ARMv8.4 and FEAT_SEL2).
1566
1567S-EL0 partitions are useful for simple partitions that don't require full
1568Trusted OS functionality. It is also useful to reduce jitter and cycle
1569stealing from normal world since they are more lightweight than VMs.
1570
1571S-EL0 partitions are presented, loaded and initialized the same as S-EL1 VMs by
1572the SPMC. They are differentiated primarily by the 'exception-level' property
1573and the 'execution-ctx-count' property in the SP manifest. They are host apps
1574under the single EL2&0 Stage-1 translation regime controlled by the SPMC and
1575call into the SPMC through SVCs as opposed to HVCs and SMCs. These partitions
1576can use FF-A defined services (FFA_MEM_PERM_*) to update or change permissions
1577for memory regions.
1578
1579S-EL0 partitions are required by the FF-A specification to be UP endpoints,
1580capable of migrating, and the SPMC enforces this requirement. The SPMC allows
1581a S-EL0 partition to accept a direct message from secure world and normal world,
1582and generate direct responses to them.
1583All S-EL0 partitions must use AArch64. AArch32 S-EL0 partitions are not supported.
1584
1585Memory sharing, indirect messaging, and notifications functionality with S-EL0
1586partitions is supported.
1587
1588Interrupt handling is not supported with S-EL0 partitions and is work in
1589progress.
1590
1591References
1592==========
1593
J-Alves5eafd222023-10-26 14:19:21 +01001594.. _TF-A project: https://trustedfirmware-a.readthedocs.io/en/latest/
1595
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001596.. _[1]:
1597
1598[1] `Arm Firmware Framework for Arm A-profile <https://developer.arm.com/docs/den0077/latest>`__
1599
1600.. _[2]:
1601
1602[2] `Secure Partition Manager using MM interface <https://trustedfirmware-a.readthedocs.io/en/latest/components/secure-partition-manager-mm.html>`__
1603
1604.. _[3]:
1605
1606[3] `Trusted Boot Board Requirements
1607Client <https://developer.arm.com/documentation/den0006/d/>`__
1608
1609.. _[4]:
1610
1611[4] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/lib/el3_runtime/aarch64/context.S#n45
1612
1613.. _[5]:
1614
1615[5] https://git.trustedfirmware.org/TF-A/tf-a-tests.git/tree/spm/cactus/plat/arm/fvp/fdts/cactus.dts
1616
1617.. _[6]:
1618
1619[6] https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html
1620
1621.. _[7]:
1622
1623[7] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/arm/board/fvp/fdts/fvp_spmc_manifest.dts
1624
1625.. _[8]:
1626
1627[8] https://lists.trustedfirmware.org/archives/list/tf-a@lists.trustedfirmware.org/thread/CFQFGU6H2D5GZYMUYGTGUSXIU3OYZP6U/
1628
1629.. _[9]:
1630
1631[9] https://trustedfirmware-a.readthedocs.io/en/latest/design/firmware-design.html#dynamic-configuration-during-cold-boot
1632
J-Alvesd8094162023-10-26 12:44:33 +01001633.. _[10]:
1634
1635[10] https://trustedfirmware-a.readthedocs.io/en/latest/getting_started/build-options.html#
1636
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001637--------------
1638
1639*Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.*