[PATCH RFC 1/2] add functions to read and set the ldt

Izik Eidus
2008-03-13T00:42:24Z

>From 28f36d30f8eef9c12afe52e183bf4c8405d113d2 Mon Sep 17 00:00:00 2001
From: Izik Eidus <izike@qumranet.com>
Date: Thu, 13 Mar 2008 02:03:37 +0200
Subject: [PATCH] KVM: vmx, svm add functions to read and set the ldt

Signed-off-by: Izik Eidus <izike@qumranet.com>
---
arch/x86/kvm/svm.c | 18 ++++++++++++++++++
arch/x86/kvm/vmx.c | 14 ++++++++++++++
include/asm-x86/kvm_host.h | 2 ++
3 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 51741f9..4e1dd61 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -824,6 +824,22 @@ static void svm_set_gdt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
svm->vmcb->save.gdtr.base = dt->base ;
}

+static void svm_get_ldt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
+{
+ struct vcpu_svm *svm = to_svm(vcpu);
+
+ dt->limit = svm->vmcb->save.ldtr.limit;
+ dt->base = svm->vmcb->save.ldtr.base;
+}
+
+static void svm_set_ldt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
+{
+ struct vcpu_svm *svm = to_svm(vcpu);
+
+ svm->vmcb->save.ldtr.limit = dt->limit;
+ svm->vmcb->save.ldtr.base = dt->base ;
+}
+
static void svm_decache_cr4_guest_bits(struct kvm_vcpu *vcpu)
{
}
@@ -1832,6 +1848,8 @@ static struct kvm_x86_ops svm_x86_ops = {
.set_idt = svm_set_idt,
.get_gdt = svm_get_gdt,
.set_gdt = svm_set_gdt,
+ .get_ldt = svm_get_ldt,
+ .set_ldt = svm_set_ldt,
.get_dr = svm_get_dr,
.set_dr = svm_set_dr,
.cache_regs = svm_cache_regs,
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 9951ec9..459b0bd 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -1476,6 +1476,18 @@ static void vmx_set_gdt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
vmcs_writel(GUEST_GDTR_BASE, dt->base);
}

+static void vmx_get_ldt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
+{
+ dt->limit = vmcs_read32(GUEST_LDTR_LIMIT);
+ dt->base = vmcs_readl(GUEST_LDTR_BASE);
+}
+
+static void vmx_set_ldt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
+{
+ vmcs_write32(GUEST_LDTR_LIMIT, dt->limit);
+ vmcs_writel(GUEST_LDTR_BASE, dt->base);
+}
+
static int init_rmode_tss(struct kvm *kvm)
{
gfn_t fn = rmode_tss_base(kvm) >> PAGE_SHIFT;
@@ -2674,6 +2686,8 @@ static struct kvm_x86_ops vmx_x86_ops = {
.set_idt = vmx_set_idt,
.get_gdt = vmx_get_gdt,
.set_gdt = vmx_set_gdt,
+ .get_ldt = vmx_get_ldt,
+ .set_ldt = vmx_set_ldt,
.cache_regs = vcpu_load_rsp_rip,
.decache_regs = vcpu_put_rsp_rip,
.get_rflags = vmx_get_rflags,
diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
index 12932bb..d9806e2 100644
--- a/include/asm-x86/kvm_host.h
+++ b/include/asm-x86/kvm_host.h
@@ -386,6 +386,8 @@ struct kvm_x86_ops {
void (*set_idt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
void (*get_gdt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
void (*set_gdt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
+ void (*get_ldt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
+ void (*set_ldt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
unsigned long (*get_dr)(struct kvm_vcpu *vcpu, int dr);
void (*set_dr)(struct kvm_vcpu *vcpu, int dr, unsigned long value,
int *exception);
--
1.5.3.6

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.