Commit ab510027 authored by Vladimir Murzin's avatar Vladimir Murzin Committed by Catalin Marinas
Browse files

arm64: KVM: Enable Common Not Private translations



We rely on cpufeature framework to detect and enable CNP so for KVM we
need to patch hyp to set CNP bit just before TTBR0_EL2 gets written.

For the guest we encode CNP bit while building vttbr, so we don't need
to bother with that in a world switch.

Reviewed-by: default avatarJames Morse <james.morse@arm.com>
Acked-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
Acked-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
Signed-off-by: default avatarVladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
parent 5ffdfaed
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -161,6 +161,7 @@
#else
#define VTTBR_X		(5 - KVM_T0SZ)
#endif
#define VTTBR_CNP_BIT     _AC(1, UL)
#define VTTBR_BADDR_MASK  (((_AC(1, ULL) << (40 - VTTBR_X)) - 1) << VTTBR_X)
#define VTTBR_VMID_SHIFT  _AC(48, ULL)
#define VTTBR_VMID_MASK(size)	(_AT(u64, (1 << size) - 1) << VTTBR_VMID_SHIFT)
+5 −0
Original line number Diff line number Diff line
@@ -355,6 +355,11 @@ static inline int hyp_map_aux_data(void)

#define kvm_phys_to_vttbr(addr)		(addr)

static inline bool kvm_cpu_has_cnp(void)
{
	return false;
}

#endif	/* !__ASSEMBLY__ */

#endif /* __ARM_KVM_MMU_H__ */
+1 −0
Original line number Diff line number Diff line
@@ -175,6 +175,7 @@
#define VTCR_EL2_FLAGS			(VTCR_EL2_COMMON_BITS | VTCR_EL2_TGRAN_FLAGS)
#define VTTBR_X				(VTTBR_X_TGRAN_MAGIC - VTCR_EL2_T0SZ_IPA)

#define VTTBR_CNP_BIT     (UL(1))
#define VTTBR_BADDR_MASK  (((UL(1) << (PHYS_MASK_SHIFT - VTTBR_X)) - 1) << VTTBR_X)
#define VTTBR_VMID_SHIFT  (UL(48))
#define VTTBR_VMID_MASK(size) (_AT(u64, (1 << size) - 1) << VTTBR_VMID_SHIFT)
+5 −0
Original line number Diff line number Diff line
@@ -517,5 +517,10 @@ static inline int hyp_map_aux_data(void)

#define kvm_phys_to_vttbr(addr)		phys_to_ttbr(addr)

static inline bool kvm_cpu_has_cnp(void)
{
	return system_supports_cnp();
}

#endif /* __ASSEMBLY__ */
#endif /* __ARM64_KVM_MMU_H__ */
+3 −0
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ __do_hyp_init:
	b.lo	__kvm_handle_stub_hvc

	phys_to_ttbr x4, x0
alternative_if ARM64_HAS_CNP
	orr	x4, x4, #TTBR_CNP_BIT
alternative_else_nop_endif
	msr	ttbr0_el2, x4

	mrs	x4, tcr_el1
Loading