diff options
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r-- | arch/x86/kvm/x86.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 76f54461f7cb..c243b81e3c74 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -120,7 +120,7 @@ struct kvm_shared_msrs { | |||
120 | }; | 120 | }; |
121 | 121 | ||
122 | static struct kvm_shared_msrs_global __read_mostly shared_msrs_global; | 122 | static struct kvm_shared_msrs_global __read_mostly shared_msrs_global; |
123 | static DEFINE_PER_CPU(struct kvm_shared_msrs, shared_msrs); | 123 | static struct kvm_shared_msrs __percpu *shared_msrs; |
124 | 124 | ||
125 | struct kvm_stats_debugfs_item debugfs_entries[] = { | 125 | struct kvm_stats_debugfs_item debugfs_entries[] = { |
126 | { "pf_fixed", VCPU_STAT(pf_fixed) }, | 126 | { "pf_fixed", VCPU_STAT(pf_fixed) }, |
@@ -191,10 +191,10 @@ static void kvm_on_user_return(struct user_return_notifier *urn) | |||
191 | 191 | ||
192 | static void shared_msr_update(unsigned slot, u32 msr) | 192 | static void shared_msr_update(unsigned slot, u32 msr) |
193 | { | 193 | { |
194 | struct kvm_shared_msrs *smsr; | ||
195 | u64 value; | 194 | u64 value; |
195 | unsigned int cpu = smp_processor_id(); | ||
196 | struct kvm_shared_msrs *smsr = per_cpu_ptr(shared_msrs, cpu); | ||
196 | 197 | ||
197 | smsr = &__get_cpu_var(shared_msrs); | ||
198 | /* only read, and nobody should modify it at this time, | 198 | /* only read, and nobody should modify it at this time, |
199 | * so don't need lock */ | 199 | * so don't need lock */ |
200 | if (slot >= shared_msrs_global.nr) { | 200 | if (slot >= shared_msrs_global.nr) { |
@@ -226,7 +226,8 @@ static void kvm_shared_msr_cpu_online(void) | |||
226 | 226 | ||
227 | void kvm_set_shared_msr(unsigned slot, u64 value, u64 mask) | 227 | void kvm_set_shared_msr(unsigned slot, u64 value, u64 mask) |
228 | { | 228 | { |
229 | struct kvm_shared_msrs *smsr = &__get_cpu_var(shared_msrs); | 229 | unsigned int cpu = smp_processor_id(); |
230 | struct kvm_shared_msrs *smsr = per_cpu_ptr(shared_msrs, cpu); | ||
230 | 231 | ||
231 | if (((value ^ smsr->values[slot].curr) & mask) == 0) | 232 | if (((value ^ smsr->values[slot].curr) & mask) == 0) |
232 | return; | 233 | return; |
@@ -242,7 +243,8 @@ EXPORT_SYMBOL_GPL(kvm_set_shared_msr); | |||
242 | 243 | ||
243 | static void drop_user_return_notifiers(void *ignore) | 244 | static void drop_user_return_notifiers(void *ignore) |
244 | { | 245 | { |
245 | struct kvm_shared_msrs *smsr = &__get_cpu_var(shared_msrs); | 246 | unsigned int cpu = smp_processor_id(); |
247 | struct kvm_shared_msrs *smsr = per_cpu_ptr(shared_msrs, cpu); | ||
246 | 248 | ||
247 | if (smsr->registered) | 249 | if (smsr->registered) |
248 | kvm_on_user_return(&smsr->urn); | 250 | kvm_on_user_return(&smsr->urn); |
@@ -5233,9 +5235,16 @@ int kvm_arch_init(void *opaque) | |||
5233 | goto out; | 5235 | goto out; |
5234 | } | 5236 | } |
5235 | 5237 | ||
5238 | r = -ENOMEM; | ||
5239 | shared_msrs = alloc_percpu(struct kvm_shared_msrs); | ||
5240 | if (!shared_msrs) { | ||
5241 | printk(KERN_ERR "kvm: failed to allocate percpu kvm_shared_msrs\n"); | ||
5242 | goto out; | ||
5243 | } | ||
5244 | |||
5236 | r = kvm_mmu_module_init(); | 5245 | r = kvm_mmu_module_init(); |
5237 | if (r) | 5246 | if (r) |
5238 | goto out; | 5247 | goto out_free_percpu; |
5239 | 5248 | ||
5240 | kvm_set_mmio_spte_mask(); | 5249 | kvm_set_mmio_spte_mask(); |
5241 | kvm_init_msr_list(); | 5250 | kvm_init_msr_list(); |
@@ -5258,6 +5267,8 @@ int kvm_arch_init(void *opaque) | |||
5258 | 5267 | ||
5259 | return 0; | 5268 | return 0; |
5260 | 5269 | ||
5270 | out_free_percpu: | ||
5271 | free_percpu(shared_msrs); | ||
5261 | out: | 5272 | out: |
5262 | return r; | 5273 | return r; |
5263 | } | 5274 | } |
@@ -5275,6 +5286,7 @@ void kvm_arch_exit(void) | |||
5275 | #endif | 5286 | #endif |
5276 | kvm_x86_ops = NULL; | 5287 | kvm_x86_ops = NULL; |
5277 | kvm_mmu_module_exit(); | 5288 | kvm_mmu_module_exit(); |
5289 | free_percpu(shared_msrs); | ||
5278 | } | 5290 | } |
5279 | 5291 | ||
5280 | int kvm_emulate_halt(struct kvm_vcpu *vcpu) | 5292 | int kvm_emulate_halt(struct kvm_vcpu *vcpu) |