From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0773C32771 for ; Wed, 15 Jan 2020 17:29:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 67D882084D for ; Wed, 15 Jan 2020 17:29:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=lca.pw header.i=@lca.pw header.b="OCHYlLdX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 67D882084D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lca.pw Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 15E538E0008; Wed, 15 Jan 2020 12:29:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E95F8E0005; Wed, 15 Jan 2020 12:29:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF2398E0008; Wed, 15 Jan 2020 12:29:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id D60B38E0005 for ; Wed, 15 Jan 2020 12:29:24 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id A1D9B40D3 for ; Wed, 15 Jan 2020 17:29:24 +0000 (UTC) X-FDA: 76380555048.20.oven59_34ffbe1cd082b X-HE-Tag: oven59_34ffbe1cd082b X-Filterd-Recvd-Size: 10240 Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Wed, 15 Jan 2020 17:29:24 +0000 (UTC) Received: by mail-qk1-f196.google.com with SMTP id c16so16395065qko.6 for ; Wed, 15 Jan 2020 09:29:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ALGtJRIfs6JPuh7XQxbp07M5KedAZgbWwahNq6bx2Aw=; b=OCHYlLdXBSz+MTgV0/aodXdMuuIA6WvbsMHuI2qdqv0pe/kCZb1arw8Ub57pZPU+PU CIsfywS5LFuVThHkzrM8D04JKBxu5GSoxxC27OfQBfLCAVzYU9nP27RYeqBR3W6RGNsU 8Q0j2JeaB9wxS4axj9Ligrcol02rvlztrukWEZ/0KK6bVHTEnHfZ6O+b1+62Xm143pBo lnCnzOBa8wT6Rxy0e8VviYzalmV07bv+PpxZPdjH+nNqVHmZ3vjs8xxGKxBck2sAEX81 DKkdIWCKmoOyRASJrgz8QH9iQxQXSuU1UtuDS89teNsNJozzihXfXrTFYtQLtXqeeDud GeOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ALGtJRIfs6JPuh7XQxbp07M5KedAZgbWwahNq6bx2Aw=; b=a99JtcE0fCvcovUVukxiew0CLZ1PH6OQj6JZuwrLpgTrodOaljWM/RiefOzkdpDnPO 51UtIwOPMBNAbb4m0PO504JyDl6yKigHE6ESM2jt2QZbfOEQbkWyFpmLMZMDw4ZQZHaA Ux98g+G8sUSlm5ziUwgD6pbn7p9nPEWGOrTs/CFb3dNMbJfodeJUWbst/GTpXFfJrWra l6G0tfmWkb/DUrU0g3aPBhUEmwqwZ5QwCBtQe5N9vkW2w/3/O1cAoxbUYvwiPT/OECT+ rftWObThD6vOff2hoDJ+3tNZfqNVhNYKJSk0D5HAJH3AFXMq9EY1u2fbGDgoEoWJ1lfm wQiQ== X-Gm-Message-State: APjAAAUTA+VAPYuxT5DnItFAMPe+mDoejhcKurKpU1uCNvTjhzh+laBR bTrjuTy86SjLgMkvrqnOg8PVIQ== X-Google-Smtp-Source: APXvYqwf3aG2GyIDGkHdz2kicACxuHDNJAJ2YO/EK75Z6xRYK4GiPSRlAWTHyqslu0RSTWp2TGRFIA== X-Received: by 2002:a05:620a:164e:: with SMTP id c14mr27248366qko.19.1579109363458; Wed, 15 Jan 2020 09:29:23 -0800 (PST) Received: from ovpn-120-31.rdu2.redhat.com (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id z6sm8523147qkz.101.2020.01.15.09.29.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jan 2020 09:29:22 -0800 (PST) From: Qian Cai To: akpm@linux-foundation.org Cc: mhocko@kernel.org, sergey.senozhatsky.work@gmail.com, pmladek@suse.com, rostedt@goodmis.org, peterz@infradead.org, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH -next v3] mm/hotplug: silence a lockdep splat with printk() Date: Wed, 15 Jan 2020 12:29:16 -0500 Message-Id: <20200115172916.16277-1-cai@lca.pw> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: It is guaranteed to trigger a lockdep splat if calling printk() with zone->lock held because there are many places (tty, console drivers, debugobjects etc) would allocate some memory with another lock held which is proved to be difficult to fix them all. A common workaround until the onging effort to make all printk() as deferred happens is to use printk_deferred() in those places similar to the recent commit [1] merged into the random and -next trees, but memory offline will call dump_page() which needs to be deferred after the lock. So change has_unmovable_pages() so that it no longer calls dump_page() itself - instead it returns a "struct page *" of the unmovable page back to the caller so that in the case of a has_unmovable_pages() failure, the caller can call dump_page() after releasing zone->lock. Also, make dump_page() is able to report a CMA page as well, so the reason string from has_unmovable_pages() can be removed. While at it, remove a similar but unnecessary debug-only printk() as well. A few sample lockdep splats can be founnd here [2]. [1] https://lore.kernel.org/lkml/1573679785-21068-1-git-send-email-cai@lc= a.pw/ [2] https://lore.kernel.org/lkml/7CD27FC6-CFFF-4519-A57D-85179E9815FE@lca= .pw/ Signed-off-by: Qian Cai --- v3: Rebase to next-20200115 for the mm/debug change and update some comments thanks to Michal. v2: Improve the commit log and report CMA in dump_page() per Andrew. has_unmovable_pages() returns a "struct page *" to the caller. include/linux/page-isolation.h | 4 ++-- mm/debug.c | 4 +++- mm/memory_hotplug.c | 6 ++++-- mm/page_alloc.c | 22 +++++++++------------- mm/page_isolation.c | 11 ++++++++++- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/include/linux/page-isolation.h b/include/linux/page-isolatio= n.h index 148e65a9c606..da043ae86488 100644 --- a/include/linux/page-isolation.h +++ b/include/linux/page-isolation.h @@ -33,8 +33,8 @@ static inline bool is_migrate_isolate(int migratetype) #define MEMORY_OFFLINE 0x1 #define REPORT_FAILURE 0x2 =20 -bool has_unmovable_pages(struct zone *zone, struct page *page, int migra= tetype, - int flags); +struct page *has_unmovable_pages(struct zone *zone, struct page *page, i= nt + migratetype, int flags); void set_pageblock_migratetype(struct page *page, int migratetype); int move_freepages_block(struct zone *zone, struct page *page, int migratetype, int *num_movable); diff --git a/mm/debug.c b/mm/debug.c index 6a52316af839..784f9da711b0 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -46,6 +46,7 @@ void __dump_page(struct page *page, const char *reason) { struct address_space *mapping; bool page_poisoned =3D PagePoisoned(page); + bool page_cma =3D is_migrate_cma_page(page); int mapcount; char *type =3D ""; =20 @@ -92,7 +93,8 @@ void __dump_page(struct page *page, const char *reason) } BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) !=3D __NR_PAGEFLAGS + 1); =20 - pr_warn("%sflags: %#lx(%pGp)\n", type, page->flags, &page->flags); + pr_warn("%sflags: %#lx(%pGp)%s", type, page->flags, &page->flags, + page_cma ? " CMA\n" : "\n"); =20 hex_only: print_hex_dump(KERN_WARNING, "raw: ", DUMP_PREFIX_NONE, 32, diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 7a6de9b0dcab..06e7dd3eb9a9 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1148,8 +1148,10 @@ static bool is_pageblock_removable_nolock(unsigned= long pfn) if (!zone_spans_pfn(zone, pfn)) return false; =20 - return !has_unmovable_pages(zone, page, MIGRATE_MOVABLE, - MEMORY_OFFLINE); + if (has_unmovable_pages(zone, page, MIGRATE_MOVABLE, MEMORY_OFFLINE)) + return false; + + return true; } =20 /* Checks if this range of memory is likely to be hot-removable. */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index e56cd1f33242..e90140e879e6 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8202,13 +8202,16 @@ void *__init alloc_large_system_hash(const char *= tablename, * MIGRATE_MOVABLE block might include unmovable pages. And __PageMovabl= e * check without lock_page also may miss some movable non-lru pages at * race condition. So you can't expect this function should be exact. + * + * It returns a page without holding a reference. It should be safe here + * because the page cannot go away because it is unmovable, but it must = not to + * be used for anything else rather than dumping its state. */ -bool has_unmovable_pages(struct zone *zone, struct page *page, int migra= tetype, - int flags) +struct page *has_unmovable_pages(struct zone *zone, struct page *page, + int migratetype, int flags) { unsigned long iter =3D 0; unsigned long pfn =3D page_to_pfn(page); - const char *reason =3D "unmovable page"; =20 /* * TODO we could make this much more efficient by not checking every @@ -8225,9 +8228,8 @@ bool has_unmovable_pages(struct zone *zone, struct = page *page, int migratetype, * so consider them movable here. */ if (is_migrate_cma(migratetype)) - return false; + return NULL; =20 - reason =3D "CMA page"; goto unmovable; } =20 @@ -8302,12 +8304,10 @@ bool has_unmovable_pages(struct zone *zone, struc= t page *page, int migratetype, */ goto unmovable; } - return false; + return NULL; unmovable: WARN_ON_ONCE(zone_idx(zone) =3D=3D ZONE_MOVABLE); - if (flags & REPORT_FAILURE) - dump_page(pfn_to_page(pfn + iter), reason); - return true; + return pfn_to_page(pfn + iter); } =20 #ifdef CONFIG_CONTIG_ALLOC @@ -8711,10 +8711,6 @@ __offline_isolated_pages(unsigned long start_pfn, = unsigned long end_pfn) BUG_ON(!PageBuddy(page)); order =3D page_order(page); offlined_pages +=3D 1 << order; -#ifdef CONFIG_DEBUG_VM - pr_info("remove from free list %lx %d %lx\n", - pfn, 1 << order, end_pfn); -#endif del_page_from_free_area(page, &zone->free_area[order]); pfn +=3D (1 << order); } diff --git a/mm/page_isolation.c b/mm/page_isolation.c index 1f8b9dfecbe8..f3af65bac1e0 100644 --- a/mm/page_isolation.c +++ b/mm/page_isolation.c @@ -20,6 +20,7 @@ static int set_migratetype_isolate(struct page *page, i= nt migratetype, int isol_ struct zone *zone; unsigned long flags; int ret =3D -EBUSY; + struct page *unmovable =3D NULL; =20 zone =3D page_zone(page); =20 @@ -37,7 +38,8 @@ static int set_migratetype_isolate(struct page *page, i= nt migratetype, int isol_ * FIXME: Now, memory hotplug doesn't call shrink_slab() by itself. * We just check MOVABLE pages. */ - if (!has_unmovable_pages(zone, page, migratetype, isol_flags)) { + unmovable =3D has_unmovable_pages(zone, page, migratetype, isol_flags); + if (!unmovable) { unsigned long nr_pages; int mt =3D get_pageblock_migratetype(page); =20 @@ -54,6 +56,13 @@ static int set_migratetype_isolate(struct page *page, = int migratetype, int isol_ spin_unlock_irqrestore(&zone->lock, flags); if (!ret) drain_all_pages(zone); + else if (isol_flags & REPORT_FAILURE && unmovable) + /* + * printk() with zone->lock held will guarantee to trigger a + * lockdep splat, so defer it here. + */ + dump_page(unmovable, "unmovable page"); + return ret; } =20 --=20 2.21.0 (Apple Git-122.2)