Lines Matching +full:guest +full:- +full:index +full:- +full:bits

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()
85 struct kvm_cpuid_entry2 *entries, int nent, u32 function, u64 index) in kvm_find_cpuid_entry2() argument
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()
109 * If the index isn't significant, use the first entry with a in kvm_find_cpuid_entry2()
113 if (!(e->flags & KVM_CPUID_FLAG_SIGNIFCANT_INDEX) || e->index == index) in kvm_find_cpuid_entry2()
120 * architecturally defined as not having a significant index. in kvm_find_cpuid_entry2()
122 if (index == KVM_CPUID_INDEX_NOT_SIGNIFICANT) { 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()
154 * Exposing dynamic xfeatures to the guest requires additional in kvm_check_cpuid()
155 * enabling in the FPU, e.g. to expand the guest XSAVE state size. 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()
252 * Calculate guest's supported XCR0 taking into account guest CPUID data and
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()
384 * Reset guest capabilities to userspace's guest CPUID definition, i.e. in kvm_vcpu_after_set_cpuid()
395 entry = kvm_find_cpuid_entry_index(vcpu, cpuid.function, cpuid.index); in kvm_vcpu_after_set_cpuid()
403 * in guest CPUID. Note, this includes features that are 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()
414 * If TDP is enabled, let the guest use GBPAGES if they're supported in 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()
421 * If TDP is disabled, honor *only* guest CPUID as KVM has full control 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()
450 vcpu->arch.cr4_guest_rsvd_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_) | in kvm_vcpu_after_set_cpuid()
461 * adjustments to the reserved GPA bits. 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()
497 * This "raw" version returns the reserved GPA bits without any adjustments for
498 * encryption technologies that usurp bits. The raw mask should be used if and
499 * only if hardware does _not_ strip the usurped bits, e.g. in virtual MTRRs.
514 * order to massage the new entries, e.g. to account for dynamic bits in kvm_set_cpuid()
515 * that KVM controls, without clobbering the current guest CPUID, which in kvm_set_cpuid()
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()
530 * KVM does not correctly handle changing guest CPUID after KVM_RUN, as in kvm_set_cpuid()
532 * tracked in kvm_mmu_page_role. As a result, KVM may miss guest page 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()
604 e2[i].index = 0; 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()
679 cpuid_count(cpuid.function, cpuid.index, in raw_cpuid_get()
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
731 /* Scattered Flag - For features that are scattered by cpufeatures.h. */
740 /* Features that KVM supports only on 64-bit kernels. */
749 * Emulated Feature - For features that KVM emulates in software irrespective
759 * Synthesized Feature - For features that are synthesized into boot_cpu_data,
770 * Passthrough Feature - For features that KVM supports based purely on raw
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()
837 /* DS-CPL */ in kvm_set_cpu_caps()
842 /* CNXT-ID */ in kvm_set_cpu_caps()
1143 * AMD has separate bits for each SPEC_CTRL bit. 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()
1252 * should never happen, but the guest will likely crash if RDTSCP or in kvm_set_cpu_caps()
1284 if (array->nent >= array->maxnent) in get_next_cpuid()
1287 return &array->entries[array->nent++]; in get_next_cpuid()
1291 u32 function, u32 index) in do_host_cpuid() argument
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()
1350 * the guest, but the MWAIT feature flag is never advertised in cpuid_func_emulated()
1353 * emulates them as NOPs), and allowing the guest to execute 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()
1405 * CPUID(function=2, index=0) may return different results each 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()
1420 /* functions 4 and 0x8000001d have additional index. */ 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()
1439 /* function 7 has additional index. */ 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()
1580 * Index 1: SECS.ATTRIBUTES. ATTRIBUTES are restricted a la 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()
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()
1682 * highest Intel leaf which QEMU tries to use as the guest's 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()
1700 /* Drop reserved bits, pass host L2 cache and TLB info. */ 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()
1716 * guest in PhysAddrSize (phys_as), and the maximum in __do_cpuid_func()
1722 * the guest, e.g. if MAXPHYADDR>48 but the CPU doesn't 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()
1730 * the guest operates in the same PA space as the host, i.e. in __do_cpuid_func()
1737 * that it's capped at 48 bits if 5-level TDP isn't supported in __do_cpuid_func()
1738 * (hardware processes bits 51:48 only when walking the fifth 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()
1788 * Enumerate '0' for "PA bits reduction", the adjusted 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
1962 * class exists if a guest CPUID entry for its <base> leaf exists. For a given
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
1979 get_out_of_range_cpuid_entry(struct kvm_vcpu *vcpu, u32 *fn_ptr, u32 index) in get_out_of_range_cpuid_entry() argument
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()
2005 * entry for CPUID.0xb.index (see below), then the output value for EDX in get_out_of_range_cpuid_entry()
2008 *fn_ptr = basic->eax; in get_out_of_range_cpuid_entry()
2012 * the effective CPUID entry is the max basic leaf. Note, the index of 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()
2021 u32 orig_function = *eax, function = *eax, index = *ecx; in kvm_cpuid() local
2025 if (vcpu->arch.cpuid_dynamic_bits_dirty) in kvm_cpuid()
2028 entry = kvm_find_cpuid_entry_index(vcpu, function, index); in kvm_cpuid()
2032 entry = get_out_of_range_cpuid_entry(vcpu, &function, index); 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()
2041 if (function == 7 && index == 0) { in kvm_cpuid()
2053 * Update guest TSC frequency information if necessary. in kvm_cpuid()
2060 if (index == 1) { in kvm_cpuid()
2061 *ecx = vcpu->arch.pvclock_tsc_mul; in kvm_cpuid()
2062 *edx = vcpu->arch.pvclock_tsc_shift; in kvm_cpuid()
2063 } else if (index == 2) { 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()
2072 * subleaves. Index 1 will exist iff the leaf is in kvm_cpuid()
2074 * exists. EDX can be copied from any existing index. in kvm_cpuid()
2079 *ecx = index & 0xff; in kvm_cpuid()
2080 *edx = entry->edx; in kvm_cpuid()
2084 trace_kvm_cpuid(orig_function, index, *eax, *ebx, *ecx, *edx, exact, in kvm_cpuid()