Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1255196pxa; Thu, 20 Aug 2020 06:53:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIpdkUehLg+zQ3E0U5DW3v+4RfDj5vu2GDA1Eam5ksK+hPJo/Mxis9E/SXOJTTZkwXZ1BV X-Received: by 2002:aa7:d6c7:: with SMTP id x7mr2977255edr.167.1597931606852; Thu, 20 Aug 2020 06:53:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597931606; cv=none; d=google.com; s=arc-20160816; b=QcW5oQcGpUtMWXJk5JpIO+v81pzRmZ/m3TeeHWSvUBIpleM5ew9tyTKH8sneFROSzA fLYNHTP3VwWTzpEQ9DSf43VGoaq7NF0bvoyg84DtghbGcdFxVdArVwm/sPeSXYOubu5i nQo5Bb191XCfEx9ixibldUVDYVQmQF20O6QOOBJQXSnFwjm3JksE0CsiBc3jf2b8zLqA fFaSWY082a2OYomQFd13Lru/NvJ7gpiFGSJvL9C8V4GE4ixrzK8nqHObtbePYy/gnENb DM7Lxby/cAyKL9PLbz8xmwf1/DwBSpC9pEjoc2hbBafo6fW6+n4q9uEA0a0Z9Iu9eTan JFMQ== 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=EyFC97OgekTB7StYsNKufxl+IAJXhMLow96lAkdcfFs=; b=zV0nqNiKc/a69osE1FzgLNfLaCXTOUqpLP9Q66HeAQqjYoN2Z8S9SzugSEC2yrB1oi mKsvrCGXBn+j6f4uGWHrCD9mRoe/3S0waUNdYCHe1hfL/QzvGIV85q2dWaoYuBB2cpTd seTTiHfDyFMh3Jx+JAQ5VwVZNVE259Q5qiUDrfGZUBf0fBYdvItuAzcpjpsETLNNTFUB ZxR0TDkHTeucTEGNBYiHU1YCiVrKsT4vUe0LU7Ov3O1JsfDeua60IRza3sH2lOasNXWq ljhIDoIxFhjf2jJEZEPtZxyZyQ/dRrVJTnRpZ6ilkmApXWho6ibkeKJ9QYKbD0OuEUyv YXiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lh+fPpHa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c5si1234665ejm.274.2020.08.20.06.53.01; Thu, 20 Aug 2020 06:53:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lh+fPpHa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728290AbgHTNuV (ORCPT + 99 others); Thu, 20 Aug 2020 09:50:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:35382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727866AbgHTJ1P (ORCPT ); Thu, 20 Aug 2020 05:27:15 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 25D802173E; Thu, 20 Aug 2020 09:27:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915635; bh=4fUQNNlmCRsuUQDDHxUNiUzha6ciUZBaVWDskHewTUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lh+fPpHa2/Rok5LZm76MPmiAjRB+6tgDdIV2KfvQ3PTHDU8GIbNBqe/bQxcJEQ3HK 2Vk/wknfKBVYqGtSOxSdGUsof9VbkiqsEHLyStdIpfdTUFUEsOjfVX07Wai6iTz7wE vBivtDw8+Dq4Wrs4TDs68sV+LqITh63hme5mm+9c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Hildenbrand , Andrew Morton , Wei Yang , Michal Hocko , Dan Williams , Johannes Weiner , Minchan Kim , Huang Ying , Wei Yang , Mel Gorman , Linus Torvalds Subject: [PATCH 5.8 082/232] mm/shuffle: dont move pages between zones and dont read garbage memmaps Date: Thu, 20 Aug 2020 11:18:53 +0200 Message-Id: <20200820091616.790123189@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 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 From: David Hildenbrand commit 4a93025cbe4a0b19d1a25a2d763a3d2018bad0d9 upstream. Especially with memory hotplug, we can have offline sections (with a garbage memmap) and overlapping zones. We have to make sure to only touch initialized memmaps (online sections managed by the buddy) and that the zone matches, to not move pages between zones. To test if this can actually happen, I added a simple BUG_ON(page_zone(page_i) != page_zone(page_j)); right before the swap. When hotplugging a 256M DIMM to a 4G x86-64 VM and onlining the first memory block "online_movable" and the second memory block "online_kernel", it will trigger the BUG, as both zones (NORMAL and MOVABLE) overlap. This might result in all kinds of weird situations (e.g., double allocations, list corruptions, unmovable allocations ending up in the movable zone). Fixes: e900a918b098 ("mm: shuffle initial free memory to improve memory-side-cache utilization") Signed-off-by: David Hildenbrand Signed-off-by: Andrew Morton Reviewed-by: Wei Yang Acked-by: Michal Hocko Acked-by: Dan Williams Cc: Andrew Morton Cc: Johannes Weiner Cc: Michal Hocko Cc: Minchan Kim Cc: Huang Ying Cc: Wei Yang Cc: Mel Gorman Cc: [5.2+] Link: http://lkml.kernel.org/r/20200624094741.9918-2-david@redhat.com Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/shuffle.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) --- a/mm/shuffle.c +++ b/mm/shuffle.c @@ -58,25 +58,25 @@ module_param_call(shuffle, shuffle_store * For two pages to be swapped in the shuffle, they must be free (on a * 'free_area' lru), have the same order, and have the same migratetype. */ -static struct page * __meminit shuffle_valid_page(unsigned long pfn, int order) +static struct page * __meminit shuffle_valid_page(struct zone *zone, + unsigned long pfn, int order) { - struct page *page; + struct page *page = pfn_to_online_page(pfn); /* * Given we're dealing with randomly selected pfns in a zone we * need to ask questions like... */ - /* ...is the pfn even in the memmap? */ - if (!pfn_valid_within(pfn)) + /* ... is the page managed by the buddy? */ + if (!page) return NULL; - /* ...is the pfn in a present section or a hole? */ - if (!pfn_in_present_section(pfn)) + /* ... is the page assigned to the same zone? */ + if (page_zone(page) != zone) return NULL; /* ...is the page free and currently on a free_area list? */ - page = pfn_to_page(pfn); if (!PageBuddy(page)) return NULL; @@ -123,7 +123,7 @@ void __meminit __shuffle_zone(struct zon * page_j randomly selected in the span @zone_start_pfn to * @spanned_pages. */ - page_i = shuffle_valid_page(i, order); + page_i = shuffle_valid_page(z, i, order); if (!page_i) continue; @@ -137,7 +137,7 @@ void __meminit __shuffle_zone(struct zon j = z->zone_start_pfn + ALIGN_DOWN(get_random_long() % z->spanned_pages, order_pages); - page_j = shuffle_valid_page(j, order); + page_j = shuffle_valid_page(z, j, order); if (page_j && page_j != page_i) break; }