All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm <kvm@vger.kernel.org>, Yongjie Ren <yongjie.ren@intel.com>
Subject: Re: KVM: x86: fix deadlock in clock-in-progress request handling
Date: Mon, 18 Mar 2013 19:20:11 +0200	[thread overview]
Message-ID: <20130318172011.GM4020@redhat.com> (raw)
In-Reply-To: <20130318165432.GA12342@amt.cnet>

On Mon, Mar 18, 2013 at 01:54:32PM -0300, Marcelo Tosatti wrote:
> 
> There is a deadlock in pvclock handling:
> 
> cpu0:                                               cpu1:
> kvm_gen_update_masterclock()
>                                               kvm_guest_time_update()
>  spin_lock(pvclock_gtod_sync_lock)
>                                                local_irq_save(flags)
>                                               
> spin_lock(pvclock_gtod_sync_lock)
> 
>  kvm_make_mclock_inprogress_request(kvm)
>   make_all_cpus_request()
>    smp_call_function_many()
> 
> Now if smp_call_function_many() called by cpu0 tries to call function on
> cpu1 there will be a deadlock.
> 
> Fix by moving pvclock_gtod_sync_lock protected section outside irq
> disabled section.
> 
> Analyzed by Gleb Natapov <gleb@redhat.com>
> Reported-and-Tested-by: Yongjie Ren <yongjie.ren@intel.com>
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> 
Acked-by: Gleb Natapov <gleb@redhat.com>

> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index f71500a..f7c850b 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -1416,15 +1416,6 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
>  	kernel_ns = 0;
>  	host_tsc = 0;
>  
> -	/* Keep irq disabled to prevent changes to the clock */
> -	local_irq_save(flags);
> -	this_tsc_khz = __get_cpu_var(cpu_tsc_khz);
> -	if (unlikely(this_tsc_khz == 0)) {
> -		local_irq_restore(flags);
> -		kvm_make_request(KVM_REQ_CLOCK_UPDATE, v);
> -		return 1;
> -	}
> -
>  	/*
>  	 * If the host uses TSC clock, then passthrough TSC as stable
>  	 * to the guest.
> @@ -1436,6 +1427,15 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
>  		kernel_ns = ka->master_kernel_ns;
>  	}
>  	spin_unlock(&ka->pvclock_gtod_sync_lock);
> +
> +	/* Keep irq disabled to prevent changes to the clock */
> +	local_irq_save(flags);
> +	this_tsc_khz = __get_cpu_var(cpu_tsc_khz);
> +	if (unlikely(this_tsc_khz == 0)) {
> +		local_irq_restore(flags);
> +		kvm_make_request(KVM_REQ_CLOCK_UPDATE, v);
> +		return 1;
> +	}
>  	if (!use_master_clock) {
>  		host_tsc = native_read_tsc();
>  		kernel_ns = get_kernel_ns();

--
			Gleb.

      reply	other threads:[~2013-03-18 17:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-18 16:54 KVM: x86: fix deadlock in clock-in-progress request handling Marcelo Tosatti
2013-03-18 17:20 ` Gleb Natapov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130318172011.GM4020@redhat.com \
    --to=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=yongjie.ren@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.