Olivier Deprez | ecb2fe5 | 2020-04-02 15:38:02 +0200 | [diff] [blame] | 1 | Secure Partition Manager |
| 2 | ************************ |
| 3 | |
| 4 | .. contents:: |
| 5 | |
| 6 | Acronyms |
| 7 | ======== |
| 8 | |
| 9 | +--------+-----------------------------------+ |
| 10 | | DTB | Device Tree Blob | |
| 11 | +--------+-----------------------------------+ |
| 12 | | DTS | Device Tree Source | |
| 13 | +--------+-----------------------------------+ |
| 14 | | EC | Execution Context | |
| 15 | +--------+-----------------------------------+ |
| 16 | | FIP | Firmware Image Package | |
| 17 | +--------+-----------------------------------+ |
| 18 | | FF-A | Firmware Framework for A-class | |
| 19 | +--------+-----------------------------------+ |
| 20 | | IPA | Intermediate Physical Address | |
| 21 | +--------+-----------------------------------+ |
| 22 | | NWd | Normal World | |
| 23 | +--------+-----------------------------------+ |
| 24 | | ODM | Original Design Manufacturer | |
| 25 | +--------+-----------------------------------+ |
| 26 | | OEM | Original Equipment Manufacturer | |
| 27 | +--------+-----------------------------------+ |
| 28 | | PA | Physical Address | |
| 29 | +--------+-----------------------------------+ |
| 30 | | PE | Processing Element | |
| 31 | +--------+-----------------------------------+ |
| 32 | | PVM | Primary VM | |
| 33 | +--------+-----------------------------------+ |
| 34 | | PSA | Platform Security Architecture | |
| 35 | +--------+-----------------------------------+ |
| 36 | | SP | Secure Partition | |
| 37 | +--------+-----------------------------------+ |
| 38 | | SPM | Secure Partition Manager | |
| 39 | +--------+-----------------------------------+ |
| 40 | | SPMC | SPM Core | |
| 41 | +--------+-----------------------------------+ |
| 42 | | SPMD | SPM Dispatcher | |
| 43 | +--------+-----------------------------------+ |
| 44 | | SiP | Silicon Provider | |
| 45 | +--------+-----------------------------------+ |
| 46 | | SWd | Secure World | |
| 47 | +--------+-----------------------------------+ |
| 48 | | TLV | Tag-Length-Value | |
| 49 | +--------+-----------------------------------+ |
| 50 | | TOS | Trusted Operating System | |
| 51 | +--------+-----------------------------------+ |
| 52 | | VM | Virtual Machine | |
| 53 | +--------+-----------------------------------+ |
| 54 | |
| 55 | Foreword |
| 56 | ======== |
| 57 | |
| 58 | Two implementations of a Secure Partition Manager co-exist in the TF-A codebase: |
| 59 | |
| 60 | - SPM based on the PSA FF-A specification `[1]`_. |
| 61 | - SPM based on the MM interface to communicate with an S-EL0 partition `[2]`_. |
| 62 | |
| 63 | Both implementations differ in their architectures and only one can be selected |
| 64 | at build time. |
| 65 | |
| 66 | This document: |
| 67 | |
| 68 | - describes the PSA FF-A implementation where the Secure Partition Manager |
| 69 | resides at EL3 and S-EL2 (or EL3 and S-EL1). |
| 70 | - is not an architecture specification and it might provide assumptions |
| 71 | on sections mandated as implementation-defined in the specification. |
| 72 | - covers the implications to TF-A used as a bootloader, and Hafnium |
| 73 | used as a reference code base for an S-EL2 secure firmware on |
| 74 | platforms implementing Armv8.4-SecEL2. |
| 75 | |
| 76 | Terminology |
| 77 | ----------- |
| 78 | |
| 79 | - Hypervisor refers to the NS-EL2 component managing Virtual Machines (or |
| 80 | partitions) in the Normal World. |
| 81 | - SPMC refers to the S-EL2 component managing Virtual Machines (or Secure |
| 82 | Partitions) in the Secure World when Armv8.4-SecEL2 extension is implemented. |
| 83 | - Alternatively, SPMC can refer to an S-EL1 component, itself being a Secure |
| 84 | Partition and implementing the FF-A ABI on pre-Armv8.4 platforms. |
| 85 | - VM refers to a Normal World Virtual Machine managed by an Hypervisor. |
| 86 | - SP refers to a Secure World "Virtual Machine" managed by the SPMC component. |
| 87 | |
| 88 | Support for legacy platforms |
| 89 | ---------------------------- |
| 90 | |
| 91 | In the implementation, the SPM is split into SPMD and SPMC components |
| 92 | (although not strictly mandated by the specification). SPMD is located |
| 93 | at EL3 and principally relays FF-A messages from NWd (Hypervisor or OS |
| 94 | kernel) to SPMC located either at S-EL1 or S-EL2. |
| 95 | |
| 96 | Hence TF-A must support both cases where SPMC is either located at: |
| 97 | |
| 98 | - S-EL1 supporting pre-Armv8.4 platforms. SPMD conveys FF-A protocol |
| 99 | from EL3 to S-EL1. |
| 100 | - S-EL2 supporting platforms implementing Armv8.4-SecEL2 extension. |
| 101 | SPMD conveys FF-A protocol from EL3 to S-EL2. |
| 102 | |
| 103 | The same SPMD component is used to support both configurations. The SPMC |
| 104 | execution level is a build time choice. |
| 105 | |
| 106 | Sample reference stack |
| 107 | ====================== |
| 108 | |
| 109 | The following diagram illustrates a possible configuration with SPMD and SPMC, |
| 110 | one or multiple Secure Partitions, with or without an optional Hypervisor: |
| 111 | |
| 112 | .. image:: ../resources/diagrams/ff-a-spm-sel2.png |
| 113 | |
| 114 | TF-A build options |
| 115 | ================== |
| 116 | |
| 117 | The following TF-A build options are provisioned: |
| 118 | |
| 119 | - **SPD=spmd**: this option selects the SPMD component to relay FF-A |
| 120 | protocol from NWd to SWd back and forth. It is not possible to |
| 121 | enable another Secure Payload Dispatcher when this option is chosen. |
| 122 | - **SPMD_SPM_AT_SEL2**: this option adjusts the SPMC execution |
| 123 | level to being S-EL1 or S-EL2. It defaults to enabled (value 1) when |
| 124 | SPD=spmd is chosen. |
| 125 | - **CTX_INCLUDE_EL2_REGS**: this option permits saving (resp. |
| 126 | restoring) the EL2 system register context before entering (resp. |
| 127 | after leaving) the SPMC. It is mandatory when ``SPMD_SPM_AT_SEL2`` is |
| 128 | enabled. The context save/restore routine and exhaustive list of |
Madhukar Pappireddy | 423d18c | 2020-08-06 12:36:17 -0500 | [diff] [blame] | 129 | registers is visible at `[4]`_. |
Olivier Deprez | ecb2fe5 | 2020-04-02 15:38:02 +0200 | [diff] [blame] | 130 | - **SP_LAYOUT_FILE**: this option provides a text description file |
| 131 | providing paths to SP binary images and DTS format manifests |
| 132 | (see `Specifying partition binary image and DT`_). It |
| 133 | is required when ``SPMD_SPM_AT_SEL2`` is enabled hence when multiple |
| 134 | secure partitions are to be loaded on behalf of SPMC. |
| 135 | |
| 136 | +------------------------------+----------------------+------------------+ |
| 137 | | | CTX_INCLUDE_EL2_REGS | SPMD_SPM_AT_SEL2 | |
| 138 | +------------------------------+----------------------+------------------+ |
| 139 | | SPMC at S-EL1 (e.g. OP-TEE) | 0 | 0 | |
| 140 | +------------------------------+----------------------+------------------+ |
| 141 | | SPMC at S-EL2 (e.g. Hafnium) | 1 | 1 (default when | |
| 142 | | | | SPD=spmd) | |
| 143 | +------------------------------+----------------------+------------------+ |
| 144 | |
| 145 | Other combinations of such build options either break the build or are not |
| 146 | supported. |
| 147 | |
| 148 | Note, the ``CTX_INCLUDE_EL2_REGS`` option provides the generic support for |
| 149 | barely saving/restoring EL2 registers from an Arm arch perspective. As such |
| 150 | it is decoupled from the ``SPD=spmd`` option. |
| 151 | |
| 152 | BL32 option is re-purposed to specify the SPMC image. It can specify either the |
| 153 | Hafnium binary path (built for the secure world) or the path to a TEE binary |
| 154 | implementing the FF-A protocol. |
| 155 | |
| 156 | BL33 option can specify either: |
| 157 | |
| 158 | - the TFTF binary or |
| 159 | - the Hafnium binary path (built for the normal world) if VMs were loaded by |
| 160 | TF-A beforehand or |
| 161 | - a minimal loader performing the loading of VMs and Hafnium. |
| 162 | |
| 163 | Sample TF-A build command line when SPMC is located at S-EL1 |
| 164 | (typically pre-Armv8.4): |
| 165 | |
| 166 | .. code:: shell |
| 167 | |
| 168 | make \ |
| 169 | CROSS_COMPILE=aarch64-none-elf- \ |
| 170 | SPD=spmd \ |
| 171 | SPMD_SPM_AT_SEL2=0 \ |
| 172 | BL32=<path-to-tee-binary> \ |
| 173 | BL33=<path-to-nwd-binary> \ |
| 174 | PLAT=fvp \ |
| 175 | all fip |
| 176 | |
| 177 | Sample TF-A build command line for an Armv8.4-SecEL2 enabled system |
| 178 | where SPMC is located at S-EL2: |
| 179 | |
| 180 | .. code:: shell |
| 181 | |
| 182 | make \ |
| 183 | CROSS_COMPILE=aarch64-none-elf- \ |
| 184 | SPD=spmd \ |
| 185 | CTX_INCLUDE_EL2_REGS=1 \ |
| 186 | ARM_ARCH_MINOR=4 \ |
| 187 | BL32=<path-to-swd-hafnium-binary> |
| 188 | BL33=<path-to-nwd-binary> \ |
| 189 | SP_LAYOUT_FILE=sp_layout.json \ |
| 190 | PLAT=fvp \ |
| 191 | all fip |
| 192 | |
| 193 | Build options to enable secure boot: |
| 194 | |
| 195 | .. code:: shell |
| 196 | |
| 197 | make \ |
| 198 | CROSS_COMPILE=aarch64-none-elf- \ |
| 199 | SPD=spmd \ |
| 200 | CTX_INCLUDE_EL2_REGS=1 \ |
| 201 | ARM_ARCH_MINOR=4 \ |
| 202 | BL32=<path-to-swd-hafnium-binary> |
| 203 | BL33=<path-to-nwd-binary> \ |
| 204 | SP_LAYOUT_FILE=../tf-a-tests/build/fvp/debug/sp_layout.json \ |
| 205 | MBEDTLS_DIR=<path-to-mbedtls-lib> \ |
| 206 | TRUSTED_BOARD_BOOT=1 \ |
| 207 | COT=dualroot \ |
| 208 | ARM_ROTPK_LOCATION=devel_rsa \ |
| 209 | ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem \ |
| 210 | GENERATE_COT=1 \ |
| 211 | PLAT=fvp \ |
| 212 | all fip |
| 213 | |
| 214 | Boot process |
| 215 | ============ |
| 216 | |
| 217 | Loading Hafnium and Secure Partitions in the secure world |
| 218 | --------------------------------------------------------- |
| 219 | |
| 220 | The Hafnium implementation in normal world requires VMs to be loaded in |
| 221 | memory prior to booting. The mechanism upon which VMs are loaded and |
| 222 | exposed to Hafnium are either: |
| 223 | |
| 224 | - by supplying a ramdisk image where VM images are concatenated (1) |
| 225 | - or by providing VM load addresses within Hafnium manifest (2) |
| 226 | |
| 227 | TF-A is the bootlader for the Hafnium and SPs in the secure world. TF-A |
| 228 | does not provide tooling or libraries manipulating ramdisks as required |
| 229 | by (1). Thus BL2 loads SPs payloads independently. |
| 230 | SPs may be signed by different parties (SiP, OEM/ODM, TOS vendor, etc.). |
| 231 | Thus they are supplied as distinct āself-containedā signed entities within |
| 232 | the FIP flash image. The FIP image itself is not signed hence providing |
| 233 | ability to upgrade SPs in the field. |
| 234 | |
| 235 | Booting through TF-A |
| 236 | -------------------- |
| 237 | |
| 238 | SP manifests |
| 239 | ~~~~~~~~~~~~ |
| 240 | |
| 241 | An SP manifest describes SP attributes as defined in `[1]`_ |
| 242 | section 3.1 (partition manifest at virtual FF-A instance) in DTS text format. It |
| 243 | is represented as a single file associated with the SP. A sample is |
| 244 | provided by `[5]`_. A binding document is provided by `[6]`_. |
| 245 | |
| 246 | Secure Partition packages |
| 247 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 248 | |
| 249 | Secure Partitions are bundled as independent package files consisting |
| 250 | of: |
| 251 | |
| 252 | - a header |
| 253 | - a DTB |
| 254 | - an image payload |
| 255 | |
| 256 | The header starts with a magic value and offset values to SP DTB and |
| 257 | image payload. Each SP package is loaded independently by BL2 loader |
| 258 | and verified for authenticity and integrity. |
| 259 | |
| 260 | The SP package identified by its UUID (matching FF-A uuid) is inserted |
| 261 | as a single entry into the FIP at end of the TF-A build flow as shown: |
| 262 | |
| 263 | .. code:: shell |
| 264 | |
| 265 | Trusted Boot Firmware BL2: offset=0x1F0, size=0x8AE1, cmdline="--tb-fw" |
| 266 | EL3 Runtime Firmware BL31: offset=0x8CD1, size=0x13000, cmdline="--soc-fw" |
| 267 | Secure Payload BL32 (Trusted OS): offset=0x1BCD1, size=0x15270, cmdline="--tos-fw" |
| 268 | Non-Trusted Firmware BL33: offset=0x30F41, size=0x92E0, cmdline="--nt-fw" |
| 269 | HW_CONFIG: offset=0x3A221, size=0x2348, cmdline="--hw-config" |
| 270 | TB_FW_CONFIG: offset=0x3C569, size=0x37A, cmdline="--tb-fw-config" |
| 271 | SOC_FW_CONFIG: offset=0x3C8E3, size=0x48, cmdline="--soc-fw-config" |
| 272 | TOS_FW_CONFIG: offset=0x3C92B, size=0x427, cmdline="--tos-fw-config" |
| 273 | NT_FW_CONFIG: offset=0x3CD52, size=0x48, cmdline="--nt-fw-config" |
| 274 | B4B5671E-4A90-4FE1-B81F-FB13DAE1DACB: offset=0x3CD9A, size=0xC168, cmdline="--blob" |
| 275 | D1582309-F023-47B9-827C-4464F5578FC8: offset=0x48F02, size=0xC168, cmdline="--blob" |
| 276 | |
| 277 | .. uml:: ../resources/diagrams/plantuml/fip-secure-partitions.puml |
| 278 | |
| 279 | Specifying partition binary image and DT |
| 280 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 281 | |
| 282 | A description file (json format) is passed to the build flow specifying |
| 283 | paths to the SP binary image and associated DTS partition manifest file. |
| 284 | The latter is going through the dtc compiler to generate the dtb fed into |
| 285 | the SP package. |
| 286 | |
| 287 | .. code:: shell |
| 288 | |
| 289 | { |
| 290 | "tee1" : { |
| 291 | "image": "tee1.bin", |
| 292 | "pm": "tee1.dts" |
| 293 | }, |
| 294 | |
| 295 | "tee2" : { |
| 296 | "image": "tee2.bin", |
| 297 | "pm": "tee2.dts" |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | SPMC manifest |
| 302 | ~~~~~~~~~~~~~ |
| 303 | |
| 304 | This manifest contains an SPMC attributes node consumed by SPMD at boot time. It |
| 305 | is implementing the description from `[1]`_ section 3.2 (SP manifest at physical |
| 306 | FF-A instance). The SP manifest at physical FF-A instance is used by the SPMD to |
| 307 | setup a SP that co-resides with the SPMC and executes at S-EL1 or Secure |
| 308 | Supervisor mode. |
| 309 | |
| 310 | In this implementation its usage is extended to the secure physical FF-A |
| 311 | instance where SPMC executes at S-EL2. |
| 312 | |
| 313 | .. code:: shell |
| 314 | |
| 315 | attribute { |
| 316 | spmc_id = <0x8000>; |
| 317 | maj_ver = <0x1>; |
| 318 | min_ver = <0x0>; |
| 319 | exec_state = <0x0>; |
| 320 | load_address = <0x0 0x6000000>; |
| 321 | entrypoint = <0x0 0x6000000>; |
| 322 | binary_size = <0x60000>; |
| 323 | }; |
| 324 | |
| 325 | - *spmc_id* defines the endpoint ID value that SPMC can query through |
| 326 | ``FFA_ID_GET``. |
| 327 | - *maj_ver/min_ver*. SPMD checks provided version versus its internal |
| 328 | version and aborts if not matching. |
| 329 | - *exec_state* defines SPMC execution state (can be AArch64 for |
| 330 | Hafnium, or AArch64/AArch32 for OP-TEE at S-EL1). |
| 331 | - *load_address* and *binary_size* are mostly used to verify secondary |
| 332 | entry points fit into the loaded binary image. |
| 333 | - *entrypoint* defines the cold boot primary core entry point used by |
| 334 | SPMD (currently matches ``BL32_BASE``) |
| 335 | |
| 336 | Other nodes in the manifest are consumed by Hafnium in the secure world. |
| 337 | A sample can be found at [7]: |
| 338 | |
| 339 | - The *chosen* node is currently unused in SWd. It is meant for NWd to |
| 340 | specify the init ramdisk image. |
| 341 | - The *hypervisor* node describes SPs. *is_ffa_partition* boolean |
| 342 | attribute indicates an SP. Load-addr field specifies the load address |
| 343 | at which TF-A loaded the SP package. |
| 344 | - *cpus* node provide the platform topology and allows MPIDR to VMPIDR |
| 345 | mapping. Notice with current implementation primary cpu is declared |
| 346 | first, then secondary cpus must be declared in reverse order. |
| 347 | |
| 348 | SPMC boot |
| 349 | ~~~~~~~~~ |
| 350 | |
| 351 | The SPMC is loaded by BL2 as the BL32 image. |
| 352 | |
| 353 | The SPMC manifest is loaded by BL2 as the ``TOS_FW_CONFIG`` image. |
| 354 | |
| 355 | BL2 passes the SPMC manifest address to BL31 through a register. |
| 356 | |
| 357 | BL31(SPMD) runs from primary core, initializes the core contexts and |
| 358 | launches BL32 passing the SPMC manifest address through a register. |
| 359 | |
| 360 | Loading of SPs |
| 361 | ~~~~~~~~~~~~~~ |
| 362 | |
| 363 | .. uml:: ../resources/diagrams/plantuml/bl2-loading-sp.puml |
| 364 | |
| 365 | |
| 366 | Notice this boot flow is an implementation sample on Arm's FVP platform. Platforms |
| 367 | not using FW_CONFIG would adjust to a different implementation. |
| 368 | |
| 369 | Secure boot |
| 370 | ~~~~~~~~~~~ |
| 371 | |
| 372 | The SP content certificate is inserted as a separate FIP item so that BL2 loads SPMC, |
| 373 | SPMC manifest and Secure Partitions and verifies them for authenticity and integrity. |
| 374 | Refer to TBBR specification `[3]`_. |
| 375 | |
| 376 | The multiple-signing domain feature (in current state dual signing domain) allows |
| 377 | the use of two root keys namely S-ROTPK and NS-ROTPK (see `[8]`_): |
| 378 | |
| 379 | - SPMC(BL32), SPMC manifest, SPs may be signed by the SiP using the S-ROTPK. |
| 380 | - BL33 may be signed by the OEM using NS-ROTPK. |
| 381 | |
| 382 | Longer term multiple signing domain will allow additional signing keys, e.g. |
| 383 | if SPs originate from different parties. |
| 384 | |
| 385 | See `TF-A build options`_ for a sample build command line. |
| 386 | |
| 387 | Hafnium in the secure world |
| 388 | =========================== |
| 389 | |
| 390 | **NOTE: this section is work in progress. Descriptions and implementation choices |
| 391 | are subject to evolve.** |
| 392 | |
| 393 | General considerations |
| 394 | ---------------------- |
| 395 | |
| 396 | Build platform for the secure world |
| 397 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 398 | |
| 399 | The implementation might add specific code parts only relevant to the |
| 400 | secure world. Such code parts might be isolated into different files |
| 401 | and/or conditional code enclosed by a ``SECURE_WORLD`` macro. |
| 402 | |
| 403 | Secure Partitions CPU scheduling |
| 404 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 405 | |
| 406 | In the normal world, VMs are scheduled by the FFA_RUN ABI invoked from the |
| 407 | primary scheduler (in the primary VM), or by a direct message request or |
| 408 | response. |
| 409 | |
| 410 | With the FF-A EAC specification, Secure Partitions are scheduled by direct |
| 411 | message invocations from a NWd VM or another SP. |
| 412 | |
| 413 | Platform topology |
| 414 | ~~~~~~~~~~~~~~~~~ |
| 415 | |
| 416 | As stated in `[1]`_ section 4.4.1 the SPMC implementation assumes the |
| 417 | following SP types: |
| 418 | |
| 419 | - Pinned MP SPs: an Execution Context id matches a physical PE id. MP |
| 420 | SPs must implement the same number of ECs as the number of PEs in the |
| 421 | platform. Hence the *execution-ctx-count* as defined by |
| 422 | `[1]`_ (or NWd-Hafnium *vcpu_count*) can only take the |
| 423 | value of one or the number of physical PEs. |
| 424 | - Migratable UP SPs: a single execution context can run and be migrated |
| 425 | on any physical PE. It declares a single EC in its SP manifest. An UP |
| 426 | SP can receive a direct message request on any physical core. |
| 427 | |
| 428 | Usage of PSCI services in the secure world |
| 429 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 430 | |
| 431 | - The normal world Hypervisor (optional) or OS kernel issues PSCI service |
| 432 | invocations e.g. to request PSCI version, wake-up a secondary core, or request |
| 433 | core suspend. This happens at the non-secure physical FF-A instance. In the |
| 434 | example case of Hafnium in the normal world, it boots on the primary core and |
| 435 | one of the first initialization step is to request the PSCI version. It then |
| 436 | launches the primary VM. The primary VM upon initializing performs PSCI service |
| 437 | calls (at non-secure virtual FF-A instance) which are trapped by the |
| 438 | Hypervisor. Invocation from OS Kernel ends straight at EL3. The PVM issues |
| 439 | ``PSCI_CPU_ON`` service calls to wake-up secondary cores by passing an |
| 440 | ``MPIDR``, entry point address and a CPU context address. The EL3 PSCI layer |
| 441 | then performs an exception return to the secondary core entry point on the |
| 442 | targeted core. Other PSCI calls can happen at run-time from the PVM e.g. to |
| 443 | request core suspend. |
| 444 | - In the existing TF-A PSCI standard library, PSCI service calls are filtered at |
| 445 | EL3 to only originate from the NWd. Thus concerning the SPMC (at secure |
| 446 | physical FF-A instance) the PSCI service invocations cannot happen as in the |
| 447 | normal world. For example, a ``PSCI_CPU_ON`` service invocation from the SPMC |
| 448 | does not reach the PSCI layer. |
| 449 | |
| 450 | Parsing SP partition manifests |
| 451 | ------------------------------ |
| 452 | |
| 453 | Hafnium must be able to consume SP manifests as defined in |
| 454 | `[1]`_ section 3.1, at least for the mandatory fields. |
| 455 | |
| 456 | The SP manifest may contain memory and device regions nodes. |
| 457 | |
| 458 | - Memory regions shall be mapped in the SP Stage-2 translation regime at |
| 459 | load time. A memory region node can specify RX/TX buffer regions in which |
| 460 | case it is not necessary for an SP to explicitly call the ``FFA_RXTX_MAP`` |
| 461 | service. |
| 462 | - Device regions shall be mapped in SP Stage-2 translation regime as |
| 463 | peripherals and possibly allocate additional resources (e.g. interrupts) |
| 464 | |
| 465 | Base addresses for memory and device region nodes are IPAs provided SPMC |
| 466 | identity maps IPAs to PAs within SP Stage-2 translation regime. |
| 467 | |
| 468 | Note: currently both VTTBR_EL2 and VSTTBR_EL2 resolve to the same set of page |
| 469 | tables. It is still open whether two sets of page tables shall be provided per |
| 470 | SP. The memory region node as defined in the spec (section 3.1 Table 10) |
| 471 | provides a memory security attribute hinting to map either to the secure or |
| 472 | non-secure stage-2 table. |
| 473 | |
| 474 | Passing boot data to the SP |
| 475 | --------------------------- |
| 476 | |
| 477 | `[1]`_ Section 3.4.2 āProtocol for passing dataā defines a |
| 478 | method to passing boot data to SPs (not currently implemented). |
| 479 | |
| 480 | Provided that the whole Secure Partition package image (see `Secure |
| 481 | Partition packages`_) is mapped to the SP's secure Stage-2 translation |
| 482 | regime, an SP can access its own manifest DTB blob and extract its partition |
| 483 | manifest properties. |
| 484 | |
| 485 | SP Boot order |
| 486 | ------------- |
| 487 | |
| 488 | SP manifests provide an optional boot order attribute meant to resolve |
| 489 | dependencies such as an SP providing a service required to properly boot |
| 490 | another SP. |
| 491 | |
| 492 | Boot phases |
| 493 | ----------- |
| 494 | |
| 495 | Primary core boot-up |
| 496 | ~~~~~~~~~~~~~~~~~~~~ |
| 497 | |
| 498 | The SPMC performs its platform initializations then loads and creates |
| 499 | secure partitions based on SP packages and manifests. Then each secure |
| 500 | partition is launched in sequence (see `SP Boot order`_) on their primary |
| 501 | Execution Context. |
| 502 | |
| 503 | Notice the primary physical core may not be core 0. Hence if the primary |
| 504 | core linear id is N, the 1:1 mapping requires MP SPs are launched using |
| 505 | EC[N] on PE[N] (see `Platform topology`_). |
| 506 | |
| 507 | The SP's primary Execution Context (or the EC used when the partition is booted) |
| 508 | exits through ``FFA_MSG_WAIT`` to indicate successful initialization. |
| 509 | |
| 510 | Secondary physical core boot-up |
| 511 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 512 | |
| 513 | Upon boot-up, the SPMC running on the primary core performs |
| 514 | implementation-defined SPMD service calls at secure physical FF-A instance |
| 515 | to register the secondary physical cores entry points and context information: |
| 516 | |
| 517 | - This is done through a direct message request invocation to the SPMD |
| 518 | (``SET_ENTRY_POINT``). This service call does not wake-up the targeted |
| 519 | core immediately. The secondary core is woken up later by a NWd |
| 520 | ``PSCI_CPU_ON`` service invocation. A notification is passed from EL3 |
| 521 | PSCI layer to the SPMD, and then to SPMC through an implementation-defined |
| 522 | interface. |
| 523 | - The SPMC/SPMD interface can consist of FF-A direct message requests/responses |
| 524 | transporting PM events. |
| 525 | |
| 526 | If there is no Hypervisor in the normal world, the OS Kernel issues |
| 527 | ``PSCI_CPU_ON`` calls that are directly trapped to EL3. |
| 528 | |
| 529 | When a secondary physical core wakes-up the SPMD notifies the SPMC which updates |
| 530 | its internal states reflecting current physical core is being turned on. |
| 531 | It might then return straight to the SPMD and then to the NWd. |
| 532 | |
| 533 | *(under discussion)* There may be possibility that an SP registers "PM events" |
| 534 | (during primary EC boot stage) through an ad-hoc interface. Such events would |
| 535 | be relayed by SPMC to one or more registered SPs on need basis |
| 536 | (see `Power management`_). |
| 537 | |
| 538 | Secondary virtual core boot-up |
| 539 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 540 | |
| 541 | In the example case where Hafnium exists in the normal world, secondary VMs |
| 542 | issue a ``PSCI_CPU_ON`` service call which is trapped to the Hypervisor. The |
| 543 | latter then enables the vCPU context for the targeted core, and switches to |
| 544 | the PVM down to the kernel driver with an ``HF_WAKE_UP`` message. The NWd |
| 545 | driver in PVM can then schedule the newly woken up vCPU context. |
| 546 | |
| 547 | In the secure world the primary EC of a given SP passes the secondary EC entry |
| 548 | point and context. The SMC service call is trapped into the SPMC. This can be |
| 549 | either *(under discussion)*: |
| 550 | |
| 551 | - a specific interface registering the secondary EC entry point, |
| 552 | similarly to above ``SET_ENTRY_POINT`` service. |
| 553 | - Re-purposing the ``PSCI_CPU_ON`` function id. It is |
| 554 | assumed that even if the input arguments are the same as the ones defined in |
| 555 | the PSCI standard, the usage deviates by the fact the secondary EC is not |
| 556 | woken up immediately. At least for the PSA-FF-A EAC where only |
| 557 | direct messaging is allowed, it is only after the first direct |
| 558 | message invocation that the secondary EC is entered. This option |
| 559 | might be preferred when the same code base is re-used for a VM or |
| 560 | an SP. The ABI to wake-up a secondary EC can remain similar. |
| 561 | |
| 562 | SPs are always scheduled from the NWd, this paradigm did not change from legacy |
| 563 | TEEs. There must always be some logic (or driver) in the NWd to relinquish CPU |
| 564 | cycles to the SWd. If primary core is 0, an SP EC[x>0] entry point is supplied |
| 565 | by the SP EC[0] when the system boots in SWd. But this EC[x] is not immediately |
| 566 | entered at boot. Later in the boot process when NWd is up, a direct message |
| 567 | request issued from physical core 1 ends up in SP EC[1], and only at this stage |
| 568 | this context is effectively scheduled. |
| 569 | |
| 570 | It should be possible for an SP to call into another SP through direct message |
| 571 | provided the latter SP has been booted already. The "boot-order" field in |
| 572 | partition manifests (`SP Boot order`_) fulfills the dependency towards availability |
| 573 | of a service within an SP offered to another SP. |
| 574 | |
| 575 | Mandatory interfaces |
| 576 | -------------------- |
| 577 | |
| 578 | The following interfaces must be exposed to any VM or SP: |
| 579 | |
| 580 | - ``FFA_STATUS`` |
| 581 | - ``FFA_ERROR`` |
| 582 | - ``FFA_INTERRUPT`` |
| 583 | - ``FFA_VERSION`` |
| 584 | - ``FFA_FEATURES`` |
| 585 | - ``FFA_RX_RELEASE`` |
| 586 | - ``FFA_RXTX_MAP`` |
| 587 | - ``FFA_RXTX_UNMAP`` |
| 588 | - ``FFA_PARTITION_INFO_GET`` |
| 589 | - ``FFA_ID_GET`` |
| 590 | |
| 591 | FFA_VERSION |
| 592 | ~~~~~~~~~~~ |
| 593 | |
| 594 | Per `[1]`_ section 8.1 ``FFA_VERSION`` requires a |
| 595 | *requested_version* parameter from the caller. |
| 596 | |
| 597 | In the current implementation when ``FFA_VERSION`` is invoked from: |
| 598 | |
| 599 | - Hypervisor in NS-EL2: the SPMD returns the SPMC version specified |
| 600 | in the SPMC manifest. |
| 601 | - OS kernel in NS-EL1 when NS-EL2 is not present: the SPMD returns the |
| 602 | SPMC version specified in the SPMC manifest. |
| 603 | - VM in NWd: the Hypervisor returns its implemented version. |
| 604 | - SP in SWd: the SPMC returns its implemented version. |
| 605 | - SPMC at S-EL1/S-EL2: the SPMD returns its implemented version. |
| 606 | |
| 607 | FFA_FEATURES |
| 608 | ~~~~~~~~~~~~ |
| 609 | |
| 610 | FF-A features may be discovered by Secure Partitions while booting |
| 611 | through the SPMC. However, SPMC cannot get features from Hypervisor |
| 612 | early at boot time as NS world is not setup yet. |
| 613 | |
| 614 | The Hypervisor may decide to gather FF-A features from SPMC through SPMD |
| 615 | once at boot time and store the result. Later when a VM requests FF-A |
| 616 | features, the Hypervisor can adjust its own set of features with what |
| 617 | SPMC advertised, if necessary. Another approach is to always forward FF-A |
| 618 | features to the SPMC when a VM requests it to the Hypervisor. Although |
| 619 | the result is not supposed to change over time so there may not be added |
| 620 | value doing the systematic forwarding. |
| 621 | |
| 622 | FFA_RXTX_MAP/FFA_RXTX_UNMAP |
| 623 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 624 | |
| 625 | VM mailboxes are re-purposed to serve as SP RX/TX buffers. The RX/TX |
| 626 | map API maps the send and receive buffer IPAs to the SP Stage-2 translation regime. |
| 627 | |
| 628 | Hafnium in the normal world defines VMs and their attributes as logical structures, |
| 629 | including a mailbox used for FF-A indirect messaging, memory sharing, or the |
| 630 | `FFA_PARTITION_INFO_GET`_ ABI. |
| 631 | This same mailbox structure is re-used in the SPMC. `[1]`_ states only direct |
| 632 | messaging is allowed to SPs. Thus mailbox usage is restricted to implementing |
| 633 | `FFA_PARTITION_INFO_GET`_ and memory sharing ABIs. |
| 634 | |
| 635 | FFA_PARTITION_INFO_GET |
| 636 | ~~~~~~~~~~~~~~~~~~~~~~ |
| 637 | |
| 638 | Partition info get service call can originate: |
| 639 | |
| 640 | - from SP to SPM |
| 641 | - from VM to Hypervisor |
| 642 | - from Hypervisor to SPM |
| 643 | |
| 644 | For the latter case, the service call must be forwarded through the SPMD. |
| 645 | |
| 646 | FFA_ID_GET |
| 647 | ~~~~~~~~~~ |
| 648 | |
| 649 | The SPMD returns: |
| 650 | |
| 651 | - a default zero value on invocation from the Hypervisor. |
| 652 | - The ``spmc_id`` value specified in the SPMC manifest on invocation from |
| 653 | the SPMC (see `SPMC manifest`_) |
| 654 | |
| 655 | The FF-A id space is split into a non-secure space and secure space: |
| 656 | |
| 657 | - FF-A id with bit 15 clear refer to normal world VMs. |
| 658 | - FF-A id with bit 15 set refer to secure world SPs |
| 659 | |
| 660 | Such convention helps the SPMC discriminating the origin and destination worlds |
| 661 | in an FF-A service invocation. In particular the SPMC shall filter unauthorized |
| 662 | transactions in its world switch routine. It must not be permitted for a VM to |
| 663 | use a secure FF-A id as origin world through spoofing: |
| 664 | |
| 665 | - A VM-to-SP messaging passing shall have an origin world being non-secure |
| 666 | (FF-A id bit 15 clear) and destination world being secure (FF-A id bit 15 |
| 667 | set). |
| 668 | - Similarly, an SP-to-SP message shall have FF-A id bit 15 set for both origin |
| 669 | and destination ids. |
| 670 | |
| 671 | An incoming direct message request arriving at SPMD from NWd is forwarded to |
| 672 | SPMC without a specific check. The SPMC is resumed through eret and "knows" the |
| 673 | message is coming from normal world in this specific code path. Thus the origin |
| 674 | endpoint id must be checked by SPMC for being a normal world id. |
| 675 | |
| 676 | An SP sending a direct message request must have bit 15 set in its origin |
| 677 | endpoint id and this can be checked by the SPMC when the SP invokes the ABI. |
| 678 | |
| 679 | The SPMC shall reject the direct message if the claimed world in origin endpoint |
| 680 | id is not consistent: |
| 681 | |
| 682 | - It is either forwarded by SPMD and thus origin endpoint id must be a "normal |
| 683 | world id", |
| 684 | - or initiated by an SP and thus origin endpoint id must be a "secure world id". |
| 685 | |
| 686 | Direct messaging |
| 687 | ---------------- |
| 688 | |
| 689 | This is a mandatory interface for Secure Partitions consisting in direct |
| 690 | message request and responses. |
| 691 | |
| 692 | The ``ffa_handler`` Hafnium function may: |
| 693 | |
| 694 | - trigger a world change e.g. when an SP invokes the direct message |
| 695 | response ABI to a VM. |
| 696 | - handle multiple requests from the NWd without resuming an SP. |
| 697 | |
| 698 | SP-to-SP |
| 699 | ~~~~~~~~ |
| 700 | |
| 701 | - An SP can send a direct message request to another SP |
| 702 | - An SP can receive a direct message response from another SP. |
| 703 | |
| 704 | VM-to-SP |
| 705 | ~~~~~~~~ |
| 706 | |
| 707 | - A VM can send a direct message request to an SP |
| 708 | - An SP can send a direct message response to a VM |
| 709 | |
| 710 | SPMC-SPMD messaging |
| 711 | ~~~~~~~~~~~~~~~~~~~ |
| 712 | |
| 713 | Specific implementation-defined endpoint IDs are allocated to the SPMC and SPMD. |
| 714 | Referring those IDs in source/destination fields of a direct message |
| 715 | request/response permits SPMD to SPMC messaging back and forth. |
| 716 | |
| 717 | Per `[1]`_ Table 114 Config No. 1 (physical FF-A instance): |
| 718 | |
| 719 | - SPMC=>SPMD direct message request uses SMC conduit |
| 720 | - SPMD=>SPMC direct message request uses ERET conduit |
| 721 | |
| 722 | Per `[1]`_ Table 118 Config No. 1 (physical FF-A instance): |
| 723 | |
| 724 | - SPMC=>SPMD direct message response uses SMC conduit |
| 725 | - SPMD=>SPMC direct message response uses ERET conduit |
| 726 | |
| 727 | Memory management |
| 728 | ----------------- |
| 729 | |
| 730 | This section only deals with the PE MMU configuration. |
| 731 | |
| 732 | Hafnium in the normal world deals with NS buffers only and provisions |
| 733 | a single root page table directory to VMs. In context of S-EL2 enabled |
| 734 | firmware, two IPA spaces are output from Stage-1 translation (secure |
| 735 | and non-secure). The Stage-2 translation handles: |
| 736 | |
| 737 | - A single secure IPA space when an SP Stage-1 MMU is disabled. |
| 738 | - Two IPA spaces (secure and non-secure) when Stage-1 MMU is enabled. |
| 739 | |
| 740 | ``VTCR_EL2`` and ``VSTCR_EL2`` provide additional bits for controlling the |
| 741 | NS/S IPA translations (``VSTCR_EL2.SW``, ``VSTCR_EL2.SA``, ``VTCR_EL2.NSW``, |
| 742 | ``VTCR_EL2.NSA``). There may be two approaches: |
| 743 | |
| 744 | - secure and non-secure mappings are rooted as two separate root page |
| 745 | tables |
| 746 | - secure and non-secure mappings use the same root page table. Access |
| 747 | from S-EL1 to an NS region translates to a secure physical address |
| 748 | space access. |
| 749 | |
| 750 | Interrupt management |
| 751 | -------------------- |
| 752 | |
| 753 | Road to a para-virtualized interface |
| 754 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 755 | |
| 756 | Current Hafnium implementation uses an ad-hoc mechanism for a VM to get |
| 757 | a pending interrupt number through an hypercall. The PVM injects |
| 758 | interrupts to VMs by delegation from the Hypervisor. The PVM probes a |
| 759 | pending interrupt directly from the GIC distributor. |
| 760 | |
| 761 | The short-term plan is to have Hafnium/SPMC in the secure world owner |
| 762 | of the GIC configuration. |
| 763 | |
| 764 | The SPMC fully owns the GIC configuration at S-EL2. The SPMC manages |
| 765 | interrupt resources and allocates interrupt ID based on SP manifests. |
| 766 | The SPMC acknowledges physical interrupts and injects virtual interrupts |
| 767 | by setting the vIRQ bit when resuming an SP. A Secure Partition gathers |
| 768 | the interrupt number through an hypercall. |
| 769 | |
| 770 | Notice the SPMC/SPMD has to handle Group0 secure interrupts in addition |
| 771 | to Group1 S/NS interrupts. |
| 772 | |
| 773 | Power management |
| 774 | ---------------- |
| 775 | |
| 776 | Assumption on the Nwd: |
| 777 | |
| 778 | - NWd is the best candidate to own the platform Power Management |
| 779 | policy. It is master to invoking PSCI service calls from physical |
| 780 | CPUs. |
| 781 | - EL3 monitor is in charge of the PM control part (its PSCI layer |
| 782 | actually writing to platform registers). |
| 783 | - It is fine for the Hypervisor to trap PSCI calls and relay to EL3, or |
| 784 | OS kernel driver to emit PSCI service calls. |
| 785 | |
| 786 | PSCI notification are relayed through the SPMD/SPD PM hooks to the SPMC. |
| 787 | This can either be through re-use of PSCI FIDs or an FF-A direct message |
| 788 | from SPMD to SPMC. |
| 789 | |
| 790 | The SPMD performs an exception return to the SPMC which is resumed to |
| 791 | its ``eret_handler`` routine. It is then either consuming a PSCI FID or |
| 792 | an FF-A FID. Depending on the servicing, the SPMC may return directly to |
| 793 | the SPMD (and then NWd) without resuming an SP at this stage. An example |
| 794 | of this is invocation of ``FFA_PARTITION_INFO_GET`` from NWd relayed by |
| 795 | the SPMD to the SPMC. The SPMC returns the needed partition information |
| 796 | to the SPMD (then NWd) without actually resuming a partition in secure world. |
| 797 | |
| 798 | *(under discussion)* |
| 799 | About using PSCI FIDs from SPMD to SPMC to notify of PM events, it is still |
| 800 | questioned what to use as the return code from the SPMC. |
| 801 | If the function ID used by the SPMC is not an FF-A ID when doing SMC, then the |
| 802 | EL3 std svc handler won't route the response to the SPMD. That's where comes the |
| 803 | idea to embed the notification into an FF-A message. The SPMC can discriminate |
| 804 | this message as being a PSCI event, process it, and reply with an FF-A return |
| 805 | message that the SPMD receives as an acknowledgement. |
| 806 | |
| 807 | SP notification |
| 808 | --------------- |
| 809 | |
| 810 | Power management notifications are conveyed from PSCI library to the |
| 811 | SPMD / SPD hooks. A range of events can be relayed to SPMC. |
| 812 | |
| 813 | SPs may need to be notified about specific PM events. |
| 814 | |
| 815 | - SPs might register PM events to the SPMC |
| 816 | - On SPMD to SPMC notification, a limited range of SPs may be notified |
| 817 | through a direct message. |
| 818 | - This assumes the mentioned SPs supports managed exit. |
| 819 | |
| 820 | The SPMC is the first to be notified about PM events from the SPMD. It is up |
| 821 | to the SPMC to arbitrate to which SP it needs to send PM events. |
| 822 | An SP explicitly registers to receive notifications to specific PM events. |
| 823 | The register operation can either be an implementation-defined service call |
| 824 | to the SPMC when the primary SP EC boots, or be supplied through the SP |
| 825 | manifest. |
| 826 | |
| 827 | References |
| 828 | ========== |
| 829 | |
| 830 | .. _[1]: |
| 831 | |
| 832 | [1] `Platform Security Architecture Firmware Framework for ArmĀ® v8-A 1.0 Platform Design Document <https://developer.arm.com/docs/den0077/latest>`__ |
| 833 | |
| 834 | .. _[2]: |
| 835 | |
Madhukar Pappireddy | 86350ae | 2020-07-29 09:37:25 -0500 | [diff] [blame] | 836 | [2] :ref:`Secure Partition Manager using MM interface<Secure Partition Manager (MM)>` |
Olivier Deprez | ecb2fe5 | 2020-04-02 15:38:02 +0200 | [diff] [blame] | 837 | |
| 838 | .. _[3]: |
| 839 | |
| 840 | [3] `Trusted Boot Board Requirements |
| 841 | Client <https://developer.arm.com/docs/den0006/latest/trusted-board-boot-requirements-client-tbbr-client-armv8-a>`__ |
| 842 | |
| 843 | .. _[4]: |
| 844 | |
| 845 | [4] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/lib/el3_runtime/aarch64/context.S#n45 |
| 846 | |
| 847 | .. _[5]: |
| 848 | |
| 849 | [5] https://git.trustedfirmware.org/TF-A/tf-a-tests.git/tree/spm/cactus/cactus.dts |
| 850 | |
| 851 | .. _[6]: |
| 852 | |
| 853 | [6] https://trustedfirmware-a.readthedocs.io/en/latest/components/psa-ffa-manifest-binding.html |
| 854 | |
| 855 | .. _[7]: |
| 856 | |
| 857 | [7] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/arm/board/fvp/fdts/fvp_spmc_manifest.dts |
| 858 | |
| 859 | .. _[8]: |
| 860 | |
| 861 | [8] https://developer.trustedfirmware.org/w/tf_a/poc-multiple-signing-domains/ |
| 862 | |
| 863 | -------------- |
| 864 | |
| 865 | *Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.* |