realm-management-extension.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. Realm Management Extension (RME)
  2. ====================================
  3. FEAT_RME (or RME for short) is an Armv9-A extension and is one component of the
  4. `Arm Confidential Compute Architecture (Arm CCA)`_. TF-A supports RME starting
  5. from version 2.6. This chapter discusses the changes to TF-A to support RME and
  6. provides instructions on how to build and run TF-A with RME.
  7. RME support in TF-A
  8. ---------------------
  9. The following diagram shows an Arm CCA software architecture with TF-A as the
  10. EL3 firmware. In the Arm CCA architecture there are two additional security
  11. states and address spaces: ``Root`` and ``Realm``. TF-A firmware runs in the
  12. Root world. In the realm world, a Realm Management Monitor firmware (`RMM`_)
  13. manages the execution of Realm VMs and their interaction with the hypervisor.
  14. .. image:: ../resources/diagrams/arm-cca-software-arch.png
  15. RME is the hardware extension to support Arm CCA. To support RME, various
  16. changes have been introduced to TF-A. We discuss those changes below.
  17. Changes to translation tables library
  18. ***************************************
  19. RME adds Root and Realm Physical address spaces. To support this, two new
  20. memory type macros, ``MT_ROOT`` and ``MT_REALM``, have been added to the
  21. :ref:`Translation (XLAT) Tables Library`. These macros are used to configure
  22. memory regions as Root or Realm respectively.
  23. .. note::
  24. Only version 2 of the translation tables library supports the new memory
  25. types.
  26. Changes to context management
  27. *******************************
  28. A new CPU context for the Realm world has been added. The existing
  29. :ref:`CPU context management API<PSCI Library Integration guide for Armv8-A
  30. AArch32 systems>` can be used to manage Realm context.
  31. Boot flow changes
  32. *******************
  33. In a typical TF-A boot flow, BL2 runs at Secure-EL1. However when RME is
  34. enabled, TF-A runs in the Root world at EL3. Therefore, the boot flow is
  35. modified to run BL2 at EL3 when RME is enabled. In addition to this, a
  36. Realm-world firmware (`RMM`_) is loaded by BL2 in the Realm physical address
  37. space.
  38. The boot flow when RME is enabled looks like the following:
  39. 1. BL1 loads and executes BL2 at EL3
  40. 2. BL2 loads images including RMM
  41. 3. BL2 transfers control to BL31
  42. 4. BL31 initializes SPM (if SPM is enabled)
  43. 5. BL31 initializes RMM
  44. 6. BL31 transfers control to Normal-world software
  45. Granule Protection Tables (GPT) library
  46. *****************************************
  47. Isolation between the four physical address spaces is enforced by a process
  48. called Granule Protection Check (GPC) performed by the MMU downstream any
  49. address translation. GPC makes use of Granule Protection Table (GPT) in the
  50. Root world that describes the physical address space assignment of every
  51. page (granule). A GPT library that provides APIs to initialize GPTs and to
  52. transition granules between different physical address spaces has been added.
  53. More information about the GPT library can be found in the
  54. :ref:`Granule Protection Tables Library` chapter.
  55. RMM Dispatcher (RMMD)
  56. ************************
  57. RMMD is a new standard runtime service that handles the switch to the Realm
  58. world. It initializes the `RMM`_ and handles Realm Management Interface (RMI)
  59. SMC calls from Non-secure.
  60. There is a contract between `RMM`_ and RMMD that defines the arguments that the
  61. former needs to take in order to initialize and also the possible return values.
  62. This contract is defined in the `RMM`_ Boot Interface, which can be found at
  63. :ref:`rmm_el3_boot_interface`.
  64. There is also a specification of the runtime services provided by TF-A
  65. to `RMM`_. This can be found at :ref:`runtime_services_and_interface`.
  66. Test Realm Payload (TRP)
  67. *************************
  68. TRP is a small test payload that runs at R-EL2 and implements a subset of
  69. the Realm Management Interface (RMI) commands to primarily test EL3 firmware
  70. and the interface between R-EL2 and EL3. When building TF-A with RME enabled,
  71. if the path to an RMM image is not provided, TF-A builds the TRP by default
  72. and uses it as the R-EL2 payload.
  73. Building and running TF-A with RME
  74. ----------------------------------
  75. This section describes how you can build and run TF-A with RME enabled.
  76. We assume you have read the :ref:`Prerequisites` to build TF-A.
  77. The following instructions show you how to build and run TF-A with RME
  78. on FVP for two scenarios:
  79. - Three-world execution: This is the configuration to use if Secure
  80. world functionality is not needed. TF-A is tested with the following
  81. software entities in each world as listed below:
  82. - NS Host (RME capable Linux or TF-A Tests),
  83. - Root (TF-A)
  84. - R-EL2 (`RMM`_ or TRP)
  85. - Four-world execution: This is the configuration to use if both Secure
  86. and Realm world functionality is needed. TF-A is tested with the following
  87. software entities in each world as listed below:
  88. - NS Host (RME capable Linux or TF-A Tests),
  89. - Root (TF-A)
  90. - R-EL2 (`RMM`_ or TRP)
  91. - S-EL2 (Hafnium SPM)
  92. To run the tests, you need an FVP model. Please use the :ref:`latest version
  93. <Arm Fixed Virtual Platforms (FVP)>` of *FVP_Base_RevC-2xAEMvA* model. If NS
  94. Host is Linux, then the below instructions assume that a suitable RME enabled
  95. kernel image and associated root filesystem are available.
  96. Three-world execution
  97. *********************
  98. **1. Clone and build RMM Image**
  99. Please refer to the `RMM Getting Started`_ on how to setup
  100. Host Environment and build `RMM`_. The build commands assume that
  101. an AArch64 toolchain and CMake executable are available in the
  102. shell PATH variable and CROSS_COMPILE variable has been setup
  103. appropriately.
  104. To clone `RMM`_ and build using the default build options for FVP:
  105. .. code:: shell
  106. git clone --recursive https://git.trustedfirmware.org/TF-RMM/tf-rmm.git
  107. cd tf-rmm
  108. cmake -DRMM_CONFIG=fvp_defcfg -S . -B build
  109. cmake --build build
  110. This will generate **rmm.img** in **build/Release** folder.
  111. **2. Clone and build TF-A Tests with Realm Payload**
  112. This step is only needed if NS Host is TF-A Tests. The full set
  113. of instructions to setup build host and build options for
  114. TF-A-Tests can be found in the `TFTF Getting Started`_. TF-A Tests
  115. can test Realm world with either `RMM`_ or TRP in R-EL2. In the TRP case,
  116. some tests which are not applicable will be skipped.
  117. Use the following instructions to build TF-A with `TF-A Tests`_ as the
  118. non-secure payload (BL33).
  119. .. code:: shell
  120. git clone https://git.trustedfirmware.org/TF-A/tf-a-tests.git
  121. cd tf-a-tests
  122. make CROSS_COMPILE=aarch64-none-elf- PLAT=fvp DEBUG=1 ENABLE_REALM_PAYLOAD_TESTS=1 all
  123. This produces a TF-A Tests binary (**tftf.bin**) with Realm payload packaged
  124. and **sp_layout.json** in the **build/fvp/debug** directory.
  125. **3. Build RME Enabled TF-A**
  126. The `TF-A Getting Started`_ has the necessary instructions to setup Host
  127. machine and build TF-A.
  128. To build for RME, set ``ENABLE_RME`` build option to 1 and provide the path to
  129. the `RMM`_ binary ``rmm.img`` using ``RMM`` build option.
  130. .. note::
  131. ENABLE_RME build option is currently experimental.
  132. .. note::
  133. If the ``RMM`` option is not specified, TF-A builds the TRP to load and
  134. run at R-EL2.
  135. .. code:: shell
  136. git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git
  137. cd trusted-firmware-a
  138. make CROSS_COMPILE=aarch64-none-elf- \
  139. PLAT=fvp \
  140. ENABLE_RME=1 \
  141. RMM=<path/to/rmm.img> \
  142. FVP_HW_CONFIG_DTS=fdts/fvp-base-gicv3-psci-1t.dts \
  143. DEBUG=1 \
  144. BL33=<path/to/bl33> \
  145. all fip
  146. ``BL33`` can point to a Non Secure Bootloader like UEFI/U-Boot or
  147. the TF-A Tests binary(**tftf.bin**) from the previous step.
  148. This produces **bl1.bin** and **fip.bin** binaries in the **build/fvp/debug**
  149. directory.
  150. TF-A can also directly boot Linux kernel on the FVP. The kernel needs to be
  151. `preloaded` to a suitable memory location and this needs to be specified via
  152. ``PRELOADED_BL33_BASE`` build option. Also TF-A should implement the Linux
  153. kernel register conventions for boot and this can be set using the
  154. ``ARM_LINUX_KERNEL_AS_BL33`` option.
  155. .. code-block:: shell
  156. cd trusted-firmware-a
  157. make CROSS_COMPILE=aarch64-none-elf- \
  158. PLAT=fvp \
  159. ENABLE_RME=1 \
  160. RMM=<path/to/rmm.img> \
  161. FVP_HW_CONFIG_DTS=fdts/fvp-base-gicv3-psci-1t.dts \
  162. DEBUG=1 \
  163. ARM_LINUX_KERNEL_AS_BL33=1 \
  164. PRELOADED_BL33_BASE=0x84000000 \
  165. all fip
  166. The above command assumes that the Linux kernel will be placed in FVP
  167. memory at 0x84000000 via suitable FVP option (see the next step).
  168. .. _fvp_3_world_cmd:
  169. **4. Running FVP for 3 world setup**
  170. Use the following command to run the tests on FVP.
  171. .. code:: shell
  172. FVP_Base_RevC-2xAEMvA \
  173. -C bp.refcounter.non_arch_start_at_default=1 \
  174. -C bp.secureflashloader.fname=<path/to/bl1.bin> \
  175. -C bp.flashloader0.fname=<path/to/fip.bin> \
  176. -C bp.refcounter.use_real_time=0 \
  177. -C bp.ve_sysregs.exit_on_shutdown=1 \
  178. -C cache_state_modelled=1 \
  179. -C bp.dram_size=4 \
  180. -C bp.secure_memory=0 \
  181. -C pci.pci_smmuv3.mmu.SMMU_ROOT_IDR0=3 \
  182. -C pci.pci_smmuv3.mmu.SMMU_ROOT_IIDR=0x43B \
  183. -C pci.pci_smmuv3.mmu.root_register_page_offset=0x20000 \
  184. -C cluster0.NUM_CORES=4 \
  185. -C cluster0.PA_SIZE=48 \
  186. -C cluster0.ecv_support_level=2 \
  187. -C cluster0.gicv3.cpuintf-mmap-access-level=2 \
  188. -C cluster0.gicv3.without-DS-support=1 \
  189. -C cluster0.gicv4.mask-virtual-interrupt=1 \
  190. -C cluster0.has_arm_v8-6=1 \
  191. -C cluster0.has_amu=1 \
  192. -C cluster0.has_branch_target_exception=1 \
  193. -C cluster0.rme_support_level=2 \
  194. -C cluster0.has_rndr=1 \
  195. -C cluster0.has_v8_7_pmu_extension=2 \
  196. -C cluster0.max_32bit_el=-1 \
  197. -C cluster0.stage12_tlb_size=1024 \
  198. -C cluster0.check_memory_attributes=0 \
  199. -C cluster0.ish_is_osh=1 \
  200. -C cluster0.restriction_on_speculative_execution=2 \
  201. -C cluster0.restriction_on_speculative_execution_aarch32=2 \
  202. -C cluster1.NUM_CORES=4 \
  203. -C cluster1.PA_SIZE=48 \
  204. -C cluster1.ecv_support_level=2 \
  205. -C cluster1.gicv3.cpuintf-mmap-access-level=2 \
  206. -C cluster1.gicv3.without-DS-support=1 \
  207. -C cluster1.gicv4.mask-virtual-interrupt=1 \
  208. -C cluster1.has_arm_v8-6=1 \
  209. -C cluster1.has_amu=1 \
  210. -C cluster1.has_branch_target_exception=1 \
  211. -C cluster1.rme_support_level=2 \
  212. -C cluster1.has_rndr=1 \
  213. -C cluster1.has_v8_7_pmu_extension=2 \
  214. -C cluster1.max_32bit_el=-1 \
  215. -C cluster1.stage12_tlb_size=1024 \
  216. -C cluster1.check_memory_attributes=0 \
  217. -C cluster1.ish_is_osh=1 \
  218. -C cluster1.restriction_on_speculative_execution=2 \
  219. -C cluster1.restriction_on_speculative_execution_aarch32=2 \
  220. -C pctl.startup=0.0.0.0 \
  221. -C bp.smsc_91c111.enabled=1 \
  222. -C bp.hostbridge.userNetworking=1 \
  223. -C bp.virtioblockdevice.image_path=<path/to/rootfs.ext4>
  224. The ``bp.virtioblockdevice.image_path`` option presents the rootfs as a
  225. virtio block device to Linux kernel. It can be ignored if NS Host is
  226. TF-A-Tests or rootfs is accessed by some other mechanism.
  227. If TF-A was built to expect a preloaded Linux kernel, then use the following
  228. FVP argument to load the kernel image at the expected address.
  229. .. code-block:: shell
  230. --data cluster0.cpu0=<path_to_kernel_Image>@0x84000000 \
  231. .. tip::
  232. Tips to boot and run Linux faster on the FVP :
  233. 1. Set the FVP option ``cache_state_modelled`` to 0.
  234. 2. Disable the CPU Idle driver in Linux either by setting the kernel command line
  235. parameter "cpuidle.off=1" or by disabling the ``CONFIG_CPU_IDLE`` kernel config.
  236. If the NS Host is TF-A-Tests, then the default test suite in TFTF
  237. will execute on the FVP and this includes Realm world tests. The
  238. tail of the output from *uart0* should look something like the following.
  239. .. code-block:: shell
  240. ...
  241. > Test suite 'FF-A Interrupt'
  242. Passed
  243. > Test suite 'SMMUv3 tests'
  244. Passed
  245. > Test suite 'PMU Leakage'
  246. Passed
  247. > Test suite 'DebugFS'
  248. Passed
  249. > Test suite 'RMI and SPM tests'
  250. Passed
  251. > Test suite 'Realm payload at EL1'
  252. Passed
  253. > Test suite 'Invalid memory access'
  254. Passed
  255. ...
  256. Four-world execution
  257. ********************
  258. Four-world execution involves software components in each security state: root,
  259. secure, realm and non-secure. This section describes how to build TF-A
  260. with four-world support.
  261. We use TF-A as the root firmware, `Hafnium SPM`_ is the reference Secure world
  262. component running at S-EL2. `RMM`_ can be built as described in previous
  263. section. The examples below assume TF-A-Tests as the NS Host and utilize SPs
  264. from TF-A-Tests.
  265. **1. Obtain and build Hafnium SPM**
  266. .. code:: shell
  267. git clone --recurse-submodules https://git.trustedfirmware.org/hafnium/hafnium.git
  268. cd hafnium
  269. # Use the default prebuilt LLVM/clang toolchain
  270. PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH
  271. Feature MTE needs to be disabled in Hafnium build, apply following patch to
  272. project/reference submodule
  273. .. code:: diff
  274. diff --git a/BUILD.gn b/BUILD.gn
  275. index cc6a78f..234b20a 100644
  276. --- a/BUILD.gn
  277. +++ b/BUILD.gn
  278. @@ -83,7 +83,6 @@ aarch64_toolchains("secure_aem_v8a_fvp") {
  279. pl011_base_address = "0x1c090000"
  280. smmu_base_address = "0x2b400000"
  281. smmu_memory_size = "0x100000"
  282. - enable_mte = "1"
  283. plat_log_level = "LOG_LEVEL_INFO"
  284. }
  285. }
  286. .. code:: shell
  287. make PROJECT=reference
  288. The Hafnium binary should be located at
  289. *out/reference/secure_aem_v8a_fvp_clang/hafnium.bin*
  290. **2. Build RME enabled TF-A with SPM**
  291. Build TF-A with RME as well as SPM enabled.
  292. Use the ``sp_layout.json`` previously generated in TF-A Tests
  293. build to run SP tests.
  294. .. code:: shell
  295. make CROSS_COMPILE=aarch64-none-elf- \
  296. PLAT=fvp \
  297. ENABLE_RME=1 \
  298. FVP_HW_CONFIG_DTS=fdts/fvp-base-gicv3-psci-1t.dts \
  299. SPD=spmd \
  300. BRANCH_PROTECTION=1 \
  301. CTX_INCLUDE_PAUTH_REGS=1 \
  302. DEBUG=1 \
  303. SP_LAYOUT_FILE=<path/to/sp_layout.json> \
  304. BL32=<path/to/hafnium.bin> \
  305. BL33=<path/to/tftf.bin> \
  306. RMM=<path/to/rmm.img> \
  307. all fip
  308. **3. Running the FVP for a 4 world setup**
  309. Use the following arguments in addition to the FVP options mentioned in
  310. :ref:`4. Running FVP for 3 world setup <fvp_3_world_cmd>` to run tests for
  311. 4 world setup.
  312. .. code:: shell
  313. -C pci.pci_smmuv3.mmu.SMMU_AIDR=2 \
  314. -C pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B \
  315. -C pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 \
  316. -C pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 \
  317. -C pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0475 \
  318. -C pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 \
  319. -C pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 \
  320. -C pci.pci_smmuv3.mmu.SMMU_S_IDR3=0
  321. .. _Arm Confidential Compute Architecture (Arm CCA): https://www.arm.com/why-arm/architecture/security-features/arm-confidential-compute-architecture
  322. .. _Arm Architecture Models website: https://developer.arm.com/tools-and-software/simulation-models/fixed-virtual-platforms/arm-ecosystem-models
  323. .. _TF-A Getting Started: https://trustedfirmware-a.readthedocs.io/en/latest/getting_started/index.html
  324. .. _TF-A Tests: https://trustedfirmware-a-tests.readthedocs.io/en/latest
  325. .. _TFTF Getting Started: https://trustedfirmware-a-tests.readthedocs.io/en/latest/getting_started/index.html
  326. .. _Hafnium SPM: https://www.trustedfirmware.org/projects/hafnium
  327. .. _RMM Getting Started: https://tf-rmm.readthedocs.io/en/latest/getting_started/index.html
  328. .. _RMM: https://www.trustedfirmware.org/projects/tf-rmm/