Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp237249imm; Tue, 14 Aug 2018 18:06:26 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwL02krFqSoJ1Yr8mxYuNcsfpjZNP8h0LXm5x0x5pvamJxkIOClKFi8XQjjoLN31icfRaZZ X-Received: by 2002:a17:902:b594:: with SMTP id a20-v6mr22628255pls.140.1534295186060; Tue, 14 Aug 2018 18:06:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534295186; cv=none; d=google.com; s=arc-20160816; b=FiU8IDmgmSX7slkIgk5z4pdSySSsSTAdLcOQhK4SdtpdfauRBqdVXguwFEZXm8MGaF TzPmhrYwiAra7u4r7ORRovmARoeW3g/lED7MND8UffKRCP9YsX9jN7igoTCJFnUI7krl WuQQgav47XISpiJZXVRF5WNb9Mymx84ZLnRKz4pmNGskiKt08RvZHsO7o2gllu3GXet5 mA93khr8G5MgY1jHN4qnVVaracZTM0dIOZar6wrLNjgDUH6EfLQzcD+F0AmWnD5bx35F 2I8iRWkHpWg0B9Fn59zYiZmUnMYY2XAQVSfj5vzAEgWpZhClZGjabFjwBqn7lnIF275f sQuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=tz7ZefK1LbrDSKn0DwrEqUV/sh3GPJSqGEK8Q3VVW7I=; b=uNi746l3WufCY6YVNXNLH5U19Gj3dWy3lC4GIgH2zym3oFb8yI1YpCHes90oHx7uI2 WpYUKb2d5STpxIYG04VGLhnxr3sLGpSn3q6oNi12d7z9YxbYP5/o58brxchFB9kKcpKe isKVMLDivFczYDvLD/ylBknQnnMEsGlR/zZI3W2PTuCzbmj4Vxo3rnaGcl8+Ns9Cq8Wj T4MsyT/EoWrwdfZuPjwjTv4Y/57thkb5UOnRMNXKWQFrks3iexZo5FJ2O8YUweb8e1ay UOQgNtjgpZ8guP41i1HqghsVF2pYNrelT5oIu1VXBLLOj1/Wp8xe82XPwFqQXkMTOLjD zFKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CXU3vAcP; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j67-v6si19175636pgc.186.2018.08.14.18.06.10; Tue, 14 Aug 2018 18:06:26 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CXU3vAcP; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728373AbeHODzJ (ORCPT + 99 others); Tue, 14 Aug 2018 23:55:09 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43549 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727872AbeHODzJ (ORCPT ); Tue, 14 Aug 2018 23:55:09 -0400 Received: by mail-pf1-f194.google.com with SMTP id j26-v6so10012127pfi.10 for ; Tue, 14 Aug 2018 18:05:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=tz7ZefK1LbrDSKn0DwrEqUV/sh3GPJSqGEK8Q3VVW7I=; b=CXU3vAcPGAzUXqQmT2LIrvWhitStQpx+kZjFaAE87N59mwFnNqtFUwHajYnqtkHCBw 2uQaN0k9HjnyT2e+2QKdYvZ2y+2KfeZw+mpYeFuzirkTED6n8MNV4nTW+lkmEcZswQf1 rOaby8E2K6sBH1s5EsWrMd/6TWLnX29BUiOrGPprpGIRUONyatVw0PyBIhdZCH4ENqQQ adyAdDy5kiO6/BqVN+7KJYil4mDEp8nikXDwU+R701g0h1RJ753mBRTomRbFY7eu2z/Y irpzl+XdUvf2CHsF/kfF+3Yghs+T35+/RT9kKlOrXlrBKNICs6EnOHdfwNtY4WMrWKGA JYrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=tz7ZefK1LbrDSKn0DwrEqUV/sh3GPJSqGEK8Q3VVW7I=; b=m8Sy/XoCo0yOFsDq6fHm0uINj5mjAe6tQc/CG5V8rWg/D/tVyVpwoPtzvcYnkDcBtT fK50tievlKqFxd/CEFI1c0t/D3US1YIfW1UQ5M4xsyUQc59l6jOv43wzUXCH0D52Rdq3 oiZtOBHFu9zf4H7neuC21D8cJS7rD9QGirA6ASRcMK29zDe6KJuXiiJ+dFB0xPSoA2XD 4SQtgu9007zHVmDy3QG66hCyUZVuZS1qHL/1rOjZuCLk/WuwX0qVB7a0/9ZQZ7t+KXxq a9anPk4bzccqp7Zq2w9Udo8+IKTFQBoesxlBq0qArkUOkULbpehBYAvioRTJxpLOZBOp Ur/g== X-Gm-Message-State: AOUpUlHVtj8ViSq2H9AHjv3vSWjwN6bKlitj2PeCkkKABd7Pqb2tTBcc Kce8bKI6vkc1C9VePflNTj+LW+IM X-Received: by 2002:a62:3306:: with SMTP id z6-v6mr25054727pfz.85.1534295121572; Tue, 14 Aug 2018 18:05:21 -0700 (PDT) Received: from ?IPv6:2402:f000:1:1501:200:5efe:166.111.71.57? ([2402:f000:1:1501:200:5efe:a66f:4739]) by smtp.gmail.com with ESMTPSA id n9-v6sm36718418pfg.21.2018.08.14.18.05.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Aug 2018 18:05:21 -0700 (PDT) Subject: Re: [BUG] kernel: rcu: a possible sleep-in-atomic-context bug in srcu_read_delay() To: paulmck@linux.vnet.ibm.com Cc: dave@stgolabs.net, josh@joshtriplett.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com, Linux Kernel Mailing List References: <4179b4d2-b832-abcd-d407-b865765f28d6@gmail.com> <20180813041826.GL24813@linux.vnet.ibm.com> <5b3fd721-541c-5165-ef54-d6c476318d92@gmail.com> <20180813124232.GM24813@linux.vnet.ibm.com> From: Jia-Ju Bai Message-ID: <5a9b96db-07a2-67bb-c2ab-6ee1f5c0e24d@gmail.com> Date: Wed, 15 Aug 2018 09:05:16 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20180813124232.GM24813@linux.vnet.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018/8/13 20:42, Paul E. McKenney wrote: > On Mon, Aug 13, 2018 at 05:26:49PM +0800, Jia-Ju Bai wrote: >> >> On 2018/8/13 12:18, Paul E. McKenney wrote: >>> 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. >> Thanks for your reply :) >> My tool does not track this bit... >> Sorry for this false report. > Not a problem, a few false positives are to be expected. And it looks > like you have some work to do on your tool -- which is good, because I > would not want you to be bored. ;-) > > Thanx, Paul > Thanks for your advice. I will improve my tool to produce less false positives :) Best wishes, Jia-Ju Bai