From patchwork Thu Sep 22 01:12:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 12984353 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 76CACC32771 for ; Thu, 22 Sep 2022 01:13:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3D3980008; Wed, 21 Sep 2022 21:12:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 99ECD80007; Wed, 21 Sep 2022 21:12:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C90280008; Wed, 21 Sep 2022 21:12:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6611780007 for ; Wed, 21 Sep 2022 21:12:57 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 487DB1C6A92 for ; Thu, 22 Sep 2022 01:12:57 +0000 (UTC) X-FDA: 79937947194.16.BE89BA8 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by imf13.hostedemail.com (Postfix) with ESMTP id BBA6B20031 for ; Thu, 22 Sep 2022 01:12:56 +0000 (UTC) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 651605C00D9; Wed, 21 Sep 2022 21:12:56 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 21 Sep 2022 21:12:56 -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 :in-reply-to:message-id:mime-version:references:reply-to :reply-to:sender:subject:subject:to:to; s=fm2; t=1663809176; x= 1663895576; bh=MSo7ULomsyjNP4gRg30AmWuJ8lrcYe6Of6vn0yDqlEI=; b=U bvAtdk3jqb/SLwIn3LagFuki25gtt0dyJHJe9GYei1VxOuWrjHDbf2r7EJwFbaQE 0saVlcT5+46mnum8Oa4i9NU54dcRAapsGGa4RMi1/Ax7JE6idJfyGjat1dabv/Wo cXXbWW8eZYlsVw82WERLDKJEDBXToudONPyYqTZ8cIJzJxt0QW4F6AXUyN6/V0+X IitSXYDnm/cC7+u/DJ061AadZf9knvGEcQfpRHdmwSD9E45olDT+cmrMl8WTsyQl rlHP7lZ/lG/pgCKfDZV9umu1n0dM083fXP95M/EM+R7a7TLUI9mMpLC+VmHPgG+t ZbxnzTBDu8WC4tlP2S0gA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references: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=fm2; t=1663809176; x=1663895576; bh=M So7ULomsyjNP4gRg30AmWuJ8lrcYe6Of6vn0yDqlEI=; b=prFzzCkOPM8m5u0lS RomLqylk3YLZgI0vBFe22NgHQ/tGmwhDWMYNWgbeblejanHX3scU1pFw2PMRJbBl ahnq8kJkHFG4Kb4iRS1piPUShoW4CvryBzt0qOXiuM6Z/StxS9DZXzdT988whWrj U+MNmFceFC+C40vZa8BfnoQRmPTcbom+dQEV2O1JesZe1eZLNk1pKukJgFpKY71T fE5ug2hfv2SqkymjpCA4vc8zZzwbz/v/lwPXt1jxFnO5SnU+qRSvtBCMsxJ0w30S NSNxIJsCUolE5X8Xg+ehavsd+h/VGpuhcb4lhWat8zfIPovz21hjOfyN1/cLCKMx FMW+g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeefvddggeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrggfgsedtqhertdertddtnecuhfhrohhmpegkihcu jggrnhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeegge ehudfgudduvdelheehteegledtteeiveeuhfffveekhfevueefieeijeegvdenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpeiiihdrhigrnhessh gvnhhtrdgtohhm X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 21 Sep 2022 21:12:55 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org Cc: Zi Yan , David Hildenbrand , Matthew Wilcox , Vlastimil Babka , "Kirill A . Shutemov" , Mike Kravetz , John Hubbard , Yang Shi , David Rientjes , James Houghton , Mike Rapoport , Muchun Song , Andrew Morton , linux-kernel@vger.kernel.org Subject: [PATCH v1 02/12] mm: check page validity when find a buddy page in a non-contiguous zone Date: Wed, 21 Sep 2022 21:12:42 -0400 Message-Id: <20220922011252.2266780-3-zi.yan@sent.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220922011252.2266780-1-zi.yan@sent.com> References: <20220922011252.2266780-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663809176; a=rsa-sha256; cv=none; b=7B0GAzML52TxGEMgjRoP2IuSvGTTR8+v0cRpv+lAc4npJFN6acnCE/USzBZmeu9I5n02bx QijID9TKjhrsNByIougIapSZK7Cb8lWvpBrlAQUkw/sWPVGtvv7iStU8ZpMsPDXpY5vMP3 wznF09UiWGQriWl2owTTFJuurqFxYHc= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=sent.com header.s=fm2 header.b="U bvAtdk"; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=prFzzCkO; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf13.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.26 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663809176; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MSo7ULomsyjNP4gRg30AmWuJ8lrcYe6Of6vn0yDqlEI=; b=q/bp9kGZrBAcEJ6B1reHiHsF8GHcem/CVKInV6V3k250jmsUwvE5/2/53wMzf6acGfTMnG VMjcQeOY2c7SHlosI3qlwEvPK9yntR0zw9V8yg0RPDBR7N+bOrgP+EzP/51QIip9V/PfGH gRG9DKWsiNgc2M5NkAP03EPOGcPVmZA= X-Rspam-User: X-Stat-Signature: mbtem8brur5nn9c51yyngxpxecomdngs X-Rspamd-Queue-Id: BBA6B20031 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=sent.com header.s=fm2 header.b="U bvAtdk"; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=prFzzCkO; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf13.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.26 as permitted sender) smtp.mailfrom=zi.yan@sent.com X-Rspamd-Server: rspam07 X-HE-Tag: 1663809176-669921 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 When MAX_ORDER > section size, buddy page might not be valid when the zone is non-contiguous. Check it and return NULL if buddy page is not valid. For PFNs that not aligned to MAX_ORDER (usually at the beginning and end of a zone), __free_pages_memory() clamps down the order to make sure invalid PFN will not show up as a buddy PFN. Signed-off-by: Zi Yan --- mm/internal.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/internal.h b/mm/internal.h index b3002e03c28f..22fb1e6e3541 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -330,12 +330,16 @@ static inline struct page *find_buddy_page_pfn(struct page *page, unsigned long pfn, unsigned int order, unsigned long *buddy_pfn) { unsigned long __buddy_pfn = __find_buddy_pfn(pfn, order); + struct zone *zone = page_zone(page); struct page *buddy; buddy = page + (__buddy_pfn - pfn); if (buddy_pfn) *buddy_pfn = __buddy_pfn; + if (unlikely(!zone->contiguous && !pfn_valid(__buddy_pfn))) + return NULL; + if (page_is_buddy(page, buddy, order)) return buddy; return NULL;