From patchwork Wed Dec 5 09:35:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10713541 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 284E213AF for ; Wed, 5 Dec 2018 09:42:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 145952CC67 for ; Wed, 5 Dec 2018 09:42:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0410E2CC74; Wed, 5 Dec 2018 09:42:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79F002CC67 for ; Wed, 5 Dec 2018 09:42:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 932A86B73A6; Wed, 5 Dec 2018 04:42:14 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8DE9E6B73A7; Wed, 5 Dec 2018 04:42:14 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CD936B73A8; Wed, 5 Dec 2018 04:42:14 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 3B95B6B73A6 for ; Wed, 5 Dec 2018 04:42:14 -0500 (EST) Received: by mail-pg1-f197.google.com with SMTP id r16so10826422pgr.15 for ; Wed, 05 Dec 2018 01:42:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=3mE1lO7gXT9uqHfvfpujrlxpBnkzIbqGEXUm9F8m4fQ=; b=nrBwzZ2+E+X8G3zlT/gJ6fV0nR9QMJ/HxKeti6Iq82ycOqk0qoyYKnV77MncKzb+xm 3bWn0f7eMHlCzMGkuFoN2nGNbDnPFZS9HRTGshwLNm6Fy1evKoymMTznEi1kk1AuIgPZ 2ewmvFjaYnPThiF6EFy2Fdq8Y1TzHqtZ2lTlM5IxQTR1PQxudo/PhmopmyQTXcPeaheI xcut5lYZUtNqdOfBnfJAkjT6Xe1GaFh6JldluOzFlQErn715LicpTTU7JloojY5qkOJS bPBf/fB5VxmUTpq8VStukUUi7qUZIkgqCrKuzkfefogIp5/+dy78sooUQzetxQ/Ue3+o Y8YA== X-Gm-Message-State: AA+aEWY1OY1iQR4VHmpqHsZtcwX/YfGuA83m2vmSzYbSaCg1qQMVVOiV gHuuaqB8Y2WhOyqYhjPCLuZdU9q3AO8bsEovtxaWe2Tvfw2Gnf50IGO/5lY7AlxVotsR9ktt5L2 7Q6wyRw0J4JPD1gwIicDOj0E2U9xGDJoL4r8g0JGgVHx3NdxBw8X0YRCA2u5MkAZw7g== X-Received: by 2002:a17:902:583:: with SMTP id f3mr24193988plf.202.1544002933891; Wed, 05 Dec 2018 01:42:13 -0800 (PST) X-Google-Smtp-Source: AFSGD/U/p0nKnIRIwnIpLx7/7oMypyH6v2xX8dh7sLIWn6zSAnuYZNCuGU3KCXTQh4UCu1cXBRwJ X-Received: by 2002:a17:902:583:: with SMTP id f3mr24193959plf.202.1544002933195; Wed, 05 Dec 2018 01:42:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544002933; cv=none; d=google.com; s=arc-20160816; b=f4kgNPPjSdGQoS7ius20mV8HZ5+eIgrQNcWMoeua+eBIhWNJqzUmeQZuSxZw5kjrMl wfiyT79LEVrvqjB/4j0N9GgK4T3VZ04AX+CfXwPIYaSmQAZZnj/P6Zcb6oe4G/8A2jCL vJaSxizKbg5dmAW1axBbguCYaTtu7h0Xnzgh1pTVR4hgmMVRWFctuyw8XF+Me4JcX+EV A46yvlnYheh20+ZP6N0dcGRLsqTA+DVBUzhpKfG4svetUL2TtU/KDK7oiBizNs9zthFy r/j+Q0PRc1aJS6S3g9jo8UQGV3FN0Pil26h5+LBoJ73FpteyGGq0fcbu2BwuarJ6XNnC +95Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3mE1lO7gXT9uqHfvfpujrlxpBnkzIbqGEXUm9F8m4fQ=; b=XfQePcIDv4jUlQprzhzQ/UOLJxwRh4RF2AS9crNGQi5gveGT6bEA0NqSevQ5JwJET4 Deq1S/o263C64esz/AwDHuyowPuNXH4o1R2ZkSozsfvFcEkgKWd55s4aKdVWZKKHAczG zhMNRFwTncWqNYr/gkP316rZIA55kIRNgHiCWGPCAPnPbQoddR0OCShcQkUig2ST+ytC Av0tT9yup2URkljj9gGR8AaPPQmQ3GbXNZaZQJc+n2b6IT/1o3DniYoNpXBKkl9CDTIl DLENSmJHuFRtaWr2NC/UB4RgSSVFvKqrri+GxDRdGXtpsucpuMKO0+SXG3jDgDApBY70 glDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tJrnbcHP; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id o14si17373357pgj.59.2018.12.05.01.42.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Dec 2018 01:42:13 -0800 (PST) Received-SPF: pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tJrnbcHP; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sasha-vm.mshome.net (unknown [213.57.143.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8DE7120850; Wed, 5 Dec 2018 09:42:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544002932; bh=kIwkgi4Z7ZH3fPU+burNiqE1zH3LziBbQtYZlRe44XQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tJrnbcHPVh5PhLr+GA2B2tF7dY6a2eKAYPJxAD+6U+HluufZXc7lbCYo9i5jNSzFZ 2OUEsxrtJJYRS7TqBkZlDhEoezUPOgg23qQw3FAlfp/bsOymrsQiVIJU91tQ2RMPT1 nnwG/lTQy8eNIMY5xF8BNwU8kQNLmT7gTEKpfQuw= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wei Yang , Anshuman Khandual , Dave Hansen , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.19 116/123] mm/page_alloc.c: fix calculation of pgdat->nr_zones Date: Wed, 5 Dec 2018 04:35:48 -0500 Message-Id: <20181205093555.5386-116-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181205093555.5386-1-sashal@kernel.org> References: <20181205093555.5386-1-sashal@kernel.org> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Wei Yang [ 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;