Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3184575pxb; Mon, 18 Apr 2022 18:25:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxs/OGZYBp7FaFwl+TUrsO1iZEjPyR5JgHyY69fAcJpbKk1UGOeAHIwfSf8XVId9FLLKWT X-Received: by 2002:a17:907:a42c:b0:6e8:d248:f877 with SMTP id sg44-20020a170907a42c00b006e8d248f877mr9714197ejc.249.1650331538254; Mon, 18 Apr 2022 18:25:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650331538; cv=none; d=google.com; s=arc-20160816; b=kcBaFtmZ1vH0gpZg1HIYlz0/ETDf95r7IVbudY1z6YzmFVtAmRtMZ5hMc2wfIBRZzj 0DkVNhnlPyH3WotAYIM31uGym9nokc/nGxrKHl7rm3UqQ4m4mFTgnfcVMKQhm0t0tjYC pu4L7P4e/1T8KOVMXhL731WATPLX7KscZrM68dfuAjaJKhcoNDR1e5hWJfmUnQ2qAiVF 8qGXPY7VclMWjfaVzLThTWxQ2DG+EaNFzLy76KnCvVlbzd4/vCOPTHgPTzDTQpXcrKnd wAkw0orVDzrZsfIydVFvyMvpaqLVIdaalyv4/uwsHZQhsOwD8SWtLwKcQ0lr+X/+mFYv ibvw== 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=k8MWJOu0wLruOPw0nt1t13xNRNMv6/EVRppr5hoJMqY=; b=D9vKfuVebiC8RwJG31drk0kJR3SRvKLI6WipcWuSnqOSQmmjP0nt6HSth+QfZXqoBe /Jl40l4uGNOvslMEysIBNTfrtf+BrivBEB/8R4qsGN+ZYQPPNd+PS4uCQkaW9IZKBQjs G2tbzrpuB/lVFJJPZ6pIEC8oHLoBEF21gHw45asBBqJnrIOFneHx0hovHC0dTLJF9iii yLcpxNXA6CXvswSNbBc6bX3Oz6MUaG9gPrr6Cjg6eW2bK3iCuY5zWHXn6/OWYFLgvWuC oT6CN9OHiPZoyhVA6I6YtYKeMFo9RNJUlZFb+tb/Eo2cd0YLioa5rOS5aIyQHVnYmjoU wySg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1tJKviRI; 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 cb2-20020a0564020b6200b0041d78a7223esi6566658edb.597.2022.04.18.18.25.15; Mon, 18 Apr 2022 18:25:38 -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=1tJKviRI; 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 S240317AbiDRMix (ORCPT + 99 others); Mon, 18 Apr 2022 08:38:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239769AbiDRMdY (ORCPT ); Mon, 18 Apr 2022 08:33:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C082A1E3FF; Mon, 18 Apr 2022 05:25:42 -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 5D11860FB0; Mon, 18 Apr 2022 12:25:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 537ACC385A1; Mon, 18 Apr 2022 12:25:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650284741; bh=rW1u9K8345+MlZzqAj6h4y9oB8V4Y/VHGKcLCTUIvac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1tJKviRIGfxQnLrXo8w1Gf/DrGoe9x8zZ9muyOUX9fddyjNHlFxnxUdrX3q4NXFiH b49g0BPZE+WqvkAf3d2nFepSc8H2t3JBYg89nP+eHHLdYF4oNrgMxsBMapdylarlwp ihun+HRdFHGBPWIrRnJNZKq3+TP16IGVVlEFVkBU= 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 5.17 176/219] mm, page_alloc: fix build_zonerefs_node() Date: Mon, 18 Apr 2022 14:12:25 +0200 Message-Id: <20220418121211.804040370@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121203.462784814@linuxfoundation.org> References: <20220418121203.462784814@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 @@ -6112,7 +6112,7 @@ static int build_zonerefs_node(pg_data_t do { zone_type--; zone = pgdat->node_zones + zone_type; - if (managed_zone(zone)) { + if (populated_zone(zone)) { zoneref_set_zone(zone, &zonerefs[nr_zones++]); check_highest_zone(zone_type); }