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 508EBC433F5 for ; Thu, 21 Apr 2022 13:50:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C75246B0072; Thu, 21 Apr 2022 09:50:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C26326B0073; Thu, 21 Apr 2022 09:50:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B142C6B0074; Thu, 21 Apr 2022 09:50:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id A37826B0072 for ; Thu, 21 Apr 2022 09:50:46 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 80E3726A0A for ; Thu, 21 Apr 2022 13:50:46 +0000 (UTC) X-FDA: 79381021692.16.8AE8527 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf31.hostedemail.com (Postfix) with ESMTP id A69A720023 for ; Thu, 21 Apr 2022 13:50:42 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Kkf6m2QR4zdZPG; Thu, 21 Apr 2022 21:49:52 +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; Thu, 21 Apr 2022 21:50:38 +0800 Subject: Re: [PATCH v2 2/3] mm/swapfile: Fix lost swap bits in unuse_pte() To: David Hildenbrand , CC: , , , , , , , , , , , References: <20220421125348.62483-1-linmiaohe@huawei.com> <20220421125348.62483-3-linmiaohe@huawei.com> <67fc9368-0876-b931-14c2-ffa4dac35b6d@redhat.com> From: Miaohe Lin Message-ID: <58980370-f1b6-afa9-9abb-1335bf369155@huawei.com> Date: Thu, 21 Apr 2022 21:50:38 +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: <67fc9368-0876-b931-14c2-ffa4dac35b6d@redhat.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A69A720023 X-Stat-Signature: z34gqjcj5o6auuhrxcdj4hq5mjusn8ik Authentication-Results: imf31.hostedemail.com; dkim=none; spf=pass (imf31.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-HE-Tag: 1650549042-969604 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/21 21:13, David Hildenbrand wrote: > On 21.04.22 14:53, Miaohe Lin wrote: >> This is observed by code review only but not any real report. >> >> When we turn off swapping we could have lost the bits stored in the swap >> ptes. The new rmap-exclusive bit is fine since that turned into a page >> flag, but not for soft-dirty and uffd-wp. Add them. >> >> Suggested-by: Peter Xu >> Signed-off-by: Miaohe Lin >> --- >> mm/swapfile.c | 12 +++++++++--- >> 1 file changed, 9 insertions(+), 3 deletions(-) >> >> diff --git a/mm/swapfile.c b/mm/swapfile.c >> index 95b63f69f388..332ccfc76142 100644 >> --- a/mm/swapfile.c >> +++ b/mm/swapfile.c >> @@ -1783,7 +1783,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, >> { >> struct page *swapcache; >> spinlock_t *ptl; >> - pte_t *pte; >> + pte_t *pte, new_pte; >> int ret = 1; >> >> swapcache = page; >> @@ -1832,8 +1832,14 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, >> page_add_new_anon_rmap(page, vma, addr); >> lru_cache_add_inactive_or_unevictable(page, vma); >> } >> - set_pte_at(vma->vm_mm, addr, pte, >> - pte_mkold(mk_pte(page, vma->vm_page_prot))); >> + new_pte = pte_mkold(mk_pte(page, vma->vm_page_prot)); >> + if (pte_swp_soft_dirty(*pte)) >> + new_pte = pte_mksoft_dirty(new_pte); >> + if (pte_swp_uffd_wp(*pte)) { >> + new_pte = pte_mkuffd_wp(new_pte); >> + new_pte = pte_wrprotect(new_pte); > > The wrprotect shouldn't be necessary, we don't do a pte_mkwrite(). Note > that in do_swap_page() we might have done a > maybe_mkwrite(pte_mkdirty(pte)), which is why the pte_wrprotect() is > required there. You're so smart. I happened to be referring to the code in do_swap_page. ;) Now I see why pte_wrprotect() is only required there. Will remove it in the next verison when there is enough feedback. Many thanks! >