Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp652495pxb; Tue, 5 Apr 2022 17:23:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/ZGY2lGWqxrfD5944QioEeBGfblip41IqgJdsTjuKH70BkxJR67MMUvxrT1ehNaotY6Jo X-Received: by 2002:a17:90a:af86:b0:1c7:db8e:8589 with SMTP id w6-20020a17090aaf8600b001c7db8e8589mr6962544pjq.94.1649204630061; Tue, 05 Apr 2022 17:23:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649204630; cv=none; d=google.com; s=arc-20160816; b=WWA0eiVwYm1rRS0i+uYwh36iKPvhYCTXkT02sO825j1FeIeLCU3ISBt0aRaU10fjeH 18yHxdDAIMlTzLj1yrDvikxRpKCzj8SfcJJAa0lH50ojQMUfn1kbLqUzcW26LvRuC3dV 12/bMlldgSvfdbdpGSEtNF4C2uTpK3mXKggXqiDmbCP3hS7AF67udTdgOd22YfoW3NAG gnVbxtVclLjYGohG0EOzoU4Cpl8FWgRQocG7Fpq0E0CwIeGjzunjGhSx90iW0QUTWvzi t3cCtLsDUihBi7aHdGGiGzSJEdhOADdt0w5F58n1AcPyuyfRb8bqF1xNMFedbfYfbLkZ Y1HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CGzgmQvuGO+0+ApsidefTywyXQp591wr+kMswh9aiSw=; b=whS2zDfNOC3vBjbyQsdhmgmLr2F6idwsnxhdii64FlK58sTYohMKlRqM4z0RZnbGvu v4HrZTpnDzj5vozeDbBUvEw+SD+S8wvmq6sHqeH3sPh/+SVeBUzPGE/AmQmmgAxPrZLT ToClkdjQbbMQi8iLlzgpBLkvp37oxTjHxCWYzNKlGb9X3aCeFecaTxqPhpPn3dmW658X cu4TrHIMjAzQInSS8SLnOD9Km4mRl0FB0CbULEzQuqp6yzqFkA2voojjAo0LuJ4zqeYN U8fDBg5ucou4ORd3ahQWaZh9FV4eNvlNGySnLmjLh338CMmoTjQ5ImRVWUL/Fg04PW0z 1GzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XU8moSHH; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id bx1-20020a17090af48100b001ca7d91b0c4si3307166pjb.54.2022.04.05.17.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 17:23:50 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XU8moSHH; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 46046211ED6; Tue, 5 Apr 2022 17:10:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351654AbiDELEz (ORCPT + 99 others); Tue, 5 Apr 2022 07:04:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237456AbiDEImZ (ORCPT ); Tue, 5 Apr 2022 04:42:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C1E5DE7; Tue, 5 Apr 2022 01:34:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id ACD00B81B13; Tue, 5 Apr 2022 08:34:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF296C385A1; Tue, 5 Apr 2022 08:34:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649147691; bh=lmZ+OnSjM4E5Vl+GHeAAk6puN4cSKNSeRi0omoqJ7K0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XU8moSHHaVMcokmkKqyrG1x1NyFLA6G50LxxT3hWrPp4ciw2t3iUSrczdsvQkEeZq QToLXXzjIZpNo5aSqH2DESlPTFHxhVblTZwfLhkoIV+cCXKY9aW/8YWt86PwiLu8SK Iybe3w3YuLBf6lgVR1Rcnh6vQQKbe/MHrdROpOwc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alistair Popple , David Hildenbrand , Mel Gorman , John Hubbard , Zi Yan , Anshuman Khandual , Oscar Salvador , Andrew Morton , Linus Torvalds Subject: [PATCH 5.16 0088/1017] mm/pages_alloc.c: dont create ZONE_MOVABLE beyond the end of a node Date: Tue, 5 Apr 2022 09:16:41 +0200 Message-Id: <20220405070356.806380229@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alistair Popple commit ddbc84f3f595cf1fc8234a191193b5d20ad43938 upstream. ZONE_MOVABLE uses the remaining memory in each node. Its 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: BUG: kernel NULL pointer dereference, address: 0000000000000000 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 0 P4D 0 Oops: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC NOPTI CPU: 0 PID: 456 Comm: cat Not tainted 5.16.0 #461 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-2 04/01/2014 RIP: 0010:pagetypeinfo_show+0x163/0x460 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 RSP: 0018:ffffc90001c4bd10 EFLAGS: 00010003 RAX: 0000000000000000 RBX: ffff88801105f638 RCX: 0000000000000001 RDX: 0000000000000001 RSI: 000000000000068b RDI: ffff8880163dc68b RBP: ffffc90001c4bd90 R08: 0000000000000001 R09: ffff8880163dc67e R10: 656c6261766f6d6e R11: 6c6261766f6d6e55 R12: ffff88807ffb4a00 R13: ffff88807ffb49f8 R14: ffff88807ffb4580 R15: ffff88807ffb3000 FS: 00007f9c83eff5c0(0000) GS:ffff88807dc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 0000000013c8e000 CR4: 0000000000350ef0 Call Trace: seq_read_iter+0x128/0x460 proc_reg_read_iter+0x51/0x80 new_sync_read+0x113/0x1a0 vfs_read+0x136/0x1d0 ksys_read+0x70/0xf0 __x64_sys_read+0x1a/0x20 do_syscall_64+0x3b/0xc0 entry_SYSCALL_64_after_hwframe+0x44/0xae 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. Link: https://lkml.kernel.org/r/20220215025831.2113067-1-apopple@nvidia.com Fixes: 2a1e274acf0b ("Create the ZONE_MOVABLE zone") Signed-off-by: Alistair Popple Acked-by: David Hildenbrand Acked-by: Mel Gorman Cc: John Hubbard Cc: Zi Yan Cc: Anshuman Khandual Cc: Oscar Salvador Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/page_alloc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7910,10 +7910,17 @@ restart: out2: /* Align start of ZONE_MOVABLE on all nids to MAX_ORDER_NR_PAGES */ - for (nid = 0; nid < MAX_NUMNODES; nid++) + for (nid = 0; nid < MAX_NUMNODES; nid++) { + unsigned long start_pfn, end_pfn; + zone_movable_pfn[nid] = roundup(zone_movable_pfn[nid], MAX_ORDER_NR_PAGES); + get_pfn_range_for_nid(nid, &start_pfn, &end_pfn); + if (zone_movable_pfn[nid] >= end_pfn) + zone_movable_pfn[nid] = 0; + } + out: /* restore the node_state */ node_states[N_MEMORY] = saved_node_state;