From mboxrd@z Thu Jan 1 00:00:00 1970 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 BF867C43334 for ; Tue, 14 Jun 2022 02:04:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EAC1D8D01FD; Mon, 13 Jun 2022 22:04:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E5A5D8D01EE; Mon, 13 Jun 2022 22:04:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D563C8D01FD; Mon, 13 Jun 2022 22:04:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C60BC8D01EE for ; Mon, 13 Jun 2022 22:04:15 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 929C72DDDC for ; Tue, 14 Jun 2022 02:04:15 +0000 (UTC) X-FDA: 79575196470.13.A85672A Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by imf26.hostedemail.com (Postfix) with ESMTP id 5EE1514009F for ; Tue, 14 Jun 2022 02:04:13 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=xianting.tian@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0VGKvHPB_1655172248; Received: from B-LB6YLVDL-0141.local(mailfrom:xianting.tian@linux.alibaba.com fp:SMTPD_---0VGKvHPB_1655172248) by smtp.aliyun-inc.com; Tue, 14 Jun 2022 10:04:09 +0800 Subject: Re: [RESEND PATCH] mm: page_alloc: validate buddy before check the migratetype To: Guo Ren Cc: Andrew Morton , Vlastimil Babka , ziy@nvidia.com, Linux-MM , Linux Kernel Mailing List , stable@vger.kernel.org, huanyi.xj@alibaba-inc.com, zjb194813@alibaba-inc.com, tianhu.hh@alibaba-inc.com References: <20220613131046.3009889-1-xianting.tian@linux.alibaba.com> From: Xianting Tian Message-ID: Date: Tue, 14 Jun 2022 10:04:08 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655172254; a=rsa-sha256; cv=none; b=szSiGkNz0cpv4+bxubejLoTmoR9Ls9sFN1e9UYmtw/NekiQS0ZdaJz5qx34KIm4K04y/nl 9nuU4csR/NpU6nNjKvsZ+4lWnR84IhbdIr14+EU4W61gFJiPNKI9g8Yoq91N8sKvujR3tU kpdyvj5QqwJE82tnEpCP9Kz0zbB6Vhk= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf26.hostedemail.com: domain of xianting.tian@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=xianting.tian@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655172254; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=orCi631e/B0G4LdPFB444vL51TmQfVeAAcI5FqhMUfE=; b=aYHvz0yMXoexRv9Fl6eky2a1x+P3mZVeB672NCWbs/McEbgSZdQeRFDseYQ089EZ+ELdUJ g/bJ43ikW98vx52Xh+eVuSOMdsO70Lu2hNm+DWvchndkFsjYUgsdmt2al1E73G/U4U6Jb8 w0bAIkZU8QOkWdG9VgCJijRmEUMRWEU= X-Rspamd-Queue-Id: 5EE1514009F X-Rspam-User: Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf26.hostedemail.com: domain of xianting.tian@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=xianting.tian@linux.alibaba.com X-Rspamd-Server: rspam06 X-Stat-Signature: kx1cdkuuifba6g376xhftsxju5i9kgqa X-HE-Tag: 1655172252-240193 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: 在 2022/6/14 上午12:08, Guo Ren 写道: > On Mon, Jun 13, 2022 at 9:11 PM Xianting Tian > wrote: >> 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) > How did we get 0? (Try it in gdb) > (gdb) p /x (0x2000 ^ (1<<12)) > $3 = 0x3000 > > I think it got buddy PFN 0 for PFN 0x1000, right? > (gdb) p /x (0x1000 ^ (1<<12)) > $4 = 0x0 Sorry, it is a typo, the order is 0xd = 13, not 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)) > Right, we need to check the buddy_pfn valid, because some SoCs would > start dram address with an offset that has an order smaller than > MAX_ORDER. > >> + goto done_merging; >> buddy_mt = get_pageblock_migratetype(buddy); >> >> if (migratetype != buddy_mt >> -- >> 2.17.1 >> > Fixup the comment and > > Reviewed-by: Guo Ren >