Skip to content

Commit

Permalink
Merge changes I26b33394,If884ab4a,I3d273f5b,I6c6d2a5c into integration
Browse files Browse the repository at this point in the history
* changes:
  feat(fake_host): implement attestation related monitor calls
  feat(fake_host): set ID_AA64ISAR0_EL1_RNDR
  feat(fake_host): unify boot manifest setup in host platforms
  feat(fake_host): make shared buf init platform specific
  • Loading branch information
soby-mathew authored and TrustedFirmware Code Review committed Mar 3, 2023
2 parents 19067b3 + 30190d5 commit 274f45a
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 131 deletions.
25 changes: 25 additions & 0 deletions plat/common/include/plat_import_sym.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
*/

#ifndef PLAT_IMPORT_SYM_H
#define PLAT_IMPORT_SYM_H

#include <import_sym.h>

IMPORT_SYM(uintptr_t, rmm_text_start, RMM_CODE_START);
IMPORT_SYM(uintptr_t, rmm_text_end, RMM_CODE_END);
IMPORT_SYM(uintptr_t, rmm_ro_start, RMM_RO_START);
IMPORT_SYM(uintptr_t, rmm_ro_end, RMM_RO_END);
IMPORT_SYM(uintptr_t, rmm_rw_start, RMM_RW_START);
IMPORT_SYM(uintptr_t, rmm_rw_end, RMM_RW_END);

/*
* Leave an invalid page between the end of RMM memory and the beginning
* of the shared buffer VA. This will help to detect any memory access
* underflow by RMM.
*/
#define RMM_SHARED_BUFFER_START (RMM_RW_END + SZ_4K)

#endif /* PLAT_IMPORT_SYM_H */
29 changes: 6 additions & 23 deletions plat/common/src/plat_common_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,14 @@
#include <debug.h>
#include <errno.h>
#include <gic.h>
#include <import_sym.h>
#include <plat_import_sym.h>
#include <rmm_el3_ifc.h>
#include <sizes.h>
#include <stdint.h>
#include <string.h>
#include <xlat_contexts.h>
#include <xlat_tables.h>

IMPORT_SYM(uintptr_t, rmm_text_start, RMM_CODE_START);
IMPORT_SYM(uintptr_t, rmm_text_end, RMM_CODE_END);
IMPORT_SYM(uintptr_t, rmm_ro_start, RMM_RO_START);
IMPORT_SYM(uintptr_t, rmm_ro_end, RMM_RO_END);
IMPORT_SYM(uintptr_t, rmm_rw_start, RMM_RW_START);
IMPORT_SYM(uintptr_t, rmm_rw_end, RMM_RW_END);

/*
* Leave an invalid page between the end of RMM memory and the beginning
* of the shared buffer VA. This will help to detect any memory access
* underflow by RMM.
*/
#define RMM_SHARED_BUFFER_START (RMM_RW_END + SZ_4K)

