secure-partition-manager.rst 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  1. Secure Partition Manager
  2. ************************
  3. .. contents::
  4. .. toctree::
  5. ffa-manifest-binding
  6. Acronyms
  7. ========
  8. +--------+--------------------------------------+
  9. | CoT | Chain of Trust |
  10. +--------+--------------------------------------+
  11. | DMA | Direct Memory Access |
  12. +--------+--------------------------------------+
  13. | DTB | Device Tree Blob |
  14. +--------+--------------------------------------+
  15. | DTS | Device Tree Source |
  16. +--------+--------------------------------------+
  17. | EC | Execution Context |
  18. +--------+--------------------------------------+
  19. | FIP | Firmware Image Package |
  20. +--------+--------------------------------------+
  21. | FF-A | Firmware Framework for Arm A-profile |
  22. +--------+--------------------------------------+
  23. | IPA | Intermediate Physical Address |
  24. +--------+--------------------------------------+
  25. | JOP | Jump-Oriented Programming |
  26. +--------+--------------------------------------+
  27. | NWd | Normal World |
  28. +--------+--------------------------------------+
  29. | ODM | Original Design Manufacturer |
  30. +--------+--------------------------------------+
  31. | OEM | Original Equipment Manufacturer |
  32. +--------+--------------------------------------+
  33. | PA | Physical Address |
  34. +--------+--------------------------------------+
  35. | PE | Processing Element |
  36. +--------+--------------------------------------+
  37. | PM | Power Management |
  38. +--------+--------------------------------------+
  39. | PVM | Primary VM |
  40. +--------+--------------------------------------+
  41. | ROP | Return-Oriented Programming |
  42. +--------+--------------------------------------+
  43. | SMMU | System Memory Management Unit |
  44. +--------+--------------------------------------+
  45. | SP | Secure Partition |
  46. +--------+--------------------------------------+
  47. | SPD | Secure Payload Dispatcher |
  48. +--------+--------------------------------------+
  49. | SPM | Secure Partition Manager |
  50. +--------+--------------------------------------+
  51. | SPMC | SPM Core |
  52. +--------+--------------------------------------+
  53. | SPMD | SPM Dispatcher |
  54. +--------+--------------------------------------+
  55. | SiP | Silicon Provider |
  56. +--------+--------------------------------------+
  57. | SWd | Secure World |
  58. +--------+--------------------------------------+
  59. | TLV | Tag-Length-Value |
  60. +--------+--------------------------------------+
  61. | TOS | Trusted Operating System |
  62. +--------+--------------------------------------+
  63. | VM | Virtual Machine |
  64. +--------+--------------------------------------+
  65. Foreword
  66. ========
  67. Three implementations of a Secure Partition Manager co-exist in the TF-A
  68. codebase:
  69. #. S-EL2 SPMC based on the FF-A specification `[1]`_, enabling virtualization in
  70. the secure world, managing multiple S-EL1 or S-EL0 partitions.
  71. #. EL3 SPMC based on the FF-A specification, managing a single S-EL1 partition
  72. without virtualization in the secure world.
  73. #. EL3 SPM based on the MM specification, legacy implementation managing a
  74. single S-EL0 partition `[2]`_.
  75. These implementations differ in their respective SW architecture and only one
  76. can be selected at build time. This document:
  77. - describes the implementation from bullet 1. when the SPMC resides at S-EL2.
  78. - is not an architecture specification and it might provide assumptions
  79. on sections mandated as implementation-defined in the specification.
  80. - covers the implications to TF-A used as a bootloader, and Hafnium used as a
  81. reference code base for an S-EL2/SPMC secure firmware on platforms
  82. implementing the FEAT_SEL2 architecture extension.
  83. Terminology
  84. -----------
  85. - The term Hypervisor refers to the NS-EL2 component managing Virtual Machines
  86. (or partitions) in the normal world.
  87. - The term SPMC refers to the S-EL2 component managing secure partitions in
  88. the secure world when the FEAT_SEL2 architecture extension is implemented.
  89. - Alternatively, SPMC can refer to an S-EL1 component, itself being a secure
  90. partition and implementing the FF-A ABI on platforms not implementing the
  91. FEAT_SEL2 architecture extension.
  92. - The term VM refers to a normal world Virtual Machine managed by an Hypervisor.
  93. - The term SP refers to a secure world "Virtual Machine" managed by an SPMC.
  94. Support for legacy platforms
  95. ----------------------------
  96. The SPM is split into a dispatcher and a core component (respectively SPMD and
  97. SPMC) residing at different exception levels. To permit the FF-A specification
  98. adoption and a smooth migration, the SPMD supports an SPMC residing either at
  99. S-EL1 or S-EL2:
  100. - The SPMD is located at EL3 and mainly relays the FF-A protocol from NWd
  101. (Hypervisor or OS kernel) to the SPMC.
  102. - The same SPMD component is used for both S-EL1 and S-EL2 SPMC configurations.
  103. - The SPMC exception level is a build time choice.
  104. TF-A supports both cases:
  105. - S-EL1 SPMC for platforms not supporting the FEAT_SEL2 architecture
  106. extension. The SPMD relays the FF-A protocol from EL3 to S-EL1.
  107. - S-EL2 SPMC for platforms implementing the FEAT_SEL2 architecture
  108. extension. The SPMD relays the FF-A protocol from EL3 to S-EL2.
  109. Sample reference stack
  110. ======================
  111. The following diagram illustrates a possible configuration when the
  112. FEAT_SEL2 architecture extension is implemented, showing the SPMD
  113. and SPMC, one or multiple secure partitions, with an optional
  114. Hypervisor:
  115. .. image:: ../resources/diagrams/ff-a-spm-sel2.png
  116. TF-A build options
  117. ==================
  118. This section explains the TF-A build options involved in building with
  119. support for an FF-A based SPM where the SPMD is located at EL3 and the
  120. SPMC located at S-EL1, S-EL2 or EL3:
  121. - **SPD=spmd**: this option selects the SPMD component to relay the FF-A
  122. protocol from NWd to SWd back and forth. It is not possible to
  123. enable another Secure Payload Dispatcher when this option is chosen.
  124. - **SPMD_SPM_AT_SEL2**: this option adjusts the SPMC exception
  125. level to being at S-EL2. It defaults to enabled (value 1) when
  126. SPD=spmd is chosen.
  127. - **SPMC_AT_EL3**: this option adjusts the SPMC exception level to being
  128. at EL3.
  129. - If neither ``SPMD_SPM_AT_SEL2`` or ``SPMC_AT_EL3`` are enabled the SPMC
  130. exception level is set to S-EL1.
  131. - **CTX_INCLUDE_EL2_REGS**: this option permits saving (resp.
  132. restoring) the EL2 system register context before entering (resp.
  133. after leaving) the SPMC. It is mandatorily enabled when
  134. ``SPMD_SPM_AT_SEL2`` is enabled. The context save/restore routine
  135. and exhaustive list of registers is visible at `[4]`_.
  136. - **SP_LAYOUT_FILE**: this option specifies a text description file
  137. providing paths to SP binary images and manifests in DTS format
  138. (see `Describing secure partitions`_). It
  139. is required when ``SPMD_SPM_AT_SEL2`` is enabled hence when multiple
  140. secure partitions are to be loaded by BL2 on behalf of the SPMC.
  141. +---------------+----------------------+------------------+-------------+
  142. | | CTX_INCLUDE_EL2_REGS | SPMD_SPM_AT_SEL2 | SPMC_AT_EL3 |
  143. +---------------+----------------------+------------------+-------------+
  144. | SPMC at S-EL1 | 0 | 0 | 0 |
  145. +---------------+----------------------+------------------+-------------+
  146. | SPMC at S-EL2 | 1 | 1 (default when | 0 |
  147. | | | SPD=spmd) | |
  148. +---------------+----------------------+------------------+-------------+
  149. | SPMC at EL3 | 0 | 0 | 1 |
  150. +---------------+----------------------+------------------+-------------+
  151. Other combinations of such build options either break the build or are not
  152. supported.
  153. Notes:
  154. - Only Arm's FVP platform is supported to use with the TF-A reference software
  155. stack.
  156. - When ``SPMD_SPM_AT_SEL2=1``, the reference software stack assumes enablement
  157. of FEAT_PAuth, FEAT_BTI and FEAT_MTE architecture extensions.
  158. - The ``CTX_INCLUDE_EL2_REGS`` option provides the generic support for
  159. barely saving/restoring EL2 registers from an Arm arch perspective. As such
  160. it is decoupled from the ``SPD=spmd`` option.
  161. - BL32 option is re-purposed to specify the SPMC image. It can specify either
  162. the Hafnium binary path (built for the secure world) or the path to a TEE
  163. binary implementing FF-A interfaces.
  164. - BL33 option can specify the TFTF binary or a normal world loader
  165. such as U-Boot or the UEFI framework payload.
  166. Sample TF-A build command line when the SPMC is located at S-EL1
  167. (e.g. when the FEAT_SEL2 architecture extension is not implemented):
  168. .. code:: shell
  169. make \
  170. CROSS_COMPILE=aarch64-none-elf- \
  171. SPD=spmd \
  172. SPMD_SPM_AT_SEL2=0 \
  173. BL32=<path-to-tee-binary> \
  174. BL33=<path-to-bl33-binary> \
  175. PLAT=fvp \
  176. all fip
  177. Sample TF-A build command line when FEAT_SEL2 architecture extension is
  178. implemented and the SPMC is located at S-EL2:
  179. .. code:: shell
  180. make \
  181. CROSS_COMPILE=aarch64-none-elf- \
  182. PLAT=fvp \
  183. SPD=spmd \
  184. CTX_INCLUDE_EL2_REGS=1 \
  185. ARM_ARCH_MINOR=5 \
  186. BRANCH_PROTECTION=1 \
  187. CTX_INCLUDE_PAUTH_REGS=1 \
  188. CTX_INCLUDE_MTE_REGS=1 \
  189. BL32=<path-to-hafnium-binary> \
  190. BL33=<path-to-bl33-binary> \
  191. SP_LAYOUT_FILE=sp_layout.json \
  192. all fip
  193. Sample TF-A build command line when FEAT_SEL2 architecture extension is
  194. implemented, the SPMC is located at S-EL2, and enabling secure boot:
  195. .. code:: shell
  196. make \
  197. CROSS_COMPILE=aarch64-none-elf- \
  198. PLAT=fvp \
  199. SPD=spmd \
  200. CTX_INCLUDE_EL2_REGS=1 \
  201. ARM_ARCH_MINOR=5 \
  202. BRANCH_PROTECTION=1 \
  203. CTX_INCLUDE_PAUTH_REGS=1 \
  204. CTX_INCLUDE_MTE_REGS=1 \
  205. BL32=<path-to-hafnium-binary> \
  206. BL33=<path-to-bl33-binary> \
  207. SP_LAYOUT_FILE=sp_layout.json \
  208. MBEDTLS_DIR=<path-to-mbedtls-lib> \
  209. TRUSTED_BOARD_BOOT=1 \
  210. COT=dualroot \
  211. ARM_ROTPK_LOCATION=devel_rsa \
  212. ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem \
  213. GENERATE_COT=1 \
  214. all fip
  215. Sample TF-A build command line when the SPMC is located at EL3:
  216. .. code:: shell
  217. make \
  218. CROSS_COMPILE=aarch64-none-elf- \
  219. SPD=spmd \
  220. SPMD_SPM_AT_SEL2=0 \
  221. SPMC_AT_EL3=1 \
  222. BL32=<path-to-tee-binary> \
  223. BL33=<path-to-bl33-binary> \
  224. PLAT=fvp \
  225. all fip
  226. FVP model invocation
  227. ====================
  228. The FVP command line needs the following options to exercise the S-EL2 SPMC:
  229. +---------------------------------------------------+------------------------------------+
  230. | - cluster0.has_arm_v8-5=1 | Implements FEAT_SEL2, FEAT_PAuth, |
  231. | - cluster1.has_arm_v8-5=1 | and FEAT_BTI. |
  232. +---------------------------------------------------+------------------------------------+
  233. | - pci.pci_smmuv3.mmu.SMMU_AIDR=2 | Parameters required for the |
  234. | - pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B | SMMUv3.2 modeling. |
  235. | - pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 | |
  236. | - pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 | |
  237. | - pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472 | |
  238. | - pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 | |
  239. | - pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 | |
  240. | - pci.pci_smmuv3.mmu.SMMU_S_IDR3=0 | |
  241. +---------------------------------------------------+------------------------------------+
  242. | - cluster0.has_branch_target_exception=1 | Implements FEAT_BTI. |
  243. | - cluster1.has_branch_target_exception=1 | |
  244. +---------------------------------------------------+------------------------------------+
  245. | - cluster0.has_pointer_authentication=2 | Implements FEAT_PAuth |
  246. | - cluster1.has_pointer_authentication=2 | |
  247. +---------------------------------------------------+------------------------------------+
  248. | - cluster0.memory_tagging_support_level=2 | Implements FEAT_MTE2 |
  249. | - cluster1.memory_tagging_support_level=2 | |
  250. | - bp.dram_metadata.is_enabled=1 | |
  251. +---------------------------------------------------+------------------------------------+
  252. Sample FVP command line invocation:
  253. .. code:: shell
  254. <path-to-fvp-model>/FVP_Base_RevC-2xAEMvA -C pctl.startup=0.0.0.0 \
  255. -C cluster0.NUM_CORES=4 -C cluster1.NUM_CORES=4 -C bp.secure_memory=1 \
  256. -C bp.secureflashloader.fname=trusted-firmware-a/build/fvp/debug/bl1.bin \
  257. -C bp.flashloader0.fname=trusted-firmware-a/build/fvp/debug/fip.bin \
  258. -C bp.pl011_uart0.out_file=fvp-uart0.log -C bp.pl011_uart1.out_file=fvp-uart1.log \
  259. -C bp.pl011_uart2.out_file=fvp-uart2.log \
  260. -C cluster0.has_arm_v8-5=1 -C cluster1.has_arm_v8-5=1 \
  261. -C cluster0.has_pointer_authentication=2 -C cluster1.has_pointer_authentication=2 \
  262. -C cluster0.has_branch_target_exception=1 -C cluster1.has_branch_target_exception=1 \
  263. -C cluster0.memory_tagging_support_level=2 -C cluster1.memory_tagging_support_level=2 \
  264. -C bp.dram_metadata.is_enabled=1 \
  265. -C pci.pci_smmuv3.mmu.SMMU_AIDR=2 -C pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B \
  266. -C pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 -C pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 \
  267. -C pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472 -C pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 \
  268. -C pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 -C pci.pci_smmuv3.mmu.SMMU_S_IDR3=0
  269. Boot process
  270. ============
  271. Loading Hafnium and secure partitions in the secure world
  272. ---------------------------------------------------------
  273. TF-A BL2 is the bootlader for the SPMC and SPs in the secure world.
  274. SPs may be signed by different parties (SiP, OEM/ODM, TOS vendor, etc.).
  275. Thus they are supplied as distinct signed entities within the FIP flash
  276. image. The FIP image itself is not signed hence this provides the ability
  277. to upgrade SPs in the field.
  278. Booting through TF-A
  279. --------------------
  280. SP manifests
  281. ~~~~~~~~~~~~
  282. An SP manifest describes SP attributes as defined in `[1]`_
  283. (partition manifest at virtual FF-A instance) in DTS format. It is
  284. represented as a single file associated with the SP. A sample is
  285. provided by `[5]`_. A binding document is provided by `[6]`_.
  286. Secure Partition packages
  287. ~~~~~~~~~~~~~~~~~~~~~~~~~
  288. Secure partitions are bundled as independent package files consisting
  289. of:
  290. - a header
  291. - a DTB
  292. - an image payload
  293. The header starts with a magic value and offset values to SP DTB and
  294. image payload. Each SP package is loaded independently by BL2 loader
  295. and verified for authenticity and integrity.
  296. The SP package identified by its UUID (matching FF-A uuid property) is
  297. inserted as a single entry into the FIP at end of the TF-A build flow
  298. as shown:
  299. .. code:: shell
  300. Trusted Boot Firmware BL2: offset=0x1F0, size=0x8AE1, cmdline="--tb-fw"
  301. EL3 Runtime Firmware BL31: offset=0x8CD1, size=0x13000, cmdline="--soc-fw"
  302. Secure Payload BL32 (Trusted OS): offset=0x1BCD1, size=0x15270, cmdline="--tos-fw"
  303. Non-Trusted Firmware BL33: offset=0x30F41, size=0x92E0, cmdline="--nt-fw"
  304. HW_CONFIG: offset=0x3A221, size=0x2348, cmdline="--hw-config"
  305. TB_FW_CONFIG: offset=0x3C569, size=0x37A, cmdline="--tb-fw-config"
  306. SOC_FW_CONFIG: offset=0x3C8E3, size=0x48, cmdline="--soc-fw-config"
  307. TOS_FW_CONFIG: offset=0x3C92B, size=0x427, cmdline="--tos-fw-config"
  308. NT_FW_CONFIG: offset=0x3CD52, size=0x48, cmdline="--nt-fw-config"
  309. B4B5671E-4A90-4FE1-B81F-FB13DAE1DACB: offset=0x3CD9A, size=0xC168, cmdline="--blob"
  310. D1582309-F023-47B9-827C-4464F5578FC8: offset=0x48F02, size=0xC168, cmdline="--blob"
  311. .. uml:: ../resources/diagrams/plantuml/fip-secure-partitions.puml
  312. Describing secure partitions
  313. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  314. A json-formatted description file is passed to the build flow specifying paths
  315. to the SP binary image and associated DTS partition manifest file. The latter
  316. is processed by the dtc compiler to generate a DTB fed into the SP package.
  317. Optionally, the partition's json description can contain offsets for both
  318. the image and partition manifest within the SP package. Both offsets need to be
  319. 4KB aligned, because it is the translation granule supported by Hafnium SPMC.
  320. These fields can be leveraged to support SPs with S1 translation granules that
  321. differ from 4KB, and to configure the regions allocated within the SP package,
  322. as well as to comply with the requirements for the implementation of the boot
  323. information protocol (see `Passing boot data to the SP`_ for more details). In
  324. case the offsets are absent in their json node, they default to 0x1000 and
  325. 0x4000 for the manifest offset and image offset respectively.
  326. This file also specifies the SP owner (as an optional field) identifying the
  327. signing domain in case of dual root CoT.
  328. The SP owner can either be the silicon or the platform provider. The
  329. corresponding "owner" field value can either take the value of "SiP" or "Plat".
  330. In absence of "owner" field, it defaults to "SiP" owner.
  331. The UUID of the partition can be specified as a field in the description file or
  332. if it does not exist there the UUID is extracted from the DTS partition
  333. manifest.
  334. .. code:: shell
  335. {
  336. "tee1" : {
  337. "image": "tee1.bin",
  338. "pm": "tee1.dts",
  339. "owner": "SiP",
  340. "uuid": "1b1820fe-48f7-4175-8999-d51da00b7c9f"
  341. },
  342. "tee2" : {
  343. "image": "tee2.bin",
  344. "pm": "tee2.dts",
  345. "owner": "Plat"
  346. },
  347. "tee3" : {
  348. "image": {
  349. "file": "tee3.bin",
  350. "offset":"0x2000"
  351. },
  352. "pm": {
  353. "file": "tee3.dts",
  354. "offset":"0x6000"
  355. },
  356. "owner": "Plat"
  357. },
  358. }
  359. SPMC manifest
  360. ~~~~~~~~~~~~~
  361. This manifest contains the SPMC *attribute* node consumed by the SPMD at boot
  362. time. It implements `[1]`_ (SP manifest at physical FF-A instance) and serves
  363. two different cases:
  364. - The SPMC resides at S-EL1: the SPMC manifest is used by the SPMD to setup a
  365. SP that co-resides with the SPMC and executes at S-EL1 or Secure Supervisor
  366. mode.
  367. - The SPMC resides at S-EL2: the SPMC manifest is used by the SPMD to setup
  368. the environment required by the SPMC to run at S-EL2. SPs run at S-EL1 or
  369. S-EL0.
  370. .. code:: shell
  371. attribute {
  372. spmc_id = <0x8000>;
  373. maj_ver = <0x1>;
  374. min_ver = <0x1>;
  375. exec_state = <0x0>;
  376. load_address = <0x0 0x6000000>;
  377. entrypoint = <0x0 0x6000000>;
  378. binary_size = <0x60000>;
  379. };
  380. - *spmc_id* defines the endpoint ID value that SPMC can query through
  381. ``FFA_ID_GET``.
  382. - *maj_ver/min_ver*. SPMD checks provided version versus its internal
  383. version and aborts if not matching.
  384. - *exec_state* defines the SPMC execution state (AArch64 or AArch32).
  385. Notice Hafnium used as a SPMC only supports AArch64.
  386. - *load_address* and *binary_size* are mostly used to verify secondary
  387. entry points fit into the loaded binary image.
  388. - *entrypoint* defines the cold boot primary core entry point used by
  389. SPMD (currently matches ``BL32_BASE``) to enter the SPMC.
  390. Other nodes in the manifest are consumed by Hafnium in the secure world.
  391. A sample can be found at `[7]`_:
  392. - The *hypervisor* node describes SPs. *is_ffa_partition* boolean attribute
  393. indicates a FF-A compliant SP. The *load_address* field specifies the load
  394. address at which BL2 loaded the SP package.
  395. - *cpus* node provide the platform topology and allows MPIDR to VMPIDR mapping.
  396. Note the primary core is declared first, then secondary cores are declared
  397. in reverse order.
  398. - The *memory* node provides platform information on the ranges of memory
  399. available to the SPMC.
  400. SPMC boot
  401. ~~~~~~~~~
  402. The SPMC is loaded by BL2 as the BL32 image.
  403. The SPMC manifest is loaded by BL2 as the ``TOS_FW_CONFIG`` image `[9]`_.
  404. BL2 passes the SPMC manifest address to BL31 through a register.
  405. At boot time, the SPMD in BL31 runs from the primary core, initializes the core
  406. contexts and launches the SPMC (BL32) passing the following information through
  407. registers:
  408. - X0 holds the ``TOS_FW_CONFIG`` physical address (or SPMC manifest blob).
  409. - X1 holds the ``HW_CONFIG`` physical address.
  410. - X4 holds the currently running core linear id.
  411. Loading of SPs
  412. ~~~~~~~~~~~~~~
  413. At boot time, BL2 loads SPs sequentially in addition to the SPMC as depicted
  414. below:
  415. .. uml:: ../resources/diagrams/plantuml/bl2-loading-sp.puml
  416. Note this boot flow is an implementation sample on Arm's FVP platform.
  417. Platforms not using TF-A's *Firmware CONFiguration* framework would adjust to a
  418. different boot flow. The flow restricts to a maximum of 8 secure partitions.
  419. Secure boot
  420. ~~~~~~~~~~~
  421. The SP content certificate is inserted as a separate FIP item so that BL2 loads SPMC,
  422. SPMC manifest, secure partitions and verifies them for authenticity and integrity.
  423. Refer to TBBR specification `[3]`_.
  424. The multiple-signing domain feature (in current state dual signing domain `[8]`_) allows
  425. the use of two root keys namely S-ROTPK and NS-ROTPK:
  426. - SPMC (BL32) and SPMC manifest are signed by the SiP using the S-ROTPK.
  427. - BL33 may be signed by the OEM using NS-ROTPK.
  428. - An SP may be signed either by SiP (using S-ROTPK) or by OEM (using NS-ROTPK).
  429. - A maximum of 4 partitions can be signed with the S-ROTPK key and 4 partitions
  430. signed with the NS-ROTPK key.
  431. Also refer to `Describing secure partitions`_ and `TF-A build options`_ sections.
  432. Hafnium in the secure world
  433. ===========================
  434. General considerations
  435. ----------------------
  436. Build platform for the secure world
  437. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  438. In the Hafnium reference implementation specific code parts are only relevant to
  439. the secure world. Such portions are isolated in architecture specific files
  440. and/or enclosed by a ``SECURE_WORLD`` macro.
  441. Secure partitions scheduling
  442. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  443. The FF-A specification `[1]`_ provides two ways to relinquinsh CPU time to
  444. secure partitions. For this a VM (Hypervisor or OS kernel), or SP invokes one of:
  445. - the FFA_MSG_SEND_DIRECT_REQ interface.
  446. - the FFA_RUN interface.
  447. Additionally a secure interrupt can pre-empt the normal world execution and give
  448. CPU cycles by transitioning to EL3 and S-EL2.
  449. Platform topology
  450. ~~~~~~~~~~~~~~~~~
  451. The *execution-ctx-count* SP manifest field can take the value of one or the
  452. total number of PEs. The FF-A specification `[1]`_ recommends the
  453. following SP types:
  454. - Pinned MP SPs: an execution context matches a physical PE. MP SPs must
  455. implement the same number of ECs as the number of PEs in the platform.
  456. - Migratable UP SPs: a single execution context can run and be migrated on any
  457. physical PE. Such SP declares a single EC in its SP manifest. An UP SP can
  458. receive a direct message request originating from any physical core targeting
  459. the single execution context.
  460. Parsing SP partition manifests
  461. ------------------------------
  462. Hafnium consumes SP manifests as defined in `[1]`_ and `SP manifests`_.
  463. Note the current implementation may not implement all optional fields.
  464. The SP manifest may contain memory and device regions nodes. In case of
  465. an S-EL2 SPMC:
  466. - Memory regions are mapped in the SP EL1&0 Stage-2 translation regime at
  467. load time (or EL1&0 Stage-1 for an S-EL1 SPMC). A memory region node can
  468. specify RX/TX buffer regions in which case it is not necessary for an SP
  469. to explicitly invoke the ``FFA_RXTX_MAP`` interface.
  470. - Device regions are mapped in the SP EL1&0 Stage-2 translation regime (or
  471. EL1&0 Stage-1 for an S-EL1 SPMC) as peripherals and possibly allocate
  472. additional resources (e.g. interrupts).
  473. For the S-EL2 SPMC, base addresses for memory and device region nodes are IPAs
  474. provided the SPMC identity maps IPAs to PAs within SP EL1&0 Stage-2 translation
  475. regime.
  476. Note: in the current implementation both VTTBR_EL2 and VSTTBR_EL2 point to the
  477. same set of page tables. It is still open whether two sets of page tables shall
  478. be provided per SP. The memory region node as defined in the specification
  479. provides a memory security attribute hinting to map either to the secure or
  480. non-secure EL1&0 Stage-2 table if it exists.
  481. Passing boot data to the SP
  482. ---------------------------
  483. In `[1]`_ , the section "Boot information protocol" defines a method for passing
  484. data to the SPs at boot time. It specifies the format for the boot information
  485. descriptor and boot information header structures, which describe the data to be
  486. exchanged between SPMC and SP.
  487. The specification also defines the types of data that can be passed.
  488. The aggregate of both the boot info structures and the data itself is designated
  489. the boot information blob, and is passed to a Partition as a contiguous memory
  490. region.
  491. Currently, the SPM implementation supports the FDT type which is used to pass the
  492. partition's DTB manifest.
  493. The region for the boot information blob is allocated through the SP package.
  494. .. image:: ../resources/diagrams/partition-package.png
  495. To adjust the space allocated for the boot information blob, the json description
  496. of the SP (see section `Describing secure partitions`_) shall be updated to contain
  497. the manifest offset. If no offset is provided the manifest offset defaults to 0x1000,
  498. which is the page size in the Hafnium SPMC.
  499. The configuration of the boot protocol is done in the SPs manifest. As defined by
  500. the specification, the manifest field 'gp-register-num' configures the GP register
  501. which shall be used to pass the address to the partitions boot information blob when
  502. booting the partition.
  503. In addition, the Hafnium SPMC implementation requires the boot information arguments
  504. to be listed in a designated DT node:
  505. .. code:: shell
  506. boot-info {
  507. compatible = "arm,ffa-manifest-boot-info";
  508. ffa_manifest;
  509. };
  510. The whole secure partition package image (see `Secure Partition packages`_) is
  511. mapped to the SP secure EL1&0 Stage-2 translation regime. As such, the SP can
  512. retrieve the address for the boot information blob in the designated GP register,
  513. process the boot information header and descriptors, access its own manifest
  514. DTB blob and extract its partition manifest properties.
  515. SP Boot order
  516. -------------
  517. SP manifests provide an optional boot order attribute meant to resolve
  518. dependencies such as an SP providing a service required to properly boot
  519. another SP. SPMC boots the SPs in accordance to the boot order attribute,
  520. lowest to the highest value. If the boot order attribute is absent from the FF-A
  521. manifest, the SP is treated as if it had the highest boot order value
  522. (i.e. lowest booting priority).
  523. It is possible for an SP to call into another SP through a direct request
  524. provided the latter SP has already been booted.
  525. Boot phases
  526. -----------
  527. Primary core boot-up
  528. ~~~~~~~~~~~~~~~~~~~~
  529. Upon boot-up, BL31 hands over to the SPMC (BL32) on the primary boot physical
  530. core. The SPMC performs its platform initializations and registers the SPMC
  531. secondary physical core entry point physical address by the use of the
  532. `FFA_SECONDARY_EP_REGISTER`_ interface (SMC invocation from the SPMC to the SPMD
  533. at secure physical FF-A instance).
  534. The SPMC then creates secure partitions based on SP packages and manifests. Each
  535. secure partition is launched in sequence (`SP Boot order`_) on their "primary"
  536. execution context. If the primary boot physical core linear id is N, an MP SP is
  537. started using EC[N] on PE[N] (see `Platform topology`_). If the partition is a
  538. UP SP, it is started using its unique EC0 on PE[N].
  539. The SP primary EC (or the EC used when the partition is booted as described
  540. above):
  541. - Performs the overall SP boot time initialization, and in case of a MP SP,
  542. prepares the SP environment for other execution contexts.
  543. - In the case of a MP SP, it invokes the FFA_SECONDARY_EP_REGISTER at secure
  544. virtual FF-A instance (SMC invocation from SP to SPMC) to provide the IPA
  545. entry point for other execution contexts.
  546. - Exits through ``FFA_MSG_WAIT`` to indicate successful initialization or
  547. ``FFA_ERROR`` in case of failure.
  548. Secondary cores boot-up
  549. ~~~~~~~~~~~~~~~~~~~~~~~
  550. Once the system is started and NWd brought up, a secondary physical core is
  551. woken up by the ``PSCI_CPU_ON`` service invocation. The TF-A SPD hook mechanism
  552. calls into the SPMD on the newly woken up physical core. Then the SPMC is
  553. entered at the secondary physical core entry point.
  554. In the current implementation, the first SP is resumed on the coresponding EC
  555. (the virtual CPU which matches the physical core). The implication is that the
  556. first SP must be a MP SP.
  557. In a linux based system, once secure and normal worlds are booted but prior to
  558. a NWd FF-A driver has been loaded:
  559. - The first SP has initialized all its ECs in response to primary core boot up
  560. (at system initialization) and secondary core boot up (as a result of linux
  561. invoking PSCI_CPU_ON for all secondary cores).
  562. - Other SPs have their first execution context initialized as a result of secure
  563. world initialization on the primary boot core. Other ECs for those SPs have to
  564. be run first through ffa_run to complete their initialization (which results
  565. in the EC completing with FFA_MSG_WAIT).
  566. Refer to `Power management`_ for further details.
  567. Notifications
  568. -------------
  569. The FF-A v1.1 specification `[1]`_ defines notifications as an asynchronous
  570. communication mechanism with non-blocking semantics. It allows for one FF-A
  571. endpoint to signal another for service provision, without hindering its current
  572. progress.
  573. Hafnium currently supports 64 notifications. The IDs of each notification define
  574. a position in a 64-bit bitmap.
  575. The signaling of notifications can interchangeably happen between NWd and SWd
  576. FF-A endpoints.
  577. The SPMC is in charge of managing notifications from SPs to SPs, from SPs to
  578. VMs, and from VMs to SPs. An hypervisor component would only manage
  579. notifications from VMs to VMs. Given the SPMC has no visibility of the endpoints
  580. deployed in NWd, the Hypervisor or OS kernel must invoke the interface
  581. FFA_NOTIFICATION_BITMAP_CREATE to allocate the notifications bitmap per FF-A
  582. endpoint in the NWd that supports it.
  583. A sender can signal notifications once the receiver has provided it with
  584. permissions. Permissions are provided by invoking the interface
  585. FFA_NOTIFICATION_BIND.
  586. Notifications are signaled by invoking FFA_NOTIFICATION_SET. Henceforth
  587. they are considered to be in a pending sate. The receiver can retrieve its
  588. pending notifications invoking FFA_NOTIFICATION_GET, which, from that moment,
  589. are considered to be handled.
  590. Per the FF-A v1.1 spec, each FF-A endpoint must be associated with a scheduler
  591. that is in charge of donating CPU cycles for notifications handling. The
  592. FF-A driver calls FFA_NOTIFICATION_INFO_GET to retrieve the information about
  593. which FF-A endpoints have pending notifications. The receiver scheduler is
  594. called and informed by the FF-A driver, and it should allocate CPU cycles to the
  595. receiver.
  596. There are two types of notifications supported:
  597. - Global, which are targeted to a FF-A endpoint and can be handled within any of
  598. its execution contexts, as determined by the scheduler of the system.
  599. - Per-vCPU, which are targeted to a FF-A endpoint and to be handled within a
  600. a specific execution context, as determined by the sender.
  601. The type of a notification is set when invoking FFA_NOTIFICATION_BIND to give
  602. permissions to the sender.
  603. Notification signaling resorts to two interrupts:
  604. - Schedule Receiver Interrupt: non-secure physical interrupt to be handled by
  605. the FF-A driver within the receiver scheduler. At initialization the SPMC
  606. donates a SGI ID chosen from the secure SGI IDs range and configures it as
  607. non-secure. The SPMC triggers this SGI on the currently running core when
  608. there are pending notifications, and the respective receivers need CPU cycles
  609. to handle them.
  610. - Notifications Pending Interrupt: virtual interrupt to be handled by the
  611. receiver of the notification. Set when there are pending notifications for the
  612. given secure partition. The NPI is pended when the NWd relinquishes CPU cycles
  613. to an SP.
  614. The notifications receipt support is enabled in the partition FF-A manifest.
  615. Mandatory interfaces
  616. --------------------
  617. The following interfaces are exposed to SPs:
  618. - ``FFA_VERSION``
  619. - ``FFA_FEATURES``
  620. - ``FFA_RX_RELEASE``
  621. - ``FFA_RXTX_MAP``
  622. - ``FFA_RXTX_UNMAP``
  623. - ``FFA_PARTITION_INFO_GET``
  624. - ``FFA_ID_GET``
  625. - ``FFA_MSG_WAIT``
  626. - ``FFA_MSG_SEND_DIRECT_REQ``
  627. - ``FFA_MSG_SEND_DIRECT_RESP``
  628. - ``FFA_MEM_DONATE``
  629. - ``FFA_MEM_LEND``
  630. - ``FFA_MEM_SHARE``
  631. - ``FFA_MEM_RETRIEVE_REQ``
  632. - ``FFA_MEM_RETRIEVE_RESP``
  633. - ``FFA_MEM_RELINQUISH``
  634. - ``FFA_MEM_FRAG_RX``
  635. - ``FFA_MEM_FRAG_TX``
  636. - ``FFA_MEM_RECLAIM``
  637. - ``FFA_RUN``
  638. As part of the FF-A v1.1 support, the following interfaces were added:
  639. - ``FFA_NOTIFICATION_BITMAP_CREATE``
  640. - ``FFA_NOTIFICATION_BITMAP_DESTROY``
  641. - ``FFA_NOTIFICATION_BIND``
  642. - ``FFA_NOTIFICATION_UNBIND``
  643. - ``FFA_NOTIFICATION_SET``
  644. - ``FFA_NOTIFICATION_GET``
  645. - ``FFA_NOTIFICATION_INFO_GET``
  646. - ``FFA_SPM_ID_GET``
  647. - ``FFA_SECONDARY_EP_REGISTER``
  648. - ``FFA_MEM_PERM_GET``
  649. - ``FFA_MEM_PERM_SET``
  650. FFA_VERSION
  651. ~~~~~~~~~~~
  652. ``FFA_VERSION`` requires a *requested_version* parameter from the caller.
  653. The returned value depends on the caller:
  654. - Hypervisor or OS kernel in NS-EL1/EL2: the SPMD returns the SPMC version
  655. specified in the SPMC manifest.
  656. - SP: the SPMC returns its own implemented version.
  657. - SPMC at S-EL1/S-EL2: the SPMD returns its own implemented version.
  658. FFA_FEATURES
  659. ~~~~~~~~~~~~
  660. FF-A features supported by the SPMC may be discovered by secure partitions at
  661. boot (that is prior to NWd is booted) or run-time.
  662. The SPMC calling FFA_FEATURES at secure physical FF-A instance always get
  663. FFA_SUCCESS from the SPMD.
  664. The request made by an Hypervisor or OS kernel is forwarded to the SPMC and
  665. the response relayed back to the NWd.
  666. FFA_RXTX_MAP/FFA_RXTX_UNMAP
  667. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  668. When invoked from a secure partition FFA_RXTX_MAP maps the provided send and
  669. receive buffers described by their IPAs to the SP EL1&0 Stage-2 translation
  670. regime as secure buffers in the MMU descriptors.
  671. When invoked from the Hypervisor or OS kernel, the buffers are mapped into the
  672. SPMC EL2 Stage-1 translation regime and marked as NS buffers in the MMU
  673. descriptors.
  674. The FFA_RXTX_UNMAP unmaps the RX/TX pair from the translation regime of the
  675. caller, either it being the Hypervisor or OS kernel, as well as a secure
  676. partition.
  677. FFA_PARTITION_INFO_GET
  678. ~~~~~~~~~~~~~~~~~~~~~~
  679. Partition info get call can originate:
  680. - from SP to SPMC
  681. - from Hypervisor or OS kernel to SPMC. The request is relayed by the SPMD.
  682. FFA_ID_GET
  683. ~~~~~~~~~~
  684. The FF-A id space is split into a non-secure space and secure space:
  685. - FF-A ID with bit 15 clear relates to VMs.
  686. - FF-A ID with bit 15 set related to SPs.
  687. - FF-A IDs 0, 0xffff, 0x8000 are assigned respectively to the Hypervisor, SPMD
  688. and SPMC.
  689. The SPMD returns:
  690. - The default zero value on invocation from the Hypervisor.
  691. - The ``spmc_id`` value specified in the SPMC manifest on invocation from
  692. the SPMC (see `SPMC manifest`_)
  693. This convention helps the SPMC to determine the origin and destination worlds in
  694. an FF-A ABI invocation. In particular the SPMC shall filter unauthorized
  695. transactions in its world switch routine. It must not be permitted for a VM to
  696. use a secure FF-A ID as origin world by spoofing:
  697. - A VM-to-SP direct request/response shall set the origin world to be non-secure
  698. (FF-A ID bit 15 clear) and destination world to be secure (FF-A ID bit 15
  699. set).
  700. - Similarly, an SP-to-SP direct request/response shall set the FF-A ID bit 15
  701. for both origin and destination IDs.
  702. An incoming direct message request arriving at SPMD from NWd is forwarded to
  703. SPMC without a specific check. The SPMC is resumed through eret and "knows" the
  704. message is coming from normal world in this specific code path. Thus the origin
  705. endpoint ID must be checked by SPMC for being a normal world ID.
  706. An SP sending a direct message request must have bit 15 set in its origin
  707. endpoint ID and this can be checked by the SPMC when the SP invokes the ABI.
  708. The SPMC shall reject the direct message if the claimed world in origin endpoint
  709. ID is not consistent:
  710. - It is either forwarded by SPMD and thus origin endpoint ID must be a "normal
  711. world ID",
  712. - or initiated by an SP and thus origin endpoint ID must be a "secure world ID".
  713. FFA_MSG_SEND_DIRECT_REQ/FFA_MSG_SEND_DIRECT_RESP
  714. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  715. This is a mandatory interface for secure partitions consisting in direct request
  716. and responses with the following rules:
  717. - An SP can send a direct request to another SP.
  718. - An SP can receive a direct request from another SP.
  719. - An SP can send a direct response to another SP.
  720. - An SP cannot send a direct request to an Hypervisor or OS kernel.
  721. - An Hypervisor or OS kernel can send a direct request to an SP.
  722. - An SP can send a direct response to an Hypervisor or OS kernel.
  723. FFA_NOTIFICATION_BITMAP_CREATE/FFA_NOTIFICATION_BITMAP_DESTROY
  724. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  725. The secure partitions notifications bitmap are statically allocated by the SPMC.
  726. Hence, this interface is not to be issued by secure partitions.
  727. At initialization, the SPMC is not aware of VMs/partitions deployed in the
  728. normal world. Hence, the Hypervisor or OS kernel must use both ABIs for SPMC
  729. to be prepared to handle notifications for the provided VM ID.
  730. FFA_NOTIFICATION_BIND/FFA_NOTIFICATION_UNBIND
  731. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  732. Pair of interfaces to manage permissions to signal notifications. Prior to
  733. handling notifications, an FF-A endpoint must allow a given sender to signal a
  734. bitmap of notifications.
  735. If the receiver doesn't have notification support enabled in its FF-A manifest,
  736. it won't be able to bind notifications, hence forbidding it to receive any
  737. notifications.
  738. FFA_NOTIFICATION_SET/FFA_NOTIFICATION_GET
  739. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  740. FFA_NOTIFICATION_GET retrieves all pending global notifications and
  741. per-vCPU notifications targeted to the current vCPU.
  742. Hafnium maintains a global count of pending notifications which gets incremented
  743. and decremented when handling FFA_NOTIFICATION_SET and FFA_NOTIFICATION_GET
  744. respectively. A delayed SRI is triggered if the counter is non-zero when the
  745. SPMC returns to normal world.
  746. FFA_NOTIFICATION_INFO_GET
  747. ~~~~~~~~~~~~~~~~~~~~~~~~~
  748. Hafnium maintains a global count of pending notifications whose information
  749. has been retrieved by this interface. The count is incremented and decremented
  750. when handling FFA_NOTIFICATION_INFO_GET and FFA_NOTIFICATION_GET respectively.
  751. It also tracks notifications whose information has been retrieved individually,
  752. such that it avoids duplicating returned information for subsequent calls to
  753. FFA_NOTIFICATION_INFO_GET. For each notification, this state information is
  754. reset when receiver called FFA_NOTIFICATION_GET to retrieve them.
  755. FFA_SPM_ID_GET
  756. ~~~~~~~~~~~~~~
  757. Returns the FF-A ID allocated to an SPM component which can be one of SPMD
  758. or SPMC.
  759. At initialization, the SPMC queries the SPMD for the SPMC ID, using the
  760. FFA_ID_GET interface, and records it. The SPMC can also query the SPMD ID using
  761. the FFA_SPM_ID_GET interface at the secure physical FF-A instance.
  762. Secure partitions call this interface at the virtual FF-A instance, to which
  763. the SPMC returns the priorly retrieved SPMC ID.
  764. The Hypervisor or OS kernel can issue the FFA_SPM_ID_GET call handled by the
  765. SPMD, which returns the SPMC ID.
  766. FFA_SECONDARY_EP_REGISTER
  767. ~~~~~~~~~~~~~~~~~~~~~~~~~
  768. When the SPMC boots, all secure partitions are initialized on their primary
  769. Execution Context.
  770. The FFA_SECONDARY_EP_REGISTER interface is to be used by a secure partition
  771. from its first execution context, to provide the entry point address for
  772. secondary execution contexts.
  773. A secondary EC is first resumed either upon invocation of PSCI_CPU_ON from
  774. the NWd or by invocation of FFA_RUN.
  775. SPMC-SPMD direct requests/responses
  776. -----------------------------------
  777. Implementation-defined FF-A IDs are allocated to the SPMC and SPMD.
  778. Using those IDs in source/destination fields of a direct request/response
  779. permits SPMD to SPMC communication and either way.
  780. - SPMC to SPMD direct request/response uses SMC conduit.
  781. - SPMD to SPMC direct request/response uses ERET conduit.
  782. This is used in particular to convey power management messages.
  783. PE MMU configuration
  784. --------------------
  785. With secure virtualization enabled (``HCR_EL2.VM = 1``) and for S-EL1
  786. partitions, two IPA spaces (secure and non-secure) are output from the
  787. secure EL1&0 Stage-1 translation.
  788. The EL1&0 Stage-2 translation hardware is fed by:
  789. - A secure IPA when the SP EL1&0 Stage-1 MMU is disabled.
  790. - One of secure or non-secure IPA when the secure EL1&0 Stage-1 MMU is enabled.
  791. ``VTCR_EL2`` and ``VSTCR_EL2`` provide configuration bits for controlling the
  792. NS/S IPA translations. The following controls are set up:
  793. ``VSTCR_EL2.SW = 0`` , ``VSTCR_EL2.SA = 0``, ``VTCR_EL2.NSW = 0``,
  794. ``VTCR_EL2.NSA = 1``:
  795. - Stage-2 translations for the NS IPA space access the NS PA space.
  796. - Stage-2 translation table walks for the NS IPA space are to the secure PA space.
  797. Secure and non-secure IPA regions (rooted to by ``VTTBR_EL2`` and ``VSTTBR_EL2``)
  798. use the same set of Stage-2 page tables within a SP.
  799. The ``VTCR_EL2/VSTCR_EL2/VTTBR_EL2/VSTTBR_EL2`` virtual address space
  800. configuration is made part of a vCPU context.
  801. For S-EL0 partitions with VHE enabled, a single secure EL2&0 Stage-1 translation
  802. regime is used for both Hafnium and the partition.
  803. Interrupt management
  804. --------------------
  805. GIC ownership
  806. ~~~~~~~~~~~~~
  807. The SPMC owns the GIC configuration. Secure and non-secure interrupts are
  808. trapped at S-EL2. The SPMC manages interrupt resources and allocates interrupt
  809. IDs based on SP manifests. The SPMC acknowledges physical interrupts and injects
  810. virtual interrupts by setting the use of vIRQ/vFIQ bits before resuming a SP.
  811. Non-secure interrupt handling
  812. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  813. The following illustrate the scenarios of non secure physical interrupts trapped
  814. by the SPMC:
  815. - The SP handles a managed exit operation:
  816. .. image:: ../resources/diagrams/ffa-ns-interrupt-handling-managed-exit.png
  817. - The SP is pre-empted without managed exit:
  818. .. image:: ../resources/diagrams/ffa-ns-interrupt-handling-sp-preemption.png
  819. Secure interrupt handling
  820. -------------------------
  821. This section documents the support implemented for secure interrupt handling in
  822. SPMC as per the guidance provided by FF-A v1.1 Beta0 specification.
  823. The following assumptions are made about the system configuration:
  824. - In the current implementation, S-EL1 SPs are expected to use the para
  825. virtualized ABIs for interrupt management rather than accessing virtual GIC
  826. interface.
  827. - Unless explicitly stated otherwise, this support is applicable only for
  828. S-EL1 SPs managed by SPMC.
  829. - Secure interrupts are configured as G1S or G0 interrupts.
  830. - All physical interrupts are routed to SPMC when running a secure partition
  831. execution context.
  832. A physical secure interrupt could preempt normal world execution. Moreover, when
  833. the execution is in secure world, it is highly likely that the target of a
  834. secure interrupt is not the currently running execution context of an SP. It
  835. could be targeted to another FF-A component. Consequently, secure interrupt
  836. management depends on the state of the target execution context of the SP that
  837. is responsible for handling the interrupt. Hence, the spec provides guidance on
  838. how to signal start and completion of secure interrupt handling as discussed in
  839. further sections.
  840. Secure interrupt signaling mechanisms
  841. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  842. Signaling refers to the mechanisms used by SPMC to indicate to the SP execution
  843. context that it has a pending virtual interrupt and to further run the SP
  844. execution context, such that it can handle the virtual interrupt. SPMC uses
  845. either the FFA_INTERRUPT interface with ERET conduit or vIRQ signal for signaling
  846. to S-EL1 SPs. When normal world execution is preempted by a secure interrupt,
  847. the SPMD uses the FFA_INTERRUPT ABI with ERET conduit to signal interrupt to SPMC
  848. running in S-EL2.
  849. +-----------+---------+---------------+---------------------------------------+
  850. | SP State | Conduit | Interface and | Description |
  851. | | | parameters | |
  852. +-----------+---------+---------------+---------------------------------------+
  853. | WAITING | ERET, | FFA_INTERRUPT,| SPMC signals to SP the ID of pending |
  854. | | vIRQ | Interrupt ID | interrupt. It pends vIRQ signal and |
  855. | | | | resumes execution context of SP |
  856. | | | | through ERET. |
  857. +-----------+---------+---------------+---------------------------------------+
  858. | BLOCKED | ERET, | FFA_INTERRUPT | SPMC signals to SP that an interrupt |
  859. | | vIRQ | | is pending. It pends vIRQ signal and |
  860. | | | | resumes execution context of SP |
  861. | | | | through ERET. |
  862. +-----------+---------+---------------+---------------------------------------+
  863. | PREEMPTED | vIRQ | NA | SPMC pends the vIRQ signal but does |
  864. | | | | not resume execution context of SP. |
  865. +-----------+---------+---------------+---------------------------------------+
  866. | RUNNING | ERET, | NA | SPMC pends the vIRQ signal and resumes|
  867. | | vIRQ | | execution context of SP through ERET. |
  868. +-----------+---------+---------------+---------------------------------------+
  869. Secure interrupt completion mechanisms
  870. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  871. A SP signals secure interrupt handling completion to the SPMC through the
  872. following mechanisms:
  873. - ``FFA_MSG_WAIT`` ABI if it was in WAITING state.
  874. - ``FFA_RUN`` ABI if its was in BLOCKED state.
  875. In the current implementation, S-EL1 SPs use para-virtualized HVC interface
  876. implemented by SPMC to perform priority drop and interrupt deactivation (we
  877. assume EOImode = 0, i.e. priority drop and deactivation are done together).
  878. If normal world execution was preempted by secure interrupt, SPMC uses
  879. FFA_NORMAL_WORLD_RESUME ABI to indicate completion of secure interrupt handling
  880. and further return execution to normal world. If the current SP execution
  881. context was preempted by a secure interrupt to be handled by execution context
  882. of target SP, SPMC resumes current SP after signal completion by target SP
  883. execution context.
  884. An action is broadly a set of steps taken by the SPMC in response to a physical
  885. interrupt. In order to simplify the design, the current version of secure
  886. interrupt management support in SPMC (Hafnium) does not fully implement the
  887. Scheduling models and Partition runtime models. However, the current
  888. implementation loosely maps to the following actions that are legally allowed
  889. by the specification. Please refer to the Table 8.4 in the spec for further
  890. description of actions. The action specified for a type of interrupt when the
  891. SP is in the message processing running state cannot be less permissive than the
  892. action specified for the same type of interrupt when the SP is in the interrupt
  893. handling running state.
  894. +--------------------+--------------------+------------+-------------+
  895. | Runtime Model | NS-Int | Self S-Int | Other S-Int |
  896. +--------------------+--------------------+------------+-------------+
  897. | Message Processing | Signalable with ME | Signalable | Signalable |
  898. +--------------------+--------------------+------------+-------------+
  899. | Interrupt Handling | Queued | Queued | Queued |
  900. +--------------------+--------------------+------------+-------------+
  901. Abbreviations:
  902. - NS-Int: A Non-secure physical interrupt. It requires a switch to the Normal
  903. world to be handled.
  904. - Other S-Int: A secure physical interrupt targeted to an SP different from
  905. the one that is currently running.
  906. - Self S-Int: A secure physical interrupt targeted to the SP that is currently
  907. running.
  908. The following figure describes interrupt handling flow when secure interrupt
  909. triggers while in normal world:
  910. .. image:: ../resources/diagrams/ffa-secure-interrupt-handling-nwd.png
  911. A brief description of the events:
  912. - 1) Secure interrupt triggers while normal world is running.
  913. - 2) FIQ gets trapped to EL3.
  914. - 3) SPMD signals secure interrupt to SPMC at S-EL2 using FFA_INTERRUPT ABI.
  915. - 4) SPMC identifies target vCPU of SP and injects virtual interrupt (pends
  916. vIRQ).
  917. - 5) Since SP1 vCPU is in WAITING state, SPMC signals using FFA_INTERRUPT with
  918. interrupt id as argument and resume it using ERET.
  919. - 6) Execution traps to vIRQ handler in SP1 provided that interrupt is not
  920. masked i.e., PSTATE.I = 0
  921. - 7) SP1 services the interrupt and invokes the de-activation HVC call.
  922. - 8) SPMC does internal state management and further de-activates the physical
  923. interrupt and resumes SP vCPU.
  924. - 9) SP performs secure interrupt completion through FFA_MSG_WAIT ABI.
  925. - 10) SPMC returns control to EL3 using FFA_NORMAL_WORLD_RESUME.
  926. - 11) EL3 resumes normal world execution.
  927. The following figure describes interrupt handling flow when secure interrupt
  928. triggers while in secure world:
  929. .. image:: ../resources/diagrams/ffa-secure-interrupt-handling-swd.png
  930. A brief description of the events:
  931. - 1) Secure interrupt triggers while SP2 is running and SP1 is blocked.
  932. - 2) Gets trapped to SPMC as IRQ.
  933. - 3) SPMC finds the target vCPU of secure partition responsible for handling
  934. this secure interrupt. In this scenario, it is SP1.
  935. - 4) SPMC pends vIRQ for SP1 and signals through FFA_INTERRUPT interface.
  936. SPMC further resumes SP1 through ERET conduit.
  937. - 5) Execution traps to vIRQ handler in SP1 provided that interrupt is not
  938. masked i.e., PSTATE.I = 0
  939. - 6) SP1 services the secure interrupt and invokes the de-activation HVC call.
  940. - 7) SPMC does internal state management, de-activates the physical interrupt
  941. and resumes SP1 vCPU.
  942. - 8) Assuming SP1 is in BLOCKED state, SP1 performs secure interrupt completion
  943. through FFA_RUN ABI.
  944. - 9) SPMC resumes the pre-empted vCPU of SP2.
  945. Power management
  946. ----------------
  947. In platforms with or without secure virtualization:
  948. - The NWd owns the platform PM policy.
  949. - The Hypervisor or OS kernel is the component initiating PSCI service calls.
  950. - The EL3 PSCI library is in charge of the PM coordination and control
  951. (eventually writing to platform registers).
  952. - While coordinating PM events, the PSCI library calls backs into the Secure
  953. Payload Dispatcher for events the latter has statically registered to.
  954. When using the SPMD as a Secure Payload Dispatcher:
  955. - A power management event is relayed through the SPD hook to the SPMC.
  956. - In the current implementation only cpu on (svc_on_finish) and cpu off
  957. (svc_off) hooks are registered.
  958. - The behavior for the cpu on event is described in `Secondary cores boot-up`_.
  959. The SPMC is entered through its secondary physical core entry point.
  960. - The cpu off event occurs when the NWd calls PSCI_CPU_OFF. The PM event is
  961. signaled to the SPMC through a power management framework message.
  962. It consists in a SPMD-to-SPMC direct request/response (`SPMC-SPMD direct
  963. requests/responses`_) conveying the event details and SPMC response.
  964. The SPMD performs a synchronous entry into the SPMC. The SPMC is entered and
  965. updates its internal state to reflect the physical core is being turned off.
  966. In the current implementation no SP is resumed as a consequence. This behavior
  967. ensures a minimal support for CPU hotplug e.g. when initiated by the NWd linux
  968. userspace.
  969. Arm architecture extensions for security hardening
  970. ==================================================
  971. Hafnium supports the following architecture extensions for security hardening:
  972. - Pointer authentication (FEAT_PAuth): the extension permits detection of forged
  973. pointers used by ROP type of attacks through the signing of the pointer
  974. value. Hafnium is built with the compiler branch protection option to permit
  975. generation of a pointer authentication code for return addresses (pointer
  976. authentication for instructions). The APIA key is used while Hafnium runs.
  977. A random key is generated at boot time and restored upon entry into Hafnium
  978. at run-time. APIA and other keys (APIB, APDA, APDB, APGA) are saved/restored
  979. in vCPU contexts permitting to enable pointer authentication in VMs/SPs.
  980. - Branch Target Identification (FEAT_BTI): the extension permits detection of
  981. unexpected indirect branches used by JOP type of attacks. Hafnium is built
  982. with the compiler branch protection option, inserting land pads at function
  983. prologues that are reached by indirect branch instructions (BR/BLR).
  984. Hafnium code pages are marked as guarded in the EL2 Stage-1 MMU descriptors
  985. such that an indirect branch must always target a landpad. A fault is
  986. triggered otherwise. VMs/SPs can (independently) mark their code pages as
  987. guarded in the EL1&0 Stage-1 translation regime.
  988. - Memory Tagging Extension (FEAT_MTE): the option permits detection of out of
  989. bound memory array accesses or re-use of an already freed memory region.
  990. Hafnium enables the compiler option permitting to leverage MTE stack tagging
  991. applied to core stacks. Core stacks are marked as normal tagged memory in the
  992. EL2 Stage-1 translation regime. A synchronous data abort is generated upon tag
  993. check failure on load/stores. A random seed is generated at boot time and
  994. restored upon entry into Hafnium. MTE system registers are saved/restored in
  995. vCPU contexts permitting MTE usage from VMs/SPs.
  996. SMMUv3 support in Hafnium
  997. =========================
  998. An SMMU is analogous to an MMU in a CPU. It performs address translations for
  999. Direct Memory Access (DMA) requests from system I/O devices.
  1000. The responsibilities of an SMMU include:
  1001. - Translation: Incoming DMA requests are translated from bus address space to
  1002. system physical address space using translation tables compliant to
  1003. Armv8/Armv7 VMSA descriptor format.
  1004. - Protection: An I/O device can be prohibited from read, write access to a
  1005. memory region or allowed.
  1006. - Isolation: Traffic from each individial device can be independently managed.
  1007. The devices are differentiated from each other using unique translation
  1008. tables.
  1009. The following diagram illustrates a typical SMMU IP integrated in a SoC with
  1010. several I/O devices along with Interconnect and Memory system.
  1011. .. image:: ../resources/diagrams/MMU-600.png
  1012. SMMU has several versions including SMMUv1, SMMUv2 and SMMUv3. Hafnium provides
  1013. support for SMMUv3 driver in both normal and secure world. A brief introduction
  1014. of SMMUv3 functionality and the corresponding software support in Hafnium is
  1015. provided here.
  1016. SMMUv3 features
  1017. ---------------
  1018. - SMMUv3 provides Stage1, Stage2 translation as well as nested (Stage1 + Stage2)
  1019. translation support. It can either bypass or abort incoming translations as
  1020. well.
  1021. - Traffic (memory transactions) from each upstream I/O peripheral device,
  1022. referred to as Stream, can be independently managed using a combination of
  1023. several memory based configuration structures. This allows the SMMUv3 to
  1024. support a large number of streams with each stream assigned to a unique
  1025. translation context.
  1026. - Support for Armv8.1 VMSA where the SMMU shares the translation tables with
  1027. a Processing Element. AArch32(LPAE) and AArch64 translation table format
  1028. are supported by SMMUv3.
  1029. - SMMUv3 offers non-secure stream support with secure stream support being
  1030. optional. Logically, SMMUv3 behaves as if there is an indepdendent SMMU
  1031. instance for secure and non-secure stream support.
  1032. - It also supports sub-streams to differentiate traffic from a virtualized
  1033. peripheral associated with a VM/SP.
  1034. - Additionally, SMMUv3.2 provides support for PEs implementing Armv8.4-A
  1035. extensions. Consequently, SPM depends on Secure EL2 support in SMMUv3.2
  1036. for providing Secure Stage2 translation support to upstream peripheral
  1037. devices.
  1038. SMMUv3 Programming Interfaces
  1039. -----------------------------
  1040. SMMUv3 has three software interfaces that are used by the Hafnium driver to
  1041. configure the behaviour of SMMUv3 and manage the streams.
  1042. - Memory based data strutures that provide unique translation context for
  1043. each stream.
  1044. - Memory based circular buffers for command queue and event queue.
  1045. - A large number of SMMU configuration registers that are memory mapped during
  1046. boot time by Hafnium driver. Except a few registers, all configuration
  1047. registers have independent secure and non-secure versions to configure the
  1048. behaviour of SMMUv3 for translation of secure and non-secure streams
  1049. respectively.
  1050. Peripheral device manifest
  1051. --------------------------
  1052. Currently, SMMUv3 driver in Hafnium only supports dependent peripheral devices.
  1053. These devices are dependent on PE endpoint to initiate and receive memory
  1054. management transactions on their behalf. The acccess to the MMIO regions of
  1055. any such device is assigned to the endpoint during boot. Moreover, SMMUv3 driver
  1056. uses the same stage 2 translations for the device as those used by partition
  1057. manager on behalf of the PE endpoint. This ensures that the peripheral device
  1058. has the same visibility of the physical address space as the endpoint. The
  1059. device node of the corresponding partition manifest (refer to `[1]`_ section 3.2
  1060. ) must specify these additional properties for each peripheral device in the
  1061. system :
  1062. - smmu-id: This field helps to identify the SMMU instance that this device is
  1063. upstream of.
  1064. - stream-ids: List of stream IDs assigned to this device.
  1065. .. code:: shell
  1066. smmuv3-testengine {
  1067. base-address = <0x00000000 0x2bfe0000>;
  1068. pages-count = <32>;
  1069. attributes = <0x3>;
  1070. smmu-id = <0>;
  1071. stream-ids = <0x0 0x1>;
  1072. interrupts = <0x2 0x3>, <0x4 0x5>;
  1073. exclusive-access;
  1074. };
  1075. SMMUv3 driver limitations
  1076. -------------------------
  1077. The primary design goal for the Hafnium SMMU driver is to support secure
  1078. streams.
  1079. - Currently, the driver only supports Stage2 translations. No support for
  1080. Stage1 or nested translations.
  1081. - Supports only AArch64 translation format.
  1082. - No support for features such as PCI Express (PASIDs, ATS, PRI), MSI, RAS,
  1083. Fault handling, Performance Monitor Extensions, Event Handling, MPAM.
  1084. - No support for independent peripheral devices.
  1085. S-EL0 Partition support
  1086. =======================
  1087. The SPMC (Hafnium) has limited capability to run S-EL0 FF-A partitions using
  1088. FEAT_VHE (mandatory with ARMv8.1 in non-secure state, and in secure world
  1089. with ARMv8.4 and FEAT_SEL2).
  1090. S-EL0 partitions are useful for simple partitions that don't require full
  1091. Trusted OS functionality. It is also useful to reduce jitter and cycle
  1092. stealing from normal world since they are more lightweight than VMs.
  1093. S-EL0 partitions are presented, loaded and initialized the same as S-EL1 VMs by
  1094. the SPMC. They are differentiated primarily by the 'exception-level' property
  1095. and the 'execution-ctx-count' property in the SP manifest. They are host apps
  1096. under the single EL2&0 Stage-1 translation regime controlled by the SPMC and
  1097. call into the SPMC through SVCs as opposed to HVCs and SMCs. These partitions
  1098. can use FF-A defined services (FFA_MEM_PERM_*) to update or change permissions
  1099. for memory regions.
  1100. S-EL0 partitions are required by the FF-A specification to be UP endpoints,
  1101. capable of migrating, and the SPMC enforces this requirement. The SPMC allows
  1102. a S-EL0 partition to accept a direct message from secure world and normal world,
  1103. and generate direct responses to them.
  1104. Memory sharing between and with S-EL0 partitions is supported.
  1105. Indirect messaging, Interrupt handling and Notifications are not supported with
  1106. S-EL0 partitions and is work in progress, planned for future releases.
  1107. All S-EL0 partitions must use AArch64. AArch32 S-EL0 partitions are not
  1108. supported.
  1109. References
  1110. ==========
  1111. .. _[1]:
  1112. [1] `Arm Firmware Framework for Arm A-profile <https://developer.arm.com/docs/den0077/latest>`__
  1113. .. _[2]:
  1114. [2] :ref:`Secure Partition Manager using MM interface<Secure Partition Manager (MM)>`
  1115. .. _[3]:
  1116. [3] `Trusted Boot Board Requirements
  1117. Client <https://developer.arm.com/documentation/den0006/d/>`__
  1118. .. _[4]:
  1119. [4] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/lib/el3_runtime/aarch64/context.S#n45
  1120. .. _[5]:
  1121. [5] https://git.trustedfirmware.org/TF-A/tf-a-tests.git/tree/spm/cactus/plat/arm/fvp/fdts/cactus.dts
  1122. .. _[6]:
  1123. [6] https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html
  1124. .. _[7]:
  1125. [7] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/arm/board/fvp/fdts/fvp_spmc_manifest.dts
  1126. .. _[8]:
  1127. [8] https://lists.trustedfirmware.org/archives/list/tf-a@lists.trustedfirmware.org/thread/CFQFGU6H2D5GZYMUYGTGUSXIU3OYZP6U/
  1128. .. _[9]:
  1129. [9] https://trustedfirmware-a.readthedocs.io/en/latest/design/firmware-design.html#dynamic-configuration-during-cold-boot
  1130. --------------
  1131. *Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.*