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=-14.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 3BB9BC433E2 for ; Wed, 15 Jul 2020 02:05:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C41FB20663 for ; Wed, 15 Jul 2020 02:05:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=synology.com header.i=@synology.com header.b="kHqL3YjT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C41FB20663 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=synology.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4A3F46B0002; Tue, 14 Jul 2020 22:05:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 453F26B0003; Tue, 14 Jul 2020 22:05:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3425B6B0005; Tue, 14 Jul 2020 22:05:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0233.hostedemail.com [216.40.44.233]) by kanga.kvack.org (Postfix) with ESMTP id 1998D6B0002 for ; Tue, 14 Jul 2020 22:05:31 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A10F28248D7C for ; Wed, 15 Jul 2020 02:05:30 +0000 (UTC) X-FDA: 77038668420.29.pull18_061666526ef5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 715CF18086E4F for ; Wed, 15 Jul 2020 02:05:30 +0000 (UTC) X-HE-Tag: pull18_061666526ef5 X-Filterd-Recvd-Size: 4728 Received: from synology.com (mail.synology.com [211.23.38.101]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Wed, 15 Jul 2020 02:05:29 +0000 (UTC) Subject: Re: [PATCH] mm : fix pte _PAGE_DIRTY bit when fallback migrate page DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1594778727; bh=YDrsMEH4rB9HXHNVRExpD6LMr7xokp4y9XlpkI3qsRo=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=kHqL3YjTUkLKU+mFo39ywmRMf4qTO8txj2I5J34NwSQiOHh7HNklZCY4H6mFUzXBV GeVsjmCAtIkNCO5Tbt3orFAbv3EVXejLhZTOuEmhwhypkLlUBzhS7jeKCw1GPp25tH deYTKO02Sk3S3YYJTWoYOUAfLmaIUyQO2wW/66S8= To: Vlastimil Babka , linux-mm@kvack.org Cc: LKML , linux-btrfs@vger.kernel.org, Roman Gushchin , David Sterba , "Kirill A. Shutemov" References: <20200709024808.18466-1-robbieko@synology.com> <859c810e-376e-5e8b-e8a5-0da3f83315d1@suse.cz> <80b55fcf-def1-8a83-8f53-a22f2be56244@synology.com> <433e26b0-5201-129a-4afe-4881e42781fa@suse.cz> From: Robbie Ko Message-ID: <13d4b937-23e8-2d6f-919c-deb2f4284951@synology.com> Date: Wed, 15 Jul 2020 10:05:26 +0800 MIME-Version: 1.0 In-Reply-To: <433e26b0-5201-129a-4afe-4881e42781fa@suse.cz> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Synology-MCP-Status: no X-Synology-Spam-Flag: no X-Synology-Spam-Status: score=0, required 6, WHITELIST_FROM_ADDRESS 0 X-Synology-Virus-Status: no X-Rspamd-Queue-Id: 715CF18086E4F X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: Vlastimil Babka =E6=96=BC 2020/7/14 =E4=B8=8B=E5=8D=885:46 =E5=AF=AB=E9=81= =93: > On 7/13/20 3:57 AM, Robbie Ko wrote: >> Vlastimil Babka =E6=96=BC 2020/7/10 =E4=B8=8B=E5=8D=8811:31 =E5=AF=AB=E9= =81=93: >>> On 7/9/20 4:48 AM, robbieko wrote: >>>> From: Robbie Ko >>>> >>>> When a migrate page occurs, we first create a migration entry >>>> to replace the original pte, and then go to fallback_migrate_page >>>> to execute a writeout if the migratepage is not supported. >>>> >>>> In the writeout, we will clear the dirty bit of the page and use >>>> page_mkclean to clear the dirty bit along with the corresponding pte= , >>>> but page_mkclean does not support migration entry. >>>> >>>> The page ditry bit is cleared, but the dirty bit of the pte still ex= ists, >>>> so if mmap continues to write, it will result in data loss. >>> Curious, did you observe this data loss? What filesystem? If yes, it = seems >>> serious enough to >>> CC stable and determine a Fixes: tag? >> Yes, there is data loss. >> I'm using a btrfs environment, but not the following patch > And the kernel is otherwise upstream? Which version? > Anyway we better let btrfs guys know (+CC) even if the fix is in MM cod= e. Kernel verion is 4.4. I think this is a bug that has been around for a long time. I think the problem is not limited to btrfs, as long as other fs have not implemented the migrationpage, they will encounter the problem. (Eg ecryptfs, fat, nfs...) >> btrfs: implement migratepage callback for data pages >> https://git.kernel.org/pub/scm/linux/kernel >> /git/torvalds/linux.git/commit/?h=3Dv5.8-rc5& >> id=3Df8e6608180a31cc72a23b74969da428da236dbd1 > That's a new commit, so if this is really affecting upstream btrfs pre-= 5.8 we > should either backport that commit, or your fix (after review). > >>>> We fix the by first remove the migration entry and then clearing >>>> the dirty bits of the page, which also clears the pte's dirty bits. >>>> >>>> Signed-off-by: Robbie Ko >>>> --- >>>> mm/migrate.c | 8 ++++---- >>>> 1 file changed, 4 insertions(+), 4 deletions(-) >>>> >>>> diff --git a/mm/migrate.c b/mm/migrate.c >>>> index f37729673558..5c407434b9ba 100644 >>>> --- a/mm/migrate.c >>>> +++ b/mm/migrate.c >>>> @@ -875,10 +875,6 @@ static int writeout(struct address_space *mappi= ng, struct page *page) >>>> /* No write method for the address space */ >>>> return -EINVAL; >>>> =20 >>>> - if (!clear_page_dirty_for_io(page)) >>>> - /* Someone else already triggered a write */ >>>> - return -EAGAIN; >>>> - >>>> /* >>>> * A dirty page may imply that the underlying filesystem has >>>> * the page on some queue. So the page must be clean for >>>> @@ -889,6 +885,10 @@ static int writeout(struct address_space *mappi= ng, struct page *page) >>>> */ >>>> remove_migration_ptes(page, page, false); >>>> =20 >>>> + if (!clear_page_dirty_for_io(page)) >>>> + /* Someone else already triggered a write */ >>>> + return -EAGAIN; >>>> + >>>> rc =3D mapping->a_ops->writepage(page, &wbc); >>>> =20 >>>> if (rc !=3D AOP_WRITEPAGE_ACTIVATE) >>>> >