blob: 25a431efe0d76c8b19b3900432d2efc292f009de [file] [log] [blame]
Soby Mathewb4c6df42022-11-09 11:13:29 +00001/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4 */
5
6#include <attestation.h>
Soby Mathewb4c6df42022-11-09 11:13:29 +00007#include <debug.h>
8#include <granule.h>
9#include <measurement.h>
10#include <realm.h>
AlexeiFedorov5b186ad2023-04-26 14:43:18 +010011#include <rsi-handler.h>
Soby Mathewb4c6df42022-11-09 11:13:29 +000012#include <smc-rsi.h>
13#include <smc.h>
14#include <string.h>
15#include <utils_def.h>
16
AlexeiFedorovefe2aec2023-06-08 16:17:00 +010017#define MAX_EXTENDED_SIZE (64U)
AlexeiFedorov7b3c3042023-06-28 15:41:11 +010018#define MAX_MEASUREMENT_WORDS (MAX_MEASUREMENT_SIZE / sizeof(unsigned long))
Soby Mathewb4c6df42022-11-09 11:13:29 +000019/*
20 * Return the Realm Personalization Value.
21 *
22 * Arguments:
23 * rd - The Realm descriptor.
Mate Toth-Pal071aa562023-07-04 09:09:26 +020024 * claim_ptr - The start address of the Realm Personalization Value claim
25 * claim_len - The length of the Realm Personalization Value claim
Soby Mathewb4c6df42022-11-09 11:13:29 +000026 */
Mate Toth-Pal071aa562023-07-04 09:09:26 +020027static void get_rpv(struct rd *rd, void **claim_ptr, size_t *claim_len)
Soby Mathewb4c6df42022-11-09 11:13:29 +000028{
Mate Toth-Pal071aa562023-07-04 09:09:26 +020029 *claim_ptr = (uint8_t *)&(rd->rpv[0]);
30 *claim_len = RPV_SIZE;
Soby Mathewb4c6df42022-11-09 11:13:29 +000031}
32
33/*
AlexeiFedorov97844202023-04-27 15:17:35 +010034 * Function to continue with the sign operation
Soby Mathewb4c6df42022-11-09 11:13:29 +000035 */
AlexeiFedorovec35c542023-04-27 17:52:02 +010036static void attest_token_continue_sign_state(
37 struct rec_attest_data *attest_data,
38 struct rsi_result *res)
Soby Mathewb4c6df42022-11-09 11:13:29 +000039{
40 /*
41 * Sign and finish creating the token.
42 */
43 enum attest_token_err_t ret =
AlexeiFedorovec35c542023-04-27 17:52:02 +010044 attest_realm_token_sign(&(attest_data->token_sign_ctx.ctx),
45 &(attest_data->rmm_realm_token_len));
Soby Mathewb4c6df42022-11-09 11:13:29 +000046 if ((ret == ATTEST_TOKEN_ERR_COSE_SIGN_IN_PROGRESS) ||
47 (ret == ATTEST_TOKEN_ERR_SUCCESS)) {
48 /*
49 * Return to RSI handler function after each iteration
50 * to check is there anything else to do (pending IRQ)
51 * or next signing iteration can be executed.
52 */
Soby Mathewb4c6df42022-11-09 11:13:29 +000053 res->smc_res.x[0] = RSI_INCOMPLETE;
54
55 /* If this was the last signing cycle */
56 if (ret == ATTEST_TOKEN_ERR_SUCCESS) {
AlexeiFedorovec35c542023-04-27 17:52:02 +010057 attest_data->token_sign_ctx.state =
Soby Mathewb4c6df42022-11-09 11:13:29 +000058 ATTEST_SIGN_TOKEN_WRITE_IN_PROGRESS;
59 }
60 } else {
61 /* Accessible only in case of failure during token signing */
62 ERROR("FATAL_ERROR: Realm token creation failed\n");
63 panic();
64 }
65}
66
67/*
AlexeiFedorov97844202023-04-27 15:17:35 +010068 * Function to continue with the token write operation
Soby Mathewb4c6df42022-11-09 11:13:29 +000069 */
70static void attest_token_continue_write_state(struct rec *rec,
AlexeiFedorov97844202023-04-27 15:17:35 +010071 struct rsi_result *res)
Soby Mathewb4c6df42022-11-09 11:13:29 +000072{
Soby Mathewb4c6df42022-11-09 11:13:29 +000073 struct granule *gr;
AlexeiFedorovea68b552023-10-03 11:11:47 +010074 uintptr_t realm_att_token;
Soby Mathewb4c6df42022-11-09 11:13:29 +000075 unsigned long realm_att_token_ipa = rec->regs[1];
AlexeiFedorovea68b552023-10-03 11:11:47 +010076 unsigned long offset = rec->regs[2];
77 unsigned long size = rec->regs[3];
Soby Mathewb4c6df42022-11-09 11:13:29 +000078 enum s2_walk_status walk_status;
79 struct s2_walk_result walk_res = { 0UL };
AlexeiFedorovea68b552023-10-03 11:11:47 +010080 size_t attest_token_len, length;
AlexeiFedorovec35c542023-04-27 17:52:02 +010081 struct rec_attest_data *attest_data = rec->aux_data.attest_data;
AlexeiFedorovea68b552023-10-03 11:11:47 +010082 uintptr_t cca_token_buf = rec->aux_data.cca_token_buf;
Soby Mathewb4c6df42022-11-09 11:13:29 +000083
84 /*
Soby Mathewb4c6df42022-11-09 11:13:29 +000085 * Translate realm granule IPA to PA. If returns with
86 * WALK_SUCCESS then the last level page table (llt),
87 * which holds the realm_att_token_buf mapping, is locked.
88 */
AlexeiFedorovd2e1bbd2023-04-18 15:18:39 +010089 walk_status = realm_ipa_to_pa(rec, realm_att_token_ipa, &walk_res);
Soby Mathewb4c6df42022-11-09 11:13:29 +000090
91 /* Walk parameter validity was checked by RSI_ATTESTATION_TOKEN_INIT */
92 assert(walk_status != WALK_INVALID_PARAMS);
93
94 if (walk_status == WALK_FAIL) {
AlexeiFedorovd2e1bbd2023-04-18 15:18:39 +010095 if (walk_res.ripas_val == RIPAS_EMPTY) {
Soby Mathewb4c6df42022-11-09 11:13:29 +000096 res->smc_res.x[0] = RSI_ERROR_INPUT;
97 } else {
98 /*
AlexeiFedorov97844202023-04-27 15:17:35 +010099 * Translation failed, IPA is not mapped.
100 * Return to NS host to fix the issue.
Soby Mathewb4c6df42022-11-09 11:13:29 +0000101 */
AlexeiFedorov97844202023-04-27 15:17:35 +0100102 res->action = STAGE_2_TRANSLATION_FAULT;
103 res->rtt_level = walk_res.rtt_level;
Soby Mathewb4c6df42022-11-09 11:13:29 +0000104 }
105 return;
106 }
107
Soby Mathew19eb4332023-11-20 14:03:23 +0000108 /* If size of buffer is 0, then return early. */
AlexeiFedorovea68b552023-10-03 11:11:47 +0100109 if (size == 0UL) {
Soby Mathew19eb4332023-11-20 14:03:23 +0000110 res->smc_res.x[0] = RSI_INCOMPLETE;
111 goto out_unlock;
AlexeiFedorovea68b552023-10-03 11:11:47 +0100112 }
113
Soby Mathewb4c6df42022-11-09 11:13:29 +0000114 /* Map realm data granule to RMM address space */
115 gr = find_granule(walk_res.pa);
AlexeiFedorovea68b552023-10-03 11:11:47 +0100116 realm_att_token = (uintptr_t)granule_map(gr, SLOT_RSI_CALL);
117 assert(realm_att_token != 0UL);
Soby Mathewb4c6df42022-11-09 11:13:29 +0000118
AlexeiFedorovea68b552023-10-03 11:11:47 +0100119 if (attest_data->token_sign_ctx.copied_len == 0UL) {
120 attest_token_len = attest_cca_token_create(
121 (void *)cca_token_buf,
122 REC_ATTEST_TOKEN_BUF_SIZE,
123 &attest_data->rmm_realm_token_buf,
124 attest_data->rmm_realm_token_len);
Soby Mathewb4c6df42022-11-09 11:13:29 +0000125
AlexeiFedorovea68b552023-10-03 11:11:47 +0100126 if (attest_token_len == 0UL) {
127 res->smc_res.x[0] = RSI_ERROR_INPUT;
128
129 /* The signing has failed. Reset the state. */
130 attest_data->token_sign_ctx.state =
131 ATTEST_SIGN_NOT_STARTED;
132 goto out_unmap;
133 }
134
135 attest_data->token_sign_ctx.cca_token_len = attest_token_len;
136 } else {
137 attest_token_len = attest_data->token_sign_ctx.cca_token_len;
138 }
139
140 length = (size < attest_token_len) ? size : attest_token_len;
141
142 /* Copy attestation token */
143 (void)memcpy((void *)(realm_att_token + offset),
144 (void *)(cca_token_buf +
145 attest_data->token_sign_ctx.copied_len),
146 length);
147
148 attest_token_len -= length;
149
150 if (attest_token_len != 0UL) {
151 attest_data->token_sign_ctx.cca_token_len = attest_token_len;
152 attest_data->token_sign_ctx.copied_len += length;
153
154 res->smc_res.x[0] = RSI_INCOMPLETE;
155 } else {
156
157 /* The signing has succeeded. Reset the state. */
158 attest_data->token_sign_ctx.state = ATTEST_SIGN_NOT_STARTED;
159 res->smc_res.x[0] = RSI_SUCCESS;
160 }
161
162 res->smc_res.x[1] = length;
163
164out_unmap:
Soby Mathewb4c6df42022-11-09 11:13:29 +0000165 /* Unmap realm granule */
AlexeiFedorovea68b552023-10-03 11:11:47 +0100166 buffer_unmap((void *)realm_att_token);
Soby Mathew19eb4332023-11-20 14:03:23 +0000167out_unlock:
Soby Mathewb4c6df42022-11-09 11:13:29 +0000168 /* Unlock last level page table (walk_res.g_llt) */
169 granule_unlock(walk_res.llt);
Soby Mathewb4c6df42022-11-09 11:13:29 +0000170}
171
AlexeiFedorov97844202023-04-27 15:17:35 +0100172void handle_rsi_attest_token_init(struct rec *rec, struct rsi_result *res)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000173{
AlexeiFedorovea68b552023-10-03 11:11:47 +0100174 struct rd *rd;
AlexeiFedorovec35c542023-04-27 17:52:02 +0100175 struct rec_attest_data *attest_data;
Mate Toth-Pal071aa562023-07-04 09:09:26 +0200176 void *rpv_ptr;
177 size_t rpv_len;
Soby Mathewb4c6df42022-11-09 11:13:29 +0000178 int att_ret;
179
180 assert(rec != NULL);
181
AlexeiFedorovec35c542023-04-27 17:52:02 +0100182 attest_data = rec->aux_data.attest_data;
AlexeiFedorov97844202023-04-27 15:17:35 +0100183 res->action = UPDATE_REC_RETURN_TO_REALM;
184
Soby Mathewb4c6df42022-11-09 11:13:29 +0000185 /*
186 * Calling RSI_ATTESTATION_TOKEN_INIT any time aborts any ongoing
187 * operation.
188 * TODO: This can be moved to attestation lib
189 */
AlexeiFedorovec35c542023-04-27 17:52:02 +0100190 if (attest_data->token_sign_ctx.state != ATTEST_SIGN_NOT_STARTED) {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000191 int restart;
192
AlexeiFedorovec35c542023-04-27 17:52:02 +0100193 attest_data->token_sign_ctx.state = ATTEST_SIGN_NOT_STARTED;
Soby Mathewb4c6df42022-11-09 11:13:29 +0000194 restart = attestation_heap_reinit_pe(rec->aux_data.attest_heap_buf,
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000195 REC_HEAP_SIZE);
Soby Mathewb4c6df42022-11-09 11:13:29 +0000196 if (restart != 0) {
197 /* There is no provision for this failure so panic */
198 panic();
199 }
200 }
201
AlexeiFedorov2dcd79f2023-10-17 10:04:11 +0100202 /* Clear context for signing an attestation token */
203 (void)memset(&attest_data->token_sign_ctx, 0,
204 sizeof(struct token_sign_cntxt));
205
206 attest_data->token_sign_ctx.state = ATTEST_SIGN_NOT_STARTED;
207
Soby Mathewb4c6df42022-11-09 11:13:29 +0000208 /*
209 * rd lock is acquired so that measurement cannot be updated
210 * simultaneously by another rec
211 */
212 granule_lock(rec->realm_info.g_rd, GRANULE_STATE_RD);
213 rd = granule_map(rec->realm_info.g_rd, SLOT_RD);
AlexeiFedorov9a9062c2023-08-21 15:41:48 +0100214 assert(rd != NULL);
215
AlexeiFedorovea68b552023-10-03 11:11:47 +0100216 /* Save challenge value in the context */
217 (void)memcpy((void *)attest_data->token_sign_ctx.challenge,
218 (const void *)&rec->regs[1],
219 ATTEST_CHALLENGE_SIZE);
Soby Mathewb4c6df42022-11-09 11:13:29 +0000220
Mate Toth-Pal071aa562023-07-04 09:09:26 +0200221 get_rpv(rd, &rpv_ptr, &rpv_len);
Soby Mathewb4c6df42022-11-09 11:13:29 +0000222 att_ret = attest_realm_token_create(rd->algorithm, rd->measurement,
223 MEASUREMENT_SLOT_NR,
Mate Toth-Pal071aa562023-07-04 09:09:26 +0200224 rpv_ptr,
225 rpv_len,
AlexeiFedorovec35c542023-04-27 17:52:02 +0100226 &attest_data->token_sign_ctx,
227 attest_data->rmm_realm_token_buf,
228 sizeof(attest_data->rmm_realm_token_buf));
AlexeiFedorovea68b552023-10-03 11:11:47 +0100229 buffer_unmap(rd);
230 granule_unlock(rec->realm_info.g_rd);
231
Soby Mathewb4c6df42022-11-09 11:13:29 +0000232 if (att_ret != 0) {
AlexeiFedorov97844202023-04-27 15:17:35 +0100233 ERROR("FATAL_ERROR: Realm token creation failed\n");
Soby Mathewb4c6df42022-11-09 11:13:29 +0000234 panic();
235 }
236
AlexeiFedorovec35c542023-04-27 17:52:02 +0100237 attest_data->token_sign_ctx.state = ATTEST_SIGN_IN_PROGRESS;
Soby Mathewb4c6df42022-11-09 11:13:29 +0000238
AlexeiFedorovea68b552023-10-03 11:11:47 +0100239 res->smc_res.x[0] = RSI_SUCCESS;
AlexeiFedorov755a70b2023-10-12 12:31:45 +0100240 res->smc_res.x[1] = REC_ATTEST_TOKEN_BUF_SIZE;
AlexeiFedorov97844202023-04-27 15:17:35 +0100241}
242
243/*
244 * Return 'false' if no IRQ is pending,
245 * return 'true' if there is an IRQ pending, and need to return to Host.
246 */
247static bool check_pending_irq(void)
248{
249 return (read_isr_el1() != 0UL);
Soby Mathewb4c6df42022-11-09 11:13:29 +0000250}
251
Soby Mathewb4c6df42022-11-09 11:13:29 +0000252void handle_rsi_attest_token_continue(struct rec *rec,
AlexeiFedorov97844202023-04-27 15:17:35 +0100253 struct rmi_rec_exit *rec_exit,
254 struct rsi_result *res)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000255{
AlexeiFedorovec35c542023-04-27 17:52:02 +0100256 struct rec_attest_data *attest_data;
AlexeiFedorovea68b552023-10-03 11:11:47 +0100257 unsigned long realm_buf_ipa, offset, size;
AlexeiFedorovec35c542023-04-27 17:52:02 +0100258
Soby Mathewb4c6df42022-11-09 11:13:29 +0000259 assert(rec != NULL);
AlexeiFedorov97844202023-04-27 15:17:35 +0100260 assert(rec_exit != NULL);
Soby Mathewb4c6df42022-11-09 11:13:29 +0000261
AlexeiFedorovec35c542023-04-27 17:52:02 +0100262 attest_data = rec->aux_data.attest_data;
AlexeiFedorov97844202023-04-27 15:17:35 +0100263 res->action = UPDATE_REC_RETURN_TO_REALM;
Soby Mathewb4c6df42022-11-09 11:13:29 +0000264
AlexeiFedorovea68b552023-10-03 11:11:47 +0100265 realm_buf_ipa = rec->regs[1];
266 offset = rec->regs[2];
267 size = rec->regs[3];
268
269 if (!GRANULE_ALIGNED(realm_buf_ipa) ||
270 (offset >= GRANULE_SIZE) ||
271 ((offset + size) > GRANULE_SIZE) ||
272 ((offset + size) < offset)) {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000273 res->smc_res.x[0] = RSI_ERROR_INPUT;
274 return;
275 }
276
AlexeiFedorovea68b552023-10-03 11:11:47 +0100277 if (!addr_in_rec_par(rec, realm_buf_ipa)) {
278 res->smc_res.x[0] = RSI_ERROR_INPUT;
279 return;
280 }
AlexeiFedorov97844202023-04-27 15:17:35 +0100281
AlexeiFedorovea68b552023-10-03 11:11:47 +0100282 if (attest_data->token_sign_ctx.state == ATTEST_SIGN_NOT_STARTED) {
283 /*
284 * Before this call the initial attestation token call
285 * (SMC_RSI_ATTEST_TOKEN_INIT) must have been executed
286 * successfully.
287 */
288 res->smc_res.x[0] = RSI_ERROR_STATE;
289 return;
290 }
291
292 while (attest_data->token_sign_ctx.state == ATTEST_SIGN_IN_PROGRESS) {
293 attest_token_continue_sign_state(attest_data, res);
294 if (check_pending_irq()) {
295 res->action = UPDATE_REC_EXIT_TO_HOST;
296 rec_exit->exit_reason = RMI_EXIT_IRQ;
297 return;
AlexeiFedorov97844202023-04-27 15:17:35 +0100298 }
Soby Mathewb4c6df42022-11-09 11:13:29 +0000299 }
AlexeiFedorovea68b552023-10-03 11:11:47 +0100300
301 /* Any other state is considered an error */
302 assert(attest_data->token_sign_ctx.state ==
303 ATTEST_SIGN_TOKEN_WRITE_IN_PROGRESS);
304
305 attest_token_continue_write_state(rec, res);
Soby Mathewb4c6df42022-11-09 11:13:29 +0000306}
307
AlexeiFedorov97844202023-04-27 15:17:35 +0100308void handle_rsi_measurement_extend(struct rec *rec, struct rsi_result *res)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000309{
310 struct granule *g_rd;
311 struct rd *rd;
312 unsigned long index;
313 unsigned long rd_addr;
314 size_t size;
Soby Mathewb4c6df42022-11-09 11:13:29 +0000315 void *extend_measurement;
316 unsigned char *current_measurement;
317 int __unused meas_ret;
318
AlexeiFedorov97844202023-04-27 15:17:35 +0100319 assert(rec != NULL);
320
321 res->action = UPDATE_REC_RETURN_TO_REALM;
322
Soby Mathewb4c6df42022-11-09 11:13:29 +0000323 /*
324 * rd lock is acquired so that measurement cannot be updated
325 * simultaneously by another rec
326 */
327 rd_addr = granule_addr(rec->realm_info.g_rd);
328 g_rd = find_lock_granule(rd_addr, GRANULE_STATE_RD);
329
330 assert(g_rd != NULL);
331
332 rd = granule_map(rec->realm_info.g_rd, SLOT_RD);
AlexeiFedorov9a9062c2023-08-21 15:41:48 +0100333 assert(rd != NULL);
Soby Mathewb4c6df42022-11-09 11:13:29 +0000334
335 /*
336 * X1: index
337 * X2: size
338 * X3-X10: measurement value
339 */
340 index = rec->regs[1];
341
342 if ((index == RIM_MEASUREMENT_SLOT) ||
343 (index >= MEASUREMENT_SLOT_NR)) {
AlexeiFedorov97844202023-04-27 15:17:35 +0100344 res->smc_res.x[0] = RSI_ERROR_INPUT;
Soby Mathewb4c6df42022-11-09 11:13:29 +0000345 goto out_unmap_rd;
346 }
347
348 size = rec->regs[2];
349
350 if (size > MAX_EXTENDED_SIZE) {
AlexeiFedorov97844202023-04-27 15:17:35 +0100351 res->smc_res.x[0] = RSI_ERROR_INPUT;
Soby Mathewb4c6df42022-11-09 11:13:29 +0000352 goto out_unmap_rd;
353 }
354
355 extend_measurement = &rec->regs[3];
356 current_measurement = rd->measurement[index];
357
358 measurement_extend(rd->algorithm,
359 current_measurement,
360 extend_measurement,
361 size,
362 current_measurement);
363
AlexeiFedorov97844202023-04-27 15:17:35 +0100364 res->smc_res.x[0] = RSI_SUCCESS;
Soby Mathewb4c6df42022-11-09 11:13:29 +0000365
366out_unmap_rd:
367 buffer_unmap(rd);
368 granule_unlock(g_rd);
Soby Mathewb4c6df42022-11-09 11:13:29 +0000369}
370
AlexeiFedorov97844202023-04-27 15:17:35 +0100371void handle_rsi_measurement_read(struct rec *rec, struct rsi_result *res)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000372{
373 struct rd *rd;
374 unsigned long idx;
AlexeiFedorovefe2aec2023-06-08 16:17:00 +0100375 unsigned int i, cnt;
Mate Toth-Pal59b52d02023-08-18 14:14:19 +0200376 unsigned long *measurement_value_part;
Soby Mathewb4c6df42022-11-09 11:13:29 +0000377
378 assert(rec != NULL);
379
AlexeiFedorov97844202023-04-27 15:17:35 +0100380 res->action = UPDATE_REC_RETURN_TO_REALM;
381
Soby Mathewb4c6df42022-11-09 11:13:29 +0000382 /* X1: Index */
383 idx = rec->regs[1];
384
385 if (idx >= MEASUREMENT_SLOT_NR) {
AlexeiFedorov97844202023-04-27 15:17:35 +0100386 res->smc_res.x[0] = RSI_ERROR_INPUT;
387 return;
Soby Mathewb4c6df42022-11-09 11:13:29 +0000388 }
389
390 /*
391 * rd lock is acquired so that measurement cannot be updated
392 * simultaneously by another rec
393 */
394 granule_lock(rec->realm_info.g_rd, GRANULE_STATE_RD);
395 rd = granule_map(rec->realm_info.g_rd, SLOT_RD);
AlexeiFedorov9a9062c2023-08-21 15:41:48 +0100396 assert(rd != NULL);
Soby Mathewb4c6df42022-11-09 11:13:29 +0000397
AlexeiFedorovefe2aec2023-06-08 16:17:00 +0100398 /* Number of 8-bytes words in measurement */
AlexeiFedorov4faab852023-08-30 15:06:49 +0100399 cnt = (unsigned int)(measurement_get_size(rd->algorithm) /
400 sizeof(unsigned long));
Soby Mathewb4c6df42022-11-09 11:13:29 +0000401
AlexeiFedorovea68b552023-10-03 11:11:47 +0100402 assert(cnt >= (SMC_RESULT_REGS - 1U));
Mate Toth-Pal59b52d02023-08-18 14:14:19 +0200403 assert(cnt < ARRAY_LEN(rec->regs));
404
AlexeiFedorovefe2aec2023-06-08 16:17:00 +0100405 /* Copy the part of the measurement to res->smc_res.x[] */
AlexeiFedorovea68b552023-10-03 11:11:47 +0100406 for (i = 0U; i < (SMC_RESULT_REGS - 1U); i++) {
Mate Toth-Pal59b52d02023-08-18 14:14:19 +0200407 measurement_value_part = (unsigned long *)
408 &(rd->measurement[idx][i * sizeof(unsigned long)]);
409 res->smc_res.x[i + 1U] = *measurement_value_part;
AlexeiFedorovefe2aec2023-06-08 16:17:00 +0100410 }
Soby Mathewb4c6df42022-11-09 11:13:29 +0000411
AlexeiFedorovefe2aec2023-06-08 16:17:00 +0100412 /* Copy the rest of the measurement to the rec->regs[] */
413 for (; i < cnt; i++) {
Mate Toth-Pal59b52d02023-08-18 14:14:19 +0200414 measurement_value_part = (unsigned long *)
415 &(rd->measurement[idx][i * sizeof(unsigned long)]);
416 rec->regs[i + 1U] = *measurement_value_part;
AlexeiFedorovefe2aec2023-06-08 16:17:00 +0100417 }
418
419 /* Zero-initialize unused area */
420 for (; i < MAX_MEASUREMENT_WORDS; i++) {
421 rec->regs[i + 1U] = 0UL;
Soby Mathewb4c6df42022-11-09 11:13:29 +0000422 }
423
424 buffer_unmap(rd);
425 granule_unlock(rec->realm_info.g_rd);
426
AlexeiFedorov97844202023-04-27 15:17:35 +0100427 res->smc_res.x[0] = RSI_SUCCESS;
Soby Mathewb4c6df42022-11-09 11:13:29 +0000428}