aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIzik Eidus <izike@qumranet.com>2008-03-24 13:38:34 -0400
committerAvi Kivity <avi@qumranet.com>2008-04-27 05:00:38 -0400
commit2e4d2653497856b102c90153f970c9e344ba96c6 (patch)
tree8a1929d5caa1f9436c25a104f75403fb2b3e5e2f
parent4c9fc8ef501790732ed035585b491756b75ea4c6 (diff)
KVM: x86: add functions to get the cpl of vcpu
Signed-off-by: Izik Eidus <izike@qumranet.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
-rw-r--r--arch/x86/kvm/svm.c8
-rw-r--r--arch/x86/kvm/vmx.c15
-rw-r--r--include/asm-x86/kvm_host.h1
3 files changed, 24 insertions, 0 deletions
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 51741f96e7fb..c1c1b973e80a 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -792,6 +792,13 @@ static void svm_get_segment(struct kvm_vcpu *vcpu,
792 var->unusable = !var->present; 792 var->unusable = !var->present;
793} 793}
794 794
795static int svm_get_cpl(struct kvm_vcpu *vcpu)
796{
797 struct vmcb_save_area *save = &to_svm(vcpu)->vmcb->save;
798
799 return save->cpl;
800}
801
795static void svm_get_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt) 802static void svm_get_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
796{ 803{
797 struct vcpu_svm *svm = to_svm(vcpu); 804 struct vcpu_svm *svm = to_svm(vcpu);
@@ -1822,6 +1829,7 @@ static struct kvm_x86_ops svm_x86_ops = {
1822 .get_segment_base = svm_get_segment_base, 1829 .get_segment_base = svm_get_segment_base,
1823 .get_segment = svm_get_segment, 1830 .get_segment = svm_get_segment,
1824 .set_segment = svm_set_segment, 1831 .set_segment = svm_set_segment,
1832 .get_cpl = svm_get_cpl,
1825 .get_cs_db_l_bits = kvm_get_cs_db_l_bits, 1833 .get_cs_db_l_bits = kvm_get_cs_db_l_bits,
1826 .decache_cr4_guest_bits = svm_decache_cr4_guest_bits, 1834 .decache_cr4_guest_bits = svm_decache_cr4_guest_bits,
1827 .set_cr0 = svm_set_cr0, 1835 .set_cr0 = svm_set_cr0,
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 01559311df8c..9b560325b127 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -1395,6 +1395,20 @@ static void vmx_get_segment(struct kvm_vcpu *vcpu,
1395 var->unusable = (ar >> 16) & 1; 1395 var->unusable = (ar >> 16) & 1;
1396} 1396}
1397 1397
1398static int vmx_get_cpl(struct kvm_vcpu *vcpu)
1399{
1400 struct kvm_segment kvm_seg;
1401
1402 if (!(vcpu->arch.cr0 & X86_CR0_PE)) /* if real mode */
1403 return 0;
1404
1405 if (vmx_get_rflags(vcpu) & X86_EFLAGS_VM) /* if virtual 8086 */
1406 return 3;
1407
1408 vmx_get_segment(vcpu, &kvm_seg, VCPU_SREG_CS);
1409 return kvm_seg.selector & 3;
1410}
1411
1398static u32 vmx_segment_access_rights(struct kvm_segment *var) 1412static u32 vmx_segment_access_rights(struct kvm_segment *var)
1399{ 1413{
1400 u32 ar; 1414 u32 ar;
@@ -2665,6 +2679,7 @@ static struct kvm_x86_ops vmx_x86_ops = {
2665 .get_segment_base = vmx_get_segment_base, 2679 .get_segment_base = vmx_get_segment_base,
2666 .get_segment = vmx_get_segment, 2680 .get_segment = vmx_get_segment,
2667 .set_segment = vmx_set_segment, 2681 .set_segment = vmx_set_segment,
2682 .get_cpl = vmx_get_cpl,
2668 .get_cs_db_l_bits = vmx_get_cs_db_l_bits, 2683 .get_cs_db_l_bits = vmx_get_cs_db_l_bits,
2669 .decache_cr4_guest_bits = vmx_decache_cr4_guest_bits, 2684 .decache_cr4_guest_bits = vmx_decache_cr4_guest_bits,
2670 .set_cr0 = vmx_set_cr0, 2685 .set_cr0 = vmx_set_cr0,
diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
index 2c85d01d0764..93e809c251ef 100644
--- a/include/asm-x86/kvm_host.h
+++ b/include/asm-x86/kvm_host.h
@@ -388,6 +388,7 @@ struct kvm_x86_ops {
388 u64 (*get_segment_base)(struct kvm_vcpu *vcpu, int seg); 388 u64 (*get_segment_base)(struct kvm_vcpu *vcpu, int seg);
389 void (*get_segment)(struct kvm_vcpu *vcpu, 389 void (*get_segment)(struct kvm_vcpu *vcpu,
390 struct kvm_segment *var, int seg); 390 struct kvm_segment *var, int seg);
391 int (*get_cpl)(struct kvm_vcpu *vcpu);
391 void (*set_segment)(struct kvm_vcpu *vcpu, 392 void (*set_segment)(struct kvm_vcpu *vcpu,
392 struct kvm_segment *var, int seg); 393 struct kvm_segment *var, int seg);
393 void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l); 394 void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l);