Lines Matching full:cpuid
4 * cpuid support routines
24 #include <asm/cpuid.h>
25 #include "cpuid.h"
85 * Magic value used by KVM when querying userspace-provided CPUID entries and
89 * to avoid false positives when processing guest CPUID input.
100 * KVM has a semi-arbitrary rule that querying the guest's CPUID model in cpuid_entry2_find()
101 * with IRQs disabled is disallowed. The CPUID model can legitimately in cpuid_entry2_find()
107 * of the hotpath, e.g. by caching information during CPUID updates. in cpuid_entry2_find()
128 * 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
400 * Reset guest capabilities to userspace's guest CPUID definition, i.e. in kvm_vcpu_after_set_cpuid()
405 const struct cpuid_reg cpuid = reverse_cpuid[i]; in kvm_vcpu_after_set_cpuid() local
408 if (!cpuid.function) in kvm_vcpu_after_set_cpuid()
411 entry = kvm_find_cpuid_entry_index(vcpu, cpuid.function, cpuid.index); in kvm_vcpu_after_set_cpuid()
415 cpuid_func_emulated(&emulated, cpuid.function, true); in kvm_vcpu_after_set_cpuid()
419 * in guest CPUID. Note, this includes features that are in kvm_vcpu_after_set_cpuid()
423 cpuid_get_reg_unsafe(&emulated, cpuid.reg); in kvm_vcpu_after_set_cpuid()
424 vcpu->arch.cpu_caps[i] &= cpuid_get_reg_unsafe(entry, cpuid.reg); in kvm_vcpu_after_set_cpuid()
437 * If TDP is disabled, honor *only* guest CPUID as KVM has full control in kvm_vcpu_after_set_cpuid()
514 * that KVM controls, without clobbering the current guest CPUID, which in kvm_set_cpuid()
518 * can be updated alongside the CPUID entries when performing runtime in kvm_set_cpuid()
520 * run, i.e. only if userspace is potentially changing CPUID features. in kvm_set_cpuid()
529 * KVM does not correctly handle changing guest CPUID after KVM_RUN, as in kvm_set_cpuid()
537 * whether the supplied CPUID data is equal to what's already set. in kvm_set_cpuid()
559 vcpu->arch.xen.cpuid = kvm_get_hypervisor_cpuid(vcpu, XEN_SIGNATURE); in kvm_set_cpuid()
576 struct kvm_cpuid *cpuid, in kvm_vcpu_ioctl_set_cpuid() argument
583 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES) in kvm_vcpu_ioctl_set_cpuid()
586 if (cpuid->nent) { in kvm_vcpu_ioctl_set_cpuid()
587 e = vmemdup_array_user(entries, cpuid->nent, sizeof(*e)); in kvm_vcpu_ioctl_set_cpuid()
591 e2 = kvmalloc_array(cpuid->nent, sizeof(*e2), GFP_KERNEL_ACCOUNT); in kvm_vcpu_ioctl_set_cpuid()
597 for (i = 0; i < cpuid->nent; i++) { in kvm_vcpu_ioctl_set_cpuid()
610 r = kvm_set_cpuid(vcpu, e2, cpuid->nent); in kvm_vcpu_ioctl_set_cpuid()
621 struct kvm_cpuid2 *cpuid, in kvm_vcpu_ioctl_set_cpuid2() argument
627 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES) in kvm_vcpu_ioctl_set_cpuid2()
630 if (cpuid->nent) { in kvm_vcpu_ioctl_set_cpuid2()
631 e2 = vmemdup_array_user(entries, cpuid->nent, sizeof(*e2)); in kvm_vcpu_ioctl_set_cpuid2()
636 r = kvm_set_cpuid(vcpu, e2, cpuid->nent); in kvm_vcpu_ioctl_set_cpuid2()
644 struct kvm_cpuid2 *cpuid, in kvm_vcpu_ioctl_get_cpuid2() argument
647 if (cpuid->nent < vcpu->arch.cpuid_nent) in kvm_vcpu_ioctl_get_cpuid2()
657 cpuid->nent = vcpu->arch.cpuid_nent; in kvm_vcpu_ioctl_get_cpuid2()
661 static __always_inline u32 raw_cpuid_get(struct cpuid_reg cpuid) in raw_cpuid_get() argument
671 base = cpuid.function & 0xffff0000; in raw_cpuid_get()
675 if (cpuid_eax(base) < cpuid.function) in raw_cpuid_get()
678 cpuid_count(cpuid.function, cpuid.index, in raw_cpuid_get()
681 return *__cpuid_entry_get_reg(&entry, cpuid.reg); in raw_cpuid_get()
686 * capabilities as well as raw CPUID. For KVM-defined leafs, consult only raw
687 * CPUID, as KVM is the one and only authority (in the kernel).
691 const struct cpuid_reg cpuid = x86_feature_cpuid(leaf * 32); \
707 kvm_cpu_caps[leaf] &= (raw_cpuid_get(cpuid) | \
713 * Assert that the feature bit being declared, e.g. via F(), is in the CPUID
759 * i.e. may not be present in the raw CPUID, but can still be advertised to
770 * hardware CPUID, i.e. that KVM virtualizes even if the host kernel doesn't
772 * CPUID support will be factored in by kvm_cpu_cap_mask().
831 * advertised to guests via CPUID! MWAIT is also technically a in kvm_set_cpu_caps()
1169 * in KVM's supported CPUID, i.e. if the feature is reported as in kvm_set_cpu_caps()
1174 * CPUID will drop the flags, and reporting support in AMD's in kvm_set_cpu_caps()
1366 * CPUID(function=2, index=0) may return different results each in __do_cpuid_func()
1368 * number of times software should do CPUID(2, 0). in __do_cpuid_func()
1374 * APM states that CPUID(2) is reserved. in __do_cpuid_func()
1377 * a stateful CPUID.0x2 is encountered. in __do_cpuid_func()
1636 * NullSegClearsBase is not reported in CPUID on Zen2; help in __do_cpuid_func()
1637 * userspace by providing the CPUID leaf ourselves. in __do_cpuid_func()
1639 * However, only do it if the host has CPUID leaf 0x8000001d. in __do_cpuid_func()
1641 * CPUID leaf if KVM reports that it supports 0x8000001d or in __do_cpuid_func()
1778 /*Add support for Centaur's CPUID instruction*/ in __do_cpuid_func()
1866 int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid, in kvm_dev_ioctl_get_cpuid() argument
1879 if (cpuid->nent < 1) in kvm_dev_ioctl_get_cpuid()
1881 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES) in kvm_dev_ioctl_get_cpuid()
1882 cpuid->nent = KVM_MAX_CPUID_ENTRIES; in kvm_dev_ioctl_get_cpuid()
1884 if (sanity_check_entries(entries, cpuid->nent, type)) in kvm_dev_ioctl_get_cpuid()
1887 array.entries = kvcalloc(cpuid->nent, sizeof(struct kvm_cpuid_entry2), GFP_KERNEL); in kvm_dev_ioctl_get_cpuid()
1891 array.maxnent = cpuid->nent; in kvm_dev_ioctl_get_cpuid()
1898 cpuid->nent = array.nent; in kvm_dev_ioctl_get_cpuid()
1910 * Intel CPUID semantics treats any query for an out-of-range leaf as if the
1911 * highest basic leaf (i.e. CPUID.0H:EAX) were requested. AMD CPUID semantics
1921 * class exists if a guest CPUID entry for its <base> leaf exists. For a given
1922 * class, CPUID.<base>.EAX contains the max supported leaf for the class.
1932 * CPUID sub-classes are:
1964 * entry for CPUID.0xb.index (see below), then the output value for EDX in get_out_of_range_cpuid_entry()
1965 * needs to be pulled from CPUID.0xb.1. in get_out_of_range_cpuid_entry()
1971 * the effective CPUID entry is the max basic leaf. Note, the index of in get_out_of_range_cpuid_entry()