Received: by 10.223.185.116 with SMTP id b49csp4193679wrg; Tue, 6 Mar 2018 11:22:15 -0800 (PST) X-Google-Smtp-Source: AG47ELseyYc0Fo9sHreJrF1jhtiwvxYZrUksDfNba1HPBdNax0/s0/LN5weRyIj+HJmNKRukStMU X-Received: by 10.98.89.85 with SMTP id n82mr19690722pfb.233.1520364135230; Tue, 06 Mar 2018 11:22:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520364135; cv=none; d=google.com; s=arc-20160816; b=musmhATNBBD1zwbUxXZWTk9TTDfAa/xIhQ7+NRRNjnyzS4+6G1Q6SkdH9yzo3tHPse mTqqNk0mTNyWGRK24q0w3pFWHXD+rj3S2KI6Z0V0PWu+U1kuLJ348dNry39Nz+7Edudt CXb7yqvm95cXm+eZEkjq1uU2MVpkMPsCQPbgKpV46zWo6fAaicWI12ylBIex5O4JInAx 9pm5mrt3yqs2246MoZkXch2ZZkVIKtHE0Onuf3W2oQIhVyM7oSJA45sy0vbnj3duCxjH uvVl/Q/4rYH9o7K6SlAPXuGKStmElEeftMGuKDm2MHyc8IIz2CBqlqBHan51S0hsS8aN paRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from :dkim-signature:arc-authentication-results; bh=0s9ewakjY3cKfUY2XOPiiwbPQoTEkQFtUyJxvf8u9OI=; b=YXE0iLqUEmBH7EDuYbMWmTyP82thwd0fZLBOD86Zh1/MbaqrMt3KpdQ8U0tnnlCGPc 8O8ce+WSkrClnlfjSo6kCJNHHPJkjqn7ufgtdYxDSIRpx4kbDu4iW6/zsTDLq5mo4MM6 vhOi6TaBUJVmIPkRAl6S19T/6sAGALaP9pkjINd3P/s/HS68FhIHoTBwuAL9yD6lqrrq 3+Yd/oGxH+SwBD9WQS+LHtiK3SK6jyia15wvFr7O0EZS1ktK4AudX5lIJvp5CsbyL9M3 fFSkQ4k5GQiRZea4nb2aQXLT+KcQW6nSahUuA68rqZUlUIYkJzLFYeUcwFzNtjcTaENm gwuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=MS8fYusX; 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=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q76si12516208pfl.236.2018.03.06.11.22.00; Tue, 06 Mar 2018 11:22:15 -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=@oracle.com header.s=corp-2017-10-26 header.b=MS8fYusX; 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=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753878AbeCFTVD (ORCPT + 99 others); Tue, 6 Mar 2018 14:21:03 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:32828 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753453AbeCFTVC (ORCPT ); Tue, 6 Mar 2018 14:21:02 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w26JH1Gk092327; Tue, 6 Mar 2018 19:20:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id; s=corp-2017-10-26; bh=0s9ewakjY3cKfUY2XOPiiwbPQoTEkQFtUyJxvf8u9OI=; b=MS8fYusXLQuObnV/Sc5LFdJqkc4wAulxdGQZ1b9Iw7pgypoRJCrU1cqMtSijJwutLmRg RyBZLlegzNb9GERiCrRpwM3QNS9hXWqkBqHGc1xoxNjNH4JzY+g9d0HxownJpzvcwW0L eWY8DjCDKk2cJkgU2yhkqKMdf5chDoMaTzkEZcPTdgZLMQp8VeyXrLH/qP/tY1XpJVqE zjM8HOKo8t9Qzb3uZprzIvJvoDK6eMPAm7SnWh+WszMLjHPc2hCr5t3PvNR1i0qFrs2l v57LdqV9PbccgMJLyTpfAqagF2w2VE2LUQoYEi/oA283lVLb79Wfe36mAiw387F4eJ/O aQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2ghygt8hnd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 06 Mar 2018 19:20:30 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w26JKUB7001822 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 6 Mar 2018 19:20:30 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w26JKRqu019805; Tue, 6 Mar 2018 19:20:28 GMT Received: from localhost.localdomain (/98.216.35.41) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 06 Mar 2018 11:20:27 -0800 From: Pavel Tatashin To: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, pasha.tatashin@oracle.com, m.mizuma@jp.fujitsu.com, akpm@linux-foundation.org, mhocko@suse.com, catalin.marinas@arm.com, takahiro.akashi@linaro.org, gi-oh.kim@profitbricks.com, heiko.carstens@de.ibm.com, baiyaowei@cmss.chinamobile.com, richard.weiyang@gmail.com, paul.burton@mips.com, miles.chen@mediatek.com, vbabka@suse.cz, mgorman@suse.de, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] mm: might_sleep warning Date: Tue, 6 Mar 2018 14:20:22 -0500 Message-Id: <20180306192022.28289-1-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.16.2 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8824 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803060210 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Robot reported this issue: https://lkml.org/lkml/2018/2/27/851 That is introduced by: mm: initialize pages on demand during boot The problem is caused by changing static branch value within spin lock. Spin lock disables preemption, and changing static branch value takes mutex lock in its path, and thus may sleep. The fix is to add another boolean variable to avoid the need to change static branch within spinlock. Signed-off-by: Pavel Tatashin --- mm/page_alloc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b337a026007c..52edc6695b2b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1579,6 +1579,7 @@ static int __init deferred_init_memmap(void *data) * page_alloc_init_late() soon after smp_init() is complete. */ static __initdata DEFINE_SPINLOCK(deferred_zone_grow_lock); +static bool deferred_zone_grow __initdata = true; static DEFINE_STATIC_KEY_TRUE(deferred_pages); /* @@ -1616,7 +1617,7 @@ deferred_grow_zone(struct zone *zone, unsigned int order) * Bail if we raced with another thread that disabled on demand * initialization. */ - if (!static_branch_unlikely(&deferred_pages)) { + if (!static_branch_unlikely(&deferred_pages) || !deferred_zone_grow) { spin_unlock_irqrestore(&deferred_zone_grow_lock, flags); return false; } @@ -1683,10 +1684,15 @@ void __init page_alloc_init_late(void) /* * We are about to initialize the rest of deferred pages, permanently * disable on-demand struct page initialization. + * + * Note: it is prohibited to modify static branches in non-preemptible + * context. Since, spin_lock() disables preemption, we must use an + * extra boolean deferred_zone_grow. */ spin_lock(&deferred_zone_grow_lock); - static_branch_disable(&deferred_pages); + deferred_zone_grow = false; spin_unlock(&deferred_zone_grow_lock); + static_branch_disable(&deferred_pages); /* There will be num_node_state(N_MEMORY) threads */ atomic_set(&pgdat_init_n_undone, num_node_state(N_MEMORY)); -- 2.16.2