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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B58AC433EF for ; Mon, 21 Feb 2022 11:20:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2EAC8D0003; Mon, 21 Feb 2022 06:20:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BDEDB8D0001; Mon, 21 Feb 2022 06:20:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA5618D0003; Mon, 21 Feb 2022 06:20:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 9D3AE8D0001 for ; Mon, 21 Feb 2022 06:20:45 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 74B9120EEB for ; Mon, 21 Feb 2022 11:20:45 +0000 (UTC) X-FDA: 79166544450.03.5321957 Received: from outbound-smtp45.blacknight.com (outbound-smtp45.blacknight.com [46.22.136.57]) by imf13.hostedemail.com (Postfix) with ESMTP id E4EA220007 for ; Mon, 21 Feb 2022 11:20:44 +0000 (UTC) Received: from mail.blacknight.com (pemlinmail01.blacknight.ie [81.17.254.10]) by outbound-smtp45.blacknight.com (Postfix) with ESMTPS id 7C4CCFB64B for ; Mon, 21 Feb 2022 11:20:43 +0000 (GMT) Received: (qmail 15512 invoked from network); 21 Feb 2022 11:20:43 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.17.223]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 21 Feb 2022 11:20:43 -0000 Date: Mon, 21 Feb 2022 11:20:37 +0000 From: Mel Gorman To: Alistair Popple Cc: akpm@linux-foundation.org, jhubbard@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, ziy@nvidia.com, Oscar Salvador Subject: Re: [PATCH] mm/pages_alloc.c: Don't create ZONE_MOVABLE beyond the end of a node Message-ID: <20220221112037.GA4423@techsingularity.net> References: <20220215025831.2113067-1-apopple@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <20220215025831.2113067-1-apopple@nvidia.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Stat-Signature: 8watqq6kep659bdgzbcxq8e7hnsi4fzi X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of mgorman@techsingularity.net designates 46.22.136.57 as permitted sender) smtp.mailfrom=mgorman@techsingularity.net; dmarc=none X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: E4EA220007 X-HE-Tag: 1645442444-425513 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: On Tue, Feb 15, 2022 at 01:58:31PM +1100, Alistair Popple wrote: > ZONE_MOVABLE uses the remaining memory in each node. It's starting pfn > is also aligned to MAX_ORDER_NR_PAGES. It is possible for the remaining > memory in a node to be less than MAX_ORDER_NR_PAGES, meaning there is > not enough room for ZONE_MOVABLE on that node. > > Unfortunately this condition is not checked for. This leads to > zone_movable_pfn[] getting set to a pfn greater than the last pfn in a > node. > > calculate_node_totalpages() then sets zone->present_pages to be greater > than zone->spanned_pages which is invalid, as spanned_pages represents > the maximum number of pages in a zone assuming no holes. > > Subsequently it is possible free_area_init_core() will observe a zone of > size zero with present pages. In this case it will skip setting up the > zone, including the initialisation of free_lists[]. > > However populated_zone() checks zone->present_pages to see if a zone has > memory available. This is used by iterators such as > walk_zones_in_node(). pagetypeinfo_showfree() uses this to walk the > free_list of each zone in each node, which are assumed to be initialised > due to the zone not being empty. As free_area_init_core() never > initialised the free_lists[] this results in the following kernel crash > when trying to read /proc/pagetypeinfo: > > [ 67.534914] BUG: kernel NULL pointer dereference, address: 0000000000000000 > [ 67.535429] #PF: supervisor read access in kernel mode > [ 67.535789] #PF: error_code(0x0000) - not-present page > [ 67.536128] PGD 0 P4D 0 > [ 67.536305] Oops: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC NOPTI > [ 67.536696] CPU: 0 PID: 456 Comm: cat Not tainted 5.16.0 #461 > [ 67.537096] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-2 04/01/2014 > [ 67.537638] RIP: 0010:pagetypeinfo_show+0x163/0x460 > [ 67.537992] Code: 9e 82 e8 80 57 0e 00 49 8b 06 b9 01 00 00 00 4c 39 f0 75 16 e9 65 02 00 00 48 83 c1 01 48 81 f9 a0 86 01 00 0f 84 48 02 00 00 <48> 8b 00 4c 39 f0 75 e7 48 c7 c2 80 a2 e2 82 48 c7 c6 79 ef e3 82 > [ 67.538259] RSP: 0018:ffffc90001c4bd10 EFLAGS: 00010003 > [ 67.538259] RAX: 0000000000000000 RBX: ffff88801105f638 RCX: 0000000000000001 > [ 67.538259] RDX: 0000000000000001 RSI: 000000000000068b RDI: ffff8880163dc68b > [ 67.538259] RBP: ffffc90001c4bd90 R08: 0000000000000001 R09: ffff8880163dc67e > [ 67.538259] R10: 656c6261766f6d6e R11: 6c6261766f6d6e55 R12: ffff88807ffb4a00 > [ 67.538259] R13: ffff88807ffb49f8 R14: ffff88807ffb4580 R15: ffff88807ffb3000 > [ 67.538259] FS: 00007f9c83eff5c0(0000) GS:ffff88807dc00000(0000) knlGS:0000000000000000 > [ 67.538259] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > [ 67.538259] CR2: 0000000000000000 CR3: 0000000013c8e000 CR4: 0000000000350ef0 > [ 67.538259] Call Trace: > [ 67.538259] > [ 67.538259] seq_read_iter+0x128/0x460 > [ 67.538259] ? aa_file_perm+0x1af/0x5f0 > [ 67.538259] proc_reg_read_iter+0x51/0x80 > [ 67.538259] ? lock_is_held_type+0xea/0x140 > [ 67.538259] new_sync_read+0x113/0x1a0 > [ 67.538259] vfs_read+0x136/0x1d0 > [ 67.538259] ksys_read+0x70/0xf0 > [ 67.538259] __x64_sys_read+0x1a/0x20 > [ 67.538259] do_syscall_64+0x3b/0xc0 > [ 67.538259] entry_SYSCALL_64_after_hwframe+0x44/0xae > [ 67.538259] RIP: 0033:0x7f9c83e23cce > [ 67.538259] Code: c0 e9 b6 fe ff ff 50 48 8d 3d 6e 13 0a 00 e8 c9 e3 01 00 66 0f 1f 84 00 00 00 00 00 64 8b 04 25 18 00 00 00 85 c0 75 14 0f 05 <48> 3d 00 f0 ff ff 77 5a c3 66 0f 1f 84 00 00 00 00 00 48 83 ec 28 > [ 67.538259] RSP: 002b:00007fff116e1a08 EFLAGS: 00000246 ORIG_RAX: 0000000000000000 > [ 67.538259] RAX: ffffffffffffffda RBX: 0000000000020000 RCX: 00007f9c83e23cce > [ 67.538259] RDX: 0000000000020000 RSI: 00007f9c83a2c000 RDI: 0000000000000003 > [ 67.538259] RBP: 00007f9c83a2c000 R08: 00007f9c83a2b010 R09: 0000000000000000 > [ 67.538259] R10: 00007f9c83f2d7d0 R11: 0000000000000246 R12: 0000000000000000 > [ 67.538259] R13: 0000000000000003 R14: 0000000000020000 R15: 0000000000020000 > [ 67.538259] > > Fix this by checking that the aligned zone_movable_pfn[] does not exceed > the end of the node, and if it does skip creating a movable zone on this > node. > > Signed-off-by: Alistair Popple > Fixes: 2a1e274acf0b ("Create the ZONE_MOVABLE zone") Seems reasonable; Acked-by: Mel Gorman -- Mel Gorman SUSE Labs