Received: by 10.223.185.116 with SMTP id b49csp4376988wrg; Tue, 6 Mar 2018 14:49:34 -0800 (PST) X-Google-Smtp-Source: AG47ELsRcru3nIAvSpbhoGQzvScVYo99IlapXeM9D8J8EX9DjEQs2n6jHuqzszG2rTmNBTjGNucT X-Received: by 10.98.32.200 with SMTP id m69mr20384462pfj.82.1520376574280; Tue, 06 Mar 2018 14:49:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520376574; cv=none; d=google.com; s=arc-20160816; b=HVoOf37tpnCJgBN6B8UxIJA4LhyzpxFPBoB9d40C6arizScdCoYDbNF+U3Nn3PO3ZI K87+g+lmYn68F85BBwqbOBsp/xDdcXf6oOTtxFVm/nR1igCQEYLx/EbYIQpLVrkpu2kU yXwjY6npodbLsum53hoHCn+o+WLrjoxSw80EjzNgw0AGlNLDjFmZuA/RBasJGwz9yV5M 2VR8E1IMbFIFeSxoziEmkgFKn4OUJsiISylaiq8r/tYMvU4tK2JzR8dwumPnSyVns+tv xtUQSPptF2ziA+aY8GcCVqnqBSA2M0+g0ovz0ayJLsQc3hK/L1jV9gjtOuvJzk7v5Slv OrQw== 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=Y7AnPnYsxIOz5jBc8g4VIiFROgpJFEpf50M15XBkYzU=; b=EMNXuo5yvy0gkiO77XbzvQv+ZsPRm2h4Ye6mAS8kkYgYu48wPq2387q/j7PHG09Mly +b47MmbddG+1CFflQ5aEOuR7BD5cXccSZqhQY0LrdJ1HwCm6ApGcMXBgH+2SyYEdhEp3 WkeBrx7p8tTTFZ9yzB8uonvyl+AHzEGs3CMo8I7S3gj9NoCvOjFeNOWdTo1OApnJ+YmP VYE/JWjZwu+xJW0MVwmPdfa6x5/vMzQlSqq8t5l4fa8lEcoT5EelSz6hP5OvN0qOc9Sq 4pyuHXyEKsRUMKn133VbB6Jl5Gn54QDo73Euqy6C4pB5lhhEJwJW7i7MQzpf4j+d89ob +oFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=Mi1irUs0; 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 z2-v6si8050206plk.670.2018.03.06.14.49.19; Tue, 06 Mar 2018 14:49:34 -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=Mi1irUs0; 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 S1754317AbeCFWkr (ORCPT + 99 others); Tue, 6 Mar 2018 17:40:47 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:54672 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754306AbeCFWkq (ORCPT ); Tue, 6 Mar 2018 17:40:46 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w26Mb72L104030; Tue, 6 Mar 2018 22:40:14 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=Y7AnPnYsxIOz5jBc8g4VIiFROgpJFEpf50M15XBkYzU=; b=Mi1irUs05ZKciK515IAjFgWlzUr6fLA9dRS1jUo+kOuEYXAUYvC3G6oqjahuomLGezLM b79P37lB//MPTFck3TN+SK3vvcClXnywsGIkfVZIbVj6QBXID/I42JNjnvU7gyRKqfAR yjtJrTtPiaiMd1OfJ/Gj2R+/PVTu5E5GXo9mpcHygr9ZV4HC8M2hXohYlzwkQXf4BoN6 wQzU+oBZHLVexCwur0uPBR0sbDYx2Yc2NrqJ2tGkAWY1yo2jvzxfbFvbAeYYLoxo9NFd AuQ06ynx90nSyAw25DZLpQrzK81xJvR8XVjcqqizH9kKV4gXUetol/G0Nw5abS6Za0lL xg== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2gj2xyg9xs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 06 Mar 2018 22:40:14 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w26MeDIY032023 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 6 Mar 2018 22:40:14 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w26MeBJj004047; Tue, 6 Mar 2018 22:40:11 GMT Received: from localhost.localdomain (/98.216.35.41) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 06 Mar 2018 14:40:10 -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 v2] mm: might_sleep warning Date: Tue, 6 Mar 2018 17:40:04 -0500 Message-Id: <20180306224004.25150-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-1803060243 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. Also, as noticed by Andrew, change spin_lock to spin_lock_irq, in order to disable interrupts and avoid possible deadlock with deferred_grow_zone(). Signed-off-by: Pavel Tatashin --- mm/page_alloc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b337a026007c..5df1ca40a2ff 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); + spin_lock_irq(&deferred_zone_grow_lock); + deferred_zone_grow = false; + spin_unlock_irq(&deferred_zone_grow_lock); static_branch_disable(&deferred_pages); - spin_unlock(&deferred_zone_grow_lock); /* There will be num_node_state(N_MEMORY) threads */ atomic_set(&pgdat_init_n_undone, num_node_state(N_MEMORY)); -- 2.16.2