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()
72 offset = (xs->ecx & 0x2) ? ALIGN(ret, 64) : ret; in xstate_required_size()
74 offset = xs->ebx; in xstate_required_size()
75 ret = max(ret, offset + xs->eax); in xstate_required_size()
86 * Magic value used by KVM when querying userspace-provided CPUID entries and
87 * doesn't care about the CPIUD index because the index of the function in
89 * bit set in bits[63:32] and must be consumed as a u64 by cpuid_entry2_find()
90 * to avoid false positives when processing guest CPUID input.
92 #define KVM_CPUID_INDEX_NOT_SIGNIFICANT -1ull
95 u32 function, u64 index) in cpuid_entry2_find() argument
101 * KVM has a semi-arbitrary rule that querying the guest's CPUID model in cpuid_entry2_find()
105 * path, e.g. the core VM-Enter/VM-Exit run loop. Nothing will break in cpuid_entry2_find()
112 for (i = 0; i < vcpu->arch.cpuid_nent; i++) { in cpuid_entry2_find()
113 e = &vcpu->arch.cpuid_entries[i]; in cpuid_entry2_find()
115 if (e->function != function) in cpuid_entry2_find()
119 * If the index isn't significant, use the first entry with a in cpuid_entry2_find()
123 if (!(e->flags & KVM_CPUID_FLAG_SIGNIFCANT_INDEX) || e->index == index) in cpuid_entry2_find()
130 * architecturally defined as not having a significant index. in cpuid_entry2_find()
132 if (index == KVM_CPUID_INDEX_NOT_SIGNIFICANT) { in cpuid_entry2_find()
146 u32 function, u32 index) in kvm_find_cpuid_entry_index() argument
148 return cpuid_entry2_find(vcpu, function, index); in kvm_find_cpuid_entry_index()
171 * The existing code assumes virtual address is 48-bit or 57-bit in the in kvm_check_cpuid()
176 int vaddr_bits = (best->eax & 0xff00) >> 8; in kvm_check_cpuid()
179 return -EINVAL; in kvm_check_cpuid()
183 * Exposing dynamic xfeatures to the guest requires additional in kvm_check_cpuid()
184 * enabling in the FPU, e.g. to expand the guest XSAVE state size. in kvm_check_cpuid()
190 xfeatures = best->eax | ((u64)best->edx << 32); in kvm_check_cpuid()
195 return fpu_enable_guest_xfd_features(&vcpu->arch.guest_fpu, xfeatures); in kvm_check_cpuid()
209 * false positives due mismatches on KVM-owned feature flags. in kvm_cpuid_check_equal()
216 if (nent != vcpu->arch.cpuid_nent) in kvm_cpuid_check_equal()
217 return -EINVAL; in kvm_cpuid_check_equal()
220 orig = &vcpu->arch.cpuid_entries[i]; in kvm_cpuid_check_equal()
221 if (e2[i].function != orig->function || in kvm_cpuid_check_equal()
222 e2[i].index != orig->index || in kvm_cpuid_check_equal()
223 e2[i].flags != orig->flags || in kvm_cpuid_check_equal()
224 e2[i].eax != orig->eax || e2[i].ebx != orig->ebx || in kvm_cpuid_check_equal()
225 e2[i].ecx != orig->ecx || e2[i].edx != orig->edx) in kvm_cpuid_check_equal()
226 return -EINVAL; in kvm_cpuid_check_equal()
245 signature[0] = entry->ebx; in kvm_get_hypervisor_cpuid()
246 signature[1] = entry->ecx; in kvm_get_hypervisor_cpuid()
247 signature[2] = entry->edx; in kvm_get_hypervisor_cpuid()
251 cpuid.limit = entry->eax; in kvm_get_hypervisor_cpuid()
273 if (kvm_hlt_in_guest(vcpu->kvm)) in kvm_apply_cpuid_pv_features_quirk()
274 best->eax &= ~(1 << KVM_FEATURE_PV_UNHALT); in kvm_apply_cpuid_pv_features_quirk()
276 return best->eax; in kvm_apply_cpuid_pv_features_quirk()
280 * Calculate guest's supported XCR0 taking into account guest CPUID data and
291 return (best->eax | ((u64)best->edx << 32)) & kvm_caps.supported_xcr0; in cpuid_get_supported_xcr0()
313 vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE); in kvm_update_cpuid_runtime()
315 if (!kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT)) in kvm_update_cpuid_runtime()
317 vcpu->arch.ia32_misc_enable_msr & in kvm_update_cpuid_runtime()
329 best->ebx = xstate_required_size(vcpu->arch.xcr0, false); in kvm_update_cpuid_runtime()
334 best->ebx = xstate_required_size(vcpu->arch.xcr0, true); in kvm_update_cpuid_runtime()
344 return entry && entry->eax == HYPERV_CPUID_SIGNATURE_EAX; in kvm_cpuid_has_hyperv()
358 return is_guest_vendor_amd(entry->ebx, entry->ecx, entry->edx) || in guest_cpuid_is_amd_or_hygon()
359 is_guest_vendor_hygon(entry->ebx, entry->ecx, entry->edx); in guest_cpuid_is_amd_or_hygon()
365 * compile-time validation of the input.
371 return entry->eax; in cpuid_get_reg_unsafe()
373 return entry->ebx; in cpuid_get_reg_unsafe()
375 return entry->ecx; in cpuid_get_reg_unsafe()
377 return entry->edx; in cpuid_get_reg_unsafe()
389 struct kvm_lapic *apic = vcpu->arch.apic; in kvm_vcpu_after_set_cpuid()
395 memset(vcpu->arch.cpu_caps, 0, sizeof(vcpu->arch.cpu_caps)); in kvm_vcpu_after_set_cpuid()
399 * Reset guest capabilities to userspace's guest CPUID definition, i.e. in kvm_vcpu_after_set_cpuid()
410 entry = kvm_find_cpuid_entry_index(vcpu, cpuid.function, cpuid.index); in kvm_vcpu_after_set_cpuid()
418 * in guest CPUID. Note, this includes features that are in kvm_vcpu_after_set_cpuid()
421 vcpu->arch.cpu_caps[i] = kvm_cpu_caps[i] | in kvm_vcpu_after_set_cpuid()
423 vcpu->arch.cpu_caps[i] &= cpuid_get_reg_unsafe(entry, cpuid.reg); in kvm_vcpu_after_set_cpuid()
429 * If TDP is enabled, let the guest use GBPAGES if they're supported in in kvm_vcpu_after_set_cpuid()
431 * i.e. won't treat them as reserved, and KVM doesn't redo the GVA->GPA in kvm_vcpu_after_set_cpuid()
433 * _can't_ solve the problem because GVA->GPA walks aren't visible to in kvm_vcpu_after_set_cpuid()
436 * If TDP is disabled, honor *only* guest CPUID as KVM has full control in kvm_vcpu_after_set_cpuid()
446 apic->lapic_timer.timer_mode_mask = 3 << 17; in kvm_vcpu_after_set_cpuid()
448 apic->lapic_timer.timer_mode_mask = 1 << 17; in kvm_vcpu_after_set_cpuid()
453 vcpu->arch.guest_supported_xcr0 = cpuid_get_supported_xcr0(vcpu); in kvm_vcpu_after_set_cpuid()
455 vcpu->arch.pv_cpuid.features = kvm_apply_cpuid_pv_features_quirk(vcpu); in kvm_vcpu_after_set_cpuid()
457 vcpu->arch.is_amd_compatible = guest_cpuid_is_amd_or_hygon(vcpu); in kvm_vcpu_after_set_cpuid()
458 vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu); in kvm_vcpu_after_set_cpuid()
459 vcpu->arch.reserved_gpa_bits = kvm_vcpu_reserved_gpa_bits_raw(vcpu); in kvm_vcpu_after_set_cpuid()
464 vcpu->arch.cr4_guest_rsvd_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_) | in kvm_vcpu_after_set_cpuid()
475 * adjustments to the reserved GPA bits. in kvm_vcpu_after_set_cpuid()
485 if (!best || best->eax < 0x80000008) in cpuid_query_maxphyaddr()
489 return best->eax & 0xff; in cpuid_query_maxphyaddr()
495 * This "raw" version returns the reserved GPA bits without any adjustments for
496 * encryption technologies that usurp bits. The raw mask should be used if and
497 * only if hardware does _not_ strip the usurped bits, e.g. in virtual MTRRs.
512 * order to massage the new entries, e.g. to account for dynamic bits in kvm_set_cpuid()
513 * that KVM controls, without clobbering the current guest CPUID, which in kvm_set_cpuid()
521 swap(vcpu->arch.cpuid_entries, e2); in kvm_set_cpuid()
522 swap(vcpu->arch.cpuid_nent, nent); in kvm_set_cpuid()
524 memcpy(vcpu_caps, vcpu->arch.cpu_caps, sizeof(vcpu_caps)); in kvm_set_cpuid()
525 BUILD_BUG_ON(sizeof(vcpu_caps) != sizeof(vcpu->arch.cpu_caps)); in kvm_set_cpuid()
528 * KVM does not correctly handle changing guest CPUID after KVM_RUN, as in kvm_set_cpuid()
530 * tracked in kvm_mmu_page_role. As a result, KVM may miss guest page in kvm_set_cpuid()
558 vcpu->arch.xen.cpuid = kvm_get_hypervisor_cpuid(vcpu, XEN_SIGNATURE); in kvm_set_cpuid()
567 memcpy(vcpu->arch.cpu_caps, vcpu_caps, sizeof(vcpu_caps)); in kvm_set_cpuid()
568 swap(vcpu->arch.cpuid_entries, e2); in kvm_set_cpuid()
569 swap(vcpu->arch.cpuid_nent, nent); in kvm_set_cpuid()
582 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES) in kvm_vcpu_ioctl_set_cpuid()
583 return -E2BIG; in kvm_vcpu_ioctl_set_cpuid()
585 if (cpuid->nent) { in kvm_vcpu_ioctl_set_cpuid()
586 e = vmemdup_array_user(entries, cpuid->nent, sizeof(*e)); in kvm_vcpu_ioctl_set_cpuid()
590 e2 = kvmalloc_array(cpuid->nent, sizeof(*e2), GFP_KERNEL_ACCOUNT); in kvm_vcpu_ioctl_set_cpuid()
592 r = -ENOMEM; in kvm_vcpu_ioctl_set_cpuid()
596 for (i = 0; i < cpuid->nent; i++) { in kvm_vcpu_ioctl_set_cpuid()
602 e2[i].index = 0; in kvm_vcpu_ioctl_set_cpuid()
609 r = kvm_set_cpuid(vcpu, e2, cpuid->nent); in kvm_vcpu_ioctl_set_cpuid()
626 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES) in kvm_vcpu_ioctl_set_cpuid2()
627 return -E2BIG; in kvm_vcpu_ioctl_set_cpuid2()
629 if (cpuid->nent) { in kvm_vcpu_ioctl_set_cpuid2()
630 e2 = vmemdup_array_user(entries, cpuid->nent, sizeof(*e2)); in kvm_vcpu_ioctl_set_cpuid2()
635 r = kvm_set_cpuid(vcpu, e2, cpuid->nent); in kvm_vcpu_ioctl_set_cpuid2()
646 if (cpuid->nent < vcpu->arch.cpuid_nent) in kvm_vcpu_ioctl_get_cpuid2()
647 return -E2BIG; in kvm_vcpu_ioctl_get_cpuid2()
649 if (copy_to_user(entries, vcpu->arch.cpuid_entries, in kvm_vcpu_ioctl_get_cpuid2()
650 vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2))) in kvm_vcpu_ioctl_get_cpuid2()
651 return -EFAULT; in kvm_vcpu_ioctl_get_cpuid2()
653 cpuid->nent = vcpu->arch.cpuid_nent; in kvm_vcpu_ioctl_get_cpuid2()
674 cpuid_count(cpuid.function, cpuid.index, in raw_cpuid_get()
681 * For kernel-defined leafs, mask KVM's supported feature set with the kernel's
682 * capabilities as well as raw CPUID. For KVM-defined leafs, consult only raw
726 /* Scattered Flag - For features that are scattered by cpufeatures.h. */
735 /* Features that KVM supports only on 64-bit kernels. */
744 * Emulated Feature - For features that KVM emulates in software irrespective
754 * Synthesized Feature - For features that are synthesized into boot_cpu_data,
765 * Passthrough Feature - For features that KVM supports based purely on raw
777 * Aliased Features - For features in 0x8000_0001.EDX that are duplicates of
788 * Vendor Features - For features that KVM supports, but are added in later
797 * Runtime Features - For features that KVM dynamically sets/clears at runtime,
811 /* DS is defined by ptrace-abi.h on 32-bit builds. */
818 BUILD_BUG_ON(sizeof(kvm_cpu_caps) - (NKVMCAPINTS * sizeof(*kvm_cpu_caps)) > in kvm_set_cpu_caps()
832 /* DS-CPL */ in kvm_set_cpu_caps()
837 /* CNXT-ID */ in kvm_set_cpu_caps()
1111 * AMD has separate bits for each SPEC_CTRL bit. in kvm_set_cpu_caps()
1164 * Synthesize "LFENCE is serializing" into the AMD-defined entry in kvm_set_cpu_caps()
1166 * supported by the kernel. LFENCE_RDTSC was a Linux-defined in kvm_set_cpu_caps()
1209 * should never happen, but the guest will likely crash if RDTSCP or in kvm_set_cpu_caps()
1241 if (array->nent >= array->maxnent) in get_next_cpuid()
1244 return &array->entries[array->nent++]; in get_next_cpuid()
1248 u32 function, u32 index) in do_host_cpuid() argument
1256 entry->function = function; in do_host_cpuid()
1257 entry->index = index; in do_host_cpuid()
1266 * would result in out-of-bounds calls to do_host_cpuid. in do_host_cpuid()
1281 cpuid_count(entry->function, entry->index, in do_host_cpuid()
1282 &entry->eax, &entry->ebx, &entry->ecx, &entry->edx); in do_host_cpuid()
1285 entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; in do_host_cpuid()
1295 entry->function = func; in cpuid_func_emulated()
1296 entry->index = 0; in cpuid_func_emulated()
1297 entry->flags = 0; in cpuid_func_emulated()
1301 entry->eax = 7; in cpuid_func_emulated()
1304 entry->ecx = feature_bit(MOVBE); in cpuid_func_emulated()
1307 * the guest, but the MWAIT feature flag is never advertised in cpuid_func_emulated()
1310 * emulates them as NOPs), and allowing the guest to execute in cpuid_func_emulated()
1311 * them natively requires enabling a per-VM capability. in cpuid_func_emulated()
1314 entry->ecx |= feature_bit(MWAIT); in cpuid_func_emulated()
1317 entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; in cpuid_func_emulated()
1318 entry->eax = 0; in cpuid_func_emulated()
1320 entry->ecx = feature_bit(RDPID); in cpuid_func_emulated()
1329 if (array->nent >= array->maxnent) in __do_cpuid_func_emulated()
1330 return -E2BIG; in __do_cpuid_func_emulated()
1332 array->nent += cpuid_func_emulated(&array->entries[array->nent], func, false); in __do_cpuid_func_emulated()
1344 r = -E2BIG; in __do_cpuid_func()
1353 entry->eax = min(entry->eax, 0x24U); in __do_cpuid_func()
1362 * CPUID(function=2, index=0) may return different results each in __do_cpuid_func()
1363 * time, with the least-significant byte in EAX enumerating the in __do_cpuid_func()
1375 WARN_ON_ONCE((entry->eax & 0xff) > 1); in __do_cpuid_func()
1377 /* functions 4 and 0x8000001d have additional index. */ in __do_cpuid_func()
1384 for (i = 1; entry->eax & 0x1f; ++i) { in __do_cpuid_func()
1391 entry->eax = 0x4; /* allow ARAT */ in __do_cpuid_func()
1392 entry->ebx = 0; in __do_cpuid_func()
1393 entry->ecx = 0; in __do_cpuid_func()
1394 entry->edx = 0; in __do_cpuid_func()
1396 /* function 7 has additional index. */ in __do_cpuid_func()
1398 max_idx = entry->eax = min(entry->eax, 2u); in __do_cpuid_func()
1411 entry->ebx = 0; in __do_cpuid_func()
1412 entry->ecx = 0; in __do_cpuid_func()
1420 entry->ecx = 0; in __do_cpuid_func()
1421 entry->ebx = 0; in __do_cpuid_func()
1422 entry->eax = 0; in __do_cpuid_func()
1430 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1444 entry->eax = eax.full; in __do_cpuid_func()
1445 entry->ebx = kvm_pmu_cap.events_mask; in __do_cpuid_func()
1446 entry->ecx = 0; in __do_cpuid_func()
1447 entry->edx = edx.full; in __do_cpuid_func()
1456 entry->eax = entry->ebx = entry->ecx = 0; in __do_cpuid_func()
1462 entry->eax &= permitted_xcr0; in __do_cpuid_func()
1463 entry->ebx = xstate_required_size(permitted_xcr0, false); in __do_cpuid_func()
1464 entry->ecx = entry->ebx; in __do_cpuid_func()
1465 entry->edx &= permitted_xcr0 >> 32; in __do_cpuid_func()
1474 if (entry->eax & (feature_bit(XSAVES) | feature_bit(XSAVEC))) in __do_cpuid_func()
1475 entry->ebx = xstate_required_size(permitted_xcr0 | permitted_xss, in __do_cpuid_func()
1479 entry->ebx = 0; in __do_cpuid_func()
1481 entry->ecx &= permitted_xss; in __do_cpuid_func()
1482 entry->edx &= permitted_xss >> 32; in __do_cpuid_func()
1499 * invalid sub-leafs. Only valid sub-leafs should in __do_cpuid_func()
1500 * reach this point, and they should have a non-zero in __do_cpuid_func()
1503 * on whether this is an XCR0- or IA32_XSS-managed area. in __do_cpuid_func()
1505 if (WARN_ON_ONCE(!entry->eax || (entry->ecx & 0x1) != s_state)) { in __do_cpuid_func()
1506 --array->nent; in __do_cpuid_func()
1511 entry->ecx &= ~BIT_ULL(2); in __do_cpuid_func()
1512 entry->edx = 0; in __do_cpuid_func()
1519 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1524 * Index 0: Sub-features, MISCSELECT (a.k.a extended features) in __do_cpuid_func()
1525 * and max enclave sizes. The SGX sub-features and MISCSELECT in __do_cpuid_func()
1530 entry->ebx &= SGX_MISC_EXINFO; in __do_cpuid_func()
1537 * Index 1: SECS.ATTRIBUTES. ATTRIBUTES are restricted a la in __do_cpuid_func()
1539 * privileged attributes that require explicit opt-in from in __do_cpuid_func()
1543 entry->eax &= SGX_ATTR_PRIV_MASK | SGX_ATTR_UNPRIV_MASK; in __do_cpuid_func()
1544 entry->ebx &= 0; in __do_cpuid_func()
1549 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1553 for (i = 1, max_idx = entry->eax; i <= max_idx; ++i) { in __do_cpuid_func()
1561 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1565 for (i = 1, max_idx = entry->eax; i <= max_idx; ++i) { in __do_cpuid_func()
1572 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1580 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1589 avx10_version = min_t(u8, entry->ebx & 0xff, 1); in __do_cpuid_func()
1591 entry->ebx |= avx10_version; in __do_cpuid_func()
1593 entry->eax = 0; in __do_cpuid_func()
1594 entry->ecx = 0; in __do_cpuid_func()
1595 entry->edx = 0; in __do_cpuid_func()
1600 entry->eax = KVM_CPUID_FEATURES; in __do_cpuid_func()
1601 entry->ebx = sigptr[0]; in __do_cpuid_func()
1602 entry->ecx = sigptr[1]; in __do_cpuid_func()
1603 entry->edx = sigptr[2]; in __do_cpuid_func()
1607 entry->eax = (1 << KVM_FEATURE_CLOCKSOURCE) | in __do_cpuid_func()
1622 entry->eax |= (1 << KVM_FEATURE_STEAL_TIME); in __do_cpuid_func()
1624 entry->ebx = 0; in __do_cpuid_func()
1625 entry->ecx = 0; in __do_cpuid_func()
1626 entry->edx = 0; in __do_cpuid_func()
1629 entry->eax = min(entry->eax, 0x80000022); in __do_cpuid_func()
1639 * highest Intel leaf which QEMU tries to use as the guest's in __do_cpuid_func()
1643 if (entry->eax >= 0x8000001d && in __do_cpuid_func()
1646 entry->eax = max(entry->eax, 0x80000021); in __do_cpuid_func()
1649 entry->ebx &= ~GENMASK(27, 16); in __do_cpuid_func()
1657 /* Drop reserved bits, pass host L2 cache and TLB info. */ in __do_cpuid_func()
1658 entry->edx &= ~GENMASK(17, 16); in __do_cpuid_func()
1664 entry->edx &= boot_cpu_data.x86_power; in __do_cpuid_func()
1665 entry->eax = entry->ebx = entry->ecx = 0; in __do_cpuid_func()
1673 * guest in PhysAddrSize (phys_as), and the maximum in __do_cpuid_func()
1679 * the guest, e.g. if MAXPHYADDR>48 but the CPU doesn't in __do_cpuid_func()
1680 * support 5-level TDP. in __do_cpuid_func()
1682 unsigned int virt_as = max((entry->eax >> 8) & 0xff, 48U); in __do_cpuid_func()
1687 * the guest operates in the same PA space as the host, i.e. in __do_cpuid_func()
1694 * that it's capped at 48 bits if 5-level TDP isn't supported in __do_cpuid_func()
1695 * (hardware processes bits 51:48 only when walking the fifth in __do_cpuid_func()
1702 phys_as = entry->eax & 0xff; in __do_cpuid_func()
1708 entry->eax = phys_as | (virt_as << 8) | (g_phys_as << 16); in __do_cpuid_func()
1709 entry->ecx &= ~(GENMASK(31, 16) | GENMASK(11, 8)); in __do_cpuid_func()
1710 entry->edx = 0; in __do_cpuid_func()
1716 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1719 entry->eax = 1; /* SVM revision 1 */ in __do_cpuid_func()
1720 entry->ebx = 8; /* Lets support 8 ASIDs in case we add proper in __do_cpuid_func()
1722 entry->ecx = 0; /* Reserved */ in __do_cpuid_func()
1726 entry->ecx = entry->edx = 0; in __do_cpuid_func()
1729 entry->eax &= GENMASK(2, 0); in __do_cpuid_func()
1730 entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1734 entry->eax = entry->ebx = entry->ecx = 0; in __do_cpuid_func()
1735 entry->edx = 0; /* reserved */ in __do_cpuid_func()
1739 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1743 entry->ebx &= ~GENMASK(31, 12); in __do_cpuid_func()
1745 * Enumerate '0' for "PA bits reduction", the adjusted in __do_cpuid_func()
1748 entry->ebx &= ~GENMASK(11, 6); in __do_cpuid_func()
1752 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1755 entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1762 entry->ecx = entry->edx = 0; in __do_cpuid_func()
1764 entry->eax = entry->ebx = 0; in __do_cpuid_func()
1777 entry->ebx = ebx.full; in __do_cpuid_func()
1783 entry->eax = min(entry->eax, 0xC0000004); in __do_cpuid_func()
1794 entry->eax = entry->ebx = entry->ecx = entry->edx = 0; in __do_cpuid_func()
1831 limit = array->entries[array->nent - 1].eax; in get_cpuid_func()
1851 * We want to make sure that ->padding is being passed clean from in sanity_check_entries()
1881 if (cpuid->nent < 1) in kvm_dev_ioctl_get_cpuid()
1882 return -E2BIG; in kvm_dev_ioctl_get_cpuid()
1883 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES) in kvm_dev_ioctl_get_cpuid()
1884 cpuid->nent = KVM_MAX_CPUID_ENTRIES; in kvm_dev_ioctl_get_cpuid()
1886 if (sanity_check_entries(entries, cpuid->nent, type)) in kvm_dev_ioctl_get_cpuid()
1887 return -EINVAL; in kvm_dev_ioctl_get_cpuid()
1889 array.entries = kvcalloc(cpuid->nent, sizeof(struct kvm_cpuid_entry2), GFP_KERNEL); in kvm_dev_ioctl_get_cpuid()
1891 return -ENOMEM; in kvm_dev_ioctl_get_cpuid()
1893 array.maxnent = cpuid->nent; in kvm_dev_ioctl_get_cpuid()
1900 cpuid->nent = array.nent; in kvm_dev_ioctl_get_cpuid()
1904 r = -EFAULT; in kvm_dev_ioctl_get_cpuid()
1912 * Intel CPUID semantics treats any query for an out-of-range leaf as if the
1917 * A leaf is considered out-of-range if its function is higher than the maximum
1922 * ranges described as "<base> - <top>[,<base2> - <top2>] inclusive. A primary
1923 * class exists if a guest CPUID entry for its <base> leaf exists. For a given
1926 * - Basic: 0x00000000 - 0x3fffffff, 0x50000000 - 0x7fffffff
1927 * - Hypervisor: 0x40000000 - 0x4fffffff
1928 * - Extended: 0x80000000 - 0xbfffffff
1929 * - Centaur: 0xc0000000 - 0xcfffffff
1931 * The Hypervisor class is further subdivided into sub-classes that each act as
1934 * CPUID sub-classes are:
1936 * - HyperV: 0x40000000 - 0x400000ff
1937 * - KVM: 0x40000100 - 0x400001ff
1940 get_out_of_range_cpuid_entry(struct kvm_vcpu *vcpu, u32 *fn_ptr, u32 index) in get_out_of_range_cpuid_entry() argument
1949 if (is_guest_vendor_amd(basic->ebx, basic->ecx, basic->edx) || in get_out_of_range_cpuid_entry()
1950 is_guest_vendor_hygon(basic->ebx, basic->ecx, basic->edx)) in get_out_of_range_cpuid_entry()
1960 if (class && function <= class->eax) in get_out_of_range_cpuid_entry()
1966 * entry for CPUID.0xb.index (see below), then the output value for EDX in get_out_of_range_cpuid_entry()
1969 *fn_ptr = basic->eax; in get_out_of_range_cpuid_entry()
1973 * the effective CPUID entry is the max basic leaf. Note, the index of in get_out_of_range_cpuid_entry()
1976 return kvm_find_cpuid_entry_index(vcpu, basic->eax, index); in get_out_of_range_cpuid_entry()
1982 u32 orig_function = *eax, function = *eax, index = *ecx; in kvm_cpuid() local
1986 entry = kvm_find_cpuid_entry_index(vcpu, function, index); in kvm_cpuid()
1990 entry = get_out_of_range_cpuid_entry(vcpu, &function, index); in kvm_cpuid()
1995 *eax = entry->eax; in kvm_cpuid()
1996 *ebx = entry->ebx; in kvm_cpuid()
1997 *ecx = entry->ecx; in kvm_cpuid()
1998 *edx = entry->edx; in kvm_cpuid()
1999 if (function == 7 && index == 0) { in kvm_cpuid()
2011 * When leaf 0BH or 1FH is defined, CL is pass-through in kvm_cpuid()
2013 * subleaves. Index 1 will exist iff the leaf is in kvm_cpuid()
2015 * exists. EDX can be copied from any existing index. in kvm_cpuid()
2020 *ecx = index & 0xff; in kvm_cpuid()
2021 *edx = entry->edx; in kvm_cpuid()
2025 trace_kvm_cpuid(orig_function, index, *eax, *ebx, *ecx, *edx, exact, in kvm_cpuid()