Merge tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux
[linux-2.6-microblaze.git] / arch / arm64 / kernel / cpufeature.c
index 5643a9c..2e3e551 100644 (file)
@@ -1967,6 +1967,20 @@ static void cpu_copy_el2regs(const struct arm64_cpu_capabilities *__unused)
                write_sysreg(read_sysreg(tpidr_el1), tpidr_el2);
 }
 
+static bool has_nested_virt_support(const struct arm64_cpu_capabilities *cap,
+                                   int scope)
+{
+       if (kvm_get_mode() != KVM_MODE_NV)
+               return false;
+
+       if (!has_cpuid_feature(cap, scope)) {
+               pr_warn("unavailable: %s\n", cap->desc);
+               return false;
+       }
+
+       return true;
+}
+
 #ifdef CONFIG_ARM64_PAN
 static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused)
 {
@@ -2262,6 +2276,17 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
                .matches = runs_at_el2,
                .cpu_enable = cpu_copy_el2regs,
        },
+       {
+               .desc = "Nested Virtualization Support",
+               .capability = ARM64_HAS_NESTED_VIRT,
+               .type = ARM64_CPUCAP_SYSTEM_FEATURE,
+               .matches = has_nested_virt_support,
+               .sys_reg = SYS_ID_AA64MMFR2_EL1,
+               .sign = FTR_UNSIGNED,
+               .field_pos = ID_AA64MMFR2_EL1_NV_SHIFT,
+               .field_width = 4,
+               .min_field_value = ID_AA64MMFR2_EL1_NV_IMP,
+       },
        {
                .capability = ARM64_HAS_32BIT_EL0_DO_NOT_USE,
                .type = ARM64_CPUCAP_SYSTEM_FEATURE,