From bb6a8befff70d30a58297933dc3b7b8c80772a43 Mon Sep 17 00:00:00 2001 From: Yang Yingliang Date: Fri, 12 Jul 2019 11:18:45 +0800 Subject: [PATCH] arm64: arch_timer: Disable CNTVCT_EL0 trap if workaround is enabled hulk inclusion category: performance bugzilla: 16082 CVE: NA ------------------------------------------------- It costs very much time to read CNTVCT_EL0, if a cntvct workaround and CNTVCT_EL0 trap is enabled. To decrease the read time, we disable CNTVCT_EL0 trap and do the cntvct workaround in the VDSO by adding vdso_fix. Signed-off-by: Yang Yingliang Reviewed-by: Xuefeng Wang Signed-off-by: Yang Yingliang --- drivers/clocksource/arm_arch_timer.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index 0445ad7e559e..eeea2bd27c1e 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -76,6 +76,7 @@ static bool arch_timer_c3stop; static bool arch_timer_mem_use_virtual; static bool arch_counter_suspend_stop; static bool vdso_default = true; +DEFINE_STATIC_KEY_FALSE(vdso_fix); static cpumask_t evtstrm_available = CPU_MASK_NONE; static bool evtstrm_enable = IS_ENABLED(CONFIG_ARM_ARCH_TIMER_EVTSTREAM); @@ -550,8 +551,9 @@ void arch_timer_enable_workaround(const struct arch_timer_erratum_workaround *wa * change both the default value and the vdso itself. */ if (wa->read_cntvct_el0) { - clocksource_counter.archdata.vdso_direct = false; - vdso_default = false; + clocksource_counter.archdata.vdso_direct = true; + vdso_default = true; + static_branch_enable(&vdso_fix); } } @@ -855,7 +857,8 @@ static void arch_counter_set_user_access(void) * need to be workaround. The vdso may have been already * disabled though. */ - if (arch_timer_this_cpu_has_cntvct_wa()) + if (arch_timer_this_cpu_has_cntvct_wa() && + !static_branch_unlikely(&vdso_fix)) pr_info("CPU%d: Trapping CNTVCT access\n", smp_processor_id()); else cntkctl |= ARCH_TIMER_USR_VCT_ACCESS_EN; -- GitLab