From patchwork Wed Mar 30 22:12:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 12796425 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 292C2C433F5 for ; Wed, 30 Mar 2022 22:12:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9163B6B0072; Wed, 30 Mar 2022 18:12:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C4E68D0002; Wed, 30 Mar 2022 18:12:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7662D8D0001; Wed, 30 Mar 2022 18:12:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 64C056B0072 for ; Wed, 30 Mar 2022 18:12:57 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 20131A7267 for ; Wed, 30 Mar 2022 22:12:57 +0000 (UTC) X-FDA: 79302453594.28.56F7CED Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by imf11.hostedemail.com (Postfix) with ESMTP id F178640009 for ; Wed, 30 Mar 2022 22:12:54 +0000 (UTC) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id AB3A23200D98; Wed, 30 Mar 2022 18:12:52 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 30 Mar 2022 18:12:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:reply-to:sender:subject :subject:to:to; s=fm3; bh=VafuHBoZUzeSxeYTXUmAINKRMraZTcsVMF+kik 9kRS8=; b=D48d5msTfHW2+sZdc2uTI4B2sz6GNQT1thu8W6z0+/qRf/SlHg/t7f se1yGjjdHLGvpCRO1s00lt9/UtUODmENcVimzrg2oEbW8unmhZHbQga+UEQHtqKm dOLFquqqulEpBA33ByjSKPL3JVGBTQ5dQqIiYxd1/ajWvxsC7WRMJk4Txc/Niv10 a0tKF0pV3tZrhailrjmg9NpOAho95yeCk8kuMZT0kBBxKLmxunehb/Zkd8s61w5c YWNc+BhBaW7QrKLwmzzg2bUezDo1UUPJoQvh48CbDt68MjMsni5LRHz8Z3t4+Li4 NzmKf8GAM4xK7/xIB3QFgZia/TdzDxsA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :from:from:in-reply-to:message-id:mime-version:reply-to:reply-to :sender:subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=VafuHBoZUzeSxeYTXUmAINKRMraZT csVMF+kik9kRS8=; b=i85FOJef4YHfcyIo37PzgfhHuMaNe1MmPiroCz/ADhnFI gLsFQUpkOkaDwksKTYTMQv4BuGydKSbdPjH9hqp7pFIOKms1bxcC7oG6Qed+OeMZ Tpqhlb4RLHIV6kEju2K+Ug7HK+wsxLvVbjLXmnTvqrD9Co2qoKCrSOvgTgvsPF7b C4zpkhoCYq543FsB6lNDXsatm+cqJiil8xk+MJF5qYMLomgIiS/e9EWfdRdxs55q nWksVR/Wli38Jq56r5aSeVEGPlGcQfBwKShCeqZIHuWqGSaKrN5uebTxuAcQjXgL gULoKf3aTd3bII3Ya4OitzU4Ge7L5ay/+Y1x1hOyA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudeifedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkfforhgggfestdhqredtredttdenucfhrhhomhepkghiucgjrghn uceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepleetvddtvd dttdetffdvkeehffdtjefhkedtheffjeehvdejueektedukedufeffnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnsehsvghnth drtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 30 Mar 2022 18:12:51 -0400 (EDT) From: Zi Yan To: Linus Torvalds , Steven Rostedt Cc: David Hildenbrand , Vlastimil Babka , Mel Gorman , Mike Rapoport , Oscar Salvador , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH] mm: page_alloc: validate buddy before check its migratetype. Date: Wed, 30 Mar 2022 18:12:38 -0400 Message-Id: <20220330221238.396357-1-zi.yan@sent.com> X-Mailer: git-send-email 2.35.1 Reply-To: Zi Yan MIME-Version: 1.0 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=D48d5msT; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=i85FOJef; spf=pass (imf11.hostedemail.com: domain of zi.yan@sent.com designates 64.147.123.24 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: F178640009 X-Stat-Signature: g3j1ys35bxgectxikegru5idyc39i7jn X-HE-Tag: 1648678374-953985 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: From: Zi Yan Whenever a buddy page is found, page_is_buddy() should be called to check its validity. Add the missing check during pageblock merge check. Fixes: 1dd214b8f21c ("mm: page_alloc: avoid merging non-fallbackable pageblocks with others") Reported-by: Steven Rostedt Signed-off-by: Zi Yan Tested-by: Steven Rostedt (Google) --- mm/page_alloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index bdc8f60ae462..6c6af8658775 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1108,6 +1108,9 @@ static inline void __free_one_page(struct page *page, buddy_pfn = __find_buddy_pfn(pfn, order); buddy = page + (buddy_pfn - pfn); + + if (!page_is_buddy(page, buddy, order)) + goto done_merging; buddy_mt = get_pageblock_migratetype(buddy); if (migratetype != buddy_mt