]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
test(el3-runtime): dit is retained on world switch
authorDaniel Boulby <daniel.boulby@arm.com>
Fri, 22 Oct 2021 10:37:34 +0000 (11:37 +0100)
committerDaniel Boulby <daniel.boulby@arm.com>
Thu, 3 Feb 2022 11:33:55 +0000 (11:33 +0000)
Add tsp service to check the value of the PSTATE DIT bit is as
expected and toggle it's value. This is used to ensure that
the DIT bit is maintained during a switch from the Normal to
Secure worlds and back.

Change-Id: I4e8bdfa6530e5e75925c0079d4fa2795133c5105
Signed-off-by: Daniel Boulby <daniel.boulby@arm.com>
bl32/tsp/tsp_main.c
include/arch/aarch64/arch_features.h
include/arch/aarch64/arch_helpers.h
include/bl32/tsp/tsp.h
services/spd/tspd/tspd_main.c

index 55e1532129406e5a003cb2346a3a97ce56ccd0fe..522c1b4036f7acc14b5489b91a77be00f2afac43 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2013-2022, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -370,6 +370,7 @@ tsp_args_t *tsp_smc_handler(uint64_t func,
        uint64_t service_arg1;
        uint64_t results[2];
        uint32_t linear_id = plat_my_core_pos();
+       u_register_t dit;
 
        /* Update this cpu's statistics */
        tsp_stats[linear_id].smc_count++;
@@ -424,6 +425,23 @@ tsp_args_t *tsp_smc_handler(uint64_t func,
                results[0] /= service_arg0 ? service_arg0 : 1;
                results[1] /= service_arg1 ? service_arg1 : 1;
                break;
+       case TSP_CHECK_DIT:
+               if (!is_armv8_4_dit_present()) {
+#if LOG_LEVEL >= LOG_LEVEL_ERROR
+                       spin_lock(&console_lock);
+                       ERROR("DIT not supported\n");
+                       spin_unlock(&console_lock);
+#endif
+                       results[0] = 0;
+                       results[1] = 0xffff;
+                       break;
+               }
+               dit = read_dit();
+               results[0] = dit == service_arg0;
+               results[1] = dit;
+               /* Toggle the dit bit */
+               write_dit(service_arg0 != 0U ? 0 : DIT_BIT);
+               break;
        default:
                break;
        }
index 46cd1c9824cbd4e104179020d5cc7d593e649eac..a260f031653588dae4b7bea65cc5c956fcbce250 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -46,6 +46,12 @@ static inline bool is_armv8_3_pauth_present(void)
        return (read_id_aa64isar1_el1() & mask) != 0U;
 }
 
+static inline bool is_armv8_4_dit_present(void)
+{
+       return ((read_id_aa64pfr0_el1() >> ID_AA64PFR0_DIT_SHIFT) &
+               ID_AA64PFR0_DIT_MASK) == 1U;
+}
+
 static inline bool is_armv8_4_ttst_present(void)
 {
        return ((read_id_aa64mmfr2_el1() >> ID_AA64MMFR2_EL1_ST_SHIFT) &
index 733bb23c4de0412265a687dda086f8fcbb51196f..009eb90e949bc9dda051296a8794f99861782121 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2021, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2013-2022, Arm Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -529,6 +529,9 @@ DEFINE_RENAME_SYSREG_READ_FUNC(id_aa64mmfr2_el1, ID_AA64MMFR2_EL1)
 DEFINE_RENAME_SYSREG_RW_FUNCS(apiakeyhi_el1, APIAKeyHi_EL1)
 DEFINE_RENAME_SYSREG_RW_FUNCS(apiakeylo_el1, APIAKeyLo_EL1)
 
+/* Armv8.4 Data Independent Timing Register */
+DEFINE_RENAME_SYSREG_RW_FUNCS(dit, DIT)
+
 /* Armv8.5 MTE Registers */
 DEFINE_RENAME_SYSREG_RW_FUNCS(tfsre0_el1, TFSRE0_EL1)
 DEFINE_RENAME_SYSREG_RW_FUNCS(tfsr_el1, TFSR_EL1)
index 637e14abf798cf8745c798bf43e9ed89b744f528..285bfbe295b566a002ca7b7d8008c81e2794bd53 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2013-2022, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -41,6 +41,7 @@
 #define TSP_MUL                0x2002
 #define TSP_DIV                0x2003
 #define TSP_HANDLE_SEL1_INTR_AND_RETURN        0x2004
+#define TSP_CHECK_DIT  0x2005
 
 /*
  * Identify a TSP service from function ID filtering the last 16 bits from the
index 29fc238aef2fc4307a30e62ac96e3a8c19b4459c..6cb4992a20a4e1877ca0761de7e7aa1b56d4ed29 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2021, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2013-2022, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -570,6 +570,11 @@ static uintptr_t tspd_smc_handler(uint32_t smc_fid,
        case TSP_YIELD_FID(TSP_SUB):
        case TSP_YIELD_FID(TSP_MUL):
        case TSP_YIELD_FID(TSP_DIV):
+               /*
+                * Request from non-secure client to perform a check
+                * of the DIT PSTATE bit.
+                */
+       case TSP_YIELD_FID(TSP_CHECK_DIT):
                if (ns) {
                        /*
                         * This is a fresh request from the non-secure client.