diff options
author | Joerg Roedel <joerg.roedel@amd.com> | 2010-09-10 11:30:41 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-10-24 04:52:30 -0400 |
commit | 1c97f0a04c74196880f22a563134c8f6d0b9d752 (patch) | |
tree | 060da15688879d0a50c4854f40980ac915f39663 /arch | |
parent | f43addd46168110d572dcf69100cb215a4e9fd08 (diff) |
KVM: X86: Introduce a tdp_set_cr3 function
This patch introduces a special set_tdp_cr3 function pointer
in kvm_x86_ops which is only used for tpd enabled mmu
contexts. This allows to remove some hacks from svm code.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86/include/asm/kvm_host.h | 2 | ||||
-rw-r--r-- | arch/x86/kvm/mmu.c | 2 | ||||
-rw-r--r-- | arch/x86/kvm/svm.c | 23 | ||||
-rw-r--r-- | arch/x86/kvm/vmx.c | 2 |
4 files changed, 19 insertions, 10 deletions
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 53cedede88fa..81a51473f745 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h | |||
@@ -526,6 +526,8 @@ struct kvm_x86_ops { | |||
526 | bool (*rdtscp_supported)(void); | 526 | bool (*rdtscp_supported)(void); |
527 | void (*adjust_tsc_offset)(struct kvm_vcpu *vcpu, s64 adjustment); | 527 | void (*adjust_tsc_offset)(struct kvm_vcpu *vcpu, s64 adjustment); |
528 | 528 | ||
529 | void (*set_tdp_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3); | ||
530 | |||
529 | void (*set_supported_cpuid)(u32 func, struct kvm_cpuid_entry2 *entry); | 531 | void (*set_supported_cpuid)(u32 func, struct kvm_cpuid_entry2 *entry); |
530 | 532 | ||
531 | bool (*has_wbinvd_exit)(void); | 533 | bool (*has_wbinvd_exit)(void); |
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index c8acb9609ca4..a55f8d5a7985 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c | |||
@@ -2714,7 +2714,7 @@ static int init_kvm_tdp_mmu(struct kvm_vcpu *vcpu) | |||
2714 | context->shadow_root_level = kvm_x86_ops->get_tdp_level(); | 2714 | context->shadow_root_level = kvm_x86_ops->get_tdp_level(); |
2715 | context->root_hpa = INVALID_PAGE; | 2715 | context->root_hpa = INVALID_PAGE; |
2716 | context->direct_map = true; | 2716 | context->direct_map = true; |
2717 | context->set_cr3 = kvm_x86_ops->set_cr3; | 2717 | context->set_cr3 = kvm_x86_ops->set_tdp_cr3; |
2718 | 2718 | ||
2719 | if (!is_paging(vcpu)) { | 2719 | if (!is_paging(vcpu)) { |
2720 | context->gva_to_gpa = nonpaging_gva_to_gpa; | 2720 | context->gva_to_gpa = nonpaging_gva_to_gpa; |
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index fcbc491e1f87..53c9039583fd 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c | |||
@@ -3216,9 +3216,6 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu) | |||
3216 | savesegment(gs, gs_selector); | 3216 | savesegment(gs, gs_selector); |
3217 | ldt_selector = kvm_read_ldt(); | 3217 | ldt_selector = kvm_read_ldt(); |
3218 | svm->vmcb->save.cr2 = vcpu->arch.cr2; | 3218 | svm->vmcb->save.cr2 = vcpu->arch.cr2; |
3219 | /* required for live migration with NPT */ | ||
3220 | if (npt_enabled) | ||
3221 | svm->vmcb->save.cr3 = vcpu->arch.cr3; | ||
3222 | 3219 | ||
3223 | clgi(); | 3220 | clgi(); |
3224 | 3221 | ||
@@ -3340,16 +3337,22 @@ static void svm_set_cr3(struct kvm_vcpu *vcpu, unsigned long root) | |||
3340 | { | 3337 | { |
3341 | struct vcpu_svm *svm = to_svm(vcpu); | 3338 | struct vcpu_svm *svm = to_svm(vcpu); |
3342 | 3339 | ||
3343 | if (npt_enabled) { | ||
3344 | svm->vmcb->control.nested_cr3 = root; | ||
3345 | force_new_asid(vcpu); | ||
3346 | return; | ||
3347 | } | ||
3348 | |||
3349 | svm->vmcb->save.cr3 = root; | 3340 | svm->vmcb->save.cr3 = root; |
3350 | force_new_asid(vcpu); | 3341 | force_new_asid(vcpu); |
3351 | } | 3342 | } |
3352 | 3343 | ||
3344 | static void set_tdp_cr3(struct kvm_vcpu *vcpu, unsigned long root) | ||
3345 | { | ||
3346 | struct vcpu_svm *svm = to_svm(vcpu); | ||
3347 | |||
3348 | svm->vmcb->control.nested_cr3 = root; | ||
3349 | |||
3350 | /* Also sync guest cr3 here in case we live migrate */ | ||
3351 | svm->vmcb->save.cr3 = vcpu->arch.cr3; | ||
3352 | |||
3353 | force_new_asid(vcpu); | ||
3354 | } | ||
3355 | |||
3353 | static int is_disabled(void) | 3356 | static int is_disabled(void) |
3354 | { | 3357 | { |
3355 | u64 vm_cr; | 3358 | u64 vm_cr; |
@@ -3576,6 +3579,8 @@ static struct kvm_x86_ops svm_x86_ops = { | |||
3576 | 3579 | ||
3577 | .write_tsc_offset = svm_write_tsc_offset, | 3580 | .write_tsc_offset = svm_write_tsc_offset, |
3578 | .adjust_tsc_offset = svm_adjust_tsc_offset, | 3581 | .adjust_tsc_offset = svm_adjust_tsc_offset, |
3582 | |||
3583 | .set_tdp_cr3 = set_tdp_cr3, | ||
3579 | }; | 3584 | }; |
3580 | 3585 | ||
3581 | static int __init svm_init(void) | 3586 | static int __init svm_init(void) |
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 275a81d571cf..ff7a8d48fd24 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c | |||
@@ -4341,6 +4341,8 @@ static struct kvm_x86_ops vmx_x86_ops = { | |||
4341 | 4341 | ||
4342 | .write_tsc_offset = vmx_write_tsc_offset, | 4342 | .write_tsc_offset = vmx_write_tsc_offset, |
4343 | .adjust_tsc_offset = vmx_adjust_tsc_offset, | 4343 | .adjust_tsc_offset = vmx_adjust_tsc_offset, |
4344 | |||
4345 | .set_tdp_cr3 = vmx_set_cr3, | ||
4344 | }; | 4346 | }; |
4345 | 4347 | ||
4346 | static int __init vmx_init(void) | 4348 | static int __init vmx_init(void) |