Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752497AbbF3LL3 (ORCPT ); Tue, 30 Jun 2015 07:11:29 -0400 Received: from terminus.zytor.com ([198.137.202.10]:42748 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751199AbbF3LLU (ORCPT ); Tue, 30 Jun 2015 07:11:20 -0400 Date: Tue, 30 Jun 2015 04:10:24 -0700 From: tip-bot for Peter Zijlstra Message-ID: Cc: peterz@infradead.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, bp@alien8.de, gleb@kernel.org, akpm@linux-foundation.org, torvalds@linux-foundation.org, hpa@zytor.com, pontus.fuchs@gmail.com, mingo@kernel.org Reply-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 In-Reply-To: <20150625125514.GA3644@twins.programming.kicks-ass.net> References: <20150625125514.GA3644@twins.programming.kicks-ass.net> To: linux-tip-commits@vger.kernel.org Subject: [tip:sched/urgent] sched/preempt, kvm: Fix KVM preempt_notifier usage Git-Commit-ID: 6efde1d3716b7d055d3310bccba2df244cf430d7 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3505 Lines: 99 Commit-ID: 6efde1d3716b7d055d3310bccba2df244cf430d7 Gitweb: http://git.kernel.org/tip/6efde1d3716b7d055d3310bccba2df244cf430d7 Author: Peter Zijlstra AuthorDate: Thu, 25 Jun 2015 14:55:14 +0200 Committer: Ingo Molnar 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 Signed-off-by: Peter Zijlstra (Intel) Cc: Andrew Morton Cc: Borislav Petkov Cc: Gleb Natapov Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Pontus Fuchs Cc: Thomas Gleixner 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 --- 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(¬ifier->link, ¤t->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(¬ifier->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); } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/