From: Ignacio Alvarado Date: Wed, 28 Feb 2018 11:09:31 +0000 (+0000) Subject: KVM: Disable irq while unregistering user notifier X-Git-Tag: v4.1.12-124.31.3~1119 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f1e015ab372d9a6fe2f8381e39262e4cff895b84;p=users%2Fjedix%2Flinux-maple.git KVM: Disable irq while unregistering user notifier 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. Signed-off-by: Ignacio Alvarado Cc: stable@vger.kernel.org Fixes: 18863bdd60f8 ("KVM: x86 shared msr infrastructure") Reviewed-by: Paolo Bonzini Signed-off-by: Radim Krčmář (cherry picked from commit 1650b4ebc99da4c137bfbfc531be4a2405f951dd) OraBug: 27623575 Signed-off-by: Allan Xavier Reviewed-by: Darren Kenny Signed-off-by: Konrad Rzeszutek Wilk --- diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 304c48893c68..469d027df08e 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -187,7 +187,18 @@ static void kvm_on_user_return(struct user_return_notifier *urn) struct kvm_shared_msrs *locals = container_of(urn, struct kvm_shared_msrs, urn); struct kvm_shared_msr_values *values; + unsigned long flags; + /* + * Disabling irqs at this point since the following code could be + * interrupted and executed through kvm_arch_hardware_disable() + */ + local_irq_save(flags); + if (locals->registered) { + locals->registered = false; + user_return_notifier_unregister(urn); + } + local_irq_restore(flags); for (slot = 0; slot < shared_msrs_global.nr; ++slot) { values = &locals->values[slot]; if (values->host != values->curr) { @@ -195,8 +206,6 @@ static void kvm_on_user_return(struct user_return_notifier *urn) values->curr = values->host; } } - locals->registered = false; - user_return_notifier_unregister(urn); } static void shared_msr_update(unsigned slot, u32 msr)