Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3285503pxb; Mon, 18 Apr 2022 21:49:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjr3Hu6QUmlOm9zT75/TfKePtISoOekao8pOkL8NX73gN2BmPKaklpn5kyz5cea5hQyjAp X-Received: by 2002:a05:6402:2881:b0:41d:8c32:917 with SMTP id eg1-20020a056402288100b0041d8c320917mr15529778edb.328.1650343780973; Mon, 18 Apr 2022 21:49:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650343780; cv=none; d=google.com; s=arc-20160816; b=SGqw3zq3CWQOmsxIlygSXG46KMOHaJ/bUgY5tYhWfhpPI3859JWoRt/kRGkhmio7jl tLlH3XbY6a3IkLEzna3HoJO1RUvA9Iq4i59wDB0gFBnQEPiBA+nFJtMwWhBFlOAUCQaK Xc254kdL/yrcILMsjmh+cZz3P92miPWFv1eA97kBY1vSItP23CR4jf+GZyic3oYDY0fA qAIN3j2XbqIg00KBzZ7+ftgstphPvkwo6jxVkAfY+7goUXR+AutgxC4o6SJ/PmZu2pXM 1vwTE4WTry5fT5S+lBmQjkkc11Tm/GHZH9uP2+m668L7sWp0A4RP0cpi3LvQeRI1LdV6 lb4w== 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=wW1s5xur9lfGdlFdpSyypbiDX7utwmw3UGTZv/AHPPQ=; b=A0mAFWGEzfZ+SnIq+H7ozDz8fZWRtqz1FVC/3bEf6suVn75ROSRiHTvkD2f4HVGY4C zYr1K0/Qnt4+iN+dEik1UDBuvTeYSffE01olWAys4+BRpVVLqC7JeYfM5LEGr3RuN0aw WF1LI83Wo0SyFVM1P3GwVTN8VashMnXCsbEvEqOkVA4miTzJD2T+owuRG3Ct4bxI99ar 31lnOaCiQwxFvRGM2hDhg0BnqqENmOplMMaVJ19GCJfNG99gfDRSTmAoYpVPYkSbgTtb z1MteoPo4mRrX+tAKhpHBBLdpdF0G+Qmne914FQTKKocssSgXrYCSR1JdP4+u/rYprHb +Y7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GEbbHXej; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h1-20020a056402280100b0041d85852a22si9089428ede.190.2022.04.18.21.49.17; Mon, 18 Apr 2022 21:49:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GEbbHXej; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344250AbiDRO31 (ORCPT + 99 others); Mon, 18 Apr 2022 10:29:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344754AbiDROSV (ORCPT ); Mon, 18 Apr 2022 10:18:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46EFA3AA59; Mon, 18 Apr 2022 06:14:10 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 7920A60F16; Mon, 18 Apr 2022 13:13:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81F1DC385A1; Mon, 18 Apr 2022 13:13:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650287624; bh=jOUWDwSM48EwLPQiSa0MQj38n2CarrW+cQpNBFmloZQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GEbbHXejr6SZnHwCjw86KPyBHkRL07Jg7enlqOTAz67Pof3KbYVAlpSc98tcjz1uL 8uNS7zCuEQKLI0RMG4TtTgbN7S9N+QaDWELh89+pG0XaBGUVAW8ZWpOFtghm8MEQkG NXVWJM3TMUT/6/ZHDQDuuN0Xm+AUExTSdu/iw2/I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Juergen Gross , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Michal Hocko , David Hildenbrand , Wei Yang , Andrew Morton , Linus Torvalds Subject: [PATCH 4.9 212/218] mm, page_alloc: fix build_zonerefs_node() Date: Mon, 18 Apr 2022 14:14:38 +0200 Message-Id: <20220418121208.270309832@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121158.636999985@linuxfoundation.org> References: <20220418121158.636999985@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=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: Juergen Gross commit e553f62f10d93551eb883eca227ac54d1a4fad84 upstream. Since commit 6aa303defb74 ("mm, vmscan: only allocate and reclaim from zones with pages managed by the buddy allocator") only zones with free memory are included in a built zonelist. This is problematic when e.g. all memory of a zone has been ballooned out when zonelists are being rebuilt. The decision whether to rebuild the zonelists when onlining new memory is done based on populated_zone() returning 0 for the zone the memory will be added to. The new zone is added to the zonelists only, if it has free memory pages (managed_zone() returns a non-zero value) after the memory has been onlined. This implies, that onlining memory will always free the added pages to the allocator immediately, but this is not true in all cases: when e.g. running as a Xen guest the onlined new memory will be added only to the ballooned memory list, it will be freed only when the guest is being ballooned up afterwards. Another problem with using managed_zone() for the decision whether a zone is being added to the zonelists is, that a zone with all memory used will in fact be removed from all zonelists in case the zonelists happen to be rebuilt. Use populated_zone() when building a zonelist as it has been done before that commit. There was a report that QubesOS (based on Xen) is hitting this problem. Xen has switched to use the zone device functionality in kernel 5.9 and QubesOS wants to use memory hotplugging for guests in order to be able to start a guest with minimal memory and expand it as needed. This was the report leading to the patch. Link: https://lkml.kernel.org/r/20220407120637.9035-1-jgross@suse.com Fixes: 6aa303defb74 ("mm, vmscan: only allocate and reclaim from zones with pages managed by the buddy allocator") Signed-off-by: Juergen Gross Reported-by: Marek Marczykowski-Górecki Acked-by: Michal Hocko Acked-by: David Hildenbrand Cc: Marek Marczykowski-Górecki Reviewed-by: Wei Yang Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4503,7 +4503,7 @@ static int build_zonelists_node(pg_data_ do { zone_type--; zone = pgdat->node_zones + zone_type; - if (managed_zone(zone)) { + if (populated_zone(zone)) { zoneref_set_zone(zone, &zonelist->_zonerefs[nr_zones++]); check_highest_zone(zone_type);