aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandrine Bailleux <sandrine.bailleux@arm.com>2019-10-15 13:56:00 +0000
committerTrustedFirmware Code Review <review@review.trustedfirmware.org>2019-10-15 13:56:00 +0000
commit6f97b12dac69d3a8ee51fed7af1c32ae33f987c8 (patch)
treeacc5c0e3cd789017df4e44a18a449c8b0d9305d6
parent5b9cc97bbeda000d2f72728320f9dc96aeb6fa46 (diff)
parent85926bc3d544111d412472e24cdd86668175c831 (diff)
downloadtf-a-tests-6f97b12dac69d3a8ee51fed7af1c32ae33f987c8.tar.gz
Merge "Bugfix for PMU leakage test"v2.2-rc1
-rw-r--r--tftf/tests/misc_tests/test_pmu_leakage.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/tftf/tests/misc_tests/test_pmu_leakage.c b/tftf/tests/misc_tests/test_pmu_leakage.c
index a0ac82d7e..09f4d510a 100644
--- a/tftf/tests/misc_tests/test_pmu_leakage.c
+++ b/tftf/tests/misc_tests/test_pmu_leakage.c
@@ -249,6 +249,21 @@ static void measure_event(u_register_t (*read_cntr_func)(void),
}
/*
+ * Checks that when requesting an SMC call after getting a baseline PMU event
+ * count the number of PMU events counted is either not greater than the
+ * baseline or it has increased by no more than ALLOWED_DEVIATION%. The first
+ * comparison is required because of underflow on unsigned types.
+ * This is used to determine if PMU timing information has been leaked from the
+ * secure world.
+ */
+static bool results_within_allowed_margin(unsigned long long baseline_cnt,
+ unsigned long long smc_cnt)
+{
+ return (smc_cnt <= baseline_cnt) ||
+ (smc_cnt - baseline_cnt <= baseline_cnt / ALLOWED_DEVIATION);
+}
+
+/*
* Measure the number of retired writes to the PC in the PSCI_SUSPEND SMC.
* This test only succeeds if no useful information about the PMU counters has
* been leaked.
@@ -268,7 +283,7 @@ test_result_t smc_psci_suspend_pc_write_retired(void)
tftf_testcase_printf("Profiling PSCI_SUSPEND_PC:\n");
measure_event(read_pmevcntr0_el0, profile_cpu_suspend, &cpu_suspend);
- if (cpu_suspend.avg - baseline.avg > baseline.avg / ALLOWED_DEVIATION)
+ if (!results_within_allowed_margin(baseline.avg, cpu_suspend.avg))
return TEST_RESULT_FAIL;
return TEST_RESULT_SUCCESS;
}
@@ -293,7 +308,7 @@ test_result_t smc_psci_suspend_cycles(void)
tftf_testcase_printf("Profiling PSCI_SUSPEND_PC:\n");
measure_event(read_pmccntr_el0, profile_cpu_suspend, &cpu_suspend);
- if (cpu_suspend.avg - baseline.avg > baseline.avg / ALLOWED_DEVIATION)
+ if (!results_within_allowed_margin(baseline.avg, cpu_suspend.avg))
return TEST_RESULT_FAIL;
return TEST_RESULT_SUCCESS;
}
@@ -320,7 +335,7 @@ test_result_t fast_smc_add_pc_write_retired(void)
tftf_testcase_printf("Profiling Fast Add SMC:\n");
measure_event(read_pmevcntr0_el0, profile_fast_smc_add, &fast_smc_add);
- if (fast_smc_add.avg - baseline.avg > baseline.avg / ALLOWED_DEVIATION)
+ if (!results_within_allowed_margin(baseline.avg, fast_smc_add.avg))
return TEST_RESULT_FAIL;
return TEST_RESULT_SUCCESS;
}
@@ -347,7 +362,7 @@ test_result_t fast_smc_add_cycles(void)
tftf_testcase_printf("Profiling Fast Add SMC:\n");
measure_event(read_pmccntr_el0, profile_fast_smc_add, &fast_smc_add);
- if (fast_smc_add.avg - baseline.avg > baseline.avg / ALLOWED_DEVIATION)
+ if (!results_within_allowed_margin(baseline.avg, fast_smc_add.avg))
return TEST_RESULT_FAIL;
return TEST_RESULT_SUCCESS;
}