From patchwork Wed Dec 5 09:42:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10713575 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 E20FC13AF for ; Wed, 5 Dec 2018 09:46:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1BA92CC74 for ; Wed, 5 Dec 2018 09:46:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C45B62CCDA; Wed, 5 Dec 2018 09:46:52 +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 95C7C2CC74 for ; Wed, 5 Dec 2018 09:46:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B513A6B73AD; Wed, 5 Dec 2018 04:46:50 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AD79D6B73AE; Wed, 5 Dec 2018 04:46:50 -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 9795F6B73AF; Wed, 5 Dec 2018 04:46:50 -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 507886B73AD for ; Wed, 5 Dec 2018 04:46:50 -0500 (EST) Received: by mail-pg1-f197.google.com with SMTP id s22so10799565pgv.8 for ; Wed, 05 Dec 2018 01:46:50 -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=KU1a6mTZVdMOhI4v9gVe+2WEbqQWpKH0OguUeALqZPo=; b=EdWqn/7jfM6L0aiI4kfxadsLIGGdq3yWxBDIQeaBCvcL11LffZpOJZHcATyjKWphTk BvL/Jl8A/frASqy7hJ/JyyECaSqm3F2ILg/kUMj3t0ib9IBCSE//trgHRuGkfPZDWBl6 kdioQKpY5RbyS3+gX5A/DHywxQKty/7o7bTdWj8R/usHwRyI1j5vevFyLSasWaNdPp/q +O4oflPH34P8YeQjhrYuqxlTskoS7VJhjGs2m8u5d6iH3xbnFXBsMfPr1d5/BXipekn7 NDd0DMUFVxW79qTxyxMKmAh62y9TTvAQ43QDbLd1Uf+NeHJiGqxOGE1ClT/ZGBtKDeXo lHpw== X-Gm-Message-State: AA+aEWb9wGF+oTdcgZX5/UIGD+8u+cUZO1IlQM5etuEGLeI4crlU+UT+ wLwg8GjFMTrI3v2+hMINYuuEAQpRmglYoVX07ljhYIY7UadAY/saICGnb8XlkWnyXR7C/L8Gg9f rkylCZjZ2ffAp29B7eflq+T4yF3ribsu99myJy6uMqol4SuiXCnf/CJr67TSXaQXsnA== X-Received: by 2002:a62:7086:: with SMTP id l128mr23541795pfc.68.1544003209962; Wed, 05 Dec 2018 01:46:49 -0800 (PST) X-Google-Smtp-Source: AFSGD/XgouiZ1Q6eD5dIZ9SkTpVs1DGvlarQ+Ih+PBe+F0WAkjykKq0FJSCrxrpvDYTEimYvadd6 X-Received: by 2002:a62:7086:: with SMTP id l128mr23541756pfc.68.1544003208997; Wed, 05 Dec 2018 01:46:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544003208; cv=none; d=google.com; s=arc-20160816; b=mDlBW7Y2p8zZOhmeF8LDBWaCUNyvtAPdtICQ1vmUCDSaujg+S5xsALGl9gi/zlQ7Xo VNAvluoFEzBqFiMyR+L7HVqU1VKVpnIt7LODsa7Sgws7sML9n1Ikk5hVSzvfS8AdWBgZ l1ydwhS5otYhmF00mQ0gAARZ8IWnYr8HaNIdrrrrXeP9Fmzd3QiKbZPIth37vgO/a85q ErxAMFKEfbJZMK4ur7axVA7a07+WS6GGxeIoNVhwKbcKHyZprNPgEDHhdpm7537srFgO KeIYpZ/AcFzQN5l/UAZ1ri7CcwpLQoaPqzS6tVeRtckQS2TlNJEuP+2D2R3pWli0mJ26 tcew== 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=KU1a6mTZVdMOhI4v9gVe+2WEbqQWpKH0OguUeALqZPo=; b=Ubm6fvCa8k6FDG64lv0MOJVskhIR7CWUuqTlF4EK8KSmEV5NF/A7tO4+EZIdmrWb9s VVAqe+GDiaav2dL52saJ2ojvD5lNtDEY4261AXz6MgRnOZxHVg8Xsp6H2BRlGVHqXQl9 B+/pDHcknRCRn45O9nUnpKVppnMELjkIqO0pYV/XoQ/ZaCAw9v+geELvzHw80Kz9wCqC 1GUAxS49zMpYgY/tXHwGl6oUcBud3YA+g0modrFXF2F/hniwPmFr4vqiy0dy6OR6s2sW jmayqAbW3G0HRwMsqfQcO/FL6Oi76i17dC7ERhCdG6lcpBGOrrAMTl6mlSYgKDTgKjAs 1+Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bUEDsJjL; 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 q8si18188276pgc.580.2018.12.05.01.46.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Dec 2018 01:46:48 -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=bUEDsJjL; 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 6459C20878; Wed, 5 Dec 2018 09:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544003208; bh=MytifBFqhD8qxDtP+VB5UAGzmhyxcO+ZcXBnjD/NR6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bUEDsJjLGCvVUPgKI+9Alqb2pLXb2OecXjKMmhhE305o1cQBV0qSIP9VR4KohSwKB Lp7M8OgsYpVgws7MXmr7MLauG22VqbHPkY1kHtpeaL6whjpBPjPSTB1BuUb2PUS4F+ 7aCNk6Jr7h6RHewHqnTbzDFi4i2+/OLaANxnBKKQ= 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.14 65/69] mm/page_alloc.c: fix calculation of pgdat->nr_zones Date: Wed, 5 Dec 2018 04:42:43 -0500 Message-Id: <20181205094247.6556-65-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181205094247.6556-1-sashal@kernel.org> References: <20181205094247.6556-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 2074f424dabf..86a5cab8b5dc 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5554,8 +5554,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;