Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2019742imu; Fri, 14 Dec 2018 04:36:38 -0800 (PST) X-Google-Smtp-Source: AFSGD/XoWgnAil/XKklLo+aliQ2TwABbzhNfLetrOB+K02LFupvujPqHC54040I3kIOLh/RiTGHv X-Received: by 2002:a63:ba4d:: with SMTP id l13mr2570202pgu.194.1544790998222; Fri, 14 Dec 2018 04:36:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544790998; cv=none; d=google.com; s=arc-20160816; b=UDTmKiT3R1+4v/Mh7J69j3jrsIYIDw0JHln78fiXBpWnl8011b0k3/dLVb13vbJWpx qGZ8eJfMiNo4MorKoul4bWeySJzn6aruHbTb3KR5sb36k992fa9exCApaak8E8Nj+SIU WWUdJoCocIHJlsVcvcOz/aHXOU/PAVsGWDeUc9/YXto1R9WSH2yMxEsdS3LVz81LAluW vj34bzFKWyr+Vlg9NruiAOYz21+OgB0LsDfa0qgcJRCw9agxzxaNtz7iGhhl3/xnbpkZ wfaT0SfD1WS6gFR/oyENphSkge1tsWB4Nr43Fn2t8AMR5/zngIWeE34r2N3pRRP8bPhw ZW9Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nq3nLmInh5sDY1GG1644DmkFDhZX5H+ewThTJe7v2vA=; b=iV/wAqliG4qjBQ8gm9N/dk3NkGOsz5ULzXvUC9e8Oj8G3VgXOz0KQEjRhIuD+rm8Pr pEcD+YFZG9Ko+Khy3bqUaGJNqOUfP8towEXbGFTT9Bw9ful7ZpCJIKzCd8P5j5Enu1TX MKyHJhfityIAsGofg8uriSQI3q24ICRMb0m7bN3xeQOjSD3pJd39QQ7XTqMBD0elTcdA LzH8eJw55iIi1T04yhlNPVZyWBtSrESdM77PYuOKiGu1qTSDc7Xsw5kYklVOEv9Q8p2I h4Hs5HHszQPpE+AeLZi5eYNmbU4NnEAkoAlOzlx7XBA8uLVFggHfOtT0oVBZzdxWrr7r gTSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=axS3ol9C; 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 g19si3966388pgj.358.2018.12.14.04.36.23; Fri, 14 Dec 2018 04:36:38 -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; dkim=pass header.i=@kernel.org header.s=default header.b=axS3ol9C; 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 S1731099AbeLNMHW (ORCPT + 99 others); Fri, 14 Dec 2018 07:07:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:52518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729873AbeLNMHS (ORCPT ); Fri, 14 Dec 2018 07:07:18 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F2135214AE; Fri, 14 Dec 2018 12:07:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789237; bh=zBRLDU+LBgzmyriOaBWeIOMWZPC4UiL147KMvwDxPH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=axS3ol9CDWHeT7VkW+G1lkBujsZijynJc8l295dzPIYMTWt9XW+xJexZqKTG4WXHz duWYfx1o709uMKnWNCAapNW5l9BHdy4uNRsBLoybBQjjpAmYINhb/JFqYDWIeopz4d dCZn4tWqJSjkFczqEzNTWrKrXY8024B6IfUfO2wA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wei Yang , Michal Hocko , Oscar Salvador , Anshuman Khandual , Dave Hansen , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 125/142] mm/page_alloc.c: fix calculation of pgdat->nr_zones Date: Fri, 14 Dec 2018 13:00:10 +0100 Message-Id: <20181214115752.035179121@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115747.053633987@linuxfoundation.org> References: <20181214115747.053633987@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 8f416836c0d50b198cad1225132e5abebf8980dc ] init_currently_empty_zone() will adjust pgdat->nr_zones and set it to 'zone_idx(zone) + 1' unconditionally. This is correct in the normal case, while not exact in hot-plug situation. This function is used in two places: * free_area_init_core() * move_pfn_range_to_zone() In the first case, we are sure zone index increase monotonically. While in the second one, this is under users control. One way to reproduce this is: ---------------------------- 1. create a virtual machine with empty node1 -m 4G,slots=32,maxmem=32G \ -smp 4,maxcpus=8 \ -numa node,nodeid=0,mem=4G,cpus=0-3 \ -numa node,nodeid=1,mem=0G,cpus=4-7 2. hot-add cpu 3-7 cpu-add [3-7] 2. hot-add memory to nod1 object_add memory-backend-ram,id=ram0,size=1G device_add pc-dimm,id=dimm0,memdev=ram0,node=1 3. online memory with following order echo online_movable > memory47/state echo online > memory40/state After this, node1 will have its nr_zones equals to (ZONE_NORMAL + 1) instead of (ZONE_MOVABLE + 1). Michal said: "Having an incorrect nr_zones might result in all sorts of problems which would be quite hard to debug (e.g. reclaim not considering the movable zone). I do not expect many users would suffer from this it but still this is trivial and obviously right thing to do so backporting to the stable tree shouldn't be harmful (last famous words)" Link: http://lkml.kernel.org/r/20181117022022.9956-1-richard.weiyang@gmail.com Fixes: f1dd2cd13c4b ("mm, memory_hotplug: do not associate hotadded memory to zones until online") Signed-off-by: Wei Yang Acked-by: Michal Hocko Reviewed-by: Oscar Salvador Cc: Anshuman Khandual Cc: Dave Hansen Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/page_alloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b721631d78ab..6a62b2421cdf 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5733,8 +5733,10 @@ void __meminit init_currently_empty_zone(struct zone *zone, unsigned long size) { struct pglist_data *pgdat = zone->zone_pgdat; + int zone_idx = zone_idx(zone) + 1; - pgdat->nr_zones = zone_idx(zone) + 1; + if (zone_idx > pgdat->nr_zones) + pgdat->nr_zones = zone_idx; zone->zone_start_pfn = zone_start_pfn; -- 2.19.1