blob: 964c18cef05142cf25d95dc30f9a8ade680b7bd1 [file] [log] [blame]
Mingyang Sun8360ef72021-01-07 18:02:45 +08001##########################################
2Stateless Root of Trust Services Reference
3##########################################
4
5:Author: Mingyang Sun
6:Organization: Arm Limited
7:Contact: mingyang.sun@arm.com
8
9
10************
11Introduction
12************
13
14This document describes the implementation for the FF-M v1.1 feature -
15'Stateless RoT Service', and the related references when developing RoT
16services.
17
18It is recommended to refer to the FF-M v1.0 specification [1]_ and FF-M v1.1
19extension [2]_ for background and rationale details.
20
21
22**********************
23Implementation Details
24**********************
25
26This chapter describes the implementation-defined items, including stateless
27handle value definition, tooling update, and programming API changes.
28
29Stateless Handle Value Definition
30=================================
31
32The index, stateless indicator, and service version information are encoded into
33a handle by the manifest tooling, and then generated to header file ``sid.h``.
34
35.. list-table:: Bit Fields of Stateless Handle
36 :header-rows: 1
37 :widths: 20 80
38
39 * - Bits
40 - Field Description
41 * - bit 31
42 - reserved
43 * - bit 30
44 - stateless handle indicator bit, always 1
45 * - bit 29 - bit 16
46 - reserved
47 * - bit 15 - bit 8
48 - service version requested by client - for client version check
49 * - bit 7 - bit 0
50 - the handle index, [0, 31]
51
52Since connection-based services and stateless services share the same PSA API
53``psa_call()``, an indicator bit is set in the handle indicate the type of the
54handle. If it is set, the handle is stateless, and definition is as described
55in the table above. Maximum connection-based handle is 0x3FFFFFFF, thus the
56indicator bit is always 0.
57
58The index is used for organizing stateless services in manifest tool and
59locating a stateless service in SPM logic. A range of index [0, 31] is the
60initial implementation. Future expansion is possible.
61
62Tooling Support
63===============
64
65TF-M provides a tool (``tools/tfm_parse_manifest_list.py``) to generate source
66header files required by partition and services. For example, the generated
67``sid.h`` contains service ID and version. The tooling is extended to generate
68stateless handle from partition manifests automatically.
69
70The ``stateless_handle`` attribute in manifest is only supported by partitions
71with firmware framework version 1.1.
72
73- If ``stateless_handle`` in manifest is set to an integer, the index is
74 ``stateless_handle - 1``.
75- If it is ``auto`` or not set, the first empty index in range [0, 31] is
76 assigned.
77- Other settings - tooling reports an error.
78
79Finally, the tooling encodes the handle according to definitions in
80`Stateless Handle Value Definition`_ section, and writes them to ``sid.h``
81header file.
82
83Changes in Programming API
84==========================
85
86This chapter describes the changes in programming API for stateless services.
87The following APIs' bebavious and message data structure members are updated to
88support the stateless service.
89
90psa_connect()
91-------------
92
93According to FF-M v1.1, client calling ``psa_connect()`` with the SID of a
94stateless RoT Service is a ``PROGRAMMER_ERROR``.
95
96psa_close()
97-----------
98
99According to FF-M v1.1, client passing a stateless handle to call this API is a
100``PROGRAMMER_ERROR``.
101
102psa_call()
103----------
104
105.. code-block:: c
106
107 psa_status_t psa_call(psa_handle_t handle, int32_t type,
108 const psa_invec *in_vec, size_t in_len,
109 psa_outvec *out_vec, size_t out_len)
110
111API parameters and behaviour change:
112
1131. The ``handle`` parameter must be a stateless handle defined in
114 ``psa_manifest/sid.h`` when requesting a stateless service.
1152. This API validates stateless handle, decodes index and service version
116 information from it. SPM uses the index to know which stateless service is
117 requested.
1183. This API performs some operations as ``psa_connect()`` does, such as the
119 authorization check, service and client version check, and handle space
120 allocation.
121
122Service behaviour change during a "psa_call":
123
124Service does not accept connection and disconnection messages. After a
125"psa_call" request is serviced, it calls ``psa_reply()``, frees the connection
126handle to handle pool.
127
128psa_set_rhandle()
129-----------------
130
131According to FF-M v1.1, stateless service calling this API on a message is a
132``PROGRAMMER_ERROR`` and it will never return.
133
134psa_msg_t type
135--------------
136
137The ``rhandle`` member of a ``psa_msg_t`` type received by a stateless RoT
138Service is always ``NULL``.
139
140
141**************************
142Application Recommendation
143**************************
144
145There are particular services that do not need sessions. The access to the
146service is a one-shot connection. These services provide standalone operations
147that do not require any non-volatile state of resources to be maintained by the
148RoT service itself or do not expose any kind of context or session to the
149caller. Such services are recommended to be implemented as stateless, to provide
150quick access and to avoid extra overheads.
151
152In this case, ``rhandle`` access would be prohibited as it is used for saving
153state or non-volatile resources while stateless services do not need them.
154
155Update Feasibility of Existing Services
156=======================================
157
158TF-M native services are used widely. They only need standalone operations and
159do not need to keep state between sessions. For example, the service in Crypto
160partition does not do anything during ``psa_connect()`` or ``psa_close()``
161process. Same for services in other partitions, thus all of them can be
162implemented as stateless.
163
164Analysis for them:
165
166.. list-table:: TF-M Partition Services Update Possibility
167 :header-rows: 1
168 :widths: 30 30 40
169
170 * - Partition
171 - Number of Services
172 - Can be Stateless
173 * - ITS
174 - 4
175 - All
176 * - PS
177 - 5
178 - All
179 * - Crypto
180 - 1
181 - All
182 * - FWU
183 - 6
184 - All
185 * - Platform
186 - 4
187 - All
188 * - Initial Attestation
189 - 2
190 - All
191
192Other services are not analyzed here.
193
194Grouping Services
195=================
196
197Stateless service table is stored statically, and TF-M supports 32 stateless
198services currently.
199
200Similar stateless services in a partition could be grouped, and assign one
201``SID`` for the group. The ``type`` parameter in ``psa_call()`` could be
202extended to identify the service in group. In this case, it is recommended to
203use consecutive value for ``type``.
204
205It is recommended that each Seccure Partition declares one stateless service
206and uses the type parameter to distinguish different stateless services.
207Therefore, more stateless services can be supported.
208
209Migrating to Stateless Services
210===============================
211
212Please refer to Chapter 4 "Stateless Root of Trust services", Appendix B.3.2
213"Using a stateless RoT Service", and Appendix D "Implementing session-less RoT
214Services" in FF-M v1.1 document for details on which kind of service can be
215stateless and how to implement a stateless service.
216
217
218*********
219Reference
220*********
221
222.. [1] `FF-M v1.0 Specification <https://developer.arm.com/-/media/Files/pdf/PlatformSecurityArchitecture/Architect/DEN0063-PSA_Firmware_Framework-1.0.0-2.pdf?revision=2d1429fa-4b5b-461a-a60e-4ef3d8f7f4b4>`__
223
224.. [2] `FF-M v1.1 Extention <https://documentation-service.arm.com/static/600067c09b9c2d1bb22cd1c5?token=>`__
225
226--------------
227
228*Copyright (c) 2021, Arm Limited. All rights reserved.*