diff options
author | Eddie Dong <eddie.dong@intel.com> | 2007-09-06 05:22:56 -0400 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2007-10-13 04:18:25 -0400 |
commit | 96ad2cc6132479aa0aea485d0838a13fda765bd5 (patch) | |
tree | dc3596b92981332cee0749004b7076a7d52a90b1 | |
parent | 6bf9e962d14deb9e460afbbfd83ea2f450325c2d (diff) |
KVM: in-kernel LAPIC save and restore support
This patch adds a new vcpu-based IOCTL to save and restore the local
apic registers for a single vcpu. The kernel only copies the apic page as
a whole, extraction of registers is left to userspace side. On restore, the
APIC timer is restarted from the initial count, this introduces a little
delay, but works fine.
Signed-off-by: Yaozu (Eddie) Dong <eddie.dong@intel.com>
Signed-off-by: Qing He <qing.he@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
-rw-r--r-- | drivers/kvm/irq.h | 1 | ||||
-rw-r--r-- | drivers/kvm/kvm_main.c | 46 | ||||
-rw-r--r-- | drivers/kvm/lapic.c | 13 | ||||
-rw-r--r-- | include/linux/kvm.h | 8 |
4 files changed, 68 insertions, 0 deletions
diff --git a/drivers/kvm/irq.h b/drivers/kvm/irq.h index 30adddcb182d..24b871f9b5fc 100644 --- a/drivers/kvm/irq.h +++ b/drivers/kvm/irq.h | |||
@@ -149,6 +149,7 @@ int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest); | |||
149 | void kvm_ioapic_update_eoi(struct kvm *kvm, int vector); | 149 | void kvm_ioapic_update_eoi(struct kvm *kvm, int vector); |
150 | int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda); | 150 | int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda); |
151 | int kvm_apic_set_irq(struct kvm_lapic *apic, u8 vec, u8 trig); | 151 | int kvm_apic_set_irq(struct kvm_lapic *apic, u8 vec, u8 trig); |
152 | void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu); | ||
152 | int kvm_ioapic_init(struct kvm *kvm); | 153 | int kvm_ioapic_init(struct kvm *kvm); |
153 | void kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level); | 154 | void kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level); |
154 | 155 | ||
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c index 61dff55f137e..a012d70d9eff 100644 --- a/drivers/kvm/kvm_main.c +++ b/drivers/kvm/kvm_main.c | |||
@@ -2642,6 +2642,27 @@ static int kvm_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) | |||
2642 | return 0; | 2642 | return 0; |
2643 | } | 2643 | } |
2644 | 2644 | ||
2645 | static int kvm_vcpu_ioctl_get_lapic(struct kvm_vcpu *vcpu, | ||
2646 | struct kvm_lapic_state *s) | ||
2647 | { | ||
2648 | vcpu_load(vcpu); | ||
2649 | memcpy(s->regs, vcpu->apic->regs, sizeof *s); | ||
2650 | vcpu_put(vcpu); | ||
2651 | |||
2652 | return 0; | ||
2653 | } | ||
2654 | |||
2655 | static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu, | ||
2656 | struct kvm_lapic_state *s) | ||
2657 | { | ||
2658 | vcpu_load(vcpu); | ||
2659 | memcpy(vcpu->apic->regs, s->regs, sizeof *s); | ||
2660 | kvm_apic_post_state_restore(vcpu); | ||
2661 | vcpu_put(vcpu); | ||
2662 | |||
2663 | return 0; | ||
2664 | } | ||
2665 | |||
2645 | static long kvm_vcpu_ioctl(struct file *filp, | 2666 | static long kvm_vcpu_ioctl(struct file *filp, |
2646 | unsigned int ioctl, unsigned long arg) | 2667 | unsigned int ioctl, unsigned long arg) |
2647 | { | 2668 | { |
@@ -2811,6 +2832,31 @@ static long kvm_vcpu_ioctl(struct file *filp, | |||
2811 | r = 0; | 2832 | r = 0; |
2812 | break; | 2833 | break; |
2813 | } | 2834 | } |
2835 | case KVM_GET_LAPIC: { | ||
2836 | struct kvm_lapic_state lapic; | ||
2837 | |||
2838 | memset(&lapic, 0, sizeof lapic); | ||
2839 | r = kvm_vcpu_ioctl_get_lapic(vcpu, &lapic); | ||
2840 | if (r) | ||
2841 | goto out; | ||
2842 | r = -EFAULT; | ||
2843 | if (copy_to_user(argp, &lapic, sizeof lapic)) | ||
2844 | goto out; | ||
2845 | r = 0; | ||
2846 | break; | ||
2847 | } | ||
2848 | case KVM_SET_LAPIC: { | ||
2849 | struct kvm_lapic_state lapic; | ||
2850 | |||
2851 | r = -EFAULT; | ||
2852 | if (copy_from_user(&lapic, argp, sizeof lapic)) | ||
2853 | goto out; | ||
2854 | r = kvm_vcpu_ioctl_set_lapic(vcpu, &lapic);; | ||
2855 | if (r) | ||
2856 | goto out; | ||
2857 | r = 0; | ||
2858 | break; | ||
2859 | } | ||
2814 | default: | 2860 | default: |
2815 | ; | 2861 | ; |
2816 | } | 2862 | } |
diff --git a/drivers/kvm/lapic.c b/drivers/kvm/lapic.c index 4b5c77d8900d..df636bf19798 100644 --- a/drivers/kvm/lapic.c +++ b/drivers/kvm/lapic.c | |||
@@ -931,3 +931,16 @@ int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu) | |||
931 | apic_clear_irr(vector, apic); | 931 | apic_clear_irr(vector, apic); |
932 | return vector; | 932 | return vector; |
933 | } | 933 | } |
934 | |||
935 | void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu) | ||
936 | { | ||
937 | struct kvm_lapic *apic = vcpu->apic; | ||
938 | |||
939 | apic->base_address = vcpu->apic_base & | ||
940 | MSR_IA32_APICBASE_BASE; | ||
941 | apic_set_reg(apic, APIC_LVR, APIC_VERSION); | ||
942 | apic_update_ppr(apic); | ||
943 | hrtimer_cancel(&apic->timer.dev); | ||
944 | update_divide_count(apic); | ||
945 | start_apic_timer(apic); | ||
946 | } | ||
diff --git a/include/linux/kvm.h b/include/linux/kvm.h index 42d15150d7a3..30a83696906c 100644 --- a/include/linux/kvm.h +++ b/include/linux/kvm.h | |||
@@ -208,6 +208,12 @@ struct kvm_fpu { | |||
208 | __u32 pad2; | 208 | __u32 pad2; |
209 | }; | 209 | }; |
210 | 210 | ||
211 | /* for KVM_GET_LAPIC and KVM_SET_LAPIC */ | ||
212 | #define KVM_APIC_REG_SIZE 0x400 | ||
213 | struct kvm_lapic_state { | ||
214 | char regs[KVM_APIC_REG_SIZE]; | ||
215 | }; | ||
216 | |||
211 | struct kvm_segment { | 217 | struct kvm_segment { |
212 | __u64 base; | 218 | __u64 base; |
213 | __u32 limit; | 219 | __u32 limit; |
@@ -380,5 +386,7 @@ struct kvm_signal_mask { | |||
380 | #define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask) | 386 | #define KVM_SET_SIGNAL_MASK _IOW(KVMIO, 0x8b, struct kvm_signal_mask) |
381 | #define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu) | 387 | #define KVM_GET_FPU _IOR(KVMIO, 0x8c, struct kvm_fpu) |
382 | #define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu) | 388 | #define KVM_SET_FPU _IOW(KVMIO, 0x8d, struct kvm_fpu) |
389 | #define KVM_GET_LAPIC _IOR(KVMIO, 0x8e, struct kvm_lapic_state) | ||
390 | #define KVM_SET_LAPIC _IOW(KVMIO, 0x8f, struct kvm_lapic_state) | ||
383 | 391 | ||
384 | #endif | 392 | #endif |