Received: by 2002:a05:7412:3210:b0:e2:908c:2ebd with SMTP id eu16csp833297rdb; Fri, 1 Sep 2023 05:45:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE6OITG6Ul/sLL43ZXV9HXdDlFwdHVIsZ6iFxS27a9ia6+4F5ZobcVS3j0bAE+MwuJkGNKx X-Received: by 2002:a05:6512:3047:b0:500:9860:f8a with SMTP id b7-20020a056512304700b0050098600f8amr1625864lfb.4.1693572333078; Fri, 01 Sep 2023 05:45:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693572333; cv=none; d=google.com; s=arc-20160816; b=QfxiIAmnwlM2a2dkaxkcNj49YJBO1iUjNuCAh8h1yN2ixrwSXZa16/+WjhSv+f04vB RB1ECSG4SPFgTJ9WF0O8CynVctP4m5eTHHjq47lFe+crS6kFQOkkGk/ffd/v47Zxn+Go yfRxSf39I9YdIe22r8IE+HlyW2RYmD/Tx4B8HLIaL+63CjUNj0DPe8PFpfFIZYQWjdas Zm5UJB3ecF1pl4VT4lv/qscFJ7nAAKbMmrqWHV9F1FVnswgAMiZx5aAoIgVLILyEyOUo jpx90svrnW9majCDnvQGvONTFN4xp/cB8Cc6CihFp+cVLQpIR9H1BseLMZFNpRbxXGJn VT3g== 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 :references:in-reply-to:message-id:date:subject:to:from; bh=NAb8+6/7dSLGpKnlgarSqxOMuIIQQFN/QCTYuGiDNNU=; fh=dxs2ymm2SV1fOwIdM32R4WPr3GXwsemQ8zdr+rmjkVo=; b=p13tyWvaP0odzPefIL0UsBZtqsUwa8Nr6ZgryTjvr5KFOT3LiQGQu4P2Yh/hwukdi2 StZ9ZrxKMVeFpc9d14dHlEAUsRyMLHgGToh02ZrrXE5K8lMXq8omLWWkxChTI9sqakrj Tkz8Gd5qOGRKq/u3fOfXmDicdCxf0LbnTiQ2H+XByIWOZqJ3kVPuJlsGLi7RmSDq0UVh QueIy1KyUuuMZ5Vp6bMCLI0J7KzJchVBukcCPAB0na4gOW3nu9kJH0aRSzqD0QayI2eq EFkjPBYwkcJ91tOxgUWy526F8DrNAfRz+MYn+v4RKhWamChgbncriTAItC+A69/EPK/7 OzqA== 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 c14-20020aa7df0e000000b005223aaec697si2534602edy.576.2023.09.01.05.45.05; Fri, 01 Sep 2023 05:45:33 -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; 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 S1344843AbjIAHwK (ORCPT + 99 others); Fri, 1 Sep 2023 03:52:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242464AbjIAHwJ (ORCPT ); Fri, 1 Sep 2023 03:52:09 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20B8410E4 for ; Fri, 1 Sep 2023 00:52:05 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4RcVby18Zsz4f3kp4 for ; Fri, 1 Sep 2023 15:51:58 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP4 (Coremail) with SMTP id gCh0CgDnw6YfmPFk1Z5cCA--.13825S5; Fri, 01 Sep 2023 15:52:01 +0800 (CST) From: Kemeng Shi To: akpm@linux-foundation.org, baolin.wang@linux.alibaba.com, mgorman@techsingularity.net, david@redhat.com, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/6] mm/compaction: correctly return failure with bogus compound_order in strict mode Date: Fri, 1 Sep 2023 23:51:38 +0800 Message-Id: <20230901155141.249860-4-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230901155141.249860-1-shikemeng@huaweicloud.com> References: <20230901155141.249860-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgDnw6YfmPFk1Z5cCA--.13825S5 X-Coremail-Antispam: 1UD129KBjvJXoW7Kr4xury8Jw43tr18tFWrKrg_yoW8Ar47pa srK3WIkr18Za4YgFy8AF4kZ3W3Grsa9FW7A393Kr18Aas5ta4xA342yr1UZFyjqrnrAF90 vrsrtFWIya1qqaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB0b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUWwA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l 84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUIq2MUUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=2.2 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, MAY_BE_FORGED,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** 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 In strict mode, we should return 0 if there is any hole in pageblock. If we successfully isolated pages at beginning at pageblock and then have a bogus compound_order outside pageblock in next page. We will abort search loop with blockpfn > end_pfn. Although we will limit blockpfn to end_pfn, we will treat it as a successful isolation in strict mode as blockpfn is not < end_pfn and return partial isolated pages. Then isolate_freepages_range may success unexpectly with hole in isolated range. Fixes: 9fcd6d2e052e ("mm, compaction: skip compound pages by order in free scanner") Signed-off-by: Kemeng Shi Reviewed-by: Baolin Wang --- mm/compaction.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index a40550a33aee..9ecbfbc695e5 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -626,11 +626,12 @@ static unsigned long isolate_freepages_block(struct compact_control *cc, if (PageCompound(page)) { const unsigned int order = compound_order(page); - if (likely(order <= MAX_ORDER)) { + if (blockpfn + (1UL << order) <= end_pfn) { blockpfn += (1UL << order) - 1; page += (1UL << order) - 1; nr_scanned += (1UL << order) - 1; } + goto isolate_fail; } @@ -678,8 +679,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc, spin_unlock_irqrestore(&cc->zone->lock, flags); /* - * There is a tiny chance that we have read bogus compound_order(), - * so be careful to not go outside of the pageblock. + * Be careful to not go outside of the pageblock. */ if (unlikely(blockpfn > end_pfn)) blockpfn = end_pfn; -- 2.30.0