Function user_notifier_unregister should be called only once for each registered user notifier. Function kvm_arch_hardware_disable can be executed from an IPI context which could cause a race condition with a VCPU returning to user mode and attempting to unregister the notifier.
Unified · Split
| @@ -210,7 +210,18 @@ static void kvm_on_user_return(struct user_return_notifier *urn) · 209 unmodified lines | |||
| 210 | struct kvm_shared_msrs *locals | 210 | struct kvm_shared_msrs *locals |
| 211 | = container_of(urn, struct kvm_shared_msrs, urn); | 211 | = container_of(urn, struct kvm_shared_msrs, urn); |
| 212 | struct kvm_shared_msr_values *values; | 212 | struct kvm_shared_msr_values *values; |
| 213 | unsigned long flags; | ||
| 213 | 214 | ||
| 215 | /* | ||
| 216 | * Disabling irqs at this point since the following code could be | ||
| 217 | * interrupted and executed through kvm_arch_hardware_disable() | ||
| 218 | */ | ||
| 219 | local_irq_save(flags); | ||
| 220 | if (locals->registered) { | ||
| 221 | locals->registered = false; | ||
| 222 | user_return_notifier_unregister(urn); | ||
| 223 | } | ||
| 224 | local_irq_restore(flags); | ||
| 214 | for (slot = 0; slot < shared_msrs_global.nr; ++slot) { | 225 | for (slot = 0; slot < shared_msrs_global.nr; ++slot) { |
| 215 | values = &locals->values[slot]; | 226 | values = &locals->values[slot]; |
| 216 | if (values->host != values->curr) { | 227 | if (values->host != values->curr) { |
| @@ -218,8 +229,6 @@ static void kvm_on_user_return(struct user_return_notifier *urn) · 1 unmodified line | |||
| 218 | values->curr = values->host; | 229 | values->curr = values->host; |
| 219 | } | 230 | } |
| 220 | } | 231 | } |
| 221 | locals->registered = false; | ||
| 222 | user_return_notifier_unregister(urn); | ||
| 223 | } | 232 | } |
| 224 | 233 | ||
| 225 | static void shared_msr_update(unsigned slot, u32 msr) | 234 | static void shared_msr_update(unsigned slot, u32 msr) |