Lines Matching +full:f +full:- +full:tile
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Kernel-based Virtual Machine driver for Linux
55 cpuid_count(0xD, i, &xs->eax, &xs->ebx, &xs->ecx, &ign); in kvm_init_xstate_sizes()
74 offset = (xs->ecx & 0x2) ? ALIGN(ret, 64) : ret; in xstate_required_size()
76 offset = xs->ebx; in xstate_required_size()
77 ret = max(ret, offset + xs->eax); in xstate_required_size()
91 * KVM has a semi-arbitrary rule that querying the guest's CPUID model in kvm_find_cpuid_entry2()
95 * path, e.g. the core VM-Enter/VM-Exit run loop. Nothing will break in kvm_find_cpuid_entry2()
105 if (e->function != function) in kvm_find_cpuid_entry2()
113 if (!(e->flags & KVM_CPUID_FLAG_SIGNIFCANT_INDEX) || e->index == index) in kvm_find_cpuid_entry2()
142 * The existing code assumes virtual address is 48-bit or 57-bit in the in kvm_check_cpuid()
147 int vaddr_bits = (best->eax & 0xff00) >> 8; in kvm_check_cpuid()
150 return -EINVAL; in kvm_check_cpuid()
161 xfeatures = best->eax | ((u64)best->edx << 32); in kvm_check_cpuid()
166 return fpu_enable_guest_xfd_features(&vcpu->arch.guest_fpu, xfeatures); in kvm_check_cpuid()
181 * false positives due mismatches on KVM-owned feature flags. in kvm_cpuid_check_equal()
188 if (nent != vcpu->arch.cpuid_nent) in kvm_cpuid_check_equal()
189 return -EINVAL; in kvm_cpuid_check_equal()
192 orig = &vcpu->arch.cpuid_entries[i]; in kvm_cpuid_check_equal()
193 if (e2[i].function != orig->function || in kvm_cpuid_check_equal()
194 e2[i].index != orig->index || in kvm_cpuid_check_equal()
195 e2[i].flags != orig->flags || in kvm_cpuid_check_equal()
196 e2[i].eax != orig->eax || e2[i].ebx != orig->ebx || in kvm_cpuid_check_equal()
197 e2[i].ecx != orig->ecx || e2[i].edx != orig->edx) in kvm_cpuid_check_equal()
198 return -EINVAL; in kvm_cpuid_check_equal()
217 signature[0] = entry->ebx; in kvm_get_hypervisor_cpuid()
218 signature[1] = entry->ecx; in kvm_get_hypervisor_cpuid()
219 signature[2] = entry->edx; in kvm_get_hypervisor_cpuid()
223 cpuid.limit = entry->eax; in kvm_get_hypervisor_cpuid()
245 if (kvm_hlt_in_guest(vcpu->kvm)) in kvm_apply_cpuid_pv_features_quirk()
246 best->eax &= ~(1 << KVM_FEATURE_PV_UNHALT); in kvm_apply_cpuid_pv_features_quirk()
248 return best->eax; in kvm_apply_cpuid_pv_features_quirk()
263 return (best->eax | ((u64)best->edx << 32)) & kvm_caps.supported_xcr0; in cpuid_get_supported_xcr0()
274 return (best->ecx | ((u64)best->edx << 32)) & kvm_caps.supported_xss; in cpuid_get_supported_xss()
290 vcpu->arch.cpuid_dynamic_bits_dirty = false; in kvm_update_cpuid_runtime()
298 vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE); in kvm_update_cpuid_runtime()
300 if (!kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT)) in kvm_update_cpuid_runtime()
302 vcpu->arch.ia32_misc_enable_msr & in kvm_update_cpuid_runtime()
314 best->ebx = xstate_required_size(vcpu->arch.xcr0, false); in kvm_update_cpuid_runtime()
319 best->ebx = xstate_required_size(vcpu->arch.xcr0 | in kvm_update_cpuid_runtime()
320 vcpu->arch.ia32_xss, true); in kvm_update_cpuid_runtime()
329 return entry && entry->eax == HYPERV_CPUID_SIGNATURE_EAX; in kvm_cpuid_has_hyperv()
343 return is_guest_vendor_amd(entry->ebx, entry->ecx, entry->edx) || in guest_cpuid_is_amd_or_hygon()
344 is_guest_vendor_hygon(entry->ebx, entry->ecx, entry->edx); in guest_cpuid_is_amd_or_hygon()
350 * compile-time validation of the input.
356 return entry->eax; in cpuid_get_reg_unsafe()
358 return entry->ebx; in cpuid_get_reg_unsafe()
360 return entry->ecx; in cpuid_get_reg_unsafe()
362 return entry->edx; in cpuid_get_reg_unsafe()
374 struct kvm_lapic *apic = vcpu->arch.apic; in kvm_vcpu_after_set_cpuid()
380 memset(vcpu->arch.cpu_caps, 0, sizeof(vcpu->arch.cpu_caps)); in kvm_vcpu_after_set_cpuid()
406 vcpu->arch.cpu_caps[i] = kvm_cpu_caps[i] | in kvm_vcpu_after_set_cpuid()
408 vcpu->arch.cpu_caps[i] &= cpuid_get_reg_unsafe(entry, cpuid.reg); in kvm_vcpu_after_set_cpuid()
416 * i.e. won't treat them as reserved, and KVM doesn't redo the GVA->GPA in kvm_vcpu_after_set_cpuid()
418 * _can't_ solve the problem because GVA->GPA walks aren't visible to in kvm_vcpu_after_set_cpuid()
431 apic->lapic_timer.timer_mode_mask = 3 << 17; in kvm_vcpu_after_set_cpuid()
433 apic->lapic_timer.timer_mode_mask = 1 << 17; in kvm_vcpu_after_set_cpuid()
438 vcpu->arch.guest_supported_xcr0 = cpuid_get_supported_xcr0(vcpu); in kvm_vcpu_after_set_cpuid()
439 vcpu->arch.guest_supported_xss = cpuid_get_supported_xss(vcpu); in kvm_vcpu_after_set_cpuid()
441 vcpu->arch.pv_cpuid.features = kvm_apply_cpuid_pv_features_quirk(vcpu); in kvm_vcpu_after_set_cpuid()
443 vcpu->arch.is_amd_compatible = guest_cpuid_is_amd_or_hygon(vcpu); in kvm_vcpu_after_set_cpuid()
444 vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu); in kvm_vcpu_after_set_cpuid()
445 vcpu->arch.reserved_gpa_bits = kvm_vcpu_reserved_gpa_bits_raw(vcpu); in kvm_vcpu_after_set_cpuid()
449 #define __kvm_cpu_cap_has(UNUSED_, f) kvm_cpu_cap_has(f) in kvm_vcpu_after_set_cpuid() argument
450 vcpu->arch.cr4_guest_rsvd_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_) | in kvm_vcpu_after_set_cpuid()
473 if (!best || best->eax < 0x80000008) in cpuid_query_maxphyaddr()
477 return best->eax & 0xff; in cpuid_query_maxphyaddr()
487 if (!best || best->eax < 0x80000008) in cpuid_query_maxguestphyaddr()
491 return (best->eax >> 16) & 0xff; in cpuid_query_maxguestphyaddr()
523 swap(vcpu->arch.cpuid_entries, e2); in kvm_set_cpuid()
524 swap(vcpu->arch.cpuid_nent, nent); in kvm_set_cpuid()
526 memcpy(vcpu_caps, vcpu->arch.cpu_caps, sizeof(vcpu_caps)); in kvm_set_cpuid()
527 BUILD_BUG_ON(sizeof(vcpu_caps) != sizeof(vcpu->arch.cpu_caps)); in kvm_set_cpuid()
560 vcpu->arch.xen.cpuid = kvm_get_hypervisor_cpuid(vcpu, XEN_SIGNATURE); in kvm_set_cpuid()
569 memcpy(vcpu->arch.cpu_caps, vcpu_caps, sizeof(vcpu_caps)); in kvm_set_cpuid()
570 swap(vcpu->arch.cpuid_entries, e2); in kvm_set_cpuid()
571 swap(vcpu->arch.cpuid_nent, nent); in kvm_set_cpuid()
584 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES) in kvm_vcpu_ioctl_set_cpuid()
585 return -E2BIG; in kvm_vcpu_ioctl_set_cpuid()
587 if (cpuid->nent) { in kvm_vcpu_ioctl_set_cpuid()
588 e = vmemdup_array_user(entries, cpuid->nent, sizeof(*e)); in kvm_vcpu_ioctl_set_cpuid()
592 e2 = kvmalloc_array(cpuid->nent, sizeof(*e2), GFP_KERNEL_ACCOUNT); in kvm_vcpu_ioctl_set_cpuid()
594 r = -ENOMEM; in kvm_vcpu_ioctl_set_cpuid()
598 for (i = 0; i < cpuid->nent; i++) { in kvm_vcpu_ioctl_set_cpuid()
611 r = kvm_set_cpuid(vcpu, e2, cpuid->nent); in kvm_vcpu_ioctl_set_cpuid()
628 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES) in kvm_vcpu_ioctl_set_cpuid2()
629 return -E2BIG; in kvm_vcpu_ioctl_set_cpuid2()
631 if (cpuid->nent) { in kvm_vcpu_ioctl_set_cpuid2()
632 e2 = vmemdup_array_user(entries, cpuid->nent, sizeof(*e2)); in kvm_vcpu_ioctl_set_cpuid2()
637 r = kvm_set_cpuid(vcpu, e2, cpuid->nent); in kvm_vcpu_ioctl_set_cpuid2()
648 if (cpuid->nent < vcpu->arch.cpuid_nent) in kvm_vcpu_ioctl_get_cpuid2()
649 return -E2BIG; in kvm_vcpu_ioctl_get_cpuid2()
651 if (vcpu->arch.cpuid_dynamic_bits_dirty) in kvm_vcpu_ioctl_get_cpuid2()
654 if (copy_to_user(entries, vcpu->arch.cpuid_entries, in kvm_vcpu_ioctl_get_cpuid2()
655 vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2))) in kvm_vcpu_ioctl_get_cpuid2()
656 return -EFAULT; in kvm_vcpu_ioctl_get_cpuid2()
658 cpuid->nent = vcpu->arch.cpuid_nent; in kvm_vcpu_ioctl_get_cpuid2()
686 * For kernel-defined leafs, mask KVM's supported feature set with the kernel's
687 * capabilities as well as raw CPUID. For KVM-defined leafs, consult only raw
714 * Assert that the feature bit being declared, e.g. via F(), is in the CPUID
725 #define F(name) \ macro
731 /* Scattered Flag - For features that are scattered by cpufeatures.h. */
737 F(name); \
740 /* Features that KVM supports only on 64-bit kernels. */
745 F(name); \
749 * Emulated Feature - For features that KVM emulates in software irrespective
755 F(name); \
759 * Synthesized Feature - For features that are synthesized into boot_cpu_data,
766 F(name); \
770 * Passthrough Feature - For features that KVM supports based purely on raw
778 F(name); \
782 * Aliased Features - For features in 0x8000_0001.EDX that are duplicates of
793 * Vendor Features - For features that KVM supports, but are added in later
802 * Runtime Features - For features that KVM dynamically sets/clears at runtime,
816 /* DS is defined by ptrace-abi.h on 32-bit builds. */
823 BUILD_BUG_ON(sizeof(kvm_cpu_caps) - (NKVMCAPINTS * sizeof(*kvm_cpu_caps)) > in kvm_set_cpu_caps()
827 F(XMM3), in kvm_set_cpu_caps()
828 F(PCLMULQDQ), in kvm_set_cpu_caps()
837 /* DS-CPL */ in kvm_set_cpu_caps()
841 F(SSSE3), in kvm_set_cpu_caps()
842 /* CNXT-ID */ in kvm_set_cpu_caps()
844 F(FMA), in kvm_set_cpu_caps()
845 F(CX16), in kvm_set_cpu_caps()
847 F(PDCM), in kvm_set_cpu_caps()
848 F(PCID), in kvm_set_cpu_caps()
850 F(XMM4_1), in kvm_set_cpu_caps()
851 F(XMM4_2), in kvm_set_cpu_caps()
853 F(MOVBE), in kvm_set_cpu_caps()
854 F(POPCNT), in kvm_set_cpu_caps()
856 F(AES), in kvm_set_cpu_caps()
857 F(XSAVE), in kvm_set_cpu_caps()
859 F(AVX), in kvm_set_cpu_caps()
860 F(F16C), in kvm_set_cpu_caps()
861 F(RDRAND), in kvm_set_cpu_caps()
866 F(FPU), in kvm_set_cpu_caps()
867 F(VME), in kvm_set_cpu_caps()
868 F(DE), in kvm_set_cpu_caps()
869 F(PSE), in kvm_set_cpu_caps()
870 F(TSC), in kvm_set_cpu_caps()
871 F(MSR), in kvm_set_cpu_caps()
872 F(PAE), in kvm_set_cpu_caps()
873 F(MCE), in kvm_set_cpu_caps()
874 F(CX8), in kvm_set_cpu_caps()
875 F(APIC), in kvm_set_cpu_caps()
877 F(SEP), in kvm_set_cpu_caps()
878 F(MTRR), in kvm_set_cpu_caps()
879 F(PGE), in kvm_set_cpu_caps()
880 F(MCA), in kvm_set_cpu_caps()
881 F(CMOV), in kvm_set_cpu_caps()
882 F(PAT), in kvm_set_cpu_caps()
883 F(PSE36), in kvm_set_cpu_caps()
885 F(CLFLUSH), in kvm_set_cpu_caps()
889 F(MMX), in kvm_set_cpu_caps()
890 F(FXSR), in kvm_set_cpu_caps()
891 F(XMM), in kvm_set_cpu_caps()
892 F(XMM2), in kvm_set_cpu_caps()
893 F(SELFSNOOP), in kvm_set_cpu_caps()
898 F(FSGSBASE), in kvm_set_cpu_caps()
900 F(SGX), in kvm_set_cpu_caps()
901 F(BMI1), in kvm_set_cpu_caps()
902 F(HLE), in kvm_set_cpu_caps()
903 F(AVX2), in kvm_set_cpu_caps()
904 F(FDP_EXCPTN_ONLY), in kvm_set_cpu_caps()
905 F(SMEP), in kvm_set_cpu_caps()
906 F(BMI2), in kvm_set_cpu_caps()
907 F(ERMS), in kvm_set_cpu_caps()
908 F(INVPCID), in kvm_set_cpu_caps()
909 F(RTM), in kvm_set_cpu_caps()
910 F(ZERO_FCS_FDS), in kvm_set_cpu_caps()
912 F(AVX512F), in kvm_set_cpu_caps()
913 F(AVX512DQ), in kvm_set_cpu_caps()
914 F(RDSEED), in kvm_set_cpu_caps()
915 F(ADX), in kvm_set_cpu_caps()
916 F(SMAP), in kvm_set_cpu_caps()
917 F(AVX512IFMA), in kvm_set_cpu_caps()
918 F(CLFLUSHOPT), in kvm_set_cpu_caps()
919 F(CLWB), in kvm_set_cpu_caps()
921 F(AVX512PF), in kvm_set_cpu_caps()
922 F(AVX512ER), in kvm_set_cpu_caps()
923 F(AVX512CD), in kvm_set_cpu_caps()
924 F(SHA_NI), in kvm_set_cpu_caps()
925 F(AVX512BW), in kvm_set_cpu_caps()
926 F(AVX512VL), in kvm_set_cpu_caps()
930 F(AVX512VBMI), in kvm_set_cpu_caps()
932 F(PKU), in kvm_set_cpu_caps()
934 F(RDPID), in kvm_set_cpu_caps()
935 F(AVX512_VPOPCNTDQ), in kvm_set_cpu_caps()
936 F(UMIP), in kvm_set_cpu_caps()
937 F(AVX512_VBMI2), in kvm_set_cpu_caps()
938 F(GFNI), in kvm_set_cpu_caps()
939 F(VAES), in kvm_set_cpu_caps()
940 F(VPCLMULQDQ), in kvm_set_cpu_caps()
941 F(AVX512_VNNI), in kvm_set_cpu_caps()
942 F(AVX512_BITALG), in kvm_set_cpu_caps()
943 F(CLDEMOTE), in kvm_set_cpu_caps()
944 F(MOVDIRI), in kvm_set_cpu_caps()
945 F(MOVDIR64B), in kvm_set_cpu_caps()
947 F(SGX_LC), in kvm_set_cpu_caps()
948 F(BUS_LOCK_DETECT), in kvm_set_cpu_caps()
968 F(AVX512_4VNNIW), in kvm_set_cpu_caps()
969 F(AVX512_4FMAPS), in kvm_set_cpu_caps()
970 F(SPEC_CTRL), in kvm_set_cpu_caps()
971 F(SPEC_CTRL_SSBD), in kvm_set_cpu_caps()
973 F(INTEL_STIBP), in kvm_set_cpu_caps()
974 F(MD_CLEAR), in kvm_set_cpu_caps()
975 F(AVX512_VP2INTERSECT), in kvm_set_cpu_caps()
976 F(FSRM), in kvm_set_cpu_caps()
977 F(SERIALIZE), in kvm_set_cpu_caps()
978 F(TSXLDTRK), in kvm_set_cpu_caps()
979 F(AVX512_FP16), in kvm_set_cpu_caps()
980 F(AMX_TILE), in kvm_set_cpu_caps()
981 F(AMX_INT8), in kvm_set_cpu_caps()
982 F(AMX_BF16), in kvm_set_cpu_caps()
983 F(FLUSH_L1D), in kvm_set_cpu_caps()
984 F(IBT), in kvm_set_cpu_caps()
1007 F(SHA512), in kvm_set_cpu_caps()
1008 F(SM3), in kvm_set_cpu_caps()
1009 F(SM4), in kvm_set_cpu_caps()
1010 F(AVX_VNNI), in kvm_set_cpu_caps()
1011 F(AVX512_BF16), in kvm_set_cpu_caps()
1012 F(CMPCCXADD), in kvm_set_cpu_caps()
1013 F(FZRM), in kvm_set_cpu_caps()
1014 F(FSRS), in kvm_set_cpu_caps()
1015 F(FSRC), in kvm_set_cpu_caps()
1016 F(WRMSRNS), in kvm_set_cpu_caps()
1018 F(AMX_FP16), in kvm_set_cpu_caps()
1019 F(AVX_IFMA), in kvm_set_cpu_caps()
1020 F(LAM), in kvm_set_cpu_caps()
1028 F(AVX_VNNI_INT8), in kvm_set_cpu_caps()
1029 F(AVX_NE_CONVERT), in kvm_set_cpu_caps()
1030 F(AMX_COMPLEX), in kvm_set_cpu_caps()
1031 F(AVX_VNNI_INT16), in kvm_set_cpu_caps()
1032 F(PREFETCHITI), in kvm_set_cpu_caps()
1033 F(AVX10), in kvm_set_cpu_caps()
1037 F(INTEL_PSFD), in kvm_set_cpu_caps()
1038 F(IPRED_CTRL), in kvm_set_cpu_caps()
1039 F(RRSBA_CTRL), in kvm_set_cpu_caps()
1040 F(DDPD_U), in kvm_set_cpu_caps()
1041 F(BHI_CTRL), in kvm_set_cpu_caps()
1042 F(MCDT_NO), in kvm_set_cpu_caps()
1046 F(XSAVEOPT), in kvm_set_cpu_caps()
1047 F(XSAVEC), in kvm_set_cpu_caps()
1048 F(XGETBV1), in kvm_set_cpu_caps()
1049 F(XSAVES), in kvm_set_cpu_caps()
1060 F(AVX10_128), in kvm_set_cpu_caps()
1061 F(AVX10_256), in kvm_set_cpu_caps()
1062 F(AVX10_512), in kvm_set_cpu_caps()
1066 F(LAHF_LM), in kvm_set_cpu_caps()
1067 F(CMP_LEGACY), in kvm_set_cpu_caps()
1070 F(CR8_LEGACY), in kvm_set_cpu_caps()
1071 F(ABM), in kvm_set_cpu_caps()
1072 F(SSE4A), in kvm_set_cpu_caps()
1073 F(MISALIGNSSE), in kvm_set_cpu_caps()
1074 F(3DNOWPREFETCH), in kvm_set_cpu_caps()
1075 F(OSVW), in kvm_set_cpu_caps()
1077 F(XOP), in kvm_set_cpu_caps()
1079 F(FMA4), in kvm_set_cpu_caps()
1080 F(TBM), in kvm_set_cpu_caps()
1081 F(TOPOEXT), in kvm_set_cpu_caps()
1097 F(SYSCALL), in kvm_set_cpu_caps()
1105 F(NX), in kvm_set_cpu_caps()
1107 F(MMXEXT), in kvm_set_cpu_caps()
1110 F(FXSR_OPT), in kvm_set_cpu_caps()
1112 F(RDTSCP), in kvm_set_cpu_caps()
1115 F(3DNOWEXT), in kvm_set_cpu_caps()
1116 F(3DNOW), in kvm_set_cpu_caps()
1127 F(CLZERO), in kvm_set_cpu_caps()
1128 F(XSAVEERPTR), in kvm_set_cpu_caps()
1129 F(WBNOINVD), in kvm_set_cpu_caps()
1130 F(AMD_IBPB), in kvm_set_cpu_caps()
1131 F(AMD_IBRS), in kvm_set_cpu_caps()
1132 F(AMD_SSBD), in kvm_set_cpu_caps()
1133 F(VIRT_SSBD), in kvm_set_cpu_caps()
1134 F(AMD_SSB_NO), in kvm_set_cpu_caps()
1135 F(AMD_STIBP), in kvm_set_cpu_caps()
1136 F(AMD_STIBP_ALWAYS_ON), in kvm_set_cpu_caps()
1137 F(AMD_IBRS_SAME_MODE), in kvm_set_cpu_caps()
1138 F(AMD_PSFD), in kvm_set_cpu_caps()
1139 F(AMD_IBPB_RET), in kvm_set_cpu_caps()
1190 F(SME_COHERENT), in kvm_set_cpu_caps()
1194 F(NO_NESTED_DATA_BP), in kvm_set_cpu_caps()
1195 F(WRMSR_XX_BASE_NS), in kvm_set_cpu_caps()
1197 * Synthesize "LFENCE is serializing" into the AMD-defined entry in kvm_set_cpu_caps()
1199 * supported by the kernel. LFENCE_RDTSC was a Linux-defined in kvm_set_cpu_caps()
1210 F(NULL_SEL_CLR_BASE), in kvm_set_cpu_caps()
1212 F(AUTOIBRS), in kvm_set_cpu_caps()
1213 F(PREFETCHI), in kvm_set_cpu_caps()
1221 F(SRSO_USER_KERNEL_NO), in kvm_set_cpu_caps()
1230 F(PERFMON_V2), in kvm_set_cpu_caps()
1237 F(XSTORE), in kvm_set_cpu_caps()
1238 F(XSTORE_EN), in kvm_set_cpu_caps()
1239 F(XCRYPT), in kvm_set_cpu_caps()
1240 F(XCRYPT_EN), in kvm_set_cpu_caps()
1241 F(ACE2), in kvm_set_cpu_caps()
1242 F(ACE2_EN), in kvm_set_cpu_caps()
1243 F(PHE), in kvm_set_cpu_caps()
1244 F(PHE_EN), in kvm_set_cpu_caps()
1245 F(PMM), in kvm_set_cpu_caps()
1246 F(PMM_EN), in kvm_set_cpu_caps()
1266 #undef F
1284 if (array->nent >= array->maxnent) in get_next_cpuid()
1287 return &array->entries[array->nent++]; in get_next_cpuid()
1299 entry->function = function; in do_host_cpuid()
1300 entry->index = index; in do_host_cpuid()
1309 * would result in out-of-bounds calls to do_host_cpuid. in do_host_cpuid()
1324 cpuid_count(entry->function, entry->index, in do_host_cpuid()
1325 &entry->eax, &entry->ebx, &entry->ecx, &entry->edx); in do_host_cpuid()
1328 entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; in do_host_cpuid()
1338 entry->function = func; in cpuid_func_emulated()
1339 entry->index = 0; in cpuid_func_emulated()
1340 entry->flags = 0; in cpuid_func_emulated()
1344 entry->eax = 7; in cpuid_func_emulated()
1347 entry->ecx = feature_bit(MOVBE); in cpuid_func_emulated()
1354 * them natively requires enabling a per-VM capability. in cpuid_func_emulated()
1357 entry->ecx |= feature_bit(MWAIT); in cpuid_func_emulated()
1360 entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; in cpuid_func_emulated()
1361 entry->eax = 0; in cpuid_func_emulated()
1363 entry->ecx = feature_bit(RDPID); in cpuid_func_emulated()
1372 if (array->nent >= array->maxnent) in __do_cpuid_func_emulated()
1373 return -E2BIG; in __do_cpuid_func_emulated()
1375 array->nent += cpuid_func_emulated(&array->entries[array->nent], func, false); in __do_cpuid_func_emulated()
1387 r = -E2BIG; in __do_cpuid_func()
1396 entry->eax = min(entry->eax, 0x24U); in __do_cpuid_func()
1406 * time, with the least-significant byte in EAX enumerating the in __do_cpuid_func()
1418 WARN_ON_ONCE((entry->eax & 0xff) > 1); in __do_cpuid_func()
1427 for (i = 1; entry->eax & 0x1f; ++i) { in __do_cpuid_func()
1434 entry->eax = 0x4; /* allow ARAT */ in __do_cpuid_func()
1435 entry->ebx = 0; in __do_cpuid_func()
1436 entry->ecx = 0; in __do_cpuid_func()
1437 entry->edx = 0; in __do_cpuid_func()
1441 max_idx = entry->eax = min(entry->eax, 2u); in __do_cpuid_func()
1455 entry->ebx = 0; in __do_cpuid_func()
1463 entry->ecx = 0; in __do_cpuid_func()
1464 entry->ebx = 0; in __do_cpuid_func()
1465 entry->eax = 0; in __do_cpuid_func()
1473 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1487 entry->eax = eax.full; in __do_cpuid_func()
1488 entry->ebx = kvm_pmu_cap.events_mask; in __do_cpuid_func()
1489 entry->ecx = 0; in __do_cpuid_func()
1490 entry->edx = edx.full; in __do_cpuid_func()
1499 entry->eax = entry->ebx = entry->ecx = 0; in __do_cpuid_func()
1505 entry->eax &= permitted_xcr0; in __do_cpuid_func()
1506 entry->ebx = xstate_required_size(permitted_xcr0, false); in __do_cpuid_func()
1507 entry->ecx = entry->ebx; in __do_cpuid_func()
1508 entry->edx &= permitted_xcr0 >> 32; in __do_cpuid_func()
1517 if (entry->eax & (feature_bit(XSAVES) | feature_bit(XSAVEC))) in __do_cpuid_func()
1518 entry->ebx = xstate_required_size(permitted_xcr0 | permitted_xss, in __do_cpuid_func()
1522 entry->ebx = 0; in __do_cpuid_func()
1524 entry->ecx &= permitted_xss; in __do_cpuid_func()
1525 entry->edx &= permitted_xss >> 32; in __do_cpuid_func()
1542 * invalid sub-leafs. Only valid sub-leafs should in __do_cpuid_func()
1543 * reach this point, and they should have a non-zero in __do_cpuid_func()
1546 * on whether this is an XCR0- or IA32_XSS-managed area. in __do_cpuid_func()
1548 if (WARN_ON_ONCE(!entry->eax || (entry->ecx & 0x1) != s_state)) { in __do_cpuid_func()
1549 --array->nent; in __do_cpuid_func()
1554 entry->ecx &= ~BIT_ULL(2); in __do_cpuid_func()
1555 entry->edx = 0; in __do_cpuid_func()
1562 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1567 * Index 0: Sub-features, MISCSELECT (a.k.a extended features) in __do_cpuid_func()
1568 * and max enclave sizes. The SGX sub-features and MISCSELECT in __do_cpuid_func()
1573 entry->ebx &= SGX_MISC_EXINFO; in __do_cpuid_func()
1582 * privileged attributes that require explicit opt-in from in __do_cpuid_func()
1586 entry->eax &= SGX_ATTR_PRIV_MASK | SGX_ATTR_UNPRIV_MASK; in __do_cpuid_func()
1587 entry->ebx &= 0; in __do_cpuid_func()
1592 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1596 for (i = 1, max_idx = entry->eax; i <= max_idx; ++i) { in __do_cpuid_func()
1601 /* Intel AMX TILE */ in __do_cpuid_func()
1604 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1608 for (i = 1, max_idx = entry->eax; i <= max_idx; ++i) { in __do_cpuid_func()
1615 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1623 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1632 avx10_version = min_t(u8, entry->ebx & 0xff, 1); in __do_cpuid_func()
1634 entry->ebx |= avx10_version; in __do_cpuid_func()
1636 entry->eax = 0; in __do_cpuid_func()
1637 entry->ecx = 0; in __do_cpuid_func()
1638 entry->edx = 0; in __do_cpuid_func()
1643 entry->eax = KVM_CPUID_FEATURES; in __do_cpuid_func()
1644 entry->ebx = sigptr[0]; in __do_cpuid_func()
1645 entry->ecx = sigptr[1]; in __do_cpuid_func()
1646 entry->edx = sigptr[2]; in __do_cpuid_func()
1650 entry->eax = (1 << KVM_FEATURE_CLOCKSOURCE) | in __do_cpuid_func()
1665 entry->eax |= (1 << KVM_FEATURE_STEAL_TIME); in __do_cpuid_func()
1667 entry->ebx = 0; in __do_cpuid_func()
1668 entry->ecx = 0; in __do_cpuid_func()
1669 entry->edx = 0; in __do_cpuid_func()
1672 entry->eax = min(entry->eax, 0x80000022); in __do_cpuid_func()
1686 if (entry->eax >= 0x8000001d && in __do_cpuid_func()
1689 entry->eax = max(entry->eax, 0x80000021); in __do_cpuid_func()
1692 entry->ebx &= ~GENMASK(27, 16); in __do_cpuid_func()
1701 entry->edx &= ~GENMASK(17, 16); in __do_cpuid_func()
1707 entry->edx &= boot_cpu_data.x86_power; in __do_cpuid_func()
1708 entry->eax = entry->ebx = entry->ecx = 0; in __do_cpuid_func()
1723 * support 5-level TDP. in __do_cpuid_func()
1725 unsigned int virt_as = max((entry->eax >> 8) & 0xff, 48U); in __do_cpuid_func()
1737 * that it's capped at 48 bits if 5-level TDP isn't supported in __do_cpuid_func()
1745 phys_as = entry->eax & 0xff; in __do_cpuid_func()
1751 entry->eax = phys_as | (virt_as << 8) | (g_phys_as << 16); in __do_cpuid_func()
1752 entry->ecx &= ~(GENMASK(31, 16) | GENMASK(11, 8)); in __do_cpuid_func()
1753 entry->edx = 0; in __do_cpuid_func()
1759 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1762 entry->eax = 1; /* SVM revision 1 */ in __do_cpuid_func()
1763 entry->ebx = 8; /* Lets support 8 ASIDs in case we add proper in __do_cpuid_func()
1765 entry->ecx = 0; /* Reserved */ in __do_cpuid_func()
1769 entry->ecx = entry->edx = 0; in __do_cpuid_func()
1772 entry->eax &= GENMASK(2, 0); in __do_cpuid_func()
1773 entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1777 entry->eax = entry->ebx = entry->ecx = 0; in __do_cpuid_func()
1778 entry->edx = 0; /* reserved */ in __do_cpuid_func()
1782 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1786 entry->ebx &= ~GENMASK(31, 12); in __do_cpuid_func()
1791 entry->ebx &= ~GENMASK(11, 6); in __do_cpuid_func()
1795 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1798 entry->ebx = entry->edx = 0; in __do_cpuid_func()
1806 entry->ecx = entry->edx = 0; in __do_cpuid_func()
1808 entry->eax = entry->ebx = 0; in __do_cpuid_func()
1815 entry->ebx = ebx.full; in __do_cpuid_func()
1821 entry->eax = min(entry->eax, 0xC0000004); in __do_cpuid_func()
1832 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1870 limit = array->entries[array->nent - 1].eax; in get_cpuid_func()
1890 * We want to make sure that ->padding is being passed clean from in sanity_check_entries()
1920 if (cpuid->nent < 1) in kvm_dev_ioctl_get_cpuid()
1921 return -E2BIG; in kvm_dev_ioctl_get_cpuid()
1922 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES) in kvm_dev_ioctl_get_cpuid()
1923 cpuid->nent = KVM_MAX_CPUID_ENTRIES; in kvm_dev_ioctl_get_cpuid()
1925 if (sanity_check_entries(entries, cpuid->nent, type)) in kvm_dev_ioctl_get_cpuid()
1926 return -EINVAL; in kvm_dev_ioctl_get_cpuid()
1928 array.entries = kvcalloc(cpuid->nent, sizeof(struct kvm_cpuid_entry2), GFP_KERNEL); in kvm_dev_ioctl_get_cpuid()
1930 return -ENOMEM; in kvm_dev_ioctl_get_cpuid()
1932 array.maxnent = cpuid->nent; in kvm_dev_ioctl_get_cpuid()
1939 cpuid->nent = array.nent; in kvm_dev_ioctl_get_cpuid()
1943 r = -EFAULT; in kvm_dev_ioctl_get_cpuid()
1951 * Intel CPUID semantics treats any query for an out-of-range leaf as if the
1956 * A leaf is considered out-of-range if its function is higher than the maximum
1961 * ranges described as "<base> - <top>[,<base2> - <top2>] inclusive. A primary
1965 * - Basic: 0x00000000 - 0x3fffffff, 0x50000000 - 0x7fffffff
1966 * - Hypervisor: 0x40000000 - 0x4fffffff
1967 * - Extended: 0x80000000 - 0xbfffffff
1968 * - Centaur: 0xc0000000 - 0xcfffffff
1970 * The Hypervisor class is further subdivided into sub-classes that each act as
1973 * CPUID sub-classes are:
1975 * - HyperV: 0x40000000 - 0x400000ff
1976 * - KVM: 0x40000100 - 0x400001ff
1988 if (is_guest_vendor_amd(basic->ebx, basic->ecx, basic->edx) || in get_out_of_range_cpuid_entry()
1989 is_guest_vendor_hygon(basic->ebx, basic->ecx, basic->edx)) in get_out_of_range_cpuid_entry()
1999 if (class && function <= class->eax) in get_out_of_range_cpuid_entry()
2008 *fn_ptr = basic->eax; in get_out_of_range_cpuid_entry()
2015 return kvm_find_cpuid_entry_index(vcpu, basic->eax, index); in get_out_of_range_cpuid_entry()
2025 if (vcpu->arch.cpuid_dynamic_bits_dirty) in kvm_cpuid()
2037 *eax = entry->eax; in kvm_cpuid()
2038 *ebx = entry->ebx; in kvm_cpuid()
2039 *ecx = entry->ecx; in kvm_cpuid()
2040 *edx = entry->edx; in kvm_cpuid()
2061 *ecx = vcpu->arch.pvclock_tsc_mul; in kvm_cpuid()
2062 *edx = vcpu->arch.pvclock_tsc_shift; in kvm_cpuid()
2064 *eax = vcpu->arch.hw_tsc_khz; in kvm_cpuid()
2070 * When leaf 0BH or 1FH is defined, CL is pass-through in kvm_cpuid()
2080 *edx = entry->edx; in kvm_cpuid()