From: Zhang Xiantao <[EMAIL PROTECTED]> Date: Fri, 14 Dec 2007 00:33:56 +0800 Subject: [PATCH] kvm portability: Moving apic and apic_base to kvm_vcpu arch.
This patches moving apic and apic_base to kvm_vcpu_arch.
And use a macro apic(v) to simplifily get apic from vcpu.
Signed-off-by: Zhang Xiantao <[EMAIL PROTECTED]>
---
drivers/kvm/ioapic.c | 10 +++---
drivers/kvm/lapic.c | 75
++++++++++++++++++++++++++------------------------
drivers/kvm/svm.c | 4 +-
drivers/kvm/vmx.c | 2 +-
drivers/kvm/x86.c | 14 ++++----
drivers/kvm/x86.h | 4 +-
6 files changed, 56 insertions(+), 53 deletions(-)
diff --git a/drivers/kvm/ioapic.c b/drivers/kvm/ioapic.c
index e7debfa..0491036 100644
--- a/drivers/kvm/ioapic.c
+++ b/drivers/kvm/ioapic.c
@@ -158,7 +158,7 @@ static u32 ioapic_get_delivery_bitmask(struct
kvm_ioapic *ioapic, u8 dest,
if (dest_mode == 0) { /* Physical mode. */
if (dest == 0xFF) { /* Broadcast. */
for (i = 0; i < KVM_MAX_VCPUS; ++i)
- if (kvm->vcpus[i] &&
kvm->vcpus[i]->apic)
+ if (kvm->vcpus[i] &&
kvm->vcpus[i]->arch.apic)
mask |= 1 << i;
return mask;
}
@@ -166,8 +166,8 @@ static u32 ioapic_get_delivery_bitmask(struct
kvm_ioapic *ioapic, u8 dest,
vcpu = kvm->vcpus[i];
if (!vcpu)
continue;
- if (kvm_apic_match_physical_addr(vcpu->apic,
dest)) {
- if (vcpu->apic)
+ if
(kvm_apic_match_physical_addr(vcpu->arch.apic, dest)) {
+ if (vcpu->arch.apic)
mask = 1 << i;
break;
}
@@ -177,8 +177,8 @@ static u32 ioapic_get_delivery_bitmask(struct
kvm_ioapic *ioapic, u8 dest,
vcpu = kvm->vcpus[i];
if (!vcpu)
continue;
- if (vcpu->apic &&
- kvm_apic_match_logical_addr(vcpu->apic,
dest))
+ if (vcpu->arch.apic &&
+ kvm_apic_match_logical_addr(vcpu->arch.apic,
dest))
mask |= 1 << vcpu->vcpu_id;
}
ioapic_debug("mask %x\n", mask);
diff --git a/drivers/kvm/lapic.c b/drivers/kvm/lapic.c
index 466c37f..77a6252 100644
--- a/drivers/kvm/lapic.c
+++ b/drivers/kvm/lapic.c
@@ -58,6 +58,9 @@
#define VEC_POS(v) ((v) & (32 - 1))
#define REG_POS(v) (((v) >> 5) << 4)
+
+#define apic(v) ((v)->arch.apic)
+
static inline u32 apic_get_reg(struct kvm_lapic *apic, int reg_off)
{
return *((u32 *) (apic->regs + reg_off));
@@ -90,7 +93,7 @@ static inline void apic_clear_vector(int vec, void
*bitmap)
static inline int apic_hw_enabled(struct kvm_lapic *apic)
{
- return (apic)->vcpu->apic_base & MSR_IA32_APICBASE_ENABLE;
+ return (apic)->vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE;
}
static inline int apic_sw_enabled(struct kvm_lapic *apic)
@@ -174,7 +177,7 @@ static inline int apic_find_highest_irr(struct
kvm_lapic *apic)
int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu)
{
- struct kvm_lapic *apic = vcpu->apic;
+ struct kvm_lapic *apic = apic(vcpu);
int highest_irr;
if (!apic)
@@ -187,7 +190,7 @@ EXPORT_SYMBOL_GPL(kvm_lapic_find_highest_irr);
int kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 trig)
{
- struct kvm_lapic *apic = vcpu->apic;
+ struct kvm_lapic *apic = apic(vcpu);
if (!apic_test_and_set_irr(vec, apic)) {
/* a new pending irq is set in IRR */
@@ -272,7 +275,7 @@ static int apic_match_dest(struct kvm_vcpu *vcpu,
struct kvm_lapic *source,
int short_hand, int dest, int dest_mode)
{
int result = 0;
- struct kvm_lapic *target = vcpu->apic;
+ struct kvm_lapic *target = apic(vcpu);
apic_debug("target %p, source %p, dest 0x%x, "
"dest_mode 0x%x, short_hand 0x%x",
@@ -411,7 +414,7 @@ static struct kvm_lapic *kvm_apic_round_robin(struct
kvm *kvm, u8 vector,
next = 0;
if (kvm->vcpus[next] == NULL || !test_bit(next,
&bitmap))
continue;
- apic = kvm->vcpus[next]->apic;
+ apic = kvm->vcpus[next]->arch.apic;
if (apic && apic_enabled(apic))
break;
apic = NULL;
@@ -482,12 +485,12 @@ static void apic_send_ipi(struct kvm_lapic *apic)
if (!vcpu)
continue;
- if (vcpu->apic &&
+ if (apic(vcpu) &&
apic_match_dest(vcpu, apic, short_hand, dest,
dest_mode)) {
if (delivery_mode == APIC_DM_LOWEST)
set_bit(vcpu->vcpu_id, &lpr_map);
else
- __apic_accept_irq(vcpu->apic,
delivery_mode,
+ __apic_accept_irq(apic(vcpu),
delivery_mode,
vector, level,
trig_mode);
}
}
@@ -495,7 +498,7 @@ static void apic_send_ipi(struct kvm_lapic *apic)
if (delivery_mode == APIC_DM_LOWEST) {
target = kvm_get_lowest_prio_vcpu(vcpu->kvm, vector,
lpr_map);
if (target != NULL)
- __apic_accept_irq(target->apic, delivery_mode,
+ __apic_accept_irq(target->arch.apic,
delivery_mode,
vector, level, trig_mode);
}
}
@@ -772,15 +775,15 @@ static int apic_mmio_range(struct kvm_io_device
*this, gpa_t addr)
void kvm_free_lapic(struct kvm_vcpu *vcpu)
{
- if (!vcpu->apic)
+ if (!apic(vcpu))
return;
- hrtimer_cancel(&vcpu->apic->timer.dev);
+ hrtimer_cancel(&apic(vcpu)->timer.dev);
- if (vcpu->apic->regs_page)
- __free_page(vcpu->apic->regs_page);
+ if (apic(vcpu)->regs_page)
+ __free_page(apic(vcpu)->regs_page);
- kfree(vcpu->apic);
+ kfree(apic(vcpu));
}
/*
@@ -791,7 +794,7 @@ void kvm_free_lapic(struct kvm_vcpu *vcpu)
void kvm_lapic_set_tpr(struct kvm_vcpu *vcpu, unsigned long cr8)
{
- struct kvm_lapic *apic = vcpu->apic;
+ struct kvm_lapic *apic = apic(vcpu);
if (!apic)
return;
@@ -800,7 +803,7 @@ void kvm_lapic_set_tpr(struct kvm_vcpu *vcpu,
unsigned long cr8)
u64 kvm_lapic_get_cr8(struct kvm_vcpu *vcpu)
{
- struct kvm_lapic *apic = vcpu->apic;
+ struct kvm_lapic *apic = apic(vcpu);
u64 tpr;
if (!apic)
@@ -813,29 +816,29 @@ EXPORT_SYMBOL_GPL(kvm_lapic_get_cr8);
void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value)
{
- struct kvm_lapic *apic = vcpu->apic;
+ struct kvm_lapic *apic = apic(vcpu);
if (!apic) {
value |= MSR_IA32_APICBASE_BSP;
- vcpu->apic_base = value;
+ vcpu->arch.apic_base = value;
return;
}
if (apic->vcpu->vcpu_id)
value &= ~MSR_IA32_APICBASE_BSP;
- vcpu->apic_base = value;
- apic->base_address = apic->vcpu->apic_base &
+ vcpu->arch.apic_base = value;
+ apic->base_address = apic->vcpu->arch.apic_base &
MSR_IA32_APICBASE_BASE;
/* with FSB delivery interrupt, we can restart APIC
functionality */
apic_debug("apic base msr is 0x%016" PRIx64 ", and base address
is "
- "0x%lx.\n", apic->vcpu->apic_base,
apic->base_address);
+ "0x%lx.\n", apic->vcpu->arch.apic_base,
apic->base_address);
}
u64 kvm_lapic_get_base(struct kvm_vcpu *vcpu)
{
- return vcpu->apic_base;
+ return vcpu->arch.apic_base;
}
EXPORT_SYMBOL_GPL(kvm_lapic_get_base);
@@ -847,7 +850,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu)
apic_debug("%s\n", __FUNCTION__);
ASSERT(vcpu);
- apic = vcpu->apic;
+ apic = apic(vcpu);
ASSERT(apic != NULL);
/* Stop the timer in case it's a reset to an active apic */
@@ -878,19 +881,19 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu)
update_divide_count(apic);
atomic_set(&apic->timer.pending, 0);
if (vcpu->vcpu_id == 0)
- vcpu->apic_base |= MSR_IA32_APICBASE_BSP;
+ vcpu->arch.apic_base |= MSR_IA32_APICBASE_BSP;
apic_update_ppr(apic);
apic_debug(KERN_INFO "%s: vcpu=%p, id=%d, base_msr="
"0x%016" PRIx64 ", base_address=0x%0lx.\n",
__FUNCTION__,
vcpu, kvm_apic_id(apic),
- vcpu->apic_base, apic->base_address);
+ vcpu->arch.apic_base, apic->base_address);
}
EXPORT_SYMBOL_GPL(kvm_lapic_reset);
int kvm_lapic_enabled(struct kvm_vcpu *vcpu)
{
- struct kvm_lapic *apic = vcpu->apic;
+ struct kvm_lapic *apic = apic(vcpu);
int ret = 0;
if (!apic)
@@ -961,7 +964,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
if (!apic)
goto nomem;
- vcpu->apic = apic;
+ apic(vcpu) = apic;
apic->regs_page = alloc_page(GFP_KERNEL);
if (apic->regs_page == NULL) {
@@ -976,7 +979,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
hrtimer_init(&apic->timer.dev, CLOCK_MONOTONIC,
HRTIMER_MODE_ABS);
apic->timer.dev.function = apic_timer_fn;
apic->base_address = APIC_DEFAULT_PHYS_BASE;
- vcpu->apic_base = APIC_DEFAULT_PHYS_BASE;
+ vcpu->arch.apic_base = APIC_DEFAULT_PHYS_BASE;
kvm_lapic_reset(vcpu);
apic->dev.read = apic_mmio_read;
@@ -994,7 +997,7 @@ EXPORT_SYMBOL_GPL(kvm_create_lapic);
int kvm_apic_has_interrupt(struct kvm_vcpu *vcpu)
{
- struct kvm_lapic *apic = vcpu->apic;
+ struct kvm_lapic *apic = apic(vcpu);
int highest_irr;
if (!apic || !apic_enabled(apic))
@@ -1010,11 +1013,11 @@ int kvm_apic_has_interrupt(struct kvm_vcpu
*vcpu)
int kvm_apic_accept_pic_intr(struct kvm_vcpu *vcpu)
{
- u32 lvt0 = apic_get_reg(vcpu->apic, APIC_LVT0);
+ u32 lvt0 = apic_get_reg(apic(vcpu), APIC_LVT0);
int r = 0;
if (vcpu->vcpu_id == 0) {
- if (!apic_hw_enabled(vcpu->apic))
+ if (!apic_hw_enabled(apic(vcpu)))
r = 1;
if ((lvt0 & APIC_LVT_MASKED) == 0 &&
GET_APIC_DELIVERY_MODE(lvt0) == APIC_MODE_EXTINT)
@@ -1025,7 +1028,7 @@ int kvm_apic_accept_pic_intr(struct kvm_vcpu
*vcpu)
void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu)
{
- struct kvm_lapic *apic = vcpu->apic;
+ struct kvm_lapic *apic = apic(vcpu);
if (apic && apic_lvt_enabled(apic, APIC_LVTT) &&
atomic_read(&apic->timer.pending) > 0) {
@@ -1036,7 +1039,7 @@ void kvm_inject_apic_timer_irqs(struct kvm_vcpu
*vcpu)
void kvm_apic_timer_intr_post(struct kvm_vcpu *vcpu, int vec)
{
- struct kvm_lapic *apic = vcpu->apic;
+ struct kvm_lapic *apic = apic(vcpu);
if (apic && apic_lvt_vector(apic, APIC_LVTT) == vec)
apic->timer.last_update = ktime_add_ns(
@@ -1047,7 +1050,7 @@ void kvm_apic_timer_intr_post(struct kvm_vcpu
*vcpu, int vec)
int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu)
{
int vector = kvm_apic_has_interrupt(vcpu);
- struct kvm_lapic *apic = vcpu->apic;
+ struct kvm_lapic *apic = apic(vcpu);
if (vector == -1)
return -1;
@@ -1060,9 +1063,9 @@ int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu)
void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu)
{
- struct kvm_lapic *apic = vcpu->apic;
+ struct kvm_lapic *apic = apic(vcpu);
- apic->base_address = vcpu->apic_base &
+ apic->base_address = vcpu->arch.apic_base &
MSR_IA32_APICBASE_BASE;
apic_set_reg(apic, APIC_LVR, APIC_VERSION);
apic_update_ppr(apic);
@@ -1073,7 +1076,7 @@ void kvm_apic_post_state_restore(struct kvm_vcpu
*vcpu)
void kvm_migrate_apic_timer(struct kvm_vcpu *vcpu)
{
- struct kvm_lapic *apic = vcpu->apic;
+ struct kvm_lapic *apic = apic(vcpu);
struct hrtimer *timer;
if (!apic)
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 3650e35..f937292 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -597,9 +597,9 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm
*kvm, unsigned int id)
fx_init(&svm->vcpu);
svm->vcpu.fpu_active = 1;
- svm->vcpu.apic_base = 0xfee00000 | MSR_IA32_APICBASE_ENABLE;
+ svm->vcpu.arch.apic_base = 0xfee00000 |
MSR_IA32_APICBASE_ENABLE;
if (svm->vcpu.vcpu_id == 0)
- svm->vcpu.apic_base |= MSR_IA32_APICBASE_BSP;
+ svm->vcpu.arch.apic_base |= MSR_IA32_APICBASE_BSP;
return &svm->vcpu;
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index d94b925..5e9a542 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -1691,7 +1691,7 @@ static int vmx_vcpu_reset(struct kvm_vcpu *vcpu)
vmcs_write64(VIRTUAL_APIC_PAGE_ADDR, 0);
if (vm_need_tpr_shadow(vmx->vcpu.kvm))
vmcs_write64(VIRTUAL_APIC_PAGE_ADDR,
-
page_to_phys(vmx->vcpu.apic->regs_page));
+
page_to_phys(vmx->vcpu.arch.apic->regs_page));
vmcs_write32(TPR_THRESHOLD, 0);
}
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index f3adc15..a173bea 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -113,9 +113,9 @@ EXPORT_SYMBOL_GPL(segment_base);
u64 kvm_get_apic_base(struct kvm_vcpu *vcpu)
{
if (irqchip_in_kernel(vcpu->kvm))
- return vcpu->apic_base;
+ return vcpu->arch.apic_base;
else
- return vcpu->apic_base;
+ return vcpu->arch.apic_base;
}
EXPORT_SYMBOL_GPL(kvm_get_apic_base);
@@ -125,7 +125,7 @@ void kvm_set_apic_base(struct kvm_vcpu *vcpu, u64
data)
if (irqchip_in_kernel(vcpu->kvm))
kvm_lapic_set_base(vcpu, data);
else
- vcpu->apic_base = data;
+ vcpu->arch.apic_base = data;
}
EXPORT_SYMBOL_GPL(kvm_set_apic_base);
@@ -1021,7 +1021,7 @@ static int kvm_vcpu_ioctl_get_lapic(struct
kvm_vcpu *vcpu,
struct kvm_lapic_state *s)
{
vcpu_load(vcpu);
- memcpy(s->regs, vcpu->apic->regs, sizeof *s);
+ memcpy(s->regs, vcpu->arch.apic->regs, sizeof *s);
vcpu_put(vcpu);
return 0;
@@ -1031,7 +1031,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct
kvm_vcpu *vcpu,
struct kvm_lapic_state *s)
{
vcpu_load(vcpu);
- memcpy(vcpu->apic->regs, s->regs, sizeof *s);
+ memcpy(vcpu->arch.apic->regs, s->regs, sizeof *s);
kvm_apic_post_state_restore(vcpu);
vcpu_put(vcpu);
@@ -1499,8 +1499,8 @@ static struct kvm_io_device
*vcpu_find_pervcpu_dev(struct kvm_vcpu *vcpu,
{
struct kvm_io_device *dev;
- if (vcpu->apic) {
- dev = &vcpu->apic->dev;
+ if (vcpu->arch.apic) {
+ dev = &vcpu->arch.apic->dev;
if (dev->in_range(dev, addr))
return dev;
}
diff --git a/drivers/kvm/x86.h b/drivers/kvm/x86.h
index 8f5b875..568cdb1 100644
--- a/drivers/kvm/x86.h
+++ b/drivers/kvm/x86.h
@@ -107,12 +107,12 @@ struct kvm_vcpu_arch {
unsigned long cr8;
u64 pdptrs[4]; /* pae */
u64 shadow_efer;
+ u64 apic_base;
+ struct kvm_lapic *apic; /* kernel irqchip context */
};
struct kvm_vcpu {
KVM_VCPU_COMM;
- u64 apic_base;
- struct kvm_lapic *apic; /* kernel irqchip context */
#define VCPU_MP_STATE_RUNNABLE 0
#define VCPU_MP_STATE_UNINITIALIZED 1
#define VCPU_MP_STATE_INIT_RECEIVED 2
--
1.5.1.2
0005-kvm-portability-Moving-apic-and-apic_base-to-kvm_vc.patch
Description: 0005-kvm-portability-Moving-apic-and-apic_base-to-kvm_vc.patch
------------------------------------------------------------------------- SF.Net email is sponsored by: Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________ kvm-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/kvm-devel
