diff options
author | Avi Kivity <avi@redhat.com> | 2010-05-13 04:53:06 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-08-01 03:35:47 -0400 |
commit | 526b78ad1a9e66ef240ad7c757988de039e42229 (patch) | |
tree | 00e68ab9dd880a3e994d555b8f4aa70c43f4bb8d /arch/x86/kvm/x86.c | |
parent | 2122ff5eab8faec853e43f6de886e8dc8f31e317 (diff) |
KVM: x86: Lock arch specific vcpu ioctls centrally
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r-- | arch/x86/kvm/x86.c | 41 |
1 files changed, 2 insertions, 39 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 5acd21245fc7..999b017011f4 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -1541,16 +1541,12 @@ static int __msr_io(struct kvm_vcpu *vcpu, struct kvm_msrs *msrs, | |||
1541 | { | 1541 | { |
1542 | int i, idx; | 1542 | int i, idx; |
1543 | 1543 | ||
1544 | vcpu_load(vcpu); | ||
1545 | |||
1546 | idx = srcu_read_lock(&vcpu->kvm->srcu); | 1544 | idx = srcu_read_lock(&vcpu->kvm->srcu); |
1547 | for (i = 0; i < msrs->nmsrs; ++i) | 1545 | for (i = 0; i < msrs->nmsrs; ++i) |
1548 | if (do_msr(vcpu, entries[i].index, &entries[i].data)) | 1546 | if (do_msr(vcpu, entries[i].index, &entries[i].data)) |
1549 | break; | 1547 | break; |
1550 | srcu_read_unlock(&vcpu->kvm->srcu, idx); | 1548 | srcu_read_unlock(&vcpu->kvm->srcu, idx); |
1551 | 1549 | ||
1552 | vcpu_put(vcpu); | ||
1553 | |||
1554 | return i; | 1550 | return i; |
1555 | } | 1551 | } |
1556 | 1552 | ||
@@ -1798,7 +1794,6 @@ static int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu, | |||
1798 | if (copy_from_user(cpuid_entries, entries, | 1794 | if (copy_from_user(cpuid_entries, entries, |
1799 | cpuid->nent * sizeof(struct kvm_cpuid_entry))) | 1795 | cpuid->nent * sizeof(struct kvm_cpuid_entry))) |
1800 | goto out_free; | 1796 | goto out_free; |
1801 | vcpu_load(vcpu); | ||
1802 | for (i = 0; i < cpuid->nent; i++) { | 1797 | for (i = 0; i < cpuid->nent; i++) { |
1803 | vcpu->arch.cpuid_entries[i].function = cpuid_entries[i].function; | 1798 | vcpu->arch.cpuid_entries[i].function = cpuid_entries[i].function; |
1804 | vcpu->arch.cpuid_entries[i].eax = cpuid_entries[i].eax; | 1799 | vcpu->arch.cpuid_entries[i].eax = cpuid_entries[i].eax; |
@@ -1816,7 +1811,6 @@ static int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu, | |||
1816 | r = 0; | 1811 | r = 0; |
1817 | kvm_apic_set_version(vcpu); | 1812 | kvm_apic_set_version(vcpu); |
1818 | kvm_x86_ops->cpuid_update(vcpu); | 1813 | kvm_x86_ops->cpuid_update(vcpu); |
1819 | vcpu_put(vcpu); | ||
1820 | 1814 | ||
1821 | out_free: | 1815 | out_free: |
1822 | vfree(cpuid_entries); | 1816 | vfree(cpuid_entries); |
@@ -1837,11 +1831,9 @@ static int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu, | |||
1837 | if (copy_from_user(&vcpu->arch.cpuid_entries, entries, | 1831 | if (copy_from_user(&vcpu->arch.cpuid_entries, entries, |
1838 | cpuid->nent * sizeof(struct kvm_cpuid_entry2))) | 1832 | cpuid->nent * sizeof(struct kvm_cpuid_entry2))) |
1839 | goto out; | 1833 | goto out; |
1840 | vcpu_load(vcpu); | ||
1841 | vcpu->arch.cpuid_nent = cpuid->nent; | 1834 | vcpu->arch.cpuid_nent = cpuid->nent; |
1842 | kvm_apic_set_version(vcpu); | 1835 | kvm_apic_set_version(vcpu); |
1843 | kvm_x86_ops->cpuid_update(vcpu); | 1836 | kvm_x86_ops->cpuid_update(vcpu); |
1844 | vcpu_put(vcpu); | ||
1845 | return 0; | 1837 | return 0; |
1846 | 1838 | ||
1847 | out: | 1839 | out: |
@@ -1854,7 +1846,6 @@ static int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu, | |||
1854 | { | 1846 | { |
1855 | int r; | 1847 | int r; |
1856 | 1848 | ||
1857 | vcpu_load(vcpu); | ||
1858 | r = -E2BIG; | 1849 | r = -E2BIG; |
1859 | if (cpuid->nent < vcpu->arch.cpuid_nent) | 1850 | if (cpuid->nent < vcpu->arch.cpuid_nent) |
1860 | goto out; | 1851 | goto out; |
@@ -1866,7 +1857,6 @@ static int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu, | |||
1866 | 1857 | ||
1867 | out: | 1858 | out: |
1868 | cpuid->nent = vcpu->arch.cpuid_nent; | 1859 | cpuid->nent = vcpu->arch.cpuid_nent; |
1869 | vcpu_put(vcpu); | ||
1870 | return r; | 1860 | return r; |
1871 | } | 1861 | } |
1872 | 1862 | ||
@@ -2098,9 +2088,7 @@ out: | |||
2098 | static int kvm_vcpu_ioctl_get_lapic(struct kvm_vcpu *vcpu, | 2088 | static int kvm_vcpu_ioctl_get_lapic(struct kvm_vcpu *vcpu, |
2099 | struct kvm_lapic_state *s) | 2089 | struct kvm_lapic_state *s) |
2100 | { | 2090 | { |
2101 | vcpu_load(vcpu); | ||
2102 | memcpy(s->regs, vcpu->arch.apic->regs, sizeof *s); | 2091 | memcpy(s->regs, vcpu->arch.apic->regs, sizeof *s); |
2103 | vcpu_put(vcpu); | ||
2104 | 2092 | ||
2105 | return 0; | 2093 | return 0; |
2106 | } | 2094 | } |
@@ -2108,11 +2096,9 @@ static int kvm_vcpu_ioctl_get_lapic(struct kvm_vcpu *vcpu, | |||
2108 | static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu, | 2096 | static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu, |
2109 | struct kvm_lapic_state *s) | 2097 | struct kvm_lapic_state *s) |
2110 | { | 2098 | { |
2111 | vcpu_load(vcpu); | ||
2112 | memcpy(vcpu->arch.apic->regs, s->regs, sizeof *s); | 2099 | memcpy(vcpu->arch.apic->regs, s->regs, sizeof *s); |
2113 | kvm_apic_post_state_restore(vcpu); | 2100 | kvm_apic_post_state_restore(vcpu); |
2114 | update_cr8_intercept(vcpu); | 2101 | update_cr8_intercept(vcpu); |
2115 | vcpu_put(vcpu); | ||
2116 | 2102 | ||
2117 | return 0; | 2103 | return 0; |
2118 | } | 2104 | } |
@@ -2124,20 +2110,15 @@ static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, | |||
2124 | return -EINVAL; | 2110 | return -EINVAL; |
2125 | if (irqchip_in_kernel(vcpu->kvm)) | 2111 | if (irqchip_in_kernel(vcpu->kvm)) |
2126 | return -ENXIO; | 2112 | return -ENXIO; |
2127 | vcpu_load(vcpu); | ||
2128 | 2113 | ||
2129 | kvm_queue_interrupt(vcpu, irq->irq, false); | 2114 | kvm_queue_interrupt(vcpu, irq->irq, false); |
2130 | 2115 | ||
2131 | vcpu_put(vcpu); | ||
2132 | |||
2133 | return 0; | 2116 | return 0; |
2134 | } | 2117 | } |
2135 | 2118 | ||
2136 | static int kvm_vcpu_ioctl_nmi(struct kvm_vcpu *vcpu) | 2119 | static int kvm_vcpu_ioctl_nmi(struct kvm_vcpu *vcpu) |
2137 | { | 2120 | { |
2138 | vcpu_load(vcpu); | ||
2139 | kvm_inject_nmi(vcpu); | 2121 | kvm_inject_nmi(vcpu); |
2140 | vcpu_put(vcpu); | ||
2141 | 2122 | ||
2142 | return 0; | 2123 | return 0; |
2143 | } | 2124 | } |
@@ -2157,7 +2138,6 @@ static int kvm_vcpu_ioctl_x86_setup_mce(struct kvm_vcpu *vcpu, | |||
2157 | int r; | 2138 | int r; |
2158 | unsigned bank_num = mcg_cap & 0xff, bank; | 2139 | unsigned bank_num = mcg_cap & 0xff, bank; |
2159 | 2140 | ||
2160 | vcpu_load(vcpu); | ||
2161 | r = -EINVAL; | 2141 | r = -EINVAL; |
2162 | if (!bank_num || bank_num >= KVM_MAX_MCE_BANKS) | 2142 | if (!bank_num || bank_num >= KVM_MAX_MCE_BANKS) |
2163 | goto out; | 2143 | goto out; |
@@ -2172,7 +2152,6 @@ static int kvm_vcpu_ioctl_x86_setup_mce(struct kvm_vcpu *vcpu, | |||
2172 | for (bank = 0; bank < bank_num; bank++) | 2152 | for (bank = 0; bank < bank_num; bank++) |
2173 | vcpu->arch.mce_banks[bank*4] = ~(u64)0; | 2153 | vcpu->arch.mce_banks[bank*4] = ~(u64)0; |
2174 | out: | 2154 | out: |
2175 | vcpu_put(vcpu); | ||
2176 | return r; | 2155 | return r; |
2177 | } | 2156 | } |
2178 | 2157 | ||
@@ -2230,8 +2209,6 @@ static int kvm_vcpu_ioctl_x86_set_mce(struct kvm_vcpu *vcpu, | |||
2230 | static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu, | 2209 | static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu, |
2231 | struct kvm_vcpu_events *events) | 2210 | struct kvm_vcpu_events *events) |
2232 | { | 2211 | { |
2233 | vcpu_load(vcpu); | ||
2234 | |||
2235 | events->exception.injected = | 2212 | events->exception.injected = |
2236 | vcpu->arch.exception.pending && | 2213 | vcpu->arch.exception.pending && |
2237 | !kvm_exception_is_soft(vcpu->arch.exception.nr); | 2214 | !kvm_exception_is_soft(vcpu->arch.exception.nr); |
@@ -2256,8 +2233,6 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu, | |||
2256 | events->flags = (KVM_VCPUEVENT_VALID_NMI_PENDING | 2233 | events->flags = (KVM_VCPUEVENT_VALID_NMI_PENDING |
2257 | | KVM_VCPUEVENT_VALID_SIPI_VECTOR | 2234 | | KVM_VCPUEVENT_VALID_SIPI_VECTOR |
2258 | | KVM_VCPUEVENT_VALID_SHADOW); | 2235 | | KVM_VCPUEVENT_VALID_SHADOW); |
2259 | |||
2260 | vcpu_put(vcpu); | ||
2261 | } | 2236 | } |
2262 | 2237 | ||
2263 | static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu, | 2238 | static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu, |
@@ -2268,8 +2243,6 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu, | |||
2268 | | KVM_VCPUEVENT_VALID_SHADOW)) | 2243 | | KVM_VCPUEVENT_VALID_SHADOW)) |
2269 | return -EINVAL; | 2244 | return -EINVAL; |
2270 | 2245 | ||
2271 | vcpu_load(vcpu); | ||
2272 | |||
2273 | vcpu->arch.exception.pending = events->exception.injected; | 2246 | vcpu->arch.exception.pending = events->exception.injected; |
2274 | vcpu->arch.exception.nr = events->exception.nr; | 2247 | vcpu->arch.exception.nr = events->exception.nr; |
2275 | vcpu->arch.exception.has_error_code = events->exception.has_error_code; | 2248 | vcpu->arch.exception.has_error_code = events->exception.has_error_code; |
@@ -2292,22 +2265,16 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu, | |||
2292 | if (events->flags & KVM_VCPUEVENT_VALID_SIPI_VECTOR) | 2265 | if (events->flags & KVM_VCPUEVENT_VALID_SIPI_VECTOR) |
2293 | vcpu->arch.sipi_vector = events->sipi_vector; | 2266 | vcpu->arch.sipi_vector = events->sipi_vector; |
2294 | 2267 | ||
2295 | vcpu_put(vcpu); | ||
2296 | |||
2297 | return 0; | 2268 | return 0; |
2298 | } | 2269 | } |
2299 | 2270 | ||
2300 | static void kvm_vcpu_ioctl_x86_get_debugregs(struct kvm_vcpu *vcpu, | 2271 | static void kvm_vcpu_ioctl_x86_get_debugregs(struct kvm_vcpu *vcpu, |
2301 | struct kvm_debugregs *dbgregs) | 2272 | struct kvm_debugregs *dbgregs) |
2302 | { | 2273 | { |
2303 | vcpu_load(vcpu); | ||
2304 | |||
2305 | memcpy(dbgregs->db, vcpu->arch.db, sizeof(vcpu->arch.db)); | 2274 | memcpy(dbgregs->db, vcpu->arch.db, sizeof(vcpu->arch.db)); |
2306 | dbgregs->dr6 = vcpu->arch.dr6; | 2275 | dbgregs->dr6 = vcpu->arch.dr6; |
2307 | dbgregs->dr7 = vcpu->arch.dr7; | 2276 | dbgregs->dr7 = vcpu->arch.dr7; |
2308 | dbgregs->flags = 0; | 2277 | dbgregs->flags = 0; |
2309 | |||
2310 | vcpu_put(vcpu); | ||
2311 | } | 2278 | } |
2312 | 2279 | ||
2313 | static int kvm_vcpu_ioctl_x86_set_debugregs(struct kvm_vcpu *vcpu, | 2280 | static int kvm_vcpu_ioctl_x86_set_debugregs(struct kvm_vcpu *vcpu, |
@@ -2316,14 +2283,10 @@ static int kvm_vcpu_ioctl_x86_set_debugregs(struct kvm_vcpu *vcpu, | |||
2316 | if (dbgregs->flags) | 2283 | if (dbgregs->flags) |
2317 | return -EINVAL; | 2284 | return -EINVAL; |
2318 | 2285 | ||
2319 | vcpu_load(vcpu); | ||
2320 | |||
2321 | memcpy(vcpu->arch.db, dbgregs->db, sizeof(vcpu->arch.db)); | 2286 | memcpy(vcpu->arch.db, dbgregs->db, sizeof(vcpu->arch.db)); |
2322 | vcpu->arch.dr6 = dbgregs->dr6; | 2287 | vcpu->arch.dr6 = dbgregs->dr6; |
2323 | vcpu->arch.dr7 = dbgregs->dr7; | 2288 | vcpu->arch.dr7 = dbgregs->dr7; |
2324 | 2289 | ||
2325 | vcpu_put(vcpu); | ||
2326 | |||
2327 | return 0; | 2290 | return 0; |
2328 | } | 2291 | } |
2329 | 2292 | ||
@@ -2335,6 +2298,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp, | |||
2335 | int r; | 2298 | int r; |
2336 | struct kvm_lapic_state *lapic = NULL; | 2299 | struct kvm_lapic_state *lapic = NULL; |
2337 | 2300 | ||
2301 | vcpu_load(vcpu); | ||
2338 | switch (ioctl) { | 2302 | switch (ioctl) { |
2339 | case KVM_GET_LAPIC: { | 2303 | case KVM_GET_LAPIC: { |
2340 | r = -EINVAL; | 2304 | r = -EINVAL; |
@@ -2481,9 +2445,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp, | |||
2481 | r = -EFAULT; | 2445 | r = -EFAULT; |
2482 | if (copy_from_user(&mce, argp, sizeof mce)) | 2446 | if (copy_from_user(&mce, argp, sizeof mce)) |
2483 | goto out; | 2447 | goto out; |
2484 | vcpu_load(vcpu); | ||
2485 | r = kvm_vcpu_ioctl_x86_set_mce(vcpu, &mce); | 2448 | r = kvm_vcpu_ioctl_x86_set_mce(vcpu, &mce); |
2486 | vcpu_put(vcpu); | ||
2487 | break; | 2449 | break; |
2488 | } | 2450 | } |
2489 | case KVM_GET_VCPU_EVENTS: { | 2451 | case KVM_GET_VCPU_EVENTS: { |
@@ -2534,6 +2496,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp, | |||
2534 | r = -EINVAL; | 2496 | r = -EINVAL; |
2535 | } | 2497 | } |
2536 | out: | 2498 | out: |
2499 | vcpu_put(vcpu); | ||
2537 | kfree(lapic); | 2500 | kfree(lapic); |
2538 | return r; | 2501 | return r; |
2539 | } | 2502 | } |