public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: mingo@kernel.org, hpa@zytor.com, pontus.fuchs@gmail.com,
	peterz@infradead.org, gleb@kernel.org, bp@alien8.de,
	linux-kernel@vger.kernel.org, tglx@linutronix.de,
	torvalds@linux-foundation.org, akpm@linux-foundation.org,
	linux-tip-commits@vger.kernel.org
Subject: Re: [tip:sched/urgent] sched/preempt, kvm: Fix KVM preempt_notifier usage
Date: Fri, 3 Jul 2015 13:23:52 +0200	[thread overview]
Message-ID: <559670C8.3020709@redhat.com> (raw)
In-Reply-To: <tip-6efde1d3716b7d055d3310bccba2df244cf430d7@git.kernel.org>



On 30/06/2015 13:10, tip-bot for Peter Zijlstra wrote:
> Commit-ID:  6efde1d3716b7d055d3310bccba2df244cf430d7
> Gitweb:     http://git.kernel.org/tip/6efde1d3716b7d055d3310bccba2df244cf430d7
> Author:     Peter Zijlstra <peterz@infradead.org>
> AuthorDate: Thu, 25 Jun 2015 14:55:14 +0200
> Committer:  Ingo Molnar <mingo@kernel.org>
> CommitDate: Tue, 30 Jun 2015 07:58:53 +0200
> 
> sched/preempt, kvm: Fix KVM preempt_notifier usage
> 
> The preempt-notifier API needs to sleep with the addition of the
> static_key, we do however need to hold off preemption while
> modifying the preempt notifier list, otherwise a preemption
> could observe an inconsistent list state.
> 
> There is no reason to have preemption disabled in the caller,
> registering a preempt notifier is a purely task local affair.
> 
> Therefore move the preempt_disable into the functions and change
> the callers to a preemptible context.
> 
> Reported-and-Tested-by: Pontus Fuchs <pontus.fuchs@gmail.com>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Gleb Natapov <gleb@kernel.org>
> Cc: H. Peter Anvin <hpa@zytor.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Pontus Fuchs <pontus.fuchs@gmail.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Fixes: 1cde2930e154 ("sched/preempt: Add static_key() to preempt_notifiers")
> Link: http://lkml.kernel.org/r/20150625125514.GA3644@twins.programming.kicks-ass.net
> Signed-off-by: Ingo Molnar <mingo@kernel.org>
> ---
>  kernel/sched/core.c | 11 +++++++++++
>  virt/kvm/kvm_main.c |  5 +++--
>  2 files changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index c86935a..5bcf926 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -2138,7 +2138,12 @@ static struct static_key preempt_notifier_key = STATIC_KEY_INIT_FALSE;
>  void preempt_notifier_register(struct preempt_notifier *notifier)
>  {
>  	static_key_slow_inc(&preempt_notifier_key);
> +	/*
> +	 * Avoid preemption while changing the preempt notifier list.
> +	 */
> +	preempt_disable();
>  	hlist_add_head(&notifier->link, &current->preempt_notifiers);
> +	preempt_enable();
>  }
>  EXPORT_SYMBOL_GPL(preempt_notifier_register);
>  
> @@ -2150,7 +2155,13 @@ EXPORT_SYMBOL_GPL(preempt_notifier_register);
>   */
>  void preempt_notifier_unregister(struct preempt_notifier *notifier)
>  {
> +	/*
> +	 * Avoid preemption while changing the preempt notifier list.
> +	 */
> +	preempt_disable();
>  	hlist_del(&notifier->link);
> +	preempt_enable();
> +
>  	static_key_slow_dec(&preempt_notifier_key);
>  }
>  EXPORT_SYMBOL_GPL(preempt_notifier_unregister);
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 9097741..d7aafa0 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -128,8 +128,9 @@ int vcpu_load(struct kvm_vcpu *vcpu)
>  
>  	if (mutex_lock_killable(&vcpu->mutex))
>  		return -EINTR;
> -	cpu = get_cpu();
>  	preempt_notifier_register(&vcpu->preempt_notifier);
> +
> +	cpu = get_cpu();
>  	kvm_arch_vcpu_load(vcpu, cpu);
>  	put_cpu();
>  	return 0;
> @@ -139,8 +140,8 @@ void vcpu_put(struct kvm_vcpu *vcpu)
>  {
>  	preempt_disable();
>  	kvm_arch_vcpu_put(vcpu);
> -	preempt_notifier_unregister(&vcpu->preempt_notifier);
>  	preempt_enable();
> +	preempt_notifier_unregister(&vcpu->preempt_notifier);
>  	mutex_unlock(&vcpu->mutex);
>  }
>  
> 

NACK.

Paolo

  reply	other threads:[~2015-07-03 11:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-25 12:00 Regression: sched/preempt: Add static_key() to preempt_notifiers breaks my KVM Pontus Fuchs
2015-06-25 12:09 ` Peter Zijlstra
2015-06-25 12:15   ` Pontus Fuchs
2015-06-25 12:55     ` [PATCH] sched,kvm: Fix KVM preempt_notifier usage Peter Zijlstra
2015-06-30 11:10       ` [tip:sched/urgent] sched/preempt, kvm: " tip-bot for Peter Zijlstra
2015-07-03 11:23         ` Paolo Bonzini [this message]
2015-07-03 11:12       ` [PATCH] sched,kvm: " Paolo Bonzini
2015-07-03 12:19         ` Peter Zijlstra
2015-07-03 12:31           ` Paolo Bonzini
2015-07-03 13:17             ` Peter Zijlstra
2015-07-03 15:16               ` Peter Zijlstra
2015-07-03 15:26                 ` Paolo Bonzini
2015-07-03 15:38                   ` Paolo Bonzini
2015-07-03 15:42                     ` Peter Zijlstra
2015-07-03 15:46                       ` Paolo Bonzini
2015-07-03 15:57                         ` Takashi Iwai
2015-06-30 13:47     ` Regression: sched/preempt: Add static_key() to preempt_notifiers breaks my KVM Josh Boyer
2015-07-01  6:55       ` Ingo Molnar
2015-07-03 13:15         ` Takashi Iwai

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=559670C8.3020709@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=gleb@kernel.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pontus.fuchs@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox