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 X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B45CC433ED for ; Mon, 17 May 2021 06:48:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BB12561185 for ; Mon, 17 May 2021 06:48:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB12561185 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 48B726B006E; Mon, 17 May 2021 02:48:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 462586B0070; Mon, 17 May 2021 02:48:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3030A6B0071; Mon, 17 May 2021 02:48:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0225.hostedemail.com [216.40.44.225]) by kanga.kvack.org (Postfix) with ESMTP id EBB7A6B006E for ; Mon, 17 May 2021 02:48:53 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 79820A2C2 for ; Mon, 17 May 2021 06:48:53 +0000 (UTC) X-FDA: 78149795346.11.E892A26 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf20.hostedemail.com (Postfix) with ESMTP id B2E343C8 for ; Mon, 17 May 2021 06:48:51 +0000 (UTC) Received: from dggems705-chm.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Fk8mC5c9Kz16QxW; Mon, 17 May 2021 14:46:03 +0800 (CST) Received: from dggema766-chm.china.huawei.com (10.1.198.208) by dggems705-chm.china.huawei.com (10.3.19.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Mon, 17 May 2021 14:48:47 +0800 Received: from [10.174.177.210] (10.174.177.210) by dggema766-chm.china.huawei.com (10.1.198.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Mon, 17 May 2021 14:48:47 +0800 Subject: Re: [PATCH] mm/memory-failure: make sure wait for page writeback in memory_failure To: Oscar Salvador , Jan Kara , CC: , , , , , , , , , References: <20210511070329.2002597-1-yangerkun@huawei.com> <20210511084600.GG24154@quack2.suse.cz> From: yangerkun Message-ID: <4803a723-666f-c710-3ad4-2579390e4a9d@huawei.com> Date: Mon, 17 May 2021 14:48:46 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed X-Originating-IP: [10.174.177.210] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggema766-chm.china.huawei.com (10.1.198.208) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: B2E343C8 Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of yangerkun@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=yangerkun@huawei.com; dmarc=pass (policy=none) header.from=huawei.com X-Rspamd-Server: rspam03 X-Stat-Signature: b14rfhyrqq4du45s48fbe3k8bdtsj1gh X-HE-Tag: 1621234131-208557 Content-Transfer-Encoding: quoted-printable 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: =E5=9C=A8 2021/5/11 17:34, Oscar Salvador =E5=86=99=E9=81=93: > On Tue, May 11, 2021 at 10:46:00AM +0200, Jan Kara wrote: >> We definitely need to wait for writeback of these pages and the change= you >> suggest makes sense to me. I'm just not sure whether the only problem = with >> these "pages in the process of being munlocked()" cannot confuse the s= tate >> machinery in memory_failure() also in some other way. Also I'm not sur= e if >> are really allowed to call wait_on_page_writeback() on just any page t= hat >> hits memory_failure() - there can be slab pages, anon pages, completel= y >> unknown pages given out by page allocator to device drivers etc. That = needs >> someone more familiar with these MM details than me. >=20 > I am not really into mm/writeback stuff, but: >=20 > shake_page() a few lines before tries to identifiy the page, and > make those sitting in lruvec real PageLRU, and then we take page's lock= . >=20 > I thought that such pages (pages on writeback) are stored in the file > LRU, and maybe the code was written with that in mind? And given that > we are under the PageLock, such state could not have changed. Hi, Crash of this bug show we can clear page LRU without lock_page by follow=20 stack. So this page_lock in memory_failure seems useless to prevent this=20 BUG. do_mmap->mmap_region->do_munmap->munlock_vma_pages_range->__munlock_pagev= ec static void __munlock_pagevec(struct pagevec *pvec, struct zone *zone) { ... for (i =3D 0; i < nr; i++) { struct page *page =3D pvec->pages[i]; if (TestClearPageMlocked(page)) { if (TestClearPageLRU(page)) { <=3D=3D=3D clear LRU flag ... } ... } ... } ... } >=20 > But if such pages are allowed to not be in the LRU (maybe they are take= n > off before initiating the writeback?), I guess the change is correct. > Checking wait_on_page_writeback(), it seems it first checks for > Writeback bit, and since that bit is not "shared" and only being set > in mm/writeback code, it should be fine to call that. >=20 > But alternatively, we could also modify the check and go with: >=20 > if (!PageTransTail(p) && !PageLRU(p) && !PageWriteBack(p)) > goto identify_page_state; I have no idea should we process this page with such state. But it seems=20 reasonable to add some comments to clarify our change. Thanks, Kun. >=20 > and stating why a page under writeback might not be in the LRU, as I > think the code assumes. >=20 > AFAUI, mm/writeback locks the page before setting the bit, and since we > hold the lock, we could not race here. >=20