Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp639763iog; Mon, 13 Jun 2022 09:40:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6ctJ1vwfSsFNyn8j2666OcE2AmuGlo6E7bkTumm6Y/wmtkOcfRt9o8TtHRG7qUM/WujrF X-Received: by 2002:a17:90b:4ac1:b0:1e6:7c82:9aee with SMTP id mh1-20020a17090b4ac100b001e67c829aeemr16634618pjb.234.1655138433924; Mon, 13 Jun 2022 09:40:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655138433; cv=none; d=google.com; s=arc-20160816; b=GePb2rqgB8QRV9RWVjsdyziR1UBvtXz64801w93TG/cK2ffwlP/nMurAUzWoJi94o4 L1ROwhnnqIqfF0igY8vZx35fK1fY9C3y7F5V4af8Kn2G0u9rhxAJyhxGKsWOuiwBbAtU flybKFNFSIzEWGgIGaV2NgrWZC73TU6tE40qCJKRfBVchjCi/6kQ780DsHqy0mF+SQyw BLi4K1DP1WyT3OrcHS9hVnqAwTrb4EyUUyKEBUQV3noqohd56PEPF0EEStSmLDOwSeOp CDqcJep6q3BdOv1VRGs1anmcjQnNB6Pxoz8adbCt5pao3XQDz7EJznruXMxnfSEQg2V9 M/FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=Z0xDkjOrV+CdYZsDe8y7C54SKZZutxLHJ7R0w63z1Gs=; b=bshI5rQVkKxdxZUClnplbtWXtAZ5h43s6X93nlblwLn6+N29Rr7/h3ac4hLRY4z52v NSlHSMHlE4+cedG/OMWvbvmOtkwSn+Zm/UH70F9FDpNTnvE+VTMkWDP0vAyvgIZuv/QF 6X37gU8juDGKszBRBnxnPdNyRYvlUtW2Y8E39MNOKZlpRvHMHEEIZCG0bLv6cDxyiRhp nELfl1WAaB2/xsGrreWclJrr9P/zpmgGENeHMJVwKybpkI2XliqvrJQmjGC5WETEyT09 ml3g3vuHxQLsd4Wjaw0h7ImlGOw8K5tHcEDUOPMPPKGPkQNOCdBOyfqz2tzGEf/i22kC SlKA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i3-20020a17090a64c300b001e26550d25esi12391311pjm.142.2022.06.13.09.40.20; Mon, 13 Jun 2022 09:40: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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239269AbiFMPhH (ORCPT + 99 others); Mon, 13 Jun 2022 11:37:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244371AbiFMPgj (ORCPT ); Mon, 13 Jun 2022 11:36:39 -0400 Received: from out30-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com [115.124.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B77F381B9; Mon, 13 Jun 2022 06:09:05 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0VGHIVnj_1655125740; Received: from localhost(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0VGHIVnj_1655125740) by smtp.aliyun-inc.com; Mon, 13 Jun 2022 21:09:01 +0800 From: Xianting Tian To: akpm@linux-foundation.org, ziy@nvidia.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, huanyi.xj@alibaba-inc.com, guoren@kernel.org, zjb194813@alibaba-inc.com, tianhu.hh@alibaba-inc.com, Xianting Tian Subject: [PATCH] mm: page_alloc: validate buddy before check the migratetype Date: Mon, 13 Jun 2022 21:08:58 +0800 Message-Id: <20220613130858.3009808-1-xianting.tian@linux.alibaba.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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 Commit 787af64d05cd ("mm: page_alloc: validate buddy before check its migratetype.") added buddy check code. But unfortunately, this fix isn't backported to linux-5.17.y and the former stable branches. The reason is it added wrong fixes message: Fixes: 1dd214b8f21c ("mm: page_alloc: avoid merging non-fallbackable pageblocks with others") Actually, this issue is involved by commit: commit d9dddbf55667 ("mm/page_alloc: prevent merging between isolated and other pageblocks") For RISC-V arch, the first 2M is reserved for sbi, so the start PFN is 512, but it got buddy PFN 0 for PFN 0x2000: 0 = 0x2000 ^ (1 << 12) With the illegal buddy PFN 0, it got an illegal buddy page, which caused crash in __get_pfnblock_flags_mask(). With the patch, it can avoid the calling of get_pageblock_migratetype() if it isn't buddy page. Fixes: d9dddbf55667 ("mm/page_alloc: prevent merging between isolated and other pageblocks") Cc: stable@vger.kernel.org Reported-by: zjb194813@alibaba-inc.com Reported-by: tianhu.hh@alibaba-inc.com Signed-off-by: Xianting Tian --- mm/page_alloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b1caa1c6c887..5b423caa68fd 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1129,6 +1129,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 -- 2.17.1