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