/*
* Memory map REGIONS used for the RMM runtime (static mappings)
*/
Expand Down Expand Up @@ -99,6 +85,11 @@ int plat_cmn_setup(unsigned long x0, unsigned long x1,
int ret;
unsigned int plat_offset, cmn_offset;

(void)x0;
(void)x1;
(void)x2;
(void)x3;

/* Common regions sorted by ascending VA */
struct xlat_mmap_region regions[COMMON_REGIONS] = {
RMM_CODE,
Expand All @@ -115,14 +106,6 @@ int plat_cmn_setup(unsigned long x0, unsigned long x1,
return -EINVAL;
}

/* Initialize the RMM <-> EL3 interface */
ret = rmm_el3_ifc_init(x0, x1, x2, x3, RMM_SHARED_BUFFER_START);
if (ret != 0) {
ERROR("%s (%u): Failed to initialize the RMM EL3 Interface\n",
__func__, __LINE__);
return ret;
}

/* Setup the parameters of the shared area */
regions[3].base_pa = rmm_el3_ifc_get_shared_buf_pa();
regions[3].size = rmm_el3_ifc_get_shared_buf_size();
Expand Down
11 changes: 10 additions & 1 deletion plat/fvp/src/fvp_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <fvp_private.h>
#include <pl011.h>
#include <plat_common.h>
#include <plat_import_sym.h>
#include <rmm_el3_ifc.h>
#include <sizes.h>
#include <xlat_tables.h>
Expand Down Expand Up @@ -58,7 +59,15 @@ void plat_setup(uint64_t x0, uint64_t x1, uint64_t x2, uint64_t x3)

uart_init(RMM_UART_ADDR, FVP_UART_CLK_IN_HZ, FVP_UART_BAUDRATE);

/* Initialize the RMM <-> EL3 interface and xlat table */
/* Initialize the RMM <-> EL3 interface */
ret = rmm_el3_ifc_init(x0, x1, x2, x3, RMM_SHARED_BUFFER_START);
if (ret != 0) {
ERROR("%s (%u): Failed to initialize the RMM EL3 Interface\n",
__func__, __LINE__);
panic();
}

/* Carry on with the rest of the system setup */
ret = plat_cmn_setup(x0, x1, x2, x3, plat_regions, 1U);
if (ret != 0) {
ERROR("%s (%u): Failed to setup the platform (%i)\n",
Expand Down
11 changes: 11 additions & 0 deletions plat/host/common/include/host_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,15 @@ unsigned long host_util_get_granule_base(void);
*/
void host_util_set_cpuid(unsigned int cpuid);

/*
* Return the address of the EL3 RMM shared buffer.
*/
unsigned char *host_util_get_el3_rmm_shared_buffer(void);

/*
* Performs some initialization needed before RMM can be run, such as
* setting up callbacks for sysreg access.
*/
void host_util_setup_sysreg_and_boot_manifest(void);

#endif /* HOST_UTILS_H */
154 changes: 149 additions & 5 deletions plat/host/common/src/host_harness_cmn.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,111 @@
*/

#include <arch.h>
#include <debug.h>
#include <errno.h>
#include <host_utils.h>
#include <rmm_el3_ifc.h>
#include <spinlock.h>
#include <string.h>

#define ATTEST_KEY_CURVE_ECC_SECP384R1 0

/* Hardcoded platform token value */
static uint8_t platform_token[] = {
0xD2, 0x84, 0x44, 0xA1, 0x01, 0x38, 0x22, 0xA0,
0x59, 0x02, 0x33, 0xA9, 0x19, 0x01, 0x09, 0x78,
0x1C, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F,
0x61, 0x72, 0x6D, 0x2E, 0x63, 0x6F, 0x6D, 0x2F,
0x43, 0x43, 0x41, 0x2D, 0x53, 0x53, 0x44, 0x2F,
0x31, 0x2E, 0x30, 0x2E, 0x30, 0x0A, 0x58, 0x20,
0xB5, 0x97, 0x3C, 0xB6, 0x8B, 0xAA, 0x9F, 0xC5,
0x55, 0x58, 0x78, 0x6B, 0x7E, 0xC6, 0x7F, 0x69,
0xE4, 0x0D, 0xF5, 0xBA, 0x5A, 0xA9, 0x21, 0xCD,
0x0C, 0x27, 0xF4, 0x05, 0x87, 0xA0, 0x11, 0xEA,
0x19, 0x09, 0x5C, 0x58, 0x20, 0x7F, 0x45, 0x4C,
0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x3E,
0x00, 0x01, 0x00, 0x00, 0x00, 0x50, 0x58, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x01, 0x00,
0x58, 0x21, 0x01, 0x07, 0x06, 0x05, 0x04, 0x03,
0x02, 0x01, 0x00, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B,
0x0A, 0x09, 0x08, 0x17, 0x16, 0x15, 0x14, 0x13,
0x12, 0x11, 0x10, 0x1F, 0x1E, 0x1D, 0x1C, 0x1B,
0x1A, 0x19, 0x18, 0x19, 0x09, 0x61, 0x58, 0x21,
0x01, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
0x00, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09,
0x08, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11,
0x10, 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19,
0x18, 0x19, 0x09, 0x5B, 0x19, 0x30, 0x03, 0x19,
0x09, 0x62, 0x67, 0x73, 0x68, 0x61, 0x2D, 0x32,
0x35, 0x36, 0x19, 0x09, 0x5F, 0x84, 0xA5, 0x01,
0x62, 0x42, 0x4C, 0x05, 0x58, 0x20, 0x07, 0x06,
0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0F, 0x0E,
0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x17, 0x16,
0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x1F, 0x1E,
0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 0x04, 0x65,
0x33, 0x2E, 0x34, 0x2E, 0x32, 0x02, 0x58, 0x20,
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08,
0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10,
0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18,
0x06, 0x74, 0x54, 0x46, 0x2D, 0x4D, 0x5F, 0x53,
0x48, 0x41, 0x32, 0x35, 0x36, 0x4D, 0x65, 0x6D,
0x50, 0x72, 0x65, 0x58, 0x49, 0x50, 0xA4, 0x01,
0x62, 0x4D, 0x31, 0x05, 0x58, 0x20, 0x07, 0x06,
0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0F, 0x0E,
0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x17, 0x16,
0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x1F, 0x1E,
0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 0x04, 0x63,
0x31, 0x2E, 0x32, 0x02, 0x58, 0x20, 0x07, 0x06,
0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0F, 0x0E,
0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x17, 0x16,
0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x1F, 0x1E,
0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 0xA4, 0x01,
0x62, 0x4D, 0x32, 0x05, 0x58, 0x20, 0x07, 0x06,
0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0F, 0x0E,
0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x17, 0x16,
0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x1F, 0x1E,
0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 0x04, 0x65,
0x31, 0x2E, 0x32, 0x2E, 0x33, 0x02, 0x58, 0x20,
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08,
0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10,
0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18,
0xA4, 0x01, 0x62, 0x4D, 0x33, 0x05, 0x58, 0x20,
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08,
0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10,
0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18,
0x04, 0x61, 0x31, 0x02, 0x58, 0x20, 0x07, 0x06,
0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0F, 0x0E,
0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x17, 0x16,
0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x1F, 0x1E,
0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 0x19, 0x09,
0x60, 0x6C, 0x77, 0x68, 0x61, 0x74, 0x65, 0x76,
0x65, 0x72, 0x2E, 0x63, 0x6F, 0x6D, 0x58, 0x60,
0xE6, 0xB6, 0x38, 0x4F, 0xAE, 0x3F, 0x6E, 0x67,
0xF5, 0xD4, 0x97, 0x4B, 0x3F, 0xFD, 0x0A, 0xFA,
0x1D, 0xF0, 0x2F, 0x73, 0xB8, 0xFF, 0x5F, 0x02,
0xC0, 0x0F, 0x40, 0xAC, 0xF3, 0xA2, 0x9D, 0xB5,
0x31, 0x50, 0x16, 0x4F, 0xFA, 0x34, 0x3D, 0x0E,
0xAF, 0xE0, 0xD0, 0xD1, 0x6C, 0xF0, 0x9D, 0xC1,
0x01, 0x42, 0xA2, 0x3C, 0xCE, 0xD4, 0x4A, 0x59,
0xDC, 0x29, 0x0A, 0x30, 0x93, 0x5F, 0xB4, 0x98,
0x61, 0xBA, 0xE3, 0x91, 0x22, 0x95, 0x24, 0xF4,
0xAE, 0x47, 0x93, 0xD3, 0x84, 0xA3, 0x76, 0xD0,
0xC1, 0x26, 0x96, 0x53, 0xA3, 0x60, 0x3F, 0x6C,
0x75, 0x96, 0x90, 0x6A, 0xF9, 0x4E, 0xDA, 0x30
};

static uint8_t sample_attest_priv_key[] = {
0x20, 0x11, 0xC7, 0xF0, 0x3C, 0xEE, 0x43, 0x25, 0x17, 0x6E,
0x52, 0x4F, 0x03, 0x3C, 0x0C, 0xE1, 0xE2, 0x1A, 0x76, 0xE6,
0xC1, 0xA4, 0xF0, 0xB8, 0x39, 0xAA, 0x1D, 0xF6, 0x1E, 0x0E,
0x8A, 0x5C, 0x8A, 0x05, 0x74, 0x0F, 0x9B, 0x69, 0xEF, 0xA7,
0xEB, 0x1A, 0x41, 0x85, 0xBD, 0x11, 0x7F, 0x68
};

bool host_memcpy_ns_read(void *dest, const void *ns_src, unsigned long size)
{
(void)memcpy(dest, ns_src, size);
Expand Down Expand Up @@ -39,6 +140,41 @@ unsigned long host_monitor_call(unsigned long id,
return 0UL;
}

static int attest_get_platform_token(uint64_t buf_pa, uint64_t *buf_size,
uint64_t c_size)
{
(void)c_size; /* The challenge is ignored */

if (*buf_size < sizeof(platform_token)) {
ERROR("Failed to get platform token: Buffer is too small.\n");
return -ENOMEM;
}

(void)memcpy((void *)buf_pa, (void *)platform_token, sizeof(platform_token));
*buf_size = sizeof(platform_token);

return 0;
}

static int attest_get_signing_key(uint64_t buf_pa, uint64_t *buf_size,
uint64_t ecc_curve)
{
if (ecc_curve != ATTEST_KEY_CURVE_ECC_SECP384R1) {
ERROR("Invalid ECC curve specified\n");
return -EINVAL;
}

if (*buf_size < sizeof(sample_attest_priv_key)) {
return -EINVAL;
}

(void)memcpy((void *)buf_pa, (void *)sample_attest_priv_key,
sizeof(sample_attest_priv_key));
*buf_size = sizeof(sample_attest_priv_key);

return 0;
}

void host_monitor_call_with_res(unsigned long id,
unsigned long arg0,
unsigned long arg1,
Expand All @@ -49,14 +185,22 @@ void host_monitor_call_with_res(unsigned long id,
struct smc_result *res)
{
/* Avoid MISRA C:2102-2.7 warnings */
(void)id;
(void)arg0;
(void)arg1;
(void)arg2;
(void)arg3;
(void)arg4;
(void)arg5;
(void)res;

switch (id) {
case SMC_RMM_GET_PLAT_TOKEN:
res->x[0] = attest_get_platform_token(arg0, &arg1, arg2);
res->x[1] = arg1;
break;
case SMC_RMM_GET_REALM_ATTEST_KEY:
res->x[0] = attest_get_signing_key(arg0, &arg1, arg2);
res->x[1] = arg1;
break;
default:
VERBOSE("Unimplemented monitor call id %lx\n", id);
}
}

int host_run_realm(unsigned long *regs)
Expand Down
12 changes: 11 additions & 1 deletion plat/host/common/src/host_platform_api_cmn.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <host_defs.h>
#include <host_utils.h>
#include <plat_common.h>
#include <rmm_el3_ifc.h>
#include <stdint.h>
#include <xlat_tables.h>

Expand Down Expand Up @@ -45,7 +46,16 @@ void plat_warmboot_setup(uint64_t x0, uint64_t x1,
void plat_setup(uint64_t x0, uint64_t x1,
uint64_t x2, uint64_t x3)
{
/* Initialize xlat table */
/* Initialize the RMM <-> EL3 interface.
* Since host platform does not have VA address translation, we pass the
* same shared buf address as the VA to be used for access by users of
* rmm-el3-ifc.
*/
if (rmm_el3_ifc_init(x0, x1, x2, x3, x3) != 0) {
panic();
}

/* Carry on with the rest of the system setup */
if (plat_cmn_setup(x0, x1, x2, x3, NULL, 0) != 0) {
panic();
}
Expand Down

0 comments on commit 274f45a

Please sign in to comment.