diff --git a/include/lib/utils_def.h b/include/lib/utils_def.h index 02963ac..2b48967 100644 --- a/include/lib/utils_def.h +++ b/include/lib/utils_def.h @@ -162,4 +162,11 @@ #define COMPILER_BARRIER() __asm__ volatile ("" ::: "memory") +/* Compiler builtin of GCC >= 9 and planned in llvm */ +#ifdef __HAVE_SPECULATION_SAFE_VALUE +# define SPECULATION_SAFE_VALUE(var) __builtin_speculation_safe_value(var) +#else +# define SPECULATION_SAFE_VALUE(var) var +#endif + #endif /* UTILS_DEF_H */ diff --git a/lib/psci/psci_stat.c b/lib/psci/psci_stat.c index 421db44..6f6a7d4 100644 --- a/lib/psci/psci_stat.c +++ b/lib/psci/psci_stat.c @@ -206,9 +206,9 @@ if (pwrlvl > PSCI_CPU_PWR_LVL) { /* Get the power domain index */ - parent_idx = psci_cpu_pd_nodes[target_idx].parent_node; + parent_idx = SPECULATION_SAFE_VALUE(psci_cpu_pd_nodes[target_idx].parent_node); for (lvl = PSCI_CPU_PWR_LVL + 1U; lvl < pwrlvl; lvl++) - parent_idx = psci_non_cpu_pd_nodes[parent_idx].parent_node; + parent_idx = SPECULATION_SAFE_VALUE(psci_non_cpu_pd_nodes[parent_idx].parent_node); /* Get the non cpu power domain stats */ *psci_stat = psci_non_cpu_stat[parent_idx][stat_idx];