Skip to content

Commit e2d6c90

Browse files
Marc Zyngieroupton
authored andcommitted
arm64: Add KVM_HVHE capability and has_hvhe() predicate
Expose a capability keying the hVHE feature as well as a new predicate testing it. Nothing is so far using it, and nothing is enabling it yet. Signed-off-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Link: https://lore.kernel.org/r/20230609162200.2024064-5-maz@kernel.org Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 0ddc312 commit e2d6c90

4 files changed

Lines changed: 29 additions & 0 deletions

File tree

arch/arm64/include/asm/cpufeature.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define cpu_feature(x) KERNEL_HWCAP_ ## x
1717

1818
#define ARM64_SW_FEATURE_OVERRIDE_NOKASLR 0
19+
#define ARM64_SW_FEATURE_OVERRIDE_HVHE 4
1920

2021
#ifndef __ASSEMBLY__
2122

arch/arm64/include/asm/virt.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ static __always_inline bool is_protected_kvm_enabled(void)
142142
return cpus_have_final_cap(ARM64_KVM_PROTECTED_MODE);
143143
}
144144

145+
static __always_inline bool has_hvhe(void)
146+
{
147+
if (is_vhe_hyp_code())
148+
return false;
149+
150+
return cpus_have_final_cap(ARM64_KVM_HVHE);
151+
}
152+
145153
static inline bool is_hyp_nvhe(void)
146154
{
147155
return is_hyp_mode_available() && !is_kernel_in_hyp_mode();

arch/arm64/kernel/cpufeature.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,19 @@ static bool has_nested_virt_support(const struct arm64_cpu_capabilities *cap,
19981998
return true;
19991999
}
20002000

2001+
static bool hvhe_possible(const struct arm64_cpu_capabilities *entry,
2002+
int __unused)
2003+
{
2004+
u64 val;
2005+
2006+
val = read_sysreg(id_aa64mmfr1_el1);
2007+
if (!cpuid_feature_extract_unsigned_field(val, ID_AA64MMFR1_EL1_VH_SHIFT))
2008+
return false;
2009+
2010+
val = arm64_sw_feature_override.val & arm64_sw_feature_override.mask;
2011+
return cpuid_feature_extract_unsigned_field(val, ARM64_SW_FEATURE_OVERRIDE_HVHE);
2012+
}
2013+
20012014
#ifdef CONFIG_ARM64_PAN
20022015
static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused)
20032016
{
@@ -2643,6 +2656,12 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
26432656
.cpu_enable = cpu_enable_dit,
26442657
ARM64_CPUID_FIELDS(ID_AA64PFR0_EL1, DIT, IMP)
26452658
},
2659+
{
2660+
.desc = "VHE for hypervisor only",
2661+
.capability = ARM64_KVM_HVHE,
2662+
.type = ARM64_CPUCAP_SYSTEM_FEATURE,
2663+
.matches = hvhe_possible,
2664+
},
26462665
{},
26472666
};
26482667

arch/arm64/tools/cpucaps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ HAS_TLB_RANGE
4747
HAS_VIRT_HOST_EXTN
4848
HAS_WFXT
4949
HW_DBM
50+
KVM_HVHE
5051
KVM_PROTECTED_MODE
5152
MISMATCHED_CACHE_TYPE
5253
MTE

0 commit comments

Comments
 (0)