Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp104057rwb; Wed, 21 Sep 2022 18:21:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM41O/fzOgu3oQqTJ1cqrvWEmij+Ex+dEwMRxzlM0M0T0AbZflDDY5lCz/uVaLAjejno2Qcs X-Received: by 2002:a17:907:a4e:b0:77d:94d:8148 with SMTP id be14-20020a1709070a4e00b0077d094d8148mr709750ejc.607.1663809668956; Wed, 21 Sep 2022 18:21:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663809668; cv=none; d=google.com; s=arc-20160816; b=rYDXM95+8Oku38ShhzytW2T6/0V4jMVbWzJJ0oFVjib0UiNoC6mf1lqg8OLXilkekd jojRUFE5GUgtrOs3GodlOKQ9LYcSlO704xJXGlUiOI9zlN2nDITKBHqyz05LXh1KAD1X 7MYthwznkprJ3j5shq/ZRvYexCxuIb83rhaZwzSXGSWWxOeertNZ4bkkjTFlOLoBnetH yUb2RmN5chbpM3pNeVTN7pdPwci0NZecFkJUnE2whnchd9CnJPnpcip3Q6XOl/DpyhoF cOHZl/N/qinezUwSO/+2gs1OVJ14+GYoDmMbnjZrsTjEMetl0rKUeFRt1Zyd2hfTNap1 64Dw== 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:reply-to :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=MSo7ULomsyjNP4gRg30AmWuJ8lrcYe6Of6vn0yDqlEI=; b=z9BC0EMT4BzDXfWJ0hxQC6/agIi4/TUV1uEjuCHJ8zpMfzJILpHsXDIPY1vddIgpp5 5Z3GhhzlBwTHuEC5gtDux1tAfff5qf2TB1PgjrZLnH+T07+IKDFUUQELC+fJtMatkw9Y ZgM/OId+QgGZ4pOCUzouEZZe85vLeMvcQ0yMqNijoMqNbnEasBC2MK8QHjSJz+AnFVIm AiIQthv/V4Bo9kwZ1jF8MvB5dEwPOfLDTslD4k6xC2esSsvhzzKL/YA7/cjIkhcLbNAY pooso+wkvxPydtH2n+srWp7wcOw5F+ObPJBhe/DOP47OKA2OvJvjg/A+1lTp7Djz+55t iGUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm2 header.b=UbvAtdk3; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=prFzzCkO; 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=sent.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t4-20020a17090605c400b0074168953071si2911393ejt.866.2022.09.21.18.20.34; Wed, 21 Sep 2022 18:21:08 -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=@sent.com header.s=fm2 header.b=UbvAtdk3; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=prFzzCkO; 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=sent.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229985AbiIVBNE (ORCPT + 99 others); Wed, 21 Sep 2022 21:13:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbiIVBNA (ORCPT ); Wed, 21 Sep 2022 21:13:00 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A2DBAA35B for ; Wed, 21 Sep 2022 18:12:57 -0700 (PDT) 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 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS 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: 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 =3D __find_buddy_pfn(pfn, order); + struct zone *zone =3D page_zone(page); struct page *buddy; =20 buddy =3D page + (__buddy_pfn - pfn); if (buddy_pfn) *buddy_pfn =3D __buddy_pfn; =20 + if (unlikely(!zone->contiguous && !pfn_valid(__buddy_pfn))) + return NULL; + if (page_is_buddy(page, buddy, order)) return buddy; return NULL; --=20 2.35.1