Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1116418ioo; Fri, 27 May 2022 01:40:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyqj33wDmFEVmguMB5YhcnBJGFQT4phWSsbGi9h9X65WBonl6oUpY1SQJzdbESyI6RQyMl X-Received: by 2002:a17:907:7d8a:b0:6fe:dccb:cf4c with SMTP id oz10-20020a1709077d8a00b006fedccbcf4cmr23156976ejc.714.1653640838836; Fri, 27 May 2022 01:40:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653640838; cv=none; d=google.com; s=arc-20160816; b=sQ5cEzFsto5wxtRfXKFfIaNE8+TjwVO9sDcrQyDoKuwOnY7P1LQ6IUYZxA6ggJ6XAy wbSfMgk7S+12gPoTKd/aVEHqqQDzp/Lfsc4ve5YXqO1ixkmWT6WjY0n1dhGUf/iU/cDl LApbvahz9ER7el+QP6TPfqcDAkZzdh3HdrXY7P6Fj2yy2381a/Y+u82ftK9/UoZfMEp8 2SISP9dI4z7wkgE5AX4oZwfpWFm9ZGSc1DbEJh5iwlzCmy5H8bpPls/2GsAHKWk/89Nk KgxY7u1VYIjoCHQL7mQZMgnoXyGq4NDF/WFLrDwLUCpCb5bn7Po8NCDuQAq7vtjGL++/ QSMQ== 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 :message-id:date:subject:cc:to:from:feedback-id:dkim-signature :dkim-signature; bh=qCVBc37kvbRszsEQWErm5bs0GrXfiWiwMbQyFvk4XSk=; b=KmHlkQAYkS2G8EdtSlyvZgGTXh37w3CfR6GS04RtOtaLx4V4tl96wZSx+/OvTzdcN5 x71SBdLH2L7sszluKBN51ltS6PU1VG4vTERGFTgpMLkKArh9bINywIrN71XQ5q4zr6Hc taxdk8HPiBjuEta5+wPIqyaJN+NCRJnkVxzSdz8A294oVs6uunxWLKC72L2TwoV5fDq5 yj6WTEjFnMXBL1HG8BNjeP0FnBl4IOiW4ATGvXOO9Ch4HH0eYMWK1EHpIuTTLDHlXDdU yfMBfGu3TIwy8TvLUmgtoBh9uazwZPzxBA+IT1/8QECA2YdwjFcs+1yBkQfrBwpBpyZV /tzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b=r+k3sseN; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=vTaJwHRx; 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 ne4-20020a1709077b8400b006df846edd5fsi1801966ejc.998.2022.05.27.01.40.12; Fri, 27 May 2022 01:40:38 -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=fm1 header.b=r+k3sseN; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=vTaJwHRx; 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 S1349486AbiEZXPp (ORCPT + 99 others); Thu, 26 May 2022 19:15:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232203AbiEZXPm (ORCPT ); Thu, 26 May 2022 19:15:42 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80434E52A3 for ; Thu, 26 May 2022 16:15:40 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 97E045C01E4; Thu, 26 May 2022 19:15:39 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 26 May 2022 19:15:39 -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=fm1; t=1653606939; x=1653693339; bh=qCVBc37kvb RszsEQWErm5bs0GrXfiWiwMbQyFvk4XSk=; b=r+k3sseNp3hgKV6KYqE5AEMXyP ARuxlET4aUSFmVJaBFMglZ1BWjzHWif4PY9OXqflziN9J0jMuBvtBK1lqi0MPf+f Yzgd0SHcmcek+EHHp6uNAHsyY6oLolaIsTDjGDoTsg9sdUOZE2SyCxwvyMMYW+aH FvABK+TT2dkpOjiH1D0b5fydd/MnhGCrAS43XpQprNT0lGB8h7+RWywc0bImlYfa aDYY3iOyrzQATDG4VenDOrYRseTt83MAGHbWE4HZ2QlnX9K+lroX7Jw0hIz8WViv G9RWiEy7qsbhlZL1QurhJMDRvdFz6ZV9XGBkCChQoZqK8zO+PMI0ybjLQOjw== 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: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= fm1; t=1653606939; x=1653693339; bh=qCVBc37kvbRszsEQWErm5bs0GrXf iWiwMbQyFvk4XSk=; b=vTaJwHRxEds7yaBLMX8wV+cHSOI1lqc15hAGEr/BGSyc 9r9O7qaVU48pWGhScb7PE7jlFqRREVJUCvw0TBK7JBf5QrKB/pEtRkljfoxzLuMV 7Ljer4tIGh6k9Pouee3a7v5Bge4dAGNzRywftI0RVJPRG/i9Q3Qeje2d99obZju+ LBm2f0b+OYuYAsCRcj9t7N559brFl4Ugy3rnaz/FSHpmdhtP/maaUUyoJQ740ZA6 y9svYiBJneAEOz4lhdCGtxzoW6Ko+3ZWyudoiNBgCIumf6YPd6167nbpYJD/Df5L gLGL/pk3VnfZwbscG86CUWyTMPDjMgRxQmV7oqpskQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrjeekgddukecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculddutddmnegovehorghsthgrlhdqhfeguddvqddtvdculdduhedtmden ucfjughrpefhvfevufffkfforhgggfestdhqredtredttdenucfhrhhomhepkghiucgjrg hnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepvdeiuedt hedttdfhgeevkeeuveefvdeuheejledtvefgjeetkedugfdvleevkeffnecuffhomhgrih hnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpeiiihdrhigrnhesshgvnhhtrdgtohhm X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 May 2022 19:15:37 -0400 (EDT) From: Zi Yan To: Andrew Morton , David Hildenbrand , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, Qian Cai , Vlastimil Babka , Mel Gorman , Eric Ren , Mike Rapoport , Oscar Salvador , Christophe Leroy , Zi Yan , Marek Szyprowski , Michael Walle Subject: [PATCH 1/2] mm: page-isolation: skip isolated pageblock in start_isolate_page_range() Date: Thu, 26 May 2022 19:15:30 -0400 Message-Id: <20220526231531.2404977-1-zi.yan@sent.com> X-Mailer: git-send-email 2.35.1 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, 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 From: Zi Yan start_isolate_page_range() first isolates the first and the last pageblocks in the range and ensure pages across range boundaries are split during isolation. But it missed the case when the range is <=3D a pageblock and the first and the last pageblocks are the same one, so the second isolate_single_pageblock() will always fail. To fix it, skip the pageblock isolation in second isolate_single_pageblock(). Fixes: 88ee134320b8 ("mm: fix a potential infinite loop in start_isolate_pa= ge_range()") Reported-by: Marek Szyprowski Tested-by: Marek Szyprowski Link: https://lore.kernel.org/linux-mm/ac65adc0-a7e4-cdfe-a0d8-757195b86293= @samsung.com/ Reported-by: Michael Walle Tested-by: Michael Walle Link: https://lore.kernel.org/linux-mm/8ca048ca8b547e0dd1c95387ee05c23d@wal= le.cc/ Signed-off-by: Zi Yan --- mm/page_isolation.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/mm/page_isolation.c b/mm/page_isolation.c index c643c8420809..fbd820b21292 100644 --- a/mm/page_isolation.c +++ b/mm/page_isolation.c @@ -300,7 +300,7 @@ __first_valid_page(unsigned long pfn, unsigned long nr_= pages) * the in-use page then splitting the free page. */ static int isolate_single_pageblock(unsigned long boundary_pfn, int flags, - gfp_t gfp_flags, bool isolate_before) + gfp_t gfp_flags, bool isolate_before, bool skip_isolation) { unsigned char saved_mt; unsigned long start_pfn; @@ -327,11 +327,16 @@ static int isolate_single_pageblock(unsigned long bou= ndary_pfn, int flags, zone->zone_start_pfn); =20 saved_mt =3D get_pageblock_migratetype(pfn_to_page(isolate_pageblock)); - ret =3D set_migratetype_isolate(pfn_to_page(isolate_pageblock), saved_mt,= flags, - isolate_pageblock, isolate_pageblock + pageblock_nr_pages); =20 - if (ret) - return ret; + if (skip_isolation) + VM_BUG_ON(!is_migrate_isolate(saved_mt)); + else { + ret =3D set_migratetype_isolate(pfn_to_page(isolate_pageblock), saved_mt= , flags, + isolate_pageblock, isolate_pageblock + pageblock_nr_pages); + + if (ret) + return ret; + } =20 /* * Bail out early when the to-be-isolated pageblock does not form @@ -463,7 +468,8 @@ static int isolate_single_pageblock(unsigned long bound= ary_pfn, int flags, return 0; failed: /* restore the original migratetype */ - unset_migratetype_isolate(pfn_to_page(isolate_pageblock), saved_mt); + if (!skip_isolation) + unset_migratetype_isolate(pfn_to_page(isolate_pageblock), saved_mt); return -EBUSY; } =20 @@ -522,14 +528,18 @@ int start_isolate_page_range(unsigned long start_pfn,= unsigned long end_pfn, unsigned long isolate_start =3D ALIGN_DOWN(start_pfn, pageblock_nr_pages); unsigned long isolate_end =3D ALIGN(end_pfn, pageblock_nr_pages); int ret; + bool skip_isolation =3D false; =20 /* isolate [isolate_start, isolate_start + pageblock_nr_pages) pageblock = */ - ret =3D isolate_single_pageblock(isolate_start, flags, gfp_flags, false); + ret =3D isolate_single_pageblock(isolate_start, flags, gfp_flags, false, = skip_isolation); if (ret) return ret; =20 + if (isolate_start =3D=3D isolate_end - pageblock_nr_pages) + skip_isolation =3D true; + /* isolate [isolate_end - pageblock_nr_pages, isolate_end) pageblock */ - ret =3D isolate_single_pageblock(isolate_end, flags, gfp_flags, true); + ret =3D isolate_single_pageblock(isolate_end, flags, gfp_flags, true, ski= p_isolation); if (ret) { unset_migratetype_isolate(pfn_to_page(isolate_start), migratetype); return ret; --=20 2.35.1