From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8975ACA9ECB for ; Thu, 31 Oct 2019 14:21:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5DBAE20873 for ; Thu, 31 Oct 2019 14:21:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726793AbfJaOVd (ORCPT ); Thu, 31 Oct 2019 10:21:33 -0400 Received: from out30-54.freemail.mail.aliyun.com ([115.124.30.54]:48731 "EHLO out30-54.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726741AbfJaOVc (ORCPT ); Thu, 31 Oct 2019 10:21:32 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=laijs@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0Tgn2jJU_1572531643; Received: from 192.168.2.229(mailfrom:laijs@linux.alibaba.com fp:SMTPD_---0Tgn2jJU_1572531643) by smtp.aliyun-inc.com(127.0.0.1); Thu, 31 Oct 2019 22:20:44 +0800 Subject: Re: [PATCH 02/11] rcu: fix bug when rcu_exp_handler() in nested interrupt To: paulmck@kernel.org Cc: linux-kernel@vger.kernel.org, Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , rcu@vger.kernel.org References: <20191031100806.1326-1-laijs@linux.alibaba.com> <20191031100806.1326-3-laijs@linux.alibaba.com> <20191031134731.GP20975@paulmck-ThinkPad-P72> From: Lai Jiangshan Message-ID: Date: Thu, 31 Oct 2019 22:20:43 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20191031134731.GP20975@paulmck-ThinkPad-P72> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: rcu-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org On 2019/10/31 9:47 下午, Paul E. McKenney wrote: > On Thu, Oct 31, 2019 at 10:07:57AM +0000, Lai Jiangshan wrote: >> These is a possible bug (although which I can't triger yet) >> since 2015 8203d6d0ee78 >> (rcu: Use single-stage IPI algorithm for RCU expedited grace period) >> >> rcu_read_unlock() >> ->rcu_read_lock_nesting = -RCU_NEST_BIAS; >> interrupt(); // before or after rcu_read_unlock_special() >> rcu_read_lock() >> fetch some rcu protected pointers >> // exp GP starts in other cpu. >> some works >> NESTED interrupt for rcu_exp_handler(); >> report exp qs! BUG! > > Why would a quiescent state for the expedited grace period be reported > here? This CPU is still in an RCU read-side critical section, isn't it? > > Thanx, Paul Remember, the ->rcu_read_lock_nesting is -RCU_NEST_BIAS + 1 now. In for rcu_exp_handler(), it goes into this branch: rdp->exp_deferred_qs = true; if (!(preempt_count() & (PREEMPT_MASK | SOFTIRQ_MASK)) || WARN_ON_ONCE(rcu_dynticks_curr_cpu_in_eqs())) { rcu_preempt_deferred_qs(t); } else { and rcu_preempt_deferred_qs(t) report the QS no matter what the value of ->rcu_read_lock_nesting is if it is negative, in other words, "-RCU_NEST_BIAS + 1" is not different from "-RCU_NEST_BIAS" > >> // exp GP completes and pointers are freed in other cpu >> some works with the pointers. BUG >> rcu_read_unlock(); >> ->rcu_read_lock_nesting = 0; >> >> Although rcu_sched_clock_irq() can be in nested interrupt, >> there is no such similar bug since special.b.need_qs >> can only be set when ->rcu_read_lock_nesting > 0 >> >> Signed-off-by: Lai Jiangshan >> --- >> kernel/rcu/tree_exp.h | 5 +++-- >> kernel/rcu/tree_plugin.h | 9 ++++++--- >> 2 files changed, 9 insertions(+), 5 deletions(-) >> >> diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h >> index 6dec21909b30..c0d06bce35ea 100644 >> --- a/kernel/rcu/tree_exp.h >> +++ b/kernel/rcu/tree_exp.h >> @@ -664,8 +664,9 @@ static void rcu_exp_handler(void *unused) >> * Otherwise, force a context switch after the CPU enables everything. >> */ >> rdp->exp_deferred_qs = true; >> - if (!(preempt_count() & (PREEMPT_MASK | SOFTIRQ_MASK)) || >> - WARN_ON_ONCE(rcu_dynticks_curr_cpu_in_eqs())) { >> + if (rcu_preempt_need_deferred_qs(t) && >> + (!(preempt_count() & (PREEMPT_MASK | SOFTIRQ_MASK)) || >> + WARN_ON_ONCE(rcu_dynticks_curr_cpu_in_eqs()))) { >> rcu_preempt_deferred_qs(t); >> } else { >> set_tsk_need_resched(t); >> diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h >> index d4c482490589..59ef10da1e39 100644 >> --- a/kernel/rcu/tree_plugin.h >> +++ b/kernel/rcu/tree_plugin.h >> @@ -549,9 +549,12 @@ rcu_preempt_deferred_qs_irqrestore(struct task_struct *t, unsigned long flags) >> */ >> static bool rcu_preempt_need_deferred_qs(struct task_struct *t) >> { >> - return (__this_cpu_read(rcu_data.exp_deferred_qs) || >> - READ_ONCE(t->rcu_read_unlock_special.s)) && >> - t->rcu_read_lock_nesting <= 0; >> + return (__this_cpu_read(rcu_data.exp_deferred_qs) && >> + (!t->rcu_read_lock_nesting || >> + t->rcu_read_lock_nesting == -RCU_NEST_BIAS)) >> + || >> + (READ_ONCE(t->rcu_read_unlock_special.s) && >> + t->rcu_read_lock_nesting <= 0); >> } >> >> /* >> -- >> 2.20.1 >>