Lines Matching +full:0 +full:x40000000 +full:- +full:0 +full:x4fffffff

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Kernel-based Virtual Machine driver for Linux
41 int feature_bit = 0; in xstate_required_size()
46 if (xstate_bv & 0x1) { in xstate_required_size()
48 cpuid_count(0xD, feature_bit, &eax, &ebx, &ecx, &edx); in xstate_required_size()
51 offset = (ecx & 0x2) ? ALIGN(ret, 64) : ret; in xstate_required_size()
66 /* Scattered Flag - For features that are scattered by cpufeatures.h. */
70 (boot_cpu_has(X86_FEATURE_##name) ? F(name) : 0); \
74 * Magic value used by KVM when querying userspace-provided CPUID entries and
80 #define KVM_CPUID_INDEX_NOT_SIGNIFICANT -1ull
89 * KVM has a semi-arbitrary rule that querying the guest's CPUID model in cpuid_entry2_find()
93 * path, e.g. the core VM-Enter/VM-Exit run loop. Nothing will break in cpuid_entry2_find()
100 for (i = 0; i < nent; i++) { in cpuid_entry2_find()
103 if (e->function != function) in cpuid_entry2_find()
111 if (!(e->flags & KVM_CPUID_FLAG_SIGNIFCANT_INDEX) || e->index == index) in cpuid_entry2_find()
141 * The existing code assumes virtual address is 48-bit or 57-bit in the in kvm_check_cpuid()
144 best = cpuid_entry2_find(entries, nent, 0x80000008, in kvm_check_cpuid()
147 int vaddr_bits = (best->eax & 0xff00) >> 8; in kvm_check_cpuid()
149 if (vaddr_bits != 48 && vaddr_bits != 57 && vaddr_bits != 0) in kvm_check_cpuid()
150 return -EINVAL; in kvm_check_cpuid()
157 best = cpuid_entry2_find(entries, nent, 0xd, 0); in kvm_check_cpuid()
159 return 0; in kvm_check_cpuid()
161 xfeatures = best->eax | ((u64)best->edx << 32); in kvm_check_cpuid()
164 return 0; in kvm_check_cpuid()
166 return fpu_enable_guest_xfd_features(&vcpu->arch.guest_fpu, xfeatures); in kvm_check_cpuid()
176 if (nent != vcpu->arch.cpuid_nent) in kvm_cpuid_check_equal()
177 return -EINVAL; in kvm_cpuid_check_equal()
179 for (i = 0; i < nent; i++) { in kvm_cpuid_check_equal()
180 orig = &vcpu->arch.cpuid_entries[i]; in kvm_cpuid_check_equal()
181 if (e2[i].function != orig->function || in kvm_cpuid_check_equal()
182 e2[i].index != orig->index || in kvm_cpuid_check_equal()
183 e2[i].flags != orig->flags || in kvm_cpuid_check_equal()
184 e2[i].eax != orig->eax || e2[i].ebx != orig->ebx || in kvm_cpuid_check_equal()
185 e2[i].ecx != orig->ecx || e2[i].edx != orig->edx) in kvm_cpuid_check_equal()
186 return -EINVAL; in kvm_cpuid_check_equal()
189 return 0; in kvm_cpuid_check_equal()
205 signature[0] = entry->ebx; in __kvm_get_hypervisor_cpuid()
206 signature[1] = entry->ecx; in __kvm_get_hypervisor_cpuid()
207 signature[2] = entry->edx; in __kvm_get_hypervisor_cpuid()
211 cpuid.limit = entry->eax; in __kvm_get_hypervisor_cpuid()
223 return __kvm_get_hypervisor_cpuid(vcpu->arch.cpuid_entries, in kvm_get_hypervisor_cpuid()
224 vcpu->arch.cpuid_nent, sig); in kvm_get_hypervisor_cpuid()
236 u32 base = vcpu->arch.kvm_cpuid.base; in kvm_find_kvm_cpuid_features()
241 return __kvm_find_kvm_cpuid_features(vcpu->arch.cpuid_entries, in kvm_find_kvm_cpuid_features()
242 vcpu->arch.cpuid_nent, base); in kvm_find_kvm_cpuid_features()
254 vcpu->arch.pv_cpuid.features = best->eax; in kvm_update_pv_runtime()
265 best = cpuid_entry2_find(entries, nent, 0xd, 0); in cpuid_get_supported_xcr0()
267 return 0; in cpuid_get_supported_xcr0()
269 return (best->eax | ((u64)best->edx << 32)) & kvm_caps.supported_xcr0; in cpuid_get_supported_xcr0()
286 vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE); in __kvm_update_cpuid_runtime()
289 best = cpuid_entry2_find(entries, nent, 7, 0); in __kvm_update_cpuid_runtime()
290 if (best && boot_cpu_has(X86_FEATURE_PKU) && best->function == 0x7) in __kvm_update_cpuid_runtime()
294 best = cpuid_entry2_find(entries, nent, 0xD, 0); in __kvm_update_cpuid_runtime()
296 best->ebx = xstate_required_size(vcpu->arch.xcr0, false); in __kvm_update_cpuid_runtime()
298 best = cpuid_entry2_find(entries, nent, 0xD, 1); in __kvm_update_cpuid_runtime()
301 best->ebx = xstate_required_size(vcpu->arch.xcr0, true); in __kvm_update_cpuid_runtime()
306 if (kvm_hlt_in_guest(vcpu->kvm) && best) in __kvm_update_cpuid_runtime()
307 best->eax &= ~(1 << KVM_FEATURE_PV_UNHALT); in __kvm_update_cpuid_runtime()
310 if (!kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT)) { in __kvm_update_cpuid_runtime()
311 best = cpuid_entry2_find(entries, nent, 0x1, KVM_CPUID_INDEX_NOT_SIGNIFICANT); in __kvm_update_cpuid_runtime()
314 vcpu->arch.ia32_misc_enable_msr & in __kvm_update_cpuid_runtime()
321 __kvm_update_cpuid_runtime(vcpu, vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent); in kvm_update_cpuid_runtime()
332 return entry && entry->eax == HYPERV_CPUID_SIGNATURE_EAX; in kvm_cpuid_has_hyperv()
342 entry = kvm_find_cpuid_entry(vcpu, 0); in guest_cpuid_is_amd_or_hygon()
346 return is_guest_vendor_amd(entry->ebx, entry->ecx, entry->edx) || in guest_cpuid_is_amd_or_hygon()
347 is_guest_vendor_hygon(entry->ebx, entry->ecx, entry->edx); in guest_cpuid_is_amd_or_hygon()
352 struct kvm_lapic *apic = vcpu->arch.apic; in kvm_vcpu_after_set_cpuid()
357 bitmap_zero(vcpu->arch.governed_features.enabled, in kvm_vcpu_after_set_cpuid()
363 * i.e. won't treat them as reserved, and KVM doesn't redo the GVA->GPA in kvm_vcpu_after_set_cpuid()
365 * _can't_ solve the problem because GVA->GPA walks aren't visible to in kvm_vcpu_after_set_cpuid()
379 apic->lapic_timer.timer_mode_mask = 3 << 17; in kvm_vcpu_after_set_cpuid()
381 apic->lapic_timer.timer_mode_mask = 1 << 17; in kvm_vcpu_after_set_cpuid()
386 vcpu->arch.guest_supported_xcr0 = in kvm_vcpu_after_set_cpuid()
387 cpuid_get_supported_xcr0(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent); in kvm_vcpu_after_set_cpuid()
391 vcpu->arch.is_amd_compatible = guest_cpuid_is_amd_or_hygon(vcpu); in kvm_vcpu_after_set_cpuid()
392 vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu); in kvm_vcpu_after_set_cpuid()
393 vcpu->arch.reserved_gpa_bits = kvm_vcpu_reserved_gpa_bits_raw(vcpu); in kvm_vcpu_after_set_cpuid()
396 vcpu->arch.cr4_guest_rsvd_bits = in kvm_vcpu_after_set_cpuid()
399 kvm_hv_set_cpuid(vcpu, kvm_cpuid_has_hyperv(vcpu->arch.cpuid_entries, in kvm_vcpu_after_set_cpuid()
400 vcpu->arch.cpuid_nent)); in kvm_vcpu_after_set_cpuid()
416 best = kvm_find_cpuid_entry(vcpu, 0x80000000); in cpuid_query_maxphyaddr()
417 if (!best || best->eax < 0x80000008) in cpuid_query_maxphyaddr()
419 best = kvm_find_cpuid_entry(vcpu, 0x80000008); in cpuid_query_maxphyaddr()
421 return best->eax & 0xff; in cpuid_query_maxphyaddr()
460 return 0; in kvm_set_cpuid()
475 kvfree(vcpu->arch.cpuid_entries); in kvm_set_cpuid()
476 vcpu->arch.cpuid_entries = e2; in kvm_set_cpuid()
477 vcpu->arch.cpuid_nent = nent; in kvm_set_cpuid()
479 vcpu->arch.kvm_cpuid = kvm_get_hypervisor_cpuid(vcpu, KVM_SIGNATURE); in kvm_set_cpuid()
481 vcpu->arch.xen.cpuid = kvm_get_hypervisor_cpuid(vcpu, XEN_SIGNATURE); in kvm_set_cpuid()
485 return 0; in kvm_set_cpuid()
497 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES) in kvm_vcpu_ioctl_set_cpuid()
498 return -E2BIG; in kvm_vcpu_ioctl_set_cpuid()
500 if (cpuid->nent) { in kvm_vcpu_ioctl_set_cpuid()
501 e = vmemdup_array_user(entries, cpuid->nent, sizeof(*e)); in kvm_vcpu_ioctl_set_cpuid()
505 e2 = kvmalloc_array(cpuid->nent, sizeof(*e2), GFP_KERNEL_ACCOUNT); in kvm_vcpu_ioctl_set_cpuid()
507 r = -ENOMEM; in kvm_vcpu_ioctl_set_cpuid()
511 for (i = 0; i < cpuid->nent; i++) { in kvm_vcpu_ioctl_set_cpuid()
517 e2[i].index = 0; in kvm_vcpu_ioctl_set_cpuid()
518 e2[i].flags = 0; in kvm_vcpu_ioctl_set_cpuid()
519 e2[i].padding[0] = 0; in kvm_vcpu_ioctl_set_cpuid()
520 e2[i].padding[1] = 0; in kvm_vcpu_ioctl_set_cpuid()
521 e2[i].padding[2] = 0; in kvm_vcpu_ioctl_set_cpuid()
524 r = kvm_set_cpuid(vcpu, e2, cpuid->nent); in kvm_vcpu_ioctl_set_cpuid()
541 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES) in kvm_vcpu_ioctl_set_cpuid2()
542 return -E2BIG; in kvm_vcpu_ioctl_set_cpuid2()
544 if (cpuid->nent) { in kvm_vcpu_ioctl_set_cpuid2()
545 e2 = vmemdup_array_user(entries, cpuid->nent, sizeof(*e2)); in kvm_vcpu_ioctl_set_cpuid2()
550 r = kvm_set_cpuid(vcpu, e2, cpuid->nent); in kvm_vcpu_ioctl_set_cpuid2()
561 if (cpuid->nent < vcpu->arch.cpuid_nent) in kvm_vcpu_ioctl_get_cpuid2()
562 return -E2BIG; in kvm_vcpu_ioctl_get_cpuid2()
564 if (copy_to_user(entries, vcpu->arch.cpuid_entries, in kvm_vcpu_ioctl_get_cpuid2()
565 vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2))) in kvm_vcpu_ioctl_get_cpuid2()
566 return -EFAULT; in kvm_vcpu_ioctl_get_cpuid2()
568 cpuid->nent = vcpu->arch.cpuid_nent; in kvm_vcpu_ioctl_get_cpuid2()
569 return 0; in kvm_vcpu_ioctl_get_cpuid2()
589 /* Use kvm_cpu_cap_mask for leafs that aren't KVM-only. */ in kvm_cpu_cap_init_kvm_defined()
599 /* Use kvm_cpu_cap_init_kvm_defined for KVM-only leafs. */ in kvm_cpu_cap_mask()
614 unsigned int f_gbpages = 0; in kvm_set_cpu_caps()
615 unsigned int f_lm = 0; in kvm_set_cpu_caps()
616 unsigned int f_xfd = 0; in kvm_set_cpu_caps()
618 memset(kvm_cpu_caps, 0, sizeof(kvm_cpu_caps)); in kvm_set_cpu_caps()
620 BUILD_BUG_ON(sizeof(kvm_cpu_caps) - (NKVMCAPINTS * sizeof(*kvm_cpu_caps)) > in kvm_set_cpu_caps()
624 sizeof(kvm_cpu_caps) - (NKVMCAPINTS * sizeof(*kvm_cpu_caps))); in kvm_set_cpu_caps()
631 F(XMM3) | F(PCLMULQDQ) | 0 /* DTES64, MONITOR */ | in kvm_set_cpu_caps()
632 0 /* DS-CPL, VMX, SMX, EST */ | in kvm_set_cpu_caps()
633 0 /* TM2 */ | F(SSSE3) | 0 /* CNXT-ID */ | 0 /* Reserved */ | in kvm_set_cpu_caps()
634 F(FMA) | F(CX16) | 0 /* xTPR Update */ | F(PDCM) | in kvm_set_cpu_caps()
635 F(PCID) | 0 /* Reserved, DCA */ | F(XMM4_1) | in kvm_set_cpu_caps()
637 0 /* Reserved*/ | F(AES) | F(XSAVE) | 0 /* OSXSAVE */ | F(AVX) | in kvm_set_cpu_caps()
646 F(CX8) | F(APIC) | 0 /* Reserved */ | F(SEP) | in kvm_set_cpu_caps()
648 F(PAT) | F(PSE36) | 0 /* PSN */ | F(CLFLUSH) | in kvm_set_cpu_caps()
649 0 /* Reserved, DS, ACPI */ | F(MMX) | in kvm_set_cpu_caps()
651 0 /* HTT, TM, Reserved, PBE */ in kvm_set_cpu_caps()
657 F(RTM) | F(ZERO_FCS_FDS) | 0 /*MPX*/ | F(AVX512F) | in kvm_set_cpu_caps()
659 F(CLFLUSHOPT) | F(CLWB) | 0 /*INTEL_PT*/ | F(AVX512PF) | in kvm_set_cpu_caps()
664 F(AVX512VBMI) | F(LA57) | F(PKU) | 0 /*OSPKE*/ | F(RDPID) | in kvm_set_cpu_caps()
667 F(CLDEMOTE) | F(MOVDIRI) | F(MOVDIR64B) | 0 /*WAITPKG*/ | in kvm_set_cpu_caps()
729 F(LAHF_LM) | F(CMP_LEGACY) | 0 /*SVM*/ | 0 /* ExtApicSpace */ | in kvm_set_cpu_caps()
731 F(3DNOWPREFETCH) | F(OSVW) | 0 /* IBS */ | F(XOP) | in kvm_set_cpu_caps()
732 0 /* SKINIT, WDT, LWP */ | F(FMA4) | F(TBM) | in kvm_set_cpu_caps()
733 F(TOPOEXT) | 0 /* PERFCTR_CORE */ in kvm_set_cpu_caps()
739 F(CX8) | F(APIC) | 0 /* Reserved */ | F(SYSCALL) | in kvm_set_cpu_caps()
741 F(PAT) | F(PSE36) | 0 /* Reserved */ | in kvm_set_cpu_caps()
742 F(NX) | 0 /* Reserved */ | F(MMXEXT) | F(MMX) | in kvm_set_cpu_caps()
744 0 /* Reserved */ | f_lm | F(3DNOWEXT) | F(3DNOW) in kvm_set_cpu_caps()
788 kvm_cpu_cap_mask(CPUID_8000_000A_EDX, 0); in kvm_set_cpu_caps()
791 0 /* SME */ | 0 /* SEV */ | 0 /* VM_PAGE_FLUSH */ | 0 /* SEV_ES */ | in kvm_set_cpu_caps()
795 F(NO_NESTED_DATA_BP) | F(LFENCE_RDTSC) | 0 /* SmmPgCfgLock */ | in kvm_set_cpu_caps()
796 F(NULL_SEL_CLR_BASE) | F(AUTOIBRS) | 0 /* PrefetchCtlMsr */ | in kvm_set_cpu_caps()
809 * Synthesize "LFENCE is serializing" into the AMD-defined entry in in kvm_set_cpu_caps()
811 * kernel. LFENCE_RDTSC was a Linux-defined synthetic feature long in kvm_set_cpu_caps()
855 if (array->nent >= array->maxnent) in get_next_cpuid()
858 return &array->entries[array->nent++]; in get_next_cpuid()
869 memset(entry, 0, sizeof(*entry)); in do_host_cpuid()
870 entry->function = function; in do_host_cpuid()
871 entry->index = index; in do_host_cpuid()
872 switch (function & 0xC0000000) { in do_host_cpuid()
873 case 0x40000000: in do_host_cpuid()
877 case 0x80000000: in do_host_cpuid()
879 * 0x80000021 is sometimes synthesized by __do_cpuid_func, which in do_host_cpuid()
880 * would result in out-of-bounds calls to do_host_cpuid. in do_host_cpuid()
885 WRITE_ONCE(max_cpuid_80000000, cpuid_eax(0x80000000)); in do_host_cpuid()
895 cpuid_count(entry->function, entry->index, in do_host_cpuid()
896 &entry->eax, &entry->ebx, &entry->ecx, &entry->edx); in do_host_cpuid()
899 entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; in do_host_cpuid()
908 if (array->nent >= array->maxnent) in __do_cpuid_func_emulated()
909 return -E2BIG; in __do_cpuid_func_emulated()
911 entry = &array->entries[array->nent]; in __do_cpuid_func_emulated()
912 entry->function = func; in __do_cpuid_func_emulated()
913 entry->index = 0; in __do_cpuid_func_emulated()
914 entry->flags = 0; in __do_cpuid_func_emulated()
917 case 0: in __do_cpuid_func_emulated()
918 entry->eax = 7; in __do_cpuid_func_emulated()
919 ++array->nent; in __do_cpuid_func_emulated()
922 entry->ecx = F(MOVBE); in __do_cpuid_func_emulated()
923 ++array->nent; in __do_cpuid_func_emulated()
926 entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; in __do_cpuid_func_emulated()
927 entry->eax = 0; in __do_cpuid_func_emulated()
929 entry->ecx = F(RDPID); in __do_cpuid_func_emulated()
930 ++array->nent; in __do_cpuid_func_emulated()
936 return 0; in __do_cpuid_func_emulated()
947 r = -E2BIG; in __do_cpuid_func()
949 entry = do_host_cpuid(array, function, 0); in __do_cpuid_func()
954 case 0: in __do_cpuid_func()
956 entry->eax = min(entry->eax, 0x24U); in __do_cpuid_func()
965 * CPUID(function=2, index=0) may return different results each in __do_cpuid_func()
966 * time, with the least-significant byte in EAX enumerating the in __do_cpuid_func()
967 * number of times software should do CPUID(2, 0). in __do_cpuid_func()
970 * idiotic. Intel's SDM states that EAX & 0xff "will always in __do_cpuid_func()
976 * a stateful CPUID.0x2 is encountered. in __do_cpuid_func()
978 WARN_ON_ONCE((entry->eax & 0xff) > 1); in __do_cpuid_func()
980 /* functions 4 and 0x8000001d have additional index. */ in __do_cpuid_func()
982 case 0x8000001d: in __do_cpuid_func()
987 for (i = 1; entry->eax & 0x1f; ++i) { in __do_cpuid_func()
994 entry->eax = 0x4; /* allow ARAT */ in __do_cpuid_func()
995 entry->ebx = 0; in __do_cpuid_func()
996 entry->ecx = 0; in __do_cpuid_func()
997 entry->edx = 0; in __do_cpuid_func()
1001 max_idx = entry->eax = min(entry->eax, 2u); in __do_cpuid_func()
1006 /* KVM only supports up to 0x7.2, capped above via min(). */ in __do_cpuid_func()
1014 entry->ebx = 0; in __do_cpuid_func()
1015 entry->ecx = 0; in __do_cpuid_func()
1023 entry->ecx = 0; in __do_cpuid_func()
1024 entry->ebx = 0; in __do_cpuid_func()
1025 entry->eax = 0; in __do_cpuid_func()
1028 case 0xa: { /* Architectural Performance Monitoring */ in __do_cpuid_func()
1033 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1046 edx.split.reserved1 = 0; in __do_cpuid_func()
1047 edx.split.reserved2 = 0; in __do_cpuid_func()
1049 entry->eax = eax.full; in __do_cpuid_func()
1050 entry->ebx = kvm_pmu_cap.events_mask; in __do_cpuid_func()
1051 entry->ecx = 0; in __do_cpuid_func()
1052 entry->edx = edx.full; in __do_cpuid_func()
1055 case 0x1f: in __do_cpuid_func()
1056 case 0xb: in __do_cpuid_func()
1061 entry->eax = entry->ebx = entry->ecx = 0; in __do_cpuid_func()
1063 case 0xd: { in __do_cpuid_func()
1067 entry->eax &= permitted_xcr0; in __do_cpuid_func()
1068 entry->ebx = xstate_required_size(permitted_xcr0, false); in __do_cpuid_func()
1069 entry->ecx = entry->ebx; in __do_cpuid_func()
1070 entry->edx &= permitted_xcr0 >> 32; in __do_cpuid_func()
1079 if (entry->eax & (F(XSAVES)|F(XSAVEC))) in __do_cpuid_func()
1080 entry->ebx = xstate_required_size(permitted_xcr0 | permitted_xss, in __do_cpuid_func()
1083 WARN_ON_ONCE(permitted_xss != 0); in __do_cpuid_func()
1084 entry->ebx = 0; in __do_cpuid_func()
1086 entry->ecx &= permitted_xss; in __do_cpuid_func()
1087 entry->edx &= permitted_xss >> 32; in __do_cpuid_func()
1104 * invalid sub-leafs. Only valid sub-leafs should in __do_cpuid_func()
1105 * reach this point, and they should have a non-zero in __do_cpuid_func()
1108 * on whether this is an XCR0- or IA32_XSS-managed area. in __do_cpuid_func()
1110 if (WARN_ON_ONCE(!entry->eax || (entry->ecx & 0x1) != s_state)) { in __do_cpuid_func()
1111 --array->nent; in __do_cpuid_func()
1116 entry->ecx &= ~BIT_ULL(2); in __do_cpuid_func()
1117 entry->edx = 0; in __do_cpuid_func()
1121 case 0x12: in __do_cpuid_func()
1124 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1129 * Index 0: Sub-features, MISCSELECT (a.k.a extended features) in __do_cpuid_func()
1130 * and max enclave sizes. The SGX sub-features and MISCSELECT in __do_cpuid_func()
1135 entry->ebx &= SGX_MISC_EXINFO; in __do_cpuid_func()
1144 * privileged attributes that require explicit opt-in from in __do_cpuid_func()
1148 entry->eax &= SGX_ATTR_PRIV_MASK | SGX_ATTR_UNPRIV_MASK; in __do_cpuid_func()
1149 entry->ebx &= 0; in __do_cpuid_func()
1152 case 0x14: in __do_cpuid_func()
1154 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1158 for (i = 1, max_idx = entry->eax; i <= max_idx; ++i) { in __do_cpuid_func()
1164 case 0x1d: in __do_cpuid_func()
1166 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1170 for (i = 1, max_idx = entry->eax; i <= max_idx; ++i) { in __do_cpuid_func()
1175 case 0x1e: /* TMUL information */ in __do_cpuid_func()
1177 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1181 case 0x24: { in __do_cpuid_func()
1185 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1190 * The AVX10 version is encoded in EBX[7:0]. Note, the version in __do_cpuid_func()
1194 avx10_version = min_t(u8, entry->ebx & 0xff, 1); in __do_cpuid_func()
1196 entry->ebx |= avx10_version; in __do_cpuid_func()
1198 entry->eax = 0; in __do_cpuid_func()
1199 entry->ecx = 0; in __do_cpuid_func()
1200 entry->edx = 0; in __do_cpuid_func()
1205 entry->eax = KVM_CPUID_FEATURES; in __do_cpuid_func()
1206 entry->ebx = sigptr[0]; in __do_cpuid_func()
1207 entry->ecx = sigptr[1]; in __do_cpuid_func()
1208 entry->edx = sigptr[2]; in __do_cpuid_func()
1212 entry->eax = (1 << KVM_FEATURE_CLOCKSOURCE) | in __do_cpuid_func()
1227 entry->eax |= (1 << KVM_FEATURE_STEAL_TIME); in __do_cpuid_func()
1229 entry->ebx = 0; in __do_cpuid_func()
1230 entry->ecx = 0; in __do_cpuid_func()
1231 entry->edx = 0; in __do_cpuid_func()
1233 case 0x80000000: in __do_cpuid_func()
1234 entry->eax = min(entry->eax, 0x80000022); in __do_cpuid_func()
1240 * However, only do it if the host has CPUID leaf 0x8000001d. in __do_cpuid_func()
1242 * CPUID leaf if KVM reports that it supports 0x8000001d or in __do_cpuid_func()
1245 * 0x8000001d. Even worse, this can result in an infinite in __do_cpuid_func()
1248 if (entry->eax >= 0x8000001d && in __do_cpuid_func()
1251 entry->eax = max(entry->eax, 0x80000021); in __do_cpuid_func()
1253 case 0x80000001: in __do_cpuid_func()
1254 entry->ebx &= ~GENMASK(27, 16); in __do_cpuid_func()
1258 case 0x80000005: in __do_cpuid_func()
1261 case 0x80000006: in __do_cpuid_func()
1263 entry->edx &= ~GENMASK(17, 16); in __do_cpuid_func()
1265 case 0x80000007: /* Advanced power management */ in __do_cpuid_func()
1269 entry->edx &= boot_cpu_data.x86_power; in __do_cpuid_func()
1270 entry->eax = entry->ebx = entry->ecx = 0; in __do_cpuid_func()
1272 case 0x80000008: { in __do_cpuid_func()
1285 * support 5-level TDP. in __do_cpuid_func()
1287 unsigned int virt_as = max((entry->eax >> 8) & 0xff, 48U); in __do_cpuid_func()
1299 * that it's capped at 48 bits if 5-level TDP isn't supported in __do_cpuid_func()
1305 g_phys_as = 0; in __do_cpuid_func()
1307 phys_as = entry->eax & 0xff; in __do_cpuid_func()
1313 entry->eax = phys_as | (virt_as << 8) | (g_phys_as << 16); in __do_cpuid_func()
1314 entry->ecx &= ~(GENMASK(31, 16) | GENMASK(11, 8)); in __do_cpuid_func()
1315 entry->edx = 0; in __do_cpuid_func()
1319 case 0x8000000A: in __do_cpuid_func()
1321 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1324 entry->eax = 1; /* SVM revision 1 */ in __do_cpuid_func()
1325 entry->ebx = 8; /* Lets support 8 ASIDs in case we add proper in __do_cpuid_func()
1327 entry->ecx = 0; /* Reserved */ in __do_cpuid_func()
1330 case 0x80000019: in __do_cpuid_func()
1331 entry->ecx = entry->edx = 0; in __do_cpuid_func()
1333 case 0x8000001a: in __do_cpuid_func()
1334 entry->eax &= GENMASK(2, 0); in __do_cpuid_func()
1335 entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1337 case 0x8000001e: in __do_cpuid_func()
1339 entry->eax = entry->ebx = entry->ecx = 0; in __do_cpuid_func()
1340 entry->edx = 0; /* reserved */ in __do_cpuid_func()
1342 case 0x8000001F: in __do_cpuid_func()
1344 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1348 entry->ebx &= ~GENMASK(31, 12); in __do_cpuid_func()
1350 * Enumerate '0' for "PA bits reduction", the adjusted in __do_cpuid_func()
1351 * MAXPHYADDR is enumerated directly (see 0x80000008). in __do_cpuid_func()
1353 entry->ebx &= ~GENMASK(11, 6); in __do_cpuid_func()
1356 case 0x80000020: in __do_cpuid_func()
1357 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1359 case 0x80000021: in __do_cpuid_func()
1360 entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1364 case 0x80000022: { in __do_cpuid_func()
1367 entry->ecx = entry->edx = 0; in __do_cpuid_func()
1369 entry->eax = entry->ebx; in __do_cpuid_func()
1382 entry->ebx = ebx.full; in __do_cpuid_func()
1386 case 0xC0000000: in __do_cpuid_func()
1387 /*Just support up to 0xC0000004 now*/ in __do_cpuid_func()
1388 entry->eax = min(entry->eax, 0xC0000004); in __do_cpuid_func()
1390 case 0xC0000001: in __do_cpuid_func()
1395 case 0xC0000002: in __do_cpuid_func()
1396 case 0xC0000003: in __do_cpuid_func()
1397 case 0xC0000004: in __do_cpuid_func()
1399 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1403 r = 0; in __do_cpuid_func()
1420 #define CENTAUR_CPUID_SIGNATURE 0xC0000000
1430 return 0; in get_cpuid_func()
1436 limit = array->entries[array->nent - 1].eax; in get_cpuid_func()
1456 * We want to make sure that ->padding is being passed clean from in sanity_check_entries()
1463 for (i = 0; i < num_entries; i++) { in sanity_check_entries()
1467 if (pad[0] || pad[1] || pad[2]) in sanity_check_entries()
1478 0, 0x80000000, CENTAUR_CPUID_SIGNATURE, KVM_CPUID_SIGNATURE, in kvm_dev_ioctl_get_cpuid()
1482 .nent = 0, in kvm_dev_ioctl_get_cpuid()
1486 if (cpuid->nent < 1) in kvm_dev_ioctl_get_cpuid()
1487 return -E2BIG; in kvm_dev_ioctl_get_cpuid()
1488 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES) in kvm_dev_ioctl_get_cpuid()
1489 cpuid->nent = KVM_MAX_CPUID_ENTRIES; in kvm_dev_ioctl_get_cpuid()
1491 if (sanity_check_entries(entries, cpuid->nent, type)) in kvm_dev_ioctl_get_cpuid()
1492 return -EINVAL; in kvm_dev_ioctl_get_cpuid()
1494 array.entries = kvcalloc(cpuid->nent, sizeof(struct kvm_cpuid_entry2), GFP_KERNEL); in kvm_dev_ioctl_get_cpuid()
1496 return -ENOMEM; in kvm_dev_ioctl_get_cpuid()
1498 array.maxnent = cpuid->nent; in kvm_dev_ioctl_get_cpuid()
1500 for (i = 0; i < ARRAY_SIZE(funcs); i++) { in kvm_dev_ioctl_get_cpuid()
1505 cpuid->nent = array.nent; in kvm_dev_ioctl_get_cpuid()
1509 r = -EFAULT; in kvm_dev_ioctl_get_cpuid()
1519 return cpuid_entry2_find(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent, in kvm_find_cpuid_entry_index()
1527 return cpuid_entry2_find(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent, in kvm_find_cpuid_entry()
1533 * Intel CPUID semantics treats any query for an out-of-range leaf as if the
1534 * highest basic leaf (i.e. CPUID.0H:EAX) were requested. AMD CPUID semantics
1538 * A leaf is considered out-of-range if its function is higher than the maximum
1543 * ranges described as "<base> - <top>[,<base2> - <top2>] inclusive. A primary
1547 * - Basic: 0x00000000 - 0x3fffffff, 0x50000000 - 0x7fffffff
1548 * - Hypervisor: 0x40000000 - 0x4fffffff
1549 * - Extended: 0x80000000 - 0xbfffffff
1550 * - Centaur: 0xc0000000 - 0xcfffffff
1552 * The Hypervisor class is further subdivided into sub-classes that each act as
1553 * their own independent class associated with a 0x100 byte range. E.g. if Qemu
1555 * CPUID sub-classes are:
1557 * - HyperV: 0x40000000 - 0x400000ff
1558 * - KVM: 0x40000100 - 0x400001ff
1566 basic = kvm_find_cpuid_entry(vcpu, 0); in get_out_of_range_cpuid_entry()
1570 if (is_guest_vendor_amd(basic->ebx, basic->ecx, basic->edx) || in get_out_of_range_cpuid_entry()
1571 is_guest_vendor_hygon(basic->ebx, basic->ecx, basic->edx)) in get_out_of_range_cpuid_entry()
1574 if (function >= 0x40000000 && function <= 0x4fffffff) in get_out_of_range_cpuid_entry()
1575 class = kvm_find_cpuid_entry(vcpu, function & 0xffffff00); in get_out_of_range_cpuid_entry()
1576 else if (function >= 0xc0000000) in get_out_of_range_cpuid_entry()
1577 class = kvm_find_cpuid_entry(vcpu, 0xc0000000); in get_out_of_range_cpuid_entry()
1579 class = kvm_find_cpuid_entry(vcpu, function & 0x80000000); in get_out_of_range_cpuid_entry()
1581 if (class && function <= class->eax) in get_out_of_range_cpuid_entry()
1586 * max basic entry, e.g. if the max basic leaf is 0xb but there is no in get_out_of_range_cpuid_entry()
1587 * entry for CPUID.0xb.index (see below), then the output value for EDX in get_out_of_range_cpuid_entry()
1588 * needs to be pulled from CPUID.0xb.1. in get_out_of_range_cpuid_entry()
1590 *fn_ptr = basic->eax; in get_out_of_range_cpuid_entry()
1597 return kvm_find_cpuid_entry_index(vcpu, basic->eax, index); in get_out_of_range_cpuid_entry()
1616 *eax = entry->eax; in kvm_cpuid()
1617 *ebx = entry->ebx; in kvm_cpuid()
1618 *ecx = entry->ecx; in kvm_cpuid()
1619 *edx = entry->edx; in kvm_cpuid()
1620 if (function == 7 && index == 0) { in kvm_cpuid()
1625 } else if (function == 0x80000007) { in kvm_cpuid()
1630 *eax = *ebx = *ecx = *edx = 0; in kvm_cpuid()
1632 * When leaf 0BH or 1FH is defined, CL is pass-through in kvm_cpuid()
1638 if (function == 0xb || function == 0x1f) { in kvm_cpuid()
1641 *ecx = index & 0xff; in kvm_cpuid()
1642 *edx = entry->edx; in kvm_cpuid()
1656 if (cpuid_fault_enabled(vcpu) && !kvm_require_cpl(vcpu, 0)) in kvm_emulate_cpuid()