From patchwork Tue Oct 1 09:18:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 11168315 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E4A4016B1 for ; Tue, 1 Oct 2019 09:18:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B07FD21924 for ; Tue, 1 Oct 2019 09:18:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="CmbcU21L" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B07FD21924 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E84E28E0005; Tue, 1 Oct 2019 05:18:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E34F68E0001; Tue, 1 Oct 2019 05:18:49 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4AAA8E0005; Tue, 1 Oct 2019 05:18:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id AE3BB8E0001 for ; Tue, 1 Oct 2019 05:18:49 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 3F0AE82437C9 for ; Tue, 1 Oct 2019 09:18:49 +0000 (UTC) X-FDA: 75994665978.01.goat50_4cf28cb61a559 X-Spam-Summary: 2,0,0,f9a20f06d32b8bbb,d41d8cd98f00b204,peterz@infradead.org,:cai@lca.pw:akpm@linux-foundation.org:bigeasy@linutronix.de:tglx@linutronix.de:thgarnie@google.com:tytso@mit.edu:cl@linux.com:penberg@kernel.org:rientjes@google.com:mingo@redhat.com:will@kernel.org::linux-kernel@vger.kernel.org:keescook@chromium.org,RULES_HIT:41:355:379:800:960:973:988:989:1260:1261:1277:1312:1313:1314:1345:1359:1437:1516:1518:1519:1534:1541:1593:1594:1595:1596:1711:1730:1747:1777:1792:2194:2198:2199:2200:2393:2553:2559:2562:2731:3138:3139:3140:3141:3142:3352:3622:3865:3867:3870:3871:3872:3873:3874:4321:4605:5007:6261:6653:6742:7903:8634:9545:10004:10400:11026:11232:11658:11914:12043:12295:12296:12297:12438:12517:12519:12555:12679:12740:12895:13069:13311:13357:13439:13895:14096:14097:14181:14394:14721:21080:21433:21451:21627:21740:30012:30045:30054:30055:30090:30091,0,RBL:205.233.59.134:@infradead.org:.lbl8.mailshell.net-62.8.55.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Ne tcheck:n X-HE-Tag: goat50_4cf28cb61a559 X-Filterd-Recvd-Size: 4301 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Tue, 1 Oct 2019 09:18:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=qJgQIp1PbWd7MDwKGdEgTjEvRijTu/H2sV4eU4dxT3E=; b=CmbcU21Ln2WAiNG4BNCs8y5uf lnrh/jm7R8+P+5vep3wk6Xg6GNVfwmJn2afgLlo7l1BZJ7G68HAFXvQdvyXWI0MRMu140eKGxYKrL i+WvbHkw1H4NMQr9HleZ6DEAPN+zJWwgIQqqpSSGFAsNOhDhtX2hcWWc6XtzTDvh9WBrqPdWkppPb bsuMgn0a1kSzm/0lu3C4+3kBNQXwjoJHdo4NIHxoAagF4AMVQt9LjfP0YiSP0Pl5dkZSamF1HB4Xh AJeGyU6MrHsWgadJ4OA3dEQWaPVDrrt8KPeKg5WM/uDQynOgOVVaisKTuVg0Ur2HTe8OgG4/mvWRP ErUx5iYHw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.2 #3 (Red Hat Linux)) id 1iFEIq-0002nx-U7; Tue, 01 Oct 2019 09:18:41 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 7300F30600C; Tue, 1 Oct 2019 11:17:49 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id C2C28265261AC; Tue, 1 Oct 2019 11:18:37 +0200 (CEST) Date: Tue, 1 Oct 2019 11:18:37 +0200 From: Peter Zijlstra To: Qian Cai Cc: akpm@linux-foundation.org, bigeasy@linutronix.de, tglx@linutronix.de, thgarnie@google.com, tytso@mit.edu, cl@linux.com, penberg@kernel.org, rientjes@google.com, mingo@redhat.com, will@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, keescook@chromium.org Subject: [PATCH] sched: Avoid spurious lock dependencies Message-ID: <20191001091837.GK4536@hirez.programming.kicks-ass.net> References: <1568392064-3052-1-git-send-email-cai@lca.pw> <20190925093153.GC4553@hirez.programming.kicks-ass.net> <1569424727.5576.221.camel@lca.pw> <20190925164527.GG4553@hirez.programming.kicks-ass.net> <1569500974.5576.234.camel@lca.pw> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1569500974.5576.234.camel@lca.pw> User-Agent: Mutt/1.10.1 (2018-07-13) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Sep 26, 2019 at 08:29:34AM -0400, Qian Cai wrote: > Oh, you were talking about took #3 while holding #2. Anyway, your patch is > working fine so far. Care to post/merge it officially or do you want me to post > it? Does the below adequately describe the situation? Reviewed-by: Valentin Schneider --- Subject: sched: Avoid spurious lock dependencies While seemingly harmless, __sched_fork() does hrtimer_init(), which, when DEBUG_OBJETS, can end up doing allocations. This then results in the following lock order: rq->lock zone->lock.rlock batched_entropy_u64.lock Which in turn causes deadlocks when we do wakeups while holding that batched_entropy lock -- as the random code does. Solve this by moving __sched_fork() out from under rq->lock. This is safe because nothing there relies on rq->lock, as also evident from the other __sched_fork() callsite. Fixes: b7d5dc21072c ("random: add a spinlock_t to struct batched_entropy") Signed-off-by: Peter Zijlstra (Intel) --- kernel/sched/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 7880f4f64d0e..1832fc0fbec5 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6039,10 +6039,11 @@ void init_idle(struct task_struct *idle, int cpu) struct rq *rq = cpu_rq(cpu); unsigned long flags; + __sched_fork(0, idle); + raw_spin_lock_irqsave(&idle->pi_lock, flags); raw_spin_lock(&rq->lock); - __sched_fork(0, idle); idle->state = TASK_RUNNING; idle->se.exec_start = sched_clock(); idle->flags |= PF_IDLE;