Commit 0e851880 authored by Sheng Yang's avatar Sheng Yang Committed by Marcelo Tosatti

KVM: Add cpuid_update() callback to kvm_x86_ops

Sometime, we need to adjust some state in order to reflect guest CPUID
setting, e.g. if we don't expose rdtscp to guest, we won't want to enable
it on hardware. cpuid_update() is introduced for this purpose.

Also export kvm_find_cpuid_entry() for later use.
Signed-off-by: default avatarSheng Yang <sheng@linux.intel.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent be43f83d
...@@ -459,6 +459,7 @@ struct kvm_x86_ops { ...@@ -459,6 +459,7 @@ struct kvm_x86_ops {
int (*hardware_setup)(void); /* __init */ int (*hardware_setup)(void); /* __init */
void (*hardware_unsetup)(void); /* __exit */ void (*hardware_unsetup)(void); /* __exit */
bool (*cpu_has_accelerated_tpr)(void); bool (*cpu_has_accelerated_tpr)(void);
void (*cpuid_update)(struct kvm_vcpu *vcpu);
/* Create, but do not attach this VCPU */ /* Create, but do not attach this VCPU */
struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned id); struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned id);
......
...@@ -2852,6 +2852,10 @@ static u64 svm_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio) ...@@ -2852,6 +2852,10 @@ static u64 svm_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio)
return 0; return 0;
} }
static void svm_cpuid_update(struct kvm_vcpu *vcpu)
{
}
static const struct trace_print_flags svm_exit_reasons_str[] = { static const struct trace_print_flags svm_exit_reasons_str[] = {
{ SVM_EXIT_READ_CR0, "read_cr0" }, { SVM_EXIT_READ_CR0, "read_cr0" },
{ SVM_EXIT_READ_CR3, "read_cr3" }, { SVM_EXIT_READ_CR3, "read_cr3" },
...@@ -2976,6 +2980,8 @@ static struct kvm_x86_ops svm_x86_ops = { ...@@ -2976,6 +2980,8 @@ static struct kvm_x86_ops svm_x86_ops = {
.exit_reasons_str = svm_exit_reasons_str, .exit_reasons_str = svm_exit_reasons_str,
.gb_page_enable = svm_gb_page_enable, .gb_page_enable = svm_gb_page_enable,
.cpuid_update = svm_cpuid_update,
}; };
static int __init svm_init(void) static int __init svm_init(void)
......
...@@ -3988,6 +3988,10 @@ static bool vmx_gb_page_enable(void) ...@@ -3988,6 +3988,10 @@ static bool vmx_gb_page_enable(void)
return false; return false;
} }
static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
{
}
static struct kvm_x86_ops vmx_x86_ops = { static struct kvm_x86_ops vmx_x86_ops = {
.cpu_has_kvm_support = cpu_has_kvm_support, .cpu_has_kvm_support = cpu_has_kvm_support,
.disabled_by_bios = vmx_disabled_by_bios, .disabled_by_bios = vmx_disabled_by_bios,
...@@ -4052,6 +4056,8 @@ static struct kvm_x86_ops vmx_x86_ops = { ...@@ -4052,6 +4056,8 @@ static struct kvm_x86_ops vmx_x86_ops = {
.exit_reasons_str = vmx_exit_reasons_str, .exit_reasons_str = vmx_exit_reasons_str,
.gb_page_enable = vmx_gb_page_enable, .gb_page_enable = vmx_gb_page_enable,
.cpuid_update = vmx_cpuid_update,
}; };
static int __init vmx_init(void) static int __init vmx_init(void)
......
...@@ -1574,6 +1574,7 @@ static int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu, ...@@ -1574,6 +1574,7 @@ static int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
cpuid_fix_nx_cap(vcpu); cpuid_fix_nx_cap(vcpu);
r = 0; r = 0;
kvm_apic_set_version(vcpu); kvm_apic_set_version(vcpu);
kvm_x86_ops->cpuid_update(vcpu);
out_free: out_free:
vfree(cpuid_entries); vfree(cpuid_entries);
...@@ -1596,6 +1597,7 @@ static int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu, ...@@ -1596,6 +1597,7 @@ static int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
goto out; goto out;
vcpu->arch.cpuid_nent = cpuid->nent; vcpu->arch.cpuid_nent = cpuid->nent;
kvm_apic_set_version(vcpu); kvm_apic_set_version(vcpu);
kvm_x86_ops->cpuid_update(vcpu);
return 0; return 0;
out: out:
...@@ -3733,6 +3735,7 @@ struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu, ...@@ -3733,6 +3735,7 @@ struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
} }
return best; return best;
} }
EXPORT_SYMBOL_GPL(kvm_find_cpuid_entry);
int cpuid_maxphyaddr(struct kvm_vcpu *vcpu) int cpuid_maxphyaddr(struct kvm_vcpu *vcpu)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment