diff options
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r-- | arch/x86/kvm/x86.c | 568 |
1 files changed, 451 insertions, 117 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ae07d261527c..9d068966fb2a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -37,11 +37,13 @@ | |||
37 | #include <linux/iommu.h> | 37 | #include <linux/iommu.h> |
38 | #include <linux/intel-iommu.h> | 38 | #include <linux/intel-iommu.h> |
39 | #include <linux/cpufreq.h> | 39 | #include <linux/cpufreq.h> |
40 | #include <linux/user-return-notifier.h> | ||
40 | #include <trace/events/kvm.h> | 41 | #include <trace/events/kvm.h> |
41 | #undef TRACE_INCLUDE_FILE | 42 | #undef TRACE_INCLUDE_FILE |
42 | #define CREATE_TRACE_POINTS | 43 | #define CREATE_TRACE_POINTS |
43 | #include "trace.h" | 44 | #include "trace.h" |
44 | 45 | ||
46 | #include <asm/debugreg.h> | ||
45 | #include <asm/uaccess.h> | 47 | #include <asm/uaccess.h> |
46 | #include <asm/msr.h> | 48 | #include <asm/msr.h> |
47 | #include <asm/desc.h> | 49 | #include <asm/desc.h> |
@@ -87,6 +89,25 @@ EXPORT_SYMBOL_GPL(kvm_x86_ops); | |||
87 | int ignore_msrs = 0; | 89 | int ignore_msrs = 0; |
88 | module_param_named(ignore_msrs, ignore_msrs, bool, S_IRUGO | S_IWUSR); | 90 | module_param_named(ignore_msrs, ignore_msrs, bool, S_IRUGO | S_IWUSR); |
89 | 91 | ||
92 | #define KVM_NR_SHARED_MSRS 16 | ||
93 | |||
94 | struct kvm_shared_msrs_global { | ||
95 | int nr; | ||
96 | struct kvm_shared_msr { | ||
97 | u32 msr; | ||
98 | u64 value; | ||
99 | } msrs[KVM_NR_SHARED_MSRS]; | ||
100 | }; | ||
101 | |||
102 | struct kvm_shared_msrs { | ||
103 | struct user_return_notifier urn; | ||
104 | bool registered; | ||
105 | u64 current_value[KVM_NR_SHARED_MSRS]; | ||
106 | }; | ||
107 | |||
108 | static struct kvm_shared_msrs_global __read_mostly shared_msrs_global; | ||
109 | static DEFINE_PER_CPU(struct kvm_shared_msrs, shared_msrs); | ||
110 | |||
90 | struct kvm_stats_debugfs_item debugfs_entries[] = { | 111 | struct kvm_stats_debugfs_item debugfs_entries[] = { |
91 | { "pf_fixed", VCPU_STAT(pf_fixed) }, | 112 | { "pf_fixed", VCPU_STAT(pf_fixed) }, |
92 | { "pf_guest", VCPU_STAT(pf_guest) }, | 113 | { "pf_guest", VCPU_STAT(pf_guest) }, |
@@ -123,6 +144,72 @@ struct kvm_stats_debugfs_item debugfs_entries[] = { | |||
123 | { NULL } | 144 | { NULL } |
124 | }; | 145 | }; |
125 | 146 | ||
147 | static void kvm_on_user_return(struct user_return_notifier *urn) | ||
148 | { | ||
149 | unsigned slot; | ||
150 | struct kvm_shared_msr *global; | ||
151 | struct kvm_shared_msrs *locals | ||
152 | = container_of(urn, struct kvm_shared_msrs, urn); | ||
153 | |||
154 | for (slot = 0; slot < shared_msrs_global.nr; ++slot) { | ||
155 | global = &shared_msrs_global.msrs[slot]; | ||
156 | if (global->value != locals->current_value[slot]) { | ||
157 | wrmsrl(global->msr, global->value); | ||
158 | locals->current_value[slot] = global->value; | ||
159 | } | ||
160 | } | ||
161 | locals->registered = false; | ||
162 | user_return_notifier_unregister(urn); | ||
163 | } | ||
164 | |||
165 | void kvm_define_shared_msr(unsigned slot, u32 msr) | ||
166 | { | ||
167 | int cpu; | ||
168 | u64 value; | ||
169 | |||
170 | if (slot >= shared_msrs_global.nr) | ||
171 | shared_msrs_global.nr = slot + 1; | ||
172 | shared_msrs_global.msrs[slot].msr = msr; | ||
173 | rdmsrl_safe(msr, &value); | ||
174 | shared_msrs_global.msrs[slot].value = value; | ||
175 | for_each_online_cpu(cpu) | ||
176 | per_cpu(shared_msrs, cpu).current_value[slot] = value; | ||
177 | } | ||
178 | EXPORT_SYMBOL_GPL(kvm_define_shared_msr); | ||
179 | |||
180 | static void kvm_shared_msr_cpu_online(void) | ||
181 | { | ||
182 | unsigned i; | ||
183 | struct kvm_shared_msrs *locals = &__get_cpu_var(shared_msrs); | ||
184 | |||
185 | for (i = 0; i < shared_msrs_global.nr; ++i) | ||
186 | locals->current_value[i] = shared_msrs_global.msrs[i].value; | ||
187 | } | ||
188 | |||
189 | void kvm_set_shared_msr(unsigned slot, u64 value, u64 mask) | ||
190 | { | ||
191 | struct kvm_shared_msrs *smsr = &__get_cpu_var(shared_msrs); | ||
192 | |||
193 | if (((value ^ smsr->current_value[slot]) & mask) == 0) | ||
194 | return; | ||
195 | smsr->current_value[slot] = value; | ||
196 | wrmsrl(shared_msrs_global.msrs[slot].msr, value); | ||
197 | if (!smsr->registered) { | ||
198 | smsr->urn.on_user_return = kvm_on_user_return; | ||
199 | user_return_notifier_register(&smsr->urn); | ||
200 | smsr->registered = true; | ||
201 | } | ||
202 | } | ||
203 | EXPORT_SYMBOL_GPL(kvm_set_shared_msr); | ||
204 | |||
205 | static void drop_user_return_notifiers(void *ignore) | ||
206 | { | ||
207 | struct kvm_shared_msrs *smsr = &__get_cpu_var(shared_msrs); | ||
208 | |||
209 | if (smsr->registered) | ||
210 | kvm_on_user_return(&smsr->urn); | ||
211 | } | ||
212 | |||
126 | unsigned long segment_base(u16 selector) | 213 | unsigned long segment_base(u16 selector) |
127 | { | 214 | { |
128 | struct descriptor_table gdt; | 215 | struct descriptor_table gdt; |
@@ -484,16 +571,19 @@ static inline u32 bit(int bitno) | |||
484 | * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST. | 571 | * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST. |
485 | * | 572 | * |
486 | * This list is modified at module load time to reflect the | 573 | * This list is modified at module load time to reflect the |
487 | * capabilities of the host cpu. | 574 | * capabilities of the host cpu. This capabilities test skips MSRs that are |
575 | * kvm-specific. Those are put in the beginning of the list. | ||
488 | */ | 576 | */ |
577 | |||
578 | #define KVM_SAVE_MSRS_BEGIN 2 | ||
489 | static u32 msrs_to_save[] = { | 579 | static u32 msrs_to_save[] = { |
580 | MSR_KVM_SYSTEM_TIME, MSR_KVM_WALL_CLOCK, | ||
490 | MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP, | 581 | MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP, |
491 | MSR_K6_STAR, | 582 | MSR_K6_STAR, |
492 | #ifdef CONFIG_X86_64 | 583 | #ifdef CONFIG_X86_64 |
493 | MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR, | 584 | MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR, |
494 | #endif | 585 | #endif |
495 | MSR_IA32_TSC, MSR_KVM_SYSTEM_TIME, MSR_KVM_WALL_CLOCK, | 586 | MSR_IA32_TSC, MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA |
496 | MSR_IA32_PERF_STATUS, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA | ||
497 | }; | 587 | }; |
498 | 588 | ||
499 | static unsigned num_msrs_to_save; | 589 | static unsigned num_msrs_to_save; |
@@ -677,7 +767,8 @@ static void kvm_write_guest_time(struct kvm_vcpu *v) | |||
677 | /* With all the info we got, fill in the values */ | 767 | /* With all the info we got, fill in the values */ |
678 | 768 | ||
679 | vcpu->hv_clock.system_time = ts.tv_nsec + | 769 | vcpu->hv_clock.system_time = ts.tv_nsec + |
680 | (NSEC_PER_SEC * (u64)ts.tv_sec); | 770 | (NSEC_PER_SEC * (u64)ts.tv_sec) + v->kvm->arch.kvmclock_offset; |
771 | |||
681 | /* | 772 | /* |
682 | * The interface expects us to write an even number signaling that the | 773 | * The interface expects us to write an even number signaling that the |
683 | * update is finished. Since the guest won't see the intermediate | 774 | * update is finished. Since the guest won't see the intermediate |
@@ -835,6 +926,38 @@ static int set_msr_mce(struct kvm_vcpu *vcpu, u32 msr, u64 data) | |||
835 | return 0; | 926 | return 0; |
836 | } | 927 | } |
837 | 928 | ||
929 | static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data) | ||
930 | { | ||
931 | struct kvm *kvm = vcpu->kvm; | ||
932 | int lm = is_long_mode(vcpu); | ||
933 | u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64 | ||
934 | : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32; | ||
935 | u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64 | ||
936 | : kvm->arch.xen_hvm_config.blob_size_32; | ||
937 | u32 page_num = data & ~PAGE_MASK; | ||
938 | u64 page_addr = data & PAGE_MASK; | ||
939 | u8 *page; | ||
940 | int r; | ||
941 | |||
942 | r = -E2BIG; | ||
943 | if (page_num >= blob_size) | ||
944 | goto out; | ||
945 | r = -ENOMEM; | ||
946 | page = kzalloc(PAGE_SIZE, GFP_KERNEL); | ||
947 | if (!page) | ||
948 | goto out; | ||
949 | r = -EFAULT; | ||
950 | if (copy_from_user(page, blob_addr + (page_num * PAGE_SIZE), PAGE_SIZE)) | ||
951 | goto out_free; | ||
952 | if (kvm_write_guest(kvm, page_addr, page, PAGE_SIZE)) | ||
953 | goto out_free; | ||
954 | r = 0; | ||
955 | out_free: | ||
956 | kfree(page); | ||
957 | out: | ||
958 | return r; | ||
959 | } | ||
960 | |||
838 | int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data) | 961 | int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data) |
839 | { | 962 | { |
840 | switch (msr) { | 963 | switch (msr) { |
@@ -950,6 +1073,8 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data) | |||
950 | "0x%x data 0x%llx\n", msr, data); | 1073 | "0x%x data 0x%llx\n", msr, data); |
951 | break; | 1074 | break; |
952 | default: | 1075 | default: |
1076 | if (msr && (msr == vcpu->kvm->arch.xen_hvm_config.msr)) | ||
1077 | return xen_hvm_config(vcpu, data); | ||
953 | if (!ignore_msrs) { | 1078 | if (!ignore_msrs) { |
954 | pr_unimpl(vcpu, "unhandled wrmsr: 0x%x data %llx\n", | 1079 | pr_unimpl(vcpu, "unhandled wrmsr: 0x%x data %llx\n", |
955 | msr, data); | 1080 | msr, data); |
@@ -1224,6 +1349,9 @@ int kvm_dev_ioctl_check_extension(long ext) | |||
1224 | case KVM_CAP_PIT2: | 1349 | case KVM_CAP_PIT2: |
1225 | case KVM_CAP_PIT_STATE2: | 1350 | case KVM_CAP_PIT_STATE2: |
1226 | case KVM_CAP_SET_IDENTITY_MAP_ADDR: | 1351 | case KVM_CAP_SET_IDENTITY_MAP_ADDR: |
1352 | case KVM_CAP_XEN_HVM: | ||
1353 | case KVM_CAP_ADJUST_CLOCK: | ||
1354 | case KVM_CAP_VCPU_EVENTS: | ||
1227 | r = 1; | 1355 | r = 1; |
1228 | break; | 1356 | break; |
1229 | case KVM_CAP_COALESCED_MMIO: | 1357 | case KVM_CAP_COALESCED_MMIO: |
@@ -1238,8 +1366,8 @@ int kvm_dev_ioctl_check_extension(long ext) | |||
1238 | case KVM_CAP_NR_MEMSLOTS: | 1366 | case KVM_CAP_NR_MEMSLOTS: |
1239 | r = KVM_MEMORY_SLOTS; | 1367 | r = KVM_MEMORY_SLOTS; |
1240 | break; | 1368 | break; |
1241 | case KVM_CAP_PV_MMU: | 1369 | case KVM_CAP_PV_MMU: /* obsolete */ |
1242 | r = !tdp_enabled; | 1370 | r = 0; |
1243 | break; | 1371 | break; |
1244 | case KVM_CAP_IOMMU: | 1372 | case KVM_CAP_IOMMU: |
1245 | r = iommu_found(); | 1373 | r = iommu_found(); |
@@ -1326,6 +1454,12 @@ out: | |||
1326 | void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) | 1454 | void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) |
1327 | { | 1455 | { |
1328 | kvm_x86_ops->vcpu_load(vcpu, cpu); | 1456 | kvm_x86_ops->vcpu_load(vcpu, cpu); |
1457 | if (unlikely(per_cpu(cpu_tsc_khz, cpu) == 0)) { | ||
1458 | unsigned long khz = cpufreq_quick_get(cpu); | ||
1459 | if (!khz) | ||
1460 | khz = tsc_khz; | ||
1461 | per_cpu(cpu_tsc_khz, cpu) = khz; | ||
1462 | } | ||
1329 | kvm_request_guest_time_update(vcpu); | 1463 | kvm_request_guest_time_update(vcpu); |
1330 | } | 1464 | } |
1331 | 1465 | ||
@@ -1759,6 +1893,61 @@ static int kvm_vcpu_ioctl_x86_set_mce(struct kvm_vcpu *vcpu, | |||
1759 | return 0; | 1893 | return 0; |
1760 | } | 1894 | } |
1761 | 1895 | ||
1896 | static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu, | ||
1897 | struct kvm_vcpu_events *events) | ||
1898 | { | ||
1899 | vcpu_load(vcpu); | ||
1900 | |||
1901 | events->exception.injected = vcpu->arch.exception.pending; | ||
1902 | events->exception.nr = vcpu->arch.exception.nr; | ||
1903 | events->exception.has_error_code = vcpu->arch.exception.has_error_code; | ||
1904 | events->exception.error_code = vcpu->arch.exception.error_code; | ||
1905 | |||
1906 | events->interrupt.injected = vcpu->arch.interrupt.pending; | ||
1907 | events->interrupt.nr = vcpu->arch.interrupt.nr; | ||
1908 | events->interrupt.soft = vcpu->arch.interrupt.soft; | ||
1909 | |||
1910 | events->nmi.injected = vcpu->arch.nmi_injected; | ||
1911 | events->nmi.pending = vcpu->arch.nmi_pending; | ||
1912 | events->nmi.masked = kvm_x86_ops->get_nmi_mask(vcpu); | ||
1913 | |||
1914 | events->sipi_vector = vcpu->arch.sipi_vector; | ||
1915 | |||
1916 | events->flags = 0; | ||
1917 | |||
1918 | vcpu_put(vcpu); | ||
1919 | } | ||
1920 | |||
1921 | static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu, | ||
1922 | struct kvm_vcpu_events *events) | ||
1923 | { | ||
1924 | if (events->flags) | ||
1925 | return -EINVAL; | ||
1926 | |||
1927 | vcpu_load(vcpu); | ||
1928 | |||
1929 | vcpu->arch.exception.pending = events->exception.injected; | ||
1930 | vcpu->arch.exception.nr = events->exception.nr; | ||
1931 | vcpu->arch.exception.has_error_code = events->exception.has_error_code; | ||
1932 | vcpu->arch.exception.error_code = events->exception.error_code; | ||
1933 | |||
1934 | vcpu->arch.interrupt.pending = events->interrupt.injected; | ||
1935 | vcpu->arch.interrupt.nr = events->interrupt.nr; | ||
1936 | vcpu->arch.interrupt.soft = events->interrupt.soft; | ||
1937 | if (vcpu->arch.interrupt.pending && irqchip_in_kernel(vcpu->kvm)) | ||
1938 | kvm_pic_clear_isr_ack(vcpu->kvm); | ||
1939 | |||
1940 | vcpu->arch.nmi_injected = events->nmi.injected; | ||
1941 | vcpu->arch.nmi_pending = events->nmi.pending; | ||
1942 | kvm_x86_ops->set_nmi_mask(vcpu, events->nmi.masked); | ||
1943 | |||
1944 | vcpu->arch.sipi_vector = events->sipi_vector; | ||
1945 | |||
1946 | vcpu_put(vcpu); | ||
1947 | |||
1948 | return 0; | ||
1949 | } | ||
1950 | |||
1762 | long kvm_arch_vcpu_ioctl(struct file *filp, | 1951 | long kvm_arch_vcpu_ioctl(struct file *filp, |
1763 | unsigned int ioctl, unsigned long arg) | 1952 | unsigned int ioctl, unsigned long arg) |
1764 | { | 1953 | { |
@@ -1769,6 +1958,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp, | |||
1769 | 1958 | ||
1770 | switch (ioctl) { | 1959 | switch (ioctl) { |
1771 | case KVM_GET_LAPIC: { | 1960 | case KVM_GET_LAPIC: { |
1961 | r = -EINVAL; | ||
1962 | if (!vcpu->arch.apic) | ||
1963 | goto out; | ||
1772 | lapic = kzalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL); | 1964 | lapic = kzalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL); |
1773 | 1965 | ||
1774 | r = -ENOMEM; | 1966 | r = -ENOMEM; |
@@ -1784,6 +1976,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp, | |||
1784 | break; | 1976 | break; |
1785 | } | 1977 | } |
1786 | case KVM_SET_LAPIC: { | 1978 | case KVM_SET_LAPIC: { |
1979 | r = -EINVAL; | ||
1980 | if (!vcpu->arch.apic) | ||
1981 | goto out; | ||
1787 | lapic = kmalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL); | 1982 | lapic = kmalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL); |
1788 | r = -ENOMEM; | 1983 | r = -ENOMEM; |
1789 | if (!lapic) | 1984 | if (!lapic) |
@@ -1910,6 +2105,27 @@ long kvm_arch_vcpu_ioctl(struct file *filp, | |||
1910 | r = kvm_vcpu_ioctl_x86_set_mce(vcpu, &mce); | 2105 | r = kvm_vcpu_ioctl_x86_set_mce(vcpu, &mce); |
1911 | break; | 2106 | break; |
1912 | } | 2107 | } |
2108 | case KVM_GET_VCPU_EVENTS: { | ||
2109 | struct kvm_vcpu_events events; | ||
2110 | |||
2111 | kvm_vcpu_ioctl_x86_get_vcpu_events(vcpu, &events); | ||
2112 | |||
2113 | r = -EFAULT; | ||
2114 | if (copy_to_user(argp, &events, sizeof(struct kvm_vcpu_events))) | ||
2115 | break; | ||
2116 | r = 0; | ||
2117 | break; | ||
2118 | } | ||
2119 | case KVM_SET_VCPU_EVENTS: { | ||
2120 | struct kvm_vcpu_events events; | ||
2121 | |||
2122 | r = -EFAULT; | ||
2123 | if (copy_from_user(&events, argp, sizeof(struct kvm_vcpu_events))) | ||
2124 | break; | ||
2125 | |||
2126 | r = kvm_vcpu_ioctl_x86_set_vcpu_events(vcpu, &events); | ||
2127 | break; | ||
2128 | } | ||
1913 | default: | 2129 | default: |
1914 | r = -EINVAL; | 2130 | r = -EINVAL; |
1915 | } | 2131 | } |
@@ -2038,9 +2254,7 @@ static int kvm_vm_ioctl_get_irqchip(struct kvm *kvm, struct kvm_irqchip *chip) | |||
2038 | sizeof(struct kvm_pic_state)); | 2254 | sizeof(struct kvm_pic_state)); |
2039 | break; | 2255 | break; |
2040 | case KVM_IRQCHIP_IOAPIC: | 2256 | case KVM_IRQCHIP_IOAPIC: |
2041 | memcpy(&chip->chip.ioapic, | 2257 | r = kvm_get_ioapic(kvm, &chip->chip.ioapic); |
2042 | ioapic_irqchip(kvm), | ||
2043 | sizeof(struct kvm_ioapic_state)); | ||
2044 | break; | 2258 | break; |
2045 | default: | 2259 | default: |
2046 | r = -EINVAL; | 2260 | r = -EINVAL; |
@@ -2070,11 +2284,7 @@ static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm, struct kvm_irqchip *chip) | |||
2070 | spin_unlock(&pic_irqchip(kvm)->lock); | 2284 | spin_unlock(&pic_irqchip(kvm)->lock); |
2071 | break; | 2285 | break; |
2072 | case KVM_IRQCHIP_IOAPIC: | 2286 | case KVM_IRQCHIP_IOAPIC: |
2073 | mutex_lock(&kvm->irq_lock); | 2287 | r = kvm_set_ioapic(kvm, &chip->chip.ioapic); |
2074 | memcpy(ioapic_irqchip(kvm), | ||
2075 | &chip->chip.ioapic, | ||
2076 | sizeof(struct kvm_ioapic_state)); | ||
2077 | mutex_unlock(&kvm->irq_lock); | ||
2078 | break; | 2288 | break; |
2079 | default: | 2289 | default: |
2080 | r = -EINVAL; | 2290 | r = -EINVAL; |
@@ -2182,7 +2392,7 @@ long kvm_arch_vm_ioctl(struct file *filp, | |||
2182 | { | 2392 | { |
2183 | struct kvm *kvm = filp->private_data; | 2393 | struct kvm *kvm = filp->private_data; |
2184 | void __user *argp = (void __user *)arg; | 2394 | void __user *argp = (void __user *)arg; |
2185 | int r = -EINVAL; | 2395 | int r = -ENOTTY; |
2186 | /* | 2396 | /* |
2187 | * This union makes it completely explicit to gcc-3.x | 2397 | * This union makes it completely explicit to gcc-3.x |
2188 | * that these two variables' stack usage should be | 2398 | * that these two variables' stack usage should be |
@@ -2244,25 +2454,39 @@ long kvm_arch_vm_ioctl(struct file *filp, | |||
2244 | if (r) | 2454 | if (r) |
2245 | goto out; | 2455 | goto out; |
2246 | break; | 2456 | break; |
2247 | case KVM_CREATE_IRQCHIP: | 2457 | case KVM_CREATE_IRQCHIP: { |
2458 | struct kvm_pic *vpic; | ||
2459 | |||
2460 | mutex_lock(&kvm->lock); | ||
2461 | r = -EEXIST; | ||
2462 | if (kvm->arch.vpic) | ||
2463 | goto create_irqchip_unlock; | ||
2248 | r = -ENOMEM; | 2464 | r = -ENOMEM; |
2249 | kvm->arch.vpic = kvm_create_pic(kvm); | 2465 | vpic = kvm_create_pic(kvm); |
2250 | if (kvm->arch.vpic) { | 2466 | if (vpic) { |
2251 | r = kvm_ioapic_init(kvm); | 2467 | r = kvm_ioapic_init(kvm); |
2252 | if (r) { | 2468 | if (r) { |
2253 | kfree(kvm->arch.vpic); | 2469 | kfree(vpic); |
2254 | kvm->arch.vpic = NULL; | 2470 | goto create_irqchip_unlock; |
2255 | goto out; | ||
2256 | } | 2471 | } |
2257 | } else | 2472 | } else |
2258 | goto out; | 2473 | goto create_irqchip_unlock; |
2474 | smp_wmb(); | ||
2475 | kvm->arch.vpic = vpic; | ||
2476 | smp_wmb(); | ||
2259 | r = kvm_setup_default_irq_routing(kvm); | 2477 | r = kvm_setup_default_irq_routing(kvm); |
2260 | if (r) { | 2478 | if (r) { |
2479 | mutex_lock(&kvm->irq_lock); | ||
2261 | kfree(kvm->arch.vpic); | 2480 | kfree(kvm->arch.vpic); |
2262 | kfree(kvm->arch.vioapic); | 2481 | kfree(kvm->arch.vioapic); |
2263 | goto out; | 2482 | kvm->arch.vpic = NULL; |
2483 | kvm->arch.vioapic = NULL; | ||
2484 | mutex_unlock(&kvm->irq_lock); | ||
2264 | } | 2485 | } |
2486 | create_irqchip_unlock: | ||
2487 | mutex_unlock(&kvm->lock); | ||
2265 | break; | 2488 | break; |
2489 | } | ||
2266 | case KVM_CREATE_PIT: | 2490 | case KVM_CREATE_PIT: |
2267 | u.pit_config.flags = KVM_PIT_SPEAKER_DUMMY; | 2491 | u.pit_config.flags = KVM_PIT_SPEAKER_DUMMY; |
2268 | goto create_pit; | 2492 | goto create_pit; |
@@ -2292,10 +2516,8 @@ long kvm_arch_vm_ioctl(struct file *filp, | |||
2292 | goto out; | 2516 | goto out; |
2293 | if (irqchip_in_kernel(kvm)) { | 2517 | if (irqchip_in_kernel(kvm)) { |
2294 | __s32 status; | 2518 | __s32 status; |
2295 | mutex_lock(&kvm->irq_lock); | ||
2296 | status = kvm_set_irq(kvm, KVM_USERSPACE_IRQ_SOURCE_ID, | 2519 | status = kvm_set_irq(kvm, KVM_USERSPACE_IRQ_SOURCE_ID, |
2297 | irq_event.irq, irq_event.level); | 2520 | irq_event.irq, irq_event.level); |
2298 | mutex_unlock(&kvm->irq_lock); | ||
2299 | if (ioctl == KVM_IRQ_LINE_STATUS) { | 2521 | if (ioctl == KVM_IRQ_LINE_STATUS) { |
2300 | irq_event.status = status; | 2522 | irq_event.status = status; |
2301 | if (copy_to_user(argp, &irq_event, | 2523 | if (copy_to_user(argp, &irq_event, |
@@ -2421,6 +2643,55 @@ long kvm_arch_vm_ioctl(struct file *filp, | |||
2421 | r = 0; | 2643 | r = 0; |
2422 | break; | 2644 | break; |
2423 | } | 2645 | } |
2646 | case KVM_XEN_HVM_CONFIG: { | ||
2647 | r = -EFAULT; | ||
2648 | if (copy_from_user(&kvm->arch.xen_hvm_config, argp, | ||
2649 | sizeof(struct kvm_xen_hvm_config))) | ||
2650 | goto out; | ||
2651 | r = -EINVAL; | ||
2652 | if (kvm->arch.xen_hvm_config.flags) | ||
2653 | goto out; | ||
2654 | r = 0; | ||
2655 | break; | ||
2656 | } | ||
2657 | case KVM_SET_CLOCK: { | ||
2658 | struct timespec now; | ||
2659 | struct kvm_clock_data user_ns; | ||
2660 | u64 now_ns; | ||
2661 | s64 delta; | ||
2662 | |||
2663 | r = -EFAULT; | ||
2664 | if (copy_from_user(&user_ns, argp, sizeof(user_ns))) | ||
2665 | goto out; | ||
2666 | |||
2667 | r = -EINVAL; | ||
2668 | if (user_ns.flags) | ||
2669 | goto out; | ||
2670 | |||
2671 | r = 0; | ||
2672 | ktime_get_ts(&now); | ||
2673 | now_ns = timespec_to_ns(&now); | ||
2674 | delta = user_ns.clock - now_ns; | ||
2675 | kvm->arch.kvmclock_offset = delta; | ||
2676 | break; | ||
2677 | } | ||
2678 | case KVM_GET_CLOCK: { | ||
2679 | struct timespec now; | ||
2680 | struct kvm_clock_data user_ns; | ||
2681 | u64 now_ns; | ||
2682 | |||
2683 | ktime_get_ts(&now); | ||
2684 | now_ns = timespec_to_ns(&now); | ||
2685 | user_ns.clock = kvm->arch.kvmclock_offset + now_ns; | ||
2686 | user_ns.flags = 0; | ||
2687 | |||
2688 | r = -EFAULT; | ||
2689 | if (copy_to_user(argp, &user_ns, sizeof(user_ns))) | ||
2690 | goto out; | ||
2691 | r = 0; | ||
2692 | break; | ||
2693 | } | ||
2694 | |||
2424 | default: | 2695 | default: |
2425 | ; | 2696 | ; |
2426 | } | 2697 | } |
@@ -2433,7 +2704,8 @@ static void kvm_init_msr_list(void) | |||
2433 | u32 dummy[2]; | 2704 | u32 dummy[2]; |
2434 | unsigned i, j; | 2705 | unsigned i, j; |
2435 | 2706 | ||
2436 | for (i = j = 0; i < ARRAY_SIZE(msrs_to_save); i++) { | 2707 | /* skip the first msrs in the list. KVM-specific */ |
2708 | for (i = j = KVM_SAVE_MSRS_BEGIN; i < ARRAY_SIZE(msrs_to_save); i++) { | ||
2437 | if (rdmsr_safe(msrs_to_save[i], &dummy[0], &dummy[1]) < 0) | 2709 | if (rdmsr_safe(msrs_to_save[i], &dummy[0], &dummy[1]) < 0) |
2438 | continue; | 2710 | continue; |
2439 | if (j < i) | 2711 | if (j < i) |
@@ -2757,13 +3029,13 @@ static void cache_all_regs(struct kvm_vcpu *vcpu) | |||
2757 | } | 3029 | } |
2758 | 3030 | ||
2759 | int emulate_instruction(struct kvm_vcpu *vcpu, | 3031 | int emulate_instruction(struct kvm_vcpu *vcpu, |
2760 | struct kvm_run *run, | ||
2761 | unsigned long cr2, | 3032 | unsigned long cr2, |
2762 | u16 error_code, | 3033 | u16 error_code, |
2763 | int emulation_type) | 3034 | int emulation_type) |
2764 | { | 3035 | { |
2765 | int r, shadow_mask; | 3036 | int r, shadow_mask; |
2766 | struct decode_cache *c; | 3037 | struct decode_cache *c; |
3038 | struct kvm_run *run = vcpu->run; | ||
2767 | 3039 | ||
2768 | kvm_clear_exception_queue(vcpu); | 3040 | kvm_clear_exception_queue(vcpu); |
2769 | vcpu->arch.mmio_fault_cr2 = cr2; | 3041 | vcpu->arch.mmio_fault_cr2 = cr2; |
@@ -2783,7 +3055,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu, | |||
2783 | kvm_x86_ops->get_cs_db_l_bits(vcpu, &cs_db, &cs_l); | 3055 | kvm_x86_ops->get_cs_db_l_bits(vcpu, &cs_db, &cs_l); |
2784 | 3056 | ||
2785 | vcpu->arch.emulate_ctxt.vcpu = vcpu; | 3057 | vcpu->arch.emulate_ctxt.vcpu = vcpu; |
2786 | vcpu->arch.emulate_ctxt.eflags = kvm_x86_ops->get_rflags(vcpu); | 3058 | vcpu->arch.emulate_ctxt.eflags = kvm_get_rflags(vcpu); |
2787 | vcpu->arch.emulate_ctxt.mode = | 3059 | vcpu->arch.emulate_ctxt.mode = |
2788 | (vcpu->arch.emulate_ctxt.eflags & X86_EFLAGS_VM) | 3060 | (vcpu->arch.emulate_ctxt.eflags & X86_EFLAGS_VM) |
2789 | ? X86EMUL_MODE_REAL : cs_l | 3061 | ? X86EMUL_MODE_REAL : cs_l |
@@ -2861,7 +3133,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu, | |||
2861 | return EMULATE_DO_MMIO; | 3133 | return EMULATE_DO_MMIO; |
2862 | } | 3134 | } |
2863 | 3135 | ||
2864 | kvm_x86_ops->set_rflags(vcpu, vcpu->arch.emulate_ctxt.eflags); | 3136 | kvm_set_rflags(vcpu, vcpu->arch.emulate_ctxt.eflags); |
2865 | 3137 | ||
2866 | if (vcpu->mmio_is_write) { | 3138 | if (vcpu->mmio_is_write) { |
2867 | vcpu->mmio_needed = 0; | 3139 | vcpu->mmio_needed = 0; |
@@ -2969,8 +3241,7 @@ static int pio_string_write(struct kvm_vcpu *vcpu) | |||
2969 | return r; | 3241 | return r; |
2970 | } | 3242 | } |
2971 | 3243 | ||
2972 | int kvm_emulate_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, | 3244 | int kvm_emulate_pio(struct kvm_vcpu *vcpu, int in, int size, unsigned port) |
2973 | int size, unsigned port) | ||
2974 | { | 3245 | { |
2975 | unsigned long val; | 3246 | unsigned long val; |
2976 | 3247 | ||
@@ -2999,7 +3270,7 @@ int kvm_emulate_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, | |||
2999 | } | 3270 | } |
3000 | EXPORT_SYMBOL_GPL(kvm_emulate_pio); | 3271 | EXPORT_SYMBOL_GPL(kvm_emulate_pio); |
3001 | 3272 | ||
3002 | int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, | 3273 | int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, int in, |
3003 | int size, unsigned long count, int down, | 3274 | int size, unsigned long count, int down, |
3004 | gva_t address, int rep, unsigned port) | 3275 | gva_t address, int rep, unsigned port) |
3005 | { | 3276 | { |
@@ -3072,9 +3343,6 @@ static void bounce_off(void *info) | |||
3072 | /* nothing */ | 3343 | /* nothing */ |
3073 | } | 3344 | } |
3074 | 3345 | ||
3075 | static unsigned int ref_freq; | ||
3076 | static unsigned long tsc_khz_ref; | ||
3077 | |||
3078 | static int kvmclock_cpufreq_notifier(struct notifier_block *nb, unsigned long val, | 3346 | static int kvmclock_cpufreq_notifier(struct notifier_block *nb, unsigned long val, |
3079 | void *data) | 3347 | void *data) |
3080 | { | 3348 | { |
@@ -3083,14 +3351,11 @@ static int kvmclock_cpufreq_notifier(struct notifier_block *nb, unsigned long va | |||
3083 | struct kvm_vcpu *vcpu; | 3351 | struct kvm_vcpu *vcpu; |
3084 | int i, send_ipi = 0; | 3352 | int i, send_ipi = 0; |
3085 | 3353 | ||
3086 | if (!ref_freq) | ||
3087 | ref_freq = freq->old; | ||
3088 | |||
3089 | if (val == CPUFREQ_PRECHANGE && freq->old > freq->new) | 3354 | if (val == CPUFREQ_PRECHANGE && freq->old > freq->new) |
3090 | return 0; | 3355 | return 0; |
3091 | if (val == CPUFREQ_POSTCHANGE && freq->old < freq->new) | 3356 | if (val == CPUFREQ_POSTCHANGE && freq->old < freq->new) |
3092 | return 0; | 3357 | return 0; |
3093 | per_cpu(cpu_tsc_khz, freq->cpu) = cpufreq_scale(tsc_khz_ref, ref_freq, freq->new); | 3358 | per_cpu(cpu_tsc_khz, freq->cpu) = freq->new; |
3094 | 3359 | ||
3095 | spin_lock(&kvm_lock); | 3360 | spin_lock(&kvm_lock); |
3096 | list_for_each_entry(kvm, &vm_list, vm_list) { | 3361 | list_for_each_entry(kvm, &vm_list, vm_list) { |
@@ -3127,9 +3392,28 @@ static struct notifier_block kvmclock_cpufreq_notifier_block = { | |||
3127 | .notifier_call = kvmclock_cpufreq_notifier | 3392 | .notifier_call = kvmclock_cpufreq_notifier |
3128 | }; | 3393 | }; |
3129 | 3394 | ||
3395 | static void kvm_timer_init(void) | ||
3396 | { | ||
3397 | int cpu; | ||
3398 | |||
3399 | if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) { | ||
3400 | cpufreq_register_notifier(&kvmclock_cpufreq_notifier_block, | ||
3401 | CPUFREQ_TRANSITION_NOTIFIER); | ||
3402 | for_each_online_cpu(cpu) { | ||
3403 | unsigned long khz = cpufreq_get(cpu); | ||
3404 | if (!khz) | ||
3405 | khz = tsc_khz; | ||
3406 | per_cpu(cpu_tsc_khz, cpu) = khz; | ||
3407 | } | ||
3408 | } else { | ||
3409 | for_each_possible_cpu(cpu) | ||
3410 | per_cpu(cpu_tsc_khz, cpu) = tsc_khz; | ||
3411 | } | ||
3412 | } | ||
3413 | |||
3130 | int kvm_arch_init(void *opaque) | 3414 | int kvm_arch_init(void *opaque) |
3131 | { | 3415 | { |
3132 | int r, cpu; | 3416 | int r; |
3133 | struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque; | 3417 | struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque; |
3134 | 3418 | ||
3135 | if (kvm_x86_ops) { | 3419 | if (kvm_x86_ops) { |
@@ -3161,13 +3445,7 @@ int kvm_arch_init(void *opaque) | |||
3161 | kvm_mmu_set_mask_ptes(PT_USER_MASK, PT_ACCESSED_MASK, | 3445 | kvm_mmu_set_mask_ptes(PT_USER_MASK, PT_ACCESSED_MASK, |
3162 | PT_DIRTY_MASK, PT64_NX_MASK, 0); | 3446 | PT_DIRTY_MASK, PT64_NX_MASK, 0); |
3163 | 3447 | ||
3164 | for_each_possible_cpu(cpu) | 3448 | kvm_timer_init(); |
3165 | per_cpu(cpu_tsc_khz, cpu) = tsc_khz; | ||
3166 | if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) { | ||
3167 | tsc_khz_ref = tsc_khz; | ||
3168 | cpufreq_register_notifier(&kvmclock_cpufreq_notifier_block, | ||
3169 | CPUFREQ_TRANSITION_NOTIFIER); | ||
3170 | } | ||
3171 | 3449 | ||
3172 | return 0; | 3450 | return 0; |
3173 | 3451 | ||
@@ -3295,7 +3573,7 @@ void realmode_lmsw(struct kvm_vcpu *vcpu, unsigned long msw, | |||
3295 | unsigned long *rflags) | 3573 | unsigned long *rflags) |
3296 | { | 3574 | { |
3297 | kvm_lmsw(vcpu, msw); | 3575 | kvm_lmsw(vcpu, msw); |
3298 | *rflags = kvm_x86_ops->get_rflags(vcpu); | 3576 | *rflags = kvm_get_rflags(vcpu); |
3299 | } | 3577 | } |
3300 | 3578 | ||
3301 | unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr) | 3579 | unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr) |
@@ -3333,7 +3611,7 @@ void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long val, | |||
3333 | switch (cr) { | 3611 | switch (cr) { |
3334 | case 0: | 3612 | case 0: |
3335 | kvm_set_cr0(vcpu, mk_cr_64(vcpu->arch.cr0, val)); | 3613 | kvm_set_cr0(vcpu, mk_cr_64(vcpu->arch.cr0, val)); |
3336 | *rflags = kvm_x86_ops->get_rflags(vcpu); | 3614 | *rflags = kvm_get_rflags(vcpu); |
3337 | break; | 3615 | break; |
3338 | case 2: | 3616 | case 2: |
3339 | vcpu->arch.cr2 = val; | 3617 | vcpu->arch.cr2 = val; |
@@ -3453,18 +3731,18 @@ EXPORT_SYMBOL_GPL(kvm_emulate_cpuid); | |||
3453 | * | 3731 | * |
3454 | * No need to exit to userspace if we already have an interrupt queued. | 3732 | * No need to exit to userspace if we already have an interrupt queued. |
3455 | */ | 3733 | */ |
3456 | static int dm_request_for_irq_injection(struct kvm_vcpu *vcpu, | 3734 | static int dm_request_for_irq_injection(struct kvm_vcpu *vcpu) |
3457 | struct kvm_run *kvm_run) | ||
3458 | { | 3735 | { |
3459 | return (!irqchip_in_kernel(vcpu->kvm) && !kvm_cpu_has_interrupt(vcpu) && | 3736 | return (!irqchip_in_kernel(vcpu->kvm) && !kvm_cpu_has_interrupt(vcpu) && |
3460 | kvm_run->request_interrupt_window && | 3737 | vcpu->run->request_interrupt_window && |
3461 | kvm_arch_interrupt_allowed(vcpu)); | 3738 | kvm_arch_interrupt_allowed(vcpu)); |
3462 | } | 3739 | } |
3463 | 3740 | ||
3464 | static void post_kvm_run_save(struct kvm_vcpu *vcpu, | 3741 | static void post_kvm_run_save(struct kvm_vcpu *vcpu) |
3465 | struct kvm_run *kvm_run) | ||
3466 | { | 3742 | { |
3467 | kvm_run->if_flag = (kvm_x86_ops->get_rflags(vcpu) & X86_EFLAGS_IF) != 0; | 3743 | struct kvm_run *kvm_run = vcpu->run; |
3744 | |||
3745 | kvm_run->if_flag = (kvm_get_rflags(vcpu) & X86_EFLAGS_IF) != 0; | ||
3468 | kvm_run->cr8 = kvm_get_cr8(vcpu); | 3746 | kvm_run->cr8 = kvm_get_cr8(vcpu); |
3469 | kvm_run->apic_base = kvm_get_apic_base(vcpu); | 3747 | kvm_run->apic_base = kvm_get_apic_base(vcpu); |
3470 | if (irqchip_in_kernel(vcpu->kvm)) | 3748 | if (irqchip_in_kernel(vcpu->kvm)) |
@@ -3525,7 +3803,7 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu) | |||
3525 | kvm_x86_ops->update_cr8_intercept(vcpu, tpr, max_irr); | 3803 | kvm_x86_ops->update_cr8_intercept(vcpu, tpr, max_irr); |
3526 | } | 3804 | } |
3527 | 3805 | ||
3528 | static void inject_pending_event(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | 3806 | static void inject_pending_event(struct kvm_vcpu *vcpu) |
3529 | { | 3807 | { |
3530 | /* try to reinject previous events if any */ | 3808 | /* try to reinject previous events if any */ |
3531 | if (vcpu->arch.exception.pending) { | 3809 | if (vcpu->arch.exception.pending) { |
@@ -3561,11 +3839,11 @@ static void inject_pending_event(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
3561 | } | 3839 | } |
3562 | } | 3840 | } |
3563 | 3841 | ||
3564 | static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | 3842 | static int vcpu_enter_guest(struct kvm_vcpu *vcpu) |
3565 | { | 3843 | { |
3566 | int r; | 3844 | int r; |
3567 | bool req_int_win = !irqchip_in_kernel(vcpu->kvm) && | 3845 | bool req_int_win = !irqchip_in_kernel(vcpu->kvm) && |
3568 | kvm_run->request_interrupt_window; | 3846 | vcpu->run->request_interrupt_window; |
3569 | 3847 | ||
3570 | if (vcpu->requests) | 3848 | if (vcpu->requests) |
3571 | if (test_and_clear_bit(KVM_REQ_MMU_RELOAD, &vcpu->requests)) | 3849 | if (test_and_clear_bit(KVM_REQ_MMU_RELOAD, &vcpu->requests)) |
@@ -3586,12 +3864,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
3586 | kvm_x86_ops->tlb_flush(vcpu); | 3864 | kvm_x86_ops->tlb_flush(vcpu); |
3587 | if (test_and_clear_bit(KVM_REQ_REPORT_TPR_ACCESS, | 3865 | if (test_and_clear_bit(KVM_REQ_REPORT_TPR_ACCESS, |
3588 | &vcpu->requests)) { | 3866 | &vcpu->requests)) { |
3589 | kvm_run->exit_reason = KVM_EXIT_TPR_ACCESS; | 3867 | vcpu->run->exit_reason = KVM_EXIT_TPR_ACCESS; |
3590 | r = 0; | 3868 | r = 0; |
3591 | goto out; | 3869 | goto out; |
3592 | } | 3870 | } |
3593 | if (test_and_clear_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests)) { | 3871 | if (test_and_clear_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests)) { |
3594 | kvm_run->exit_reason = KVM_EXIT_SHUTDOWN; | 3872 | vcpu->run->exit_reason = KVM_EXIT_SHUTDOWN; |
3595 | r = 0; | 3873 | r = 0; |
3596 | goto out; | 3874 | goto out; |
3597 | } | 3875 | } |
@@ -3615,7 +3893,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
3615 | goto out; | 3893 | goto out; |
3616 | } | 3894 | } |
3617 | 3895 | ||
3618 | inject_pending_event(vcpu, kvm_run); | 3896 | inject_pending_event(vcpu); |
3619 | 3897 | ||
3620 | /* enable NMI/IRQ window open exits if needed */ | 3898 | /* enable NMI/IRQ window open exits if needed */ |
3621 | if (vcpu->arch.nmi_pending) | 3899 | if (vcpu->arch.nmi_pending) |
@@ -3641,16 +3919,17 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
3641 | } | 3919 | } |
3642 | 3920 | ||
3643 | trace_kvm_entry(vcpu->vcpu_id); | 3921 | trace_kvm_entry(vcpu->vcpu_id); |
3644 | kvm_x86_ops->run(vcpu, kvm_run); | 3922 | kvm_x86_ops->run(vcpu); |
3645 | 3923 | ||
3646 | if (unlikely(vcpu->arch.switch_db_regs || test_thread_flag(TIF_DEBUG))) { | 3924 | /* |
3647 | set_debugreg(current->thread.debugreg0, 0); | 3925 | * If the guest has used debug registers, at least dr7 |
3648 | set_debugreg(current->thread.debugreg1, 1); | 3926 | * will be disabled while returning to the host. |
3649 | set_debugreg(current->thread.debugreg2, 2); | 3927 | * If we don't have active breakpoints in the host, we don't |
3650 | set_debugreg(current->thread.debugreg3, 3); | 3928 | * care about the messed up debug address registers. But if |
3651 | set_debugreg(current->thread.debugreg6, 6); | 3929 | * we have some of them active, restore the old state. |
3652 | set_debugreg(current->thread.debugreg7, 7); | 3930 | */ |
3653 | } | 3931 | if (hw_breakpoint_active()) |
3932 | hw_breakpoint_restore(); | ||
3654 | 3933 | ||
3655 | set_bit(KVM_REQ_KICK, &vcpu->requests); | 3934 | set_bit(KVM_REQ_KICK, &vcpu->requests); |
3656 | local_irq_enable(); | 3935 | local_irq_enable(); |
@@ -3682,13 +3961,13 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
3682 | 3961 | ||
3683 | kvm_lapic_sync_from_vapic(vcpu); | 3962 | kvm_lapic_sync_from_vapic(vcpu); |
3684 | 3963 | ||
3685 | r = kvm_x86_ops->handle_exit(kvm_run, vcpu); | 3964 | r = kvm_x86_ops->handle_exit(vcpu); |
3686 | out: | 3965 | out: |
3687 | return r; | 3966 | return r; |
3688 | } | 3967 | } |
3689 | 3968 | ||
3690 | 3969 | ||
3691 | static int __vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | 3970 | static int __vcpu_run(struct kvm_vcpu *vcpu) |
3692 | { | 3971 | { |
3693 | int r; | 3972 | int r; |
3694 | 3973 | ||
@@ -3708,7 +3987,7 @@ static int __vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
3708 | r = 1; | 3987 | r = 1; |
3709 | while (r > 0) { | 3988 | while (r > 0) { |
3710 | if (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE) | 3989 | if (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE) |
3711 | r = vcpu_enter_guest(vcpu, kvm_run); | 3990 | r = vcpu_enter_guest(vcpu); |
3712 | else { | 3991 | else { |
3713 | up_read(&vcpu->kvm->slots_lock); | 3992 | up_read(&vcpu->kvm->slots_lock); |
3714 | kvm_vcpu_block(vcpu); | 3993 | kvm_vcpu_block(vcpu); |
@@ -3736,14 +4015,14 @@ static int __vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
3736 | if (kvm_cpu_has_pending_timer(vcpu)) | 4015 | if (kvm_cpu_has_pending_timer(vcpu)) |
3737 | kvm_inject_pending_timer_irqs(vcpu); | 4016 | kvm_inject_pending_timer_irqs(vcpu); |
3738 | 4017 | ||
3739 | if (dm_request_for_irq_injection(vcpu, kvm_run)) { | 4018 | if (dm_request_for_irq_injection(vcpu)) { |
3740 | r = -EINTR; | 4019 | r = -EINTR; |
3741 | kvm_run->exit_reason = KVM_EXIT_INTR; | 4020 | vcpu->run->exit_reason = KVM_EXIT_INTR; |
3742 | ++vcpu->stat.request_irq_exits; | 4021 | ++vcpu->stat.request_irq_exits; |
3743 | } | 4022 | } |
3744 | if (signal_pending(current)) { | 4023 | if (signal_pending(current)) { |
3745 | r = -EINTR; | 4024 | r = -EINTR; |
3746 | kvm_run->exit_reason = KVM_EXIT_INTR; | 4025 | vcpu->run->exit_reason = KVM_EXIT_INTR; |
3747 | ++vcpu->stat.signal_exits; | 4026 | ++vcpu->stat.signal_exits; |
3748 | } | 4027 | } |
3749 | if (need_resched()) { | 4028 | if (need_resched()) { |
@@ -3754,7 +4033,7 @@ static int __vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
3754 | } | 4033 | } |
3755 | 4034 | ||
3756 | up_read(&vcpu->kvm->slots_lock); | 4035 | up_read(&vcpu->kvm->slots_lock); |
3757 | post_kvm_run_save(vcpu, kvm_run); | 4036 | post_kvm_run_save(vcpu); |
3758 | 4037 | ||
3759 | vapic_exit(vcpu); | 4038 | vapic_exit(vcpu); |
3760 | 4039 | ||
@@ -3787,15 +4066,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
3787 | if (r) | 4066 | if (r) |
3788 | goto out; | 4067 | goto out; |
3789 | } | 4068 | } |
3790 | #if CONFIG_HAS_IOMEM | ||
3791 | if (vcpu->mmio_needed) { | 4069 | if (vcpu->mmio_needed) { |
3792 | memcpy(vcpu->mmio_data, kvm_run->mmio.data, 8); | 4070 | memcpy(vcpu->mmio_data, kvm_run->mmio.data, 8); |
3793 | vcpu->mmio_read_completed = 1; | 4071 | vcpu->mmio_read_completed = 1; |
3794 | vcpu->mmio_needed = 0; | 4072 | vcpu->mmio_needed = 0; |
3795 | 4073 | ||
3796 | down_read(&vcpu->kvm->slots_lock); | 4074 | down_read(&vcpu->kvm->slots_lock); |
3797 | r = emulate_instruction(vcpu, kvm_run, | 4075 | r = emulate_instruction(vcpu, vcpu->arch.mmio_fault_cr2, 0, |
3798 | vcpu->arch.mmio_fault_cr2, 0, | ||
3799 | EMULTYPE_NO_DECODE); | 4076 | EMULTYPE_NO_DECODE); |
3800 | up_read(&vcpu->kvm->slots_lock); | 4077 | up_read(&vcpu->kvm->slots_lock); |
3801 | if (r == EMULATE_DO_MMIO) { | 4078 | if (r == EMULATE_DO_MMIO) { |
@@ -3806,12 +4083,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) | |||
3806 | goto out; | 4083 | goto out; |
3807 | } | 4084 | } |
3808 | } | 4085 | } |
3809 | #endif | ||
3810 | if (kvm_run->exit_reason == KVM_EXIT_HYPERCALL) | 4086 | if (kvm_run->exit_reason == KVM_EXIT_HYPERCALL) |
3811 | kvm_register_write(vcpu, VCPU_REGS_RAX, | 4087 | kvm_register_write(vcpu, VCPU_REGS_RAX, |
3812 | kvm_run->hypercall.ret); | 4088 | kvm_run->hypercall.ret); |
3813 | 4089 | ||
3814 | r = __vcpu_run(vcpu, kvm_run); | 4090 | r = __vcpu_run(vcpu); |
3815 | 4091 | ||
3816 | out: | 4092 | out: |
3817 | if (vcpu->sigset_active) | 4093 | if (vcpu->sigset_active) |
@@ -3845,13 +4121,7 @@ int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) | |||
3845 | #endif | 4121 | #endif |
3846 | 4122 | ||
3847 | regs->rip = kvm_rip_read(vcpu); | 4123 | regs->rip = kvm_rip_read(vcpu); |
3848 | regs->rflags = kvm_x86_ops->get_rflags(vcpu); | 4124 | regs->rflags = kvm_get_rflags(vcpu); |
3849 | |||
3850 | /* | ||
3851 | * Don't leak debug flags in case they were set for guest debugging | ||
3852 | */ | ||
3853 | if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) | ||
3854 | regs->rflags &= ~(X86_EFLAGS_TF | X86_EFLAGS_RF); | ||
3855 | 4125 | ||
3856 | vcpu_put(vcpu); | 4126 | vcpu_put(vcpu); |
3857 | 4127 | ||
@@ -3879,12 +4149,10 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) | |||
3879 | kvm_register_write(vcpu, VCPU_REGS_R13, regs->r13); | 4149 | kvm_register_write(vcpu, VCPU_REGS_R13, regs->r13); |
3880 | kvm_register_write(vcpu, VCPU_REGS_R14, regs->r14); | 4150 | kvm_register_write(vcpu, VCPU_REGS_R14, regs->r14); |
3881 | kvm_register_write(vcpu, VCPU_REGS_R15, regs->r15); | 4151 | kvm_register_write(vcpu, VCPU_REGS_R15, regs->r15); |
3882 | |||
3883 | #endif | 4152 | #endif |
3884 | 4153 | ||
3885 | kvm_rip_write(vcpu, regs->rip); | 4154 | kvm_rip_write(vcpu, regs->rip); |
3886 | kvm_x86_ops->set_rflags(vcpu, regs->rflags); | 4155 | kvm_set_rflags(vcpu, regs->rflags); |
3887 | |||
3888 | 4156 | ||
3889 | vcpu->arch.exception.pending = false; | 4157 | vcpu->arch.exception.pending = false; |
3890 | 4158 | ||
@@ -4103,7 +4371,7 @@ static int is_vm86_segment(struct kvm_vcpu *vcpu, int seg) | |||
4103 | { | 4371 | { |
4104 | return (seg != VCPU_SREG_LDTR) && | 4372 | return (seg != VCPU_SREG_LDTR) && |
4105 | (seg != VCPU_SREG_TR) && | 4373 | (seg != VCPU_SREG_TR) && |
4106 | (kvm_x86_ops->get_rflags(vcpu) & X86_EFLAGS_VM); | 4374 | (kvm_get_rflags(vcpu) & X86_EFLAGS_VM); |
4107 | } | 4375 | } |
4108 | 4376 | ||
4109 | int kvm_load_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, | 4377 | int kvm_load_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, |
@@ -4131,7 +4399,7 @@ static void save_state_to_tss32(struct kvm_vcpu *vcpu, | |||
4131 | { | 4399 | { |
4132 | tss->cr3 = vcpu->arch.cr3; | 4400 | tss->cr3 = vcpu->arch.cr3; |
4133 | tss->eip = kvm_rip_read(vcpu); | 4401 | tss->eip = kvm_rip_read(vcpu); |
4134 | tss->eflags = kvm_x86_ops->get_rflags(vcpu); | 4402 | tss->eflags = kvm_get_rflags(vcpu); |
4135 | tss->eax = kvm_register_read(vcpu, VCPU_REGS_RAX); | 4403 | tss->eax = kvm_register_read(vcpu, VCPU_REGS_RAX); |
4136 | tss->ecx = kvm_register_read(vcpu, VCPU_REGS_RCX); | 4404 | tss->ecx = kvm_register_read(vcpu, VCPU_REGS_RCX); |
4137 | tss->edx = kvm_register_read(vcpu, VCPU_REGS_RDX); | 4405 | tss->edx = kvm_register_read(vcpu, VCPU_REGS_RDX); |
@@ -4155,7 +4423,7 @@ static int load_state_from_tss32(struct kvm_vcpu *vcpu, | |||
4155 | kvm_set_cr3(vcpu, tss->cr3); | 4423 | kvm_set_cr3(vcpu, tss->cr3); |
4156 | 4424 | ||
4157 | kvm_rip_write(vcpu, tss->eip); | 4425 | kvm_rip_write(vcpu, tss->eip); |
4158 | kvm_x86_ops->set_rflags(vcpu, tss->eflags | 2); | 4426 | kvm_set_rflags(vcpu, tss->eflags | 2); |
4159 | 4427 | ||
4160 | kvm_register_write(vcpu, VCPU_REGS_RAX, tss->eax); | 4428 | kvm_register_write(vcpu, VCPU_REGS_RAX, tss->eax); |
4161 | kvm_register_write(vcpu, VCPU_REGS_RCX, tss->ecx); | 4429 | kvm_register_write(vcpu, VCPU_REGS_RCX, tss->ecx); |
@@ -4193,7 +4461,7 @@ static void save_state_to_tss16(struct kvm_vcpu *vcpu, | |||
4193 | struct tss_segment_16 *tss) | 4461 | struct tss_segment_16 *tss) |
4194 | { | 4462 | { |
4195 | tss->ip = kvm_rip_read(vcpu); | 4463 | tss->ip = kvm_rip_read(vcpu); |
4196 | tss->flag = kvm_x86_ops->get_rflags(vcpu); | 4464 | tss->flag = kvm_get_rflags(vcpu); |
4197 | tss->ax = kvm_register_read(vcpu, VCPU_REGS_RAX); | 4465 | tss->ax = kvm_register_read(vcpu, VCPU_REGS_RAX); |
4198 | tss->cx = kvm_register_read(vcpu, VCPU_REGS_RCX); | 4466 | tss->cx = kvm_register_read(vcpu, VCPU_REGS_RCX); |
4199 | tss->dx = kvm_register_read(vcpu, VCPU_REGS_RDX); | 4467 | tss->dx = kvm_register_read(vcpu, VCPU_REGS_RDX); |
@@ -4208,14 +4476,13 @@ static void save_state_to_tss16(struct kvm_vcpu *vcpu, | |||
4208 | tss->ss = get_segment_selector(vcpu, VCPU_SREG_SS); | 4476 | tss->ss = get_segment_selector(vcpu, VCPU_SREG_SS); |
4209 | tss->ds = get_segment_selector(vcpu, VCPU_SREG_DS); | 4477 | tss->ds = get_segment_selector(vcpu, VCPU_SREG_DS); |
4210 | tss->ldt = get_segment_selector(vcpu, VCPU_SREG_LDTR); | 4478 | tss->ldt = get_segment_selector(vcpu, VCPU_SREG_LDTR); |
4211 | tss->prev_task_link = get_segment_selector(vcpu, VCPU_SREG_TR); | ||
4212 | } | 4479 | } |
4213 | 4480 | ||
4214 | static int load_state_from_tss16(struct kvm_vcpu *vcpu, | 4481 | static int load_state_from_tss16(struct kvm_vcpu *vcpu, |
4215 | struct tss_segment_16 *tss) | 4482 | struct tss_segment_16 *tss) |
4216 | { | 4483 | { |
4217 | kvm_rip_write(vcpu, tss->ip); | 4484 | kvm_rip_write(vcpu, tss->ip); |
4218 | kvm_x86_ops->set_rflags(vcpu, tss->flag | 2); | 4485 | kvm_set_rflags(vcpu, tss->flag | 2); |
4219 | kvm_register_write(vcpu, VCPU_REGS_RAX, tss->ax); | 4486 | kvm_register_write(vcpu, VCPU_REGS_RAX, tss->ax); |
4220 | kvm_register_write(vcpu, VCPU_REGS_RCX, tss->cx); | 4487 | kvm_register_write(vcpu, VCPU_REGS_RCX, tss->cx); |
4221 | kvm_register_write(vcpu, VCPU_REGS_RDX, tss->dx); | 4488 | kvm_register_write(vcpu, VCPU_REGS_RDX, tss->dx); |
@@ -4361,8 +4628,8 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int reason) | |||
4361 | } | 4628 | } |
4362 | 4629 | ||
4363 | if (reason == TASK_SWITCH_IRET) { | 4630 | if (reason == TASK_SWITCH_IRET) { |
4364 | u32 eflags = kvm_x86_ops->get_rflags(vcpu); | 4631 | u32 eflags = kvm_get_rflags(vcpu); |
4365 | kvm_x86_ops->set_rflags(vcpu, eflags & ~X86_EFLAGS_NT); | 4632 | kvm_set_rflags(vcpu, eflags & ~X86_EFLAGS_NT); |
4366 | } | 4633 | } |
4367 | 4634 | ||
4368 | /* set back link to prev task only if NT bit is set in eflags | 4635 | /* set back link to prev task only if NT bit is set in eflags |
@@ -4370,11 +4637,6 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int reason) | |||
4370 | if (reason != TASK_SWITCH_CALL && reason != TASK_SWITCH_GATE) | 4637 | if (reason != TASK_SWITCH_CALL && reason != TASK_SWITCH_GATE) |
4371 | old_tss_sel = 0xffff; | 4638 | old_tss_sel = 0xffff; |
4372 | 4639 | ||
4373 | /* set back link to prev task only if NT bit is set in eflags | ||
4374 | note that old_tss_sel is not used afetr this point */ | ||
4375 | if (reason != TASK_SWITCH_CALL && reason != TASK_SWITCH_GATE) | ||
4376 | old_tss_sel = 0xffff; | ||
4377 | |||
4378 | if (nseg_desc.type & 8) | 4640 | if (nseg_desc.type & 8) |
4379 | ret = kvm_task_switch_32(vcpu, tss_selector, old_tss_sel, | 4641 | ret = kvm_task_switch_32(vcpu, tss_selector, old_tss_sel, |
4380 | old_tss_base, &nseg_desc); | 4642 | old_tss_base, &nseg_desc); |
@@ -4383,8 +4645,8 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int reason) | |||
4383 | old_tss_base, &nseg_desc); | 4645 | old_tss_base, &nseg_desc); |
4384 | 4646 | ||
4385 | if (reason == TASK_SWITCH_CALL || reason == TASK_SWITCH_GATE) { | 4647 | if (reason == TASK_SWITCH_CALL || reason == TASK_SWITCH_GATE) { |
4386 | u32 eflags = kvm_x86_ops->get_rflags(vcpu); | 4648 | u32 eflags = kvm_get_rflags(vcpu); |
4387 | kvm_x86_ops->set_rflags(vcpu, eflags | X86_EFLAGS_NT); | 4649 | kvm_set_rflags(vcpu, eflags | X86_EFLAGS_NT); |
4388 | } | 4650 | } |
4389 | 4651 | ||
4390 | if (reason != TASK_SWITCH_IRET) { | 4652 | if (reason != TASK_SWITCH_IRET) { |
@@ -4436,8 +4698,10 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, | |||
4436 | 4698 | ||
4437 | mmu_reset_needed |= vcpu->arch.cr4 != sregs->cr4; | 4699 | mmu_reset_needed |= vcpu->arch.cr4 != sregs->cr4; |
4438 | kvm_x86_ops->set_cr4(vcpu, sregs->cr4); | 4700 | kvm_x86_ops->set_cr4(vcpu, sregs->cr4); |
4439 | if (!is_long_mode(vcpu) && is_pae(vcpu)) | 4701 | if (!is_long_mode(vcpu) && is_pae(vcpu)) { |
4440 | load_pdptrs(vcpu, vcpu->arch.cr3); | 4702 | load_pdptrs(vcpu, vcpu->arch.cr3); |
4703 | mmu_reset_needed = 1; | ||
4704 | } | ||
4441 | 4705 | ||
4442 | if (mmu_reset_needed) | 4706 | if (mmu_reset_needed) |
4443 | kvm_mmu_reset_context(vcpu); | 4707 | kvm_mmu_reset_context(vcpu); |
@@ -4478,12 +4742,32 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, | |||
4478 | int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, | 4742 | int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, |
4479 | struct kvm_guest_debug *dbg) | 4743 | struct kvm_guest_debug *dbg) |
4480 | { | 4744 | { |
4745 | unsigned long rflags; | ||
4481 | int i, r; | 4746 | int i, r; |
4482 | 4747 | ||
4483 | vcpu_load(vcpu); | 4748 | vcpu_load(vcpu); |
4484 | 4749 | ||
4485 | if ((dbg->control & (KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_HW_BP)) == | 4750 | if (dbg->control & (KVM_GUESTDBG_INJECT_DB | KVM_GUESTDBG_INJECT_BP)) { |
4486 | (KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_HW_BP)) { | 4751 | r = -EBUSY; |
4752 | if (vcpu->arch.exception.pending) | ||
4753 | goto unlock_out; | ||
4754 | if (dbg->control & KVM_GUESTDBG_INJECT_DB) | ||
4755 | kvm_queue_exception(vcpu, DB_VECTOR); | ||
4756 | else | ||
4757 | kvm_queue_exception(vcpu, BP_VECTOR); | ||
4758 | } | ||
4759 | |||
4760 | /* | ||
4761 | * Read rflags as long as potentially injected trace flags are still | ||
4762 | * filtered out. | ||
4763 | */ | ||
4764 | rflags = kvm_get_rflags(vcpu); | ||
4765 | |||
4766 | vcpu->guest_debug = dbg->control; | ||
4767 | if (!(vcpu->guest_debug & KVM_GUESTDBG_ENABLE)) | ||
4768 | vcpu->guest_debug = 0; | ||
4769 | |||
4770 | if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP) { | ||
4487 | for (i = 0; i < KVM_NR_DB_REGS; ++i) | 4771 | for (i = 0; i < KVM_NR_DB_REGS; ++i) |
4488 | vcpu->arch.eff_db[i] = dbg->arch.debugreg[i]; | 4772 | vcpu->arch.eff_db[i] = dbg->arch.debugreg[i]; |
4489 | vcpu->arch.switch_db_regs = | 4773 | vcpu->arch.switch_db_regs = |
@@ -4494,13 +4778,23 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, | |||
4494 | vcpu->arch.switch_db_regs = (vcpu->arch.dr7 & DR7_BP_EN_MASK); | 4778 | vcpu->arch.switch_db_regs = (vcpu->arch.dr7 & DR7_BP_EN_MASK); |
4495 | } | 4779 | } |
4496 | 4780 | ||
4497 | r = kvm_x86_ops->set_guest_debug(vcpu, dbg); | 4781 | if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) { |
4782 | vcpu->arch.singlestep_cs = | ||
4783 | get_segment_selector(vcpu, VCPU_SREG_CS); | ||
4784 | vcpu->arch.singlestep_rip = kvm_rip_read(vcpu); | ||
4785 | } | ||
4786 | |||
4787 | /* | ||
4788 | * Trigger an rflags update that will inject or remove the trace | ||
4789 | * flags. | ||
4790 | */ | ||
4791 | kvm_set_rflags(vcpu, rflags); | ||
4792 | |||
4793 | kvm_x86_ops->set_guest_debug(vcpu, dbg); | ||
4498 | 4794 | ||
4499 | if (dbg->control & KVM_GUESTDBG_INJECT_DB) | 4795 | r = 0; |
4500 | kvm_queue_exception(vcpu, DB_VECTOR); | ||
4501 | else if (dbg->control & KVM_GUESTDBG_INJECT_BP) | ||
4502 | kvm_queue_exception(vcpu, BP_VECTOR); | ||
4503 | 4796 | ||
4797 | unlock_out: | ||
4504 | vcpu_put(vcpu); | 4798 | vcpu_put(vcpu); |
4505 | 4799 | ||
4506 | return r; | 4800 | return r; |
@@ -4701,14 +4995,26 @@ int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu) | |||
4701 | return kvm_x86_ops->vcpu_reset(vcpu); | 4995 | return kvm_x86_ops->vcpu_reset(vcpu); |
4702 | } | 4996 | } |
4703 | 4997 | ||
4704 | void kvm_arch_hardware_enable(void *garbage) | 4998 | int kvm_arch_hardware_enable(void *garbage) |
4705 | { | 4999 | { |
4706 | kvm_x86_ops->hardware_enable(garbage); | 5000 | /* |
5001 | * Since this may be called from a hotplug notifcation, | ||
5002 | * we can't get the CPU frequency directly. | ||
5003 | */ | ||
5004 | if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) { | ||
5005 | int cpu = raw_smp_processor_id(); | ||
5006 | per_cpu(cpu_tsc_khz, cpu) = 0; | ||
5007 | } | ||
5008 | |||
5009 | kvm_shared_msr_cpu_online(); | ||
5010 | |||
5011 | return kvm_x86_ops->hardware_enable(garbage); | ||
4707 | } | 5012 | } |
4708 | 5013 | ||
4709 | void kvm_arch_hardware_disable(void *garbage) | 5014 | void kvm_arch_hardware_disable(void *garbage) |
4710 | { | 5015 | { |
4711 | kvm_x86_ops->hardware_disable(garbage); | 5016 | kvm_x86_ops->hardware_disable(garbage); |
5017 | drop_user_return_notifiers(garbage); | ||
4712 | } | 5018 | } |
4713 | 5019 | ||
4714 | int kvm_arch_hardware_setup(void) | 5020 | int kvm_arch_hardware_setup(void) |
@@ -4946,8 +5252,36 @@ int kvm_arch_interrupt_allowed(struct kvm_vcpu *vcpu) | |||
4946 | return kvm_x86_ops->interrupt_allowed(vcpu); | 5252 | return kvm_x86_ops->interrupt_allowed(vcpu); |
4947 | } | 5253 | } |
4948 | 5254 | ||
5255 | unsigned long kvm_get_rflags(struct kvm_vcpu *vcpu) | ||
5256 | { | ||
5257 | unsigned long rflags; | ||
5258 | |||
5259 | rflags = kvm_x86_ops->get_rflags(vcpu); | ||
5260 | if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) | ||
5261 | rflags &= ~(unsigned long)(X86_EFLAGS_TF | X86_EFLAGS_RF); | ||
5262 | return rflags; | ||
5263 | } | ||
5264 | EXPORT_SYMBOL_GPL(kvm_get_rflags); | ||
5265 | |||
5266 | void kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags) | ||
5267 | { | ||
5268 | if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP && | ||
5269 | vcpu->arch.singlestep_cs == | ||
5270 | get_segment_selector(vcpu, VCPU_SREG_CS) && | ||
5271 | vcpu->arch.singlestep_rip == kvm_rip_read(vcpu)) | ||
5272 | rflags |= X86_EFLAGS_TF | X86_EFLAGS_RF; | ||
5273 | kvm_x86_ops->set_rflags(vcpu, rflags); | ||
5274 | } | ||
5275 | EXPORT_SYMBOL_GPL(kvm_set_rflags); | ||
5276 | |||
4949 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_exit); | 5277 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_exit); |
4950 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_inj_virq); | 5278 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_inj_virq); |
4951 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_page_fault); | 5279 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_page_fault); |
4952 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_msr); | 5280 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_msr); |
4953 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_cr); | 5281 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_cr); |
5282 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_nested_vmrun); | ||
5283 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_nested_vmexit); | ||
5284 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_nested_vmexit_inject); | ||
5285 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_nested_intr_vmexit); | ||
5286 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_invlpga); | ||
5287 | EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_skinit); | ||