Lines Matching full:cpuid

4  * cpuid support routines
24 #include <asm/cpuid.h>
25 #include "cpuid.h"
86 * Magic value used by KVM when querying userspace-provided CPUID entries and
90 * to avoid false positives when processing guest CPUID input.
101 * KVM has a semi-arbitrary rule that querying the guest's CPUID model in cpuid_entry2_find()
102 * with IRQs disabled is disallowed. The CPUID model can legitimately in cpuid_entry2_find()
108 * of the hotpath, e.g. by caching information during CPUID updates. in cpuid_entry2_find()
129 * lookup (as opposed to emulating CPUID) for a function that's in cpuid_entry2_find()
200 /* Check whether the supplied CPUID data is equal to what is already set for the vCPU. */
208 * Apply runtime CPUID updates to the incoming CPUID entries to avoid in kvm_cpuid_check_equal()
211 * Note! @e2 and @nent track the _old_ CPUID entries! in kvm_cpuid_check_equal()
235 struct kvm_hypervisor_cpuid cpuid = {}; in kvm_get_hypervisor_cpuid() local
250 cpuid.base = base; in kvm_get_hypervisor_cpuid()
251 cpuid.limit = entry->eax; in kvm_get_hypervisor_cpuid()
257 return cpuid; in kvm_get_hypervisor_cpuid()
280 * Calculate guest's supported XCR0 taking into account guest CPUID data and
399 * Reset guest capabilities to userspace's guest CPUID definition, i.e. in kvm_vcpu_after_set_cpuid()
404 const struct cpuid_reg cpuid = reverse_cpuid[i]; in kvm_vcpu_after_set_cpuid() local
407 if (!cpuid.function) in kvm_vcpu_after_set_cpuid()
410 entry = kvm_find_cpuid_entry_index(vcpu, cpuid.function, cpuid.index); in kvm_vcpu_after_set_cpuid()
414 cpuid_func_emulated(&emulated, cpuid.function, true); in kvm_vcpu_after_set_cpuid()
418 * in guest CPUID. Note, this includes features that are in kvm_vcpu_after_set_cpuid()
422 cpuid_get_reg_unsafe(&emulated, cpuid.reg); 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()
436 * If TDP is disabled, honor *only* guest CPUID as KVM has full control in kvm_vcpu_after_set_cpuid()
513 * that KVM controls, without clobbering the current guest CPUID, which in kvm_set_cpuid()
517 * can be updated alongside the CPUID entries when performing runtime in kvm_set_cpuid()
519 * run, i.e. only if userspace is potentially changing CPUID features. in kvm_set_cpuid()
528 * KVM does not correctly handle changing guest CPUID after KVM_RUN, as in kvm_set_cpuid()
536 * whether the supplied CPUID data is equal to what's already set. in kvm_set_cpuid()
558 vcpu->arch.xen.cpuid = kvm_get_hypervisor_cpuid(vcpu, XEN_SIGNATURE); in kvm_set_cpuid()
575 struct kvm_cpuid *cpuid, in kvm_vcpu_ioctl_set_cpuid() argument
582 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES) 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()
596 for (i = 0; i < cpuid->nent; i++) { in kvm_vcpu_ioctl_set_cpuid()
609 r = kvm_set_cpuid(vcpu, e2, cpuid->nent); in kvm_vcpu_ioctl_set_cpuid()
620 struct kvm_cpuid2 *cpuid, in kvm_vcpu_ioctl_set_cpuid2() argument
626 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES) 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()
643 struct kvm_cpuid2 *cpuid, in kvm_vcpu_ioctl_get_cpuid2() argument
646 if (cpuid->nent < vcpu->arch.cpuid_nent) in kvm_vcpu_ioctl_get_cpuid2()
653 cpuid->nent = vcpu->arch.cpuid_nent; in kvm_vcpu_ioctl_get_cpuid2()
657 static __always_inline u32 raw_cpuid_get(struct cpuid_reg cpuid) in raw_cpuid_get() argument
667 base = cpuid.function & 0xffff0000; in raw_cpuid_get()
671 if (cpuid_eax(base) < cpuid.function) in raw_cpuid_get()
674 cpuid_count(cpuid.function, cpuid.index, in raw_cpuid_get()
677 return *__cpuid_entry_get_reg(&entry, cpuid.reg); in raw_cpuid_get()
682 * capabilities as well as raw CPUID. For KVM-defined leafs, consult only raw
683 * CPUID, as KVM is the one and only authority (in the kernel).
687 const struct cpuid_reg cpuid = x86_feature_cpuid(leaf * 32); \
703 kvm_cpu_caps[leaf] &= (raw_cpuid_get(cpuid) | \
709 * Assert that the feature bit being declared, e.g. via F(), is in the CPUID
755 * i.e. may not be present in the raw CPUID, but can still be advertised to
766 * hardware CPUID, i.e. that KVM virtualizes even if the host kernel doesn't
768 * CPUID support will be factored in by kvm_cpu_cap_mask().
827 * advertised to guests via CPUID! MWAIT is also technically a in kvm_set_cpu_caps()
1165 * in KVM's supported CPUID, i.e. if the feature is reported as in kvm_set_cpu_caps()
1170 * CPUID will drop the flags, and reporting support in AMD's in kvm_set_cpu_caps()
1362 * CPUID(function=2, index=0) may return different results each in __do_cpuid_func()
1364 * number of times software should do CPUID(2, 0). in __do_cpuid_func()
1370 * APM states that CPUID(2) is reserved. in __do_cpuid_func()
1373 * a stateful CPUID.0x2 is encountered. in __do_cpuid_func()
1632 * NullSegClearsBase is not reported in CPUID on Zen2; help in __do_cpuid_func()
1633 * userspace by providing the CPUID leaf ourselves. in __do_cpuid_func()
1635 * However, only do it if the host has CPUID leaf 0x8000001d. in __do_cpuid_func()
1637 * CPUID leaf if KVM reports that it supports 0x8000001d or in __do_cpuid_func()
1780 /*Add support for Centaur's CPUID instruction*/ in __do_cpuid_func()
1868 int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid, in kvm_dev_ioctl_get_cpuid() argument
1881 if (cpuid->nent < 1) 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()
1889 array.entries = kvcalloc(cpuid->nent, sizeof(struct kvm_cpuid_entry2), GFP_KERNEL); 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()
1912 * Intel CPUID semantics treats any query for an out-of-range leaf as if the
1913 * highest basic leaf (i.e. CPUID.0H:EAX) were requested. AMD CPUID semantics
1923 * class exists if a guest CPUID entry for its <base> leaf exists. For a given
1924 * class, CPUID.<base>.EAX contains the max supported leaf for the class.
1934 * CPUID sub-classes are:
1966 * entry for CPUID.0xb.index (see below), then the output value for EDX in get_out_of_range_cpuid_entry()
1967 * needs to be pulled from CPUID.0xb.1. 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()