KVM: SMP: Add vcpu_id field in struct vcpu
authorQing He <qing.he@intel.com>
Thu, 12 Jul 2007 09:33:56 +0000 (12:33 +0300)
committerAvi Kivity <avi@qumranet.com>
Sat, 13 Oct 2007 08:18:17 +0000 (10:18 +0200)
This patch adds a `vcpu_id' field in `struct vcpu', so we can
differentiate BSP and APs without pointer comparison or arithmetic.

Signed-off-by: Qing He <qing.he@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
drivers/kvm/kvm.h
drivers/kvm/kvm_main.c
drivers/kvm/svm.c
drivers/kvm/vmx.c

index 336be86c6f5a9c023556a4b8703152213df094fb..b629a83eb82d6bc5ac958f241da47433d0f1ebb7 100644 (file)
@@ -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;
index 36a458f13ec4fbc87a1c3a3aa4dd3267df93db4c..df9c05e9b34ea8c0a97d366de919636ba21e19ee 100644 (file)
@@ -2355,6 +2355,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);
 
index bc818cc126e385f7556df64614062aafc66b1102..52a11ccdf0c29e0f7885243bf8207e0a1f5f094a 100644 (file)
@@ -591,7 +591,7 @@ static int svm_create_vcpu(struct kvm_vcpu *vcpu)
        fx_init(vcpu);
        vcpu->fpu_active = 1;
        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;
 
        return 0;
index 80628f69916d85c0c58f02f126ff62cf778ea855..7fa62c780ce4d5fa58342a57d9bc2ab0b3e459c5 100644 (file)
@@ -1253,7 +1253,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);