Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754147AbbGBAzX (ORCPT ); Wed, 1 Jul 2015 20:55:23 -0400 Received: from m13-44.163.com ([220.181.13.44]:36152 "EHLO m13-44.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753302AbbGBAzS (ORCPT ); Wed, 1 Jul 2015 20:55:18 -0400 X-Greylist: delayed 954 seconds by postgrey-1.27 at vger.kernel.org; Wed, 01 Jul 2015 20:55:17 EDT X-Originating-IP: [59.38.97.102] Date: Thu, 2 Jul 2015 08:38:26 +0800 (CST) From: cfme_admin To: "Wanpeng Li" Cc: "mingo@redhat.com" , "peterz@infradead.org" , "linux-kernel@vger.kernel.org" Subject: Re:Re: [PATCH] sched: fix BUG in preempt_notifier X-Priority: 3 X-Mailer: Coremail Webmail Server Version SP_ntes V3.5 build 20150119(59087.7062) Copyright (c) 2002-2015 www.mailtech.cn 163com In-Reply-To: References: <1435732410-18060-1-git-send-email-cfme_admin@163.com> Content-Type: text/plain; charset=UTF-8 MIME-Version: 1.0 Message-ID: <11b09322.1d7ab.14e4c33481b.Coremail.cfme_admin@163.com> X-CM-TRANSID: LMGowAAHDm4DiJRV7lRiAQ--.11356W X-CM-SenderInfo: 5fipvspdgpx0i6rwjhhfrp/1tbiVBMqd1UL3wEq-gABsP X-Coremail-Antispam: 1U5529EdanIXcx71UUUUU7vcSsGvfC2KfnxnUU== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id t620tSB1020742 Content-Length: 3975 Lines: 112 This is a better way to solve this bug. Thanks. At 2015-07-01 15:41:28, "Wanpeng Li" wrote: > > >On 7/1/15 2:33 PM, Lidong Chen wrote: >> Signed-off-by: Lidong Chen > >Subject: sched,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. > >Cc: Gleb Natapov >Fixes: 1cde2930e154 ("sched/preempt: Add static_key() to preempt_notifiers") >Reported-and-Tested-by: Pontus Fuchs >Signed-off-by: Peter Zijlstra (Intel) > > >If this commit in tip tree fix your bug? > >Regards, >Wanpeng Li > >> --- >> kernel/sched/core.c | 25 ++++--------------------- >> 1 file changed, 4 insertions(+), 21 deletions(-) >> >> diff --git a/kernel/sched/core.c b/kernel/sched/core.c >> index b803e1b..4a5a964 100644 >> --- a/kernel/sched/core.c >> +++ b/kernel/sched/core.c >> @@ -2318,15 +2318,12 @@ void wake_up_new_task(struct task_struct *p) >> >> #ifdef CONFIG_PREEMPT_NOTIFIERS >> >> -static struct static_key preempt_notifier_key = STATIC_KEY_INIT_FALSE; >> - >> /** >> * preempt_notifier_register - tell me when current is being preempted & rescheduled >> * @notifier: notifier struct to register >> */ >> void preempt_notifier_register(struct preempt_notifier *notifier) >> { >> - static_key_slow_inc(&preempt_notifier_key); >> hlist_add_head(¬ifier->link, ¤t->preempt_notifiers); >> } >> EXPORT_SYMBOL_GPL(preempt_notifier_register); >> @@ -2340,11 +2337,10 @@ EXPORT_SYMBOL_GPL(preempt_notifier_register); >> void preempt_notifier_unregister(struct preempt_notifier *notifier) >> { >> hlist_del(¬ifier->link); >> - static_key_slow_dec(&preempt_notifier_key); >> } >> EXPORT_SYMBOL_GPL(preempt_notifier_unregister); >> >> -static void __fire_sched_in_preempt_notifiers(struct task_struct *curr) >> +static void fire_sched_in_preempt_notifiers(struct task_struct *curr) >> { >> struct preempt_notifier *notifier; >> >> @@ -2352,14 +2348,9 @@ static void __fire_sched_in_preempt_notifiers(struct task_struct *curr) >> notifier->ops->sched_in(notifier, raw_smp_processor_id()); >> } >> >> -static __always_inline void fire_sched_in_preempt_notifiers(struct task_struct *curr) >> -{ >> - if (static_key_false(&preempt_notifier_key)) >> - __fire_sched_in_preempt_notifiers(curr); >> -} >> >> static void >> -__fire_sched_out_preempt_notifiers(struct task_struct *curr, >> +fire_sched_out_preempt_notifiers(struct task_struct *curr, >> struct task_struct *next) >> { >> struct preempt_notifier *notifier; >> @@ -2368,21 +2359,13 @@ __fire_sched_out_preempt_notifiers(struct task_struct *curr, >> notifier->ops->sched_out(notifier, next); >> } >> >> -static __always_inline void >> -fire_sched_out_preempt_notifiers(struct task_struct *curr, >> - struct task_struct *next) >> -{ >> - if (static_key_false(&preempt_notifier_key)) >> - __fire_sched_out_preempt_notifiers(curr, next); >> -} >> - >> #else /* !CONFIG_PREEMPT_NOTIFIERS */ >> >> -static inline void fire_sched_in_preempt_notifiers(struct task_struct *curr) >> +static void fire_sched_in_preempt_notifiers(struct task_struct *curr) >> { >> } >> >> -static inline void >> +static void >> fire_sched_out_preempt_notifiers(struct task_struct *curr, >> struct task_struct *next) >> { > ????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?