Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9ce281d3 authored by Marc Zyngier's avatar Marc Zyngier Committed by Kyle Yan
Browse files

arm64: Add CNTVCT_EL0 trap handler



Since people seem to make a point in breaking the userspace visible
counter, we have no choice but to trap the access. Add the required
handler.

Change-Id: I6181a57dad00442fc1f4dfa2729e911d539d0736
Acked-by: default avatarThomas Gleixner <tglx@linutronix.de>
Acked-by: default avatarMark Rutland <mark.rutland@arm.com>
Signed-off-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
Git-commit: 6126ce0588eb5a0752d5c8b5796a7fca324fd887
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git


[kyan@codeaurora.org: resolve trivial merge conflicts]
Signed-off-by: default avatarKyle Yan <kyan@codeaurora.org>
parent 436b6888
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -175,6 +175,8 @@
#define ESR_ELx_SYS64_ISS_SYS_CTR_READ	(ESR_ELx_SYS64_ISS_SYS_CTR | \
					 ESR_ELx_SYS64_ISS_DIR_READ)

#define ESR_ELx_SYS64_ISS_SYS_CNTVCT	(ESR_ELx_SYS64_ISS_SYS_VAL(3, 3, 2, 14, 0) | \
					 ESR_ELx_SYS64_ISS_DIR_READ)
#ifndef __ASSEMBLY__
#include <asm/types.h>

+15 −0
Original line number Diff line number Diff line
@@ -540,6 +540,15 @@ static void ctr_read_handler(unsigned int esr, struct pt_regs *regs)
	regs->pc += 4;
}

static void cntvct_read_handler(unsigned int esr, struct pt_regs *regs)
{
	int rt = (esr & ESR_ELx_SYS64_ISS_RT_MASK) >> ESR_ELx_SYS64_ISS_RT_SHIFT;

	if (rt != 31)
		regs->regs[rt] = arch_counter_get_cntvct();
	regs->pc += 4;
}

struct sys64_hook {
	unsigned int esr_mask;
	unsigned int esr_val;
@@ -558,6 +567,12 @@ static struct sys64_hook sys64_hooks[] = {
		.esr_val = ESR_ELx_SYS64_ISS_SYS_CTR_READ,
		.handler = ctr_read_handler,
	},
	{
		/* Trap read access to CNTVCT_EL0 */
		.esr_mask = ESR_ELx_SYS64_ISS_SYS_OP_MASK,
		.esr_val = ESR_ELx_SYS64_ISS_SYS_CNTVCT,
		.handler = cntvct_read_handler,
	},
	{},
};