Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp832555ybl; Wed, 11 Dec 2019 08:10:44 -0800 (PST) X-Google-Smtp-Source: APXvYqyAr/jyypUse19KwG6ogoNpaMRhwoejYaLNdNcl/LUrdGS0Vof8W1LVbWD/UBwVNNVosP0L X-Received: by 2002:a05:6808:98b:: with SMTP id a11mr3479752oic.62.1576080644519; Wed, 11 Dec 2019 08:10:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576080644; cv=none; d=google.com; s=arc-20160816; b=BnTAMGo+lZmR6xj9cButvkdGEA0iMrPoX7nUDF335JbyjDU7gEV+pbj9VPn4vy4Quv bTD2zUxUOJC2CQqlNYPjN7eQTfQ3EtFJXJI26ncp08YY8IQ3xdlXQ0XHKAho3wLFdwcN 3V9mwi8b2tI5QrFVmWugtivpOpdmiixlBaEtULfjFikeLCGjMRA8j4tSL1EH338QOS7d XE/Fcu5dH5c4IUKQrIx1Nsmg2/kKCy6qH9JXIXm8wpKZL3+8GjGs0+FOvEUodIEEAYKj 8DxadjN/4U23XKy5osbEGoPRkTWfogyZQGMMPjGCHgegzY0zMqvIjJgHVVPsHAUjaWNS 2hgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rzKiqpCssvqg2TdQXPOESlvXDabeyltEsUNUbo7lYSI=; b=Y+1RVcfERtDgUCijTxeGc1kqj/b4baehnoDOy1r/Awbhc9SBU5aZh1ADn/5CyKPxaf GkidngTEygjo9ovgVxrXcHUi1lYAismZ8o9/yaZHIJ5BRoDWQtQJ/vWXpWHuf/tr8qD+ cvEHTbkQ8YLnA9AozTdF74J/YoG/8aiJqUtOrtAHBqpyIQjrtjkBgaamoBu69bv1iyr3 neUBhPZQ2TAlVrCOjl2bzU+Yd7DUYW9saHhYpPEGr/8CmhvOFrH+shuU4pkgDVTtMv7u Y4o4MBaxxg1AMIH82csm6343bEuq/eNnRUVpNVwy4C6Tci+CcqU3E+R/Q93QsMhd2E27 d7xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YJoNaUjo; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u21si1264861otq.137.2019.12.11.08.10.32; Wed, 11 Dec 2019 08:10:44 -0800 (PST) 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=@kernel.org header.s=default header.b=YJoNaUjo; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388430AbfLKQIf (ORCPT + 99 others); Wed, 11 Dec 2019 11:08:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:33480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730717AbfLKPMP (ORCPT ); Wed, 11 Dec 2019 10:12:15 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2142A24658; Wed, 11 Dec 2019 15:12:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077134; bh=NqacZIeY751Sk6P9cZCPH3F55m9l65RSJBYodqLMxuc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YJoNaUjoNpLlRuIXUuAJsWLZ66tumSy9mDGwhZCyngo4KUrP7xRelydL/+dfAK+f8 B0GZ2sw7rU2NIZDTDOA4A+ibwW1GhDMwznpnbdf5NbA74LK0tSXy766hEXAO9NkDVD j3RbCQEpCVGfPYjVEyXXiDpSKY1lxDdrJweZaJIs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Linus Torvalds , Qian Cai , Thomas Gleixner , akpm@linux-foundation.org, bigeasy@linutronix.de, cl@linux.com, keescook@chromium.org, penberg@kernel.org, rientjes@google.com, thgarnie@google.com, tytso@mit.edu, will@kernel.org, Ingo Molnar , Sasha Levin Subject: [PATCH 5.3 029/105] sched/core: Avoid spurious lock dependencies Date: Wed, 11 Dec 2019 16:05:18 +0100 Message-Id: <20191211150230.036214995@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra [ Upstream commit ff51ff84d82aea5a889b85f2b9fb3aa2b8691668 ] 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. Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Qian Cai Cc: Thomas Gleixner Cc: akpm@linux-foundation.org Cc: bigeasy@linutronix.de Cc: cl@linux.com Cc: keescook@chromium.org Cc: penberg@kernel.org Cc: rientjes@google.com Cc: thgarnie@google.com Cc: tytso@mit.edu Cc: will@kernel.org Fixes: b7d5dc21072c ("random: add a spinlock_t to struct batched_entropy") Link: https://lkml.kernel.org/r/20191001091837.GK4536@hirez.programming.kicks-ass.net Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- 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 fffe790d98bb2..9a839798851c2 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5874,10 +5874,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; -- 2.20.1