Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2686175imm; Sun, 12 Aug 2018 21:20:50 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzaV4RwZ5svwhMTSMuPXsuIjuUw7cR0UP6kBL6/LTpHV/8TbDdFURj20RNXA42F5zPQer2j X-Received: by 2002:a63:fb57:: with SMTP id w23-v6mr15512329pgj.441.1534134050531; Sun, 12 Aug 2018 21:20:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534134050; cv=none; d=google.com; s=arc-20160816; b=Q8lOfUgf/N5k4/qexkwPVzU2ou4/ks5Qp6dlTCwDha/VKPKbcDBgXLTnQHpnZRLzBb oU3GmBtqq9/biGzZOu3M9ren0pyxPJx6cpTxhi0UaH7EX4IsZLJdfz/0uz8GPB4RCcRe drOc0jw5x9YHTvvaVFXgNtyeoorh5x7dytEHhZ7LNx7YKMsKeHmHDqeyOC2tSlnNQU4g ePbzq9eW+kA4ddVAfgdfBYGMklmfLgrADAm7ITMVtB+f1iQa2lLeBdbTZ7vTv0XHXYUn gEwk4hQddNgOOOYA9nTzTDzBXEWmsXt036tdaMPd0iDh7lCXIHvIFDbdnNcrek64rAqf WKsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:subject:cc:to :from:date:arc-authentication-results; bh=lQPVIMh5vU2Fcwsdmnxs5GkU2bT7OVy/smL/g+QjlmQ=; b=xoKQyIvvxXrcgLncPl/t04fECl5L7Nk4Y01Nnl1rdnJfurOhsVdv0XSN3Y3ZV+2mj7 4YRccdiu0cP5CM0XDjmJGuo1XC/m89Tz7RgoeuXAiSpVQk1c2Cq5hYU44zbgHODb7G9d goOSZT6sS/d+WFpLMSGvFcyucaOqL4njfl9WT+5tZ2XhA1KplKuhodga37FiInhu9xcJ Ow1W3pIc+AzeKg4cu6cTnKb1X9r0DaBbAyn4mfnAQ4dtpcLp5bw22AHqsftHbePsvaDE y5J8jkFrQbC1SdN9JAJ/PBI6MFLdKethQ8M6PsvkGLfv6uRZNonv3HryJeSFWI9uVay0 m38Q== 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 d7-v6si17475900pgc.445.2018.08.12.21.20.35; Sun, 12 Aug 2018 21:20:50 -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 S1728224AbeHMG64 (ORCPT + 99 others); Mon, 13 Aug 2018 02:58:56 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:47726 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728055AbeHMG6z (ORCPT ); Mon, 13 Aug 2018 02:58:55 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w7D4EA5l143434 for ; Mon, 13 Aug 2018 00:18:28 -0400 Received: from e14.ny.us.ibm.com (e14.ny.us.ibm.com [129.33.205.204]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ku0v334ed-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 13 Aug 2018 00:18:28 -0400 Received: from localhost by e14.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 13 Aug 2018 00:18:28 -0400 Received: from b01cxnp22034.gho.pok.ibm.com (9.57.198.24) by e14.ny.us.ibm.com (146.89.104.201) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 13 Aug 2018 00:18:25 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w7D4IOcf18481274 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 13 Aug 2018 04:18:24 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6D311B2065; Mon, 13 Aug 2018 00:17:42 -0400 (EDT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 552D3B2067; Mon, 13 Aug 2018 00:17:42 -0400 (EDT) Received: from paulmck-ThinkPad-W541 (unknown [9.80.219.61]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 13 Aug 2018 00:17:42 -0400 (EDT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id ADD7416C37A7; Sun, 12 Aug 2018 21:18:26 -0700 (PDT) Date: Sun, 12 Aug 2018 21:18:26 -0700 From: "Paul E. McKenney" To: Jia-Ju Bai Cc: dave@stgolabs.net, josh@joshtriplett.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com, Linux Kernel Mailing List Subject: Re: [BUG] kernel: rcu: a possible sleep-in-atomic-context bug in srcu_read_delay() Reply-To: paulmck@linux.vnet.ibm.com References: <4179b4d2-b832-abcd-d407-b865765f28d6@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4179b4d2-b832-abcd-d407-b865765f28d6@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 18081304-0052-0000-0000-0000031DFA57 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009533; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000266; SDB=6.01072742; UDB=6.00552672; IPR=6.00852693; MB=3.00022680; MTD=3.00000008; XFM=3.00000015; UTC=2018-08-13 04:18:27 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18081304-0053-0000-0000-00005DB5125B Message-Id: <20180813041826.GL24813@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-08-12_07:,, 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-1807170000 definitions=main-1808130046 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 13, 2018 at 11:04:10AM +0800, Jia-Ju Bai wrote: > The kernel may sleep with holding a spinlock. > > The function call paths (from bottom to top) in Linux-4.16 are: > > [FUNC] schedule_timeout_interruptible > kernel/rcu/rcutorture.c, 523: schedule_timeout_interruptible in > srcu_read_delay > kernel/rcu/rcutorture.c, 1105: [FUNC_PTR]srcu_read_delay in > rcu_torture_timer > kernel/rcu/rcutorture.c, 1104: spin_lock in rcu_torture_timer > > Note that [FUNC_PTR] means a function pointer call is used. > > I do not find a good way to fix, so I only report. > This is found by my static analysis tool (DSAC). Interesting. I would have expected to have gotten a "scheduling while atomic" error message, which I do not recall seeing. And I ran a great deal of rcutorture on v4.16. So let's see... As you say, the rcu_torture_timer() function does in fact acquire rand_lock in 4.16 and 4.17, in which case sleeping would indeed be illegal. But let's take a look at srcu_read_delay(): static void srcu_read_delay(struct torture_random_state *rrsp, struct rt_read_seg *rtrsp) { long delay; const long uspertick = 1000000 / HZ; const long longdelay = 10; /* We want there to be long-running readers, but not all the time. */ delay = torture_random(rrsp) % (nrealreaders * 2 * longdelay * uspertick); if (!delay && in_task()) { schedule_timeout_interruptible(longdelay); rtrsp->rt_delay_jiffies = longdelay; } else { rcu_read_delay(rrsp, rtrsp); } } The call to schedule_timeout_interruptible() cannot happen unless the in_task() macro returns true, which it won't if the SOFTIRQ_OFFSET bit is set: #define in_task() (!(preempt_count() & \ (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET))) And the SOFTIRQ_OFFSET bit will be set if srcu_read_delay() is invoked from a timer handler, which is the case for the call from rcu_torture_timer(). So if that lock is held, schedule_timeout_interruptible() won't ever be invoked. So what am I missing here? Thanx, Paul