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 2E8EEC433EF for ; Tue, 12 Apr 2022 08:57:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A92F46B0078; Tue, 12 Apr 2022 04:57:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A423C6B007B; Tue, 12 Apr 2022 04:57:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 931206B007D; Tue, 12 Apr 2022 04:57:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0169.hostedemail.com [216.40.44.169]) by kanga.kvack.org (Postfix) with ESMTP id 83B5E6B0078 for ; Tue, 12 Apr 2022 04:57:46 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 2C40C183CB1F5 for ; Tue, 12 Apr 2022 08:57:46 +0000 (UTC) X-FDA: 79347624132.21.38456FC Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf25.hostedemail.com (Postfix) with ESMTP id F348AA0008 for ; Tue, 12 Apr 2022 08:57:44 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Kd0365x7Tz1HBnN; Tue, 12 Apr 2022 16:57:06 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 12 Apr 2022 16:57:40 +0800 Subject: Re: [PATCH 1/3] mm/memory-failure.c: avoid false-postive PageSwapCache test To: =?UTF-8?B?SE9SSUdVQ0hJIE5BT1lBKOWggOWPoyDnm7TkuZ8p?= CC: "akpm@linux-foundation.org" , "shy828301@gmail.com" , "mike.kravetz@oracle.com" , "david@redhat.com" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" References: <20220407130352.15618-1-linmiaohe@huawei.com> <20220407130352.15618-2-linmiaohe@huawei.com> <20220411063520.GA3175313@hori.linux.bs1.fc.nec.co.jp> <792748d6-3b41-d118-27bd-75e79390ba1a@huawei.com> <20220412063724.GB3227993@hori.linux.bs1.fc.nec.co.jp> From: Miaohe Lin Message-ID: <624f330e-a01c-d0d3-82ee-f2f8f55188f2@huawei.com> Date: Tue, 12 Apr 2022 16:57:40 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20220412063724.GB3227993@hori.linux.bs1.fc.nec.co.jp> Content-Type: text/plain; charset="utf-8" Content-Language: en-US X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: F348AA0008 X-Stat-Signature: izctmkkh7ftd9zgn7epr578rwzfgmkmr Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspam-User: X-HE-Tag: 1649753864-400922 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: On 2022/4/12 14:37, HORIGUCHI NAOYA(=E5=A0=80=E5=8F=A3 =E7=9B=B4=E4=B9=9F= ) wrote: > On Mon, Apr 11, 2022 at 09:19:26PM +0800, Miaohe Lin wrote: >> On 2022/4/11 14:35, HORIGUCHI NAOYA(=E5=A0=80=E5=8F=A3 =E7=9B=B4=E4=B9= =9F) wrote: >>> On Thu, Apr 07, 2022 at 09:03:50PM +0800, Miaohe Lin wrote: >>>> PageSwapCache is only reliable when PageAnon is true because PG_swap= cache >>>> serves as PG_owner_priv_1 which can be used by fs if it's pagecache = page. >>>> So we should test PageAnon to distinguish pagecache page from swapca= che >>>> page to avoid false-postive PageSwapCache test. >>>> >>>> Signed-off-by: Miaohe Lin >>>> --- >>>> mm/memory-failure.c | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/mm/memory-failure.c b/mm/memory-failure.c >>>> index ef402b490663..2e97302d62e4 100644 >>>> --- a/mm/memory-failure.c >>>> +++ b/mm/memory-failure.c >>>> @@ -2262,7 +2262,7 @@ static int __soft_offline_page(struct page *pa= ge) >>>> return 0; >>>> } >>>> =20 >>>> - if (!PageHuge(page) && PageLRU(page) && !PageSwapCache(page)) >>>> + if (!PageHuge(page) && PageLRU(page) && !PageAnon(page)) >>>> /* >>>> * Try to invalidate first. This should work for >>>> * non dirty unmapped page cache pages. >>>> --=20 >>> >>> I foudn that with this change the following VM_BUG_ON_FOLIO() is trig= gered >>> when calling soft-offline for a swapcache. Maybe we need check both = of >>> PageAnon and PageSwapCache instead of either? >>> >> >> Many thanks for your test! This is my overlook. Sorry about it! :( The= root cause is that the page is >> added into swapcache and lru( so that it can pass the HWPoisonHandlabl= e check) but page anon is not >> set yet due to page lock is held by __soft_offline_page. So we have th= e below core dump: >> >> [ 41.232172] page:0000000033d8a20c refcount:0 mapcount:0 mapping:000= 00000bc103d88 index:0x36d pfn:0x14359b >> ^^^ page is not anon >> >> [ 41.236576] flags: 0x57ffffc0080415(locked|uptodate|lru|owner_priv_= 1|swapbacked|node=3D1|zone=3D2|lastcpupid=3D0x1fffff) >> ^^^^^^^^^^^^^^^^^^ page is in swapcache >> >> It seems we can check !PageAnon(page) && !PageSwapCache(page), as you = suggested, to fix this issue. But maybe I >> should drop this patch because invalidate_inode_page will always retur= n 0 for PageAnon due to folio_mapping =3D=3D NULL. >> So nothing is really done for anonymous page here. And the origin !Pag= eSwapCache(page) check should do the right work. >=20 > Thanks for clarification. >=20 >> Or we shouldn't even try to call invalidate_inode_page with anonymous = page in principle? >=20 > I think just keeping the current behavior is fine (because as you state= d > above invalidate_inode_page() simple ignores anonymous pages). >=20 Will drop this patch. Sorry for make noise. :( > Thanks, > Naoya Horiguchi >=20 >> BTW: PageSwapCache should be reliable here as folio_test_swapbacked is= checked implicitly inside it. In such case, PG_swapcache >> can't serve as PG_owner_priv_1 as pagecache page shouldn't set PG_swap= backed (shmem will set PG_swapbacked but PG_owner_priv_1 >> is not used anyway). Or am I miss something again?