Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3684280ybd; Fri, 28 Jun 2019 13:07:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUMEceUIIsB9ZWiG1vUG0GnJcr45/9FfdX/S4wyKGg7Q1/+gHY1fal9cr6jbyB0LLNE9Kx X-Received: by 2002:a17:902:f216:: with SMTP id gn22mr13527028plb.118.1561752461153; Fri, 28 Jun 2019 13:07:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561752461; cv=none; d=google.com; s=arc-20160816; b=fH90AEoPwrv6lPMBafd2/qrZIPmzDBk+YZIDfiNrwzQdrozyD7dQzgNHwRzqZ34Cp3 E4ubiWxCVw6hLIK9+rkXQu8RSjt0F3P5yMS/8tp+/viaxikjWD3X7x/sGg2jzTW53D0h 29+uIIXX1mjXj4gb+ZyqCRhbLzi7D/mT8xm1/Pe8zFFyZz9G0wmVqKiuI+hRq1ScHN22 i5QW+c+gNlW3KKw5ZaPk9wAE5om3Z9FN/vHfn0vqDY//bHTHPDAh3x6qvj6wNVKwreOG 0TpKsYyxHbcA3ySvE2QiJZFFZWv92K5uWEIuxrZ6p52a54ZTrOc0jnE/ulkYaIcEz5Xk AhsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date; bh=BPcttKSHLS34U5MpuvEWu6W1hBjgTnIjMlovnRKbTA8=; b=I//gmQVSonBUp2ts/ihbz2Uwe+QixJZxwsYbWXhXcJ9YclOTjG231NPBV50u+qK8R6 LVuDN31hzO4dQHG/l6dBcTGE9Pbck9+OBQWq5klphewbBlpm3JmgAl8KwKsohZUkeCzZ F4Sb/3bNh5uyAFPub21WSbrgrtMavtEKB2jfmzfCo3HSId8PcL1sFB4O9LeN/rg6ZmZB 4L85Zv9Icxm28HArTzFgs8czbket0DSlUOc7et+GuAzRG/7iQKMZ3aEkLg+s8Nqf8OZ7 SeT+0ICXtTdrg3A6VQbsgLjlrSG5BXKTzzJg71wJhJ+LTW+eFyIM4012+FZMwBx/OupO BfYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d36si2981422pla.113.2019.06.28.13.07.23; Fri, 28 Jun 2019 13:07:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727099AbfF1UHE (ORCPT + 99 others); Fri, 28 Jun 2019 16:07:04 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:23678 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726809AbfF1UHE (ORCPT ); Fri, 28 Jun 2019 16:07:04 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5SK3PAV106391; Fri, 28 Jun 2019 16:06:09 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 2tdnvsyx5q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 28 Jun 2019 16:06:09 -0400 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.27/8.16.0.27) with SMTP id x5SK4k7j110123; Fri, 28 Jun 2019 16:06:09 -0400 Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0b-001b2d01.pphosted.com with ESMTP id 2tdnvsyx4a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 28 Jun 2019 16:06:09 -0400 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id x5SK0VTL009511; Fri, 28 Jun 2019 20:06:07 GMT Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by ppma01dal.us.ibm.com with ESMTP id 2t9by7qq53-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 28 Jun 2019 20:06:07 +0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x5SK66gF52756924 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 28 Jun 2019 20:06:06 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EE3D5B2067; Fri, 28 Jun 2019 20:06:05 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C1122B2065; Fri, 28 Jun 2019 20:06:05 +0000 (GMT) Received: from paulmck-ThinkPad-W541 (unknown [9.70.82.26]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 28 Jun 2019 20:06:05 +0000 (GMT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id 8F1AB16C5D8D; Fri, 28 Jun 2019 13:06:06 -0700 (PDT) Date: Fri, 28 Jun 2019 13:06:06 -0700 From: "Paul E. McKenney" To: Joel Fernandes Cc: Sebastian Andrzej Siewior , Steven Rostedt , rcu , LKML , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan Subject: Re: [RFC] Deadlock via recursive wakeup via RCU with threadirqs Message-ID: <20190628200606.GC26519@linux.ibm.com> Reply-To: paulmck@linux.ibm.com References: <20190627173831.GW26519@linux.ibm.com> <20190627181638.GA209455@google.com> <20190627184107.GA26519@linux.ibm.com> <20190628164008.GB240964@google.com> <20190628164559.GC240964@google.com> <20190628173011.GX26519@linux.ibm.com> <20190628174545.pwgwi3wxl2eapkvm@linutronix.de> <20190628182216.GY26519@linux.ibm.com> <20190628192923.GB89956@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190628192923.GB89956@google.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-28_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906280229 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 28, 2019 at 03:29:23PM -0400, Joel Fernandes wrote: > On Fri, Jun 28, 2019 at 11:22:16AM -0700, Paul E. McKenney wrote: > > On Fri, Jun 28, 2019 at 07:45:45PM +0200, Sebastian Andrzej Siewior wrote: > > > On 2019-06-28 10:30:11 [-0700], Paul E. McKenney wrote: > > > > > I believe the .blocked field remains set even though we are not any more in a > > > > > reader section because of deferred processing of the blocked lists that you > > > > > mentioned yesterday. > > > > > > > > That can indeed happen. However, in current -rcu, that would mean > > > > that .deferred_qs is also set, which (if in_irq()) would prevent > > > > the raise_softirq_irqsoff() from being invoked. Which was why I was > > > > asking the questions about whether in_irq() returns true within threaded > > > > interrupts yesterday. If it does, I need to find if there is some way > > > > of determining whether rcu_read_unlock_special() is being called from > > > > a threaded interrupt in order to suppress the call to raise_softirq() > > > > in that case. > > > > > > Please not that: > > > | void irq_exit(void) > > > | { > > > |… > > > in_irq() returns true > > > | preempt_count_sub(HARDIRQ_OFFSET); > > > in_irq() returns false > > > | if (!in_interrupt() && local_softirq_pending()) > > > | invoke_softirq(); > > > > > > -> invoke_softirq() does > > > | if (!force_irqthreads) { > > > | __do_softirq(); > > > | } else { > > > | wakeup_softirqd(); > > > | } > > > > > > so for `force_irqthreads' rcu_read_unlock_special() within > > > wakeup_softirqd() will see false. > > > > OK, fair point. How about the following instead, again on -rcu? > > > > Here is the rationale for the new version of the "if" statement: > > > > 1. irqs_were_disabled: If interrupts are enabled, we should > > instead let the upcoming irq_enable()/local_bh_enable() > > do the rescheduling for us. > > 2. use_softirq: If we aren't using softirq, then > > raise_softirq_irqoff() will be unhelpful. > > 3a. in_interrupt(): If this returns true, the subsequent > > call to raise_softirq_irqoff() is guaranteed not to > > do a wakeup, so that call will be both very cheap and > > quite safe. > > 3b. Otherwise, if !in_interrupt(), if exp (an expedited RCU grace > > period is being blocked), then incurring wakeup overhead > > is worthwhile, and if also !.deferred_qs then scheduler locks > > cannot be held so the wakeup will be safe. > > > > Does that make more sense? > > This makes a lot of sense. It would be nice to stick these comments on top of > rcu_read_unlock_special() for future reference. I do have an expanded version in the commit log. I hope to get a more high-level description in comments. Thanx, Paul > thanks, > > - Joel > > > > > > Thanx, Paul > > > > ------------------------------------------------------------------------ > > > > diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h > > index 82c925df1d92..83333cfe8707 100644 > > --- a/kernel/rcu/tree_plugin.h > > +++ b/kernel/rcu/tree_plugin.h > > @@ -624,8 +624,9 @@ static void rcu_read_unlock_special(struct task_struct *t) > > (rdp->grpmask & rnp->expmask) || > > tick_nohz_full_cpu(rdp->cpu); > > // Need to defer quiescent state until everything is enabled. > > - if ((exp || in_irq()) && irqs_were_disabled && use_softirq && > > - (in_irq() || !t->rcu_read_unlock_special.b.deferred_qs)) { > > + if (irqs_were_disabled && use_softirq && > > + (in_interrupt() || > > + (exp && !t->rcu_read_unlock_special.b.deferred_qs))) { > > // Using softirq, safe to awaken, and we get > > // no help from enabling irqs, unlike bh/preempt. > > raise_softirq_irqoff(RCU_SOFTIRQ); > > >