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 4CA49C001DE for ; Mon, 17 Jul 2023 05:55:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A9BB8D0001; Mon, 17 Jul 2023 01:55:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 859CB6B0074; Mon, 17 Jul 2023 01:55:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7493A8D0001; Mon, 17 Jul 2023 01:55:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 653816B0072 for ; Mon, 17 Jul 2023 01:55:57 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2CA43B0AA9 for ; Mon, 17 Jul 2023 05:55:57 +0000 (UTC) X-FDA: 81020042754.19.9A60186 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf16.hostedemail.com (Postfix) with ESMTP id 1CD7D180012 for ; Mon, 17 Jul 2023 05:55:53 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689573355; 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=FlWHieSuO18xSKfiQMC5aYwcwmkVMl8ak1ZoZw8K/Do=; b=FX47sCC48dge6IjkXVf/H6Lq1m5t8BUQvXQZSvIA8HMK7SCdATEBctD3Y1Bkt/Hv229uSx ngDxtJ9p23kqTN3OK60Ogg2qBV345OfveQXMNziMkFmntt4Dt8PYP/Is5KZj7H+XPmKljq aV7xdEjC3NY3r93rAysH2jJn9uMbI30= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689573355; a=rsa-sha256; cv=none; b=yzBi4XLbW+s1fleo+DxiCnMI8KBpsxNggORRDuIquDQfZIdMvuydY0yEOmA6Va3dg7f27c 9Cut8OBzNZlkJmCjsip4hBhgm+RoaNr0t699Q6dH65Dmmu8v6rhCs3B0Nc4CjNZT69VCK/ uX+aRTG4usV1Hg1utgPJWNYi72mVfLQ= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.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 Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4R4BBK6Gqlz18LXn; Mon, 17 Jul 2023 13:55:05 +0800 (CST) Received: from [10.174.151.185] (10.174.151.185) 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.2507.27; Mon, 17 Jul 2023 13:55:46 +0800 Subject: Re: [PATCH 1/4] mm/swapfile: fix wrong swap entry type for hwpoisoned swapcache page To: Matthew Wilcox CC: , , , , References: <20230715031729.2420338-1-linmiaohe@huawei.com> <20230715031729.2420338-2-linmiaohe@huawei.com> <33748ced-5fd3-f3f7-f358-ca016ca8ba36@huawei.com> From: Miaohe Lin Message-ID: Date: Mon, 17 Jul 2023 13:55:45 +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: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Stat-Signature: dguzu7dzpx6mdn9mxi8apbqt4itcpai7 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 1CD7D180012 X-Rspam-User: X-HE-Tag: 1689573353-401550 X-HE-Meta: U2FsdGVkX1/fTer5Cw5mI4EaQy+bck/Z4YC0Ed7+7vjtLgxqe7kBRYpCzvNDie/wdhNXC3pQt7SroWYxJvGCTwkwji0u4p295XyK2fId8nyWeRBko9IAKKHdLSXe9uGjN+Bi+ZbtHr2Vo45UiBnzBpp88s1zh+YpjZKKLmrhQsWIcVtx0cwWpiyXd8sbs01V9SWZN7a3388BzPJsvmLKaaf5OHrH881BpsvRRpdQPsooxkodr9dXgMziyyBhxw06lhoXcFcRqUueA0XQDOg9sGYnNZgzA5kwmDqFKdgPLJT4oLH2+ohesz3nY2iKUhJ9gW+s57o/6Bcpg/J0a99HNQE2gyTW0FymRDG39vMIIFjar+VqECmLHPeEsXUYiKYAzDkLoqM6UBTx0Fgy+9VIxyhbxQQEi4+QduJLvkdGW3iXwK3Yo6ofX9Hs7KMiGbhbc26dG4qGUWygN41GZTX6XHnRUD+PZLzV48tZ3TaNp0ir+e2sxO7UHIikqGnNJjyff5ZAsOp7dSZKlx5hy6LsErGnJuXT60i11HNYc7F33VirLOILlMTmo02VxlY0SbEYqfIPTpDYBNLOjwEsRYVavn/Apdrwfa4OmowTeYzKT/ezVA9TqiWI4IL6oZbtIfDv2RacI6c+NLSEuFCU8piXajMEzAL6aUw0mwHSokZXjNkmfg+7cYaU6ei2SltRrprUWB8xw3nUHLxtwFfmcJK1dVllNibw4sBvRvsEwMWqGIJtDfbWBlzJevnvTxFq4+4hgwRxK+MYBYm0/ZFhGj9cqbEcsv2/x1x9cU/wRDLe/6PsvUL13mP3HiZUgqnp/cYzjrPhFloG6zdIjchZWygPr8tO9U/nUnid+Vcq34s/XF5JSS7nZJ9KGUNzq4zDt6oibTgqAU+qDGb5GfaI5N+CWGTSeagjAMIxXlceJ/l5n6Ghml/zfSFhg3JUjtDN1rCFztxcZNgLCrwimikxOPQ 05VrtaAk D3DAxbLF+2Ml8z5NRTUrOD75nGTDqWIXF8Amm9PHj6FcqoaFTQAo4mfwIzplLzt+OloCI0B2FtsJzJKebXMaK+IXYreqWVNM/2MrSft1KWEmNJergzgf9I6v2Ix8r1vAyoUGO 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 2023/7/17 10:53, Matthew Wilcox wrote: > On Mon, Jul 17, 2023 at 10:33:14AM +0800, Miaohe Lin wrote: >> On 2023/7/15 11:50, Matthew Wilcox wrote: >>> On Sat, Jul 15, 2023 at 11:17:26AM +0800, Miaohe Lin wrote: >>>> Hwpoisoned dirty swap cache page is kept in the swap cache and there's >>>> simple interception code in do_swap_page() to catch it. But when trying >>>> to swapoff, unuse_pte() will wrongly install a general sense of "future >>>> accesses are invalid" swap entry for hwpoisoned swap cache page due to >>>> unaware of such type of page. The user will receive SIGBUS signal without >>>> expected BUS_MCEERR_AR payload. >>> >>> Have you observed this, or do you just think it's true? >>> >>>> +++ b/mm/swapfile.c >>>> @@ -1767,7 +1767,8 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, >>>> swp_entry_t swp_entry; >>>> >>>> dec_mm_counter(vma->vm_mm, MM_SWAPENTS); >>>> - if (hwposioned) { >>>> + /* Hwpoisoned swapcache page is also !PageUptodate. */ >>>> + if (hwposioned || PageHWPoison(page)) { >>> >>> This line makes no sense to me. How do we get here with PageHWPoison() >>> being true and hwposioned being false? >> >> hwposioned will be true iff ksm_might_need_to_copy returns -EHWPOISON. >> And there's PageUptodate check in ksm_might_need_to_copy before we can return -EHWPOISON: >> >> ksm_might_need_to_copy >> if (!PageUptodate(page)) >> return page; /* let do_swap_page report the error */ >> ^^^ >> Will return here because hwpoisoned swapcache page is !PageUptodate(cleared via me_swapcache_dirty()). >> >> Or am I miss something? > > Ah! So we don't even get to calling copy_mc_to_kernel(). That seems > like a bug in ksm_might_need_to_copy(), don't you think? Maybe this I'm sorry but could you please explain what the bug is? > would be a better fix: > > + if (PageHWPoison(page)) > + return ERR_PTR(-EHWPOISON); Looks reasonable. We can further avoid accessing contents of hwpoisoned swapcache pages which are PageHWPoison() && PageUptodate() at first place. Thanks. > if (!PageUptodate(page)) > return page; > > . >