Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1338718pxp; Thu, 10 Mar 2022 03:39:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBNIqE6sQThupr/L27kIBGwjzleVfaWL8h282WRxkjbBPb1p6oo67FHGtFiHzItGOUow9n X-Received: by 2002:a17:902:8203:b0:153:2e8:aaae with SMTP id x3-20020a170902820300b0015302e8aaaemr4660910pln.14.1646912380490; Thu, 10 Mar 2022 03:39:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646912380; cv=none; d=google.com; s=arc-20160816; b=cb5wic6veQgXnGJRsyiE1f+qMUH/7t9dN6TG6jdMrvaVm6PBKs20GS5KhBc+JOwvua 9MCVYyDRM6KDDZWkpSj6sHbNyE6AHKqD8r5bKGhsezrKtRRJi0fTKIJeoGtqDZLAR5Yb 9QnkJ3sZbAmKQrvzFwJdgiptP7elmSIsOuElBqFgQS38AjhMs68tjv3SOQ8IlO01eeJz InmER8g218mj7h/5F3gNBhuHs3R0363ZwdYwUxJ2jMf/si06b1VV69qpQk/Uw90NtViZ NkyREgYP00VOUSBwvLoSjICv7+Eze6WeCrQDQEv2lne6zJE9/+FcqTWXhjL8jYQQ8oHW ELgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-disposition:mime-version :message-id:subject:cc:to:from:date; bh=KU6Nk8xmnGDJHxUq/zcwUeSTDRmmhBj/CAgKLRWH1b0=; b=TwHvLWFHZbXIB/osdkfQlvg1rzvo6epzeSgCBgRy9bk10F9xVPpq7I3fOoM2hQHfUn ialPrX1SaWSS9u7Q7RA9OC8yDYd/3hKVdi1wQcSHj5UDY/uxNKrnfwBugO6HFeolyGhf ZcN4yBSSbAukDom/6mkXjVA9Pt42CLUYGxkTkb/l2fPC9YbrninNCJZB5XEx2IECaze+ n3W3Ee+fyGdhVATbs7qlafsApQxwzuGTKYdDqXJ4PGdxoLN1tuj/aVM2klTMXWRPTeXA kSX58ptMx3tsk+oJBtIF/8F9zsU2lRmgjdQ4fLG75KGToj7qJNTU+IQoztjVCqBkTC7o Y1Sw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i12-20020a17090a974c00b001bd14e03063si1658336pjw.59.2022.03.10.03.39.19; Thu, 10 Mar 2022 03:39:40 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240773AbiCJJ0E (ORCPT + 99 others); Thu, 10 Mar 2022 04:26:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233142AbiCJJ0D (ORCPT ); Thu, 10 Mar 2022 04:26:03 -0500 Received: from outbound-smtp52.blacknight.com (outbound-smtp52.blacknight.com [46.22.136.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0886013982A for ; Thu, 10 Mar 2022 01:25:00 -0800 (PST) Received: from mail.blacknight.com (pemlinmail04.blacknight.ie [81.17.254.17]) by outbound-smtp52.blacknight.com (Postfix) with ESMTPS id 626CEFAC59 for ; Thu, 10 Mar 2022 09:24:59 +0000 (GMT) Received: (qmail 20471 invoked from network); 10 Mar 2022 09:24:59 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.17.223]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 10 Mar 2022 09:24:59 -0000 Date: Thu, 10 Mar 2022 09:24:56 +0000 From: Mel Gorman To: Andrew Morton Cc: Eric Dumazet , Eric Dumazet , linux-kernel , linux-mm , Vlastimil Babka , Michal Hocko , Shakeel Butt , Wei Xu , Greg Thelen , Hugh Dickins , David Rientjes Subject: [PATCH] mm/page_alloc: check high-order pages for corruption during PCP operations Message-ID: <20220310092456.GJ15701@techsingularity.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, 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 Eric Dumazet pointed out that commit 44042b449872 ("mm/page_alloc: allow high-order pages to be stored on the per-cpu lists") only checks the head page during PCP refill and allocation operations. This was an oversight and all pages should be checked. This will incur a small performance penalty but it's necessary for correctness. Fixes: 44042b449872 ("mm/page_alloc: allow high-order pages to be stored on the per-cpu lists") Reported-by: Eric Dumazet Signed-off-by: Mel Gorman Acked-by: Eric Dumazet --- mm/page_alloc.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 3589febc6d31..2920344fa887 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2342,23 +2342,36 @@ static inline int check_new_page(struct page *page) return 1; } +static bool check_new_pages(struct page *page, unsigned int order) +{ + int i; + for (i = 0; i < (1 << order); i++) { + struct page *p = page + i; + + if (unlikely(check_new_page(p))) + return true; + } + + return false; +} + #ifdef CONFIG_DEBUG_VM /* * With DEBUG_VM enabled, order-0 pages are checked for expected state when * being allocated from pcp lists. With debug_pagealloc also enabled, they are * also checked when pcp lists are refilled from the free lists. */ -static inline bool check_pcp_refill(struct page *page) +static inline bool check_pcp_refill(struct page *page, unsigned int order) { if (debug_pagealloc_enabled_static()) - return check_new_page(page); + return check_new_pages(page, order); else return false; } -static inline bool check_new_pcp(struct page *page) +static inline bool check_new_pcp(struct page *page, unsigned int order) { - return check_new_page(page); + return check_new_pages(page, order); } #else /* @@ -2366,32 +2379,19 @@ static inline bool check_new_pcp(struct page *page) * when pcp lists are being refilled from the free lists. With debug_pagealloc * enabled, they are also checked when being allocated from the pcp lists. */ -static inline bool check_pcp_refill(struct page *page) +static inline bool check_pcp_refill(struct page *page, unsigned int order) { - return check_new_page(page); + return check_new_pages(page, order); } -static inline bool check_new_pcp(struct page *page) +static inline bool check_new_pcp(struct page *page, unsigned int order) { if (debug_pagealloc_enabled_static()) - return check_new_page(page); + return check_new_pages(page, order); else return false; } #endif /* CONFIG_DEBUG_VM */ -static bool check_new_pages(struct page *page, unsigned int order) -{ - int i; - for (i = 0; i < (1 << order); i++) { - struct page *p = page + i; - - if (unlikely(check_new_page(p))) - return true; - } - - return false; -} - inline void post_alloc_hook(struct page *page, unsigned int order, gfp_t gfp_flags) { @@ -3037,7 +3037,7 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order, if (unlikely(page == NULL)) break; - if (unlikely(check_pcp_refill(page))) + if (unlikely(check_pcp_refill(page, order))) continue; /* @@ -3641,7 +3641,7 @@ struct page *__rmqueue_pcplist(struct zone *zone, unsigned int order, page = list_first_entry(list, struct page, lru); list_del(&page->lru); pcp->count -= 1 << order; - } while (check_new_pcp(page)); + } while (check_new_pcp(page, order)); return page; }