Received: by 10.223.185.116 with SMTP id b49csp4304200wrg; Tue, 6 Mar 2018 13:23:56 -0800 (PST) X-Google-Smtp-Source: AG47ELv06Ij3vZtlM6IAOMp+eO26xhtJjoVbuxtHtWFAj3T/bxqbMPp8hdmobgSrSlhQmlw93DGH X-Received: by 2002:a17:902:7686:: with SMTP id m6-v6mr18334811pll.199.1520371436143; Tue, 06 Mar 2018 13:23:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520371436; cv=none; d=google.com; s=arc-20160816; b=G2hU4pp9jmn7q1Ys/gy8LeYvJ7mhhFfvv+YCU4H2tNRBR3ZjUUj+qw1PFdEbuTeEbN kkBHp14Bh05+6l67nwz3r4RU7e6EeCaBxF+JY1NAENMaAlAmZZKoN/VoVHYuyvcDjFgl l+ghOM3jajM9PgkDBjn2C53IzoNOen+BTIzXRbMs4C+m37fCbvKicNvOOfbEtnopqFR9 kSfr7FPOT+eGPwbL3YdTfmsk7EdRPX8I4eD79QOqKnAAWz3uo2yB9c62CdgSkLNvJHCr jWTPTlgPJloB8InuUsk9W5bDV+g435HpD+5ZtEaEE9Ln2Eb+sBqNJrrSRMVnuk8oj1iA /D6g== 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=oRL8aP+31tVxyxz+XmUyEUQ8S4MxjGYLOP092MQPeLQ=; b=vLuSc6stJ0Xssrhdc9SsAwOZBisAID0E0VbB5pQyK/9iF09L8uh3P2NCKfl8EAyzWn YRbHrsG6EhVtz6rb2xB45JHAvmGIc0xGw4gxOL0luUvsX5ElytHqIc6SsA2rkLy3we4v oopBsm8r1REhvAsOnlQ8UeWoNba3rJPIUT0LeEvS0KXTFuQkhud/QxmedXQHKHU6u6Zz x2geoDhE5mqWmQkWltUmFqm6O0bDOw37f6SDVrhbPqPRrqHOQPkiLFzuo8Ddfgjiy6mr AnlEdFv9B/zhcI8ivjna+8Kk4FdmKjmsz0WSUyrcD95HGH6ygnNaBME+xiBq+9YfeKbz QLWg== 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 u11si12512905pfh.197.2018.03.06.13.23.41; Tue, 06 Mar 2018 13:23:56 -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 S1754040AbeCFVVc (ORCPT + 99 others); Tue, 6 Mar 2018 16:21:32 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42092 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753071AbeCFVVb (ORCPT ); Tue, 6 Mar 2018 16:21:31 -0500 Received: from akpm3.svl.corp.google.com (unknown [104.133.9.71]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B8C851287; Tue, 6 Mar 2018 21:21:30 +0000 (UTC) Date: Tue, 6 Mar 2018 13:21:29 -0800 From: Andrew Morton To: Pavel Tatashin Cc: Steven Sistare , Daniel Jordan , Masayoshi Mizuma , Michal Hocko , Catalin Marinas , AKASHI Takahiro , Gioh Kim , Heiko Carstens , Yaowei Bai , Wei Yang , Paul Burton , Miles Chen , Vlastimil Babka , Mel Gorman , Johannes Weiner , LKML , linux-mm@kvack.org Subject: Re: [PATCH] mm: might_sleep warning Message-Id: <20180306132129.45b395d9732b6360fa0b600d@linux-foundation.org> In-Reply-To: References: <20180306192022.28289-1-pasha.tatashin@oracle.com> <20180306123655.957e5b6b20b200505544ea7a@linux-foundation.org> <20180306125604.c394a25a50cae0e36c546855@linux-foundation.org> 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 16:04:06 -0500 Pavel Tatashin wrote: > > > > > 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? > > > > (top-posting repaired. Please don't top-post). > > > > > [CCed everyone] > > > > > > Hi Andrew, > > > > > > I afraid we cannot change this spinlock to mutex > > > because deferred_grow_zone() might be called from an interrupt context if > > > interrupt thread needs to allocate memory. > > > > > > > OK. But if deferred_grow_zone() can be called from interrupt then > > page_alloc_init_late() should be using spin_lock_irq(), shouldn't it? > > I'm surprised that lockdep didn't detect that. > > No, page_alloc_init_late() cannot be called from interrupt, it is > called straight from: > kernel_init_freeable(). But, I believe deferred_grow_zone(): can be called: > > get_page_from_freelist() > _deferred_grow_zone() > deferred_grow_zone() That's why page_alloc_init_late() needs spin_lock_irq(). If a CPU is holding deferred_zone_grow_lock with enabled interrupts and an interrupt comes in on that CPU and the CPU runs deferred_grow_zone() in its interrupt handler, we deadlock. lockdep knows about this bug and should have reported it.