[RFC 5/6] arm64: hyperv: Enable userspace to read cntvct

From: Boqun Feng
Date: Sun Dec 15 2019 - 19:20:04 EST


Since reading hyperv-timer clocksource requires reading cntvct,
userspace should be allowed to read it, otherwise reading cntvct will
result in traps, which makes vsyscall's cost similar compared to
syscall's.

So enable it on every cpu when a Hyper-V guest booting up.

Signed-off-by: Boqun Feng (Microsoft) <boqun.feng@xxxxxxxxx>
---
arch/arm64/hyperv/hv_init.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/arch/arm64/hyperv/hv_init.c b/arch/arm64/hyperv/hv_init.c
index 86e4621d5885..1ea97ecfb143 100644
--- a/arch/arm64/hyperv/hv_init.c
+++ b/arch/arm64/hyperv/hv_init.c
@@ -27,6 +27,7 @@
#include <linux/sched_clock.h>
#include <asm-generic/bug.h>
#include <asm/hyperv-tlfs.h>
+#include <asm/arch_timer.h>
#include <asm/mshyperv.h>
#include <asm/sysreg.h>
#include <clocksource/hyperv_timer.h>
@@ -45,6 +46,7 @@ EXPORT_SYMBOL_GPL(hv_max_vp_index);
static int hv_cpu_init(unsigned int cpu)
{
u64 msr_vp_index;
+ u32 cntkctl;

hv_get_vp_index(msr_vp_index);

@@ -53,6 +55,11 @@ static int hv_cpu_init(unsigned int cpu)
if (msr_vp_index > hv_max_vp_index)
hv_max_vp_index = msr_vp_index;

+ /* Enable EL0 to access cntvct */
+ cntkctl = arch_timer_get_cntkctl();
+ cntkctl |= ARCH_TIMER_USR_VCT_ACCESS_EN;
+ arch_timer_set_cntkctl(cntkctl);
+
return 0;
}

--
2.24.0