This patch sets up multiple TSS for real mode emulation on Intel vmx, one for each vcpu. This is a preparation patch for full SMP real mode support.
Signed-off-by: Qing He <[EMAIL PROTECTED]>
kvm.h | 1 +
kvm_main.c | 1 +
vmx.c | 31 +++++++++++++++++--------------
3 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 65ab268..0f7a4d9 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -328,6 +328,7 @@ void kvm_io_bus_register_dev(struct kvm_io_bus *bus,
struct kvm_vcpu {
struct kvm *kvm;
+ int vcpu_id;
union {
struct vmcs *vmcs;
struct vcpu_svm *svm;
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index a4429eb..4d2ef9b 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -2387,6 +2387,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm
*kvm, int n)
goto out;
vcpu = &kvm->vcpus[n];
+ vcpu->vcpu_id = n;
mutex_lock(&vcpu->mutex);
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 80628f6..beb25e3 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -32,7 +32,7 @@
MODULE_AUTHOR("Qumranet");
MODULE_LICENSE("GPL");
-static int init_rmode_tss(struct kvm *kvm);
+static int init_rmode_tss(struct kvm *kvm, int vcpu_id);
static DEFINE_PER_CPU(struct vmcs *, vmxarea);
static DEFINE_PER_CPU(struct vmcs *, current_vmcs);
@@ -897,9 +897,10 @@ static void enter_pmode(struct kvm_vcpu *vcpu)
vmcs_write32(GUEST_CS_AR_BYTES, 0x9b);
}
-static int rmode_tss_base(struct kvm* kvm)
+static int rmode_tss_base(struct kvm* kvm, int vcpu_id)
{
- gfn_t base_gfn = kvm->memslots[0].base_gfn +
kvm->memslots[0].npages - 3;
+ gfn_t base_gfn = kvm->memslots[0].base_gfn +
kvm->memslots[0].npages
+ - 3 * (vcpu_id + 1);
return base_gfn << PAGE_SHIFT;
}
@@ -923,7 +924,7 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
vcpu->rmode.active = 1;
vcpu->rmode.tr.base = vmcs_readl(GUEST_TR_BASE);
- vmcs_writel(GUEST_TR_BASE, rmode_tss_base(vcpu->kvm));
+ vmcs_writel(GUEST_TR_BASE, rmode_tss_base(vcpu->kvm,
vcpu->vcpu_id));
vcpu->rmode.tr.limit = vmcs_read32(GUEST_TR_LIMIT);
vmcs_write32(GUEST_TR_LIMIT, RMODE_TSS_SIZE - 1);
@@ -955,7 +956,7 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
fix_rmode_seg(VCPU_SREG_GS, &vcpu->rmode.gs);
fix_rmode_seg(VCPU_SREG_FS, &vcpu->rmode.fs);
- init_rmode_tss(vcpu->kvm);
+ init_rmode_tss(vcpu->kvm, vcpu->vcpu_id);
}
#ifdef CONFIG_X86_64
@@ -1178,10 +1179,10 @@ static void vmx_set_gdt(struct kvm_vcpu *vcpu,
struct descriptor_table *dt)
vmcs_writel(GUEST_GDTR_BASE, dt->base);
}
-static int init_rmode_tss(struct kvm* kvm)
+static int init_rmode_tss(struct kvm* kvm, int vcpu_id)
{
struct page *p1, *p2, *p3;
- gfn_t fn = rmode_tss_base(kvm) >> PAGE_SHIFT;
+ gfn_t fn = rmode_tss_base(kvm, vcpu_id) >> PAGE_SHIFT;
char *page;
p1 = gfn_to_page(kvm, fn++);
@@ -1244,7 +1245,7 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
int ret = 0;
unsigned long kvm_vmx_return;
- if (!init_rmode_tss(vcpu->kvm)) {
+ if (!init_rmode_tss(vcpu->kvm, vcpu->vcpu_id)) {
ret = -ENOMEM;
goto out;
}
@@ -1253,7 +1254,7 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
vcpu->regs[VCPU_REGS_RDX] = get_rdx_init_val();
vcpu->cr8 = 0;
vcpu->apic_base = 0xfee00000 | MSR_IA32_APICBASE_ENABLE;
- if (vcpu == &vcpu->kvm->vcpus[0])
+ if (vcpu->vcpu_id == 0)
vcpu->apic_base |= MSR_IA32_APICBASE_BSP;
fx_init(vcpu);
@@ -1262,10 +1263,13 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
* GUEST_CS_BASE should really be 0xffff0000, but VT vm86 mode
* insists on having GUEST_CS_BASE == GUEST_CS_SELECTOR << 4.
Sigh.
*/
- vmcs_write16(GUEST_CS_SELECTOR, 0xf000);
- vmcs_writel(GUEST_CS_BASE, 0x000f0000);
- vmcs_write32(GUEST_CS_LIMIT, 0xffff);
- vmcs_write32(GUEST_CS_AR_BYTES, 0x9b);
+ if (vcpu->vcpu_id == 0) {
+ vmcs_write16(GUEST_CS_SELECTOR, 0xf000);
+ vmcs_writel(GUEST_CS_BASE, 0x000f0000);
+ vmcs_write32(GUEST_CS_LIMIT, 0xffff);
+ vmcs_write32(GUEST_CS_AR_BYTES, 0x9b);
+ vmcs_writel(GUEST_RIP, 0xfff0);
+ }
seg_setup(VCPU_SREG_DS);
seg_setup(VCPU_SREG_ES);
@@ -1288,7 +1292,6 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
vmcs_writel(GUEST_SYSENTER_EIP, 0);
vmcs_writel(GUEST_RFLAGS, 0x02);
- vmcs_writel(GUEST_RIP, 0xfff0);
vmcs_writel(GUEST_RSP, 0);
//todo: dr0 = dr1 = dr2 = dr3 = 0; dr6 = 0xffff0ff0
kvm-smp-vcpu-tss.patch
Description: kvm-smp-vcpu-tss.patch
------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
_______________________________________________ kvm-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/kvm-devel
