Received: by 10.223.185.116 with SMTP id b49csp4263807wrg; Tue, 6 Mar 2018 12:38:09 -0800 (PST) X-Google-Smtp-Source: AG47ELviTz+RQpJrMtoCWeMwlGjAMLDAvFBvvnqJeZGl4NNTySTWFwLjFvAVJ3MhdR55WOcnkH5a X-Received: by 10.101.80.3 with SMTP id f3mr16469335pgo.242.1520368689465; Tue, 06 Mar 2018 12:38:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520368689; cv=none; d=google.com; s=arc-20160816; b=EW4XC4JCI4Rl0VBVq6vnCD2rhNuhKZXIrEVes9+tazMwgLOW7XjJ/0BTRkkH2nlXnh zHnbecSi2p/7dWDKmPzm86magoiRKOuf2LLc66o5yKL+zaLTaw9p2FuSwyJeIiWatq2x 78ieZNictWZI6vjRavUjlY2/4Bd7iutv9eNLltHqAEVkg7bWlG4snEKAIMRKTqenc8Dg tmFWHZweHQBaIBHfwvlVcurHQFvZflew1zAIYlHj1ZgOgLnWnElkDF6r7Coj7DMcYxDE skBrkL7s97zVVGMuyANu+nEbC0pavhiX3WZIsuTgW4q1s7vqY0c9vN1nNwTODZxIkfhW z9lw== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=9LQju/rQjNBbah3y++7NA1jF7HrqghSjfUdreMVRfEQ=; b=cPbc10A2gUDIsZVtwsQXf5LV/g7Jk6+vj0Xd7l8wRsfOiBcm+T/+0orpG81qiQOvjo y84avFgMPt6fsDPf1R2tXyXTsrnK9WKNe1YtUi4SycxtYQlM+WeWWjvlsbjew7iIPj7b lOvsEWbBUcyANQH4xYw10rMTBlfjcVp8GPbvW1hbjrRl+F+WdbCLYbc6ZJ31uw9uJESW aJxw89hQzQGeWTvPp/uRoKPgDlJA1r+mzFLsxm8LhWlPhebYceI9sWfplqjpbH/Ea4ag UgQCj4LQxvde1EjLR/AOOuL2S3/3NG16QkuVMj94LrLaJLJWye6ho5zH9vqQLJf0gMgw 4d9g== ARC-Authentication-Results: i=1; mx.google.com; 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 z22si12441215pfa.4.2018.03.06.12.37.54; Tue, 06 Mar 2018 12:38:09 -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; 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 S1753876AbeCFUg7 (ORCPT + 99 others); Tue, 6 Mar 2018 15:36:59 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:55100 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753070AbeCFUg6 (ORCPT ); Tue, 6 Mar 2018 15:36:58 -0500 Received: from akpm3.svl.corp.google.com (unknown [104.133.9.71]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id DDECBBCF; Tue, 6 Mar 2018 20:36:56 +0000 (UTC) Date: Tue, 6 Mar 2018 12:36:55 -0800 From: Andrew Morton To: Pavel Tatashin Cc: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, m.mizuma@jp.fujitsu.com, 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: Re: [PATCH] mm: might_sleep warning Message-Id: <20180306123655.957e5b6b20b200505544ea7a@linux-foundation.org> In-Reply-To: <20180306192022.28289-1-pasha.tatashin@oracle.com> References: <20180306192022.28289-1-pasha.tatashin@oracle.com> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 6 Mar 2018 14:20:22 -0500 Pavel Tatashin wrote: > 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. > > ... > > --- 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)); Kinda ugly, but I can see the logic behind the decisions. Can we instead turn deferred_zone_grow_lock into a mutex?